Skip to content

Commit

Permalink
Audio Update
Browse files Browse the repository at this point in the history
-- VERSION RELEASE 1.1.0 --

[UPDATES]:
 - New audios for the explosions for the "armored" and for the "bomber" enemies;
 - New audio played when the player die;

[CHANGES]:
 - Clean up the logic of the code;
 - Unused AudioStreamPlayer2D and Particles2D nodes will autodelete after some seconds;
  • Loading branch information
Stefano-Labianca authored Sep 25, 2021
2 parents f109af7 + ae42463 commit 73eb62b
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 64 deletions.
4 changes: 2 additions & 2 deletions .import/bomb.wav-53d9c289295285d77cf5bcdcba7a043c.md5
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source_md5="01355e4fde2397c03ba622cb409c12d8"
dest_md5="e0e6f6d8502dd2e93253d55dcedb625a"
source_md5="e5e0ba410c685e1a428aec9a6bc1534f"
dest_md5="7a2226bd964804ad214cb45888aa8282"

Binary file modified .import/bomb.wav-53d9c289295285d77cf5bcdcba7a043c.sample
Binary file not shown.
4 changes: 2 additions & 2 deletions .import/bomb_bot.wav-02f9e5de3b653a3bad693fdbd08338b2.md5
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source_md5="21404afc75a8064a8b82295c3fefa66a"
dest_md5="4298b9502d932721dbba62dcc82c1f5e"
source_md5="7a707f7929ea23c9ec373ae0bcc21f14"
dest_md5="906c2b35e4a88445fae310d79692a4e0"

Binary file modified .import/bomb_bot.wav-02f9e5de3b653a3bad693fdbd08338b2.sample
Binary file not shown.
4 changes: 2 additions & 2 deletions .import/dead_sound.wav-3092a271da9579641bec8e252931a4ad.md5
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source_md5="5cfe8e28413a39e375c15d233db38017"
dest_md5="462175630cd44d81a578da111d874987"
source_md5="19953d3fa1d3505f426ac26005beadd4"
dest_md5="89c4ee19be5c0996b1805196ba5b19f1"

Binary file modified .import/dead_sound.wav-3092a271da9579641bec8e252931a4ad.sample
Binary file not shown.
19 changes: 13 additions & 6 deletions Global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const GAME_SCENE_PATH: String = "res://World.tscn"
const LOGIN_SCENE_PATH: String = "res://World.tscn"
const DIRECTORY_SAVE_FILE: String = "user://save/"
const SAVE_FILE_PATH: String = DIRECTORY_SAVE_FILE + "save_game.dat"
const DEAD_VOLUME: float = -5.5
const CLICK_VOLUME: float = -4.0
const DEAD_VOLUME: float = -13.75
const CLICK_VOLUME: float = -7.0

var score_label: Label = null
var score_node = null
Expand Down Expand Up @@ -60,12 +60,14 @@ var enemy_dict: Dictionary = {
var explosion_type: Dictionary = {
"bomber_explosion": {
"particles": preload("res://particles/Explosion.tscn"),
"sound": load("res://assets/audio/sounds/bomb.wav")
"sound": load("res://assets/audio/sounds/bomb.wav"),
"volume": -7.5
},

"armored_explosion": {
"particles": preload("res://particles/ExplosionBot.tscn"),
"sound": load("res://assets/audio/sounds/bomb_bot.wav")
"sound": load("res://assets/audio/sounds/bomb_bot.wav"),
"volume": -15.5
}
}

Expand All @@ -92,5 +94,10 @@ func create_click_sound(button_position: Vector2) -> void:
click.play(0)


func _on_player_killed():
print("Morto")
func _clean_particles_and_sounds_on_timeout(audio: AudioStreamPlayer2D, particle: Particles2D) -> void:
audio.queue_free()
particle.queue_free()


func _clean_sounds_on_timeout(audio: AudioStreamPlayer2D) -> void:
audio.queue_free()
2 changes: 1 addition & 1 deletion Scenes/GUI/GameOver.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ margin_top = 396.0
margin_right = 1280.0
margin_bottom = 439.0
custom_fonts/font = SubResource( 4 )
text = "Premi 'Spazio' per ricominciare"
text = "Press 'Space' to restart"
align = 1
valign = 1
10 changes: 0 additions & 10 deletions Scenes/Online/Server.tscn

This file was deleted.

2 changes: 1 addition & 1 deletion Scenes/Player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extents = Vector2( 13.7541, 13.329 )
script = ExtResource( 2 )

[node name="Muzzle" type="Position2D" parent="."]
position = Vector2( 29.0627, 0 )
position = Vector2( 29, 0 )

[node name="Sprite" type="Sprite" parent="."]
scale = Vector2( 1.5, 1.5 )
Expand Down
75 changes: 56 additions & 19 deletions Scripts/enemy_script.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ extends KinematicBody2D
signal player_killed

const WEIGHT: float = 0.55
const EXPLOSION_VOLUME: float = -6.5
const HIT_VOLUME: float = -4.50

var enemy_speed: int
Expand Down Expand Up @@ -40,14 +39,13 @@ func _follow_player(delta: float) -> void:

func _on_Hitbox_body_entered(body: Node) -> void:
if body.is_in_group("player"):
if enemy_type == 3: # Verifico se il tipo di nemico è il 'bomber'
_show_explosion("bomber_explosion")
_play_explosion_sound("bomber_explosion")
if enemy_type == 3: # Check if the enemy is the 'bomber'
_instantiate_enemy_dead("bomber_explosion")

Global.play_dead_sound(body.position)

self.queue_free()
body.queue_free() # Uccidi il player
self.queue_free() # Enemy disappears
body.queue_free() # Kill the player
Global.player = null

_connect_player_killed_signal()
Expand All @@ -63,12 +61,10 @@ func _on_Hitbox_body_entered(body: Node) -> void:

if enemy_lives == 0:
if enemy_type == 3: # Check if the enemy is the 'bomber'
_show_explosion("bomber_explosion")
_play_explosion_sound("bomber_explosion")
_instantiate_enemy_dead("bomber_explosion")

if enemy_type == 4: # Check if the enemy is the 'armored'
_show_explosion("armored_explosion")
_play_explosion_sound("armored_explosion")
_instantiate_enemy_dead("armored_explosion")

Global.score_node.callv("update_score", [enemy_score])
_show_score_feed()
Expand All @@ -79,26 +75,24 @@ func _on_Hitbox_body_entered(body: Node) -> void:
$Sprite.texture = Global.stun_texture


# Show the explosion for the enemy type 'bomber' and 'armored'
func _show_explosion(explosion_type: String) -> void:
# Show the explosion for the enemy type 'bomber' or 'armored'
func _get_explosion(explosion_type: String) -> Particles2D:
var ExplosionParticles = Global.explosion_type[explosion_type].particles
var explosion_particles_instance = ExplosionParticles.instance()

explosion_particles_instance.position = self.position
get_tree().get_root().call_deferred("add_child", explosion_particles_instance, true)
explosion_particles_instance.emitting = true


return explosion_particles_instance


func _play_explosion_sound(explosion_type: String) -> void:
func _get_explosion_sound(explosion_type: String) -> AudioStreamPlayer2D:
var explosion_audio = AudioStreamPlayer2D.new()

explosion_audio.stream = Global.explosion_type[explosion_type].sound
explosion_audio.position = self.position
explosion_audio.volume_db = EXPLOSION_VOLUME
explosion_audio.volume_db = Global.explosion_type[explosion_type].volume

get_tree().get_root().call_deferred("add_child", explosion_audio, true)
explosion_audio.play(0)
return explosion_audio


func _play_hit_sound() -> void:
Expand All @@ -108,10 +102,25 @@ func _play_hit_sound() -> void:
hit_sound.position = self.position
hit_sound.volume_db = HIT_VOLUME

var timer: Timer = _create_hit_life_timer(hit_sound)
hit_sound.add_child(timer, true)

get_tree().get_root().call_deferred("add_child", hit_sound, true)
hit_sound.play(0)


# Return a life timer, of 3 seconds, for the [audio] of the enemy's hit.
# - [audio: AudioStreamPlayer2D] - The hit audio.
func _create_hit_life_timer(audio: AudioStreamPlayer2D) -> Timer:
var life_timer: Timer = Timer.new()

life_timer.wait_time = 3
life_timer.autostart = true
life_timer.connect("timeout", Global, "_clean_sounds_on_timeout", [audio])

return life_timer


func _show_score_feed() -> void:
var score_feed: Label = Global.score_feed.instance()
score_feed.text = "+" + str(enemy_score)
Expand All @@ -126,6 +135,34 @@ func _on_StunTimer_timeout() -> void:
$Sprite.texture = enemy_sprite


# Return a life timer, of 3 seconds, for the [audio] of the explosion.
# - [audio: AudioStreamPlayer2D] - The explosion audio.
# - [particle: Particles2D] - The visual effect of the explosion.
func _create_explosion_life_timer(audio: AudioStreamPlayer2D) -> Timer:
var life_timer: Timer = Timer.new()

life_timer.wait_time = 3
life_timer.autostart = true
life_timer.connect("timeout", Global, "_clean_sounds_on_timeout", [audio])

return life_timer

# Insert the explosion particle and the explosion sound of the enemy.
# - [explosion_type: String] - The tyoe of the explosion to show in the scene.
func _instantiate_enemy_dead(explosion_type: String) -> void:
var explosion_particle: Particles2D = _get_explosion(explosion_type)
var explosion_sound: AudioStreamPlayer2D = _get_explosion_sound(explosion_type)
var timer: Timer = _create_explosion_life_timer(explosion_sound)

get_tree().get_root().call_deferred("add_child", explosion_particle, true)
explosion_particle.emitting = true

get_tree().get_root().call_deferred("add_child", explosion_sound, true)
explosion_sound.play(0)

explosion_sound.add_child(timer, true)


func _connect_player_killed_signal() -> void:
var _err = self.connect("player_killed", Global.world_node, "_on_player_killed")

Expand Down
12 changes: 8 additions & 4 deletions Scripts/game_controller_script.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ func _restart_game() -> void:
score_label_node.text = "SCORE: 0"

Global.dead_node.visible = false
enemies = get_tree().get_nodes_in_group("enemy")

for enemy in enemies:
enemy.queue_free()
_clean_scene_from_enemy()

self.add_child(player_node, true)

Expand All @@ -31,3 +28,10 @@ func _on_player_killed() -> void:
$EnemySpawner/SpawnTimer.stop()
Global.dead_node.visible = true


func _clean_scene_from_enemy() -> void:
enemies = get_tree().get_nodes_in_group("enemy")

for enemy in enemies:
enemy.queue_free()

45 changes: 31 additions & 14 deletions Scripts/player_script.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func _physics_process(_delta: float) -> void:
_player_movement()


# MOve the player
# Move the player
func _player_movement() -> void:
var motion: Vector2 = Vector2()

Expand Down Expand Up @@ -51,26 +51,29 @@ func _player_movement() -> void:

# Give the possibility to shoot a bullet
func _fire() -> void:
var bullet_instance: RigidBody2D = Bullet.instance()

# Creazione proiettile
bullet_instance.position = $Muzzle.get_global_position()
bullet_instance.rotation_degrees = self.rotation_degrees
bullet_instance.apply_impulse(Vector2(), Vector2(bullet_instance.bullet_speed, 0).rotated(self.rotation))

var bullet: RigidBody2D = _create_bullet()
var spark: Particles2D = _create_spark()
var audio: AudioStreamPlayer2D = _create_shoot_audio()
var life_timer: Timer = _create_spark_life_timer(audio, spark)

# Inserisco il proiettile nella scena
get_tree().get_root().call_deferred("add_child", bullet_instance, true)

# Inserisco le particelle nella scena
get_tree().get_root().call_deferred("add_child", bullet, true)
get_tree().get_root().call_deferred("add_child", spark, true)
spark.emitting = true

# Inserisco l'audio della particella dello sparo nella scena
get_tree().get_root().call_deferred("add_child", audio, true)
audio.play(0)
audio.add_child(life_timer, true)


# Return an instance of the player's bullet.
func _create_bullet() -> RigidBody2D:
var bullet_instance: RigidBody2D = Bullet.instance()

bullet_instance.position = $Muzzle.get_global_position()
bullet_instance.rotation_degrees = self.rotation_degrees
bullet_instance.apply_impulse(Vector2(), Vector2(bullet_instance.bullet_speed, 0).rotated(self.rotation))

return bullet_instance


func _create_spark() -> Particles2D:
Expand All @@ -89,10 +92,24 @@ func _create_shoot_audio():
shoot_audio.stream = load("res://assets/audio/sounds/player_shoot.wav")
shoot_audio.volume_db = GUN_VOLUME
shoot_audio.position = $Muzzle.get_global_position()
shoot_audio.name = "ShootAudio"

return shoot_audio


# Reloadin timeout
# Reloading timeout
func _on_Reload_timeout() -> void:
can_shoot = true


# Return a life timer, of 3 seconds, for the [spark] and for the [audio] of the gun.
# - [audio: AudioStreamPlayer2D] - The shoot audio.
# - [spark: Particles2D] - The visual effect of the shoot.
func _create_spark_life_timer(audio: AudioStreamPlayer2D, spark: Particles2D) -> Timer:
var life_timer: Timer = Timer.new()

life_timer.wait_time = 3
life_timer.autostart = true
life_timer.connect("timeout", Global, "_clean_particles_and_sounds_on_timeout", [audio, spark])

return life_timer
Binary file modified assets/audio/sounds/bomb.wav
Binary file not shown.
Binary file modified assets/audio/sounds/bomb_bot.wav
Binary file not shown.
Binary file modified assets/audio/sounds/dead_sound.wav
Binary file not shown.
6 changes: 3 additions & 3 deletions particles/ExplosionBot.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 0.4, 0.5 ),
"times": PoolRealArray( 0, 0.3, 0.5 ),
"transitions": PoolRealArray( 0.196, 0.196, 0.196 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ) ]
Expand Down Expand Up @@ -84,11 +84,11 @@ script = ExtResource( 2 )
[node name="BotBlast" type="Area2D" parent="."]

[node name="CollisionShape2D" type="CollisionShape2D" parent="BotBlast"]
scale = Vector2( 0.1, 0.1 )
shape = SubResource( 4 )

[node name="Sprite" type="Sprite" parent="."]
scale = Vector2( 0.1, 0.1 )
modulate = Color( 1, 1, 1, 0 )
scale = Vector2( 4, 4 )
texture = ExtResource( 1 )

[node name="AnimationPlayer" type="AnimationPlayer" parent="Sprite"]
Expand Down

0 comments on commit 73eb62b

Please sign in to comment.