lakewood/Assets/Characters/Friendly/Tellik/tellick.gd

61 lines
1.4 KiB
GDScript3
Raw Normal View History

extends CharacterBody2D
const SPEED = 600.0
2024-09-07 12:21:36 -04:00
const JUMP_VELOCITY = -1000.0
2024-09-07 12:08:47 -04:00
const MAX_JUMP_DURATION = 0.3
2024-09-07 12:21:36 -04:00
const MIN_JUMP_DURATION = 0.01
2024-09-07 12:08:47 -04:00
const GRAVITY = 980
2024-09-07 12:21:36 -04:00
const FALL_GRAVITY_MULTIPLIER = 2
2024-09-07 12:08:47 -04:00
var jump_timer = 0.0
var is_jumping = false
2024-09-07 14:12:04 -04:00
@onready var actionableFinder: Area2D = $Marker2D/ActionableFinder
func _unhandled_input(event: InputEvent) -> void:
if Input.is_action_just_pressed("ui_accept"):
var actionables = actionableFinder.get_overlapping_areas()
if actionables.size() > 0:
actionables[0].action()
return
2024-09-07 12:08:47 -04:00
func _physics_process(delta):
# Apply gravity
if not is_on_floor():
2024-09-07 12:21:36 -04:00
var gravity_multiplier = FALL_GRAVITY_MULTIPLIER if velocity.y > 0 else 2
2024-09-07 12:08:47 -04:00
velocity.y += GRAVITY * gravity_multiplier * delta
2024-09-07 12:08:47 -04:00
# Handle Jump
if Input.is_action_just_pressed("jump") and is_on_floor():
start_jump()
if is_jumping:
2024-09-07 12:21:36 -04:00
if Input.is_action_pressed("jump"):
2024-09-07 12:08:47 -04:00
continue_jump(delta)
else:
end_jump()
2024-09-07 12:08:47 -04:00
# Handle horizontal movement
var direction = Input.get_axis("move_left", "move_right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
2024-09-07 12:08:47 -04:00
func start_jump():
velocity.y = JUMP_VELOCITY
is_jumping = true
func continue_jump(delta):
2024-09-07 12:21:36 -04:00
pass
2024-09-07 12:08:47 -04:00
func end_jump():
if velocity.y < 0:
2024-09-07 12:21:36 -04:00
velocity.y *= 0.20
is_jumping = false
func _on_kill_zone_body_entered(body: Node2D) -> void:
pass # Replace with function body.