item/fromage: reinitialisation timé
Un timer redéclenche l'apparition du fromage au bout d'un certain temps. Il suffit de paramètrer la variable CHEESE_RESPAWN_TIME pour que ça soit customisable à l'envie.
This commit is contained in:
		| @@ -8,7 +8,7 @@ atlas = ExtResource("1_rx0yq") | |||||||
| region = Rect2(16, 0, 16, 16) | region = Rect2(16, 0, 16, 16) | ||||||
|  |  | ||||||
| [sub_resource type="CircleShape2D" id="CircleShape2D_xry4i"] | [sub_resource type="CircleShape2D" id="CircleShape2D_xry4i"] | ||||||
| radius = 6.0 | radius = 4.0 | ||||||
|  |  | ||||||
| [sub_resource type="Animation" id="Animation_r46qo"] | [sub_resource type="Animation" id="Animation_r46qo"] | ||||||
| resource_name = "RESET" | resource_name = "RESET" | ||||||
| @@ -65,6 +65,18 @@ tracks/0/keys = { | |||||||
| "update": 0, | "update": 0, | ||||||
| "values": [Vector2(0, 0), Vector2(0, -2), Vector2(0, 0)] | "values": [Vector2(0, 0), Vector2(0, -2), Vector2(0, 0)] | ||||||
| } | } | ||||||
|  | tracks/1/type = "value" | ||||||
|  | tracks/1/imported = false | ||||||
|  | tracks/1/enabled = true | ||||||
|  | tracks/1/path = NodePath("Sprite2D:modulate") | ||||||
|  | tracks/1/interp = 1 | ||||||
|  | tracks/1/loop_wrap = true | ||||||
|  | tracks/1/keys = { | ||||||
|  | "times": PackedFloat32Array(0.1, 1), | ||||||
|  | "transitions": PackedFloat32Array(1, 1), | ||||||
|  | "update": 0, | ||||||
|  | "values": [Color(1, 1, 1, 1), Color(1, 1, 1, 1)] | ||||||
|  | } | ||||||
|  |  | ||||||
| [sub_resource type="Animation" id="Animation_jemsl"] | [sub_resource type="Animation" id="Animation_jemsl"] | ||||||
| resource_name = "picked" | resource_name = "picked" | ||||||
| @@ -117,6 +129,7 @@ collision_layer = 64 | |||||||
| script = ExtResource("1_2l3x1") | script = ExtResource("1_2l3x1") | ||||||
|  |  | ||||||
| [node name="Sprite2D" type="Sprite2D" parent="."] | [node name="Sprite2D" type="Sprite2D" parent="."] | ||||||
|  | scale = Vector2(0.7, 0.7) | ||||||
| texture = SubResource("AtlasTexture_7rdb1") | texture = SubResource("AtlasTexture_7rdb1") | ||||||
|  |  | ||||||
| [node name="CollisionShape2D" type="CollisionShape2D" parent="."] | [node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||||||
| @@ -128,4 +141,8 @@ libraries = { | |||||||
| "": SubResource("AnimationLibrary_4iwa0") | "": SubResource("AnimationLibrary_4iwa0") | ||||||
| } | } | ||||||
|  |  | ||||||
|  | [node name="Timer" type="Timer" parent="."] | ||||||
|  |  | ||||||
| [connection signal="body_entered" from="." to="." method="_on_body_entered"] | [connection signal="body_entered" from="." to="." method="_on_body_entered"] | ||||||
|  | [connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_animation_player_animation_finished"] | ||||||
|  | [connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"] | ||||||
|   | |||||||
| @@ -2,7 +2,24 @@ class_name NormalCheese extends Area2D | |||||||
|  |  | ||||||
|  |  | ||||||
| @onready var animation_player := $AnimationPlayer as AnimationPlayer | @onready var animation_player := $AnimationPlayer as AnimationPlayer | ||||||
|  | @onready var timer := $Timer as Timer | ||||||
|  | @export var CHEESE_RESPAWN_TIME : int = 1 | ||||||
|  | var picked :bool = false | ||||||
|  |  | ||||||
| func _on_body_entered(body: Node2D) -> void: | func _on_body_entered(body: Node2D) -> void: | ||||||
|  |     if not picked: | ||||||
|         animation_player.play(&"picked") |         animation_player.play(&"picked") | ||||||
|         (body as Princess).cheese_collected.emit() |         (body as Princess).cheese_collected.emit() | ||||||
|  |         picked = true | ||||||
|  |         # Le fromage peut être à utilisation unique | ||||||
|  |         if CHEESE_RESPAWN_TIME > 0: | ||||||
|  |             timer.start(CHEESE_RESPAWN_TIME) | ||||||
|  |  | ||||||
|  | func _on_timer_timeout() -> void: | ||||||
|  |     timer.stop() | ||||||
|  |     animation_player.play(&"RESET") | ||||||
|  |  | ||||||
|  | func _on_animation_player_animation_finished(anim_name: StringName) -> void: | ||||||
|  |     if anim_name == "RESET": | ||||||
|  |         animation_player.play(&"cheese") | ||||||
|  |         picked = false | ||||||
|   | |||||||
| @@ -1991,4 +1991,8 @@ metadata/_edit_group_ = true | |||||||
| [node name="Node" type="Node" parent="."] | [node name="Node" type="Node" parent="."] | ||||||
|  |  | ||||||
| [node name="Fromage normal" parent="Node" instance=ExtResource("3_3jwuu")] | [node name="Fromage normal" parent="Node" instance=ExtResource("3_3jwuu")] | ||||||
| position = Vector2(-101, -33) | position = Vector2(-80, -83) | ||||||
|  |  | ||||||
|  | [node name="Fromage normal2" parent="Node" instance=ExtResource("3_3jwuu")] | ||||||
|  | position = Vector2(50, 142) | ||||||
|  | CHEESE_RESPAWN_TIME = 10 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Thomas Lavocat
					Thomas Lavocat