diff --git a/.import/bomb.wav-53d9c289295285d77cf5bcdcba7a043c.md5 b/.import/bomb.wav-53d9c289295285d77cf5bcdcba7a043c.md5 index e27e301..6a7f505 100644 --- a/.import/bomb.wav-53d9c289295285d77cf5bcdcba7a043c.md5 +++ b/.import/bomb.wav-53d9c289295285d77cf5bcdcba7a043c.md5 @@ -1,3 +1,3 @@ -source_md5="01355e4fde2397c03ba622cb409c12d8" -dest_md5="e0e6f6d8502dd2e93253d55dcedb625a" +source_md5="e5e0ba410c685e1a428aec9a6bc1534f" +dest_md5="7a2226bd964804ad214cb45888aa8282" diff --git a/.import/bomb.wav-53d9c289295285d77cf5bcdcba7a043c.sample b/.import/bomb.wav-53d9c289295285d77cf5bcdcba7a043c.sample index 14fb402..046a385 100644 Binary files a/.import/bomb.wav-53d9c289295285d77cf5bcdcba7a043c.sample and b/.import/bomb.wav-53d9c289295285d77cf5bcdcba7a043c.sample differ diff --git a/.import/bomb_bot.wav-02f9e5de3b653a3bad693fdbd08338b2.md5 b/.import/bomb_bot.wav-02f9e5de3b653a3bad693fdbd08338b2.md5 index 8af49cc..d8107ef 100644 --- a/.import/bomb_bot.wav-02f9e5de3b653a3bad693fdbd08338b2.md5 +++ b/.import/bomb_bot.wav-02f9e5de3b653a3bad693fdbd08338b2.md5 @@ -1,3 +1,3 @@ -source_md5="21404afc75a8064a8b82295c3fefa66a" -dest_md5="4298b9502d932721dbba62dcc82c1f5e" +source_md5="7a707f7929ea23c9ec373ae0bcc21f14" +dest_md5="906c2b35e4a88445fae310d79692a4e0" diff --git a/.import/bomb_bot.wav-02f9e5de3b653a3bad693fdbd08338b2.sample b/.import/bomb_bot.wav-02f9e5de3b653a3bad693fdbd08338b2.sample index 734323c..4f047ff 100644 Binary files a/.import/bomb_bot.wav-02f9e5de3b653a3bad693fdbd08338b2.sample and b/.import/bomb_bot.wav-02f9e5de3b653a3bad693fdbd08338b2.sample differ diff --git a/.import/dead_sound.wav-3092a271da9579641bec8e252931a4ad.md5 b/.import/dead_sound.wav-3092a271da9579641bec8e252931a4ad.md5 index 03cb560..c50ea9d 100644 --- a/.import/dead_sound.wav-3092a271da9579641bec8e252931a4ad.md5 +++ b/.import/dead_sound.wav-3092a271da9579641bec8e252931a4ad.md5 @@ -1,3 +1,3 @@ -source_md5="5cfe8e28413a39e375c15d233db38017" -dest_md5="462175630cd44d81a578da111d874987" +source_md5="19953d3fa1d3505f426ac26005beadd4" +dest_md5="89c4ee19be5c0996b1805196ba5b19f1" diff --git a/.import/dead_sound.wav-3092a271da9579641bec8e252931a4ad.sample b/.import/dead_sound.wav-3092a271da9579641bec8e252931a4ad.sample index 46ccc2d..4b55340 100644 Binary files a/.import/dead_sound.wav-3092a271da9579641bec8e252931a4ad.sample and b/.import/dead_sound.wav-3092a271da9579641bec8e252931a4ad.sample differ diff --git a/Global.gd b/Global.gd index 87e3218..13873b3 100644 --- a/Global.gd +++ b/Global.gd @@ -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 @@ -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 } } @@ -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() diff --git a/Scenes/GUI/GameOver.tscn b/Scenes/GUI/GameOver.tscn index f17f66f..d8d1303 100644 --- a/Scenes/GUI/GameOver.tscn +++ b/Scenes/GUI/GameOver.tscn @@ -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 diff --git a/Scenes/Online/Server.tscn b/Scenes/Online/Server.tscn deleted file mode 100644 index 3613ac8..0000000 --- a/Scenes/Online/Server.tscn +++ /dev/null @@ -1,10 +0,0 @@ -[gd_scene load_steps=2 format=2] - -[ext_resource path="res://Scripts/server_script.gd" type="Script" id=1] - -[node name="Server" type="Node"] -script = ExtResource( 1 ) - -[node name="HTTPRequest" type="HTTPRequest" parent="."] - -[connection signal="request_completed" from="HTTPRequest" to="." method="_on_HTTPRequest_request_completed"] diff --git a/Scenes/Player.tscn b/Scenes/Player.tscn index 410b26d..12257df 100644 --- a/Scenes/Player.tscn +++ b/Scenes/Player.tscn @@ -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 ) diff --git a/Scripts/enemy_script.gd b/Scripts/enemy_script.gd index 51110b9..03a693d 100644 --- a/Scripts/enemy_script.gd +++ b/Scripts/enemy_script.gd @@ -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 @@ -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() @@ -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() @@ -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: @@ -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) @@ -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") diff --git a/Scripts/game_controller_script.gd b/Scripts/game_controller_script.gd index 5283aa6..9cb0465 100644 --- a/Scripts/game_controller_script.gd +++ b/Scripts/game_controller_script.gd @@ -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) @@ -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() + diff --git a/Scripts/player_script.gd b/Scripts/player_script.gd index 3d7c439..ae52c91 100644 --- a/Scripts/player_script.gd +++ b/Scripts/player_script.gd @@ -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() @@ -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: @@ -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 diff --git a/assets/audio/sounds/bomb.wav b/assets/audio/sounds/bomb.wav index 6734681..a209d06 100644 Binary files a/assets/audio/sounds/bomb.wav and b/assets/audio/sounds/bomb.wav differ diff --git a/assets/audio/sounds/bomb_bot.wav b/assets/audio/sounds/bomb_bot.wav index 933671e..6aa9a31 100644 Binary files a/assets/audio/sounds/bomb_bot.wav and b/assets/audio/sounds/bomb_bot.wav differ diff --git a/assets/audio/sounds/dead_sound.wav b/assets/audio/sounds/dead_sound.wav index e2401f3..51c22cc 100644 Binary files a/assets/audio/sounds/dead_sound.wav and b/assets/audio/sounds/dead_sound.wav differ diff --git a/particles/ExplosionBot.tscn b/particles/ExplosionBot.tscn index f7abf0d..ede54ae 100644 --- a/particles/ExplosionBot.tscn +++ b/particles/ExplosionBot.tscn @@ -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 ) ] @@ -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"]