-
Notifications
You must be signed in to change notification settings - Fork 2
Feat/adicionar tile data e tile manager #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
17543ca
wip: adicionado drtiledata e tiles manager iniciais
LeonardoCruzx 9984d2e
fix: corrigido caminhos para as texturas do player quebrado
LeonardoCruzx 16526ec
feat: foi adicionado isspawnpoint aos dados do bloco
LeonardoCruzx cb8980c
feat: tiles manager foi adaptado para se tornar um singleton e tambem…
LeonardoCruzx 3c8bfe0
adjust: tile constants foi movido para uma pasta de constantes e foi …
LeonardoCruzx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uid://bmr66sr26pdab |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uid://d0s8c7afp4vgy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uid://1v5312025i62 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.