Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
66 changes: 66 additions & 0 deletions Modules/GameManagers/Scripts/TilesManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using DungeonRoyale.Modules.Tiles.Scripts;
using DungeonRoyale.Shared.Scripts.Constants;

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)
{
if (width <= 0 || height <= 0)
{
throw new ArgumentException("Width and height must be greater than 0.");
}

_width = width;
_height = height;

Tiles = new DRTileData[_width, _height];
}

[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
2 changes: 2 additions & 0 deletions Modules/Player/Scripts/Player.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using DungeonRoyale.Shared.Scripts.Constants;

namespace DungeonRoyale.Modules.Player.Scripts;

public partial class Player : CharacterBody2D
{
[Export] private float MovementSpeed { get; set; } = 200.0f;
private AnimatedSprite2D _animatedSprite;

Check warning on line 8 in Modules/Player/Scripts/Player.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_animatedSprite' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 8 in Modules/Player/Scripts/Player.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_animatedSprite' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
private Direction _currentDirection = Direction.South;

private const float DIRECTION_THRESHOLD = 0.1f;
Expand Down
21 changes: 21 additions & 0 deletions Modules/Tiles/Scripts/DRTileData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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)
{
X = x;
Y = y;
}
}
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DungeonRoyale.Shared.Scripts;
namespace DungeonRoyale.Shared.Scripts.Constants;

public static class MappedInputs
{
Expand Down
6 changes: 6 additions & 0 deletions Shared/Scripts/Constants/TilesConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace DungeonRoyale.Shared.Scripts.Constants;

public static class TileConstants
{
public const int TILE_SIZE = 16;
}
1 change: 1 addition & 0 deletions Shared/Scripts/Constants/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