diff --git a/CREDITS.md b/CREDITS.md index e7ddac4..81329b7 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -7,7 +7,8 @@ ## Used resources - - zx spectrum font - Sizenko Alexander from [Style-7](http://www.styleseven.com) + - zx spectrum font - Sizenko Alexander from (Style-7) + - footsteps audio - [Kenney](http://www.kenney.nl/) ## Tools diff --git a/default_bus_layout.tres b/default_bus_layout.tres new file mode 100644 index 0000000..539dfc8 --- /dev/null +++ b/default_bus_layout.tres @@ -0,0 +1,21 @@ +[gd_resource type="AudioBusLayout" load_steps=2 format=3 uid="uid://l2ld5cr1ew0r"] + +[sub_resource type="AudioEffectReverb" id="AudioEffectReverb_wcs3s"] +resource_name = "Reverb" +room_size = 0.4 + +[resource] +bus/1/name = &"Music" +bus/1/solo = false +bus/1/mute = false +bus/1/bypass_fx = false +bus/1/volume_db = 0.0 +bus/1/send = &"Master" +bus/2/name = &"Sound" +bus/2/solo = false +bus/2/mute = false +bus/2/bypass_fx = false +bus/2/volume_db = 0.0 +bus/2/send = &"Master" +bus/2/effect/0/effect = SubResource("AudioEffectReverb_wcs3s") +bus/2/effect/0/enabled = true diff --git a/prefabs/AudioCollection.tscn b/prefabs/AudioCollection.tscn new file mode 100644 index 0000000..e50a67c --- /dev/null +++ b/prefabs/AudioCollection.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://phjermaw6phb"] + +[ext_resource type="Script" path="res://scripts/AudioCollection.cs" id="1_qeqpl"] + +[node name="AudioCollection" type="Node"] +script = ExtResource("1_qeqpl") diff --git a/prefabs/Player.tscn b/prefabs/Player.tscn index 6a16bf6..0131e52 100644 --- a/prefabs/Player.tscn +++ b/prefabs/Player.tscn @@ -1,9 +1,13 @@ -[gd_scene load_steps=8 format=3 uid="uid://dfdsnwub212o6"] +[gd_scene load_steps=12 format=3 uid="uid://dfdsnwub212o6"] [ext_resource type="Script" path="res://scripts/Player.cs" id="1_68nsf"] [ext_resource type="SpriteFrames" uid="uid://e8ybb7seykdx" path="res://resources/sprites/player/player.tres" id="1_be2ex"] [ext_resource type="FontFile" uid="uid://dwn20pw40jpxm" path="res://fonts/ZxSpectrum7-nROZ0.ttf" id="3_w5ojp"] [ext_resource type="PackedScene" uid="uid://cmn7af4dsj8v2" path="res://prefabs/Dialog.tscn" id="4_owmws"] +[ext_resource type="AudioStream" uid="uid://bcb1ve32foim7" path="res://resources/sounds/footsteps/impactMetal_heavy_002.ogg" id="5_2q34s"] +[ext_resource type="PackedScene" uid="uid://phjermaw6phb" path="res://prefabs/AudioCollection.tscn" id="5_wnylg"] +[ext_resource type="AudioStream" uid="uid://b0sbab3hle70o" path="res://resources/sounds/footsteps/impactMetal_heavy_003.ogg" id="6_4fib2"] +[ext_resource type="AudioStream" uid="uid://ctxrv13vv8xyb" path="res://resources/sounds/footsteps/impactMetal_heavy_004.ogg" id="7_k5uvo"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_sed4o"] size = Vector2(22, 51) @@ -51,3 +55,18 @@ layout_mode = 2 [node name="Dialog2" parent="Camera2D/ChatLog/HFlowContainer" instance=ExtResource("4_owmws")] layout_mode = 2 + +[node name="Footsteps" parent="." instance=ExtResource("5_wnylg")] +Timeout = 0.2 + +[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="Footsteps"] +stream = ExtResource("5_2q34s") +bus = &"Sound" + +[node name="AudioStreamPlayer2" type="AudioStreamPlayer" parent="Footsteps"] +stream = ExtResource("6_4fib2") +bus = &"Sound" + +[node name="AudioStreamPlayer3" type="AudioStreamPlayer" parent="Footsteps"] +stream = ExtResource("7_k5uvo") +bus = &"Sound" diff --git a/resources/music/Day1.wav b/resources/music/Day1.wav new file mode 100644 index 0000000..81a9acb Binary files /dev/null and b/resources/music/Day1.wav differ diff --git a/resources/music/Day1.wav.import b/resources/music/Day1.wav.import new file mode 100644 index 0000000..283f70f --- /dev/null +++ b/resources/music/Day1.wav.import @@ -0,0 +1,24 @@ +[remap] + +importer="wav" +type="AudioStreamWAV" +uid="uid://be35iuapayv0u" +path="res://.godot/imported/Day1.wav-78baaede954da33fc97a9ea0336dc6f5.sample" + +[deps] + +source_file="res://resources/music/Day1.wav" +dest_files=["res://.godot/imported/Day1.wav-78baaede954da33fc97a9ea0336dc6f5.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 diff --git a/resources/sounds/footsteps/impactMetal_heavy_002.ogg b/resources/sounds/footsteps/impactMetal_heavy_002.ogg new file mode 100644 index 0000000..4e1053c Binary files /dev/null and b/resources/sounds/footsteps/impactMetal_heavy_002.ogg differ diff --git a/resources/sounds/footsteps/impactMetal_heavy_002.ogg.import b/resources/sounds/footsteps/impactMetal_heavy_002.ogg.import new file mode 100644 index 0000000..a418bb8 --- /dev/null +++ b/resources/sounds/footsteps/impactMetal_heavy_002.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://bcb1ve32foim7" +path="res://.godot/imported/impactMetal_heavy_002.ogg-2ce07dc21827373020adf5ad17e8e0cb.oggvorbisstr" + +[deps] + +source_file="res://resources/sounds/footsteps/impactMetal_heavy_002.ogg" +dest_files=["res://.godot/imported/impactMetal_heavy_002.ogg-2ce07dc21827373020adf5ad17e8e0cb.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/resources/sounds/footsteps/impactMetal_heavy_003.ogg b/resources/sounds/footsteps/impactMetal_heavy_003.ogg new file mode 100644 index 0000000..432a448 Binary files /dev/null and b/resources/sounds/footsteps/impactMetal_heavy_003.ogg differ diff --git a/resources/sounds/footsteps/impactMetal_heavy_003.ogg.import b/resources/sounds/footsteps/impactMetal_heavy_003.ogg.import new file mode 100644 index 0000000..863c38f --- /dev/null +++ b/resources/sounds/footsteps/impactMetal_heavy_003.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://b0sbab3hle70o" +path="res://.godot/imported/impactMetal_heavy_003.ogg-dc105179ec501c9d214a07d441289f39.oggvorbisstr" + +[deps] + +source_file="res://resources/sounds/footsteps/impactMetal_heavy_003.ogg" +dest_files=["res://.godot/imported/impactMetal_heavy_003.ogg-dc105179ec501c9d214a07d441289f39.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/resources/sounds/footsteps/impactMetal_heavy_004.ogg b/resources/sounds/footsteps/impactMetal_heavy_004.ogg new file mode 100644 index 0000000..bdb83ee Binary files /dev/null and b/resources/sounds/footsteps/impactMetal_heavy_004.ogg differ diff --git a/resources/sounds/footsteps/impactMetal_heavy_004.ogg.import b/resources/sounds/footsteps/impactMetal_heavy_004.ogg.import new file mode 100644 index 0000000..18465aa --- /dev/null +++ b/resources/sounds/footsteps/impactMetal_heavy_004.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://ctxrv13vv8xyb" +path="res://.godot/imported/impactMetal_heavy_004.ogg-2434a77aab1cc90794b9891fc12840b4.oggvorbisstr" + +[deps] + +source_file="res://resources/sounds/footsteps/impactMetal_heavy_004.ogg" +dest_files=["res://.godot/imported/impactMetal_heavy_004.ogg-2434a77aab1cc90794b9891fc12840b4.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/scenes/test.tscn b/scenes/test.tscn index 12b9c03..a1f2739 100644 --- a/scenes/test.tscn +++ b/scenes/test.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=16 format=3 uid="uid://dwii5fob7qy7c"] +[gd_scene load_steps=18 format=3 uid="uid://dwii5fob7qy7c"] [ext_resource type="Texture2D" uid="uid://b5baxx5o21qy1" path="res://resources/sprites/Sub/Sub.png" id="1_81pua"] [ext_resource type="PackedScene" uid="uid://dfdsnwub212o6" path="res://prefabs/Player.tscn" id="2_mmd6a"] [ext_resource type="SpriteFrames" uid="uid://e8ybb7seykdx" path="res://resources/sprites/player/player.tres" id="3_cqsbi"] [ext_resource type="PackedScene" uid="uid://c5ndo6b0unkst" path="res://prefabs/NPC.tscn" id="3_cu4p0"] [ext_resource type="PackedScene" uid="uid://coogmsw6rsdun" path="res://prefabs/Door.tscn" id="4_22581"] +[ext_resource type="AudioStream" uid="uid://be35iuapayv0u" path="res://resources/music/Day1.wav" id="6_jvwn3"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_h0540"] size = Vector2(640, 24) @@ -36,6 +37,10 @@ size = Vector2(32.75, 104) [sub_resource type="RectangleShape2D" id="RectangleShape2D_bafxi"] size = Vector2(640, 24) +[sub_resource type="AudioStreamPlaylist" id="AudioStreamPlaylist_7838k"] +stream_count = 1 +stream_0 = ExtResource("6_jvwn3") + [node name="Test" type="Node2D"] [node name="Sprite2D" type="Sprite2D" parent="."] @@ -111,7 +116,43 @@ shape = SubResource("RectangleShape2D_i40av") position = Vector2(1032, -221) shape = SubResource("RectangleShape2D_bafxi") -[node name="Npc" parent="." instance=ExtResource("3_cu4p0")] +[node name="Doors" type="Node2D" parent="."] + +[node name="Door_3F" parent="Doors" node_paths=PackedStringArray("Exit") instance=ExtResource("4_22581")] +position = Vector2(788, 14) +Exit = NodePath("../Door_3F2") + +[node name="Door_3F2" parent="Doors" node_paths=PackedStringArray("Exit") instance=ExtResource("4_22581")] +position = Vector2(790, 134) +Exit = NodePath("../Door_3F") + +[node name="Door_MEDBAY" parent="Doors" node_paths=PackedStringArray("Exit") instance=ExtResource("4_22581")] +position = Vector2(474, 134) +Exit = NodePath("../Door_MEDBAY2") + +[node name="Door_MEDBAY2" parent="Doors" node_paths=PackedStringArray("Exit") instance=ExtResource("4_22581")] +position = Vector2(474, 255) +Exit = NodePath("../Door_MEDBAY") + +[node name="Door_SONAR" parent="Doors" node_paths=PackedStringArray("Exit") instance=ExtResource("4_22581")] +position = Vector2(1180, 134) +Exit = NodePath("../Door_SONAR2") + +[node name="Door_SONAR2" parent="Doors" node_paths=PackedStringArray("Exit") instance=ExtResource("4_22581")] +position = Vector2(1179, 14) +Exit = NodePath("../Door_SONAR") + +[node name="Door_QUOTERS" parent="Doors" node_paths=PackedStringArray("Exit") instance=ExtResource("4_22581")] +position = Vector2(1436, 134) +Exit = NodePath("../Door_QUOTERS2") + +[node name="Door_QUOTERS2" parent="Doors" node_paths=PackedStringArray("Exit") instance=ExtResource("4_22581")] +position = Vector2(1442, 255) +Exit = NodePath("../Door_QUOTERS") + +[node name="NPCs" type="Node2D" parent="."] + +[node name="Npc" parent="NPCs" instance=ExtResource("3_cu4p0")] position = Vector2(752, 16) NPCName = "Test" Frames = ExtResource("3_cqsbi") @@ -120,34 +161,7 @@ Frames = ExtResource("3_cqsbi") position = Vector2(263, 14) Speed = 100.0 -[node name="Door_3F" parent="." node_paths=PackedStringArray("Exit") instance=ExtResource("4_22581")] -position = Vector2(788, 14) -Exit = NodePath("../Door_3F2") - -[node name="Door_3F2" parent="." node_paths=PackedStringArray("Exit") instance=ExtResource("4_22581")] -position = Vector2(790, 134) -Exit = NodePath("../Door_3F") - -[node name="Door_MEDBAY" parent="." node_paths=PackedStringArray("Exit") instance=ExtResource("4_22581")] -position = Vector2(474, 134) -Exit = NodePath("../Door_MEDBAY2") - -[node name="Door_MEDBAY2" parent="." node_paths=PackedStringArray("Exit") instance=ExtResource("4_22581")] -position = Vector2(474, 255) -Exit = NodePath("../Door_MEDBAY") - -[node name="Door_SONAR" parent="." node_paths=PackedStringArray("Exit") instance=ExtResource("4_22581")] -position = Vector2(1180, 134) -Exit = NodePath("../Door_SONAR2") - -[node name="Door_SONAR2" parent="." node_paths=PackedStringArray("Exit") instance=ExtResource("4_22581")] -position = Vector2(1179, 14) -Exit = NodePath("../Door_SONAR") - -[node name="Door_QUOTERS" parent="." node_paths=PackedStringArray("Exit") instance=ExtResource("4_22581")] -position = Vector2(1436, 134) -Exit = NodePath("../Door_QUOTERS2") - -[node name="Door_QUOTERS2" parent="." node_paths=PackedStringArray("Exit") instance=ExtResource("4_22581")] -position = Vector2(1442, 255) -Exit = NodePath("../Door_QUOTERS") +[node name="Music" type="AudioStreamPlayer" parent="."] +stream = SubResource("AudioStreamPlaylist_7838k") +autoplay = true +bus = &"Music" diff --git a/scripts/AudioCollection.cs b/scripts/AudioCollection.cs new file mode 100644 index 0000000..39d94e5 --- /dev/null +++ b/scripts/AudioCollection.cs @@ -0,0 +1,86 @@ +using System; +using Godot; + + +public partial class AudioCollection : Node +{ + private enum State + { + Error, + Ready, + Playing, + Timeout + } + + [Export] public bool Shuffle = false; + [Export] public double Timeout = 0; + + private State _state; + + private RandomNumberGenerator _rng = new RandomNumberGenerator(); + + private int _count; + + private int _currentChild; + + private double _currentTimeout = 0; + + private AudioStreamPlayer _currentPlayer; + + public override void _Ready() + { + _rng.Randomize(); + _count = GetChildCount(); + _currentChild = Shuffle ? _rng.RandiRange(0, _count) : 0; + _state = _count == 0 ? State.Error : State.Ready; + } + + public override void _Process(double delta) + { + switch (_state) + { + case State.Playing: + if (!_currentPlayer.IsPlaying()) + { + _state = State.Timeout; + } + + break; + case State.Timeout: + if (_currentTimeout < Timeout) + { + _currentTimeout += delta; + } + else + { + _state = State.Ready; + _currentTimeout = 0; + } + break; + } + } + + public void Play() + { + switch (_state) + { + case State.Ready: + var player = GetChild(_currentChild); + player.Play(); + _state = State.Playing; + _currentChild = Shuffle ? _rng.RandiRange(0, _count) : 0; + _currentPlayer = player; + break; + } + } + + public void Stop() + { + switch (_state) + { + case State.Playing: + _currentPlayer.Stop(); + break; + } + } +} diff --git a/scripts/Player.cs b/scripts/Player.cs index 290b6d8..07f7dfb 100644 --- a/scripts/Player.cs +++ b/scripts/Player.cs @@ -69,6 +69,7 @@ public partial class Player : CharacterBody2D protected AnimatedSprite2D Sprite; protected PanelContainer ChatLog; protected Camera2D Camera; + protected AudioCollection Footsteps; private Vector2 _newPosition; private double _currentTransitionTime = 0; @@ -82,6 +83,7 @@ public partial class Player : CharacterBody2D Sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D"); ChatLog = (PanelContainer)FindChild("ChatLog"); Camera = (Camera2D)FindChild("Camera2D"); + Footsteps = (AudioCollection)FindChild("Footsteps"); } public override void _PhysicsProcess(double delta) @@ -118,6 +120,12 @@ public partial class Player : CharacterBody2D Vector2 direction = Input.GetVector("move_left", "move_right", "move_up", "move_down"); if (direction != Vector2.Zero) { + Footsteps.Play(); + // if (!Footsteps.IsPlaying()) + // { + // // Footsteps.PitchScale = (float)GD.RandRange(0.5, 1.0); + // Footsteps.Play(); + // } velocity.X = direction.X * Speed; Sprite.Play("walk"); Sprite.FlipH = direction.X switch @@ -129,6 +137,7 @@ public partial class Player : CharacterBody2D } else { + // Footsteps.Stop(); velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed); Sprite.Play("default"); }