added doublejump:

This commit is contained in:
pennyrigate 2022-12-17 00:46:54 -05:00
parent 28319efe0d
commit 457333f2b2
3 changed files with 142 additions and 16 deletions

View file

@ -1,5 +1,6 @@
extends KinematicBody2D
##CLEAN UP CODE LATER
##Children
onready var sprite = $Sprite
onready var climb_ray = $ClimbRay
@ -17,7 +18,8 @@ var gravity = 12
var jump_pressure = 0
var jump_force = 150
var current_ladder = null
##Attacking
var can_doublejump = true
var doublejump_force = 120
@ -77,6 +79,7 @@ func _process_walk():
func _process_idle_walk():
velocity.y = 0
can_doublejump = true
#Goto Fall
if !is_on_floor(): current_state = State.FALL
#Goto Jump
@ -90,6 +93,7 @@ func _process_idle_walk():
func _process_jump():
jump_pressure += 1
move(walk_speed,0,true)
check_double_jump()
#Pressure sensitive jump
if jump_pressure == 15 or Input.is_action_just_released("jump"):
velocity.y = -jump_force / 4
@ -97,7 +101,8 @@ func _process_jump():
current_state = State.FALL
func _process_fall():
anims.play("jump")
if anims.get_current_animation() != "doublejump": anims.play("jump")
check_double_jump()
#anims.play("jump")
move(walk_speed,0,true)
#Return to idle
@ -139,7 +144,7 @@ func _process_sword():
func check_jump():
if Input.is_action_just_pressed("jump") && !Input.is_action_pressed("ui_down"):
if Input.is_action_just_pressed("jump"):
#Detach ladder
if current_state == State.CLIMB:
Game.ac_climb.set_stream(null)
@ -154,6 +159,11 @@ func check_jump():
velocity.y = -jump_force
move(walk_speed,0,true)
func check_double_jump():
if Input.is_action_just_pressed("jump") && can_doublejump:
can_doublejump = false
velocity.y = -doublejump_force
anims.play("doublejump")
func move(hsp,vsp,flip:bool):
velocity.x = hsp * axis.x