diff --git a/BoxBoy/BoxBoy.gd b/BoxBoy/BoxBoy.gd index 99186b9..86cbca5 100644 --- a/BoxBoy/BoxBoy.gd +++ b/BoxBoy/BoxBoy.gd @@ -16,20 +16,31 @@ var just_bounced: bool = false #allow max bounce height (i.e. ignore jump input) const MAX_MOVE_SPEED: int = 300 const MAX_FALL_SPEED: int = 500 +#look and feel tweaks +const COYOTE_DELAY: float = 0.0 +var coyote_drop: bool = true + #boilerplate func _ready(): _sprite.play("idle", 1) #movement func _physics_process(_delta) -> void: + print(Engine.get_frames_per_second()) + #fall off a ledge (with coyote time) + if is_on_floor(): + coyote_drop = false + else: + get_tree().create_timer(COYOTE_DELAY).timeout.connect(_coyote_timer_callback) + #jump input if is_on_floor() and Input.is_action_just_pressed("input_jump"): velocity.y -= JUMP_FORCE - + coyote_drop = true #normally, fall faster than you rise - elif is_rising() and (Input.is_action_pressed("input_jump") or just_bounced): + elif velocity.y < 0 and (Input.is_action_pressed("input_jump") or just_bounced): velocity.y += GRAVITY_RISING - else: + elif just_bounced or coyote_drop: velocity.y += GRAVITY_FALLING just_bounced = false @@ -45,7 +56,7 @@ func _physics_process(_delta) -> void: velocity.x = log(abs(velocity.x)) * sign(velocity.x) #terminal velocity (in all directions) - if is_falling() and velocity.y > MAX_FALL_SPEED: + if velocity.y > MAX_FALL_SPEED: velocity.y = MAX_FALL_SPEED if abs(velocity.x) > MAX_MOVE_SPEED: velocity.x = MAX_MOVE_SPEED * sign(velocity.x) @@ -61,11 +72,10 @@ func _on_animation_finished() -> void: _sprite.play("idle", 2) #utils -#func is_airborne() -> bool: return !is_on_floor() -func is_rising() -> bool: return velocity.y < 0 -func is_falling() -> bool: return velocity.y >= 0 - -#external actions func apply_bounce() -> void: velocity.y = BOUNCE_FORCE just_bounced = true + +func _coyote_timer_callback() -> void: + coyote_drop = !is_on_floor() + print("set to ", coyote_drop)