diff --git a/scenes/Globals/global.gd b/scenes/Globals/global.gd index aba9705..fd8db83 100644 --- a/scenes/Globals/global.gd +++ b/scenes/Globals/global.gd @@ -32,6 +32,10 @@ var time = 60 var lost = false +enum MODES {INFINITE, TIME} + +var currentMode = MODES.INFINITE + func getNewUID() -> int: lastUID += 1 return lastUID @@ -42,7 +46,7 @@ func resetGame(): points = 0 lastUID = 0 currentUID = lastUID - time = 60 + resetTime() lost = false func _ready() -> void: @@ -50,3 +54,18 @@ func _ready() -> void: func lose(): lost = true + +func resetTime(): + time = 0 + + +func setTimeModeTimer(): + time = 60 + +func convertIntToTime(value) -> String: + var time = str(value) + var seconds = value % 60 + var minutes = value / 60 + if seconds < 10: + seconds = "0"+ str(seconds) + return str(minutes) + ":" + str(seconds) diff --git a/scenes/Grid/camera_2d.gd b/scenes/Grid/camera_2d.gd index 657391d..e0f391c 100644 --- a/scenes/Grid/camera_2d.gd +++ b/scenes/Grid/camera_2d.gd @@ -11,4 +11,4 @@ func _ready() -> void: # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: scoreLabel.text = str(GLOBAL.points) - timeLabel.text = str(GLOBAL.time) + timeLabel.text = GLOBAL.convertIntToTime(GLOBAL.time) diff --git a/scenes/Grid/grid.gd b/scenes/Grid/grid.gd index 347f72b..eb3cc12 100644 --- a/scenes/Grid/grid.gd +++ b/scenes/Grid/grid.gd @@ -8,7 +8,6 @@ extends Node2D @onready var loseArea = $LoseArea @onready var gameTimer = $GameTimer - var nextBlocks = [] var currentPattern = null @@ -20,6 +19,18 @@ var blockSpeed = 0.5 var stopped = false +func startGame(): + GLOBAL.resetGame() + match GLOBAL.currentMode: + GLOBAL.MODES.INFINITE: + GLOBAL.resetTime() + GLOBAL.MODES.TIME: + GLOBAL.setTimeModeTimer() + gameTimer.start(1) + tickerTimer.start(blockSpeed) + getNewPatterns() + PlacePattern() + func spawnBlock() -> void: var block = nextBlocks[0] GLOBAL.currentBlock = block @@ -28,10 +39,7 @@ func spawnBlock() -> void: if nextBlocks.size() < 2: fillNextBlocks() -func _ready() -> void: - tickerTimer.start(blockSpeed) - getNewPatterns() - PlacePattern() + func _physics_process(delta: float) -> void: var blockGroups = getBlockGroupsList() @@ -220,10 +228,15 @@ func _on_ticker_timeout() -> void: func _on_game_timer_timeout() -> void: - if GLOBAL.time - 1 > 0: - GLOBAL.time -= 1 - else: - GLOBAL.lose() + match GLOBAL.currentMode: + GLOBAL.MODES.INFINITE: + GLOBAL.time += 1 + GLOBAL.MODES.TIME: + if GLOBAL.time - 1 < 0: + GLOBAL.lose() + else: + GLOBAL.time -= 1 + gameTimer.start(1) diff --git a/scenes/Grid/grid.tscn b/scenes/Grid/grid.tscn index a03f04a..ee04933 100644 --- a/scenes/Grid/grid.tscn +++ b/scenes/Grid/grid.tscn @@ -148,7 +148,6 @@ position = Vector2(320, -128) shape = SubResource("RectangleShape2D_m21a1") [node name="GameTimer" type="Timer" parent="."] -autostart = true [node name="Camera2D" type="Camera2D" parent="."] position = Vector2(320, 640) @@ -193,7 +192,7 @@ layout_mode = 2 [node name="Time" type="Label" parent="Camera2D/CanvasLayer/Control/VBoxContainer/HBoxContainer2"] layout_mode = 2 -text = "Time:" +text = "Time: " label_settings = ExtResource("9_i2h5u") horizontal_alignment = 1 vertical_alignment = 1 diff --git a/scenes/Main/main.gd b/scenes/Main/main.gd index d9da935..b7bfa88 100644 --- a/scenes/Main/main.gd +++ b/scenes/Main/main.gd @@ -29,6 +29,7 @@ func loadGrid(): $scenes/StartMenu.queue_free() scenes.add_child(load("res://scenes/Grid/grid.tscn").instantiate()) $scenes/Grid.toggleButton() + $scenes/Grid.startGame() func scoreOverview(): if $scenes/Grid != null: diff --git a/scenes/Main/main.tscn b/scenes/Main/main.tscn index 269ea11..9706a19 100644 --- a/scenes/Main/main.tscn +++ b/scenes/Main/main.tscn @@ -11,10 +11,10 @@ show_behind_parent = true anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 -offset_left = -832.0 -offset_top = -1008.0 -offset_right = 674.0 -offset_bottom = -1991.0 +offset_left = -2856.0 +offset_top = -2504.0 +offset_right = 4287.0 +offset_bottom = -3032.0 grow_horizontal = 2 grow_vertical = 2 scale = Vector2(0.996259, 9.13391) @@ -22,56 +22,86 @@ color = Color(0.000693898, 0.000693898, 0.000693898, 1) [node name="CPUParticles2D" type="CPUParticles2D" parent="ColorRect"] modulate = Color(1, 1, 1, 0.478431) -position = Vector2(1300.87, 37.6618) +position = Vector2(3195.96, 14.0137) scale = Vector2(0.501878, 0.054741) -amount = 20 +amount = 50 lifetime = 5.0 preprocess = 5.0 speed_scale = 0.5 local_coords = true texture = ExtResource("2_5ae6b") emission_shape = 3 -emission_rect_extents = Vector2(2000, 0) +emission_rect_extents = Vector2(4000, 0) spread = 0.0 tangential_accel_max = 100.0 damping_max = 100.0 scale_amount_max = 2.0 +split_scale = true +scale_curve_x = null +scale_curve_y = null color = Color(1, 0, 0, 1) [node name="CPUParticles2D2" type="CPUParticles2D" parent="ColorRect"] modulate = Color(1, 1, 1, 0.478431) -position = Vector2(1300.87, 37.6618) +position = Vector2(3195.96, 14.0137) scale = Vector2(0.501878, 0.054741) -amount = 20 +amount = 50 lifetime = 5.0 preprocess = 5.0 speed_scale = 0.5 local_coords = true texture = ExtResource("2_5ae6b") emission_shape = 3 -emission_rect_extents = Vector2(2000, 0) +emission_rect_extents = Vector2(4000, 0) spread = 0.0 tangential_accel_max = 100.0 damping_max = 100.0 scale_amount_max = 2.0 +split_scale = true +scale_curve_x = null +scale_curve_y = null color = Color(0, 0.0499997, 1, 1) [node name="CPUParticles2D3" type="CPUParticles2D" parent="ColorRect"] modulate = Color(1, 1, 1, 0.478431) -position = Vector2(1300.87, 37.6618) +position = Vector2(3195.96, 14.0137) scale = Vector2(0.501878, 0.054741) -amount = 20 +amount = 50 lifetime = 5.0 preprocess = 5.0 speed_scale = 0.5 local_coords = true texture = ExtResource("2_5ae6b") emission_shape = 3 -emission_rect_extents = Vector2(2000, 0) +emission_rect_extents = Vector2(4000, 0) spread = 0.0 tangential_accel_max = 100.0 damping_max = 100.0 scale_amount_max = 2.0 +split_scale = true +scale_curve_x = null +scale_curve_y = null color = Color(0.966667, 1, 0, 1) +[node name="CPUParticles2D4" type="CPUParticles2D" parent="ColorRect"] +modulate = Color(1, 1, 1, 0.478431) +position = Vector2(3195.96, 14.0137) +scale = Vector2(0.501878, 0.054741) +amount = 50 +lifetime = 5.0 +preprocess = 5.0 +speed_scale = 0.5 +local_coords = true +texture = ExtResource("2_5ae6b") +emission_shape = 3 +emission_rect_extents = Vector2(4000, 0) +spread = 0.0 +tangential_accel_max = 100.0 +damping_max = 100.0 +scale_amount_max = 2.0 +split_scale = true +scale_curve_x = null +scale_curve_y = null +color = Color(0.138, 0.92, 0, 1) + [node name="scenes" type="Node" parent="."] diff --git a/scenes/Menu/start_menu.gd b/scenes/Menu/start_menu.gd index 719c1de..5d75538 100644 --- a/scenes/Menu/start_menu.gd +++ b/scenes/Menu/start_menu.gd @@ -11,5 +11,10 @@ func _process(delta: float) -> void: pass -func _on_start_button_pressed() -> void: +func _on_infinite_mode_button_pressed() -> void: + GLOBAL.currentMode = GLOBAL.MODES.INFINITE + get_parent().get_parent().loadGrid() + +func _on_time_mode_button_pressed() -> void: + GLOBAL.currentMode = GLOBAL.MODES.TIME get_parent().get_parent().loadGrid() diff --git a/scenes/Menu/start_menu.tscn b/scenes/Menu/start_menu.tscn index 8c5b908..0017176 100644 --- a/scenes/Menu/start_menu.tscn +++ b/scenes/Menu/start_menu.tscn @@ -19,7 +19,7 @@ grow_vertical = 2 theme = ExtResource("1_t0oee") script = ExtResource("2_1x51p") -[node name="StartButton" type="Button" parent="."] +[node name="VBoxContainer2" type="VBoxContainer" parent="."] layout_mode = 1 anchors_preset = 7 anchor_left = 0.5 @@ -27,13 +27,19 @@ anchor_top = 1.0 anchor_right = 0.5 anchor_bottom = 1.0 offset_left = -156.0 -offset_top = -320.0 -offset_right = 4.0 -offset_bottom = -224.0 +offset_top = -448.0 +offset_right = 164.0 +offset_bottom = -256.0 grow_horizontal = 2 grow_vertical = 0 -scale = Vector2(2, 2) -text = "Start" + +[node name="InfiniteModeButton" type="Button" parent="VBoxContainer2"] +layout_mode = 2 +text = "Infinite Mode" + +[node name="TimeModeButton" type="Button" parent="VBoxContainer2"] +layout_mode = 2 +text = "Time Mode" [node name="Label" type="Label" parent="."] layout_mode = 1 @@ -111,4 +117,5 @@ alignment = 1 layout_mode = 2 texture = ExtResource("7_mn4r0") -[connection signal="pressed" from="StartButton" to="." method="_on_start_button_pressed"] +[connection signal="pressed" from="VBoxContainer2/InfiniteModeButton" to="." method="_on_infinite_mode_button_pressed"] +[connection signal="pressed" from="VBoxContainer2/TimeModeButton" to="." method="_on_time_mode_button_pressed"] diff --git a/scenes/ScoreOverview/score_overview.gd b/scenes/ScoreOverview/score_overview.gd index df56329..f69caaa 100644 --- a/scenes/ScoreOverview/score_overview.gd +++ b/scenes/ScoreOverview/score_overview.gd @@ -9,17 +9,8 @@ func _ready() -> void: time.text = str(GLOBAL.time) GLOBAL.resetGame() - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta: float) -> void: - pass - - - - func _on_play_again_button_pressed() -> void: - get_parent().get_parent().laodGrid() - + get_parent().get_parent().loadGrid() func _on_home_pressed() -> void: get_parent().get_parent().loadStartMenu()