From 8d627efcc9bec1c9ccb424df8b044ed474f23f69 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 29 Apr 2024 06:22:15 +0200 Subject: [PATCH] Add music and fix things --- behaviours/summoning_circle.gd | 4 +-- entities/chupacabra.tscn | 1 + entities/imp.tscn | 1 + entities/watcher.tscn | 1 + scenes/game/main_game.gd | 12 +++++++++ scenes/game/main_game.tscn | 8 +++++- scenes/game/music.gd | 26 ++++++++++++++++++ scenes/game/music.tscn | 27 +++++++++++++++++++ .../layer1song.mp3 => scenes/game/music_1.mp3 | 0 scenes/game/music_1.mp3.import | 19 +++++++++++++ .../layer2song.mp3 => scenes/game/music_2.mp3 | 0 scenes/game/music_2.mp3.import | 19 +++++++++++++ .../layer3song.mp3 => scenes/game/music_3.mp3 | 0 scenes/game/music_3.mp3.import | 19 +++++++++++++ temp/layer1song.mp3.import | 19 ------------- temp/layer2song.mp3.import | 19 ------------- temp/layer3song.mp3.import | 19 ------------- 17 files changed, 134 insertions(+), 60 deletions(-) create mode 100644 scenes/game/music.gd create mode 100644 scenes/game/music.tscn rename temp/layer1song.mp3 => scenes/game/music_1.mp3 (100%) create mode 100644 scenes/game/music_1.mp3.import rename temp/layer2song.mp3 => scenes/game/music_2.mp3 (100%) create mode 100644 scenes/game/music_2.mp3.import rename temp/layer3song.mp3 => scenes/game/music_3.mp3 (100%) create mode 100644 scenes/game/music_3.mp3.import delete mode 100644 temp/layer1song.mp3.import delete mode 100644 temp/layer2song.mp3.import delete mode 100644 temp/layer3song.mp3.import diff --git a/behaviours/summoning_circle.gd b/behaviours/summoning_circle.gd index 0b23c3f..f16b6a4 100644 --- a/behaviours/summoning_circle.gd +++ b/behaviours/summoning_circle.gd @@ -66,7 +66,7 @@ func _on_sacrifice_changed(_entity: Node2D) -> void: if recipe.do_match(entities): break -func _on_recipe_matched(m: SummoningRecipe.Match, _recipe: SummoningRecipe) -> void: - recipe_matched.emit() +func _on_recipe_matched(m: SummoningRecipe.Match, recipe: SummoningRecipe) -> void: + recipe_matched.emit(m, recipe) for sacrificable in m.sacrificables: sacrificable.sacrifice() diff --git a/entities/chupacabra.tscn b/entities/chupacabra.tscn index 2b082e2..7d8c43b 100644 --- a/entities/chupacabra.tscn +++ b/entities/chupacabra.tscn @@ -483,6 +483,7 @@ debug_color = Color(1, 0, 0, 0) stream = ExtResource("17_ccla5") bus = &"KillSounds" +[connection signal="sacrificed" from="Sacrificable" to="." method="queue_free"] [connection signal="changed_direction" from="MovementWander" to="MovementWander/WanderPriority" method="priority_conditional"] [connection signal="move" from="MovementWander" to="." method="_on_move"] [connection signal="move_disabled" from="MovementWander" to="MovementWander" method="clear_direction"] diff --git a/entities/imp.tscn b/entities/imp.tscn index 36f22f4..3a0dce6 100644 --- a/entities/imp.tscn +++ b/entities/imp.tscn @@ -348,6 +348,7 @@ debug_color = Color(1, 0, 0, 0) stream = ExtResource("19_7la6c") bus = &"KillSounds" +[connection signal="sacrificed" from="Sacrificable" to="." method="queue_free"] [connection signal="timeout" from="GoldSpawner/SpawnTimer" to="GoldSpawner" method="spawn"] [connection signal="changed_direction" from="MovementWander" to="MovementWander/WanderPriority" method="priority_conditional"] [connection signal="move" from="MovementWander" to="." method="_on_move"] diff --git a/entities/watcher.tscn b/entities/watcher.tscn index 850a27f..b51a819 100644 --- a/entities/watcher.tscn +++ b/entities/watcher.tscn @@ -222,6 +222,7 @@ bus = &"DragSounds" stream = ExtResource("12_0h21e") bus = &"FallSounds" +[connection signal="sacrificed" from="Sacrificable" to="." method="queue_free"] [connection signal="changed_target" from="MovementTrap" to="MovementTrap/TrapPriority" method="priority_conditional"] [connection signal="move" from="MovementTrap" to="." method="_on_move"] [connection signal="move_disabled" from="MovementTrap" to="." method="_on_freed"] diff --git a/scenes/game/main_game.gd b/scenes/game/main_game.gd index 004c948..6bb83a6 100644 --- a/scenes/game/main_game.gd +++ b/scenes/game/main_game.gd @@ -6,6 +6,7 @@ class_name MainGame @onready var default_spawn_parent: Node2D = %"DefaultSpawnParent" @onready var inventory: Inventory = %"Inventory" @onready var cursor: Cursor = %"Cursor" +@onready var music: Music = %"Music" static func get_via_group(node: Node) -> MainGame: @@ -20,3 +21,14 @@ func _ready(): var gold_counter = inventory.get_counter(&"Gold") gold_counter.changed.connect(cursor.gold_display.change) cursor.gold_display.set_text(gold_counter.value) + +func _on_recipe_matched(m: SummoningRecipe.Match, recipe: SummoningRecipe) -> void: + # Quick hack for now + match recipe.name: + "FiveSheep": + music.enable_layer_1() + music.do_sync() + "FiveImps": + music.enable_layer_2() + "FiveChupacabra": + music.enable_layer_3() diff --git a/scenes/game/main_game.tscn b/scenes/game/main_game.tscn index 53f4a01..2b65538 100644 --- a/scenes/game/main_game.tscn +++ b/scenes/game/main_game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=25 format=3 uid="uid://cxj5aud02f40j"] +[gd_scene load_steps=26 format=3 uid="uid://cxj5aud02f40j"] [ext_resource type="Script" path="res://scenes/game/main_game.gd" id="1_wiglu"] [ext_resource type="PackedScene" uid="uid://dm068vaseh45n" path="res://scenes/game/game_camera.tscn" id="2_db5xs"] @@ -6,6 +6,7 @@ [ext_resource type="Texture2D" uid="uid://d13j4br4hxek6" path="res://scenes/game/tileset_grass.png" id="2_o7bg5"] [ext_resource type="PackedScene" uid="uid://brvbtvt4em32" path="res://behaviours/counter.tscn" id="3_we8s5"] [ext_resource type="Texture2D" uid="uid://ki0xyx6gvkty" path="res://scenes/game/tileset_flowers.png" id="4_dlm0d"] +[ext_resource type="PackedScene" uid="uid://dhrftd3ni6d20" path="res://scenes/game/music.tscn" id="4_q73jh"] [ext_resource type="PackedScene" uid="uid://col1q3elvkfwk" path="res://scenes/game/cursor.tscn" id="5_g504x"] [ext_resource type="Texture2D" uid="uid://bxm3edor0akqj" path="res://scenes/game/tileset_flowers_shaded.png" id="5_yqthh"] [ext_resource type="PackedScene" uid="uid://b3gydtrenbw3n" path="res://entities/skull.tscn" id="6_5k7gy"] @@ -861,6 +862,9 @@ script = ExtResource("1_wiglu") unique_name_in_owner = true counter_scene = ExtResource("3_we8s5") +[node name="Music" parent="." instance=ExtResource("4_q73jh")] +unique_name_in_owner = true + [node name="FloorTileMap" type="TileMap" parent="."] z_index = -30 scale = Vector2(2, 2) @@ -983,3 +987,5 @@ position = Vector2(341, 247) [node name="Tree5" parent="." instance=ExtResource("18_r8twr")] position = Vector2(379, 292) + +[connection signal="recipe_matched" from="SummoningCirclePentagram" to="." method="_on_recipe_matched"] diff --git a/scenes/game/music.gd b/scenes/game/music.gd new file mode 100644 index 0000000..315cd4e --- /dev/null +++ b/scenes/game/music.gd @@ -0,0 +1,26 @@ +extends Node +class_name Music + + +@onready var layer_1: AudioStreamPlayer = %"Layer1" +@onready var layer_2: AudioStreamPlayer = %"Layer2" +@onready var layer_3: AudioStreamPlayer = %"Layer3" + + +func do_sync(): + var position = layer_1.get_playback_position() + layer_1.stop() + layer_2.stop() + layer_3.stop() + layer_1.play(position) + layer_2.play(position) + layer_3.play(position) + +func enable_layer_1(): + layer_1.volume_db = 0 + +func enable_layer_2(): + layer_2.volume_db = 0 + +func enable_layer_3(): + layer_3.volume_db = 0 diff --git a/scenes/game/music.tscn b/scenes/game/music.tscn new file mode 100644 index 0000000..8318dc8 --- /dev/null +++ b/scenes/game/music.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=5 format=3 uid="uid://dhrftd3ni6d20"] + +[ext_resource type="Script" path="res://scenes/game/music.gd" id="1_qp1t4"] +[ext_resource type="AudioStream" uid="uid://pfr5ilmpa2me" path="res://scenes/game/music_1.mp3" id="2_0bhsw"] +[ext_resource type="AudioStream" uid="uid://c3h5p4m001fve" path="res://scenes/game/music_2.mp3" id="3_cb8nm"] +[ext_resource type="AudioStream" uid="uid://cp85uoga2ga5v" path="res://scenes/game/music_3.mp3" id="4_jcbtb"] + +[node name="Music" type="Node"] +script = ExtResource("1_qp1t4") + +[node name="Layer1" type="AudioStreamPlayer" parent="."] +unique_name_in_owner = true +stream = ExtResource("2_0bhsw") +volume_db = -80.0 +bus = &"Music" + +[node name="Layer2" type="AudioStreamPlayer" parent="."] +unique_name_in_owner = true +stream = ExtResource("3_cb8nm") +volume_db = -80.0 +bus = &"Music" + +[node name="Layer3" type="AudioStreamPlayer" parent="."] +unique_name_in_owner = true +stream = ExtResource("4_jcbtb") +volume_db = -80.0 +bus = &"Music" diff --git a/temp/layer1song.mp3 b/scenes/game/music_1.mp3 similarity index 100% rename from temp/layer1song.mp3 rename to scenes/game/music_1.mp3 diff --git a/scenes/game/music_1.mp3.import b/scenes/game/music_1.mp3.import new file mode 100644 index 0000000..078d4d7 --- /dev/null +++ b/scenes/game/music_1.mp3.import @@ -0,0 +1,19 @@ +[remap] + +importer="mp3" +type="AudioStreamMP3" +uid="uid://pfr5ilmpa2me" +path="res://.godot/imported/music_1.mp3-6430d0f78bf931cf6d2e236b4c074449.mp3str" + +[deps] + +source_file="res://scenes/game/music_1.mp3" +dest_files=["res://.godot/imported/music_1.mp3-6430d0f78bf931cf6d2e236b4c074449.mp3str"] + +[params] + +loop=true +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/temp/layer2song.mp3 b/scenes/game/music_2.mp3 similarity index 100% rename from temp/layer2song.mp3 rename to scenes/game/music_2.mp3 diff --git a/scenes/game/music_2.mp3.import b/scenes/game/music_2.mp3.import new file mode 100644 index 0000000..1f8778e --- /dev/null +++ b/scenes/game/music_2.mp3.import @@ -0,0 +1,19 @@ +[remap] + +importer="mp3" +type="AudioStreamMP3" +uid="uid://c3h5p4m001fve" +path="res://.godot/imported/music_2.mp3-9ad7929d0039d7f2980e17fd57b96f54.mp3str" + +[deps] + +source_file="res://scenes/game/music_2.mp3" +dest_files=["res://.godot/imported/music_2.mp3-9ad7929d0039d7f2980e17fd57b96f54.mp3str"] + +[params] + +loop=true +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/temp/layer3song.mp3 b/scenes/game/music_3.mp3 similarity index 100% rename from temp/layer3song.mp3 rename to scenes/game/music_3.mp3 diff --git a/scenes/game/music_3.mp3.import b/scenes/game/music_3.mp3.import new file mode 100644 index 0000000..d4bb112 --- /dev/null +++ b/scenes/game/music_3.mp3.import @@ -0,0 +1,19 @@ +[remap] + +importer="mp3" +type="AudioStreamMP3" +uid="uid://cp85uoga2ga5v" +path="res://.godot/imported/music_3.mp3-69017ed8865f2e7206faff017c5be6eb.mp3str" + +[deps] + +source_file="res://scenes/game/music_3.mp3" +dest_files=["res://.godot/imported/music_3.mp3-69017ed8865f2e7206faff017c5be6eb.mp3str"] + +[params] + +loop=true +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/temp/layer1song.mp3.import b/temp/layer1song.mp3.import deleted file mode 100644 index 6ce11b8..0000000 --- a/temp/layer1song.mp3.import +++ /dev/null @@ -1,19 +0,0 @@ -[remap] - -importer="mp3" -type="AudioStreamMP3" -uid="uid://pfr5ilmpa2me" -path="res://.godot/imported/layer1song.mp3-ce6bc20da8db13507fd0fd3e8c653f57.mp3str" - -[deps] - -source_file="res://temp/layer1song.mp3" -dest_files=["res://.godot/imported/layer1song.mp3-ce6bc20da8db13507fd0fd3e8c653f57.mp3str"] - -[params] - -loop=false -loop_offset=0 -bpm=0 -beat_count=0 -bar_beats=4 diff --git a/temp/layer2song.mp3.import b/temp/layer2song.mp3.import deleted file mode 100644 index 903acf2..0000000 --- a/temp/layer2song.mp3.import +++ /dev/null @@ -1,19 +0,0 @@ -[remap] - -importer="mp3" -type="AudioStreamMP3" -uid="uid://c3h5p4m001fve" -path="res://.godot/imported/layer2song.mp3-bddbe3acc20e065899d402af3799ca36.mp3str" - -[deps] - -source_file="res://temp/layer2song.mp3" -dest_files=["res://.godot/imported/layer2song.mp3-bddbe3acc20e065899d402af3799ca36.mp3str"] - -[params] - -loop=false -loop_offset=0 -bpm=0 -beat_count=0 -bar_beats=4 diff --git a/temp/layer3song.mp3.import b/temp/layer3song.mp3.import deleted file mode 100644 index 7dc86b5..0000000 --- a/temp/layer3song.mp3.import +++ /dev/null @@ -1,19 +0,0 @@ -[remap] - -importer="mp3" -type="AudioStreamMP3" -uid="uid://cp85uoga2ga5v" -path="res://.godot/imported/layer3song.mp3-5c48dfba6496ab0d326a87278a421d8b.mp3str" - -[deps] - -source_file="res://temp/layer3song.mp3" -dest_files=["res://.godot/imported/layer3song.mp3-5c48dfba6496ab0d326a87278a421d8b.mp3str"] - -[params] - -loop=false -loop_offset=0 -bpm=0 -beat_count=0 -bar_beats=4