diff --git a/godot/assets/sounds/victory.wav b/godot/assets/sounds/victory.wav new file mode 100644 index 0000000..4287414 --- /dev/null +++ b/godot/assets/sounds/victory.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a5c247f96d1a500806f31f8efd2d31a05c2422416afe3379b50b67cb04a7e810 +size 930948 diff --git a/godot/assets/sounds/victory.wav.import b/godot/assets/sounds/victory.wav.import new file mode 100644 index 0000000..557cd90 --- /dev/null +++ b/godot/assets/sounds/victory.wav.import @@ -0,0 +1,23 @@ +[remap] + +importer="wav" +type="AudioStreamSample" +path="res://.import/victory.wav-652e970b8418d2fc380cb882ddb39b3d.sample" + +[deps] + +source_file="res://assets/sounds/victory.wav" +dest_files=[ "res://.import/victory.wav-652e970b8418d2fc380cb882ddb39b3d.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/godot/gui/GameOver.tscn b/godot/gui/GameOver.tscn index 56c19a8..08d8f03 100644 --- a/godot/gui/GameOver.tscn +++ b/godot/gui/GameOver.tscn @@ -48,7 +48,7 @@ text = "REINICIAR" [node name="GameOverMusic" type="AudioStreamPlayer" parent="."] stream = ExtResource( 4 ) -volume_db = -23.524 +volume_db = -25.0 -[connection signal="visibility_changed" from="." to="." method="_play_music"] +[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"] [connection signal="pressed" from="Control/RestartButton" to="." method="_on_restart_button_pressed"] diff --git a/godot/gui/GameWon.tscn b/godot/gui/GameWon.tscn index 49889fc..f91c385 100644 --- a/godot/gui/GameWon.tscn +++ b/godot/gui/GameWon.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://assets/fonts/ttf/PixelOperator8.ttf" type="DynamicFontData" id=1] [ext_resource path="res://assets/fonts/ttf/PixelOperatorHB8.ttf" type="DynamicFontData" id=2] [ext_resource path="res://gui/GameWonScreen.gdns" type="Script" id=3] +[ext_resource path="res://assets/sounds/victory.wav" type="AudioStream" id=4] [sub_resource type="DynamicFont" id=1] size = 50 @@ -45,4 +46,9 @@ custom_fonts/font = SubResource( 2 ) custom_styles/hover = SubResource( 3 ) text = "SALIR" +[node name="VictorySound" type="AudioStreamPlayer" parent="."] +stream = ExtResource( 4 ) +volume_db = -18.0 + +[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"] [connection signal="pressed" from="Control/QuitButton" to="." method="_on_quit_button_pressed"] diff --git a/src/coin/CoinCounter.cpp b/src/coin/CoinCounter.cpp index da39b39..e29280b 100644 --- a/src/coin/CoinCounter.cpp +++ b/src/coin/CoinCounter.cpp @@ -30,10 +30,14 @@ void alai::CoinCounter::_ready() event->connect("coin_collected", this, "_on_coin_collected"); } - void alai::CoinCounter::_on_coin_collected(int amount) { coins = coins + amount; + if (coins >= 100) + { + auto extra = coins - 100; + coins = extra; + } godot::String coin_string = godot::String(); if (coins <= 9) { diff --git a/src/coin/CoinCounter.h b/src/coin/CoinCounter.h index 8702887..e04f5fa 100644 --- a/src/coin/CoinCounter.h +++ b/src/coin/CoinCounter.h @@ -15,7 +15,7 @@ namespace alai GODOT_CLASS(CoinCounter, godot::Label) private: - int coins; + uint8_t coins; public: /** diff --git a/src/gui/game_over/GameOverScreen.cpp b/src/gui/game_over/GameOverScreen.cpp index 622a032..9dcdf47 100644 --- a/src/gui/game_over/GameOverScreen.cpp +++ b/src/gui/game_over/GameOverScreen.cpp @@ -16,7 +16,7 @@ void alai::GameOverScreen::_register_methods() godot::register_method("restart_game", &GameOverScreen::restart_game); godot::register_method("connect_signal", &GameOverScreen::connect_signal); godot::register_method("_on_player_died", &GameOverScreen::_on_player_died); - godot::register_method("_play_music", &GameOverScreen::_play_music); + godot::register_method("_on_visibility_changed", &GameOverScreen::_on_visibility_changed); } alai::GameOverScreen::GameOverScreen() @@ -96,6 +96,15 @@ void alai::GameOverScreen::connect_signal() event->connect("player_died", this, "_on_player_died"); } -void alai::GameOverScreen::_play_music() +void alai::GameOverScreen::_on_visibility_changed() { + auto gameoversound = get_node("GameOverMusic"); + if (is_visible()) + { + gameoversound->play(); + } + else + { + gameoversound->stop(); + } } diff --git a/src/gui/game_over/GameOverScreen.h b/src/gui/game_over/GameOverScreen.h index 3fb679c..0dc7226 100644 --- a/src/gui/game_over/GameOverScreen.h +++ b/src/gui/game_over/GameOverScreen.h @@ -55,7 +55,7 @@ namespace alai void _on_restart_button_pressed(); void restart_game(); void connect_signal(); - void _play_music(); + void _on_visibility_changed(); }; } diff --git a/src/gui/game_won/GameWonScreen.cpp b/src/gui/game_won/GameWonScreen.cpp index f51822e..81ddc6d 100644 --- a/src/gui/game_won/GameWonScreen.cpp +++ b/src/gui/game_won/GameWonScreen.cpp @@ -2,6 +2,7 @@ #include "Event.h" +#include #include #include @@ -11,6 +12,7 @@ void alai::GameWonScreen::_register_methods() godot::register_method("connect_signal", &GameWonScreen::connect_signal); godot::register_method("_on_player_won", &GameWonScreen::_on_player_won); godot::register_method("_on_quit_button_pressed", &GameWonScreen::_on_quit_button_pressed); + godot::register_method("_on_visibility_changed", &GameWonScreen::_on_visibility_changed); } alai::GameWonScreen::GameWonScreen() @@ -64,3 +66,16 @@ void alai::GameWonScreen::connect_signal() auto event = get_node("/root/Event"); event->connect("player_won", this, "_on_player_won"); } + +void alai::GameWonScreen::_on_visibility_changed() +{ + auto victorysound = get_node("VictorySound"); + if (is_visible()) + { + victorysound->play(); + } + else + { + victorysound->stop(); + } +} diff --git a/src/gui/game_won/GameWonScreen.h b/src/gui/game_won/GameWonScreen.h index 987b7a1..683e554 100644 --- a/src/gui/game_won/GameWonScreen.h +++ b/src/gui/game_won/GameWonScreen.h @@ -45,6 +45,7 @@ namespace alai void _on_player_won(); void _on_quit_button_pressed(); void connect_signal(); + void _on_visibility_changed(); }; }