std::unique_ptr<State> current_state {nullptr};
std::unique_ptr<State> next_state {nullptr};
std::unique_ptr<Game_state> saved_game {nullptr};
- sf::Int32 time;
+ sf::Time time;
};
#endif
\ No newline at end of file
#include <memory>
#include <iostream>
+#include <iomanip>
#include "States.h"
#include "Context.h"
#include "constants.h"
-Game_state::Game_state() : game_map{}, player{}, pause_game{false}, bottles{}
+Game_state::Game_state() : game_map{}, player{}, pause_game{false}, bottles{}, time_since_last_bottle{0.0f}
{
Bottle* bottle = new Bottle {};
bottles.push_back(bottle);
pause_game = false;
return;
}
- time_since_last_bottle += context.time;
- //std::cout << time_since_last_bottle << std::endl;
+ time_since_last_bottle += context.time.asSeconds();
+ std::cout << std::fixed << std::setprecision(3) << time_since_last_bottle << std::endl;
if (time_since_last_bottle >= 2)
{
Bottle* bottle = new Bottle {};
void handle_input(sf::Event& event) override;
protected:
private:
- float time_since_last_bottle {0};
+ float time_since_last_bottle;
std::vector<Bottle*> bottles;
Map game_map;
Player player;
//innehåller all spelstatus
game_context.current_state->handle_input(event);
}
-
- //game_context.time = game_clock.getElapsedtime().asSeconds()
+
// Update startmeny
game_context.current_state->update(game_context);
// Make game run at constant fps
// std::cout << "frametime: " << game_clock.getElapsedTime().asSeconds() << std::endl;
sf::sleep(sf::milliseconds(1000.0 / FPS) - game_clock.getElapsedTime());
- game_clock.restart();
+ game_context.time = game_clock.restart();
}
}