Skip to content

Commit 9f3609e

Browse files
Merge pull request #8 from Coding-in-community/feat/adicionar-escaneamento-de-mapa
feat: adicionado classes iniciais de jogo que utilizara a classe mapsc…
2 parents 1bd23f2 + 6176254 commit 9f3609e

File tree

16 files changed

+210
-18
lines changed

16 files changed

+210
-18
lines changed

GlobalUsings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
global using Godot;
2-
global using DungeonRoyale.Shared.Scripts;
2+
global using DungeonRoyale.Shared.Scripts.Extensions;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://cslplb3s5se2m"]
2+
3+
[ext_resource type="Script" uid="uid://c2q15i1u3gl3y" path="res://Modules/Map/Scripts/MapSettingsResource.cs" id="1_bcgwb"]
4+
5+
[resource]
6+
script = ExtResource("1_bcgwb")
7+
Width = 1500
8+
Height = 1500

Modules/Game/Scenes/Game.tscn

Lines changed: 29 additions & 11 deletions
Large diffs are not rendered by default.

Modules/Game/Scripts/Game.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using DungeonRoyale.Modules.GameManagers.Scripts;
2+
using DungeonRoyale.Modules.Map.Scripts;
3+
4+
namespace DungeonRoyale.Modules.Game.Scripts;
5+
6+
public partial class Game : Node2D
7+
{
8+
private static TilesManager _tilesManager => TilesManager.Instance!;
9+
10+
[Export] public MapSettingsResource MapSettings { get; private set; } = new MapSettingsResource();
11+
12+
private bool MapIsLoading { get; set; } = true;
13+
14+
public override void _Ready()
15+
{
16+
_tilesManager.SetUpTiles(MapSettings.Width, MapSettings.Height);
17+
18+
if (FindChild(nameof(MapScanner), true) is not MapScanner mapScanner)
19+
{
20+
GD.PrintErr("MapScanner node not found.");
21+
return;
22+
}
23+
24+
mapScanner.MapScanned += OnMapScanned;
25+
mapScanner.Scan(MapSettings.Width, MapSettings.Height);
26+
}
27+
28+
public void OnMapScanned()
29+
{
30+
MapIsLoading = false;
31+
32+
// Do something with the scanned map
33+
}
34+
35+
public void OnMapGenerated()
36+
{
37+
MapIsLoading = false;
38+
39+
// Do something with the generated map
40+
}
41+
}

Modules/Game/Scripts/Game.cs.uid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://doeo50prutum0
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace DungeonRoyale.Modules.GameManagers.Scripts;
2+
3+
public partial class TileMapManager : Node2D
4+
{
5+
public static TileMapManager? Instance { get; private set; }
6+
7+
public TileMapLayer GroundTileMap { get; private set; } = null!;
8+
public TileMapLayer SpawnTileMap { get; private set; } = null!;
9+
10+
public override void _Ready()
11+
{
12+
if (Instance is null)
13+
{
14+
Instance = this;
15+
}
16+
else
17+
{
18+
GD.PrintErr("There is already an instance of TileMapManager in the scene.");
19+
}
20+
21+
if (GetTree().CurrentScene.FindChild(nameof(GroundTileMap), true) is not TileMapLayer groundTileMap)
22+
{
23+
GD.PrintErr("GroundTileMap node not found.");
24+
return;
25+
}
26+
27+
if (GetTree().CurrentScene.FindChild(nameof(SpawnTileMap), true) is not TileMapLayer spawnTileMap)
28+
{
29+
GD.PrintErr("SpawnTileMap node not found.");
30+
return;
31+
}
32+
33+
GroundTileMap = groundTileMap;
34+
SpawnTileMap = spawnTileMap;
35+
}
36+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://bt46ejg3cyafl

Modules/GameManagers/Scripts/TilesManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ public void SetUpTiles(int width, int height)
3838
_height = height;
3939

4040
Tiles = new DRTileData[_width, _height];
41+
42+
for (int x = 0; x < _width; x++)
43+
for (int y = 0; y < _height; y++)
44+
{
45+
Tiles[x, y] = new DRTileData(x, y);
46+
}
4147
}
4248

4349
[MethodImpl(MethodImplOptions.AggressiveInlining)]

Modules/Map/Scripts/MapScanner.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using DungeonRoyale.Modules.GameManagers.Scripts;
2+
3+
namespace DungeonRoyale.Modules.Map.Scripts;
4+
5+
public partial class MapScanner : Node2D
6+
{
7+
private TileMapManager _tileMapManager => TileMapManager.Instance!;
8+
private TilesManager _tilesManager => TilesManager.Instance!;
9+
10+
[Signal] public delegate void MapScannedEventHandler();
11+
12+
public void Scan(int width, int height)
13+
{
14+
GD.Print("Scanning map...");
15+
for (int x = 0; x < width; x++)
16+
for (int y = 0; y < height; y++)
17+
{
18+
var groundTile = _tileMapManager.GroundTileMap.GetCellTileData(new Vector2I(x, y));
19+
20+
if (groundTile is null)
21+
continue;
22+
23+
if (!_tilesManager.TryGetTileAt(x, y, out var tileData))
24+
continue;
25+
26+
tileData.IsWalkable = groundTile.GetCustomData("IsWalkable").AsBool();
27+
28+
var spawnTile = _tileMapManager.SpawnTileMap.GetCellTileData(new Vector2I(x, y));
29+
30+
if (spawnTile is null)
31+
continue;
32+
33+
tileData.IsSpawnPoint = true;
34+
}
35+
36+
GD.Print("Map scanned.");
37+
EmitSignal(SignalName.MapScanned);
38+
}
39+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://di6j7dxqlb03e

0 commit comments

Comments
 (0)