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

106 lines
2.3 KiB
GDScript3
Raw Normal View History

extends CharacterBody2D
2024-09-25 17:04:33 -04:00
var SPEED = 600.0
const REGSPEED = 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
var isFacingRight: bool
2024-09-25 17:04:33 -04:00
# jumping vars
2024-09-07 12:08:47 -04:00
var jump_timer = 0.0
var is_jumping = false
2024-09-25 17:04:33 -04:00
# crouching vars
var is_crouching = false
var can_stand_up = true
var crouch_speed = 100
# dialouge vars
@export var is_talking = false
2024-09-07 14:12:04 -04:00
@onready var actionableFinder: Area2D = $Marker2D/ActionableFinder
2024-09-25 17:04:33 -04:00
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
2024-09-07 14:12:04 -04:00
func _unhandled_input(event: InputEvent) -> void:
if Input.is_action_just_pressed("ui_accept"):
var actionables = actionableFinder.get_overlapping_areas()
if actionables.size() > 0:
2024-09-25 17:04:33 -04:00
is_talking = true
actionables[0].action(is_talking)
2024-09-07 14:12:04 -04:00
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-25 17:04:33 -04:00
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()
2024-09-25 17:04:33 -04:00
# 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
2024-09-07 12:08:47 -04:00
else:
2024-09-25 17:04:33 -04:00
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.