2024-09-27 13:39:45 -07:00
|
|
|
extends Area3D
|
2024-09-27 16:49:56 -07:00
|
|
|
class_name Character
|
2024-09-27 13:39:45 -07:00
|
|
|
|
2024-10-13 14:49:58 -07:00
|
|
|
signal turn(direction: TileTurn.Direction)
|
2024-09-27 13:39:45 -07:00
|
|
|
|
2024-10-12 16:16:43 -07:00
|
|
|
@export var speed: float = 20.0
|
2024-10-13 14:49:58 -07:00
|
|
|
@export var jump_height: float = 3
|
2024-10-04 10:01:33 -07:00
|
|
|
@export var tile: Tile
|
2024-09-27 13:39:45 -07:00
|
|
|
|
|
|
|
var total_distance: float = 0.0
|
2024-10-13 14:49:58 -07:00
|
|
|
var current_height: float = 0.0
|
|
|
|
var jump_tween: Tween
|
|
|
|
var fall_tween: Tween
|
|
|
|
var in_air: bool = false
|
2024-09-27 13:39:45 -07:00
|
|
|
|
2024-10-04 10:01:33 -07:00
|
|
|
|
2024-09-27 13:39:45 -07:00
|
|
|
func _ready() -> void:
|
2024-10-04 10:01:33 -07:00
|
|
|
if tile == null or tile is not Tile:
|
|
|
|
printerr("tile is not set to a Tile")
|
2024-09-27 13:39:45 -07:00
|
|
|
return
|
|
|
|
|
|
|
|
|
2024-10-13 14:49:58 -07:00
|
|
|
func _process(delta: float) -> void:
|
2024-10-04 10:01:33 -07:00
|
|
|
if tile == null:
|
2024-09-27 13:39:45 -07:00
|
|
|
return
|
2024-10-04 10:01:33 -07:00
|
|
|
|
|
|
|
if Input.is_action_just_pressed("ui_right"):
|
2024-10-13 14:49:58 -07:00
|
|
|
turn.emit(TileTurn.Direction.Right)
|
2024-10-04 10:01:33 -07:00
|
|
|
if Input.is_action_just_pressed("ui_left"):
|
2024-10-13 14:49:58 -07:00
|
|
|
turn.emit(TileTurn.Direction.Left)
|
|
|
|
if Input.is_action_just_pressed("ui_up"):
|
|
|
|
jump()
|
2024-10-04 10:01:33 -07:00
|
|
|
|
|
|
|
global_position = tile.marker_position
|
|
|
|
global_rotation = tile.marker_rotation
|
|
|
|
if tile.follow.progress_ratio >= 1:
|
2024-09-27 13:39:45 -07:00
|
|
|
return
|
2024-09-30 20:50:05 -07:00
|
|
|
var travel: float = speed * delta
|
2024-10-04 10:01:33 -07:00
|
|
|
tile.follow.progress += travel
|
2024-09-27 13:39:45 -07:00
|
|
|
total_distance += travel
|
2024-10-13 14:49:58 -07:00
|
|
|
tile.follow.v_offset = current_height
|
2024-10-04 18:25:33 -07:00
|
|
|
|
|
|
|
|
|
|
|
func _on_area_entered(area):
|
|
|
|
if area is Obstacle:
|
|
|
|
handle_obstacle(area)
|
|
|
|
|
|
|
|
|
2024-10-12 15:19:15 -07:00
|
|
|
func handle_obstacle(obstacle: Obstacle) -> void:
|
2024-10-04 18:25:33 -07:00
|
|
|
if obstacle.effect == Obstacle.ObstacleEffect.Kill:
|
|
|
|
print("kill")
|
|
|
|
speed = 0
|
2024-10-13 14:49:58 -07:00
|
|
|
|
|
|
|
|
|
|
|
func jump() -> void:
|
|
|
|
if in_air:
|
|
|
|
return
|
|
|
|
in_air = true
|
|
|
|
jump_tween = get_tree().create_tween()
|
|
|
|
jump_tween.tween_property(self, "current_height", jump_height, 0.25).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT)
|
|
|
|
jump_tween.tween_callback(fall)
|
|
|
|
|
|
|
|
func fall() -> void:
|
|
|
|
fall_tween = get_tree().create_tween()
|
|
|
|
fall_tween.tween_property(self, "current_height", 0, 0.25).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN)
|
|
|
|
fall_tween.tween_callback(finish_falling)
|
|
|
|
|
|
|
|
|
|
|
|
func finish_falling() -> void:
|
|
|
|
in_air = false
|