diff --git a/AsepriteThings/bureau.aseprite b/AsepriteThings/bureau.aseprite index 6f20a38..23f474c 100644 Binary files a/AsepriteThings/bureau.aseprite and b/AsepriteThings/bureau.aseprite differ diff --git a/AsepriteThings/end_screen.aseprite b/AsepriteThings/end_screen.aseprite new file mode 100644 index 0000000..3c2abe8 Binary files /dev/null and b/AsepriteThings/end_screen.aseprite differ diff --git a/AsepriteThings/feuille.aseprite b/AsepriteThings/feuille.aseprite new file mode 100644 index 0000000..0858ec3 Binary files /dev/null and b/AsepriteThings/feuille.aseprite differ diff --git a/SimpleGame/media/sprites/bureau.png b/SimpleGame/media/sprites/bureau.png index a8c5788..5e868c4 100644 Binary files a/SimpleGame/media/sprites/bureau.png and b/SimpleGame/media/sprites/bureau.png differ diff --git a/SimpleGame/media/sprites/end_screen.png b/SimpleGame/media/sprites/end_screen.png new file mode 100644 index 0000000..a259dd1 Binary files /dev/null and b/SimpleGame/media/sprites/end_screen.png differ diff --git a/SimpleGame/media/sprites/feuille.png b/SimpleGame/media/sprites/feuille.png new file mode 100644 index 0000000..a95de42 Binary files /dev/null and b/SimpleGame/media/sprites/feuille.png differ diff --git a/SimpleGame/src/Include/AudioEmitter.hpp b/SimpleGame/src/Include/AudioEmitter.hpp index bcf036c..f38459d 100644 --- a/SimpleGame/src/Include/AudioEmitter.hpp +++ b/SimpleGame/src/Include/AudioEmitter.hpp @@ -8,16 +8,15 @@ class AudioEmitter { private: - FMOD::System* system{ nullptr }; - FMOD::Sound* metronome_Sound{ nullptr }; + FMOD::System *system{nullptr}; + FMOD::Sound *metronome_Sound{nullptr}; FMOD::Channel *timer{nullptr}; - std::vector chords; - std::vector drums; - std::vector notes; + std::vector chords; + std::vector drums; + std::vector notes; std::vector> markov_matrix_chords; std::vector> markov_matrix_melody; int nbr_melo_max{4}; - int nbr_melo_total{ 64 }; int current_beat{0}; std::vector> rythmes; int index_note; @@ -25,7 +24,8 @@ private: std::vector activeChannels; public: - int tempo{ 170 }; + int nbr_melo_total{48}; + int tempo{170}; AudioEmitter(); ~AudioEmitter(); std::vector> generateMusic(); diff --git a/SimpleGame/src/Include/Game.hpp b/SimpleGame/src/Include/Game.hpp index 251a561..a73748b 100644 --- a/SimpleGame/src/Include/Game.hpp +++ b/SimpleGame/src/Include/Game.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #ifndef BOOK_GAME_HPP #define BOOK_GAME_HPP @@ -48,6 +49,8 @@ private: int score_multiplier = 1; // number of good press without misses sf::Sprite backGround; + sf::Sprite paper; + sf::Sprite endScreen; Carrot carrot; }; diff --git a/SimpleGame/src/Include/GameData.hpp b/SimpleGame/src/Include/GameData.hpp index 4d9cb1e..b3d5989 100644 --- a/SimpleGame/src/Include/GameData.hpp +++ b/SimpleGame/src/Include/GameData.hpp @@ -13,6 +13,8 @@ static constexpr unsigned int NOTE_PLACE_X_POS[3] = { SCREEN_WIDTH * 6 / 10, SCREEN_WIDTH * 7 / 10, SCREEN_WIDTH * 8 / 10}; static constexpr unsigned int FLOWER_SIZE = SCREEN_WIDTH * 0.05; +static const sf::Vector2f PAPER_POS = + sf::Vector2f(SCREEN_WIDTH * 0.19, SCREEN_HEIGHT * 0.17); static const sf::Vector2f CARROT_POS = sf::Vector2f(SCREEN_WIDTH * 9 / 20, SCREEN_HEIGHT * 0.4); diff --git a/SimpleGame/src/Include/NoteTile.hpp b/SimpleGame/src/Include/NoteTile.hpp index d255e15..02dc961 100644 --- a/SimpleGame/src/Include/NoteTile.hpp +++ b/SimpleGame/src/Include/NoteTile.hpp @@ -46,4 +46,5 @@ public: static const std::vector> &getExistingTiles() { return existing_tiles; }; + static bool isFinished() { return existing_tiles.size() == 0; } }; diff --git a/SimpleGame/src/Source/Game.cpp b/SimpleGame/src/Source/Game.cpp index 2d19044..ba5e55f 100644 --- a/SimpleGame/src/Source/Game.cpp +++ b/SimpleGame/src/Source/Game.cpp @@ -5,6 +5,7 @@ #include "NoteTile.hpp" #include "TilePattern.hpp" #include +#include #include #include #include @@ -17,9 +18,12 @@ const sf::Time Game::TimePerFrame = sf::seconds(1.f / 60.f); sf::Texture bgTexture; +sf::Texture paperTexture; +sf::Texture endScreenTexture; Game::Game() - : backGround(PLACE_HOLDER_TEXTURE), + : backGround(PLACE_HOLDER_TEXTURE), paper(PLACE_HOLDER_TEXTURE), + endScreen(PLACE_HOLDER_TEXTURE), carrot(ANGRY_PATHS, NEUTRAL_PATHS, HAPPY_PATHS, mFont) { assert(mFont.openFromFile("media/Sansation.ttf")); mStatisticsText.setPosition({5.f, 5.f}); @@ -55,6 +59,23 @@ Game::Game() float sy = backGround.getTexture().getSize().y; backGround.setScale(sf::Vector2f(SCREEN_WIDTH / sx, SCREEN_HEIGHT / sy)); + if (!endScreenTexture.loadFromFile("media/sprites/end_screen.png")) { + printf("sprite end_screen not loaded\n"); + } + + endScreen.setTexture(endScreenTexture, true); + endScreen.setScale(sf::Vector2f(SCREEN_WIDTH / sx, SCREEN_HEIGHT / sy)); + + if (!paperTexture.loadFromFile("media/sprites/feuille.png")) { + printf("paper not loaded\n"); + } + paper.setPosition(PAPER_POS); + paper.setTexture(paperTexture, true); + paper.setScale(sf::Vector2f(SCREEN_WIDTH / sx, SCREEN_HEIGHT / sy)); + + paper.setTextureRect(sf::IntRect( + sf::Vector2i(0, 0), sf::Vector2i(paper.getTexture().getSize().x, 0))); + carrot.setPosition(CARROT_POS); carrot.setScale(sf::Vector2f(5, 5)); @@ -81,8 +102,13 @@ bool updateAudio(AudioEmitter &audioEmitter, bool generated) { return generated; } +int nb_melo_total; +float tempo; + void Game::run() { AudioEmitter audioEmitter = AudioEmitter(); + nb_melo_total = audioEmitter.nbr_melo_total; + tempo = audioEmitter.tempo; generateTilePatternAndMusic(audioEmitter); bool generated = false; @@ -123,11 +149,20 @@ void Game::processEvents(AudioEmitter &audioEmitter) { } } -void Game::update(const sf::Time elapsedTime) {} +float totalTime = 0.0f; +void Game::update(const sf::Time elapsedTime) { + float maxTime = nb_melo_total * 8 * 60 / tempo; + int paperAdvancement = paper.getTexture().getSize().y * totalTime / maxTime; + paper.setTextureRect(sf::IntRect( + sf::Vector2i(0, 0), + sf::Vector2i(paper.getTexture().getSize().x, paperAdvancement))); + totalTime += elapsedTime.asSeconds(); +} void Game::render() { mWindow.clear(sf::Color::Yellow); mWindow.draw(backGround); + mWindow.draw(paper); mWindow.draw(leftPressZone); mWindow.draw(middlePressZone); mWindow.draw(rightPressZone); @@ -137,6 +172,9 @@ void Game::render() { if (!NoteTile::update(TimePerFrame.asSeconds(), mWindow)) update_scores(false); + if (NoteTile::isFinished()) { + mWindow.draw(endScreen); + } mWindow.draw(mStatisticsText); mWindow.draw(ScoreText); mWindow.draw(ScoreMultiplierText);