first commit
This commit is contained in:
commit
6f2408393c
30 changed files with 7856 additions and 0 deletions
35
src/game/game.cpp
Normal file
35
src/game/game.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include "game.h"
|
||||
|
||||
GameEvent game(Window &window)
|
||||
{
|
||||
Event event;
|
||||
|
||||
while(true)
|
||||
{
|
||||
if (event == Quit) window.quit();
|
||||
|
||||
window.clear();
|
||||
window.update();
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
bool Event::operator==(GameEvent event)
|
||||
{
|
||||
SDL_PollEvent(&(this->event));
|
||||
|
||||
GameEvent e = None;
|
||||
|
||||
switch((this->event).type)
|
||||
{
|
||||
case SDL_QUIT: e = Quit; break;
|
||||
case SDLK_w: e = Up; break;
|
||||
case SDLK_a: e = Left; break;
|
||||
case SDLK_s: e = Down; break;
|
||||
case SDLK_d: e = Right; break;
|
||||
default: e = None;
|
||||
}
|
||||
|
||||
return e == event;
|
||||
}
|
19
src/game/game.h
Normal file
19
src/game/game.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef GAME
|
||||
#define GAME
|
||||
|
||||
#include "../window/window.h"
|
||||
|
||||
enum GameEvent { None, Quit, Up, Left, Down, Right };
|
||||
|
||||
GameEvent game(Window &window);
|
||||
|
||||
class Event
|
||||
{
|
||||
public:
|
||||
bool operator==(GameEvent event);
|
||||
|
||||
private:
|
||||
SDL_Event event;
|
||||
};
|
||||
|
||||
#endif //GAME
|
Loading…
Add table
Add a link
Reference in a new issue