allow long pressing jump

This commit is contained in:
Arnaud Vergnet 2021-05-06 10:37:14 +02:00
parent 225a55bacd
commit 4c870105a8
3 changed files with 25 additions and 9 deletions

View file

@ -26,10 +26,8 @@ func move():
func _on_VisibilityNotifier2D_viewport_entered(viewport: Viewport) -> void:
print("viewport_entered")
emit_signal("viewport_entered", self)
func _on_VisibilityNotifier2D_viewport_exited(viewport: Viewport) -> void:
print("viewport_exited")
emit_signal("viewport_exited", self)

View file

@ -3,7 +3,8 @@ extends KinematicBody2D
var speed = Vector2.ZERO
export var jump_speed = 1100.0
export var gravity = 45.0
export var gravity = 60.0
export var jump_time = 0.2
export var max_lives = 1
enum {
@ -25,17 +26,20 @@ var state = RUN
var au_sol = true
var current_lives = max_lives
var pressing_jump = false
onready var animation = $AnimatedSprite
onready var bonus_texture = $BonusControl/Sprite
onready var bonus_tween = $BonusControl/Tween
onready var bonus_timer = $BonusControl/Timer
onready var animation := $AnimatedSprite
onready var bonus_texture := $BonusControl/Sprite
onready var bonus_tween := $BonusControl/Tween
onready var bonus_timer := $BonusControl/Timer
onready var jump_timer := $JumpTimer
signal hit()
signal die()
signal score()
func _ready():
jump_timer.wait_time = jump_time
stop()
@ -48,16 +52,22 @@ func _physics_process(delta):
speed = Vector2.ZERO
speed.y -= jump_speed
animation.play("man_jump")
state = IDLE
if not pressing_jump:
state = IDLE
IDLE:
pass
speed.y += gravity
move_and_collide(speed*delta)
func _input(event):
func _input(event: InputEvent):
if player_enabled and state == RUN and event.is_action_pressed(jump_key):
jump_timer.start()
pressing_jump = true
state = JUMP
elif event.is_action_released(jump_key):
jump_timer.stop()
pressing_jump = false
func _on_Area2D_body_entered(body):
@ -109,3 +119,7 @@ func _on_Timer_timeout() -> void:
bonus_tween.stop_all()
bonus_tween.interpolate_property(bonus_texture, "modulate", null, Color(1, 1, 1, 0), 0.3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
bonus_tween.start()
func _on_JumpTimer_timeout() -> void:
pressing_jump = false

View file

@ -85,6 +85,10 @@ texture = ExtResource( 22 )
[node name="Timer" type="Timer" parent="BonusControl"]
wait_time = 1.5
[node name="JumpTimer" type="Timer" parent="."]
one_shot = true
[connection signal="body_entered" from="Area2D" to="." method="_on_Area2D_body_entered"]
[connection signal="body_exited" from="Area2D" to="." method="_on_Area2D_body_exited"]
[connection signal="timeout" from="BonusControl/Timer" to="." method="_on_Timer_timeout"]
[connection signal="timeout" from="JumpTimer" to="." method="_on_JumpTimer_timeout"]