blob: 818b06421e73ad877056c8d8c49cd7b8c17956a2 (
plain)
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
|
using Godot;
using System;
public partial class Game : Node {
private static readonly ActorDefinition playerDefinition = GD.Load<ActorDefinition>("res://assets/definitions/actor/Player.tres");
private Map Map;
private InputHandler inputHandler;
public override void _Ready() {
base._Ready();
Map = GetNode<Map>("Map");
inputHandler = GetNode<InputHandler>("InputHandler");
Player player = new Player(Vector2I.Zero, null, playerDefinition);
Camera2D camera = GetNode<Camera2D>("Camera2D");
RemoveChild(camera);
player.AddChild(camera);
Map.Generate(player);
Map.UpdateFOV(player.GridPosition);
}
public override void _PhysicsProcess(double delta) {
base._PhysicsProcess(delta);
Player player = Map.Map_Data.Player;
Action action = inputHandler.GetAction(player);
if (action != null) {
Vector2I previousPlayerPos = player.GridPosition;
action.Perform();
HandleEnemyTurns();
if (player.GridPosition != previousPlayerPos) {
Map.UpdateFOV(player.GridPosition);
}
}
}
private void HandleEnemyTurns() {
foreach (Actor actor in Map.Map_Data.Actors) {
if (actor is Player) continue;
if (actor is Enemy enemy && enemy.IsAlive) {
enemy.Soul.Perform();
}
}
}
}
|