coin and bgm added, game over music still not done

This commit is contained in:
2022-09-01 15:55:02 -04:00
parent e5d92c8267
commit 7236428157
9 changed files with 69 additions and 5 deletions

View File

@@ -2,6 +2,7 @@
#include "Event.h"
#include <AudioStreamPlayer.hpp>
#include <AnimationPlayer.hpp>
void alai::CoinCollected::_register_methods()
@@ -32,7 +33,8 @@ void alai::CoinCollected::_state_enter()
auto animation_player = Object::cast_to<godot::AnimationPlayer>(node);
animation_player->play("jump");
}
auto coin_collected_sound = get_parent()->get_node<godot::AudioStreamPlayer>("CoinCollectedSound");
coin_collected_sound->play();
}
void alai::CoinCollected::_state_exit()

View File

@@ -7,6 +7,8 @@
#include <Resource.hpp>
#include <SceneTree.hpp>
#include <Viewport.hpp>
#include <AudioStreamPlayer.hpp>
#include <VisibilityNotifier.hpp>
void alai::GameOverScreen::_register_methods()
{
@@ -14,6 +16,7 @@ void alai::GameOverScreen::_register_methods()
register_method("_ready", &GameOverScreen::_ready);
register_method("connect_signal", &GameOverScreen::connect_signal);
register_method("_on_player_died", &GameOverScreen::_on_player_died);
register_method("_play music", &GameOverScreen::_play_music);
}
alai::GameOverScreen::GameOverScreen()
@@ -29,9 +32,11 @@ void alai::GameOverScreen::_init()
_resource_loader = godot::ResourceLoader::get_singleton();
}
void alai::GameOverScreen::_ready()
{
connect_signal();
}
void alai::GameOverScreen::_on_restart_button_pressed()
@@ -85,3 +90,20 @@ void alai::GameOverScreen::connect_signal()
auto event = get_node<alai::Event>("/root/Event");
event->connect("player_died", this, "_on_player_died");
}
void alai::GameOverScreen::_play_music()
{
if (this->is_on_screen() == true)
{
auto game_over_sound = get_node<godot::AudioStreamPlayer>("GameOverMusic");
game_over_sound->play();
}
else
{
auto game_over_sound = get_node<godot::AudioStreamPlayer>("GameOverMusic");
game_over_sound->stop();
}
}

View File

@@ -5,6 +5,7 @@
#include <Godot.hpp>
#include <ResourceLoader.hpp>
namespace alai
{
/**
@@ -53,6 +54,7 @@ namespace alai
void _on_player_died();
void _on_restart_button_pressed();
void connect_signal();
void _play_music();
};
}