summaryrefslogtreecommitdiff
path: root/scripts/Game.cs
blob: 836af8405a45b08bd53b7c449d372578db2e7a08 (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
53
54
55
using Godot;
using System;

public partial class Game : Node {
	private static readonly ActorDefinition playerDefinition = GD.Load<ActorDefinition>("res://assets/definitions/actor/Player.tres");
	private static readonly ActorDefinition skeletonDefinition = GD.Load<ActorDefinition>("res://assets/definitions/actor/Skeleton.tres");
	private Player player;
	private Node2D actorsNode;
	public MapData Map_Data { get; private set; }
	private InputHandler inputHandler;

	public override void _Ready() {
		base._Ready();

		Map Map = GetNode<Map>("Map");

		Map_Data = Map.Map_Data;

		inputHandler = GetNode<InputHandler>("InputHandler");
		actorsNode = GetNode<Node2D>("Actors");

		player = new Player(Vector2I.Zero, Map_Data, playerDefinition);
		Camera2D camera = GetNode<Camera2D>("Camera2D");
		RemoveChild(camera);

		player.AddChild(camera);

		actorsNode.AddChild(player);

		Enemy Skeleton = new Enemy(Vector2I.Zero, Map_Data, skeletonDefinition);
		actorsNode.AddChild(Skeleton);

		Map_Data.InsertActor(new Vector2I(1, 1), player);
		Map_Data.InsertActor(new Vector2I(3, 4), Skeleton);
	}

	public override void _PhysicsProcess(double delta) {
		base._PhysicsProcess(delta);

		Action action = inputHandler.GetAction(player);

		if (action != null) {
			action.Perform();
			HandleEnemyTurns();
		}
	}

	private void HandleEnemyTurns() {
		foreach (Actor actor in Map_Data.Actors) {
			if (actor is Player) continue;

			GD.Print($"O {actor.ActorName} foi cuckado e não tem como agir.");
		}
	}
}