Flopsy/objects/characters/character.gd

38 lines
818 B
GDScript3
Raw Normal View History

2022-07-17 14:24:15 +02:00
extends KinematicBody2D
2022-07-18 03:28:10 +02:00
var velocity = Vector2(0, 0)
2022-07-27 12:51:26 +02:00
var snap = Vector2.ZERO
var last_time_on_floor : int = 0
func _ready():
_enable_snap()
2022-07-17 14:24:15 +02:00
2022-07-18 03:28:10 +02:00
func _process_gravity(delta):
2022-07-17 14:24:15 +02:00
if not is_on_floor():
2022-07-27 12:51:26 +02:00
if last_time_on_floor == 0:
last_time_on_floor = OS.get_ticks_msec()
velocity.y += GlobalConfig.GRAVITY.y * delta
2022-07-17 14:24:15 +02:00
else:
2022-07-27 12:51:26 +02:00
last_time_on_floor = 0
_enable_snap()
velocity.y = 0
2022-07-17 14:24:15 +02:00
if is_on_ceiling():
2022-07-18 03:28:10 +02:00
velocity.y = 1
2022-07-17 14:24:15 +02:00
func _physics_process(delta):
2022-07-27 12:51:26 +02:00
move_and_slide_with_snap(velocity, snap, Vector2.UP)
_process_gravity(delta)
func _disable_snap():
snap = Vector2.ZERO
func _enable_snap():
snap = GlobalConfig.SNAP
func _check_jump():
print(OS.get_ticks_msec() - last_time_on_floor)
if last_time_on_floor == 0:
return true
return OS.get_ticks_msec() - last_time_on_floor <= GlobalConfig.JUMP_COYOTE