refactor: dragon instantiation
This commit is contained in:
parent
c75800aaa8
commit
8983b84731
6 changed files with 76 additions and 35 deletions
|
@ -2,9 +2,14 @@ extends Node
|
|||
|
||||
|
||||
@export var dragon_template: PackedScene
|
||||
@export var dragon_spots: Array[Node2D]
|
||||
|
||||
var _instantiator: DragonInstantiator
|
||||
|
||||
|
||||
func _ready():
|
||||
_instantiator = DragonInstantiator.new(dragon_template, dragon_spots)
|
||||
|
||||
await get_tree().process_frame
|
||||
move_window_to_bottom_right()
|
||||
|
||||
|
@ -24,15 +29,5 @@ func move_window_to_bottom_right():
|
|||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_accept"):
|
||||
_instantiate_dragon(Vector2i(0, 0))
|
||||
|
||||
|
||||
func _instantiate_dragon(relative_position: Vector2i) -> void:
|
||||
var dragon = dragon_template.instantiate()
|
||||
add_child(dragon)
|
||||
if dragon is Window:
|
||||
var window_position: Vector2i = DisplayServer.window_get_position()
|
||||
var window_size: Vector2i = DisplayServer.window_get_size()
|
||||
dragon.position = window_position + relative_position
|
||||
dragon.main_window_rect = Rect2i(window_position, window_size)
|
||||
dragon.show()
|
||||
var dragon = _instantiator.instantiate()
|
||||
add_child(dragon)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue