factory-expansion/logic/world/chunk/chunk.gd
2025-09-13 14:42:20 -07:00

25 lines
549 B
GDScript

extends Node2D
var tiles : Array[Tile]
var chunk_offset : Vector2i
func _init() -> void:
for i in range(TileGlobals.chunk_size ** 2):
tiles.append(Tile.new())
func get_tile(pos : Vector2i):
return tiles[pos.y * TileGlobals.chunk_size + pos.x]
func _draw() -> void:
var x : int = 0
var y : int = 0
for tile in tiles:
var tile_definition : TileDefinition = TileGlobals.tile_definitions[tile.id]
draw_texture(tile_definition.texture, Vector2(x, y) * TileGlobals.tile_size)
x += 1
if x >= TileGlobals.chunk_size:
y += 1
x = 0