Bläddra i källkod

Implement a quit() mechanism in the Game class.

legacy
Sam Hocevar sam 14 år sedan
förälder
incheckning
effd8f768a
3 ändrade filer med 17 tillägg och 3 borttagningar
  1. +12
    -0
      src/game.cpp
  2. +2
    -0
      src/game.h
  3. +3
    -3
      src/test-map.cpp

+ 12
- 0
src/game.cpp Visa fil

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

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

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

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

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


+ 2
- 0
src/game.h Visa fil

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

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

private:
GameData *data;


+ 3
- 3
src/test-map.cpp Visa fil

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

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


Laddar…
Avbryt
Spara