summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/definitions/actor/Player.tres11
-rw-r--r--project.godot5
-rw-r--r--scenes/Game.tscn6
-rw-r--r--scripts/Game.cs2
-rw-r--r--scripts/entities/actions/PickUpAction.cs34
-rw-r--r--scripts/entities/actions/PickUpAction.cs.uid1
-rw-r--r--scripts/entities/actors/Inventory.cs35
-rw-r--r--scripts/entities/actors/Inventory.cs.uid1
-rw-r--r--scripts/entities/actors/Player.cs11
-rw-r--r--scripts/entities/actors/PlayerDefinition.cs8
-rw-r--r--scripts/entities/actors/PlayerDefinition.cs.uid1
-rw-r--r--scripts/input/InputHandler.cs4
-rw-r--r--scripts/input/MainGameInputHandler.cs4
-rw-r--r--scripts/input/PickupInputHandler.cs41
-rw-r--r--scripts/input/PickupInputHandler.cs.uid1
-rw-r--r--scripts/map/Map.cs6
-rw-r--r--scripts/map/MapData.cs45
17 files changed, 205 insertions, 11 deletions
diff --git a/assets/definitions/actor/Player.tres b/assets/definitions/actor/Player.tres
index f465740..56aa604 100644
--- a/assets/definitions/actor/Player.tres
+++ b/assets/definitions/actor/Player.tres
@@ -1,11 +1,12 @@
-[gd_resource type="Resource" script_class="ActorDefinition" load_steps=4 format=3 uid="uid://cn6xnpwxjudbp"]
+[gd_resource type="Resource" script_class="PlayerDefinition" load_steps=4 format=3 uid="uid://7pwmjcgbcyoo"]
-[ext_resource type="Script" uid="uid://crxw1e37xlrrt" path="res://scripts/entities/actors/ActorDefinition.cs" id="1_2k33r"]
+[ext_resource type="Script" uid="uid://bd78nfh1tsjq6" path="res://scripts/entities/actors/PlayerDefinition.cs" id="1_2k33r"]
[ext_resource type="Texture2D" uid="uid://w0808ug4al66" path="res://assets/sprites/actors/generic_grave.png" id="1_m72ac"]
-[ext_resource type="Texture2D" uid="uid://dwky8qc2y602k" path="res://assets/sprites/actors/player.png" id="2_2xyvf"]
+[ext_resource type="Texture2D" uid="uid://dwky8qc2y602k" path="res://assets/sprites/actors/player.png" id="3_frwfa"]
[resource]
script = ExtResource("1_2k33r")
+InventoryCapacity = 20
deathTexture = ExtResource("1_m72ac")
Speed = 10
Hp = 36
@@ -14,7 +15,7 @@ Atk = 8
Def = 2
Men = 3
name = "Jogador"
-texture = ExtResource("2_2xyvf")
+texture = ExtResource("3_frwfa")
Type = 2
blocksMovement = true
-metadata/_custom_type_script = "uid://crxw1e37xlrrt"
+metadata/_custom_type_script = "uid://bd78nfh1tsjq6"
diff --git a/project.godot b/project.godot
index 9b3764e..fa6d1ed 100644
--- a/project.godot
+++ b/project.godot
@@ -99,6 +99,11 @@ quit={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194305,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
+pick-item={
+"deadzone": 0.2,
+"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":59,"physical_keycode":0,"key_label":0,"unicode":59,"location":0,"echo":false,"script":null)
+]
+}
[rendering]
diff --git a/scenes/Game.tscn b/scenes/Game.tscn
index 98d918d..2a59777 100644
--- a/scenes/Game.tscn
+++ b/scenes/Game.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=11 format=3 uid="uid://u5h6iqyi8wd0"]
+[gd_scene load_steps=12 format=3 uid="uid://u5h6iqyi8wd0"]
[ext_resource type="Script" uid="uid://dwubb28wt4bhe" path="res://scripts/Game.cs" id="1_cpr0p"]
[ext_resource type="Script" uid="uid://ejqmdbc0524i" path="res://scripts/input/MainGameInputHandler.cs" id="3_400sg"]
@@ -10,6 +10,7 @@
[ext_resource type="PackedScene" uid="uid://bryqrafavmwj4" path="res://scenes/Details.tscn" id="5_qy1jj"]
[ext_resource type="Script" uid="uid://bereyrj1s46y5" path="res://scripts/map/FieldOfView.cs" id="5_s0nni"]
[ext_resource type="PackedScene" uid="uid://b4h4xyr1g8o50" path="res://scenes/hud.tscn" id="6_aug50"]
+[ext_resource type="Script" uid="uid://dspqgdxg5jji0" path="res://scripts/input/PickupInputHandler.cs" id="10_3xj3m"]
[node name="Game" type="Node"]
script = ExtResource("1_cpr0p")
@@ -46,6 +47,9 @@ script = ExtResource("4_g4kob")
script = ExtResource("5_g4kob")
map = NodePath("../../Map")
+[node name="PickupInputHandler" type="Node" parent="InputHandler"]
+script = ExtResource("10_3xj3m")
+
[node name="Camera2D" type="Camera2D" parent="."]
offset = Vector2(8, 8)
zoom = Vector2(2, 2)
diff --git a/scripts/Game.cs b/scripts/Game.cs
index f25776e..b8c6a8b 100644
--- a/scripts/Game.cs
+++ b/scripts/Game.cs
@@ -9,7 +9,7 @@ public partial class Game : Node {
/// <summary>
/// Definição de um jogador.
/// </summary>
- private static readonly ActorDefinition playerDefinition = GD.Load<ActorDefinition>("res://assets/definitions/actor/Player.tres");
+ private static readonly PlayerDefinition playerDefinition = GD.Load<PlayerDefinition>("res://assets/definitions/actor/Player.tres");
/// <summary>
/// O jogo possui o mapa.
/// </summary>
diff --git a/scripts/entities/actions/PickUpAction.cs b/scripts/entities/actions/PickUpAction.cs
new file mode 100644
index 0000000..b772bb7
--- /dev/null
+++ b/scripts/entities/actions/PickUpAction.cs
@@ -0,0 +1,34 @@
+using Godot;
+
+public partial class PickupAction : DirectionalAction
+{
+ protected Player player;
+
+ public PickupAction(Player player, Vector2I offset) : base(player, offset)
+ {
+ this.player = player;
+ // Pegar itens requer um tempo menor.
+ cost = 2;
+ }
+
+ public override bool Perform()
+ {
+ ConsumableItem item = Map_Data.GetFirstItemAtPosition(Destination);
+
+ if (item == null) {
+ MessageLogData.Instance.AddMessage("Não tem item aqui.");
+ return false;
+ }
+
+ if (player.inventory.Items.Count >= player.inventory.Capacity) {
+ MessageLogData.Instance.AddMessage("Seu inventário está cheio");
+ return false;
+ }
+
+ Map_Data.RemoveEntity(item);
+ player.inventory.Add(item);
+
+ player.Energy -= cost;
+ return true;
+ }
+} \ No newline at end of file
diff --git a/scripts/entities/actions/PickUpAction.cs.uid b/scripts/entities/actions/PickUpAction.cs.uid
new file mode 100644
index 0000000..7ca9c72
--- /dev/null
+++ b/scripts/entities/actions/PickUpAction.cs.uid
@@ -0,0 +1 @@
+uid://dydpoqnwxwbq6
diff --git a/scripts/entities/actors/Inventory.cs b/scripts/entities/actors/Inventory.cs
new file mode 100644
index 0000000..ea9569f
--- /dev/null
+++ b/scripts/entities/actors/Inventory.cs
@@ -0,0 +1,35 @@
+using Godot;
+
+public partial class Inventory : Node {
+ private Player player;
+
+ public Godot.Collections.Array<ConsumableItem> Items { get; private set; } = [];
+
+ public int Capacity { get; private set; }
+
+ public Inventory(int capacity) {
+ Capacity = capacity;
+ }
+
+ public override void _Ready() {
+ base._Ready();
+ player = GetParent<Player>();
+ }
+
+ public void Drop(ConsumableItem item) {
+ Items.Remove(item);
+ MapData data = player.Map_Data;
+ data.InsertEntity(item);
+ data.EmitSignal(MapData.SignalName.EntityPlaced, item);
+ item.Map_Data = data;
+ item.GridPosition = player.GridPosition;
+
+ MessageLogData.Instance.AddMessage($"Você descarta {item.DisplayName}.");
+ }
+
+ public void Add(ConsumableItem item) {
+ if (Items.Count >= Capacity) return;
+
+ Items.Add(item);
+ }
+} \ No newline at end of file
diff --git a/scripts/entities/actors/Inventory.cs.uid b/scripts/entities/actors/Inventory.cs.uid
new file mode 100644
index 0000000..05c2beb
--- /dev/null
+++ b/scripts/entities/actors/Inventory.cs.uid
@@ -0,0 +1 @@
+uid://isaqxdpou22h
diff --git a/scripts/entities/actors/Player.cs b/scripts/entities/actors/Player.cs
index 324e67a..d1c4c7f 100644
--- a/scripts/entities/actors/Player.cs
+++ b/scripts/entities/actors/Player.cs
@@ -7,7 +7,16 @@ using System;
[GlobalClass]
public partial class Player : Actor
{
- public Player(Vector2I initialPosition, MapData map, ActorDefinition definition) : base(initialPosition, map, definition)
+ public Inventory inventory;
+
+ public Player(Vector2I initialPosition, MapData map, PlayerDefinition definition) : base(initialPosition, map, definition)
{
+ SetDefinition(definition);
+ }
+
+ public void SetDefinition(PlayerDefinition definition) {
+ inventory = new(definition.InventoryCapacity);
+
+ AddChild(inventory);
}
}
diff --git a/scripts/entities/actors/PlayerDefinition.cs b/scripts/entities/actors/PlayerDefinition.cs
new file mode 100644
index 0000000..aca07e1
--- /dev/null
+++ b/scripts/entities/actors/PlayerDefinition.cs
@@ -0,0 +1,8 @@
+using Godot;
+
+[GlobalClass]
+public partial class PlayerDefinition : ActorDefinition {
+ [ExportCategory("Player Mechanics")]
+ [Export]
+ public int InventoryCapacity = 0;
+} \ No newline at end of file
diff --git a/scripts/entities/actors/PlayerDefinition.cs.uid b/scripts/entities/actors/PlayerDefinition.cs.uid
new file mode 100644
index 0000000..9d01ab9
--- /dev/null
+++ b/scripts/entities/actors/PlayerDefinition.cs.uid
@@ -0,0 +1 @@
+uid://bd78nfh1tsjq6
diff --git a/scripts/input/InputHandler.cs b/scripts/input/InputHandler.cs
index 4f5b4e1..7ee2be1 100644
--- a/scripts/input/InputHandler.cs
+++ b/scripts/input/InputHandler.cs
@@ -4,7 +4,8 @@ public enum InputHandlers
{
MainGame,
GameOver,
- Inspect
+ Inspect,
+ Pickup
}
/// <summary>
@@ -27,6 +28,7 @@ public partial class InputHandler : Node
// Controles para quando o jogador está morto.
inputHandlers.Add(InputHandlers.GameOver, GetNode<GameOverInputHandler>("GameOverInputHandler"));
inputHandlers.Add(InputHandlers.Inspect, GetNode<InspectInputHandler>("InspectInputHandler"));
+ inputHandlers.Add(InputHandlers.Pickup, GetNode<PickupInputHandler>("PickupInputHandler"));
SetInputHandler(startingInputHandler);
}
diff --git a/scripts/input/MainGameInputHandler.cs b/scripts/input/MainGameInputHandler.cs
index c7bf26a..6fb6aac 100644
--- a/scripts/input/MainGameInputHandler.cs
+++ b/scripts/input/MainGameInputHandler.cs
@@ -25,6 +25,10 @@ public partial class MainGameInputHandler : BaseInputHandler {
}
}
+ if (Input.IsActionJustPressed("pick-item")) {
+ GetParent<InputHandler>().SetInputHandler(InputHandlers.Pickup);
+ }
+
if (Input.IsActionJustPressed("inspect")) {
GetParent<InputHandler>().SetInputHandler(InputHandlers.Inspect);
}
diff --git a/scripts/input/PickupInputHandler.cs b/scripts/input/PickupInputHandler.cs
new file mode 100644
index 0000000..8f4f9b2
--- /dev/null
+++ b/scripts/input/PickupInputHandler.cs
@@ -0,0 +1,41 @@
+using Godot;
+
+/// <summary>
+/// Esquema de controles para pegar um item.
+/// </summary>
+public partial class PickupInputHandler : BaseInputHandler {
+ private readonly Godot.Collections.Dictionary<string, Vector2I> directions = new()
+ {
+ {"walk-up", Vector2I.Up},
+ {"walk-down", Vector2I.Down},
+ {"walk-left", Vector2I.Left},
+ {"walk-right", Vector2I.Right},
+ {"walk-up-right", Vector2I.Up + Vector2I.Right},
+ {"walk-up-left", Vector2I.Up + Vector2I.Left},
+ {"walk-down-right", Vector2I.Down + Vector2I.Right},
+ {"walk-down-left", Vector2I.Down + Vector2I.Left},
+ {"skip-turn", Vector2I.Zero}
+ };
+ public override Action GetAction(Player player) {
+ Action action = null;
+
+ if (player.IsAlive) {
+ foreach (var direction in directions) {
+ if (Input.IsActionJustPressed(direction.Key)) {
+ action = new PickupAction(player, direction.Value);
+ Quit();
+ }
+ }
+
+ if (Input.IsActionJustPressed("quit")) {
+ Quit();
+ }
+ }
+
+ return action;
+ }
+
+ private void Quit() {
+ GetParent<InputHandler>().SetInputHandler(InputHandlers.MainGame);
+ }
+}
diff --git a/scripts/input/PickupInputHandler.cs.uid b/scripts/input/PickupInputHandler.cs.uid
new file mode 100644
index 0000000..139dd25
--- /dev/null
+++ b/scripts/input/PickupInputHandler.cs.uid
@@ -0,0 +1 @@
+uid://dspqgdxg5jji0
diff --git a/scripts/map/Map.cs b/scripts/map/Map.cs
index f4f0783..148bda6 100644
--- a/scripts/map/Map.cs
+++ b/scripts/map/Map.cs
@@ -62,6 +62,8 @@ public partial class Map : Node2D
{
Map_Data = generator.GenerateDungeon(player);
+ Map_Data.EntityPlaced += OnEntityPlaced;
+
PlaceTiles();
PlaceEntities();
}
@@ -77,4 +79,8 @@ public partial class Map : Node2D
entity.Visible = Map_Data.GetTile(entity.GridPosition).IsInView;
}
}
+
+ private void OnEntityPlaced(Entity entity) {
+ entitiesNode.AddChild(entity);
+ }
}
diff --git a/scripts/map/MapData.cs b/scripts/map/MapData.cs
index 08a144d..f3e193e 100644
--- a/scripts/map/MapData.cs
+++ b/scripts/map/MapData.cs
@@ -10,9 +10,12 @@ public partial class MapData : RefCounted
public static readonly TileDefinition wallDefinition = GD.Load<TileDefinition>("res://assets/definitions/tiles/wall.tres");
public static readonly TileDefinition floorDefinition = GD.Load<TileDefinition>("res://assets/definitions/tiles/floor.tres");
+ [Signal]
+ public delegate void EntityPlacedEventHandler(Entity entity);
+
/// <summary>
- /// Largura do mapa.
- /// </summary>
+ /// Largura do mapa.
+ /// </summary>
public int Width { get; private set; }
/// <summary>
/// Altura do mapa.
@@ -33,6 +36,18 @@ public partial class MapData : RefCounted
/// </summary>
public Godot.Collections.Array<Entity> Entities { get; private set; } = [];
+ public Godot.Collections.Array<ConsumableItem> Items {
+ get {
+ Godot.Collections.Array<ConsumableItem> list = [];
+ foreach (Entity entity in Entities) {
+ if (entity is ConsumableItem item) {
+ list.Add(item);
+ }
+ }
+ return list;
+ }
+ }
+
private AStarGrid2D pathfinder;
/// <summary>
/// Objeto do Godot que utiliza do algoritmo A* para calcular
@@ -196,6 +211,32 @@ public partial class MapData : RefCounted
}
return null;
}
+
+ /// <summary>
+ /// Obtém o primeiro item na posição especificada.
+ /// </summary>
+ /// <param name="pos">Posição</param>
+ /// <returns>O primeiro item na posição, nulo se não houver.</returns>
+ public ConsumableItem GetFirstItemAtPosition(Vector2I pos) {
+ foreach (ConsumableItem item in Items) {
+ if (item.GridPosition == pos) {
+ return item;
+ }
+ }
+
+ return null;
+ }
+
+ /// <summary>
+ /// Remove uma entidade do mapa sem dar free.
+ /// </summary>
+ /// <param name="entity">A entidade para remover</param>
+ public void RemoveEntity(Entity entity) {
+ // Eu removo a entidade do nó de entidades.
+ entity.GetParent().RemoveChild(entity);
+ // Eu removo a entidade da lista de entidades do mapa.
+ Entities.Remove(entity);
+ }
/// <summary>
/// Obtém todas as entidades na posição especificada.