feat: dragon animations

This commit is contained in:
Gerard Gascón 2025-04-15 22:21:23 +02:00
parent 9f2b78c1bd
commit 787344e5e4
4 changed files with 46 additions and 19 deletions

View file

@ -6,6 +6,7 @@ class_name GameManager
@export var dragon_ingame: PackedScene
@export var name_setter: PackedScene
@export var dragon_spots: Array[Node2D]
@export var dragon_start_spots: Dictionary[Node2D, Node2D]
var _filled_spots: Dictionary[Node2D, int]
@ -70,7 +71,7 @@ func _instantiate_random_dragon():
for d in _library.dragons:
# TODO: Search for dragon and if is in library or in instantiated dragons continue next iteration
pass
var dragon_entity: DragonEntity = _generate_entity(spot.position, dragon)
var dragon_entity: DragonEntity = _generate_entity(spot, dragon)
_filled_spots[spot] = dragon_entity.properties.id
return
@ -82,9 +83,9 @@ func _get_free_spot() -> Node2D:
return null
func _generate_entity(pos: Vector2, properties: DragonProperties) -> DragonEntity:
func _generate_entity(spot: Node2D, properties: DragonProperties) -> DragonEntity:
properties.id = rng.randi()
return _instantiate_dragon_ingame(pos, properties)
return _instantiate_dragon_ingame(spot, properties)
func move_window_to_bottom_right():
@ -106,7 +107,7 @@ func add_dragon(properties: DragonProperties):
dragon_sharing.send(properties)
for spot in dragon_spots:
if not _filled_spots.has(spot):
_instantiate_dragon_ingame(spot.position, properties)
_instantiate_dragon_ingame(spot, properties)
_filled_spots[spot] = id
break
@ -121,15 +122,15 @@ func _load_game():
print(_save_load.contents_to_save)
func _instantiate_dragon_ingame(window_position: Vector2, properties: DragonProperties) -> DragonEntity:
func _instantiate_dragon_ingame(spot: Node2D, properties: DragonProperties) -> DragonEntity:
var dragon: DragonEntity = dragon_ingame.instantiate()
add_child(dragon)
spot.add_child(dragon)
dragon.dress(properties)
dragon.properties = properties
dragon.position = window_position
dragon.on_pick.connect(_pick_dragon)
dragon.on_quit.connect(_quit_dragon)
_instantiated_dragons[properties.id] = dragon
dragon.play_initial_animation(dragon_start_spots[spot])
return dragon