52 lines
979 B
GDScript
52 lines
979 B
GDScript
extends CharacterBody2D
|
|
|
|
const SPEED = 400.0
|
|
|
|
const GRAVITY_MULT = 0.8
|
|
|
|
const JUMP_VELOCITY = -410.0
|
|
|
|
var fall_timer = 0.0
|
|
|
|
var jumps = 0
|
|
|
|
func _ready() -> void:
|
|
pass
|
|
|
|
func _process(delta: float) -> void:
|
|
if Input.is_action_just_pressed("jump"):
|
|
if is_on_floor():
|
|
velocity.y = JUMP_VELOCITY
|
|
elif !is_on_floor() and jumps >= 1:
|
|
jumps -= 1
|
|
velocity.y = JUMP_VELOCITY
|
|
|
|
if Input.is_action_pressed("jump") and is_on_wall_only():
|
|
print("WALL HANGING")
|
|
#velocity.y = 0
|
|
#velocity.x = 0
|
|
|
|
var direction = Input.get_axis("move_left","move_right")
|
|
if direction:
|
|
velocity.x = direction * SPEED
|
|
else:
|
|
velocity.x = move_toward(velocity.x, 0, SPEED)
|
|
|
|
fall_timer += 1*delta
|
|
if is_on_floor():
|
|
fall_timer = 0
|
|
jumps = 1
|
|
|
|
if is_on_wall():
|
|
jumps = 1
|
|
|
|
if fall_timer>3:
|
|
get_tree().reload_current_scene()
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
if not is_on_floor():
|
|
velocity += (get_gravity() * GRAVITY_MULT) * delta
|
|
|
|
move_and_slide()
|