From c6bbb834f7758027c0df338f1520f34fad3befea Mon Sep 17 00:00:00 2001 From: Matheus Date: Tue, 9 Sep 2025 19:09:34 -0300 Subject: Organização MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/map/DungeonGenerator.cs | 272 ------------------------------------ scripts/map/DungeonGenerator.cs.uid | 1 - scripts/map/FieldOfView.cs | 96 ------------- scripts/map/FieldOfView.cs.uid | 1 - scripts/map/Map.cs | 86 ------------ scripts/map/Map.cs.uid | 1 - scripts/map/MapData.cs | 272 ------------------------------------ scripts/map/MapData.cs.uid | 1 - scripts/map/MapDivision.cs | 98 ------------- scripts/map/MapDivision.cs.uid | 1 - scripts/map/Tile.cs | 81 ----------- scripts/map/Tile.cs.uid | 1 - scripts/map/TileDefinition.cs | 22 --- scripts/map/TileDefinition.cs.uid | 1 - 14 files changed, 934 deletions(-) delete mode 100644 scripts/map/DungeonGenerator.cs delete mode 100644 scripts/map/DungeonGenerator.cs.uid delete mode 100644 scripts/map/FieldOfView.cs delete mode 100644 scripts/map/FieldOfView.cs.uid delete mode 100644 scripts/map/Map.cs delete mode 100644 scripts/map/Map.cs.uid delete mode 100644 scripts/map/MapData.cs delete mode 100644 scripts/map/MapData.cs.uid delete mode 100644 scripts/map/MapDivision.cs delete mode 100644 scripts/map/MapDivision.cs.uid delete mode 100644 scripts/map/Tile.cs delete mode 100644 scripts/map/Tile.cs.uid delete mode 100644 scripts/map/TileDefinition.cs delete mode 100644 scripts/map/TileDefinition.cs.uid (limited to 'scripts/map') diff --git a/scripts/map/DungeonGenerator.cs b/scripts/map/DungeonGenerator.cs deleted file mode 100644 index cb89508..0000000 --- a/scripts/map/DungeonGenerator.cs +++ /dev/null @@ -1,272 +0,0 @@ -using Godot; - -/// -/// A classe dungeonGenerator cria exatamente um andar da masmorra. -/// Ela é chamada quando necessário. -/// -public partial class DungeonGenerator : Node -{ - /// - /// Coleção de todos os inimigos que o gerador tem acesso. - /// - private static readonly Godot.Collections.Array enemies = [ - GD.Load("res://assets/definitions/actor/Skeleton.tres"), - GD.Load("res://assets/definitions/actor/morcegao.tres"), - GD.Load("res://assets/definitions/actor/Shadow.tres"), - ]; - - private static readonly Godot.Collections.Array items = [ - GD.Load("res://assets/definitions/Items/small_healing_potion.tres") - ]; - - /// - /// Dimensões do mapa a ser criado. - /// - [ExportCategory("Dimension")] - [Export] - private int width = 80; - [Export] - private int height = 60; - - /// - /// Gerador de números aleatórios - /// - [ExportCategory("RNG")] - private RandomNumberGenerator rng = new(); - /// - /// Qual seed utilizar. - /// - [Export] - private ulong seed; - /// - /// Se será utilizada a nossa seed ou a seed padrão da classe RandomNumberGenerator. - /// - [Export] - private bool useSeed = true; - /// - /// Quantas iterações do algoritmo chamar. - /// - [Export] - private int iterations = 3; - - /// - /// Quantidade máxima de inimigos por sala. - /// - [ExportCategory("Monster RNG")] - [Export] - private int maxMonsterPerRoom = 2; - - /// - /// Quantidade máxima de itens por sala. - /// - [ExportCategory("Loot RNG")] - [Export] - private int maxItemsPerRoom = 2; - - public override void _Ready() - { - base._Ready(); - if (useSeed) { - rng.Seed = seed; - } - } - - /// - /// Transforma o tile da posição especificada em chão. - /// - /// o mapa - /// posição para colocar o chão. - private static void CarveTile(MapData data, Vector2I pos) - { - Tile tile = data.GetTile(pos); - if (tile == null) return; - - tile.SetDefinition(MapData.floorDefinition); - } - - /// - /// Preenche uma área retangular com chão. - /// - /// O mapa - /// Área para preencher com chão - private static void CarveRoom(MapData data, Rect2I room) - { - for (int y = room.Position.Y; y < room.End.Y; y++) - { - for (int x = room.Position.X; x < room.End.X; x++) - { - CarveTile(data, new Vector2I(x, y)); - } - } - } - - /// - /// Gera um andar da masmorra. - /// Inimigos são colocados conforme configurações. - /// O jogador é colocado na primeira sala gerada. - /// - /// Jogador. - /// O mapa gerado. - public MapData GenerateDungeon(Player player) - { - MapData data = new MapData(width, height, player); - - // Divisão mestre que engloba o mapa inteiro. - MapDivision root = new MapDivision(0, 0, width, height); - - // Chama o algoritmo para dividir o mapa. - root.Split(iterations, rng); - - bool first = true; - - // Coloca os corredores. - TunnelDivisions(data, root); - - // Cria as salas com base nas divisões geradas. - foreach(MapDivision division in root.GetLeaves()) - { - Rect2I room = new(division.Position, division.Size); - - // A sala não pode oculpar a divisão inteira, senão não haveriam paredes. - room = room.GrowIndividual( - -rng.RandiRange(1, 2), - -rng.RandiRange(1, 2), - -rng.RandiRange(1, 2), - -rng.RandiRange(1, 2) - ); - - // De fato cria a sala. - CarveRoom(data, room); - // Colocamos o jogador na primeira sala. - if (first) - { - first = false; - player.GridPosition = room.GetCenter(); - } - // Colocamos os inimigos na sala. - PlaceEntities(data, room); - } - - // Feito o mapa, inicializamos o algoritmo de pathfinding. - data.SetupPathfinding(); - return data; - } - - /// - /// Popula uma sala com inimigos. - /// - /// O mapa - /// A sala. - private void PlaceEntities(MapData data, Rect2I room) { - // Define quantos monstros serão colocados na sala - int monsterAmount = rng.RandiRange(0, maxMonsterPerRoom); - // Define quantos itens serão colocados na sala. - int itemAmount = rng.RandiRange(0, maxItemsPerRoom); - - for (int i = 0; i < monsterAmount; i++) { - // Escolhe um lugar aleatório na sala. - Vector2I position = new( - rng.RandiRange(room.Position.X, room.End.X - 1), - rng.RandiRange(room.Position.Y, room.End.Y - 1) - ); - - // Só podemos colocar um ator por ponto no espaço. - bool canPlace = true; - foreach (Entity entity in data.Entities) { - if (entity.GridPosition == position) { - canPlace = false; - break; - } - } - - // Se possível, criamos um inimigo aleatório na posição escolhida. - if (canPlace) { - EnemyDefinition definition = enemies.PickRandom(); - Enemy enemy = new(position, data, definition); - data.InsertEntity(enemy); - } - } - - for (int i = 0; i < itemAmount; i++) { - // Escolhe um lugar aleatório na sala. - Vector2I position = new( - rng.RandiRange(room.Position.X, room.End.X - 1), - rng.RandiRange(room.Position.Y, room.End.Y - 1) - ); - - // Só podemos colocar um ator por ponto no espaço. - bool canPlace = true; - foreach (Entity entity in data.Entities) { - if (entity.GridPosition == position) { - canPlace = false; - break; - } - } - - // Se possível, criamos um inimigo aleatório na posição escolhida. - if (canPlace) { - ConsumableItemDefinition definition = items.PickRandom(); - if (definition is HealingConsumableDefinition hcDefinition) { - HealingConsumable item = new(position, data, hcDefinition); - data.InsertEntity(item); - } - } - } - } - - /// - /// Preenche uma linha horizontal com chão. - /// - /// O mapa - /// Eixo y do corredor. - /// Início do corredor - /// Final do corredor. - private static void HorizontalCorridor(MapData data, int y, int xBegin, int xEnd) { - int begin = (xBegin < xEnd) ? xBegin : xEnd; - int end = (xEnd > xBegin) ? xEnd : xBegin; - for (int i = begin; i <= end; i++) { - CarveTile(data, new Vector2I(i, y)); - } - } - - /// - /// Preenche uma linha vertical com chão. - /// - /// O mapa. - /// Eixo x do corredor. - /// Início do corredor - /// Final do corredor. - private static void VerticalCorridor(MapData data, int x, int yBegin, int yEnd) { - int begin = (yBegin < yEnd) ? yBegin : yEnd; - int end = (yEnd > yBegin) ? yEnd : yBegin; - for (int i = begin; i <= end; i++) { - CarveTile(data, new Vector2I(x, i)); - } - } - - /// - /// Cria corredores vertical e horizontal para unir dois pontos no mapa. - /// - /// O mapa - /// Ponto inicial - /// Ponto final. - private static void TunnelBetween(MapData data, Vector2I start, Vector2I end) { - HorizontalCorridor(data, start.Y, start.X, end.X); - VerticalCorridor(data, end.X, start.Y, end.Y); - } - - /// - /// Cria recursivamente corredores entre o centro de cada divisão do mapa. - /// - /// O mapa - /// Divisão mestre. - private static void TunnelDivisions(MapData data, MapDivision root) { - if (root.IsLeaf) { - return; - } - - TunnelBetween(data, root.Right.Center, root.Left.Center); - TunnelDivisions(data, root.Left); - TunnelDivisions(data, root.Right); - } -} diff --git a/scripts/map/DungeonGenerator.cs.uid b/scripts/map/DungeonGenerator.cs.uid deleted file mode 100644 index 15aeef6..0000000 --- a/scripts/map/DungeonGenerator.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://dwyr067lwqcsj diff --git a/scripts/map/FieldOfView.cs b/scripts/map/FieldOfView.cs deleted file mode 100644 index bdcd206..0000000 --- a/scripts/map/FieldOfView.cs +++ /dev/null @@ -1,96 +0,0 @@ -using Godot; - -// Copiado e adaptado deste cara aqui: https://www.roguebasin.com/index.php?title=C%2B%2B_shadowcasting_implementation e deste também https://selinadev.github.io/08-rogueliketutorial-04/ - -// Eu não vou mentir, li como o algoritmo funciona, mas mesmo assim não entendi. - -public partial class FieldOfView : Node { - - private Godot.Collections.Array fov = []; - - private static int[,] multipliers = new int[4,8]{ - {1, 0, 0, -1, -1, 0, 0, 1}, - {0, 1, -1, 0, 0, -1, 1, 0}, - {0, 1, 1, 0, 0, -1, -1, 0}, - {1, 0, 0, 1, -1, 0, 0, -1} - }; - private void CastLight(MapData data, Vector2I pos, int radius, int row, float startSlope, float endSlope, int xx, int xy, int yx, int yy) { - if (startSlope < endSlope) { - return; - } - - float nextStartSlope = startSlope; - for (int i = row; i <= radius; i++) - { - bool blocked = false; - for (int dx = -i, dy = -i; dx <= 0; dx++) - { - float lSlope = (float)((dx - 0.5) / (dy + 0.5)); - float rSlope = (float)((dx + 0.5) / (dy - 0.5)); - - if (startSlope < rSlope) - { - continue; - } - else if (endSlope > lSlope) - { - break; - } - - int sax = dx * xx + dy * xy; - int say = dx * yx + dy * yy; - - if ((sax < 0 && int.Abs(sax) > pos.X) || (say < 0 && int.Abs(say) > pos.Y)) { - continue; - } - int ax = pos.X + sax; - int ay = pos.Y + say; - - if (ax >= data.Width || ay >= data.Height) { - continue; - } - - Tile currentTile = data.GetTile(ax, ay); - int radius2 = radius * radius; - if ((dx * dx + dy * dy) < radius2) { - currentTile.IsInView = true; - fov.Add(currentTile); - } - - if (blocked) { - if (!currentTile.IsTransparent) { - nextStartSlope = rSlope; - continue; - } else { - blocked = false; - startSlope = nextStartSlope; - } - } else if (!currentTile.IsTransparent) { - blocked = true; - nextStartSlope = rSlope; - CastLight(data, pos, radius, i + 1, startSlope, lSlope, xx, xy, yx, yy); - } - } - if (blocked) { - break; - } - } - } - - private void ClearFOV() { - foreach (Tile tile in fov) { - tile.IsInView = false; - } - fov.Clear(); - } - - public void UpdateFOV(MapData data, Vector2I position, int radius) { - ClearFOV(); - Tile start = data.GetTile(position); - start.IsInView = true; - fov.Add(start); - for (int i = 0; i < 8; i++) { - CastLight(data, position, radius, 1, 1.0f, 0.0f, multipliers[0, i], multipliers[1, i], multipliers[2, i], multipliers[3, i]); - } - } -} diff --git a/scripts/map/FieldOfView.cs.uid b/scripts/map/FieldOfView.cs.uid deleted file mode 100644 index a173ff3..0000000 --- a/scripts/map/FieldOfView.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://bereyrj1s46y5 diff --git a/scripts/map/Map.cs b/scripts/map/Map.cs deleted file mode 100644 index 148bda6..0000000 --- a/scripts/map/Map.cs +++ /dev/null @@ -1,86 +0,0 @@ -using Godot; - -/// -/// A parte visual do mapa. -/// -public partial class Map : Node2D -{ - /// - /// Dados do mapa. - /// - public MapData Map_Data { get; private set; } - - /// - /// raio de alcance da visão do jogador. - /// - [Export] - private int fovRadius = 12; - - /// - /// Gerador de mapas. - /// - private DungeonGenerator generator; - - FieldOfView fieldOfView; - - private Node2D tilesNode; - private Node2D entitiesNode; - - public override void _Ready() - { - base._Ready(); - // Começamos obtendo nós relevantes para o mapa. - generator = GetNode("Generator"); - fieldOfView = GetNode("FieldOfView"); - tilesNode = GetNode("Tiles"); - entitiesNode = GetNode("Entities"); - } - - /// - /// Coloca todos os tiles do mapa no mundo do jogo. - /// - private void PlaceTiles() { - foreach (Tile tile in Map_Data.Tiles) { - tilesNode.AddChild(tile); - } - } - - /// - /// Coloca todas as entidades do mapa no mundo do jogo. - /// - private void PlaceEntities() { - foreach (Entity entity in Map_Data.Entities) { - entitiesNode.AddChild(entity); - } - } - - /// - /// Cria um andar da masmorra utilizando o gerador de mapa. - /// - /// O gerador de mapas precisa do jogador. - public void Generate(Player player) - { - Map_Data = generator.GenerateDungeon(player); - - Map_Data.EntityPlaced += OnEntityPlaced; - - PlaceTiles(); - PlaceEntities(); - } - - /// - /// Atualiza o campo de visão do mapa com base em uma coordenada. - /// - /// Centro de visão, normalmente é a posição do jogador. - public void UpdateFOV(Vector2I pos) { - fieldOfView.UpdateFOV(Map_Data, pos, fovRadius); - // Esconde ou revela entidades com base no campo de visão. - foreach (Entity entity in Map_Data.Entities) { - entity.Visible = Map_Data.GetTile(entity.GridPosition).IsInView; - } - } - - private void OnEntityPlaced(Entity entity) { - entitiesNode.AddChild(entity); - } -} diff --git a/scripts/map/Map.cs.uid b/scripts/map/Map.cs.uid deleted file mode 100644 index 7306888..0000000 --- a/scripts/map/Map.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://fe2h4is11tnw diff --git a/scripts/map/MapData.cs b/scripts/map/MapData.cs deleted file mode 100644 index f3e193e..0000000 --- a/scripts/map/MapData.cs +++ /dev/null @@ -1,272 +0,0 @@ -using Godot; - -/// -/// Classe que cuida dos dados e da parte lógica do mapa. -/// O mapa é o cenário onde as ações do jogo ocorrem. -/// Mais especificamente, o mapa é um único andar da masmorra. -/// -public partial class MapData : RefCounted -{ - public static readonly TileDefinition wallDefinition = GD.Load("res://assets/definitions/tiles/wall.tres"); - public static readonly TileDefinition floorDefinition = GD.Load("res://assets/definitions/tiles/floor.tres"); - - [Signal] - public delegate void EntityPlacedEventHandler(Entity entity); - - /// - /// Largura do mapa. - /// - public int Width { get; private set; } - /// - /// Altura do mapa. - /// - public int Height { get; private set; } - - /// - /// Os tiles que compõem o mapa. - /// - public Godot.Collections.Array Tiles { get; private set; } = []; - - /// - /// O jogador é especial e por isso o mapa faz questão de rastreá-lo. - /// - public Player Player { get; set; } - /// - /// Lista de todos os atores dentro do mapa. - /// - public Godot.Collections.Array Entities { get; private set; } = []; - - public Godot.Collections.Array Items { - get { - Godot.Collections.Array list = []; - foreach (Entity entity in Entities) { - if (entity is ConsumableItem item) { - list.Add(item); - } - } - return list; - } - } - - private AStarGrid2D pathfinder; - /// - /// Objeto do Godot que utiliza do algoritmo A* para calcular - /// caminhos e rotas. - /// - public AStarGrid2D Pathfinder { get => pathfinder; } - /// - /// Peso do ator no pathfinder. - /// A IA irá evitar de passar por espaços com peso alto. - /// - private static readonly float EntityWeight = 10.0f; - - /// - /// Inicializa o pathfinder; - /// - public void SetupPathfinding() { - pathfinder = new AStarGrid2D - { - //A região é o mapa inteiro. - Region = new Rect2I(0, 0, Width, Height) - }; - - // Atualiza o pathfinder para a região definida. - pathfinder.Update(); - - // Define quais pontos do mapa são passáveis ou não. - for (int y = 0; y < Height; y++) { - for (int x = 0; x < Width; x++) { - Vector2I pos = new Vector2I(x, y); - Tile tile = GetTile(pos); - // Pontos sólidos são impossíveis de passar. - pathfinder.SetPointSolid(pos, !tile.IsWalkable); - } - } - - // Registra todos os atores em cena. - foreach (Entity entity in Entities) { - if (entity.BlocksMovement) { - RegisterBlockingEntity(entity); - } - } - - } - - /// - /// Define um peso na posição de uma entidade para que a IA evite de passar por lá. - /// Ênfase em evitar. Se o único caminho para o destino estiver bloqueado - /// por uma entidade, o jogo tentará andar mesmo assim. - /// - /// A entidade em questão. - public void RegisterBlockingEntity(Entity entity) { - pathfinder.SetPointWeightScale(entity.GridPosition, EntityWeight); - } - - /// - /// Remove o peso na posição de uma entidade. - /// Quando uma entidade move sua posição, devemos tirar o peso de sua posição anterior. - /// - /// A entidade em questão. - public void UnregisterBlockingEntity(Entity entity) { - pathfinder.SetPointWeightScale(entity.GridPosition, 0); - } - - public MapData(int width, int height, Player player) { - Width = width; - Height = height; - - Player = player; - // Como o jogador é criado antes do mapa, precisamos - // atualizá-lo com o novo mapa. - player.Map_Data = this; - InsertEntity(player); - - SetupTiles(); - } - - /// - /// Cria novos Tiles até preencher as dimensões do mapa. - /// É importante que estes tiles sejam paredes, o gerador de mapas - /// não cria paredes por conta própria. - /// - private void SetupTiles() { - for (int i = 0; i < Height; i++) - { - for (int j = 0; j < Width; j++) - { - Tiles.Add(new Tile(new Vector2I(j, i), wallDefinition)); - } - } - } - - /// - /// Registra uma entidade no mapa. A existência de uma entidade não é considerada se ela não - /// estiver registrada no mapa. - /// - /// A entidade em questão - public void InsertEntity(Entity entity) { - Entities.Add(entity); - } - - /// - /// Converte uma coordenada em um índice para acessar a lista de tiles. - /// - /// Vetor posição - /// Índice na lista de tiles. -1 se estiver fora do mapa. - private int GridToIndex(Vector2I pos) { - if (!IsInBounds(pos)) return -1; - - return pos.Y * Width + pos.X; - } - - /// - /// Se uma coordenada está dentro da área do mapa. - /// - /// Vetor posição - /// Se o vetor está dentro do mapa. - 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; - } - - /// - /// Obtém o tile na posição desejada. - /// - /// Vetor posição - /// O tile na posição, nulo se for fora do mapa. - public Tile GetTile(Vector2I pos) { - int index = GridToIndex(pos); - - if (index < 0) return null; - - return Tiles[index]; - } - - /// - /// Obtém o tile na posição desejada. - /// - /// x da coordenada - /// y da coordenada - /// O tile na posição, nulo se for fora do mapa. - public Tile GetTile(int x, int y) { - return GetTile(new Vector2I(x, y)); - } - - /// - /// Obtém a entidade na posição especificada. - /// - /// Vetor posição - /// A entidade na posição especificada, nulo se não houver. - public Entity GetBlockingEntityAtPosition(Vector2I pos) { - foreach (Entity entity in Entities) { - if (entity.GridPosition == pos && entity.BlocksMovement) { - return entity; - } - } - return null; - } - - /// - /// Obtém o primeiro item na posição especificada. - /// - /// Posição - /// O primeiro item na posição, nulo se não houver. - public ConsumableItem GetFirstItemAtPosition(Vector2I pos) { - foreach (ConsumableItem item in Items) { - if (item.GridPosition == pos) { - return item; - } - } - - return null; - } - - /// - /// Remove uma entidade do mapa sem dar free. - /// - /// A entidade para remover - public void RemoveEntity(Entity entity) { - // Eu removo a entidade do nó de entidades. - entity.GetParent().RemoveChild(entity); - // Eu removo a entidade da lista de entidades do mapa. - Entities.Remove(entity); - } - - /// - /// Obtém todas as entidades na posição especificada. - /// É possível haver mais de uma entidade na mesma posição se uma delas não bloquear movimento. - /// - /// Vetor posição - /// Lista com todas as entidades na posição especificada. - public Godot.Collections.Array GetEntitiesAtPosition(Vector2I pos) { - Godot.Collections.Array ZOfZero = []; - Godot.Collections.Array ZOfOne = []; - Godot.Collections.Array ZOfTwo = []; - - // Pego todos os atores - foreach (Entity entity in Entities) { - if (entity.GridPosition == pos) { - switch (entity.ZIndex) { - case 0: - ZOfZero.Add(entity); - break; - case 1: - ZOfOne.Add(entity); - break; - case 2: - ZOfTwo.Add(entity); - break; - } - } - } - - // Retorno os atores ordenados por ZIndex. - return ZOfZero + ZOfOne + ZOfTwo; - } -} diff --git a/scripts/map/MapData.cs.uid b/scripts/map/MapData.cs.uid deleted file mode 100644 index 6c226e7..0000000 --- a/scripts/map/MapData.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://0vbcl1etfcbg diff --git a/scripts/map/MapDivision.cs b/scripts/map/MapDivision.cs deleted file mode 100644 index 3273775..0000000 --- a/scripts/map/MapDivision.cs +++ /dev/null @@ -1,98 +0,0 @@ -using Godot; - -/// -/// Classe utilizada pelo gerador de mapas. -/// Uma divisão é uma região retangular de espaço que pode -/// conter dentro de si duas regiões menores *ou* uma sala. -/// Uma divisão é uma árvore binária que possui espaço para salas em suas folhas. -/// -public partial class MapDivision : RefCounted { - /// - /// Região retangular da divisão. - /// - public Vector2I Position { get; set; } - public Vector2I Size { get; set; } - - public Vector2I Center { - get => new(Position.X + Size.X/2, Position.Y + Size.Y/2); - } - - /// - /// Filhos da árvore - /// - private MapDivision left; - public MapDivision Left { get => this.left; } - private MapDivision right; - public MapDivision Right { get => this.right; } - - /// - /// Se a divisão atual for uma folha. - /// As folhas representam salas. - /// - public bool IsLeaf { - get => left == null && right == null; - } - - public MapDivision(Vector2I position, Vector2I size) { - Position = position; - Size = size; - } - - public MapDivision(Vector2I position, int width, int height) { - Position = position; - Size = new(width, height); - } - - public MapDivision(int x, int y, int width, int height) { - Position = new(x, y); - Size = new(width, height); - } - - /// - /// É conveniente ter acesso à todas as folhas da árvore. - /// - /// Lista com todas as folhas da árvore. - public Godot.Collections.Array GetLeaves() { - if (IsLeaf) { - Godot.Collections.Array list = []; - list.Add(this); - return list; - } - return left.GetLeaves() + right.GetLeaves(); - } - - /// - /// Algoritmo para gerar as divisões. - /// O mapa começa com uma única divisão que oculpa sua extensão completa. - /// Depois disso, ela se dividirá recursivamente n vezes. - /// As divisões nas folhas representam espaços onde pode gerar uma sala. - /// - /// Número de iterações - /// Gerador de números - public void Split(int iterations, RandomNumberGenerator rng) { - float SplitRatio = rng.RandfRange(0.35f, 0.65f); - bool horizontalSplit = Size.X <= Size.Y; - - // Eu defini um limite mínimo de 4 de altura e 4 de largura para divisões. - - if (horizontalSplit) { - int leftHeight = (int) (Size.Y * SplitRatio); - if (leftHeight > 4 && Size.Y - leftHeight > 4) { - left = new MapDivision(Position, Size.X, leftHeight); - right = new MapDivision(Position.X, Position.Y + leftHeight, Size.X, Size.Y - leftHeight); - } - } else { - int leftWidth = (int) (Size.Y * SplitRatio); - - if (leftWidth > 4 && Size.Y - leftWidth > 4) { - left = new MapDivision(Position, leftWidth, Size.Y); - right = new MapDivision(Position.X + leftWidth, Position.Y, Size.X - leftWidth, Size.Y); - } - } - - if (iterations > 1) { - left?.Split(iterations - 1, rng); - right?.Split(iterations - 1, rng); - } - } -} \ No newline at end of file diff --git a/scripts/map/MapDivision.cs.uid b/scripts/map/MapDivision.cs.uid deleted file mode 100644 index fdd53a4..0000000 --- a/scripts/map/MapDivision.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://c3niegr686acj diff --git a/scripts/map/Tile.cs b/scripts/map/Tile.cs deleted file mode 100644 index 39f7486..0000000 --- a/scripts/map/Tile.cs +++ /dev/null @@ -1,81 +0,0 @@ -using Godot; -using System; - -/// -/// O mundo do jogo é composto por Tiles. -/// Um tile é um quadrado de 16x16 que representa uma -/// unidade discreta do cenário. Tiles podem agir como -/// parede, chão, ou outras funções. -/// -public partial class Tile : Sprite2D -{ - /// - /// A definição do tile carrega seus valores padrão. - /// - private TileDefinition definition; - - /// - /// Determina se atores podem andar em cima do Tile. - /// - public bool IsWalkable { get; private set; } - /// - /// Determina se o tile bloqueia visão. - /// - public bool IsTransparent { get; private set; } - - private bool isExplored = false; - /// - /// Se o jogador já viu este tile antes. - /// Tiles não descobertos são invisíveis. - /// - public bool IsExplored { - get => this.isExplored; - set { - isExplored = value; - if (IsExplored && !Visible) { - Visible = true; - } - } - } - - private bool isInView = false; - /// - /// Se o jogador vê o tile neste exato momento. - /// Elementos neste tile estão dentro do campo de visão do jogador. - /// - public bool IsInView { - get => isInView; - set { - isInView = value; - Modulate = isInView ? definition.LitColor : definition.DarkColor; - if (IsInView && !IsExplored) { - IsExplored = true; - } - } - } - - public Tile(Vector2I pos, TileDefinition definition) - { - // Tile herda da classe Sprite2D. - // Por padrão, a posição do Sprite2D é no centro de sua textura. - // Para o jogo, faz mais sentido que a posição seja no - // canto superior esquerdo. - Centered = false; - // Tiles começam invisíveis porque não foram vistos pelo jogador. - Visible = false; - Position = Grid.GridToWorld(pos); - SetDefinition(definition); - } - - /// - /// Define as características do tile. - /// - /// Definição do tile. - public void SetDefinition(TileDefinition definition) { - this.definition = definition; - Modulate = definition.DarkColor; - Texture = definition.Texture; - IsWalkable = definition.IsWalkable; - IsTransparent = definition.IsTransparent; - } -} diff --git a/scripts/map/Tile.cs.uid b/scripts/map/Tile.cs.uid deleted file mode 100644 index 9fa3c81..0000000 --- a/scripts/map/Tile.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://b2dkecc01tqc0 diff --git a/scripts/map/TileDefinition.cs b/scripts/map/TileDefinition.cs deleted file mode 100644 index 84e5cc1..0000000 --- a/scripts/map/TileDefinition.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Godot; - -/// -/// Define as características de um tile. -/// -[GlobalClass] -public partial class TileDefinition : Resource -{ - [ExportCategory("Visuals")] - [Export] - public Texture2D Texture { get; set; } - [Export(PropertyHint.ColorNoAlpha)] - public Color LitColor { get; set; } = Colors.White; - [Export(PropertyHint.ColorNoAlpha)] - public Color DarkColor { get; set; } = Colors.White; - - [ExportCategory("Mechanics")] - [Export] - public bool IsWalkable { get; set; } - [Export] - public bool IsTransparent { get; set; } -} diff --git a/scripts/map/TileDefinition.cs.uid b/scripts/map/TileDefinition.cs.uid deleted file mode 100644 index 14f2903..0000000 --- a/scripts/map/TileDefinition.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://ba82a33ov6uuo -- cgit v1.2.3