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/Tile.cs | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 scripts/Map/Tile.cs (limited to 'scripts/Map/Tile.cs') diff --git a/scripts/Map/Tile.cs b/scripts/Map/Tile.cs new file mode 100644 index 0000000..e721fca --- /dev/null +++ b/scripts/Map/Tile.cs @@ -0,0 +1,90 @@ +using Godot; +using TheLegendOfGustav.Utils; + +namespace TheLegendOfGustav.Map; + +/// +/// 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 +{ + private bool isExplored = false; + private bool isInView = false; + + 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); + } + + /// + /// 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; } + + /// + /// A definição do tile carrega seus valores padrão. + /// + private TileDefinition Definition { get; set; } + /// + /// Se o jogador já viu este tile antes. + /// Tiles não descobertos são invisíveis. + /// + public bool IsExplored + { + get => isExplored; + set + { + isExplored = value; + if (IsExplored && !Visible) + { + Visible = true; + } + } + } + + /// + /// 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; + } + } + } + + /// + /// Define as características do tile. + /// + /// Definição do tile. + public void SetDefinition(TileDefinition definition) + { + Definition = definition; + Modulate = definition.DarkColor; + Texture = definition.Texture; + IsWalkable = definition.IsWalkable; + IsTransparent = definition.IsTransparent; + } +} -- cgit v1.2.3