brackeys-12/tile_map.gd
NnYGames 17f4e92df0 Added basic placing of building
Added placing of buildings on the tile map using get input, will try to do it using mouse handler
2024-09-09 20:46:51 +03:00

30 lines
662 B
GDScript

extends TileMap
var GridSize = 16
var Dic = {}
var placed = []
func _ready():
for x in GridSize:
for y in GridSize:
Dic[str(Vector2(x,y))] = {
"Type": "Ground",
"Position": str(Vector2(x,y)),
"Placed": false
}
set_cell(0, Vector2(x, y), 0, Vector2i(0,0), 0)
func _process(delta):
var tile = local_to_map(get_global_mouse_position())
for x in GridSize:
for y in GridSize:
if !Dic[str(Vector2(x,y))].get("Placed"):
erase_cell(1, Vector2(x,y))
if Dic.has(str(tile)):
set_cell(1, tile, 1, Vector2i(0,0), 0)
#print(Dic[str(tile)])
if Input.is_action_just_pressed("lclick"):
Dic[str(tile)]["Placed"] = true