summaryrefslogtreecommitdiff
path: root/scripts/Map
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/Map')
-rw-r--r--scripts/Map/DungeonGenerator.cs57
-rw-r--r--scripts/Map/Map.cs42
-rw-r--r--scripts/Map/MapData.cs4
-rw-r--r--scripts/Map/Tile.cs16
4 files changed, 60 insertions, 59 deletions
diff --git a/scripts/Map/DungeonGenerator.cs b/scripts/Map/DungeonGenerator.cs
index f2f00a9..7dee0b4 100644
--- a/scripts/Map/DungeonGenerator.cs
+++ b/scripts/Map/DungeonGenerator.cs
@@ -26,61 +26,60 @@ public partial class DungeonGenerator : Node
GD.Load<ScrollConsumableDefinition>("res://assets/definitions/Items/mana_bolt_scroll.tres"),
GD.Load<GrimoireConsumableDefinition>("res://assets/definitions/Items/mana_bolt_grimoire.tres")
];
- #endregion
- #region Properties
/// <summary>
/// Dimensões do mapa a ser criado.
/// </summary>
[ExportCategory("Dimension")]
[Export]
- private int Width { get; set; } = 80;
+ private int width = 80;
[Export]
- private int Height { get; set; } = 60;
+ private int height = 60;
/// <summary>
- /// Gerador de números aleatórios
- /// </summary>
- [ExportCategory("RNG")]
- private RandomNumberGenerator Rng { get; set; } = new();
- /// <summary>
/// Qual seed utilizar.
/// </summary>
[Export]
- private ulong Seed { get; set; }
+ private ulong seed;
/// <summary>
/// Se será utilizada a nossa seed ou a seed padrão da classe RandomNumberGenerator.
/// </summary>
[Export]
- private bool UseSeed { get; set; } = true;
+ private bool useSeed = true;
/// <summary>
/// Quantas iterações do algoritmo chamar.
/// </summary>
[Export]
- private int Iterations { get; set; } = 3;
+ private int iterations = 3;
+
+ /// <summary>
+ /// Gerador de números aleatórios
+ /// </summary>
+ [ExportCategory("RNG")]
+ private RandomNumberGenerator rng = new();
/// <summary>
/// Quantidade máxima de inimigos por sala.
/// </summary>
[ExportCategory("Monster RNG")]
[Export]
- private int MaxMonsterPerRoom { get; set; } = 2;
+ private int maxMonstersPerRoom = 2;
/// <summary>
/// Quantidade máxima de itens por sala.
/// </summary>
[ExportCategory("Loot RNG")]
[Export]
- private int MaxItemsPerRoom { get; set; } = 2;
+ private int maxItemsPerRoom = 2;
#endregion
#region Methods
public override void _Ready()
{
base._Ready();
- if (UseSeed)
+ if (useSeed)
{
- Rng.Seed = Seed;
+ rng.Seed = seed;
}
}
@@ -93,13 +92,13 @@ public partial class DungeonGenerator : Node
/// <returns>O mapa gerado.</returns>
public MapData GenerateDungeon(Player player)
{
- MapData data = new MapData(Width, Height, player);
+ MapData data = new MapData(width, height, player);
// Divisão mestre que engloba o mapa inteiro.
- MapDivision root = new MapDivision(0, 0, Width, Height);
+ MapDivision root = new MapDivision(0, 0, width, height);
// Chama o algoritmo para dividir o mapa.
- root.Split(Iterations, Rng);
+ root.Split(iterations, rng);
bool first = true;
@@ -113,10 +112,10 @@ public partial class DungeonGenerator : Node
// 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)
+ -rng.RandiRange(1, 2),
+ -rng.RandiRange(1, 2),
+ -rng.RandiRange(1, 2),
+ -rng.RandiRange(1, 2)
);
// De fato cria a sala.
@@ -236,16 +235,16 @@ public partial class DungeonGenerator : Node
private void PlaceEntities(MapData data, Rect2I room)
{
// Define quantos monstros serão colocados na sala
- int monsterAmount = Rng.RandiRange(0, MaxMonsterPerRoom);
+ int monsterAmount = rng.RandiRange(0, maxMonstersPerRoom);
// Define quantos itens serão colocados na sala.
- int itemAmount = Rng.RandiRange(0, MaxItemsPerRoom);
+ 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)
+ 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.
@@ -272,8 +271,8 @@ public partial class DungeonGenerator : Node
{
// 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)
+ rng.RandiRange(room.Position.X, room.End.X - 1),
+ rng.RandiRange(room.Position.Y, room.End.Y - 1)
);
bool canPlace = true;
diff --git a/scripts/Map/Map.cs b/scripts/Map/Map.cs
index 9117bc5..8521797 100644
--- a/scripts/Map/Map.cs
+++ b/scripts/Map/Map.cs
@@ -10,34 +10,34 @@ namespace TheLegendOfGustav.Map;
public partial class Map : Node2D
{
/// <summary>
- /// Dados do mapa.
- /// </summary>
- public MapData MapData { get; private set; }
-
- /// <summary>
/// raio de alcance da visão do jogador.
/// </summary>
[Export]
- private int FovRadius { get; set; } = 12;
+ private int fovRadius = 12;
+
+ private FieldOfView fieldOfView;
+
+ private Node2D tilesNode;
+ private Node2D entitiesNode;
/// <summary>
/// Gerador de mapas.
/// </summary>
- private DungeonGenerator Generator { get; set; }
-
- FieldOfView FieldOfView { get; set; }
-
- private Node2D TilesNode { get; set; }
- private Node2D EntitiesNode { get; set; }
+ private DungeonGenerator generator;
+ /// <summary>
+ /// Dados do mapa.
+ /// </summary>
+ public MapData MapData { get; private set; }
+
public override void _Ready()
{
base._Ready();
// Começamos obtendo nós relevantes para o mapa.
- Generator = GetNode<DungeonGenerator>("Generator");
- FieldOfView = GetNode<FieldOfView>("FieldOfView");
- TilesNode = GetNode<Node2D>("Tiles");
- EntitiesNode = GetNode<Node2D>("Entities");
+ generator = GetNode<DungeonGenerator>("Generator");
+ fieldOfView = GetNode<FieldOfView>("FieldOfView");
+ tilesNode = GetNode<Node2D>("Tiles");
+ entitiesNode = GetNode<Node2D>("Entities");
}
/// <summary>
@@ -46,7 +46,7 @@ public partial class Map : Node2D
/// <param name="player">O gerador de mapas precisa do jogador.</param>
public void Generate(Player player)
{
- MapData = Generator.GenerateDungeon(player);
+ MapData = generator.GenerateDungeon(player);
MapData.EntityPlaced += OnEntityPlaced;
@@ -60,7 +60,7 @@ public partial class Map : Node2D
/// <param name="pos">Centro de visão, normalmente é a posição do jogador.</param>
public void UpdateFOV(Vector2I pos)
{
- FieldOfView.UpdateFOV(MapData, pos, FovRadius);
+ fieldOfView.UpdateFOV(MapData, pos, fovRadius);
// Esconde ou revela entidades com base no campo de visão.
foreach (Entity entity in MapData.Entities)
{
@@ -76,7 +76,7 @@ public partial class Map : Node2D
{
foreach (Tile tile in MapData.Tiles)
{
- TilesNode.AddChild(tile);
+ tilesNode.AddChild(tile);
}
}
@@ -87,12 +87,12 @@ public partial class Map : Node2D
{
foreach (Entity entity in MapData.Entities)
{
- EntitiesNode.AddChild(entity);
+ entitiesNode.AddChild(entity);
}
}
private void OnEntityPlaced(Entity entity)
{
- EntitiesNode.AddChild(entity);
+ entitiesNode.AddChild(entity);
}
}
diff --git a/scripts/Map/MapData.cs b/scripts/Map/MapData.cs
index 3365380..699295e 100644
--- a/scripts/Map/MapData.cs
+++ b/scripts/Map/MapData.cs
@@ -19,7 +19,7 @@ public partial class MapData : RefCounted
/// Peso do ator no pathfinder.
/// A IA irá evitar de passar por espaços com peso alto.
/// </summary>
- private static readonly float EntityWeight = 10.0f;
+ private static readonly float entityWeight = 10.0f;
#endregion
#region Constructor
@@ -138,7 +138,7 @@ public partial class MapData : RefCounted
/// <param name="entity">A entidade em questão.</param>
public void RegisterBlockingEntity(Entity entity)
{
- Pathfinder.SetPointWeightScale(entity.GridPosition, EntityWeight);
+ Pathfinder.SetPointWeightScale(entity.GridPosition, entityWeight);
}
/// <summary>
diff --git a/scripts/Map/Tile.cs b/scripts/Map/Tile.cs
index e721fca..488d124 100644
--- a/scripts/Map/Tile.cs
+++ b/scripts/Map/Tile.cs
@@ -13,7 +13,12 @@ public partial class Tile : Sprite2D
{
private bool isExplored = false;
private bool isInView = false;
-
+
+ /// <summary>
+ /// A definição do tile carrega seus valores padrão.
+ /// </summary>
+ private TileDefinition definition;
+
public Tile(Vector2I pos, TileDefinition definition)
{
// Tile herda da classe Sprite2D.
@@ -36,10 +41,7 @@ public partial class Tile : Sprite2D
/// </summary>
public bool IsTransparent { get; private set; }
- /// <summary>
- /// A definição do tile carrega seus valores padrão.
- /// </summary>
- private TileDefinition Definition { get; set; }
+
/// <summary>
/// Se o jogador já viu este tile antes.
/// Tiles não descobertos são invisíveis.
@@ -67,7 +69,7 @@ public partial class Tile : Sprite2D
set
{
isInView = value;
- Modulate = isInView ? Definition.LitColor : Definition.DarkColor;
+ Modulate = isInView ? definition.LitColor : definition.DarkColor;
if (IsInView && !IsExplored)
{
IsExplored = true;
@@ -81,7 +83,7 @@ public partial class Tile : Sprite2D
/// <param name="definition">Definição do tile.</param>
public void SetDefinition(TileDefinition definition)
{
- Definition = definition;
+ this.definition = definition;
Modulate = definition.DarkColor;
Texture = definition.Texture;
IsWalkable = definition.IsWalkable;