Ajout score + score multiplier
This commit is contained in:
parent
58f3e7d4fb
commit
9d6c4eaa23
4 changed files with 48 additions and 9 deletions
|
@ -2,6 +2,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>
|
||||||
#ifndef BOOK_GAME_HPP
|
#ifndef BOOK_GAME_HPP
|
||||||
#define BOOK_GAME_HPP
|
#define BOOK_GAME_HPP
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ private:
|
||||||
void start();
|
void start();
|
||||||
void update(sf::Time elapsedTime);
|
void update(sf::Time elapsedTime);
|
||||||
void render();
|
void render();
|
||||||
|
void update_scores(bool good_action);
|
||||||
|
|
||||||
void updateStatistics(AudioEmitter &audioEmitter);
|
void updateStatistics(AudioEmitter &audioEmitter);
|
||||||
|
|
||||||
|
@ -38,6 +40,11 @@ private:
|
||||||
sf::RectangleShape rightPressZone;
|
sf::RectangleShape rightPressZone;
|
||||||
|
|
||||||
std::size_t mStatisticsNumFrames{0};
|
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
|
#endif // BOOK_GAME_HPP
|
||||||
|
|
|
@ -35,7 +35,8 @@ public:
|
||||||
// press
|
// press
|
||||||
static bool checkPress(float press_time, NotePlaceEnum key_pressed);
|
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 :
|
// Some getters usefull in test :
|
||||||
float getPlayTime() const { return play_time; };
|
float getPlayTime() const { return play_time; };
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <SFML/Graphics/RectangleShape.hpp>
|
#include <SFML/Graphics/RectangleShape.hpp>
|
||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
#include <SFML/Window/Keyboard.hpp>
|
#include <SFML/Window/Keyboard.hpp>
|
||||||
|
#include <format>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -33,6 +34,13 @@ Game::Game() {
|
||||||
leftPressZone.setFillColor(sf::Color::Black);
|
leftPressZone.setFillColor(sf::Color::Black);
|
||||||
middlePressZone.setFillColor(sf::Color::Black);
|
middlePressZone.setFillColor(sf::Color::Black);
|
||||||
rightPressZone.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) {
|
void generateTilePatternAndMusic(AudioEmitter &audio_emitter) {
|
||||||
|
@ -81,13 +89,16 @@ void Game::processEvents(AudioEmitter &audioEmitter) {
|
||||||
sf::Keyboard::Scancode key_scan_code = keyPressed->scancode;
|
sf::Keyboard::Scancode key_scan_code = keyPressed->scancode;
|
||||||
switch (key_scan_code) {
|
switch (key_scan_code) {
|
||||||
case sf::Keyboard::Scancode::Left:
|
case sf::Keyboard::Scancode::Left:
|
||||||
NoteTile::checkPress(audioEmitter.getTime(), NotePlaceEnum::Left);
|
update_scores(
|
||||||
|
NoteTile::checkPress(audioEmitter.getTime(), NotePlaceEnum::Left));
|
||||||
break;
|
break;
|
||||||
case sf::Keyboard::Scancode::Up:
|
case sf::Keyboard::Scancode::Up:
|
||||||
NoteTile::checkPress(audioEmitter.getTime(), NotePlaceEnum::Middle);
|
update_scores(NoteTile::checkPress(audioEmitter.getTime(),
|
||||||
|
NotePlaceEnum::Middle));
|
||||||
break;
|
break;
|
||||||
case sf::Keyboard::Scancode::Right:
|
case sf::Keyboard::Scancode::Right:
|
||||||
NoteTile::checkPress(audioEmitter.getTime(), NotePlaceEnum::Right);
|
update_scores(
|
||||||
|
NoteTile::checkPress(audioEmitter.getTime(), NotePlaceEnum::Right));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,8 +112,11 @@ void Game::render() {
|
||||||
mWindow.draw(leftPressZone);
|
mWindow.draw(leftPressZone);
|
||||||
mWindow.draw(middlePressZone);
|
mWindow.draw(middlePressZone);
|
||||||
mWindow.draw(rightPressZone);
|
mWindow.draw(rightPressZone);
|
||||||
NoteTile::update(1.0 / 60, mWindow);
|
if (!NoteTile::update(1.0 / 60, mWindow))
|
||||||
|
update_scores(false);
|
||||||
mWindow.draw(mStatisticsText);
|
mWindow.draw(mStatisticsText);
|
||||||
|
mWindow.draw(ScoreText);
|
||||||
|
mWindow.draw(ScoreMultiplierText);
|
||||||
mWindow.display();
|
mWindow.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,3 +128,17 @@ void Game::updateStatistics(AudioEmitter &audioEmitter) {
|
||||||
mStatisticsUpdateTime -= sf::seconds(1.0f);
|
mStatisticsUpdateTime -= sf::seconds(1.0f);
|
||||||
mStatisticsNumFrames = 0;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -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 &&
|
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->play_time + note_tile->good_interval / 2 > press_time &&
|
||||||
note_tile->place == key_pressed) {
|
note_tile->place == key_pressed) {
|
||||||
printf("good touch \n");
|
/*printf("good touch \n");*/
|
||||||
tiles.erase(it);
|
tiles.erase(it);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("badd touch \n");
|
/*printf("badd touch \n");*/
|
||||||
return false;
|
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;
|
auto &tiles = NoteTile::existing_tiles;
|
||||||
|
|
||||||
for (auto it = tiles.begin(); it != tiles.end();) {
|
for (auto it = tiles.begin(); it != tiles.end();) {
|
||||||
auto ¬e_tile = *it;
|
auto ¬e_tile = *it;
|
||||||
|
|
||||||
if (note_tile->note_sprite.sprite.getPosition().y > SCREEN_HEIGHT) {
|
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);
|
it = tiles.erase(it);
|
||||||
} else {
|
} else {
|
||||||
note_tile->note_sprite.update(dtime, window);
|
note_tile->note_sprite.update(dtime, window);
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return no_miss;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue