Added player character and initial interaction functionality

This commit is contained in:
2024-02-24 08:36:43 -06:00
parent 78c4291b6a
commit 5467e044a7
12 changed files with 557 additions and 46 deletions

35
scripts/autoloads/grid.gd Normal file
View File

@@ -0,0 +1,35 @@
extends Node
const GRID_SIZE := 64
var world_grid: TileMap
var world_data: Dictionary = {}
func init(grid: TileMap) -> void:
world_grid = grid
func world_to_grid(world_loc: Vector2) -> Vector2i:
return Vector2i(floor(world_loc.x / GRID_SIZE), floor(world_loc.y / GRID_SIZE))
func set_selected_tile(tile: Vector2i) -> void:
world_grid.clear_layer(Constants.TilemapLayers.CURSOR)
world_grid.set_cell(Constants.TilemapLayers.CURSOR, tile,0,Vector2i(0,7))
func corrupt_location(loc: Vector2i) -> bool:
return world_data[loc].change_layer(Constants.TilemapLayers.CORRUPTION, true)
func get_corrupted_cells() -> Array[Vector2i]:
return world_data.values().filter(func(cell: CellData): return cell.is_corrupted()).map(func(cell: CellData) -> Vector2i: return cell._pos)
func change_location_data(pos: Vector2i, layer: int, data: Vector2i) -> void:
if not world_data.has(pos):
world_data[pos] = CellData.new(pos)
world_data[pos].change_layer(layer, data)
world_grid.set_cell(layer, pos, 0, data)
func get_location_data(pos: Vector2i) -> CellData:
if world_data.has(pos):
return world_data[pos]
return null
func change_location_resource(pos: Vector2i, data: GameResource) -> void:
world_data[pos].change_resource(data)