diff options
Diffstat (limited to 'guide.gd')
-rw-r--r-- | guide.gd | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/guide.gd b/guide.gd new file mode 100644 index 0000000..aae9deb --- /dev/null +++ b/guide.gd @@ -0,0 +1,54 @@ +extends Area2D + + +@export var force: float = 10.0 + +var current_direction := Vector2.UP: set = set_current_direction +var base_gravity: float = gravity + + +func set_current_direction(value: Vector2) -> void: + current_direction = value + + gravity_direction = current_direction + gravity = base_gravity + + if current_direction == Vector2.UP: + $AnimationPlayer.play("up") + gravity = base_gravity * 0.25 + elif current_direction == Vector2.DOWN: + $AnimationPlayer.play("down") + elif current_direction == Vector2.LEFT: + $AnimationPlayer.play("left") + elif current_direction == Vector2.RIGHT: + $AnimationPlayer.play("right") + + +func get_impulse() -> Vector2: + return Vector2(force, force) + + +func apply_guiding_impulse(body: Node2D) -> void: + if ( + current_direction == Vector2.LEFT or + current_direction == Vector2.RIGHT or + (current_direction == Vector2.UP and body.global_position.y > global_position.y) + ): + body.apply_central_impulse( + (global_position - body.global_position).normalized() * + get_impulse() + ) + + +func _on_timer_timeout() -> void: + current_direction = [ + Vector2.UP, + Vector2.DOWN, + Vector2.LEFT, + Vector2.RIGHT, + ].pick_random() + $Timer.wait_time = randf_range(5.0, 10.0) + + +func _on_body_entered(body: Node2D) -> void: + apply_guiding_impulse(body) |