Browse Source

Implement a quit() mechanism in the Game class.

legacy
Sam Hocevar sam 14 years ago
parent
commit
effd8f768a
3 changed files with 17 additions and 3 deletions
  1. +12
    -0
      src/game.cpp
  2. +2
    -0
      src/game.h
  3. +3
    -3
      src/test-map.cpp

+ 12
- 0
src/game.cpp View File

@@ -26,6 +26,7 @@ private:
Font *font; Font *font;
int x, y; int x, y;
int mousex, mousey; int mousex, mousey;
int done;


int frame; int frame;
}; };
@@ -40,6 +41,7 @@ Game::Game(char const *mapname)
data->map = new Map(mapname); data->map = new Map(mapname);
data->font = new Font("gfx/font/ascii.png"); data->font = new Font("gfx/font/ascii.png");
data->x = data->y = 0; data->x = data->y = 0;
data->done = 0;
data->frame = 0; data->frame = 0;
} }


@@ -70,3 +72,13 @@ void Game::Render()
data->font->Print(10, 10, buf); data->font->Print(10, 10, buf);
} }


void Game::Quit()
{
data->done = 1;
}

int Game::Finished()
{
return data->done;
}


+ 2
- 0
src/game.h View File

@@ -21,6 +21,8 @@ public:


void SetMouse(int x, int y); void SetMouse(int x, int y);
void Render(); void Render();
void Quit();
int Finished();


private: private:
GameData *data; GameData *data;


+ 3
- 3
src/test-map.cpp View File

@@ -21,7 +21,7 @@ int main(int argc, char **argv)
Video *video = new SdlVideo("Deus Hax", 640, 480); Video *video = new SdlVideo("Deus Hax", 640, 480);
Game *game = new Game("maps/testmap.tmx"); Game *game = new Game("maps/testmap.tmx");


for (int done = 0; !done; )
while (!game->Finished())
{ {
/* Test stuff */ /* Test stuff */
int mx, my; int mx, my;
@@ -40,13 +40,13 @@ int main(int argc, char **argv)
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
if (event.type == SDL_QUIT) if (event.type == SDL_QUIT)
done = 1;
game->Quit();
if (event.type == SDL_KEYDOWN) if (event.type == SDL_KEYDOWN)
{ {
if (event.key.keysym.sym == SDLK_RETURN) if (event.key.keysym.sym == SDLK_RETURN)
video->FullScreen(); video->FullScreen();
else if (event.key.keysym.sym == SDLK_ESCAPE) else if (event.key.keysym.sym == SDLK_ESCAPE)
done = 1;
game->Quit();
} }
} }
} }


Loading…
Cancel
Save