Skip to content

Commit d832d30

Browse files
committed
Platformer: Implement shake float platform animation
Thanks to the new Block Coding plugin providing access the node's method feature. This commit uses it to play the AnimationPlayer's shake animation by invoking the the Block node's play_shake method of the AnimationPlayer node.
1 parent 2516b78 commit d832d30

File tree

3 files changed

+154
-59
lines changed

3 files changed

+154
-59
lines changed

game-03/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ life.
3535

3636
When the player enters an enemy's HitArea or drops down into the Dangerzone, the
3737
lives' score decreases one. If there is no more life, shows "You Lose!" label.
38+
39+
When the player stands on the floating platform (the player enters a thin area
40+
on top of the platform), it triggers shake platform animation and drops down.

game-03/components/platform/float_platform.tscn

Lines changed: 112 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
[gd_scene load_steps=17 format=3 uid="uid://b7gyfmfo5wtm1"]
1+
[gd_scene load_steps=27 format=3 uid="uid://b7gyfmfo5wtm1"]
22

33
[ext_resource type="TileSet" uid="uid://bmkax0b814rmy" path="res://game-03/spaces/tileset-a.tres" id="1_fn3w6"]
44
[ext_resource type="Script" path="res://addons/block_code/block_code_node/block_code.gd" id="2_xy6in"]
55
[ext_resource type="Script" path="res://addons/block_code/serialization/block_serialization_tree.gd" id="3_6j5ma"]
66
[ext_resource type="Script" path="res://addons/block_code/serialization/block_serialization.gd" id="3_r18qn"]
7-
[ext_resource type="Script" path="res://addons/block_code/code_generation/option_data.gd" id="5_0w7ia"]
7+
[ext_resource type="Script" path="res://addons/block_code/serialization/value_block_serialization.gd" id="5_83svu"]
88
[ext_resource type="Script" path="res://addons/block_code/serialization/block_script_serialization.gd" id="5_a0j4o"]
99
[ext_resource type="Script" path="res://addons/block_code/code_generation/variable_definition.gd" id="6_yyx0f"]
1010

1111
[sub_resource type="RectangleShape2D" id="RectangleShape2D_5opsn"]
1212
size = Vector2(256, 112)
1313

1414
[sub_resource type="Animation" id="Animation_vuag3"]
15-
length = 0.001
1615
tracks/0/type = "value"
1716
tracks/0/imported = false
1817
tracks/0/enabled = true
1918
tracks/0/path = NodePath("RigidBody2D:position")
2019
tracks/0/interp = 1
2120
tracks/0/loop_wrap = true
2221
tracks/0/keys = {
23-
"times": PackedFloat32Array(0),
24-
"transitions": PackedFloat32Array(1),
22+
"times": PackedFloat32Array(0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 1),
23+
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1),
2524
"update": 0,
26-
"values": [Vector2(0, 0)]
25+
"values": [Vector2(0, 0), Vector2(10, -5), Vector2(-10, -5), Vector2(-10, 5), Vector2(0, 5), Vector2(10, 5), Vector2(0, 0), Vector2(0, 600)]
2726
}
2827

2928
[sub_resource type="Animation" id="Animation_o6p3a"]
@@ -48,47 +47,131 @@ _data = {
4847
"shake": SubResource("Animation_o6p3a")
4948
}
5049

51-
[sub_resource type="Resource" id="Resource_y6vh7"]
52-
script = ExtResource("5_0w7ia")
53-
selected = 0
54-
items = ["ahead", "backwards"]
55-
56-
[sub_resource type="Resource" id="Resource_qhpan"]
50+
[sub_resource type="Resource" id="Resource_71dy5"]
5751
script = ExtResource("3_r18qn")
5852
name = &"animationplayer_play"
5953
children = Array[ExtResource("3_r18qn")]([])
6054
arguments = {
6155
"animation": "shake",
62-
"direction": SubResource("Resource_y6vh7")
56+
"direction": "forward",
57+
"wait_mode": "until done"
58+
}
59+
60+
[sub_resource type="Resource" id="Resource_wkip3"]
61+
script = ExtResource("5_83svu")
62+
name = &"get_node"
63+
arguments = {
64+
"path": NodePath("../..")
6365
}
6466

65-
[sub_resource type="Resource" id="Resource_31up2"]
67+
[sub_resource type="Resource" id="Resource_r4ifk"]
68+
script = ExtResource("3_r18qn")
69+
name = &"queue_free_node"
70+
children = Array[ExtResource("3_r18qn")]([])
71+
arguments = {
72+
"node": SubResource("Resource_wkip3")
73+
}
74+
75+
[sub_resource type="Resource" id="Resource_15x7q"]
6676
script = ExtResource("3_r18qn")
6777
name = &"define_method"
68-
children = Array[ExtResource("3_r18qn")]([SubResource("Resource_qhpan")])
78+
children = Array[ExtResource("3_r18qn")]([SubResource("Resource_71dy5"), SubResource("Resource_r4ifk")])
6979
arguments = {
7080
"method_name": &"play_shake"
7181
}
7282

73-
[sub_resource type="Resource" id="Resource_0pxlj"]
83+
[sub_resource type="Resource" id="Resource_bvj0i"]
7484
script = ExtResource("3_6j5ma")
75-
root = SubResource("Resource_31up2")
85+
root = SubResource("Resource_15x7q")
7686
canvas_position = Vector2(100, 75)
7787

7888
[sub_resource type="Resource" id="Resource_6q7jc"]
7989
script = ExtResource("5_a0j4o")
8090
script_inherits = "AnimationPlayer"
81-
block_serialization_trees = Array[ExtResource("3_6j5ma")]([SubResource("Resource_0pxlj")])
91+
block_serialization_trees = Array[ExtResource("3_6j5ma")]([SubResource("Resource_bvj0i")])
8292
variables = Array[ExtResource("6_yyx0f")]([])
8393
generated_script = "extends AnimationPlayer
8494
8595
8696
func play_shake():
87-
if \"ahead\" == \"ahead\":
97+
if 'forward' == \"forward\":
8898
play('shake')
8999
else:
90100
play_backwards('shake')
101+
if 'until done' == \"until done\":
102+
await animation_finished
103+
104+
(get_node(\"../..\")).queue_free()
105+
106+
"
107+
version = 0
108+
109+
[sub_resource type="RectangleShape2D" id="RectangleShape2D_3ufhb"]
110+
size = Vector2(256, 8)
111+
112+
[sub_resource type="Resource" id="Resource_qh7d5"]
113+
script = ExtResource("5_83svu")
114+
name = &"area2d_on_entered:something"
115+
arguments = {}
116+
117+
[sub_resource type="Resource" id="Resource_e6pu7"]
118+
script = ExtResource("5_83svu")
119+
name = &"is_node_in_group"
120+
arguments = {
121+
"group": "player",
122+
"node": SubResource("Resource_qh7d5")
123+
}
124+
125+
[sub_resource type="Resource" id="Resource_xq1nr"]
126+
script = ExtResource("5_83svu")
127+
name = &"get_node"
128+
arguments = {
129+
"path": NodePath("../RigidBody2D/AnimationPlayer")
130+
}
131+
132+
[sub_resource type="Resource" id="Resource_5a1us"]
133+
script = ExtResource("3_r18qn")
134+
name = &"call_method_node"
135+
children = Array[ExtResource("3_r18qn")]([])
136+
arguments = {
137+
"method_name": "play_shake",
138+
"node": SubResource("Resource_xq1nr")
139+
}
140+
141+
[sub_resource type="Resource" id="Resource_d8dep"]
142+
script = ExtResource("3_r18qn")
143+
name = &"if"
144+
children = Array[ExtResource("3_r18qn")]([SubResource("Resource_5a1us")])
145+
arguments = {
146+
"condition": SubResource("Resource_e6pu7")
147+
}
148+
149+
[sub_resource type="Resource" id="Resource_dm1fd"]
150+
script = ExtResource("3_r18qn")
151+
name = &"area2d_on_entered"
152+
children = Array[ExtResource("3_r18qn")]([SubResource("Resource_d8dep")])
153+
arguments = {}
154+
155+
[sub_resource type="Resource" id="Resource_jegfr"]
156+
script = ExtResource("3_6j5ma")
157+
root = SubResource("Resource_dm1fd")
158+
canvas_position = Vector2(75, 75)
159+
160+
[sub_resource type="Resource" id="Resource_cri4e"]
161+
script = ExtResource("5_a0j4o")
162+
script_inherits = "Area2D"
163+
block_serialization_trees = Array[ExtResource("3_6j5ma")]([SubResource("Resource_jegfr")])
164+
variables = Array[ExtResource("6_yyx0f")]([])
165+
generated_script = "extends Area2D
166+
167+
168+
func _init():
169+
body_entered.connect(_on_body_entered)
91170
171+
func _on_body_entered(something: Node2D):
172+
173+
if ((something).is_in_group('player')):
174+
(get_node(\"../RigidBody2D/AnimationPlayer\")).call('play_shake')
92175
93176
"
94177
version = 0
@@ -113,8 +196,17 @@ root_node = NodePath("../..")
113196
libraries = {
114197
"": SubResource("AnimationLibrary_gae7a")
115198
}
116-
autoplay = "RESET"
117199

118200
[node name="BlockCode" type="Node" parent="RigidBody2D/AnimationPlayer"]
119201
script = ExtResource("2_xy6in")
120202
block_script = SubResource("Resource_6q7jc")
203+
204+
[node name="Area2D" type="Area2D" parent="."]
205+
206+
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
207+
position = Vector2(0, -4)
208+
shape = SubResource("RectangleShape2D_3ufhb")
209+
210+
[node name="BlockCode" type="Node" parent="Area2D"]
211+
script = ExtResource("2_xy6in")
212+
block_script = SubResource("Resource_cri4e")

game-03/components/player/player.tscn

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,6 @@
1010
[ext_resource type="Script" path="res://addons/block_code/code_generation/variable_definition.gd" id="7_ubegq"]
1111
[ext_resource type="Texture2D" uid="uid://de3owpoc205t0" path="res://game-03/assets/player-red.png" id="9_d5cr6"]
1212

13-
[sub_resource type="Animation" id="Animation_mnmxn"]
14-
resource_name = "idle"
15-
length = 0.1
16-
tracks/0/type = "value"
17-
tracks/0/imported = false
18-
tracks/0/enabled = true
19-
tracks/0/path = NodePath("Sprite2D:frame")
20-
tracks/0/interp = 1
21-
tracks/0/loop_wrap = true
22-
tracks/0/keys = {
23-
"times": PackedFloat32Array(0),
24-
"transitions": PackedFloat32Array(1),
25-
"update": 1,
26-
"values": [0]
27-
}
28-
2913
[sub_resource type="Animation" id="Animation_82d58"]
3014
length = 0.001
3115
tracks/0/type = "value"
@@ -53,33 +37,40 @@ tracks/1/keys = {
5337
"values": [false]
5438
}
5539

56-
[sub_resource type="Animation" id="Animation_1w8at"]
57-
resource_name = "walk_right"
58-
length = 0.35
59-
loop_mode = 1
40+
[sub_resource type="Animation" id="Animation_7m0y0"]
41+
resource_name = "hit"
42+
length = 0.2
43+
44+
[sub_resource type="Animation" id="Animation_mnmxn"]
45+
resource_name = "idle"
46+
length = 0.1
6047
tracks/0/type = "value"
6148
tracks/0/imported = false
6249
tracks/0/enabled = true
6350
tracks/0/path = NodePath("Sprite2D:frame")
6451
tracks/0/interp = 1
6552
tracks/0/loop_wrap = true
6653
tracks/0/keys = {
67-
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3),
68-
"transitions": PackedFloat32Array(1, 1, 1, 1),
54+
"times": PackedFloat32Array(0),
55+
"transitions": PackedFloat32Array(1),
6956
"update": 1,
70-
"values": [1, 2, 3, 3]
57+
"values": [0]
7158
}
72-
tracks/1/type = "value"
73-
tracks/1/imported = false
74-
tracks/1/enabled = true
75-
tracks/1/path = NodePath("Sprite2D:flip_h")
76-
tracks/1/interp = 1
77-
tracks/1/loop_wrap = true
78-
tracks/1/keys = {
59+
60+
[sub_resource type="Animation" id="Animation_ud1om"]
61+
resource_name = "jump_down"
62+
length = 0.1
63+
tracks/0/type = "value"
64+
tracks/0/imported = false
65+
tracks/0/enabled = true
66+
tracks/0/path = NodePath("Sprite2D:frame")
67+
tracks/0/interp = 1
68+
tracks/0/loop_wrap = true
69+
tracks/0/keys = {
7970
"times": PackedFloat32Array(0),
8071
"transitions": PackedFloat32Array(1),
8172
"update": 1,
82-
"values": [false]
73+
"values": [10]
8374
}
8475

8576
[sub_resource type="Animation" id="Animation_8cvul"]
@@ -127,26 +118,35 @@ tracks/1/keys = {
127118
"values": [true]
128119
}
129120

130-
[sub_resource type="Animation" id="Animation_ud1om"]
131-
resource_name = "jump_down"
132-
length = 0.1
121+
[sub_resource type="Animation" id="Animation_1w8at"]
122+
resource_name = "walk_right"
123+
length = 0.35
124+
loop_mode = 1
133125
tracks/0/type = "value"
134126
tracks/0/imported = false
135127
tracks/0/enabled = true
136128
tracks/0/path = NodePath("Sprite2D:frame")
137129
tracks/0/interp = 1
138130
tracks/0/loop_wrap = true
139131
tracks/0/keys = {
132+
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3),
133+
"transitions": PackedFloat32Array(1, 1, 1, 1),
134+
"update": 1,
135+
"values": [1, 2, 3, 3]
136+
}
137+
tracks/1/type = "value"
138+
tracks/1/imported = false
139+
tracks/1/enabled = true
140+
tracks/1/path = NodePath("Sprite2D:flip_h")
141+
tracks/1/interp = 1
142+
tracks/1/loop_wrap = true
143+
tracks/1/keys = {
140144
"times": PackedFloat32Array(0),
141145
"transitions": PackedFloat32Array(1),
142146
"update": 1,
143-
"values": [10]
147+
"values": [false]
144148
}
145149

146-
[sub_resource type="Animation" id="Animation_7m0y0"]
147-
resource_name = "hit"
148-
length = 0.2
149-
150150
[sub_resource type="AnimationLibrary" id="AnimationLibrary_371pm"]
151151
_data = {
152152
"RESET": SubResource("Animation_82d58"),

0 commit comments

Comments
 (0)