Started working on a floaty field
This commit is contained in:
@@ -3,13 +3,24 @@ class_name BoxBoy extends CharacterBody2D
|
||||
@onready var _sprite = $AnimatedSprite2D
|
||||
|
||||
const MOVE_FORCE: int = 300
|
||||
const JUMP_FORCE: int = 800
|
||||
const JUMP_FORCE: int = 500 #about 4 tiles
|
||||
|
||||
const GRAVITY_UP: int = 15
|
||||
const GRAVITY_DOWN: int = 30
|
||||
const GRAVITY_RISING: int = 15
|
||||
const GRAVITY_FALLING: int = 30
|
||||
|
||||
#bouncy platform
|
||||
const BOUNCE_FORCE: int = -820 #about 10 tiles
|
||||
var just_bounced: bool = false #allow max bounce height (i.e. ignore jump input)
|
||||
|
||||
#floaty field
|
||||
const FLOATY_RISING: int = -10
|
||||
const FLOATY_FALLING: int = -30
|
||||
var floaty_counter: int = 0
|
||||
|
||||
#limits
|
||||
const MAX_MOVE_SPEED: int = 300
|
||||
const MAX_FALL_SPEED: int = 500
|
||||
const MAX_FLOATY_SPEED: int = -300
|
||||
|
||||
#boilerplate
|
||||
func _ready():
|
||||
@@ -17,19 +28,31 @@ func _ready():
|
||||
|
||||
#movement
|
||||
func _physics_process(_delta) -> void:
|
||||
#input, jumps
|
||||
#jump input
|
||||
if is_on_floor() and Input.is_action_just_pressed("input_jump"):
|
||||
velocity.y -= JUMP_FORCE
|
||||
|
||||
if floaty_counter > 0:
|
||||
#inverted - could tweak the rise?
|
||||
if is_rising():
|
||||
velocity.y += FLOATY_RISING
|
||||
else:
|
||||
velocity.y += FLOATY_FALLING
|
||||
#fall faster than you rise
|
||||
if is_airborne_rising() and Input.is_action_pressed("input_jump"):
|
||||
velocity.y += GRAVITY_UP
|
||||
elif is_rising() and (Input.is_action_pressed("input_jump") or just_bounced):
|
||||
velocity.y += GRAVITY_RISING
|
||||
else:
|
||||
velocity.y += GRAVITY_DOWN
|
||||
velocity.y += GRAVITY_FALLING
|
||||
just_bounced = false
|
||||
|
||||
if is_airborne_falling() and velocity.y > MAX_FALL_SPEED:
|
||||
#terminal velocity
|
||||
if floaty_counter > 0:
|
||||
if velocity.y < MAX_FLOATY_SPEED:
|
||||
velocity.y = MAX_FLOATY_SPEED
|
||||
elif is_falling() and velocity.y > MAX_FALL_SPEED:
|
||||
velocity.y = MAX_FALL_SPEED
|
||||
|
||||
|
||||
print(velocity.y)
|
||||
#input, walking
|
||||
var move_dir = Input.get_axis("input_left", "input_right")
|
||||
|
||||
@@ -55,10 +78,19 @@ func _on_animation_finished() -> void:
|
||||
_sprite.play("idle", 2)
|
||||
|
||||
#utils
|
||||
func is_airborne() -> bool: return !is_on_floor()
|
||||
func is_airborne_rising() -> bool: return !is_on_floor() and velocity.y < 0
|
||||
func is_airborne_falling() -> bool: return !is_on_floor() and velocity.y >= 0
|
||||
#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 -= JUMP_FORCE
|
||||
velocity.y = BOUNCE_FORCE
|
||||
just_bounced = true
|
||||
|
||||
func enable_float() -> void:
|
||||
floaty_counter += 1
|
||||
pass
|
||||
|
||||
func disable_float() -> void:
|
||||
floaty_counter -= 1
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user