blob: 5c1b6349ef371f8354c69d2ea6919bbc5bf80457 (
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
using Godot;
using TheLegendOfGustav.Entities.Actors;
using TheLegendOfGustav.Entities.Actions;
using TheLegendOfGustav.InputHandling;
using TheLegendOfGustav.GUI;
using TheLegendOfGustav.Time;
using TheLegendOfGustav.Utils;
namespace TheLegendOfGustav;
/// <summary>
/// Classe principal do jogo.
/// Lar da lógica central do jogo.
/// </summary>
public partial class Game : Node
{
/// <summary>
/// Definição de um jogador.
/// </summary>
private static readonly PlayerDefinition playerDefinition = GD.Load<PlayerDefinition>("res://assets/definitions/actor/Player.tres");
/// <summary>
/// O jogo possui o mapa.
/// </summary>
private Map.Map Map { get; set; }
/// <summary>
/// Objeto para obter input do usuário.
/// </summary>
private InputHandler InputHandler { get; set; }
/// <summary>
/// Gerenciador de turnos
/// </summary>
private TurnManager TurnManager { get; set; }
private Hud hud;
public override void _Ready()
{
base._Ready();
Map = GetNode<Map.Map>("Map");
InputHandler = GetNode<InputHandler>("InputHandler");
hud = GetNode<Hud>("HUD");
// O jogador é criado pelo jogo.
Player player = new Player(Vector2I.Zero, null, playerDefinition);
Camera2D camera = GetNode<Camera2D>("Camera2D");
RemoveChild(camera);
player.HealthChanged += (int hp, int maxHp) => hud.OnHealthChanged(hp, maxHp);
player.ManaChanged += hud.OnManaChanged;
player.Died += () => InputHandler.SetInputHandler(InputHandlers.GameOver);
player.AddChild(camera);
Map.Generate(player);
Map.UpdateFOV(player.GridPosition);
TurnManager = new(Map);
MessageLogData.Instance.AddMessage("Boa sorte!");
}
/// <summary>
/// Método executa aproximadamente 60 vezes por segundo.
/// </summary>
/// <param name="delta"></param>
public override void _PhysicsProcess(double delta)
{
base._PhysicsProcess(delta);
Player player = Map.MapData.Player;
// Pegamos uma ação do usuário
Action action = InputHandler.GetAction(player);
if (action != null)
{
TurnManager.InsertPlayerAction(action);
}
// Computamos um turno.
TurnManager.Tick();
}
}
|