Browse Source

allow long pressing jump

Arnaud Vergnet 4 months ago
parent
commit
4c870105a8

+ 0
- 2
mini-game/scenes/decor/ForegroundSprite.gd View File

@@ -26,10 +26,8 @@ func move():
26 26
 
27 27
 
28 28
 func _on_VisibilityNotifier2D_viewport_entered(viewport: Viewport) -> void:
29
-	print("viewport_entered")
30 29
 	emit_signal("viewport_entered", self)
31 30
 
32 31
 
33 32
 func _on_VisibilityNotifier2D_viewport_exited(viewport: Viewport) -> void:
34
-	print("viewport_exited")
35 33
 	emit_signal("viewport_exited", self)

+ 21
- 7
mini-game/scenes/players/player.gd View File

@@ -3,7 +3,8 @@ extends KinematicBody2D
3 3
 var speed = Vector2.ZERO
4 4
 
5 5
 export var jump_speed = 1100.0
6
-export var gravity = 45.0
6
+export var gravity = 60.0
7
+export var jump_time = 0.2
7 8
 export var max_lives = 1
8 9
 
9 10
 enum {
@@ -25,17 +26,20 @@ var state = RUN
25 26
 var au_sol = true
26 27
 
27 28
 var current_lives = max_lives
29
+var pressing_jump = false
28 30
 
29
-onready var animation = $AnimatedSprite
30
-onready var bonus_texture = $BonusControl/Sprite
31
-onready var bonus_tween = $BonusControl/Tween
32
-onready var bonus_timer = $BonusControl/Timer
31
+onready var animation := $AnimatedSprite
32
+onready var bonus_texture := $BonusControl/Sprite
33
+onready var bonus_tween := $BonusControl/Tween
34
+onready var bonus_timer := $BonusControl/Timer
35
+onready var jump_timer := $JumpTimer
33 36
 
34 37
 signal hit()
35 38
 signal die()
36 39
 signal score()
37 40
 
38 41
 func _ready():
42
+	jump_timer.wait_time = jump_time
39 43
 	stop()
40 44
 
41 45
 
@@ -48,16 +52,22 @@ func _physics_process(delta):
48 52
 				speed = Vector2.ZERO
49 53
 				speed.y -= jump_speed
50 54
 				animation.play("man_jump")
51
-				state = IDLE
55
+				if not pressing_jump:
56
+					state = IDLE
52 57
 			IDLE:
53 58
 				pass
54 59
 		speed.y += gravity
55 60
 		move_and_collide(speed*delta)
56 61
 
57 62
 
58
-func _input(event):
63
+func _input(event: InputEvent):
59 64
 	if player_enabled and state == RUN and event.is_action_pressed(jump_key):
65
+			jump_timer.start()
66
+			pressing_jump = true
60 67
 			state = JUMP
68
+	elif event.is_action_released(jump_key):
69
+		jump_timer.stop()
70
+		pressing_jump = false
61 71
 
62 72
 
63 73
 func _on_Area2D_body_entered(body):
@@ -109,3 +119,7 @@ func _on_Timer_timeout() -> void:
109 119
 	bonus_tween.stop_all()
110 120
 	bonus_tween.interpolate_property(bonus_texture, "modulate", null, Color(1, 1, 1, 0), 0.3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
111 121
 	bonus_tween.start()
122
+
123
+
124
+func _on_JumpTimer_timeout() -> void:
125
+		pressing_jump = false

+ 4
- 0
mini-game/scenes/players/player.tscn View File

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

Loading…
Cancel
Save