Correction d'un bug d'initialisation du temps

This commit is contained in:
Mattéo Delabre 2016-04-11 21:20:05 +02:00
parent 0c8f5d2e3e
commit 41547c1e92
4 changed files with 8 additions and 5 deletions

View File

@ -25,8 +25,6 @@ private:
sf::Time next_frame_time; sf::Time next_frame_time;
std::vector<Object::Ptr> pending_kill; std::vector<Object::Ptr> pending_kill;
float time_left;
std::shared_ptr<Editor> return_state; std::shared_ptr<Editor> return_state;
Mode mode; Mode mode;
DeathCause death_cause; DeathCause death_cause;

View File

@ -25,6 +25,7 @@ private:
sf::String name; sf::String name;
std::string current_path; std::string current_path;
int total_time; int total_time;
sf::Sprite background_sprite; sf::Sprite background_sprite;
@ -36,6 +37,8 @@ private:
std::vector<sf::Vector2f> zone; std::vector<sf::Vector2f> zone;
protected: protected:
float time_left;
/** /**
* Dessine tous les objets et le fond à l'écran * Dessine tous les objets et le fond à l'écran
*/ */

View File

@ -17,7 +17,6 @@ Game::Game(Manager& manager) : Level(manager),
mode = Game::Mode::NORMAL; mode = Game::Mode::NORMAL;
death_cause = Game::DeathCause::NONE; death_cause = Game::DeathCause::NONE;
time_left = getTotalTime();
getWindow().setFramerateLimit(0); getWindow().setFramerateLimit(0);
} }
@ -118,7 +117,7 @@ void Game::draw() {
// dessin du timer // dessin du timer
widget_timer.setTimeLeft( widget_timer.setTimeLeft(
std::max(std::floor(time_left), 0.f) std::max(std::ceil(time_left), 0.f)
); );
widget_timer.draw(sf::Vector2f(window_size.x / 2 - 50, 0)); widget_timer.draw(sf::Vector2f(window_size.x / 2 - 50, 0));

View File

@ -170,7 +170,7 @@ sf::String Level::getLevelName(std::string path) {
void Level::load() { void Level::load() {
// métadonnées par défaut // métadonnées par défaut
name = sf::String("Nouveau niveau"); name = sf::String("Nouveau niveau");
total_time = 30; time_left = total_time = 30;
// zone de jeu par défaut // zone de jeu par défaut
zone.clear(); zone.clear();
@ -200,6 +200,8 @@ void Level::load(std::string path) {
zone, background, music, zone, background, music,
std::bind(&Level::addObject, this, std::placeholders::_1) std::bind(&Level::addObject, this, std::placeholders::_1)
); );
time_left = total_time;
current_path = path; current_path = path;
} }
@ -335,6 +337,7 @@ void Level::setTotalTime(int set_total_time) {
set_total_time = std::max(set_total_time, 10); set_total_time = std::max(set_total_time, 10);
total_time = set_total_time; total_time = set_total_time;
time_left = total_time;
} }
std::string Level::getMusic() const { std::string Level::getMusic() const {