danmaku/game.cpp

58 lines
1008 B
C++

#include "game.h"
Game::Game(sf::RenderWindow &window, Application *application) :
State(window, application),
world(render_window)
{}
Game::~Game()
{}
bool Game::processInput()
{
std::queue<Command>& queue = world.getCommandQueue();
sf::Event event;
while (render_window.pollEvent(event))
{
player.handleEvent(event, queue);
switch (event.type)
{
case sf::Event::GainedFocus:
b_pause = false;
break;
case sf::Event::LostFocus:
b_pause = true;
break;
case sf::Event::Closed:
render_window.close();
break;
default:
break;
}
}
player.handleRealtimeInput(queue);
return true;
}
bool Game::update(const sf::Time &dt)
{
world.update(dt);
return true;
}
void Game::draw()
{
render_window.clear();
world.draw();
render_window.setView(render_window.getDefaultView());
render_window.display();
}