Ecran fin + feuille

This commit is contained in:
Crizomb 2025-06-17 18:47:07 +02:00
parent 5a1423d8db
commit 33bda6381d
11 changed files with 53 additions and 9 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 828 B

After

Width:  |  Height:  |  Size: 813 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -17,7 +17,6 @@ private:
std::vector<std::vector<float>> markov_matrix_chords; std::vector<std::vector<float>> markov_matrix_chords;
std::vector<std::vector<float>> markov_matrix_melody; std::vector<std::vector<float>> markov_matrix_melody;
int nbr_melo_max{4}; int nbr_melo_max{4};
int nbr_melo_total{ 64 };
int current_beat{0}; int current_beat{0};
std::vector<std::vector<float>> rythmes; std::vector<std::vector<float>> rythmes;
int index_note; int index_note;
@ -25,6 +24,7 @@ private:
std::vector<FMOD::Channel *> activeChannels; std::vector<FMOD::Channel *> activeChannels;
public: public:
int nbr_melo_total{48};
int tempo{170}; int tempo{170};
AudioEmitter(); AudioEmitter();
~AudioEmitter(); ~AudioEmitter();

View file

@ -3,6 +3,7 @@
#include <SFML/Graphics/RectangleShape.hpp> #include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Graphics/Sprite.hpp> #include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/Text.hpp> #include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/Texture.hpp>
#ifndef BOOK_GAME_HPP #ifndef BOOK_GAME_HPP
#define BOOK_GAME_HPP #define BOOK_GAME_HPP
@ -48,6 +49,8 @@ private:
int score_multiplier = 1; // number of good press without misses int score_multiplier = 1; // number of good press without misses
sf::Sprite backGround; sf::Sprite backGround;
sf::Sprite paper;
sf::Sprite endScreen;
Carrot carrot; Carrot carrot;
}; };

View file

@ -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}; SCREEN_WIDTH * 6 / 10, SCREEN_WIDTH * 7 / 10, SCREEN_WIDTH * 8 / 10};
static constexpr unsigned int FLOWER_SIZE = SCREEN_WIDTH * 0.05; 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 = static const sf::Vector2f CARROT_POS =
sf::Vector2f(SCREEN_WIDTH * 9 / 20, SCREEN_HEIGHT * 0.4); sf::Vector2f(SCREEN_WIDTH * 9 / 20, SCREEN_HEIGHT * 0.4);

View file

@ -46,4 +46,5 @@ public:
static const std::vector<std::unique_ptr<NoteTile>> &getExistingTiles() { static const std::vector<std::unique_ptr<NoteTile>> &getExistingTiles() {
return existing_tiles; return existing_tiles;
}; };
static bool isFinished() { return existing_tiles.size() == 0; }
}; };

View file

@ -5,6 +5,7 @@
#include "NoteTile.hpp" #include "NoteTile.hpp"
#include "TilePattern.hpp" #include "TilePattern.hpp"
#include <SFML/Graphics/Color.hpp> #include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/RectangleShape.hpp> #include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Graphics/Sprite.hpp> #include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/Texture.hpp> #include <SFML/Graphics/Texture.hpp>
@ -17,9 +18,12 @@
const sf::Time Game::TimePerFrame = sf::seconds(1.f / 60.f); const sf::Time Game::TimePerFrame = sf::seconds(1.f / 60.f);
sf::Texture bgTexture; sf::Texture bgTexture;
sf::Texture paperTexture;
sf::Texture endScreenTexture;
Game::Game() 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) { carrot(ANGRY_PATHS, NEUTRAL_PATHS, HAPPY_PATHS, mFont) {
assert(mFont.openFromFile("media/Sansation.ttf")); assert(mFont.openFromFile("media/Sansation.ttf"));
mStatisticsText.setPosition({5.f, 5.f}); mStatisticsText.setPosition({5.f, 5.f});
@ -55,6 +59,23 @@ Game::Game()
float sy = backGround.getTexture().getSize().y; float sy = backGround.getTexture().getSize().y;
backGround.setScale(sf::Vector2f(SCREEN_WIDTH / sx, SCREEN_HEIGHT / sy)); 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.setPosition(CARROT_POS);
carrot.setScale(sf::Vector2f(5, 5)); carrot.setScale(sf::Vector2f(5, 5));
@ -81,8 +102,13 @@ bool updateAudio(AudioEmitter &audioEmitter, bool generated) {
return generated; return generated;
} }
int nb_melo_total;
float tempo;
void Game::run() { void Game::run() {
AudioEmitter audioEmitter = AudioEmitter(); AudioEmitter audioEmitter = AudioEmitter();
nb_melo_total = audioEmitter.nbr_melo_total;
tempo = audioEmitter.tempo;
generateTilePatternAndMusic(audioEmitter); generateTilePatternAndMusic(audioEmitter);
bool generated = false; 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() { void Game::render() {
mWindow.clear(sf::Color::Yellow); mWindow.clear(sf::Color::Yellow);
mWindow.draw(backGround); mWindow.draw(backGround);
mWindow.draw(paper);
mWindow.draw(leftPressZone); mWindow.draw(leftPressZone);
mWindow.draw(middlePressZone); mWindow.draw(middlePressZone);
mWindow.draw(rightPressZone); mWindow.draw(rightPressZone);
@ -137,6 +172,9 @@ void Game::render() {
if (!NoteTile::update(TimePerFrame.asSeconds(), mWindow)) if (!NoteTile::update(TimePerFrame.asSeconds(), mWindow))
update_scores(false); update_scores(false);
if (NoteTile::isFinished()) {
mWindow.draw(endScreen);
}
mWindow.draw(mStatisticsText); mWindow.draw(mStatisticsText);
mWindow.draw(ScoreText); mWindow.draw(ScoreText);
mWindow.draw(ScoreMultiplierText); mWindow.draw(ScoreMultiplierText);