generated from SGDA/GodotExampleProject
51 lines
1.2 KiB
GDScript
51 lines
1.2 KiB
GDScript
extends CharacterBody2D
|
|
|
|
@export var move: GUIDEAction
|
|
@export var interact: GUIDEAction
|
|
|
|
@export var walk_speed = 300.0
|
|
|
|
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
|
|
|
|
var current_interactible: Interactible = null
|
|
var is_sneaking: bool = false
|
|
|
|
func _ready() -> void:
|
|
interact.triggered.connect(on_interact_triggered)
|
|
|
|
func on_interact_triggered() -> void:
|
|
if current_interactible == null:
|
|
return
|
|
SceneLoader.load_scene(current_interactible.scene_to_trigger)
|
|
|
|
|
|
func _on_interactible_found(area: Area2D) -> void:
|
|
current_interactible = area as Interactible
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
var direction = move.value_axis_2d
|
|
velocity = direction * walk_speed
|
|
|
|
if velocity.x > 0:
|
|
animated_sprite_2d.flip_h = false
|
|
if velocity.x < 0:
|
|
animated_sprite_2d.flip_h = true
|
|
|
|
if velocity.length() == 0:
|
|
if is_sneaking:
|
|
animated_sprite_2d.play("idle_sneak")
|
|
else:
|
|
animated_sprite_2d.play("idle")
|
|
if velocity.length() > 0:
|
|
if is_sneaking:
|
|
animated_sprite_2d.play("sneak")
|
|
else:
|
|
animated_sprite_2d.play("run")
|
|
|
|
move_and_slide()
|
|
|
|
|
|
func _on_area_2d_area_exited(area: Area2D) -> void:
|
|
current_interactible = null # Replace with function body.
|