Skip to content

Commit 3243c5a

Browse files
authored
Merge pull request #2 from MrakDun-desu/main
Implementing Godotris
2 parents 09e9b5b + 7afe4c4 commit 3243c5a

20 files changed

+1259
-0
lines changed

Games/Godotris/Block/Block.tscn

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[gd_scene load_steps=4 format=3 uid="uid://ddpkw5l32ogx2"]
2+
3+
[ext_resource type="Script" path="res://Games/Godotris/Block/godotris_block.gd" id="1_xp0iy"]
4+
5+
[sub_resource type="Gradient" id="Gradient_hw1qf"]
6+
offsets = PackedFloat32Array(1)
7+
colors = PackedColorArray(1, 1, 1, 1)
8+
9+
[sub_resource type="GradientTexture2D" id="GradientTexture2D_vv7n2"]
10+
gradient = SubResource("Gradient_hw1qf")
11+
width = 32
12+
height = 32
13+
14+
[node name="Block" type="Sprite2D"]
15+
texture = SubResource("GradientTexture2D_vv7n2")
16+
script = ExtResource("1_xp0iy")
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extends Sprite2D
2+
3+
class_name GodotrisBlock
4+
5+
signal cleared
6+
7+
func clear() -> void:
8+
cleared.emit()
9+
queue_free()
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
extends Control
2+
3+
class_name GodotrisGame
4+
5+
@export var start_menu: CanvasItem
6+
@export var end_menu: CanvasItem
7+
@export var countdown_timer: Timer
8+
@export var countdown_label: Label
9+
@export var score_label: Label
10+
@export var level_label: Label
11+
@export var lines_label: Label
12+
@export var piece_spawner: GodotrisPieceSpawner
13+
@export var input_handler: GodotrisInputHandler
14+
@export var grid: GodotrisGrid
15+
16+
const level_droptimes: Array[int] = [
17+
16 * 48,
18+
16 * 43,
19+
16 * 38,
20+
16 * 33,
21+
16 * 28,
22+
16 * 23,
23+
16 * 18,
24+
16 * 13,
25+
16 * 8,
26+
16 * 6,
27+
16 * 5,
28+
16 * 5,
29+
16 * 5,
30+
16 * 4,
31+
16 * 4,
32+
16 * 4,
33+
16 * 3,
34+
16 * 3,
35+
16 * 3,
36+
16 * 2,
37+
16 * 2,
38+
16 * 2,
39+
16 * 2,
40+
16 * 2,
41+
16 * 2,
42+
16 * 2,
43+
16 * 2,
44+
16 * 2,
45+
16 * 2,
46+
16 * 1
47+
]
48+
49+
var ticks_left := 3
50+
var current_score := 0
51+
var current_level := 0
52+
var lines_cleared := 0
53+
var total_lines_cleared := 0
54+
55+
func start_game() -> void:
56+
grid.clear_all_blocks()
57+
piece_spawner.initialize()
58+
start_menu.hide()
59+
end_menu.hide()
60+
ticks_left = 3
61+
current_score = 0
62+
current_level = 0
63+
lines_cleared = 0
64+
total_lines_cleared = 0
65+
update_score()
66+
update_level()
67+
update_lines()
68+
countdown_label.show()
69+
countdown_label.text = str(ticks_left)
70+
countdown_timer.start()
71+
72+
func end_game() -> void:
73+
end_menu.show()
74+
75+
func on_timer_tick() -> void:
76+
ticks_left -= 1
77+
countdown_label.text = str(ticks_left)
78+
if ticks_left == 0:
79+
countdown_label.text = "Start!"
80+
countdown_label.hide()
81+
countdown_timer.stop()
82+
input_handler.request_piece()
83+
84+
func on_piece_placed(count: int) -> void:
85+
if count == 0:
86+
return
87+
88+
var addition: int
89+
match count:
90+
1:
91+
addition = 40
92+
2:
93+
addition = 100
94+
3:
95+
addition = 300
96+
4:
97+
addition = 1200
98+
99+
addition *= current_level + 1
100+
current_score += addition
101+
lines_cleared += count
102+
total_lines_cleared += count
103+
update_lines()
104+
update_score()
105+
if lines_cleared >= 10:
106+
lines_cleared -= 10
107+
current_level += 1
108+
update_level()
109+
110+
func on_piece_softdropped() -> void:
111+
current_score += 1
112+
update_score()
113+
114+
func on_piece_harddropped(lines: int) -> void:
115+
current_score += lines * 2
116+
update_score()
117+
118+
func update_score() -> void:
119+
score_label.text = "Score: " + str(current_score)
120+
121+
func update_level() -> void:
122+
level_label.text = "Level: " + str(current_level)
123+
input_handler.update_droptime(level_droptimes[current_level])
124+
125+
func update_lines() -> void:
126+
lines_label.text = "Lines cleared: " + str(total_lines_cleared)
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
[gd_scene load_steps=15 format=3 uid="uid://xl674gbk881y"]
2+
3+
[ext_resource type="Script" path="res://Games/Godotris/Game/godotris_game.gd" id="1_0mtes"]
4+
[ext_resource type="Script" path="res://Games/Godotris/Game/godotris_input_handler.gd" id="1_g8vii"]
5+
[ext_resource type="PackedScene" uid="uid://bh4wsctpxw88n" path="res://Games/Godotris/Grid/grid.tscn" id="2_1r4od"]
6+
[ext_resource type="PackedScene" uid="uid://b1xykl5fledwa" path="res://Games/Godotris/PieceHolder/piece_holder.tscn" id="3_la86e"]
7+
[ext_resource type="PackedScene" uid="uid://corveaa2iq24x" path="res://Games/Godotris/Piece/i_piece.tscn" id="5_jv2ro"]
8+
[ext_resource type="PackedScene" uid="uid://cuxy2r5ex7lxa" path="res://Games/Godotris/Piece/j_piece.tscn" id="6_tqwyl"]
9+
[ext_resource type="PackedScene" uid="uid://b7kkiimno5ae5" path="res://Games/Godotris/Piece/l_piece.tscn" id="7_iwxu5"]
10+
[ext_resource type="Script" path="res://Games/Godotris/Game/godotris_piece_spawner.gd" id="7_kptm2"]
11+
[ext_resource type="PackedScene" uid="uid://ddf8eap1k00yb" path="res://Games/Godotris/Piece/o_piece.tscn" id="8_kiqdo"]
12+
[ext_resource type="PackedScene" uid="uid://bu55cplk7o7ja" path="res://Games/Godotris/Piece/s_piece.tscn" id="9_8dy2y"]
13+
[ext_resource type="PackedScene" uid="uid://dfa5tvxkoi4ii" path="res://Games/Godotris/Piece/t_piece.tscn" id="10_4werb"]
14+
[ext_resource type="PackedScene" uid="uid://ntmchus4unn0" path="res://Games/Godotris/Piece/z_piece.tscn" id="11_1drbf"]
15+
16+
[sub_resource type="Gradient" id="Gradient_nlwv3"]
17+
colors = PackedColorArray(0, 0.556863, 0.568627, 1, 0, 0, 0, 1)
18+
19+
[sub_resource type="GradientTexture2D" id="GradientTexture2D_he5fk"]
20+
gradient = SubResource("Gradient_nlwv3")
21+
fill_from = Vector2(0.226496, 0.987179)
22+
fill_to = Vector2(0.722222, 0.0811966)
23+
24+
[node name="GodotrisGame" type="Control" node_paths=PackedStringArray("start_menu", "end_menu", "countdown_timer", "countdown_label", "score_label", "level_label", "lines_label", "piece_spawner", "input_handler", "grid")]
25+
layout_mode = 3
26+
anchors_preset = 15
27+
anchor_right = 1.0
28+
anchor_bottom = 1.0
29+
grow_horizontal = 2
30+
grow_vertical = 2
31+
script = ExtResource("1_0mtes")
32+
start_menu = NodePath("StartMenu")
33+
end_menu = NodePath("EndMenu")
34+
countdown_timer = NodePath("StartTimer")
35+
countdown_label = NodePath("CountdownLabel")
36+
score_label = NodePath("Grid/ScoreLabel")
37+
level_label = NodePath("Grid/LevelLabel")
38+
lines_label = NodePath("Grid/LinesLabel")
39+
piece_spawner = NodePath("PieceSpawner")
40+
input_handler = NodePath("InputHandler")
41+
grid = NodePath("Grid")
42+
43+
[node name="StartTimer" type="Timer" parent="."]
44+
45+
[node name="Background" type="TextureRect" parent="."]
46+
layout_mode = 1
47+
anchors_preset = 15
48+
anchor_right = 1.0
49+
anchor_bottom = 1.0
50+
grow_horizontal = 2
51+
grow_vertical = 2
52+
texture = SubResource("GradientTexture2D_he5fk")
53+
54+
[node name="Grid" parent="." instance=ExtResource("2_1r4od")]
55+
layout_mode = 1
56+
57+
[node name="PiecePreview" parent="Grid" instance=ExtResource("3_la86e")]
58+
layout_mode = 0
59+
offset_left = 320.0
60+
offset_right = 480.0
61+
offset_bottom = 96.0
62+
63+
[node name="ControlsLabel" type="Label" parent="Grid"]
64+
layout_mode = 1
65+
offset_left = -400.0
66+
offset_top = 336.0
67+
offset_right = -32.0
68+
offset_bottom = 523.0
69+
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
70+
theme_override_constants/outline_size = 15
71+
theme_override_font_sizes/font_size = 25
72+
text = "Move left: Left arrow
73+
Move right: Right arrow
74+
Soft drop: Down arrow
75+
Rotate: Up arrow
76+
Hard drop: Space"
77+
horizontal_alignment = 2
78+
vertical_alignment = 1
79+
80+
[node name="LinesLabel" type="Label" parent="Grid"]
81+
layout_mode = 1
82+
offset_left = 352.0
83+
offset_top = 320.0
84+
offset_right = 720.0
85+
offset_bottom = 397.0
86+
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
87+
theme_override_constants/outline_size = 15
88+
theme_override_font_sizes/font_size = 40
89+
text = "Lines cleared: 0"
90+
vertical_alignment = 1
91+
92+
[node name="LevelLabel" type="Label" parent="Grid"]
93+
layout_mode = 1
94+
offset_left = 352.0
95+
offset_top = 400.0
96+
offset_right = 720.0
97+
offset_bottom = 477.0
98+
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
99+
theme_override_constants/outline_size = 15
100+
theme_override_font_sizes/font_size = 40
101+
text = "Level: 0"
102+
vertical_alignment = 1
103+
104+
[node name="ScoreLabel" type="Label" parent="Grid"]
105+
layout_mode = 1
106+
offset_left = 352.0
107+
offset_top = 480.0
108+
offset_right = 720.0
109+
offset_bottom = 557.0
110+
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
111+
theme_override_constants/outline_size = 15
112+
theme_override_font_sizes/font_size = 40
113+
text = "Score: 0"
114+
vertical_alignment = 1
115+
116+
[node name="CountdownLabel" type="Label" parent="."]
117+
visible = false
118+
layout_mode = 1
119+
anchors_preset = 8
120+
anchor_left = 0.5
121+
anchor_top = 0.5
122+
anchor_right = 0.5
123+
anchor_bottom = 0.5
124+
offset_left = -21.0
125+
offset_top = -11.5
126+
offset_right = 21.0
127+
offset_bottom = 11.5
128+
grow_horizontal = 2
129+
grow_vertical = 2
130+
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
131+
theme_override_constants/outline_size = 15
132+
theme_override_font_sizes/font_size = 100
133+
text = "Start!"
134+
horizontal_alignment = 1
135+
vertical_alignment = 1
136+
137+
[node name="PieceSpawner" type="Node" parent="." node_paths=PackedStringArray("previews", "grid")]
138+
script = ExtResource("7_kptm2")
139+
previews = [NodePath("../Grid/PiecePreview")]
140+
pieces = {
141+
"i": ExtResource("5_jv2ro"),
142+
"j": ExtResource("6_tqwyl"),
143+
"l": ExtResource("7_iwxu5"),
144+
"o": ExtResource("8_kiqdo"),
145+
"s": ExtResource("9_8dy2y"),
146+
"t": ExtResource("10_4werb"),
147+
"z": ExtResource("11_1drbf")
148+
}
149+
grid = NodePath("../Grid")
150+
151+
[node name="InputHandler" type="Node" parent="." node_paths=PackedStringArray("piece_spawner", "grid")]
152+
script = ExtResource("1_g8vii")
153+
piece_spawner = NodePath("../PieceSpawner")
154+
grid = NodePath("../Grid")
155+
156+
[node name="StartMenu" type="Control" parent="."]
157+
layout_mode = 1
158+
anchors_preset = 15
159+
anchor_right = 1.0
160+
anchor_bottom = 1.0
161+
grow_horizontal = 2
162+
grow_vertical = 2
163+
164+
[node name="VBoxContainer" type="VBoxContainer" parent="StartMenu"]
165+
layout_mode = 1
166+
anchors_preset = 15
167+
anchor_right = 1.0
168+
anchor_bottom = 1.0
169+
offset_bottom = -100.0
170+
grow_horizontal = 2
171+
grow_vertical = 2
172+
theme_override_constants/separation = 40
173+
alignment = 1
174+
175+
[node name="Title" type="Label" parent="StartMenu/VBoxContainer"]
176+
layout_mode = 2
177+
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
178+
theme_override_constants/outline_size = 15
179+
theme_override_font_sizes/font_size = 100
180+
text = "Godotris"
181+
horizontal_alignment = 1
182+
vertical_alignment = 1
183+
184+
[node name="StartButton" type="Button" parent="StartMenu/VBoxContainer"]
185+
custom_minimum_size = Vector2(250, 0)
186+
layout_mode = 2
187+
size_flags_horizontal = 4
188+
theme_override_font_sizes/font_size = 70
189+
text = "Start!"
190+
191+
[node name="EndMenu" type="Control" parent="."]
192+
visible = false
193+
layout_mode = 1
194+
anchors_preset = 15
195+
anchor_right = 1.0
196+
anchor_bottom = 1.0
197+
grow_horizontal = 2
198+
grow_vertical = 2
199+
200+
[node name="RestartButton" type="Button" parent="EndMenu"]
201+
custom_minimum_size = Vector2(250, 0)
202+
layout_mode = 1
203+
anchors_preset = 8
204+
anchor_left = 0.5
205+
anchor_top = 0.5
206+
anchor_right = 0.5
207+
anchor_bottom = 0.5
208+
offset_left = -136.5
209+
offset_top = -53.0
210+
offset_right = 136.5
211+
offset_bottom = 53.0
212+
grow_horizontal = 2
213+
grow_vertical = 2
214+
size_flags_horizontal = 4
215+
theme_override_font_sizes/font_size = 70
216+
text = "Restart"
217+
218+
[connection signal="timeout" from="StartTimer" to="." method="on_timer_tick"]
219+
[connection signal="piece_placed" from="Grid" to="." method="on_piece_placed"]
220+
[connection signal="piece_placed" from="Grid" to="InputHandler" method="on_piece_placed"]
221+
[connection signal="cant_spawn" from="PieceSpawner" to="." method="end_game"]
222+
[connection signal="cant_spawn" from="PieceSpawner" to="InputHandler" method="stop_control"]
223+
[connection signal="piece_harddropped" from="InputHandler" to="." method="on_piece_harddropped"]
224+
[connection signal="piece_softdropped" from="InputHandler" to="." method="on_piece_softdropped"]
225+
[connection signal="pressed" from="StartMenu/VBoxContainer/StartButton" to="." method="start_game"]
226+
[connection signal="pressed" from="EndMenu/RestartButton" to="." method="start_game"]

0 commit comments

Comments
 (0)