diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-28 17:01:53 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-28 17:01:53 -0300 |
| commit | 358943907bc9e37d26618ee03adf1ffd97635335 (patch) | |
| tree | 223b32f5631d3decb679302b489e6d7e124674c8 /scripts | |
| parent | afcd5055e98dcb7c9fefeabb072ecc56d0456bd7 (diff) | |
Combate corpo a corpo.
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/actors/Actor.cs | 60 | ||||
| -rw-r--r-- | scripts/actors/ActorDefinition.cs | 4 | ||||
| -rw-r--r-- | scripts/actors/Enemy.cs | 6 | ||||
| -rw-r--r-- | scripts/actors/actions/BumpAction.cs | 2 | ||||
| -rw-r--r-- | scripts/actors/actions/DirectionalAction.cs | 14 | ||||
| -rw-r--r-- | scripts/actors/actions/MeleeAction.cs | 18 | ||||
| -rw-r--r-- | scripts/actors/actions/MovementAction.cs | 6 | ||||
| -rw-r--r-- | scripts/input/BaseInputHandler.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/input/InputHandler.cs (renamed from scripts/InputHandler.cs) | 16 | ||||
| -rw-r--r-- | scripts/input/InputHandler.cs.uid (renamed from scripts/InputHandler.cs.uid) | 0 |
10 files changed, 100 insertions, 27 deletions
diff --git a/scripts/actors/Actor.cs b/scripts/actors/Actor.cs index b0e050f..642e9fd 100644 --- a/scripts/actors/Actor.cs +++ b/scripts/actors/Actor.cs @@ -37,18 +37,20 @@ public abstract partial class Actor : Sprite2D get => gridPosition; } + private bool blocksMovement; /// <summary> - /// Se o ator bloqueia movimento (não pode oculpar a mesma célula de outro ator.) - /// </summary> + /// Se o ator bloqueia movimento (não pode oculpar a mesma célula de outro ator.) + /// </summary> public bool BlocksMovement { - get => definition.blocksMovement; + get => blocksMovement; } + private string actorName; /// <summary> /// Nome do ator. /// </summary> public string ActorName { - get => definition.name; + get => actorName; } private int hp; @@ -64,6 +66,9 @@ public abstract partial class Actor : Sprite2D set { // Esta propriedade impede que o HP seja maior que o máximo. hp = int.Clamp(value, 0, MaxHp); + if (hp <= 0) { + Die(); + } } } @@ -136,6 +141,9 @@ public abstract partial class Actor : Sprite2D /// <param name="definition">A definição do ator.</param> public virtual void SetDefinition(ActorDefinition definition) { this.definition = definition; + blocksMovement = definition.blocksMovement; + actorName = definition.name; + ZIndex = 1; Texture = definition.texture; MaxHp = definition.Hp; @@ -147,4 +155,48 @@ public abstract partial class Actor : Sprite2D Def = definition.Def; Men = definition.Men; } + + public virtual void Die() { + //⠀⠀⠀⠀⢠⣤⣤⣤⢠⣤⣤⣤⣤⣄⢀⣠⣤⣤⣄⠀⠀⠀⢀⣠⣤⣤⣄⠀⣤⣤⠀⠀⣠⣤⣤⣤⣤⣤⡄⢠⣤⣤⣤⣄⠀⠀ + //⠀⠀⠀⠀⠈⢹⣿⠉⠈⠉⣿⣿⠉⠉⢾⣿⣉⣉⠙⠀⠀⢀⣾⡟⠉⠉⣿⣧⢸⣿⡄⢠⣿⠏⣿⣿⣉⣉⡁⢸⣿⡏⢉⣿⡷⠀ + //⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⣿⣿⠀⠀⠈⠿⠿⣿⣿⡀⠀⠸⣿⡇⠀⠀⣾⣿⠀⢿⣿⣸⡿⠀⣿⣿⠿⠿⠇⢸⣿⣿⣿⣿⠀⠀ + //⠀⠀⠀⠀⢠⣼⣿⣤⠀⠀⣿⣿⠀⠀⢷⣦⣤⣼⡿⠁⠀⠀⠹⣿⣤⣴⡿⠋⠀⠘⣿⣿⠃⠀⣿⣿⣤⣤⡄⢸⣿⡇⠙⢿⣦⡀ + //⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⠀⠀⠀⠀⠀⠀⠀⠀⢀⣰⣶⣶⣶⣿⣿⣿⣿⣷⣶⣤⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⠀⠀⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⠿⠛⠛⠻⢿⣿⣿⣿⣿⣿⣿⣿⣶⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⠀⠀⠀⠀⠀⢀⢾⣿⣿⣿⣿⠟⠁⠀⠀⠀⠀⠀⠈⠉⠉⠉⠻⢿⢿⣿⣿⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⠀⠀⠀⠀⢠⠏⢸⣿⣿⡿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠿⢻⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⠀⠀⠀⢀⠇⠀⠈⠿⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⠀⠀⢀⡞⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠰⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⠀⠀⡸⠀⠀⠀⠀⠀⠀⠀⠀⡼⠛⠳⣄⡀⠀⠐⢿⣦⡀⠀⠀⠀⢠⠃⠀⣸⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⠀⢠⠇⠀⠀⠀⠀⠀⠀⠀⠀⠉⠀⠀⠀⠉⣳⠟⠒⠻⣿⣦⡀⠀⡘⠀⢰⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⢀⠞⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⠃⢠⣄⡀⠈⠙⢿⡌⠁⠀⡞⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⠞⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠳⣄⣈⢻⡿⠃⢰⠟⠲⣼⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⠀⠀⠀⡰⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⡶⢴⠋⠀⠀⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⠀⠀⡴⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠞⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡴⢟⠒⠀⠀⠀⠀⢰⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠏⠀⠀⠈⠉⣿⠇⠀⢀⡎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⣷⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠠⣤⣤⣀⢰⠏⠉⠙⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⣀⣀⣀⣀⣠⠴⠢⠦⠽⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⣿⣿⣿⣷⡄⣀⡀⠈⠉⠋⢹⠋⠁⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + //⠿⠿⠿⠿⠿⠦⠈⠀⠀⠀⠸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + + string deathMessage; + + if (Map_Data.Player == this) { + deathMessage = "Você morreu!"; + } else { + deathMessage = $"{ActorName} morreu!"; + } + + GD.Print(deathMessage); + + Texture = definition.deathTexture; + blocksMovement = false; + ZIndex = 0; + actorName = $"Restos mortais de ${actorName}"; + Map_Data.UnregisterBlockingActor(this); + } }
\ No newline at end of file diff --git a/scripts/actors/ActorDefinition.cs b/scripts/actors/ActorDefinition.cs index 72eb745..7f67787 100644 --- a/scripts/actors/ActorDefinition.cs +++ b/scripts/actors/ActorDefinition.cs @@ -1,6 +1,5 @@ using Godot; - /// <summary> /// Define de forma genérica as características de um ator. /// </summary> @@ -14,6 +13,9 @@ public partial class ActorDefinition : Resource // Seu sprite. [Export] public Texture2D texture; + // Sprite de morto + [Export] + public Texture2D deathTexture; [ExportCategory("Mechanics")] // Se o ator bloqueia movimento. diff --git a/scripts/actors/Enemy.cs b/scripts/actors/Enemy.cs index 8cd3a74..19bcd2c 100644 --- a/scripts/actors/Enemy.cs +++ b/scripts/actors/Enemy.cs @@ -46,4 +46,10 @@ public partial class Enemy : Actor break; } } + + public override void Die() { + Soul.QueueFree(); + Soul = null; + base.Die(); + } } diff --git a/scripts/actors/actions/BumpAction.cs b/scripts/actors/actions/BumpAction.cs index def721b..0ce7fbe 100644 --- a/scripts/actors/actions/BumpAction.cs +++ b/scripts/actors/actions/BumpAction.cs @@ -19,7 +19,7 @@ public partial class BumpAction : DirectionalAction Action action; // Se houver um ator no destino, crie uma ação de ataque. - if (GetBlockingActorAtPosition(destination) != null) { + if (GetTargetActor() != null) { action = new MeleeAction(actor, Offset); } else { // Mas se não houver, crie uma ação de movimento. diff --git a/scripts/actors/actions/DirectionalAction.cs b/scripts/actors/actions/DirectionalAction.cs index 8c3c68f..ca2ca95 100644 --- a/scripts/actors/actions/DirectionalAction.cs +++ b/scripts/actors/actions/DirectionalAction.cs @@ -11,18 +11,20 @@ public abstract partial class DirectionalAction : Action /// Seu significado depende da ação que implementará esta classe. /// </summary> public Vector2I Offset { get; private set; } + /// <summary> + /// Coordenada do alvo da ação. + /// </summary> + public Vector2I Destination { get => actor.GridPosition + Offset; } public DirectionalAction(Actor actor, Vector2I offset) : base(actor) { Offset = offset; } /// <summary> - /// É conveniente ter acesso à função para obter atores em uma determinada posição. - /// Este método expõe o método de mesmo nome do mapa. + /// Função que obtém o alvo da ação, se houver. /// </summary> - /// <param name="pos">Posição para verificar</param> - /// <returns>O ator naquela posição, nulo se não houver.</returns> - protected Actor GetBlockingActorAtPosition(Vector2I pos) { - return Map_Data.GetBlockingActorAtPosition(pos); + /// <returns>O ator alvo da ação, nulo se não houver.</returns> + protected Actor GetTargetActor() { + return Map_Data.GetBlockingActorAtPosition(Destination); } } diff --git a/scripts/actors/actions/MeleeAction.cs b/scripts/actors/actions/MeleeAction.cs index cf40f1d..c61a803 100644 --- a/scripts/actors/actions/MeleeAction.cs +++ b/scripts/actors/actions/MeleeAction.cs @@ -14,14 +14,24 @@ public partial class MeleeAction : DirectionalAction /// </summary> public override void Perform() { - Vector2I destination = actor.GridPosition + Offset; // Eu te disse que este método seria útil. - Actor target = GetBlockingActorAtPosition(destination); + Actor target = GetTargetActor(); // Se não houver um ator na direção, não podemos continuar. if (target == null) return; - // TODO: Implementar ataque. - GD.Print($"Você tenta socar {target.ActorName}, mas como não sobra nada para o beta, você ainda não tem um método de ataque."); + // não podemos ter dano negativo. + int damage = actor.Atk - target.Def; + + string attackDesc = $"{actor.ActorName} ataca {target.ActorName}"; + + if (damage > 0) { + attackDesc += $" e remove {damage} de HP."; + target.Hp -= damage; + } else { + attackDesc += $" mas {target.ActorName} tem músculos de aço."; + } + + GD.Print(attackDesc); } } diff --git a/scripts/actors/actions/MovementAction.cs b/scripts/actors/actions/MovementAction.cs index f86d542..b37f9ae 100644 --- a/scripts/actors/actions/MovementAction.cs +++ b/scripts/actors/actions/MovementAction.cs @@ -11,14 +11,12 @@ public partial class MovementAction : DirectionalAction public override void Perform() { - Vector2I finalDestination = actor.GridPosition + Offset; - // Não anda se o destino for um tile sólido. - if (!Map_Data.IsTileWalkable(finalDestination)) return; + if (!Map_Data.IsTileWalkable(Destination)) return; // Não anda se o destino for oculpado por um ator. // Na maioria dos casos, essa condição nunca é verdadeira. - if (GetBlockingActorAtPosition(finalDestination) != null) return; + if (GetTargetActor() != null) return; actor.Walk(Offset); } diff --git a/scripts/input/BaseInputHandler.cs.uid b/scripts/input/BaseInputHandler.cs.uid new file mode 100644 index 0000000..deae303 --- /dev/null +++ b/scripts/input/BaseInputHandler.cs.uid @@ -0,0 +1 @@ +uid://cl1of0602byx0 diff --git a/scripts/InputHandler.cs b/scripts/input/InputHandler.cs index 39016ed..838790e 100644 --- a/scripts/InputHandler.cs +++ b/scripts/input/InputHandler.cs @@ -19,14 +19,16 @@ public partial class InputHandler : Node { public Action GetAction(Player player) { Action action = null; - foreach (var direction in directions) { - if (Input.IsActionJustPressed(direction.Key)) { - action = new BumpAction(player, direction.Value); + if (player.IsAlive) { + foreach (var direction in directions) { + if (Input.IsActionJustPressed(direction.Key)) { + action = new BumpAction(player, direction.Value); + } + } + + if (Input.IsActionJustPressed("skip-turn")) { + action = new WaitAction(player); } - } - - if (Input.IsActionJustPressed("skip-turn")) { - action = new WaitAction(player); } return action; diff --git a/scripts/InputHandler.cs.uid b/scripts/input/InputHandler.cs.uid index 302a3b5..302a3b5 100644 --- a/scripts/InputHandler.cs.uid +++ b/scripts/input/InputHandler.cs.uid |
