Second Map, and sound effects

This commit is contained in:
2025-08-27 22:31:00 +02:00
parent 8108485091
commit 4ff651ff8f
21 changed files with 1863 additions and 48 deletions

View File

@ -0,0 +1,2 @@
[InternetShortcut]
URL=https://freesfx.co.uk/

View File

@ -1,19 +0,0 @@
[remap]
importer="mp3"
type="AudioStreamMP3"
uid="uid://dryh5abntw5yh"
path="res://.godot/imported/Some hitting effect not used yet.mp3-bde98e53c2512e971d34737d2d9a2561.mp3str"
[deps]
source_file="res://Assets/Sounds/Some hitting effect not used yet.mp3"
dest_files=["res://.godot/imported/Some hitting effect not used yet.mp3-bde98e53c2512e971d34737d2d9a2561.mp3str"]
[params]
loop=false
loop_offset=0
bpm=0
beat_count=0
bar_beats=4

BIN
Assets/Sounds/gameover.wav Normal file

Binary file not shown.

View File

@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://ft0gm37euhrb"
path="res://.godot/imported/gameover.wav-37725ba7d688b1993d701585de7d22d1.sample"
[deps]
source_file="res://Assets/Sounds/gameover.wav"
dest_files=["res://.godot/imported/gameover.wav-37725ba7d688b1993d701585de7d22d1.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=2

BIN
Assets/Sounds/victory.mp3 Normal file

Binary file not shown.

View File

@ -0,0 +1,19 @@
[remap]
importer="mp3"
type="AudioStreamMP3"
uid="uid://bc5p25pl828fn"
path="res://.godot/imported/victory.mp3-166d758db2d39e51dcad9d845dc67cb2.mp3str"
[deps]
source_file="res://Assets/Sounds/victory.mp3"
dest_files=["res://.godot/imported/victory.mp3-166d758db2d39e51dcad9d845dc67cb2.mp3str"]
[params]
loop=false
loop_offset=0
bpm=0
beat_count=0
bar_beats=4

View File

@ -27,6 +27,7 @@ func _input(event):
get_parent().get_node("SidePanel").Update_Coins(5)
"Wall":
get_parent().get_node("SidePanel").Update_Coins(0)
i.get_parent().WallRelease()
i.get_parent().queue_free()
queue_free()

View File

@ -8,10 +8,11 @@ const COBOLD = preload("res://Game/Mobs/cobold.tscn")
const enemies = [FORKMAN, COBOLD, ORK]
var pause = 40
func _ready() -> void:
get_node("CanvasLayer/SidePanel").set_Lifes(20)
get_node("CanvasLayer/SidePanel").Update_Coins(2000)
get_node("CanvasLayer/SidePanel").Update_Coins(250)
#the meaning of the columns inside my wave generation matris:
# Number of enemies need to be spawned, chance of spawn an enemy, chance of forkman, chance of gobline, chance of ork
@ -27,23 +28,26 @@ var currentwave = 0
var endwave = false
func _on_timer_timeout() -> void:
if endwave:
if not get_node("Path2D").get_children():
endwave = false
get_node("CanvasLayer/SidePanel").Update_waves(currentwave + 1) #updating waves
if currentwave >= 4: #!!!!! CHECKS FOR THE LAST WAVE IF NEW WAVES ARE ADDED CHANGE ACCORDINGLY!!!
get_node("CanvasLayer/SidePanel").GameWon()
if pause <= 0:
if endwave:
if not get_node("Path2D").get_children():
endwave = false
get_node("CanvasLayer/SidePanel").Update_waves(currentwave + 1) #updating waves
if currentwave >= 4: #!!!!! CHECKS FOR THE LAST WAVE IF NEW WAVES ARE ADDED CHANGE ACCORDINGLY!!!
get_node("CanvasLayer/SidePanel").GameWon()
else:
spawnMonster()
else:
spawnMonster()
pause -= 1
func spawnMonster():
currentwave = 0
for w in waves:
if w[0] > 0:
if randf() < w[1]: #chance of generating any kind of enemy
w[0] -= 1
if w[0] <= 0:
endwave = true
currentwave += 1
var chosen = randf()
var sum = 0.0
for i in range(2,5):
@ -55,9 +59,7 @@ func spawnMonster():
path_2d.add_child(path)
break
break
else:
currentwave += 1
func decrease_life(damage) -> void:
get_node("CanvasLayer/SidePanel").Update_Lifes(-damage)

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=186 format=4 uid="uid://bgme05i7taycc"]
[gd_scene load_steps=186 format=4 uid="uid://dql8q1od3r32h"]
[ext_resource type="Texture2D" uid="uid://f1npbjsw71nk" path="res://Assets/Tiles/Fields/FieldsTile_01.png" id="1_fdpq6"]
[ext_resource type="Script" uid="uid://xo6vbicdva8d" path="res://Game/Maps/map_1.gd" id="1_rec5e"]
@ -531,6 +531,7 @@ size = Vector2(163, 334)
script = ExtResource("1_rec5e")
[node name="Decoration" type="Node2D" parent="."]
visible = false
[node name="6" type="Sprite2D" parent="Decoration"]
position = Vector2(386, 348)

88
Game/Maps/map_2.gd Normal file
View File

@ -0,0 +1,88 @@
extends Node2D
@onready var path_2d: Path2D = $Path2D
@onready var path_2d_2: Path2D = $Path2D2
@onready var paths = [path_2d, path_2d_2]
const FORKMAN = preload("res://Game/Mobs/forkman.tscn")
const ORK = preload("res://Game/Mobs/ork.tscn")
const COBOLD = preload("res://Game/Mobs/cobold.tscn")
const enemies = [FORKMAN, COBOLD, ORK]
var pause = 40
func _ready() -> void:
get_node("CanvasLayer/SidePanel").set_Lifes(20)
get_node("CanvasLayer/SidePanel").Update_Coins(500)
#the meaning of the columns inside my wave generation matris:
# Number of enemies need to be spawned, chance of spawn an enemy, chance of forkman, chance of gobline, chance of ork
var waves = [
[
[10, 0.2, 0.8, 0.2, 0.0], #wave 1 #First path
[20, 0.4, 0.5, 0.5, 0.0], #wave 2
[30, 0.5, 0.4, 0.4, 0.1], #wave 3
[40, 0.8, 0.3, 0.2, 0.5], #wave 4
[50, 0.9, 0.1, 0.2, 0.7], #wave 5
],
[
[5, 0.1, 0.8, 0.2, 0.0], #wave 1 #Second Path
[10, 0.2, 0.5, 0.5, 0.0], #wave 2
[20, 0.3, 0.4, 0.4, 0.1], #wave 3
[30, 0.4, 0.3, 0.2, 0.5], #wave 4
[40, 0.7, 0.1, 0.2, 0.7], #wave 5
]
]
var currentwave = 0
var endwave = false
func _on_timer_timeout() -> void:
if pause <= 0:
if endwave:
if not get_node("Path2D").get_children():
endwave = false
get_node("CanvasLayer/SidePanel").Update_waves(currentwave + 1) #updating waves
if currentwave >= 4: #!!!!! CHECKS FOR THE LAST WAVE IF NEW WAVES ARE ADDED CHANGE ACCORDINGLY!!!
get_node("CanvasLayer/SidePanel").GameWon()
else:
spawnMonster()
else:
pause -= 1
func spawnMonster():
for ROUTE in range(2):
for w in waves[ROUTE]:
if w[0] > 0:
if randf() < w[1]: #chance of generating any kind of enemy
w[0] -= 1
for i in waves:
if i[currentwave][0] > 0:
break
endwave = true
currentwave += 1
var chosen = randf()
var sum = 0.0
for i in range(2,5):
sum += w[i]
if chosen < sum:
var monster = enemies[i-2].instantiate()
var path = PathFollow2D.new()
path.add_child(monster)
paths[ROUTE].add_child(path)
break
break
func decrease_life(damage) -> void:
get_node("CanvasLayer/SidePanel").Update_Lifes(-damage)
if get_node("CanvasLayer/SidePanel").get_Lifes() <= 0:
game_over()
func game_over()-> void:
get_node("Timer").stop()
var enemy = get_node("Path2D").get_children()
for i in enemy:
i.get_children()[0].set_process(false)

1
Game/Maps/map_2.gd.uid Normal file
View File

@ -0,0 +1 @@
uid://cjoybvdfv0bk7

1628
Game/Maps/map_2.tscn Normal file

File diff suppressed because one or more lines are too long

View File

@ -9,26 +9,34 @@ func _on_button_pressed() -> void:
pass # Replace with function body.
func _on_button_map1_pressed() -> void:
func LoadMap1() -> void:
get_tree().change_scene_to_file("res://Game/Maps/map_1.tscn")
pass # Replace with function body.
func LoadMap2() -> void:
get_tree().change_scene_to_file("res://Game/Maps/map_2.tscn")
pass # Replace with function body.
func _ready() -> void:
loadData()
get_node("VBoxContainer/HBoxContainer/first/Button").connect("button_up", LoadMap1)
get_node("VBoxContainer/HBoxContainer/second/Button").connect("button_up", LoadMap2)
func loadData() -> void:
if FileAccess.file_exists(save_path):
var file = FileAccess.open(save_path, FileAccess.READ)
if file:
map_scores = file.get_var()
file.close()
get_node("VBoxContainer/HBoxContainer/first/Label2").text = "Haven't played yet" if map_scores["Map1"] == 0 else "Scored: " + str(map_scores["Map1"]) + " out of 10"
print(map_scores)
get_node("VBoxContainer/HBoxContainer/first/Label2").text = "Haven't finished yet" if map_scores["Map1"] == 0 else "Scored: " + str(map_scores["Map1"]) + " out of 10"
get_node("VBoxContainer/HBoxContainer/second/Label2").text = "Haven't finished yet" if map_scores["Map2"] == 0 else "Scored: " + str(map_scores["Map2"]) + " out of 10"
else:
map_scores["Map1"] = 0
map_scores["Map2"] = 0
save_scores()
loadData()

View File

@ -127,6 +127,28 @@ layout_mode = 2
size_flags_horizontal = 4
text = "Score: 10 / "
[node name="second" type="VBoxContainer" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
alignment = 1
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/second"]
layout_mode = 2
size_flags_horizontal = 4
text = "2nd Level"
[node name="Button" type="Button" parent="VBoxContainer/HBoxContainer/second"]
custom_minimum_size = Vector2(120, 80)
layout_mode = 2
theme_override_styles/focus = SubResource("StyleBoxTexture_mjmwi")
theme_override_styles/hover = SubResource("StyleBoxTexture_udeaf")
theme_override_styles/pressed = SubResource("StyleBoxTexture_5yqcp")
theme_override_styles/normal = SubResource("StyleBoxTexture_cg1t8")
[node name="Label2" type="Label" parent="VBoxContainer/HBoxContainer/second"]
layout_mode = 2
size_flags_horizontal = 4
text = "Score: 10 / "
[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 12

View File

@ -57,21 +57,21 @@ func set_character_data():
health = 100
shield = 100
damage = 2
value = 2
value = 5
"Ork":
self.name = "Ork-" + str(randi())
speed = 80
health = 150
shield = 200
damage = 5
value = 3
value = 10
"Cobold":
self.name = "Cobold-" + str(randi())
speed = 200
health = 50
shield = 0
damage = 1
value = 1
value = 2
adjust_speed_of_animation() #adjust animation speed based on the character speed
current_health = health

View File

@ -16,9 +16,10 @@ func _ready() -> void:
if name.contains("Wall"):
get_node("CharacterBody2D/ProgressBar").hide()
#loads the settings and sounds
var config = ConfigFile.new()
var err = config.load("user://settings.cfg")
if err == OK:
var master_volume_raw = config.get_value("audio", "master_volume", 100.0)
master_volume = clamp(master_volume_raw / 100.0, 0.0, 1.0)
@ -94,3 +95,9 @@ func _on_timer_timeout() -> void:
if i.get_parent().name.contains(j):
i.get_parent().set_process(true)
queue_free()
func WallRelease() -> void:
for i in get_node("CharacterBody2D/Area2D").get_overlapping_bodies():
for j in NAMES:
if i.get_parent().name.contains(j):
i.get_parent().set_process(true)

View File

@ -1,7 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://drjcsrjs6uobn"]
[ext_resource type="PackedScene" uid="uid://bgme05i7taycc" path="res://Game/Maps/map_1.tscn" id="1_xb63x"]
[node name="Main" type="Node2D"]
[node name="Map1" parent="." instance=ExtResource("1_xb63x")]

View File

@ -31,6 +31,9 @@ var coins = 0
var save_path = "user://map_scores.save"
var map_scores = {}
var SFX_loudness = 1.0
var master_volume = 1.0
var music_volume_raw = 1.0
func _ready() -> void:
get_node("pausemenu").hide()
@ -68,6 +71,19 @@ func _ready() -> void:
if file:
map_scores = file.get_var()
file.close()
var config = ConfigFile.new()
var err = config.load("user://settings.cfg")
if err == OK:
var master_volume_raw = config.get_value("audio", "master_volume", 100.0)
master_volume = clamp(master_volume_raw / 100.0, 0.0, 1.0)
var sfx_volume_raw = config.get_value("audio", "sfx_volume", 100.0)
SFX_loudness = clamp(sfx_volume_raw / 100.0, 0.0, 1.0)
var music_volume_raw = config.get_value("audio", "music_volume", 100.0)
SFX_loudness = clamp(sfx_volume_raw / 100.0, 0.0, 1.0)
self.get_node("HealthLostAudio").volume_db = linear_to_db(master_volume * SFX_loudness)
self.get_node("GameOverAudio").volume_db = linear_to_db(master_volume * music_volume_raw)
self.get_node("VictoryAudio").volume_db = linear_to_db(master_volume * music_volume_raw)
func _process(delta : float)-> void:
coinlabel.text = "Coins: " + str(coins)
@ -84,6 +100,8 @@ func get_Lifes():
func Update_Lifes(amount) -> void:
lives += amount
if amount < 0:
get_node("HealthLostAudio").play()
func Update_waves(wavecount) -> void:
get_node("WaveCounter/HBoxContainer/Label").text = "Current wave: "+ str(wavecount)
@ -169,6 +187,8 @@ func GameOver() -> void:
var timer_node = i.get_node("Timer") if i.has_node("Timer") else null
if timer_node:
timer_node.stop()
get_parent().get_parent().get_node("MusicPlayer").PauseAudio()
get_node("GameOverAudio").play()
func GameWon() -> void:
get_node("Panel").hide()
@ -179,6 +199,8 @@ func GameWon() -> void:
if file:
file.store_var(map_scores)
file.close()
get_parent().get_parent().get_node("MusicPlayer").PauseAudio()
get_node("VictoryAudio").play()
func _on_button_3_pressed() -> void:
get_node("pausemenu").hide()

View File

@ -1,7 +1,10 @@
[gd_scene load_steps=16 format=3 uid="uid://ddn64i6logtw0"]
[gd_scene load_steps=19 format=3 uid="uid://ddn64i6logtw0"]
[ext_resource type="Script" uid="uid://c6sh5em844tx2" path="res://Game/sidepanel.gd" id="1_klyhg"]
[ext_resource type="FontFile" uid="uid://bu44ne346ymoe" path="res://Assets/Others/Canterbury.ttf" id="2_4l4p2"]
[ext_resource type="AudioStream" uid="uid://ca6fgsgi1nqx1" path="res://Assets/Sounds/allert.mp3" id="3_s7jra"]
[ext_resource type="AudioStream" uid="uid://ft0gm37euhrb" path="res://Assets/Sounds/gameover.wav" id="4_f5es8"]
[ext_resource type="AudioStream" uid="uid://bc5p25pl828fn" path="res://Assets/Sounds/victory.mp3" id="5_dgw1d"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_4l4p2"]
bg_color = Color(1, 1, 1, 0.447059)
@ -457,6 +460,15 @@ theme_override_styles/pressed = SubResource("StyleBoxFlat_dgw1d")
theme_override_styles/normal = SubResource("StyleBoxFlat_nctfw")
text = "Continue"
[node name="HealthLostAudio" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource("3_s7jra")
[node name="GameOverAudio" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource("4_f5es8")
[node name="VictoryAudio" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource("5_dgw1d")
[connection signal="pressed" from="Panel/HBoxContainer4/HBoxContainer4/Button3" to="." method="_on_button_3_pressed"]
[connection signal="pressed" from="pausemenu/VBoxContainer/Button3" to="." method="_on_button_3_pressed"]
[connection signal="pressed" from="pausemenu/VBoxContainer/Button2" to="." method="_on_button_2_pressed"]

View File

@ -27,3 +27,7 @@ func linear2db(linear: float) -> float:
if linear <= 0.0:
return -80.0 # mute
return 20.0 * (log(linear) / log(10.0))
func PauseAudio() ->void:
get_node("AudioStreamPlayer2D").stop()
get_node("AudioStreamPlayer2D2").stop()