Skip to content

Commit f6959db

Browse files
authored
Merge pull request #6 from endlessm/T35632-float-platformer
Platformer: Add float platformer
2 parents c129e1c + f9fd840 commit f6959db

File tree

4 files changed

+447
-77
lines changed

4 files changed

+447
-77
lines changed

game-03/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Platformer demo
2+
3+
## About
4+
5+
This is a platformer game. The goal is to stay in the level, keep alive.
6+
When the player collects enough coins and reaches the flag, then wins
7+
the game.
8+
9+
## Implementation
10+
11+
The world is built with tilemap style.
12+
13+
The player is implemented with SimpleCharacter node. So, using W, A, D to jump
14+
and move left & right.
15+
16+
The collected coins and the player's lives are implemented with a SimpleScoring
17+
node. Player 1's score represents as collected coins and player 2's score
18+
represents lives.
19+
20+
The player enters a coin to collect the coin. It increase "Player 1"'s score and
21+
vanish the coin.
22+
23+
When the player collects enough coins and enters the flag's area, shows "You
24+
Win!" label.
25+
26+
The enemies walk back and forth by setting the enemy's terminal positions within
27+
AnimationPlayer's "move" animation and playing it automatically.
28+
29+
The player has a HitArea at the foot. If any enemy enters into the HitArea, the
30+
enemy's vanish_enemy method will be invoked to vanish the enemy.
31+
32+
The enemies define their HitArea, too. If the player enters into the HitArea,
33+
nodes in HUD group will invoke their own decrease_a_life method to decrease one
34+
life.
35+
36+
When the player enters an enemy's HitArea or drops down into the Dangerzone, the
37+
"Player 2"'s score decreases one. If there is no more life, shows "You Lose!"
38+
label.
39+
40+
## Limitations found
41+
42+
The float platforms should shake, then drop down after the player stands on it.
43+
However, there is no way to trigger/access the play_shake method in of
44+
AnimationPlayer's BlockCode node now.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
[gd_scene load_steps=18 format=3 uid="uid://b7gyfmfo5wtm1"]
2+
3+
[ext_resource type="TileSet" uid="uid://bmkax0b814rmy" path="res://game-03/spaces/tileset-a.tres" id="1_fn3w6"]
4+
[ext_resource type="Script" path="res://addons/block_code/block_code_node/block_code.gd" id="2_xy6in"]
5+
[ext_resource type="Script" path="res://addons/block_code/serialization/block_serialization.gd" id="3_r18qn"]
6+
[ext_resource type="Script" path="res://addons/block_code/serialization/block_serialized_properties.gd" id="4_6iq68"]
7+
[ext_resource type="Script" path="res://addons/block_code/serialization/block_script_serialization.gd" id="5_a0j4o"]
8+
[ext_resource type="Script" path="res://addons/block_code/ui/block_canvas/option_data.gd" id="5_koayc"]
9+
[ext_resource type="Script" path="res://addons/block_code/ui/block_canvas/variable_resource.gd" id="6_773h0"]
10+
11+
[sub_resource type="RectangleShape2D" id="RectangleShape2D_5opsn"]
12+
size = Vector2(256, 112)
13+
14+
[sub_resource type="Animation" id="Animation_vuag3"]
15+
length = 0.001
16+
tracks/0/type = "value"
17+
tracks/0/imported = false
18+
tracks/0/enabled = true
19+
tracks/0/path = NodePath("RigidBody2D:position")
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": 0,
26+
"values": [Vector2(0, 0)]
27+
}
28+
29+
[sub_resource type="Animation" id="Animation_o6p3a"]
30+
resource_name = "shake"
31+
length = 2.0
32+
tracks/0/type = "value"
33+
tracks/0/imported = false
34+
tracks/0/enabled = true
35+
tracks/0/path = NodePath("RigidBody2D:position")
36+
tracks/0/interp = 1
37+
tracks/0/loop_wrap = true
38+
tracks/0/keys = {
39+
"times": PackedFloat32Array(0, 0.2, 0.3, 0.5, 0.6, 0.8, 0.9, 1, 2),
40+
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1, 1),
41+
"update": 0,
42+
"values": [Vector2(0, 0), Vector2(-8, 8), Vector2(-8, 0), Vector2(8, 0), Vector2(8, 8), Vector2(-8, 0), Vector2(8, 0), Vector2(0, 0), Vector2(0, 2000)]
43+
}
44+
45+
[sub_resource type="AnimationLibrary" id="AnimationLibrary_gae7a"]
46+
_data = {
47+
"RESET": SubResource("Animation_vuag3"),
48+
"shake": SubResource("Animation_o6p3a")
49+
}
50+
51+
[sub_resource type="Resource" id="Resource_ajvdh"]
52+
script = ExtResource("4_6iq68")
53+
block_class = &"EntryBlock"
54+
serialized_props = [["scope", ""], ["param_input_strings", {
55+
"method_name": "play_shake"
56+
}]]
57+
58+
[sub_resource type="Resource" id="Resource_betlu"]
59+
script = ExtResource("5_koayc")
60+
selected = 0
61+
items = ["ahead", "backwards"]
62+
63+
[sub_resource type="Resource" id="Resource_ou5dh"]
64+
script = ExtResource("4_6iq68")
65+
block_class = &"StatementBlock"
66+
serialized_props = [["scope", ""], ["param_input_strings", {
67+
"animation": "shake",
68+
"direction": SubResource("Resource_betlu")
69+
}]]
70+
71+
[sub_resource type="Resource" id="Resource_ym3c5"]
72+
script = ExtResource("3_r18qn")
73+
name = &"animationplayer_play"
74+
position = Vector2(0, 0)
75+
path_child_pairs = []
76+
block_serialized_properties = SubResource("Resource_ou5dh")
77+
78+
[sub_resource type="Resource" id="Resource_m2it8"]
79+
script = ExtResource("3_r18qn")
80+
name = &"define_method"
81+
position = Vector2(125, 100)
82+
path_child_pairs = [[NodePath("VBoxContainer/SnapPoint"), SubResource("Resource_ym3c5")]]
83+
block_serialized_properties = SubResource("Resource_ajvdh")
84+
85+
[sub_resource type="Resource" id="Resource_ay1sf"]
86+
script = ExtResource("5_a0j4o")
87+
script_inherits = "AnimationPlayer"
88+
block_trees = Array[ExtResource("3_r18qn")]([SubResource("Resource_m2it8")])
89+
variables = Array[ExtResource("6_773h0")]([])
90+
generated_script = "extends AnimationPlayer
91+
92+
93+
func play_shake():
94+
if \"ahead\" == \"ahead\":
95+
play('shake')
96+
else:
97+
play_backwards('shake')
98+
99+
"
100+
version = 0
101+
102+
[node name="float_platform" type="Node2D" groups=["float_platform"]]
103+
104+
[node name="RigidBody2D" type="RigidBody2D" parent="."]
105+
freeze = true
106+
freeze_mode = 1
107+
108+
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"]
109+
position = Vector2(0, 56)
110+
shape = SubResource("RectangleShape2D_5opsn")
111+
112+
[node name="TileMapLayer" type="TileMapLayer" parent="RigidBody2D"]
113+
tile_map_data = PackedByteArray(0, 0, 255, 255, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0)
114+
tile_set = ExtResource("1_fn3w6")
115+
116+
[node name="AnimationPlayer" type="AnimationPlayer" parent="RigidBody2D"]
117+
root_node = NodePath("../..")
118+
libraries = {
119+
"": SubResource("AnimationLibrary_gae7a")
120+
}
121+
autoplay = "RESET"
122+
123+
[node name="BlockCode" type="Node" parent="RigidBody2D/AnimationPlayer"]
124+
script = ExtResource("2_xy6in")
125+
block_script = SubResource("Resource_ay1sf")

0 commit comments

Comments
 (0)