Double Jump
This commit is contained in:
parent
abb03863b9
commit
7f8aabadcf
|
@ -17,7 +17,8 @@ export (int) var bullet_speed = 250
|
||||||
var invincible = false setget set_invincible
|
var invincible = false setget set_invincible
|
||||||
var motion = Vector2.ZERO
|
var motion = Vector2.ZERO
|
||||||
var snap_vector = Vector2.ZERO
|
var snap_vector = Vector2.ZERO
|
||||||
var just_jumped= false
|
var just_jumped = false
|
||||||
|
var double_jump = true
|
||||||
|
|
||||||
onready var sprite = $Sprite
|
onready var sprite = $Sprite
|
||||||
onready var animation = $Animation
|
onready var animation = $Animation
|
||||||
|
@ -78,16 +79,23 @@ func update_snap_vector():
|
||||||
if is_on_floor():
|
if is_on_floor():
|
||||||
snap_vector = Vector2.DOWN
|
snap_vector = Vector2.DOWN
|
||||||
|
|
||||||
|
func jump(force):
|
||||||
|
Utils.instance_scene_on_main(JumpEffect, global_position)
|
||||||
|
motion.y = -force
|
||||||
|
snap_vector = Vector2.ZERO
|
||||||
|
|
||||||
func jump_check():
|
func jump_check():
|
||||||
if is_on_floor() or coyoteJumpTimer.time_left > 0:
|
if is_on_floor() or coyoteJumpTimer.time_left > 0:
|
||||||
if Input.is_action_just_pressed("ui_select"):
|
if Input.is_action_just_pressed("ui_select"):
|
||||||
Utils.instance_scene_on_main(JumpEffect, global_position)
|
jump(jump_force)
|
||||||
motion.y = -jump_force
|
|
||||||
snap_vector = Vector2.ZERO
|
|
||||||
just_jumped = true
|
just_jumped = true
|
||||||
else:
|
else:
|
||||||
if Input.is_action_just_released("ui_select") and motion.y < -jump_force/2:
|
if Input.is_action_just_released("ui_select") and motion.y < -jump_force/2:
|
||||||
motion.y = motion.y/2
|
motion.y = motion.y/2
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed("ui_select") and double_jump:
|
||||||
|
jump(jump_force * .75)
|
||||||
|
double_jump = false
|
||||||
|
|
||||||
func apply_gravity(delta):
|
func apply_gravity(delta):
|
||||||
if not is_on_floor():
|
if not is_on_floor():
|
||||||
|
@ -121,6 +129,7 @@ func move():
|
||||||
motion.x = last_motion.x
|
motion.x = last_motion.x
|
||||||
#create_dust_effect()
|
#create_dust_effect()
|
||||||
Utils.instance_scene_on_main(JumpEffect, global_position)
|
Utils.instance_scene_on_main(JumpEffect, global_position)
|
||||||
|
double_jump = true
|
||||||
|
|
||||||
|
|
||||||
# Just left ground
|
# Just left ground
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
[ext_resource path="res://Scenes/Objects/Hurtbox.tscn" type="PackedScene" id=5]
|
[ext_resource path="res://Scenes/Objects/Hurtbox.tscn" type="PackedScene" id=5]
|
||||||
[ext_resource path="res://Scenes/Player/PlayerCollider.tres" type="Shape2D" id=6]
|
[ext_resource path="res://Scenes/Player/PlayerCollider.tres" type="Shape2D" id=6]
|
||||||
|
|
||||||
[sub_resource type="Animation" id=2]
|
[sub_resource type="Animation" id=1]
|
||||||
resource_name = "Idle"
|
resource_name = "Idle"
|
||||||
length = 1.2
|
length = 1.2
|
||||||
loop = true
|
loop = true
|
||||||
|
@ -24,7 +24,7 @@ tracks/0/keys = {
|
||||||
"values": [ 0, 1, 2, 3 ]
|
"values": [ 0, 1, 2, 3 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id=3]
|
[sub_resource type="Animation" id=2]
|
||||||
resource_name = "Jump"
|
resource_name = "Jump"
|
||||||
length = 0.1
|
length = 0.1
|
||||||
tracks/0/type = "value"
|
tracks/0/type = "value"
|
||||||
|
@ -40,7 +40,7 @@ tracks/0/keys = {
|
||||||
"values": [ 11 ]
|
"values": [ 11 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id=4]
|
[sub_resource type="Animation" id=3]
|
||||||
resource_name = "Run"
|
resource_name = "Run"
|
||||||
length = 0.6
|
length = 0.6
|
||||||
loop = true
|
loop = true
|
||||||
|
@ -74,7 +74,7 @@ tracks/1/keys = {
|
||||||
} ]
|
} ]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id=5]
|
[sub_resource type="Animation" id=4]
|
||||||
resource_name = "Blink"
|
resource_name = "Blink"
|
||||||
length = 0.9
|
length = 0.9
|
||||||
tracks/0/type = "value"
|
tracks/0/type = "value"
|
||||||
|
@ -126,12 +126,12 @@ position = Vector2( 0, -7 )
|
||||||
shape = ExtResource( 6 )
|
shape = ExtResource( 6 )
|
||||||
|
|
||||||
[node name="Animation" type="AnimationPlayer" parent="."]
|
[node name="Animation" type="AnimationPlayer" parent="."]
|
||||||
anims/Idle = SubResource( 2 )
|
anims/Idle = SubResource( 1 )
|
||||||
anims/Jump = SubResource( 3 )
|
anims/Jump = SubResource( 2 )
|
||||||
anims/Run = SubResource( 4 )
|
anims/Run = SubResource( 3 )
|
||||||
|
|
||||||
[node name="BlinkAnimator" type="AnimationPlayer" parent="."]
|
[node name="BlinkAnimator" type="AnimationPlayer" parent="."]
|
||||||
anims/Blink = SubResource( 5 )
|
anims/Blink = SubResource( 4 )
|
||||||
|
|
||||||
[node name="Debug" parent="." instance=ExtResource( 3 )]
|
[node name="Debug" parent="." instance=ExtResource( 3 )]
|
||||||
visible = false
|
visible = false
|
||||||
|
|
Loading…
Reference in New Issue