diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-18 18:43:54 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-18 18:43:54 -0300 |
| commit | 723e66a82606ee78ca4156a0c0a850185b4c0369 (patch) | |
| tree | 1aafa29e16a462f812b804e2f3419387ba07b2f2 | |
| parent | c9057bbd88f14a4e0e572c16452c1ab9baebfe2a (diff) | |
IT'S OVER
26 files changed, 295 insertions, 71 deletions
diff --git a/assets/definitions/tiles/floor.tres b/assets/definitions/tiles/floor.tres new file mode 100644 index 0000000..4cd3e9c --- /dev/null +++ b/assets/definitions/tiles/floor.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" script_class="TileDefinition" load_steps=3 format=3 uid="uid://dfrremrf4rn15"] + +[ext_resource type="Script" uid="uid://ba82a33ov6uuo" path="res://scripts/map/TileDefinition.cs" id="1_snxyj"] +[ext_resource type="Texture2D" uid="uid://ds13x1dpu0v4s" path="res://assets/sprites/floor.png" id="1_vvyfi"] + +[resource] +script = ExtResource("1_snxyj") +Texture = ExtResource("1_vvyfi") +IsWalkable = true +metadata/_custom_type_script = "uid://ba82a33ov6uuo" diff --git a/assets/definitions/tiles/wall.tres b/assets/definitions/tiles/wall.tres new file mode 100644 index 0000000..bc16528 --- /dev/null +++ b/assets/definitions/tiles/wall.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" script_class="TileDefinition" load_steps=3 format=3 uid="uid://cdluqrbfcu5ng"] + +[ext_resource type="Texture2D" uid="uid://s5klxirh5r1w" path="res://assets/sprites/wall.png" id="1_jkwov"] +[ext_resource type="Script" uid="uid://ba82a33ov6uuo" path="res://scripts/map/TileDefinition.cs" id="1_ugwtv"] + +[resource] +script = ExtResource("1_ugwtv") +Texture = ExtResource("1_jkwov") +IsWalkable = false +metadata/_custom_type_script = "uid://ba82a33ov6uuo" diff --git a/assets/sprites/floor.png b/assets/sprites/floor.png Binary files differnew file mode 100644 index 0000000..2f93b12 --- /dev/null +++ b/assets/sprites/floor.png diff --git a/assets/sprites/floor.png.import b/assets/sprites/floor.png.import new file mode 100644 index 0000000..0314f1a --- /dev/null +++ b/assets/sprites/floor.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ds13x1dpu0v4s" +path="res://.godot/imported/floor.png-6264fbe74424f0aef23944979b83713d.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/sprites/floor.png" +dest_files=["res://.godot/imported/floor.png-6264fbe74424f0aef23944979b83713d.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/sprites/wall.png b/assets/sprites/wall.png Binary files differnew file mode 100644 index 0000000..3b2e058 --- /dev/null +++ b/assets/sprites/wall.png diff --git a/assets/sprites/wall.png.import b/assets/sprites/wall.png.import new file mode 100644 index 0000000..0ad296e --- /dev/null +++ b/assets/sprites/wall.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://s5klxirh5r1w" +path="res://.godot/imported/wall.png-a2b2dda47b1ed3651589e27171e28380.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/sprites/wall.png" +dest_files=["res://.godot/imported/wall.png-a2b2dda47b1ed3651589e27171e28380.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scenes/DungeonLevel.tscn b/scenes/DungeonLevel.tscn deleted file mode 100644 index 201dd69..0000000 --- a/scenes/DungeonLevel.tscn +++ /dev/null @@ -1,14 +0,0 @@ -[gd_scene load_steps=3 format=4 uid="uid://dnh8xgk1w76i2"] - -[ext_resource type="TileSet" uid="uid://biilh0ufacguh" path="res://assets/test_tileset.tres" id="1_bxfih"] -[ext_resource type="Script" uid="uid://cy7qumrpks2kx" path="res://scripts/DungeonLevel.cs" id="1_u6mlv"] - -[node name="Map" type="Node2D"] -script = ExtResource("1_u6mlv") - -[node name="Dungeon" type="TileMapLayer" parent="."] -texture_filter = 1 -tile_map_data = PackedByteArray("AAAHAAcAAAAAAAAAAAAIAAcAAAAAAAAAAAAJAAcAAAAAAAAAAAAKAAcAAAAAAAAAAAALAAcAAAAAAAAAAAAMAAcAAAAAAAAAAAANAAcAAAAAAAAAAAAOAAcAAAAAAAAAAAAOAAgAAAAAAAAAAAANAAgAAAAAAAAAAAAMAAgAAAAAAAAAAAALAAgAAAAAAAAAAAAKAAgAAAAAAAAAAAAJAAgAAAAAAAAAAAAIAAgAAAAAAAAAAAAHAAgAAAAAAAAAAAAHAAkAAAAAAAAAAAAIAAkAAAAAAAAAAAAKAAkAAAAAAAAAAAALAAkAAAAAAAAAAAAMAAkAAAAAAAAAAAANAAkAAAAAAAAAAAAOAAkAAAAAAAAAAAAJAAkAAAAAAAAAAAAGAAYAAAABAAAAAAAGAAcAAAABAAAAAAAGAAgAAAAAAAAAAAAGAAkAAAABAAAAAAAGAAoAAAABAAAAAAAHAAoAAAABAAAAAAAIAAoAAAABAAAAAAAJAAoAAAABAAAAAAANAAoAAAABAAAAAAAOAAoAAAABAAAAAAAPAAoAAAABAAAAAAAPAAkAAAABAAAAAAAPAAgAAAABAAAAAAAPAAcAAAABAAAAAAAPAAYAAAABAAAAAAAOAAYAAAABAAAAAAANAAYAAAABAAAAAAAMAAYA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AAYAAAAAAAAAAAAUAAcAAAABAAAAAAAUAAgAAAABAAAAAAATAAcAAAAAAAAAAAATAAYAAAAAAAAAAAAQAAQAAAAAAAAAAAAQAAgAAAAAAAAAAAARAAYAAAABAAAAAAASAAkAAAAAAAAAAAAWAAkAAAAAAAAAAAAWAAgAAAAAAAAAAAAWAAcAAAAAAAAAAAAWAAYAAAAAAAAAAAAWAAUAAAAAAAAAAAAWAAQAAAAAAAAAAAAVAAQAAAAAAAAAAAAKAAoAAAAAAAAAAAAJAAsAAAABAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAABAAEAAAAAAAAAAAABAAIAAAAAAAAAAAABAAMAAAAAAAAAAAABAAQAAAAAAAAAAAABAAUAAAAAAAAAAAABAAYAAAAAAAAAAAABAAcAAAAAAAAAAAABAAgAAAAAAAAAAAACAAgAAAAAAAAAAAADAAgAAAAAAAAAAAA=") -tile_set = ExtResource("1_bxfih") - -[node name="Actors" type="Node2D" parent="."] diff --git a/scenes/Game.tscn b/scenes/Game.tscn index 361f821..0b85ec0 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -1,17 +1,22 @@ [gd_scene load_steps=4 format=3 uid="uid://u5h6iqyi8wd0"] [ext_resource type="Script" uid="uid://dwubb28wt4bhe" path="res://scripts/Game.cs" id="1_cpr0p"] -[ext_resource type="PackedScene" uid="uid://dnh8xgk1w76i2" path="res://scenes/DungeonLevel.tscn" id="2_cpr0p"] +[ext_resource type="Script" uid="uid://fe2h4is11tnw" path="res://scripts/Map.cs" id="3_cpr0p"] [ext_resource type="Script" uid="uid://ejqmdbc0524i" path="res://scripts/InputHandler.cs" id="3_s0nni"] [node name="Game" type="Node"] script = ExtResource("1_cpr0p") -[node name="Map" parent="." instance=ExtResource("2_cpr0p")] - [node name="InputHandler" type="Node" parent="."] script = ExtResource("3_s0nni") +[node name="Map" type="Node2D" parent="."] +script = ExtResource("3_cpr0p") +Height = 20 +Width = 20 + +[node name="Actors" type="Node2D" parent="."] + [node name="Camera2D" type="Camera2D" parent="."] offset = Vector2(8, 8) zoom = Vector2(2, 2) diff --git a/scripts/DungeonGenerator.cs b/scripts/DungeonGenerator.cs new file mode 100644 index 0000000..99b8aac --- /dev/null +++ b/scripts/DungeonGenerator.cs @@ -0,0 +1,19 @@ +using Godot; +using System; + +public partial class DungeonGenerator : Node +{ + private TileMapLayer map; + + [ExportCategory("Parametres")] + [Export] + private int width = 80; + [Export] + private int height = 60; + + public override void _Ready() + { + base._Ready(); + map = GetParent().GetNode<TileMapLayer>("Dungeon"); + } +} diff --git a/scripts/DungeonGenerator.cs.uid b/scripts/DungeonGenerator.cs.uid new file mode 100644 index 0000000..15aeef6 --- /dev/null +++ b/scripts/DungeonGenerator.cs.uid @@ -0,0 +1 @@ +uid://dwyr067lwqcsj diff --git a/scripts/DungeonLevel.cs b/scripts/DungeonLevel.cs deleted file mode 100644 index 68751c5..0000000 --- a/scripts/DungeonLevel.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Godot; -using System; - -public partial class DungeonLevel : Node2D -{ - private TileMapLayer buildingLayer; - public Godot.Collections.Array<Actor> Actors { get; private set; } = []; - - private Node2D actorsNode; - - public override void _Ready() - { - base._Ready(); - - buildingLayer = GetNode<TileMapLayer>("Dungeon"); - actorsNode = GetNode<Node2D>("Actors"); - } - - public void InsertActor(Actor actor) { - Actors.Add(actor); - actorsNode.AddChild(actor); - } - - public bool IsTileWalkable(Vector2I pos) { - TileData tile = buildingLayer.GetCellTileData(pos); - - if (tile == null) return false; - - return (bool)tile.GetCustomData("isWalkable"); - } - - public Actor GetBlockingActorAtPosition(Vector2I pos) { - foreach (Actor actor in Actors) { - if (actor.GridPosition == pos && actor.BlocksMovement) { - return actor; - } - } - return null; - } -} diff --git a/scripts/Enemy.cs b/scripts/Enemy.cs index 921cd86..6f9f3d9 100644 --- a/scripts/Enemy.cs +++ b/scripts/Enemy.cs @@ -3,7 +3,7 @@ using System; public partial class Enemy : Actor { - public Enemy(Vector2I initialPosition, DungeonLevel map, ActorDefinition definition) : base(initialPosition, map, definition) + public Enemy(Vector2I initialPosition, MapData map, ActorDefinition definition) : base(initialPosition, map, definition) { } } diff --git a/scripts/Game.cs b/scripts/Game.cs index f5c5240..836af84 100644 --- a/scripts/Game.cs +++ b/scripts/Game.cs @@ -3,24 +3,35 @@ 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; - public DungeonLevel Map { get; private set; } + private Node2D actorsNode; + public MapData Map_Data { get; private set; } private InputHandler inputHandler; public override void _Ready() { base._Ready(); - Map = GetNode<DungeonLevel>("Map"); + Map Map = GetNode<Map>("Map"); + + Map_Data = Map.Map_Data; inputHandler = GetNode<InputHandler>("InputHandler"); + actorsNode = GetNode<Node2D>("Actors"); - player = new Player(new Vector2I(0, 0), Map, playerDefinition); + player = new Player(Vector2I.Zero, Map_Data, playerDefinition); Camera2D camera = GetNode<Camera2D>("Camera2D"); RemoveChild(camera); player.AddChild(camera); - Map.InsertActor(player); + 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) { @@ -35,7 +46,7 @@ public partial class Game : Node { } private void HandleEnemyTurns() { - foreach (Actor actor in Map.Actors) { + 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."); diff --git a/scripts/Map.cs b/scripts/Map.cs new file mode 100644 index 0000000..6bdd4a4 --- /dev/null +++ b/scripts/Map.cs @@ -0,0 +1,27 @@ +using Godot; +using System; + +public partial class Map : Node2D +{ + public MapData Map_Data { get; private set; } + + [Export] + public int Height; + [Export] + public int Width; + + private void PlaceTiles() { + foreach (Tile tile in Map_Data.Tiles) { + AddChild(tile); + } + } + + public override void _Ready() + { + base._Ready(); + + Map_Data = new MapData(Width, Height); + + PlaceTiles(); + } +} diff --git a/scripts/Map.cs.uid b/scripts/Map.cs.uid new file mode 100644 index 0000000..7306888 --- /dev/null +++ b/scripts/Map.cs.uid @@ -0,0 +1 @@ +uid://fe2h4is11tnw diff --git a/scripts/actors/Actor.cs b/scripts/actors/Actor.cs index 7e9ab04..a759fef 100644 --- a/scripts/actors/Actor.cs +++ b/scripts/actors/Actor.cs @@ -5,11 +5,11 @@ public abstract partial class Actor : Sprite2D { private ActorDefinition definition; private Vector2I gridPosition = Vector2I.Zero; - public DungeonLevel Map { get; private set; } + public MapData Map_Data { get; private set; } - public Actor(Vector2I initialPosition, DungeonLevel map, ActorDefinition definition) { + public Actor(Vector2I initialPosition, MapData map, ActorDefinition definition) { GridPosition = initialPosition; - Map = map; + Map_Data = map; this.definition = definition; Texture = definition.texture; Centered = false; diff --git a/scripts/actors/Player.cs b/scripts/actors/Player.cs index 590020d..c15db21 100644 --- a/scripts/actors/Player.cs +++ b/scripts/actors/Player.cs @@ -4,7 +4,7 @@ using System; [GlobalClass] public partial class Player : Actor { - public Player(Vector2I initialPosition, DungeonLevel map, ActorDefinition definition) : base(initialPosition, map, definition) + public Player(Vector2I initialPosition, MapData map, ActorDefinition definition) : base(initialPosition, map, definition) { } } diff --git a/scripts/actors/actions/Action.cs b/scripts/actors/actions/Action.cs index 76ae5d5..bb5f6f1 100644 --- a/scripts/actors/actions/Action.cs +++ b/scripts/actors/actions/Action.cs @@ -11,7 +11,7 @@ public abstract partial class Action : RefCounted { public abstract void Perform(); - protected DungeonLevel Map { - get => actor.Map; + protected MapData Map_Data { + get => actor.Map_Data; } } diff --git a/scripts/actors/actions/DirectionalAction.cs b/scripts/actors/actions/DirectionalAction.cs index 077f475..d5199f9 100644 --- a/scripts/actors/actions/DirectionalAction.cs +++ b/scripts/actors/actions/DirectionalAction.cs @@ -10,6 +10,6 @@ public abstract partial class DirectionalAction : Action } protected Actor GetBlockingActorAtPosition(Vector2I pos) { - return Map.GetBlockingActorAtPosition(pos); + return Map_Data.GetBlockingActorAtPosition(pos); } } diff --git a/scripts/actors/actions/MovementAction.cs b/scripts/actors/actions/MovementAction.cs index c9474b0..54bb99c 100644 --- a/scripts/actors/actions/MovementAction.cs +++ b/scripts/actors/actions/MovementAction.cs @@ -11,7 +11,7 @@ public partial class MovementAction : DirectionalAction { Vector2I finalDestination = actor.GridPosition + Offset; - if (!Map.IsTileWalkable(finalDestination)) return; + if (!Map_Data.IsTileWalkable(finalDestination)) return; if (GetBlockingActorAtPosition(finalDestination) != null) return; diff --git a/scripts/map/MapData.cs b/scripts/map/MapData.cs new file mode 100644 index 0000000..25d6e09 --- /dev/null +++ b/scripts/map/MapData.cs @@ -0,0 +1,87 @@ +using Godot; +using System; +using System.Runtime.InteropServices; + +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"); + + public int Width { get; private set; } + public int Height { get; private set; } + + public Godot.Collections.Array<Tile> Tiles { get; private set; } = []; + + public Godot.Collections.Array<Actor> Actors { get; private set; } = []; + + public MapData(int width, int height) { + Width = width; + Height = height; + + SetupTiles(); + } + + private void SetupTiles() { + for (int i = 0; i < Width; i++) + { + for (int j = 0; j < Height; j++) + { + Tile tile; + if (i == 0 || j == 0 || i == (Width - 1) || j == (Height - 1)) { + tile = new Tile(new Vector2I(i, j), wallDefinition); + } else { + tile = new Tile(new Vector2I(i, j), floorDefinition); + } + + Tiles.Add(tile); + } + } + } + + public void InsertActor(Vector2I pos, Actor actor) { + actor.GridPosition = pos; + Actors.Add(actor); + } + + private int GridToIndex(Vector2I pos) { + if (!IsInBounds(pos)) return -1; + + return pos.Y * Width + pos.X; + } + + private bool IsInBounds(Vector2I pos) { + if (pos.X < 0 || pos.Y < 0) { + return false; + } + if (pos.X >= Width || pos.Y >= Height) { + return false; + } + + return true; + } + + public Tile GetTile(Vector2I pos) { + int index = GridToIndex(pos); + + if (index < 0) return null; + + return Tiles[index]; + } + + public Actor GetBlockingActorAtPosition(Vector2I pos) { + foreach (Actor actor in Actors) { + if (actor.GridPosition == pos && actor.BlocksMovement) { + return actor; + } + } + return null; + } + + public bool IsTileWalkable(Vector2I pos) { + Tile tile = GetTile(pos); + + if (tile == null) return false; + + return tile.IsWalkable; + } +} diff --git a/scripts/map/MapData.cs.uid b/scripts/map/MapData.cs.uid new file mode 100644 index 0000000..6c226e7 --- /dev/null +++ b/scripts/map/MapData.cs.uid @@ -0,0 +1 @@ +uid://0vbcl1etfcbg diff --git a/scripts/map/Tile.cs b/scripts/map/Tile.cs new file mode 100644 index 0000000..c910b01 --- /dev/null +++ b/scripts/map/Tile.cs @@ -0,0 +1,22 @@ +using Godot; +using System; + +public partial class Tile : Sprite2D +{ + private TileDefinition definition; + + public bool IsWalkable { get; set; } + + public Tile(Vector2I pos, TileDefinition definition) + { + Centered = false; + Position = Grid.GridToWorld(pos); + SetDefinition(definition); + } + + public void SetDefinition(TileDefinition definition) { + this.definition = definition; + Texture = definition.Texture; + this.IsWalkable = definition.IsWalkable; + } +} diff --git a/scripts/map/Tile.cs.uid b/scripts/map/Tile.cs.uid new file mode 100644 index 0000000..9fa3c81 --- /dev/null +++ b/scripts/map/Tile.cs.uid @@ -0,0 +1 @@ +uid://b2dkecc01tqc0 diff --git a/scripts/map/TileDefinition.cs b/scripts/map/TileDefinition.cs new file mode 100644 index 0000000..548fda7 --- /dev/null +++ b/scripts/map/TileDefinition.cs @@ -0,0 +1,14 @@ +using Godot; +using System; + +[GlobalClass] +public partial class TileDefinition : Resource +{ + [ExportCategory("Visuals")] + [Export] + public Texture2D Texture { get; set; } + + [ExportCategory("Mechanics")] + [Export] + public bool IsWalkable { get; set; } +} diff --git a/scripts/map/TileDefinition.cs.uid b/scripts/map/TileDefinition.cs.uid new file mode 100644 index 0000000..14f2903 --- /dev/null +++ b/scripts/map/TileDefinition.cs.uid @@ -0,0 +1 @@ +uid://ba82a33ov6uuo |
