add Game autoload scene

This commit is contained in:
Chris Cromer 2022-11-10 00:05:28 -03:00
parent 3f9c21c5b4
commit d0c685a2b2
Signed by: cromer
GPG Key ID: FA91071797BEEEC2
3 changed files with 39 additions and 1 deletions

View File

@ -17,7 +17,8 @@ config/icon="res://icon.png"
[autoload]
Event="*res://scenes/Event.cs"
Event="*res://scripts/Event.cs"
Game="*res://scenes/game/Game.tscn"
[display]

31
scenes/game/Game.cs Normal file
View File

@ -0,0 +1,31 @@
using Godot;
public sealed class Game : Node
{
[Export]
private int _energy { get; set; } = 3;
[Export]
private int _bolts { get; set; } = 0;
public enum PhysicsLayer : ushort {
Player = 1,
Platform = 2,
Enemy = 3,
Collectable = 4
}
public override void _Ready()
{
var eventBus = GetNode<Event>("/root/Event");
eventBus.Connect("EnergyCollected", this, "OnEnergyCollected");
}
private void OnEnergyCollected(int energy)
{
_energy += energy;
if (OS.IsDebugBuild())
{
GD.Print("Energy: " + _energy);
}
}
}

6
scenes/game/Game.tscn Normal file
View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://scenes/game/Game.cs" type="Script" id=1]
[node name="Game" type="Node"]
script = ExtResource( 1 )