summaryrefslogtreecommitdiff
path: root/scripts/actors
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/actors')
-rw-r--r--scripts/actors/Actor.cs60
-rw-r--r--scripts/actors/ActorDefinition.cs4
-rw-r--r--scripts/actors/Enemy.cs6
-rw-r--r--scripts/actors/actions/BumpAction.cs2
-rw-r--r--scripts/actors/actions/DirectionalAction.cs14
-rw-r--r--scripts/actors/actions/MeleeAction.cs18
-rw-r--r--scripts/actors/actions/MovementAction.cs6
7 files changed, 90 insertions, 20 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);
}