feat: windows moving
This commit is contained in:
		
							parent
							
								
									f32dd932f6
								
							
						
					
					
						commit
						a0a746008e
					
				
					 4 changed files with 44 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -1,5 +1,40 @@
 | 
			
		|||
extends Window
 | 
			
		||||
class_name Dragon
 | 
			
		||||
 | 
			
		||||
@export var dragon_speed: float = 20.0
 | 
			
		||||
 | 
			
		||||
@onready var _actual_position: Vector2 = position
 | 
			
		||||
var main_window_rect: Rect2i
 | 
			
		||||
@onready var draggable: Draggable = $DragDropDetector
 | 
			
		||||
 | 
			
		||||
var _walking: bool = false
 | 
			
		||||
var _target_pos: Vector2
 | 
			
		||||
 | 
			
		||||
signal place_back(dragon: Dragon)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func on_place_back() -> void:
 | 
			
		||||
	place_back.emit(self)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func _process(delta: float) -> void:
 | 
			
		||||
	if draggable.dragging:
 | 
			
		||||
		_actual_position = position
 | 
			
		||||
		return
 | 
			
		||||
	
 | 
			
		||||
	if not _walking:
 | 
			
		||||
		_pick_random_screen_position()
 | 
			
		||||
	
 | 
			
		||||
	_move_to_target(delta)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func _move_to_target(delta: float):
 | 
			
		||||
	if _actual_position.distance_to(_target_pos) > 10.0:
 | 
			
		||||
		var direction: Vector2 = (_target_pos - _actual_position).normalized()
 | 
			
		||||
		_actual_position += dragon_speed * direction * delta
 | 
			
		||||
		position = _actual_position
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func _pick_random_screen_position() -> void:
 | 
			
		||||
	_walking = true
 | 
			
		||||
	_target_pos = Vector2i(10, 10)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue