feat: dragons moving freely
This commit is contained in:
parent
a0a746008e
commit
014cf47823
1 changed files with 25 additions and 2 deletions
|
@ -8,7 +8,9 @@ var main_window_rect: Rect2i
|
|||
@onready var draggable: Draggable = $DragDropDetector
|
||||
|
||||
var _walking: bool = false
|
||||
var _thinking_path: bool = false
|
||||
var _target_pos: Vector2
|
||||
var rng: RandomNumberGenerator = RandomNumberGenerator.new()
|
||||
|
||||
signal place_back(dragon: Dragon)
|
||||
|
||||
|
@ -17,12 +19,19 @@ func on_place_back() -> void:
|
|||
place_back.emit(self)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_pick_random_screen_position()
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if draggable.dragging:
|
||||
_actual_position = position
|
||||
return
|
||||
|
||||
if not _walking:
|
||||
if not _thinking_path:
|
||||
_thinking_path = true
|
||||
await get_tree().create_timer(rng.randf_range(2, 7)).timeout
|
||||
_pick_random_screen_position()
|
||||
|
||||
_move_to_target(delta)
|
||||
|
@ -33,8 +42,22 @@ func _move_to_target(delta: float):
|
|||
var direction: Vector2 = (_target_pos - _actual_position).normalized()
|
||||
_actual_position += dragon_speed * direction * delta
|
||||
position = _actual_position
|
||||
return
|
||||
|
||||
_walking = false
|
||||
|
||||
|
||||
func _pick_random_screen_position() -> void:
|
||||
_walking = true
|
||||
_target_pos = Vector2i(10, 10)
|
||||
_thinking_path = false
|
||||
|
||||
var display_index: int = DisplayServer.window_get_current_screen()
|
||||
var work_area_position: Vector2i = DisplayServer.screen_get_usable_rect(display_index).position
|
||||
var work_area_size: Vector2i = DisplayServer.screen_get_usable_rect(display_index).size
|
||||
|
||||
var random_pos: Vector2i = Vector2i(
|
||||
work_area_position.x + rng.randi_range(10, work_area_size.x - 10 - size.x),
|
||||
work_area_position.y + rng.randi_range(10, work_area_size.y - 10 - size.y)
|
||||
)
|
||||
|
||||
_target_pos = random_pos
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue