diff --git a/project.godot b/project.godot index cd4598a..89513af 100644 --- a/project.godot +++ b/project.godot @@ -18,6 +18,10 @@ boot_splash/bg_color=Color(0.92549, 0.92549, 0.960784, 1) boot_splash/image="res://splash-screen.png" config/icon="res://icon.png" +[autoload] + +Audio="*res://scripts/audio.gd" + [editor] movie_writer/movie_file="D:/Godot/recording.avi" diff --git a/scenes/main.tscn b/scenes/main.tscn index b874887..3a3b8bd 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=25 format=3 uid="uid://vgwrcfy1qawf"] +[gd_scene load_steps=26 format=3 uid="uid://vgwrcfy1qawf"] [ext_resource type="Script" uid="uid://76g8ejmdibal" path="res://scripts/builder.gd" id="1_jybm7"] [ext_resource type="Environment" uid="uid://jbptgqvstei3" path="res://scenes/main-environment.tres" id="1_yndf3"] @@ -23,6 +23,7 @@ [ext_resource type="FontFile" uid="uid://d0cxd77jybrcn" path="res://fonts/lilita_one_regular.ttf" id="16_vlub6"] [ext_resource type="Texture2D" uid="uid://bng0d1sou7c8a" path="res://sprites/coin.png" id="17_cjamx"] [ext_resource type="Texture2D" uid="uid://ciwbdik3tmxtp" path="res://sprites/instructions.png" id="22_pm3ni"] +[ext_resource type="AudioStream" uid="uid://wvfsgkl8qob6" path="res://sounds/ambience.ogg" id="24_y6deb"] [sub_resource type="LabelSettings" id="LabelSettings_q176i"] font = ExtResource("16_vlub6") @@ -111,3 +112,8 @@ offset_right = 344.0 offset_bottom = 887.0 scale = Vector2(0.5, 0.5) texture = ExtResource("22_pm3ni") + +[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] +stream = ExtResource("24_y6deb") +volume_db = -30.0 +autoplay = true diff --git a/scripts/audio.gd b/scripts/audio.gd new file mode 100644 index 0000000..e8141ef --- /dev/null +++ b/scripts/audio.gd @@ -0,0 +1,42 @@ +extends Node + +# Code adapted from KidsCanCode + +var num_players = 12 +var bus = "master" + +var available = [] # The available players. +var queue = [] # The queue of {path, volume} dictionaries. + +func _ready(): + for i in num_players: + var p = AudioStreamPlayer.new() + add_child(p) + + available.append(p) + + p.volume_db = -10 + p.finished.connect(_on_stream_finished.bind(p)) + p.bus = bus + +func _on_stream_finished(stream): + available.append(stream) + +func play(sound_path: String, volume_db: float = -10.0): + # Path (or multiple, separated by commas) + var sounds = sound_path.split(",") + var chosen = "res://" + sounds[randi() % sounds.size()].strip_edges() + queue.append({ + "path": chosen, + "volume": volume_db + }) + +func _process(_delta): + if not queue.is_empty() and not available.is_empty(): + var item = queue.pop_front() + var player = available.pop_front() + + player.stream = load(item["path"]) + player.volume_db = item["volume"] + player.pitch_scale = randf_range(0.9, 1.1) + player.play() diff --git a/scripts/audio.gd.uid b/scripts/audio.gd.uid new file mode 100644 index 0000000..e19f8c1 --- /dev/null +++ b/scripts/audio.gd.uid @@ -0,0 +1 @@ +uid://b6g5iasbsyq1x diff --git a/scripts/builder.gd b/scripts/builder.gd index fb8345f..d0b4c78 100644 --- a/scripts/builder.gd +++ b/scripts/builder.gd @@ -84,27 +84,36 @@ func action_build(gridmap_position): if previous_tile != index: map.cash -= structures[index].price update_cash() + + Audio.play("sounds/placement-a.ogg, sounds/placement-b.ogg, sounds/placement-c.ogg, sounds/placement-d.ogg", -20) # Demolish (remove) a structure func action_demolish(gridmap_position): if Input.is_action_just_pressed("demolish"): - gridmap.set_cell_item(gridmap_position, -1) + if gridmap.get_cell_item(gridmap_position) != -1: + gridmap.set_cell_item(gridmap_position, -1) + + Audio.play("sounds/removal-a.ogg, sounds/removal-b.ogg, sounds/removal-c.ogg, sounds/removal-d.ogg", -20) # Rotates the 'cursor' 90 degrees func action_rotate(): if Input.is_action_just_pressed("rotate"): selector.rotate_y(deg_to_rad(90)) + + Audio.play("sounds/rotate.ogg", -30) # Toggle between structures to build func action_structure_toggle(): if Input.is_action_just_pressed("structure_next"): index = wrap(index + 1, 0, structures.size()) + Audio.play("sounds/toggle.ogg", -30) if Input.is_action_just_pressed("structure_previous"): index = wrap(index - 1, 0, structures.size()) + Audio.play("sounds/toggle.ogg", -30) update_structure() diff --git a/sounds/ambience.ogg b/sounds/ambience.ogg new file mode 100644 index 0000000..86f7cca Binary files /dev/null and b/sounds/ambience.ogg differ diff --git a/sounds/ambience.ogg.import b/sounds/ambience.ogg.import new file mode 100644 index 0000000..732deb9 --- /dev/null +++ b/sounds/ambience.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://wvfsgkl8qob6" +path="res://.godot/imported/ambience.ogg-06f8005a28aaf7071eab8a3c7655940a.oggvorbisstr" + +[deps] + +source_file="res://sounds/ambience.ogg" +dest_files=["res://.godot/imported/ambience.ogg-06f8005a28aaf7071eab8a3c7655940a.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/sounds/placement-a.ogg b/sounds/placement-a.ogg new file mode 100644 index 0000000..52c445c Binary files /dev/null and b/sounds/placement-a.ogg differ diff --git a/sounds/placement-a.ogg.import b/sounds/placement-a.ogg.import new file mode 100644 index 0000000..7124b4a --- /dev/null +++ b/sounds/placement-a.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://dvmkltf62sl6d" +path="res://.godot/imported/placement-a.ogg-bdb1e41ed026dd9d40a4cf95bf46f2f8.oggvorbisstr" + +[deps] + +source_file="res://sounds/placement-a.ogg" +dest_files=["res://.godot/imported/placement-a.ogg-bdb1e41ed026dd9d40a4cf95bf46f2f8.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/sounds/placement-b.ogg b/sounds/placement-b.ogg new file mode 100644 index 0000000..c43b705 Binary files /dev/null and b/sounds/placement-b.ogg differ diff --git a/sounds/placement-b.ogg.import b/sounds/placement-b.ogg.import new file mode 100644 index 0000000..cbf56ca --- /dev/null +++ b/sounds/placement-b.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://bclwh4gkbpgc0" +path="res://.godot/imported/placement-b.ogg-d700d7e7fe0800ffc3998bbf539d723e.oggvorbisstr" + +[deps] + +source_file="res://sounds/placement-b.ogg" +dest_files=["res://.godot/imported/placement-b.ogg-d700d7e7fe0800ffc3998bbf539d723e.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/sounds/placement-c.ogg b/sounds/placement-c.ogg new file mode 100644 index 0000000..f783973 Binary files /dev/null and b/sounds/placement-c.ogg differ diff --git a/sounds/placement-c.ogg.import b/sounds/placement-c.ogg.import new file mode 100644 index 0000000..c3b2899 --- /dev/null +++ b/sounds/placement-c.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://dlyw5vro7nndy" +path="res://.godot/imported/placement-c.ogg-0914c55e4166d68221b1f531bfaac866.oggvorbisstr" + +[deps] + +source_file="res://sounds/placement-c.ogg" +dest_files=["res://.godot/imported/placement-c.ogg-0914c55e4166d68221b1f531bfaac866.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/sounds/placement-d.ogg b/sounds/placement-d.ogg new file mode 100644 index 0000000..830699d Binary files /dev/null and b/sounds/placement-d.ogg differ diff --git a/sounds/placement-d.ogg.import b/sounds/placement-d.ogg.import new file mode 100644 index 0000000..7c33638 --- /dev/null +++ b/sounds/placement-d.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://beod8l1kkkncu" +path="res://.godot/imported/placement-d.ogg-e0662b91eb0812e10f48dc671192b2e6.oggvorbisstr" + +[deps] + +source_file="res://sounds/placement-d.ogg" +dest_files=["res://.godot/imported/placement-d.ogg-e0662b91eb0812e10f48dc671192b2e6.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/sounds/removal-a.ogg b/sounds/removal-a.ogg new file mode 100644 index 0000000..06e2110 Binary files /dev/null and b/sounds/removal-a.ogg differ diff --git a/sounds/removal-a.ogg.import b/sounds/removal-a.ogg.import new file mode 100644 index 0000000..f932667 --- /dev/null +++ b/sounds/removal-a.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://1tf8k7b76bxv" +path="res://.godot/imported/removal-a.ogg-d917c6911910529dc9d47d7785b2e382.oggvorbisstr" + +[deps] + +source_file="res://sounds/removal-a.ogg" +dest_files=["res://.godot/imported/removal-a.ogg-d917c6911910529dc9d47d7785b2e382.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/sounds/removal-b.ogg b/sounds/removal-b.ogg new file mode 100644 index 0000000..27de469 Binary files /dev/null and b/sounds/removal-b.ogg differ diff --git a/sounds/removal-b.ogg.import b/sounds/removal-b.ogg.import new file mode 100644 index 0000000..856ecb3 --- /dev/null +++ b/sounds/removal-b.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://dqwaqhr6r6hui" +path="res://.godot/imported/removal-b.ogg-c06a07f2ba569575112caae669ec8bc5.oggvorbisstr" + +[deps] + +source_file="res://sounds/removal-b.ogg" +dest_files=["res://.godot/imported/removal-b.ogg-c06a07f2ba569575112caae669ec8bc5.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/sounds/removal-c.ogg b/sounds/removal-c.ogg new file mode 100644 index 0000000..d4c1d15 Binary files /dev/null and b/sounds/removal-c.ogg differ diff --git a/sounds/removal-c.ogg.import b/sounds/removal-c.ogg.import new file mode 100644 index 0000000..56f8ba9 --- /dev/null +++ b/sounds/removal-c.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://coeitccvxgdck" +path="res://.godot/imported/removal-c.ogg-d4227e081d5850200b0d7221d5e128ef.oggvorbisstr" + +[deps] + +source_file="res://sounds/removal-c.ogg" +dest_files=["res://.godot/imported/removal-c.ogg-d4227e081d5850200b0d7221d5e128ef.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/sounds/removal-d.ogg b/sounds/removal-d.ogg new file mode 100644 index 0000000..f25aa19 Binary files /dev/null and b/sounds/removal-d.ogg differ diff --git a/sounds/removal-d.ogg.import b/sounds/removal-d.ogg.import new file mode 100644 index 0000000..90a2616 --- /dev/null +++ b/sounds/removal-d.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://d0pi1p2aqvfnb" +path="res://.godot/imported/removal-d.ogg-a0f42199d9bdc9ce5fb842f46d43359d.oggvorbisstr" + +[deps] + +source_file="res://sounds/removal-d.ogg" +dest_files=["res://.godot/imported/removal-d.ogg-a0f42199d9bdc9ce5fb842f46d43359d.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/sounds/rotate.ogg b/sounds/rotate.ogg new file mode 100644 index 0000000..53c5fee Binary files /dev/null and b/sounds/rotate.ogg differ diff --git a/sounds/rotate.ogg.import b/sounds/rotate.ogg.import new file mode 100644 index 0000000..85e4943 --- /dev/null +++ b/sounds/rotate.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://d2c30dgleod1s" +path="res://.godot/imported/rotate.ogg-b4286264d3c0e679948714c50e420e7b.oggvorbisstr" + +[deps] + +source_file="res://sounds/rotate.ogg" +dest_files=["res://.godot/imported/rotate.ogg-b4286264d3c0e679948714c50e420e7b.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/sounds/toggle.ogg b/sounds/toggle.ogg new file mode 100644 index 0000000..91db121 Binary files /dev/null and b/sounds/toggle.ogg differ diff --git a/sounds/toggle.ogg.import b/sounds/toggle.ogg.import new file mode 100644 index 0000000..dfcf987 --- /dev/null +++ b/sounds/toggle.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://bjgshtt2m3gi5" +path="res://.godot/imported/toggle.ogg-1f105799e2386c6ae75253b056c1336b.oggvorbisstr" + +[deps] + +source_file="res://sounds/toggle.ogg" +dest_files=["res://.godot/imported/toggle.ogg-1f105799e2386c6ae75253b056c1336b.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4