31 lines
764 B
GDScript3
Raw Normal View History

2024-01-23 23:09:50 +00:00
extends Node
## Width of the grid in cells.
const width := 100
## Height of the grid in cells.
const height := 100
## The size of a single cell.
const cell_size := 10.0
var cells: Array[Cell]
func _init():
cells.resize(width * height)
for i in cells.size():
cells[i] = Cell.new()
func notify_cell_changed(player: Player, old_pos: Vector2i, new_pos: Vector2i):
print(player.name, " cell changed! ", old_pos, " ", new_pos)
add_player(player, new_pos)
remove_player(player, old_pos)
func add_player(player: Player, coords: Vector2i):
var cell := cells[coords.x + coords.y * height]
cell.player_list.append(player)
func remove_player(player: Player, coords: Vector2i):
var cell := cells[coords.x + coords.y * height]
cell.player_list.erase(player)