Improved graphics. Added game over scene

This commit is contained in:
2024-05-05 13:42:51 +01:00
parent 5a40233292
commit fef3ae9d8e
24 changed files with 392 additions and 48 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://14rcfdux2hkr"
path="res://.godot/imported/dark-green-2790337_640.png-80189e97b17f2d8e90e8b8a98e3b7d45.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Backgrounds/dark-green-2790337_640.png"
dest_files=["res://.godot/imported/dark-green-2790337_640.png-80189e97b17f2d8e90e8b8a98e3b7d45.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@@ -22,6 +22,12 @@ max_contacts_reported = 5
contact_monitor = true
script = ExtResource("1_2xu4j")
[node name="Shadow" type="Polygon2D" parent="."]
z_index = -1
position = Vector2(1, 2)
color = Color(0, 0, 0, 0.247059)
polygon = PackedVector2Array(-3, -2, -2, -3, 2, -3, 3, -2, 3, 2, 2, 3, -2, 3, -3, 2)
[node name="TextureRect" type="TextureRect" parent="."]
offset_left = -3.0
offset_top = -3.0

View File

@@ -16,6 +16,14 @@ physics_material_override = SubResource("PhysicsMaterial_s6ufd")
constant_linear_velocity = Vector2(0, 50)
script = ExtResource("1_eylhu")
[node name="Shadow" type="ColorRect" parent="."]
z_index = -1
offset_left = -13.0
offset_top = -2.0
offset_right = 19.0
offset_bottom = 14.0
color = Color(0, 0, 0, 0.247059)
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_xxkpg")

View File

@@ -16,10 +16,19 @@ enum {
var mode = MODE_WAIT
signal update_score
signal update_lives
const levels = {
"TEST": {
"data": [
" ",
" ",
" R ",
],
"left": "RAINBOW",
"right": "SATERRANOID",
"round": 1
},
"DUNKANOID": {
"data": [
" ",
@@ -92,25 +101,36 @@ 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 = "DUNKANOID"
var leave_direction : int = 0
func _ready() -> void:
Input.set_mouse_mode(Input.MOUSE_MODE_CONFINED_HIDDEN)
EventBus.update_score.connect(_on_update_score)
new_level()
func _process(_delta : float) -> void:
func _process(delta : float) -> void:
if mode == MODE_EXIT:
if $Paddle.global_position.x == 32:
level = levels[level].left
new_level()
leave(-1)
if $Paddle.global_position.x == 416:
level = levels[level].right
leave(+1)
if mode == MODE_LEAVE:
$Paddle.global_position.x += (delta * leave_direction * 20.0)
if $Paddle.global_position.x < -16 or $Paddle.global_position.x > 448:
if not $Sounds/RoundWon.playing:
new_level()
func leave(dir : int) -> void:
mode = MODE_LEAVE
leave_direction = dir
func new_level() -> void:
mode = MODE_WAIT
$Exits.visible = false
@@ -134,11 +154,11 @@ func new_level() -> void:
balls.push_back(ball)
$Start.visible = true
$StartRound.play()
$Sounds/StartRound.play()
func _brick_destroyed(brick) -> void:
score += brick.value
Global.score += brick.value
if randf() > 0.9:
var upgrade = _Upgrade.instantiate()
upgrade.position = brick.position
@@ -162,13 +182,20 @@ func _brick_destroyed(brick) -> void:
remove_child(ball)
ball.queue_free()
balls.clear()
for c in get_children():
if c is Upgrade:
remove_child(c)
c.queue_free()
mode = MODE_EXIT
$Exits.visible = true
$RoundWon.play()
$Sounds/RoundWon.play()
func _input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
if mode != MODE_LEAVE:
$Paddle.position = Vector2(min(max(32, event.position.x), 432-16), 340)
if event is InputEventMouseButton:
if mode != MODE_PLAY:
@@ -183,34 +210,40 @@ func _on_hit_paddle(ball) -> void:
ball.capture($Paddle, Vector2(diff, 8))
func _on_hit_floor(ball) -> void:
$FloorSound.play()
$Sounds/FloorSound.play()
balls.erase(ball)
remove_child(ball)
ball.call_deferred("queue_free")
if balls.size() == 0:
for c in get_children():
if c is Upgrade:
remove_child(c)
c.queue_free()
capture_mode = false
ball = _Ball.instantiate()
ball.capture($Paddle, Vector2((randf() * 32) - 16, 8))
ball.hit_paddle.connect(_on_hit_paddle)
ball.hit_floor.connect(_on_hit_floor)
add_child(ball)
balls.push_back(ball)
$StartRound.play()
$Sounds/StartRound.play()
$Start.visible = true
mode = MODE_WAIT
lives -= 1
if lives <= 0:
get_tree().change_scene_to_file("res://Intro.tscn")
get_tree().change_scene_to_file("res://GameOver.tscn")
func _on_round_won_finished() -> void:
pass
func _on_update_score() -> void:
func _on_update_score(score) -> void:
$ScoreBox.text = "%08d" % score
pass # Replace with function body.
func _on_upgrade_collected(code : String) -> void:
$Sounds/UpgradeCollected.play()
match code:
"C":
capture_mode = true
@@ -223,6 +256,8 @@ func _on_upgrade_collected(code : String) -> void:
add_ball()
func add_ball() -> void:
if balls.size() == 0:
return
var newball = _Ball.instantiate()
newball.position = balls[0].position
newball.linear_velocity = (balls[0].linear_velocity - Vector2((randf() - 0.5) * 100 , 0)).normalized() * balls[0].linear_velocity.length()
@@ -237,6 +272,9 @@ func add_ball() -> void:
func _cancel_capture_mode() -> void:
capture_mode = false
for ball in balls:
if ball.captured:
ball.release()
func load_level(data) -> void:
for y in data.size():

View File

@@ -1,12 +1,14 @@
[gd_scene load_steps=15 format=3 uid="uid://4q0epdnb0x4s"]
[gd_scene load_steps=17 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"]
[ext_resource type="Texture2D" uid="uid://14rcfdux2hkr" path="res://Backgrounds/dark-green-2790337_640.png" id="2_ke5lc"]
[ext_resource type="Script" path="res://Wall.gd" id="4_evt42"]
[ext_resource type="AudioStream" uid="uid://bkw4xksukx0dd" path="res://Sounds/Fail.wav" id="5_p5ta8"]
[ext_resource type="Script" path="res://Floor.gd" id="5_sravy"]
[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="AudioStream" uid="uid://bojc0es7165ed" path="res://Sounds/Collected.wav" id="8_fpbsr"]
[ext_resource type="Theme" uid="uid://cfvww0geatnnk" path="res://MainTheme.tres" id="8_wcf7g"]
[ext_resource type="Material" uid="uid://bv4vhjg83fqpn" path="res://ArkanoidMaterial.tres" id="9_ouuij"]
@@ -33,6 +35,16 @@ distance = -360.0
texture_filter = 1
script = ExtResource("1_kv4if")
[node name="Background" type="TextureRect" parent="."]
z_index = -2
texture_repeat = 2
clip_contents = true
offset_right = 640.0
offset_bottom = 640.0
scale = Vector2(0.7, 0.7)
texture = ExtResource("2_ke5lc")
stretch_mode = 1
[node name="Paddle" parent="." instance=ExtResource("2_26c5i")]
position = Vector2(39, 340)
input_pickable = false
@@ -57,15 +69,20 @@ script = ExtResource("5_sravy")
[node name="Bottom" type="CollisionShape2D" parent="Floor"]
shape = SubResource("WorldBoundaryShape2D_48dqy")
[node name="FloorSound" type="AudioStreamPlayer" parent="."]
[node name="Sounds" type="Node" parent="."]
[node name="FloorSound" type="AudioStreamPlayer" parent="Sounds"]
stream = ExtResource("5_p5ta8")
[node name="StartRound" type="AudioStreamPlayer" parent="."]
[node name="StartRound" type="AudioStreamPlayer" parent="Sounds"]
stream = ExtResource("6_s0pha")
[node name="RoundWon" type="AudioStreamPlayer" parent="."]
[node name="RoundWon" type="AudioStreamPlayer" parent="Sounds"]
stream = ExtResource("7_xrjor")
[node name="UpgradeCollected" type="AudioStreamPlayer" parent="Sounds"]
stream = ExtResource("8_fpbsr")
[node name="ScoreLabel" type="Label" parent="."]
offset_left = 448.0
offset_top = 29.0
@@ -173,6 +190,5 @@ 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"]
[connection signal="finished" from="Sounds/StartRound" to="." method="_on_start_round_finished"]
[connection signal="finished" from="Sounds/RoundWon" to="." method="_on_round_won_finished"]

4
EventBus.gd Normal file
View File

@@ -0,0 +1,4 @@
extends Node
signal update_score(score : int)
signal update_highscore(score : int)

15
GameOver.gd Normal file
View File

@@ -0,0 +1,15 @@
extends Node2D
func _ready() -> void:
EventBus.update_score.connect(_on_update_score)
_on_update_score(Global.score)
func _on_timer_timeout() -> void:
get_tree().change_scene_to_file("res://Intro.tscn")
func _on_update_score(score : int) -> void:
$VBoxContainer/ScoreBox.text = "%08d" % score
func _on_game_over_sound_finished() -> void:
get_tree().change_scene_to_file("res://Intro.tscn")

65
GameOver.tscn Normal file
View File

@@ -0,0 +1,65 @@
[gd_scene load_steps=5 format=3 uid="uid://c3ikcjhbrm0hp"]
[ext_resource type="Script" path="res://GameOver.gd" id="1_clfqa"]
[ext_resource type="AudioStream" uid="uid://bm1txhcguq8e1" path="res://Sounds/GameOver.wav" id="2_a07oi"]
[ext_resource type="Theme" uid="uid://cfvww0geatnnk" path="res://MainTheme.tres" id="3_km2fx"]
[ext_resource type="Material" uid="uid://bv4vhjg83fqpn" path="res://ArkanoidMaterial.tres" id="4_et3vd"]
[node name="GameOver" type="Node2D"]
texture_filter = 1
script = ExtResource("1_clfqa")
[node name="GameOverSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource("2_a07oi")
autoplay = true
[node name="Timer" type="Timer" parent="."]
wait_time = 10.0
one_shot = true
autostart = true
[node name="VBoxContainer" type="VBoxContainer" parent="."]
offset_right = 640.0
offset_bottom = 360.0
[node name="VSeparator" type="VSeparator" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme = ExtResource("3_km2fx")
[node name="GameOver" type="Label" parent="VBoxContainer"]
material = ExtResource("4_et3vd")
layout_mode = 2
theme = ExtResource("3_km2fx")
theme_type_variation = &"Arkanoid"
text = "GAME OVER"
horizontal_alignment = 1
vertical_alignment = 1
[node name="VSeparator2" type="VSeparator" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme = ExtResource("3_km2fx")
[node name="ScoreLabel" type="Label" parent="VBoxContainer"]
layout_mode = 2
theme = ExtResource("3_km2fx")
text = "Score"
horizontal_alignment = 1
vertical_alignment = 1
[node name="ScoreBox" type="Label" parent="VBoxContainer"]
layout_mode = 2
theme = ExtResource("3_km2fx")
theme_type_variation = &"Numbers"
text = "00000000"
horizontal_alignment = 1
vertical_alignment = 1
[node name="VSeparator3" type="VSeparator" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme = ExtResource("3_km2fx")
[connection signal="finished" from="GameOverSound" to="." method="_on_game_over_sound_finished"]
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]

27
Global.gd Normal file
View File

@@ -0,0 +1,27 @@
extends Node
var score : int = 0 :
set(x):
score = x
EventBus.update_score.emit(score)
if score > highscore:
highscore = score
var highscore : int = 0 :
set(x):
highscore = x
EventBus.update_highscore.emit(highscore)
_save()
func _ready() -> void:
if FileAccess.file_exists("user://data.json"):
var data = JSON.parse_string(FileAccess.get_file_as_string("user://data.json"))
highscore = data.get("highscore", 0)
func _save() -> void:
var data : Dictionary = {
"highscore": highscore
}
var f = FileAccess.open("user://data.json", FileAccess.WRITE)
f.store_string(JSON.stringify(data))
f.close()

View File

@@ -2,7 +2,17 @@ extends Node2D
func _ready() -> void:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
EventBus.update_score.connect(_on_update_score)
EventBus.update_highscore.connect(_on_update_highscore)
_on_update_score(Global.score)
_on_update_highscore(Global.highscore)
func _on_button_pressed() -> void:
get_tree().change_scene_to_file("res://Dunkanoid.tscn")
func _on_update_score(score : int) -> void:
$HBoxContainer/Score/ScoreBox.text = "%08d" % score
func _on_update_highscore(score : int) -> void:
$HBoxContainer/HighScore/HighScoreBox.text = "%08d" % score

View File

@@ -14,7 +14,7 @@ point_count = 2
script = ExtResource("1_1hnh1")
[node name="CPUParticles2D" type="CPUParticles2D" parent="."]
position = Vector2(311, 164)
position = Vector2(320, 180)
amount = 100
speed_scale = 0.1
randomness = 1.0
@@ -27,33 +27,95 @@ 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
[node name="VBoxContainer" type="VBoxContainer" parent="."]
offset_top = 104.0
offset_right = 640.0
offset_bottom = 111.0
offset_bottom = 232.0
[node name="Dunkanoid" type="Label" parent="VBoxContainer"]
material = ExtResource("2_a44d8")
layout_mode = 2
theme = ExtResource("3_8d2ix")
theme_type_variation = &"Arkanoid"
text = "DUNKANOID"
horizontal_alignment = 1
vertical_alignment = 1
[node name="Label2" type="Label" parent="."]
[node name="Revenge" type="Label" parent="VBoxContainer"]
material = ExtResource("2_a44d8")
offset_top = 113.0
offset_right = 640.0
offset_bottom = 138.0
layout_mode = 2
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"
[node name="VSeparator" type="VSeparator" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme = ExtResource("3_8d2ix")
[connection signal="pressed" from="Button" to="." method="_on_button_pressed"]
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
[node name="HSeparator" type="HSeparator" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme = ExtResource("3_8d2ix")
[node name="Play" type="Button" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
theme = ExtResource("3_8d2ix")
text = "PLAY"
icon_alignment = 1
[node name="HSeparator2" type="HSeparator" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme = ExtResource("3_8d2ix")
[node name="HBoxContainer" type="HBoxContainer" parent="."]
offset_left = 18.0
offset_top = 297.0
offset_right = 624.0
offset_bottom = 343.0
size_flags_horizontal = 3
[node name="Score" type="VBoxContainer" parent="HBoxContainer"]
layout_mode = 2
[node name="ScoreLabel" type="Label" parent="HBoxContainer/Score"]
layout_mode = 2
theme = ExtResource("3_8d2ix")
text = "Score"
[node name="ScoreBox" type="Label" parent="HBoxContainer/Score"]
layout_mode = 2
theme = ExtResource("3_8d2ix")
theme_type_variation = &"Numbers"
text = "00000000"
vertical_alignment = 1
[node name="HSeparator" type="HSeparator" parent="HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme = ExtResource("3_8d2ix")
[node name="HighScore" type="VBoxContainer" parent="HBoxContainer"]
layout_mode = 2
[node name="HighScoreLabel" type="Label" parent="HBoxContainer/HighScore"]
layout_mode = 2
theme = ExtResource("3_8d2ix")
text = "High Score"
horizontal_alignment = 2
[node name="HighScoreBox" type="Label" parent="HBoxContainer/HighScore"]
layout_mode = 2
theme = ExtResource("3_8d2ix")
theme_type_variation = &"Numbers"
text = "00000000"
horizontal_alignment = 2
vertical_alignment = 1
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Play" to="." method="_on_button_pressed"]

View File

@@ -1,8 +1,12 @@
[gd_resource type="Theme" load_steps=3 format=3 uid="uid://cfvww0geatnnk"]
[gd_resource type="Theme" load_steps=5 format=3 uid="uid://cfvww0geatnnk"]
[ext_resource type="FontFile" uid="uid://dfkm2dibf0c3b" path="res://Fonts/fonts-DSEG_v046/DSEG7-Classic-MINI/DSEG7ClassicMini-Italic.ttf" id="1_17to7"]
[ext_resource type="FontFile" uid="uid://bx41ej4o03nbx" path="res://Fonts/arkanoid/Arka_solid.ttf" id="1_s07ae"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_y3y82"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_m7r63"]
[resource]
Arkanoid/base_type = &"Label"
Arkanoid/colors/font_color = Color(1, 0, 1, 1)
@@ -10,6 +14,7 @@ Arkanoid/colors/font_outline_color = Color(1, 0.647059, 0, 1)
Arkanoid/constants/outline_size = 2
Arkanoid/font_sizes/font_size = 24
Arkanoid/fonts/font = ExtResource("1_s07ae")
HSeparator/styles/separator = SubResource("StyleBoxEmpty_y3y82")
Numbers/base_type = &"Label"
Numbers/colors/font_color = Color(1, 0.764706, 0, 1)
Numbers/colors/font_outline_color = Color(0.996078, 0.380392, 0.137255, 0.898039)
@@ -22,3 +27,4 @@ Numbers/font_sizes/font_size = 18
Numbers/fonts/font = ExtResource("1_17to7")
Upgrade/base_type = &"Label"
Upgrade/colors/font_color = Color(0, 0, 0, 1)
VSeparator/styles/separator = SubResource("StyleBoxEmpty_m7r63")

Binary file not shown.

Binary file not shown.

BIN
Sounds/Collected.wav Normal file

Binary file not shown.

View File

@@ -2,13 +2,13 @@
importer="wav"
type="AudioStreamWAV"
uid="uid://dskiawadrpcfi"
path="res://.godot/imported/240504_0193.wav-3018172abbd8b511264fa24c1c297abc.sample"
uid="uid://bojc0es7165ed"
path="res://.godot/imported/Collected.wav-edf8d5887248c8148d56679549a30a1b.sample"
[deps]
source_file="res://Sounds/240504_0193.wav"
dest_files=["res://.godot/imported/240504_0193.wav-3018172abbd8b511264fa24c1c297abc.sample"]
source_file="res://Sounds/Collected.wav"
dest_files=["res://.godot/imported/Collected.wav-edf8d5887248c8148d56679549a30a1b.sample"]
[params]

BIN
Sounds/GameOver.wav Normal file

Binary file not shown.

View File

@@ -2,13 +2,13 @@
importer="wav"
type="AudioStreamWAV"
uid="uid://dix1ctqcbapaw"
path="res://.godot/imported/240504_0194.wav-cc59451c484c97e67d764ece92915f37.sample"
uid="uid://bm1txhcguq8e1"
path="res://.godot/imported/GameOver.wav-547186bec0ccc614b6375a6cb9ffa56e.sample"
[deps]
source_file="res://Sounds/240504_0194.wav"
dest_files=["res://.godot/imported/240504_0194.wav-cc59451c484c97e67d764ece92915f37.sample"]
source_file="res://Sounds/GameOver.wav"
dest_files=["res://.godot/imported/GameOver.wav-547186bec0ccc614b6375a6cb9ffa56e.sample"]
[params]

BIN
Sounds/Grow.wav Normal file

Binary file not shown.

24
Sounds/Grow.wav.import Normal file
View File

@@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://ds7om6qbk3p6l"
path="res://.godot/imported/Grow.wav-95ebfa912c2676f79f12955ea3407fb6.sample"
[deps]
source_file="res://Sounds/Grow.wav"
dest_files=["res://.godot/imported/Grow.wav-95ebfa912c2676f79f12955ea3407fb6.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0

BIN
Sounds/Shrink.wav Normal file

Binary file not shown.

24
Sounds/Shrink.wav.import Normal file
View File

@@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://bd2o8lynhy3wn"
path="res://.godot/imported/Shrink.wav-7e048798428a0bf34f285001c01906cb.sample"
[deps]
source_file="res://Sounds/Shrink.wav"
dest_files=["res://.godot/imported/Shrink.wav-7e048798428a0bf34f285001c01906cb.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0

View File

@@ -16,6 +16,11 @@ config/features=PackedStringArray("4.2", "Forward Plus")
boot_splash/show_image=false
config/icon="res://icon.svg"
[autoload]
Global="*res://Global.gd"
EventBus="*res://EventBus.gd"
[display]
window/size/viewport_width=640