add Explosion Sounds

Pitch them randomly
pull/11/head
Sascha 2023-10-23 11:46:57 +07:00
parent dfcbc81913
commit 1afff4685a
5 changed files with 43 additions and 12 deletions

@ -120,3 +120,6 @@ texture = ExtResource("5_034vf")
transform = Transform3D(1, -2.84217e-14, 3.82137e-15, 3.82137e-15, 4.37114e-08, -1, 2.84217e-14, 1, 4.37114e-08, 0, -0.01, -1.392)
shaded = true
texture = ExtResource("4_87x8f")
[node name="AudioListener3D" type="AudioListener3D" parent="."]
current = true

@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=3 uid="uid://det8556rpxhbv"]
[gd_scene load_steps=11 format=3 uid="uid://det8556rpxhbv"]
[ext_resource type="PackedScene" uid="uid://tlr55u0gn20l" path="res://Packed-Scenes/player_ship.tscn" id="1_njb5h"]
[ext_resource type="Texture2D" uid="uid://cg6n1hh3lj7rn" path="res://Textures/tile_nebula_green_dff.png" id="2_43vix"]
@ -6,7 +6,9 @@
[ext_resource type="PackedScene" uid="uid://6dn1gjqffnt" path="res://Packed-Scenes/asteroid_01.tscn" id="5_do6ba"]
[ext_resource type="PackedScene" uid="uid://cvlxm2yrohsca" path="res://Packed-Scenes/asteroid_02.tscn" id="6_tqoe7"]
[ext_resource type="PackedScene" uid="uid://brqqgidqchi88" path="res://Packed-Scenes/asteroid_03.tscn" id="7_v6ul2"]
[ext_resource type="Script" path="res://Scripts/SoundManager.cs" id="8_4ksf0"]
[ext_resource type="AudioStream" uid="uid://bthqgu8sulv77" path="res://Sounds/music_background.wav" id="8_4ms0p"]
[ext_resource type="AudioStream" uid="uid://t0y8yw2ceskq" path="res://Sounds/explosion_asteroid.wav" id="9_2dqf6"]
[ext_resource type="Script" path="res://Scripts/GameManager.cs" id="9_rsrr5"]
[node name="SpaceShooter" type="Node3D"]
@ -17,9 +19,6 @@ transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74227e-08, 0, -1, 0, 0,
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 8, 0)
[node name="AudioListener3D" type="AudioListener3D" parent="Camera3D"]
current = true
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.707106, 0.707106, 0, -0.707106, 0.707106, 10, 10, 10)
@ -33,11 +32,6 @@ region_enabled = true
region_rect = Rect2(0, 0, 810, 1380)
script = ExtResource("3_imgbw")
[node name="BackgroundMusic" type="AudioStreamPlayer" parent="."]
stream = ExtResource("8_4ms0p")
volume_db = -20.0
autoplay = true
[node name="GameManager" type="Node" parent="." node_paths=PackedStringArray("labelAsteroids", "labelLifes")]
script = ExtResource("9_rsrr5")
asteroids = Array[PackedScene]([ExtResource("5_do6ba"), ExtResource("6_tqoe7"), ExtResource("7_v6ul2")])
@ -66,3 +60,16 @@ offset_top = 47.0
offset_right = 260.0
offset_bottom = 67.0
text = "Lives: 3"
[node name="SoundManager" type="Node" parent="." node_paths=PackedStringArray("explosionSound", "backgroundMusic")]
script = ExtResource("8_4ksf0")
explosionSound = NodePath("ExplosionSound")
backgroundMusic = NodePath("BackgroundMusic")
[node name="ExplosionSound" type="AudioStreamPlayer3D" parent="SoundManager"]
stream = ExtResource("9_2dqf6")
[node name="BackgroundMusic" type="AudioStreamPlayer" parent="SoundManager"]
stream = ExtResource("8_4ms0p")
volume_db = -20.0
autoplay = true

@ -39,7 +39,8 @@ public partial class Asteroid : Node3D {
if (asteroidRb.Position.Z >= 8f) {
GD.Print($"Asteroid {Name} below screen!");
Explode(asteroidRb.Position);
GameManager.Instance.AsteroidNumber--;
QueueFree();
}
}
@ -50,6 +51,7 @@ public partial class Asteroid : Node3D {
ex.Emitting = true;
}
SoundManager.Instance.PlayExplosion(collisionPosition);
GameManager.Instance.AsteroidNumber--;
QueueFree();
}

@ -5,7 +5,7 @@ namespace Scripts;
public partial class GameManager : Node
{
[Export] private Array<PackedScene> asteroids;
[Export] private float spawnRate = 1f;
[Export] private float spawnRate = 0.1f;
private float spawnTimer;
@ -28,7 +28,7 @@ public partial class GameManager : Node
}
}
private const int asteroidMaxNumber = 3;
private const int asteroidMaxNumber = 100;
private int lives = 3;
private int asteroidNumber;

@ -0,0 +1,19 @@
using Godot;
using Godot.Collections;
namespace Scripts;
public partial class SoundManager : Node {
[Export] private AudioStreamPlayer3D explosionSound;
[Export] private AudioStreamPlayer backgroundMusic;
public static SoundManager Instance { get; private set; }
public override void _Ready() => Instance = this;
public void PlayExplosion(Vector3 position) {
explosionSound.Position = position;
explosionSound.PitchScale = (float)GD.RandRange(0.25f, 1.75f);
explosionSound.Play();
}
}