Merge branch 'master' of https://github.com/Crizomb/RythmGame
This commit is contained in:
commit
c010e61522
5 changed files with 49 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <SFML/Graphics/RectangleShape.hpp>
|
||||
#include <SFML/Graphics/Sprite.hpp>
|
||||
#include <SFML/Graphics/Text.hpp>
|
||||
#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
|
||||
|
|
|
@ -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; };
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <SFML/Graphics/RectangleShape.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/Window/Keyboard.hpp>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
#include <string>
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue