lakewood/Assets/Characters/Friendly/Tellik/tellick.gd
2024-09-25 17:04:33 -04:00

106 lines
2.3 KiB
GDScript

extends CharacterBody2D
var SPEED = 600.0
const REGSPEED = 600.0
const JUMP_VELOCITY = -1000.0
const MAX_JUMP_DURATION = 0.3
const MIN_JUMP_DURATION = 0.01
const GRAVITY = 980
const FALL_GRAVITY_MULTIPLIER = 2
var isFacingRight: bool
# jumping vars
var jump_timer = 0.0
var is_jumping = false
# crouching vars
var is_crouching = false
var can_stand_up = true
var crouch_speed = 100
# dialouge vars
@export var is_talking = false
@onready var actionableFinder: Area2D = $Marker2D/ActionableFinder
func _input(event: InputEvent) -> void:
if event.is_action_pressed("crouch"):
is_crouching = true
update_crouch_state()
elif(event.is_action_released("crouch")):
is_crouching = false
update_crouch_state()
func update_crouch_state() -> void:
if is_crouching:
#slow speed
SPEED = crouch_speed
#shorten hitbox
$CollisionShape2D.scale.y = .5
elif(can_stand_up):
SPEED = REGSPEED # resotre normal speed
$CollisionShape2D.scale.y = 1 # restore collision
func _unhandled_input(event: InputEvent) -> void:
if Input.is_action_just_pressed("ui_accept"):
var actionables = actionableFinder.get_overlapping_areas()
if actionables.size() > 0:
is_talking = true
actionables[0].action(is_talking)
return
func _physics_process(delta):
# Apply gravity
if not is_on_floor():
var gravity_multiplier = FALL_GRAVITY_MULTIPLIER if velocity.y > 0 else 2
velocity.y += GRAVITY * gravity_multiplier * delta
if !is_talking:
# Handle Jump
if Input.is_action_just_pressed("jump") and is_on_floor():
start_jump()
if is_jumping:
if Input.is_action_pressed("jump"):
continue_jump(delta)
else:
end_jump()
# Handle horizontal movement
var direction = Input.get_axis("move_left", "move_right")
if direction < 0:
isFacingRight = false
elif direction > 0:
isFacingRight = true
if isFacingRight:
$Marker2D.scale.x = 1
$AnimatedSprite2D.scale.x = 1 * 0.2
else:
$Marker2D.scale.x = -1
$AnimatedSprite2D.scale.x = -1 * 0.2
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
func start_jump():
velocity.y = JUMP_VELOCITY
is_jumping = true
func continue_jump(delta):
pass
func end_jump():
if velocity.y < 0:
velocity.y *= 0.20
is_jumping = false
func _on_kill_zone_body_entered(body: Node2D) -> void:
pass # Replace with function body.