From 5a402332925c29ddaa155d873c4935c2893879d0 Mon Sep 17 00:00:00 2001 From: Matt Jenkins Date: Sat, 4 May 2024 23:15:32 +0100 Subject: [PATCH] Added intro scene --- ArkanoidMaterial.tres | 6 +++++ Dunkanoid.gd | 21 +++++++++++++-- Dunkanoid.tscn | 43 +++++++++++++++++++++++-------- Intro.gd | 8 ++++++ Intro.tscn | 59 +++++++++++++++++++++++++++++++++++++++++++ project.godot | 2 +- 6 files changed, 126 insertions(+), 13 deletions(-) create mode 100644 ArkanoidMaterial.tres create mode 100644 Intro.gd create mode 100644 Intro.tscn diff --git a/ArkanoidMaterial.tres b/ArkanoidMaterial.tres new file mode 100644 index 0000000..0f424e1 --- /dev/null +++ b/ArkanoidMaterial.tres @@ -0,0 +1,6 @@ +[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://bv4vhjg83fqpn"] + +[ext_resource type="Shader" path="res://Arkanoid.gdshader" id="1_otqlg"] + +[resource] +shader = ExtResource("1_otqlg") diff --git a/Dunkanoid.gd b/Dunkanoid.gd index 1c14b12..83263e8 100644 --- a/Dunkanoid.gd +++ b/Dunkanoid.gd @@ -17,6 +17,7 @@ enum { var mode = MODE_WAIT signal update_score +signal update_lives const levels = { "DUNKANOID": { @@ -87,12 +88,15 @@ const levels = { } var capture_mode : bool = false -var lives : int = 3 +var lives : int = 3 : + set(x): + lives = x + update_lives.emit() var score : int = 0 : set(x): score = x update_score.emit() -var level : String = "SATERRANOID" +var level : String = "DUNKANOID" func _ready() -> void: Input.set_mouse_mode(Input.MOUSE_MODE_CONFINED_HIDDEN) @@ -114,6 +118,10 @@ func new_level() -> void: remove_child(ball) ball.queue_free() balls.clear() + for brick in bricks: + remove_child(brick) + brick.queue_free() + bricks.clear() $Start/Title.text = level $Start/Round.text = "ROUND %3d" % [levels[level].round] @@ -187,6 +195,11 @@ func _on_hit_floor(ball) -> void: add_child(ball) balls.push_back(ball) $StartRound.play() + $Start.visible = true + mode = MODE_WAIT + lives -= 1 + if lives <= 0: + get_tree().change_scene_to_file("res://Intro.tscn") func _on_round_won_finished() -> void: @@ -268,3 +281,7 @@ func load_level(data) -> void: func _on_start_round_finished() -> void: $Start.visible = false mode = MODE_PLAY + + +func _on_update_lives() -> void: + $LivesBox.text = "%d" % lives diff --git a/Dunkanoid.tscn b/Dunkanoid.tscn index 19087e9..111935e 100644 --- a/Dunkanoid.tscn +++ b/Dunkanoid.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=16 format=3 uid="uid://4q0epdnb0x4s"] +[gd_scene load_steps=15 format=3 uid="uid://4q0epdnb0x4s"] [ext_resource type="Script" path="res://Dunkanoid.gd" id="1_kv4if"] [ext_resource type="PackedScene" uid="uid://dndemjw7up2r6" path="res://Paddle/Paddle.tscn" id="2_26c5i"] @@ -8,7 +8,7 @@ [ext_resource type="AudioStream" uid="uid://818gpo5mes22" path="res://Sounds/Start.wav" id="6_s0pha"] [ext_resource type="AudioStream" uid="uid://bh2blx1uovmyt" path="res://Sounds/Win.wav" id="7_xrjor"] [ext_resource type="Theme" uid="uid://cfvww0geatnnk" path="res://MainTheme.tres" id="8_wcf7g"] -[ext_resource type="Shader" path="res://Arkanoid.gdshader" id="9_20w5w"] +[ext_resource type="Material" uid="uid://bv4vhjg83fqpn" path="res://ArkanoidMaterial.tres" id="9_ouuij"] [sub_resource type="PhysicsMaterial" id="PhysicsMaterial_yf4r2"] rough = true @@ -29,9 +29,6 @@ distance = -432.0 [sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_48dqy"] distance = -360.0 -[sub_resource type="ShaderMaterial" id="ShaderMaterial_6dsnv"] -shader = ExtResource("9_20w5w") - [node name="Dunkanoid" type="Node2D"] texture_filter = 1 script = ExtResource("1_kv4if") @@ -70,21 +67,46 @@ stream = ExtResource("6_s0pha") stream = ExtResource("7_xrjor") [node name="ScoreLabel" type="Label" parent="."] -offset_left = 509.0 +offset_left = 448.0 offset_top = 29.0 -offset_right = 560.0 +offset_right = 639.0 offset_bottom = 52.0 theme = ExtResource("8_wcf7g") text = "SCORE" +horizontal_alignment = 1 +vertical_alignment = 1 [node name="ScoreBox" type="Label" parent="."] -offset_left = 479.0 +offset_left = 448.0 offset_top = 54.0 -offset_right = 597.0 +offset_right = 639.0 offset_bottom = 77.0 theme = ExtResource("8_wcf7g") theme_type_variation = &"Numbers" text = "00000000" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="LivesLabel" type="Label" parent="."] +offset_left = 448.0 +offset_top = 82.0 +offset_right = 639.0 +offset_bottom = 105.0 +theme = ExtResource("8_wcf7g") +text = "LIVES" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="LivesBox" type="Label" parent="."] +offset_left = 448.0 +offset_top = 105.0 +offset_right = 639.0 +offset_bottom = 128.0 +theme = ExtResource("8_wcf7g") +theme_type_variation = &"Numbers" +text = "3" +horizontal_alignment = 1 +vertical_alignment = 1 [node name="ColorRect" type="ColorRect" parent="."] offset_right = 16.0 @@ -103,7 +125,7 @@ offset_bottom = 16.0 z_index = 1 [node name="Title" type="Label" parent="Start"] -material = SubResource("ShaderMaterial_6dsnv") +material = ExtResource("9_ouuij") offset_left = 16.0 offset_top = 199.0 offset_right = 432.0 @@ -150,6 +172,7 @@ offset_right = 448.0 offset_bottom = 360.0 color = Color(0, 0, 1, 1) +[connection signal="update_lives" from="." to="." method="_on_update_lives"] [connection signal="update_score" from="." to="." method="_on_update_score"] [connection signal="finished" from="StartRound" to="." method="_on_start_round_finished"] [connection signal="finished" from="RoundWon" to="." method="_on_round_won_finished"] diff --git a/Intro.gd b/Intro.gd new file mode 100644 index 0000000..95505c4 --- /dev/null +++ b/Intro.gd @@ -0,0 +1,8 @@ +extends Node2D + +func _ready() -> void: + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + +func _on_button_pressed() -> void: + get_tree().change_scene_to_file("res://Dunkanoid.tscn") + diff --git a/Intro.tscn b/Intro.tscn new file mode 100644 index 0000000..ba2e1f4 --- /dev/null +++ b/Intro.tscn @@ -0,0 +1,59 @@ +[gd_scene load_steps=5 format=3 uid="uid://c2oboya05agti"] + +[ext_resource type="Script" path="res://Intro.gd" id="1_1hnh1"] +[ext_resource type="Material" uid="uid://bv4vhjg83fqpn" path="res://ArkanoidMaterial.tres" id="2_a44d8"] +[ext_resource type="Theme" uid="uid://cfvww0geatnnk" path="res://MainTheme.tres" id="3_8d2ix"] + +[sub_resource type="Curve" id="Curve_jhhjd"] +min_value = -200.0 +max_value = 200.0 +_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 1), 0.0, 0.0, 0, 0] +point_count = 2 + +[node name="Intro" type="Node2D"] +script = ExtResource("1_1hnh1") + +[node name="CPUParticles2D" type="CPUParticles2D" parent="."] +position = Vector2(311, 164) +amount = 100 +speed_scale = 0.1 +randomness = 1.0 +direction = Vector2(0, 0) +spread = 180.0 +gravity = Vector2(0, 0) +initial_velocity_min = 80.81 +initial_velocity_max = 838.38 +linear_accel_min = 100.0 +linear_accel_max = 100.0 +linear_accel_curve = SubResource("Curve_jhhjd") + +[node name="Label" type="Label" parent="."] +material = ExtResource("2_a44d8") +offset_top = 88.0 +offset_right = 640.0 +offset_bottom = 111.0 +theme = ExtResource("3_8d2ix") +theme_type_variation = &"Arkanoid" +text = "DUNKANOID" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Label2" type="Label" parent="."] +material = ExtResource("2_a44d8") +offset_top = 113.0 +offset_right = 640.0 +offset_bottom = 138.0 +theme = ExtResource("3_8d2ix") +theme_type_variation = &"Arkanoid" +text = "REVENGE OF AAH" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Button" type="Button" parent="."] +offset_left = 288.0 +offset_top = 186.0 +offset_right = 335.0 +offset_bottom = 217.0 +text = "PLAY" + +[connection signal="pressed" from="Button" to="." method="_on_button_pressed"] diff --git a/project.godot b/project.godot index 166522e..e1add9f 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="Dunkanoid" -run/main_scene="res://Dunkanoid.tscn" +run/main_scene="res://Intro.tscn" config/features=PackedStringArray("4.2", "Forward Plus") boot_splash/show_image=false config/icon="res://icon.svg"