mirror of
https://github.com/Steffo99/looping-for-loops.git
synced 2024-11-25 17:44:22 +00:00
✏️ Add quick fall to player jumps
credulone
This commit is contained in:
parent
b8e25a15f5
commit
b3e6fa1aa9
4 changed files with 30 additions and 14 deletions
|
@ -9,9 +9,13 @@
|
||||||
[node name="Conductor" parent="." instance=ExtResource( 2 )]
|
[node name="Conductor" parent="." instance=ExtResource( 2 )]
|
||||||
song_offset = 200000.0
|
song_offset = 200000.0
|
||||||
|
|
||||||
|
[node name="Player" parent="." instance=ExtResource( 1 )]
|
||||||
|
position = Vector2( 622.258, 379.938 )
|
||||||
|
|
||||||
[node name="ConveyorBelt" parent="." instance=ExtResource( 3 )]
|
[node name="ConveyorBelt" parent="." instance=ExtResource( 3 )]
|
||||||
position = Vector2( 662.439, 610.32 )
|
position = Vector2( 640, 700 )
|
||||||
conveyor_speed = 100.0
|
conveyor_speed = 100.0
|
||||||
|
|
||||||
[node name="Player" parent="." instance=ExtResource( 1 )]
|
[node name="ConveyorBelt2" parent="." instance=ExtResource( 3 )]
|
||||||
position = Vector2( 918.923, 436.874 )
|
position = Vector2( 640, 20 )
|
||||||
|
conveyor_speed = -100.0
|
||||||
|
|
|
@ -9,10 +9,7 @@ extents = Vector2( 20, 20 )
|
||||||
[node name="Player" type="KinematicBody2D"]
|
[node name="Player" type="KinematicBody2D"]
|
||||||
collision_layer = 2
|
collision_layer = 2
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
gravity = Vector2( 0, 10 )
|
jump_buffer_msec = 500.0
|
||||||
move_speed = 300.0
|
|
||||||
jump_speed = 500.0
|
|
||||||
jump_buffer_msec = 64.0
|
|
||||||
|
|
||||||
[node name="Sprite" type="Sprite" parent="."]
|
[node name="Sprite" type="Sprite" parent="."]
|
||||||
texture = ExtResource( 1 )
|
texture = ExtResource( 1 )
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
extends ExtendedKinematicBody2D
|
extends ExtendedKinematicBody2D
|
||||||
class_name Player
|
class_name Player
|
||||||
|
|
||||||
export(Vector2) var gravity: Vector2
|
export(Vector2) var gravity: Vector2 = Vector2(0, 10)
|
||||||
var speed: Vector2 = Vector2.ZERO
|
var speed: Vector2 = Vector2.ZERO
|
||||||
|
|
||||||
export(float) var move_speed: float
|
export(float) var move_speed: float = 300
|
||||||
export(float) var jump_speed: float
|
export(float) var jump_speed: float = 500
|
||||||
export(float) var jump_buffer_msec: float
|
export(float) var jump_buffer_msec: float = 64
|
||||||
|
export(float) var quick_fall_gravity_multiplier: float = 4
|
||||||
|
|
||||||
var can_jump = false
|
var can_jump: bool = false
|
||||||
var jump_buffer = 0
|
var jump_buffer: int = 0
|
||||||
|
|
||||||
|
var is_quick_falling: bool = false
|
||||||
|
var quick_fall_buffer: int = 0
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
|
@ -20,7 +24,11 @@ func _physics_process(delta):
|
||||||
var gravity_speed = speed * up_normal
|
var gravity_speed = speed * up_normal
|
||||||
speed -= gravity_speed * floor_normal
|
speed -= gravity_speed * floor_normal
|
||||||
can_jump = true
|
can_jump = true
|
||||||
|
is_quick_falling = false
|
||||||
|
|
||||||
|
if is_quick_falling:
|
||||||
|
speed += gravity * quick_fall_gravity_multiplier
|
||||||
|
else:
|
||||||
speed += gravity
|
speed += gravity
|
||||||
|
|
||||||
var current_time = OS.get_ticks_msec()
|
var current_time = OS.get_ticks_msec()
|
||||||
|
@ -28,10 +36,16 @@ func _physics_process(delta):
|
||||||
if Input.is_action_just_pressed("plr_up"):
|
if Input.is_action_just_pressed("plr_up"):
|
||||||
jump_buffer = current_time
|
jump_buffer = current_time
|
||||||
|
|
||||||
|
if Input.is_action_just_released("plr_up"):
|
||||||
|
quick_fall_buffer = OS.get_ticks_msec()
|
||||||
|
|
||||||
if can_jump and current_time - jump_buffer <= jump_buffer_msec:
|
if can_jump and current_time - jump_buffer <= jump_buffer_msec:
|
||||||
speed += up_normal * jump_speed
|
speed += up_normal * jump_speed
|
||||||
can_jump = false
|
can_jump = false
|
||||||
|
|
||||||
|
if quick_fall_buffer > jump_buffer:
|
||||||
|
is_quick_falling = true
|
||||||
|
|
||||||
var movement = speed
|
var movement = speed
|
||||||
|
|
||||||
if is_on_floor():
|
if is_on_floor():
|
||||||
|
|
|
@ -45,6 +45,7 @@ run/main_scene="res://Scenes/Main.tscn"
|
||||||
|
|
||||||
window/size/width=1280
|
window/size/width=1280
|
||||||
window/size/height=720
|
window/size/height=720
|
||||||
|
window/size/resizable=false
|
||||||
|
|
||||||
[input]
|
[input]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue