Plant spawn
This commit is contained in:
parent
32453f2e9d
commit
941912d7f1
25 changed files with 281 additions and 40 deletions
37
scripts/level/layered_entity_container.gd
Normal file
37
scripts/level/layered_entity_container.gd
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
extends Node
|
||||
|
||||
class_name LayeredEntityContainer
|
||||
|
||||
var entities := {
|
||||
"under" : [],
|
||||
"base" : [],
|
||||
"above" : []
|
||||
}
|
||||
|
||||
func _ready() -> void:
|
||||
LevelEventBus.layer_entity_created.connect(on_entity_spawned)
|
||||
LevelEventBus.layer_entity_killed.connect(on_entity_killed)
|
||||
|
||||
for layer in entities.keys():
|
||||
entities[layer].resize(FieldParams.COLUMNS * FieldParams.ROWS)
|
||||
|
||||
## Checks if tile is occupied. [br]
|
||||
## If position or layer are invalid, returns true
|
||||
func is_occupied(position : int, layer : StringName) -> bool:
|
||||
if position >= FieldParams.COLUMNS * FieldParams.ROWS or entities.has(layer) == false: return true
|
||||
return not entities[layer][position] == null
|
||||
|
||||
func on_entity_spawned(entity : Entity) -> void:
|
||||
if entities.has(entity.layer) == false: return
|
||||
|
||||
var index = FieldParams.indexify(entity.get_parent().global_position)
|
||||
if index >= FieldParams.COLUMNS * FieldParams.ROWS or is_occupied(index,entity.layer): return
|
||||
|
||||
entities[entity.layer][index] = entity
|
||||
|
||||
func on_entity_killed(context : Entity.KilledContext) -> void:
|
||||
var entity = context.target
|
||||
var index = FieldParams.indexify(entity.get_parent().global_position)
|
||||
if is_occupied(index,entity.layer) == false: return
|
||||
|
||||
entities[entity.layer][index] = null
|
||||
Loading…
Add table
Add a link
Reference in a new issue