Wall slide

This commit is contained in:
Felipe M 2021-02-07 12:01:22 +01:00
parent ef19463d6e
commit 11b0e77b48
Signed by: fmartingr
GPG key ID: 716BC147715E716F
2 changed files with 88 additions and 11 deletions

View file

@ -11,9 +11,17 @@ export (int) var max_speed = 64
export (float) var friction = 0.25
export (int) var gravity = 200
export (int) var jump_force = 128
export (int) var wall_slide_speed = 48
export (int) var max_wall_slide_speed = 128
export (int) var max_slope = 46
export (int) var bullet_speed = 250
enum {
MOVE,
WALL_SLIDE
}
var state = MOVE
var invincible = false setget set_invincible
var motion = Vector2.ZERO
var snap_vector = Vector2.ZERO
@ -37,15 +45,33 @@ func _ready():
func _physics_process(delta):
just_jumped = false
var input_vector = get_input_vector()
apply_horizontal_force(input_vector, delta)
apply_friction(input_vector)
update_snap_vector()
jump_check()
apply_gravity(delta)
update_animations(input_vector)
move()
match state:
MOVE:
var input_vector = get_input_vector()
apply_horizontal_force(input_vector, delta)
apply_friction(input_vector)
update_snap_vector()
jump_check()
apply_gravity(delta)
update_animations(input_vector)
move()
wall_slide_check()
WALL_SLIDE:
animation.play("WallSlide")
var wall_axis = get_wall_axis()
if wall_axis != 0:
sprite.scale.x = wall_axis
wall_slide_jump_check(wall_axis)
wall_slide_drop_check(delta)
wall_slide_fast_slide_check(delta)
move()
wall_detach_check(wall_axis)
if Input.is_action_pressed("fire") and fireBulletTimer.time_left == 0:
fire_bullet()
@ -144,11 +170,45 @@ func move():
if is_on_floor() and get_floor_velocity().length() == 0 and abs(motion.x) < 1:
position.x = last_position.x
func wall_slide_check():
if !is_on_floor() and is_on_wall():
state = WALL_SLIDE
double_jump = true
func get_wall_axis():
var is_right_wall = test_move(transform, Vector2.RIGHT)
var is_left_wall = test_move(transform, Vector2.LEFT)
return int(is_left_wall) - int(is_right_wall)
func wall_slide_jump_check(wall_axis):
if Input.is_action_just_pressed("ui_select"):
motion.x = wall_axis * max_speed
motion.y = -jump_force/1.25
state = MOVE
func wall_slide_drop_check(delta):
if Input.is_action_just_pressed("ui_right"):
motion.x = acceleration * delta
state = MOVE
if Input.is_action_just_pressed("ui_left"):
motion.x = -acceleration * delta
state = MOVE
func wall_slide_fast_slide_check(delta):
var max_slide_speed = wall_slide_speed
if Input.is_action_just_pressed("ui_down"):
max_slide_speed = max_wall_slide_speed
motion.y = min(motion.y + gravity * delta, max_wall_slide_speed)
func wall_detach_check(wall_axis):
if wall_axis == 0 or is_on_floor():
state = MOVE
func _on_Hurtbox_hit(damage):
if not invincible:
PlayerStats.health -= damage
blinkAnimator.play("Blink")
func _on_died():
queue_free()