Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions Modules/GameManagers/Scripts/TilesManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using DungeonRoyale.Modules.Tiles.Scripts;

namespace DungeonRoyale.Modules.GameManagers.Scripts;

public partial class TilesManager : Node2D
{
public static TilesManager? Instance { get; private set; }

public DRTileData[,] Tiles { get; private set; } = new DRTileData[0, 0];

private int _width;
private int _height;

public override void _Ready()
{
if (Instance is null)
{
Instance = this;
}
else
{
GD.PrintErr("There is already an instance of TilesManager in the scene.");
}
}


public void SetUpTiles(int width, int height)
{
_width = width;
_height = height;

Tiles = new DRTileData[_width, _height];

for (int x = 0; x < _width; x++)
{
for (int y = 0; y < _height; y++)
{
Tiles[x, y] = new DRTileData(x, y, true, false);
}
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool IsOutOfMapBounds(int x, int y) =>
x < 0 || x >= _width || y < 0 || y >= _height;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public DRTileData? GetTileAt(int x, int y) =>
IsOutOfMapBounds(x, y) ? null : Tiles[x, y];

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryGetTileAt(int x, int y, [NotNullWhen(returnValue: true)] out DRTileData? tileData) =>
(tileData = GetTileAt(x, y)) is not null;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryGetTileAt((int x, int y) position, [NotNullWhen(returnValue: true)] out DRTileData? tileData) =>
TryGetTileAt(position.x, position.y, out tileData);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryGetTileAt(Vector2I position, [NotNullWhen(returnValue: true)] out DRTileData? tileData) =>
TryGetTileAt(position.X, position.Y, out tileData);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryGetTileAtGlobalCoords(Vector2 position, [NotNullWhen(returnValue: true)] out DRTileData? tileData) =>
(tileData = GetTileAt((int) position.X / TileConstants.TILE_SIZE, (int) position.Y / TileConstants.TILE_SIZE)) is not null;
}
1 change: 1 addition & 0 deletions Modules/GameManagers/Scripts/TilesManager.cs.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bmr66sr26pdab
4 changes: 2 additions & 2 deletions Modules/Player/Scenes/player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

[ext_resource type="Script" uid="uid://de61d5m60vonw" path="res://Modules/Player/Scripts/Player.cs" id="1_d6hpj"]
[ext_resource type="Texture2D" uid="uid://brmg31ce6noqj" path="res://Modules/Player/Textures/d_idle.png" id="2_4itp8"]
[ext_resource type="Texture2D" uid="uid://du7cgbk1wqk0g" path="res://Modules/Player/Textures/Idle.png" id="2_eeunm"]
[ext_resource type="Texture2D" uid="uid://jf1knh77qpy2" path="res://Modules/Player/Textures/u_idle.png" id="2_eeunm"]
[ext_resource type="Texture2D" uid="uid://bu3wecbmouixt" path="res://Modules/Player/Textures/d_walk.png" id="2_i873j"]
[ext_resource type="Texture2D" uid="uid://c31cs04ddln8k" path="res://Modules/Player/Textures/s_walk.png" id="3_bxhrv"]
[ext_resource type="Texture2D" uid="uid://dpu3tffj8in05" path="res://Modules/Player/Textures/walk.png" id="3_umw3d"]
[ext_resource type="Texture2D" uid="uid://bu8810dpn686q" path="res://Modules/Player/Textures/u_walk.png" id="3_umw3d"]
[ext_resource type="Texture2D" uid="uid://dyoql8jmirecv" path="res://Modules/Player/Textures/s_idle.png" id="4_5c0ey"]

[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_d6hpj"]
Expand Down
23 changes: 23 additions & 0 deletions Modules/Tiles/Scripts/DRTileData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace DungeonRoyale.Modules.Tiles.Scripts;

public partial class DRTileData
{
public int X { get; private set; }
public int Y { get; private set; }

public bool IsWalkable { get; private set; }

public bool IsSpawnPoint { get; private set; }

public DRTileData()
{
}

public DRTileData(int x, int y, bool isWalkable, bool isSpawnPoint)
{
X = x;
Y = y;
IsWalkable = isWalkable;
IsSpawnPoint = isSpawnPoint;
}
}
1 change: 1 addition & 0 deletions Modules/Tiles/Scripts/DRTileData.cs.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://d0s8c7afp4vgy
6 changes: 6 additions & 0 deletions Shared/Scripts/TilesConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace DungeonRoyale.Shared.Scripts;

public static class TileConstants
{
public const int TILE_SIZE = 16;
}
1 change: 1 addition & 0 deletions Shared/Scripts/TilesConstants.cs.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://1v5312025i62
4 changes: 4 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ run/main_scene="res://Modules/Game/Scenes/Game.tscn"
config/features=PackedStringArray("4.4", "C#", "GL Compatibility")
config/icon="res://icon.svg"

[autoload]

TilesManager="*res://Modules/GameManagers/Scripts/TilesManager.cs"

[dotnet]

project/assembly_name="DungeonRoyale"
Expand Down
Loading