-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cs
70 lines (60 loc) · 1.63 KB
/
Game.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using Godot;
using Flecs.NET.Core;
public partial class Game : WorldNode
{
public override void _EnterTree()
{
base._EnterTree();
World.Set(new Time());
Physics.Observers(World);
Interact.Observers(World);
Timer.Observers(World);
Animation.Observers(World);
StateMachines.Observers(World);
StateMachines.Systems(World);
Animation.Systems(World);
Attack.Systems(World);
Damage.Systems(World);
Timer.Systems(World);
Input.Systems(World);
Interact.Systems(World);
Flash.Systems(World);
Colorize.Systems(World);
Moves.Systems(World);
Physics.Systems(World);
Delete.Systems(World);
}
static StringName UI_LEFT = new StringName("ui_left");
static StringName UI_RIGHT = new StringName("ui_right");
static StringName UI_UP = new StringName("ui_up");
static StringName UI_DOWN = new StringName("ui_down");
static StringName ATTACK = new StringName("attack");
public override void _PhysicsProcess(double delta)
{
ref var time = ref World.GetMut<Time>();
time.Delta = delta;
time.Scale = (float)(delta / Physics.TARGET_FRAMETIME);
time.Ticks++;
var direction = Godot.Input.GetVector(UI_LEFT, UI_RIGHT, UI_UP, UI_DOWN).Normalized();
if (!direction.IsZeroApprox())
{
World.Set(new ControllerEvent { Direction = direction });
}
if (Godot.Input.IsActionJustPressed(ATTACK))
{
World.Add<InputAttackCommand>();
}
base._PhysicsProcess(delta);
}
public override void _UnhandledInput(InputEvent @event)
{
if (@event is InputEventMouseButton mouse && mouse.IsPressed())
{
World.Set(new MouseEvent
{
Button = mouse,
Position = ToLocal(GetViewport().GetMousePosition())
});
}
}
}