From 9d6c4eaa238b9febd660aefd5fe0b03b3f43f6fb Mon Sep 17 00:00:00 2001 From: Crizomb Date: Sat, 14 Jun 2025 21:02:46 +0200 Subject: [PATCH 1/2] Ajout score + score multiplier --- SimpleGame/src/Include/Game.hpp | 7 ++++++ SimpleGame/src/Include/NoteTile.hpp | 3 ++- SimpleGame/src/Source/Game.cpp | 36 +++++++++++++++++++++++++---- SimpleGame/src/Source/NoteTile.cpp | 11 +++++---- 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/SimpleGame/src/Include/Game.hpp b/SimpleGame/src/Include/Game.hpp index 7faedba..ab3ca4c 100644 --- a/SimpleGame/src/Include/Game.hpp +++ b/SimpleGame/src/Include/Game.hpp @@ -2,6 +2,7 @@ #include #include +#include #ifndef BOOK_GAME_HPP #define BOOK_GAME_HPP @@ -21,6 +22,7 @@ private: void start(); void update(sf::Time elapsedTime); void render(); + void update_scores(bool good_action); void updateStatistics(AudioEmitter &audioEmitter); @@ -38,6 +40,11 @@ private: sf::RectangleShape rightPressZone; std::size_t mStatisticsNumFrames{0}; + + sf::Text ScoreText{mFont}; + sf::Text ScoreMultiplierText{mFont}; + int score = 0; + int score_multiplier = 1; // number of good press without misses }; #endif // BOOK_GAME_HPP diff --git a/SimpleGame/src/Include/NoteTile.hpp b/SimpleGame/src/Include/NoteTile.hpp index b2c5c65..d255e15 100644 --- a/SimpleGame/src/Include/NoteTile.hpp +++ b/SimpleGame/src/Include/NoteTile.hpp @@ -35,7 +35,8 @@ public: // press static bool checkPress(float press_time, NotePlaceEnum key_pressed); - static void update(float dtime, sf::RenderWindow &window); + // return false if missed tile + static bool update(float dtime, sf::RenderWindow &window); // Some getters usefull in test : float getPlayTime() const { return play_time; }; diff --git a/SimpleGame/src/Source/Game.cpp b/SimpleGame/src/Source/Game.cpp index 720a85a..1de082d 100644 --- a/SimpleGame/src/Source/Game.cpp +++ b/SimpleGame/src/Source/Game.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -33,6 +34,13 @@ Game::Game() { leftPressZone.setFillColor(sf::Color::Black); middlePressZone.setFillColor(sf::Color::Black); rightPressZone.setFillColor(sf::Color::Black); + + ScoreText.setPosition({SCREEN_WIDTH - 200, 5}); + ScoreText.setFillColor(sf::Color::Black); + ScoreText.setCharacterSize(20); + ScoreMultiplierText.setPosition({SCREEN_WIDTH - 200, 25}); + ScoreMultiplierText.setFillColor(sf::Color::Black); + ScoreMultiplierText.setCharacterSize(20); } void generateTilePatternAndMusic(AudioEmitter &audio_emitter) { @@ -81,13 +89,16 @@ void Game::processEvents(AudioEmitter &audioEmitter) { sf::Keyboard::Scancode key_scan_code = keyPressed->scancode; switch (key_scan_code) { case sf::Keyboard::Scancode::Left: - NoteTile::checkPress(audioEmitter.getTime(), NotePlaceEnum::Left); + update_scores( + NoteTile::checkPress(audioEmitter.getTime(), NotePlaceEnum::Left)); break; case sf::Keyboard::Scancode::Up: - NoteTile::checkPress(audioEmitter.getTime(), NotePlaceEnum::Middle); + update_scores(NoteTile::checkPress(audioEmitter.getTime(), + NotePlaceEnum::Middle)); break; case sf::Keyboard::Scancode::Right: - NoteTile::checkPress(audioEmitter.getTime(), NotePlaceEnum::Right); + update_scores( + NoteTile::checkPress(audioEmitter.getTime(), NotePlaceEnum::Right)); break; } } @@ -101,8 +112,11 @@ void Game::render() { mWindow.draw(leftPressZone); mWindow.draw(middlePressZone); mWindow.draw(rightPressZone); - NoteTile::update(1.0 / 60, mWindow); + if (!NoteTile::update(1.0 / 60, mWindow)) + update_scores(false); mWindow.draw(mStatisticsText); + mWindow.draw(ScoreText); + mWindow.draw(ScoreMultiplierText); mWindow.display(); } @@ -114,3 +128,17 @@ void Game::updateStatistics(AudioEmitter &audioEmitter) { mStatisticsUpdateTime -= sf::seconds(1.0f); mStatisticsNumFrames = 0; } + +void Game::update_scores(bool good_action) { + if (good_action) { + score += score_multiplier; + score_multiplier++; + } else { + score_multiplier = 1; + } + ScoreText.setString(std::format("Score = {}", score)); + ScoreMultiplierText.setString( + std::format("ScoreMultiplier = {}", score_multiplier)); + printf("good action : %d\n score %d\n score_multiplier %d\n ", good_action, + score, score_multiplier); +} diff --git a/SimpleGame/src/Source/NoteTile.cpp b/SimpleGame/src/Source/NoteTile.cpp index 312a66c..9864737 100644 --- a/SimpleGame/src/Source/NoteTile.cpp +++ b/SimpleGame/src/Source/NoteTile.cpp @@ -33,27 +33,30 @@ bool NoteTile::checkPress(float press_time, NotePlaceEnum key_pressed) { if (note_tile->play_time - note_tile->good_interval / 2 < press_time && note_tile->play_time + note_tile->good_interval / 2 > press_time && note_tile->place == key_pressed) { - printf("good touch \n"); + /*printf("good touch \n");*/ tiles.erase(it); return true; } } - printf("badd touch \n"); + /*printf("badd touch \n");*/ return false; } -void NoteTile::update(float dtime, sf::RenderWindow &window) { +bool NoteTile::update(float dtime, sf::RenderWindow &window) { + bool no_miss = true; auto &tiles = NoteTile::existing_tiles; for (auto it = tiles.begin(); it != tiles.end();) { auto ¬e_tile = *it; if (note_tile->note_sprite.sprite.getPosition().y > SCREEN_HEIGHT) { - printf("missed tile \n"); + /*printf("missed tile \n");*/ + no_miss = false; it = tiles.erase(it); } else { note_tile->note_sprite.update(dtime, window); ++it; } } + return no_miss; } From 785453b009a8a8e0f5aa8fdd36df7abdc11622fa Mon Sep 17 00:00:00 2001 From: Crizomb Date: Sat, 14 Jun 2025 21:04:38 +0200 Subject: [PATCH 2/2] On a un prototype, oui MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sans menu, les menus c'est pas fou fou et sur-coté --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a4c6763..96cd93f 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Notre raisonnnement : Vraiment un sujet de philo, c'est une question, on peut en ## TODO - [X] Génération de musique procédurale -- [ ] Prototype sans graphismes, sans Difficulté adaptative +- [X] Prototype sans graphismes, sans Difficulté adaptative - [ ] Beau graphismes de base (background, tiles...) - [ ] Difficulté adaptative - [ ] Ajout juice