source: trunk/src/game.cpp @ 102

Last change on this file since 102 was 102, checked in by sam, 11 years ago

Implement a quit() mechanism in the Game class.

  • Property svn:keywords set to Id
File size: 1.1 KB
Line 
1//
2// Deus Hax (working title)
3// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
4//
5
6#if defined HAVE_CONFIG_H
7#   include "config.h"
8#endif
9
10#include <cstdio>
11
12#include "game.h"
13#include "map.h"
14#include "font.h"
15
16/*
17 * Game implementation class
18 */
19
20class GameData
21{
22    friend class Game;
23
24private:
25    Map *map;
26    Font *font;
27    int x, y;
28    int mousex, mousey;
29    int done;
30
31    int frame;
32};
33
34/*
35 * Public Game class
36 */
37
38Game::Game(char const *mapname)
39{
40    data = new GameData();
41    data->map = new Map(mapname);
42    data->font = new Font("gfx/font/ascii.png");
43    data->x = data->y = 0;
44    data->done = 0;
45    data->frame = 0;
46}
47
48Game::~Game()
49{
50    delete data->font;
51    delete data->map;
52    delete data;
53}
54
55void Game::SetMouse(int x, int y)
56{
57    data->mousex = x;
58    data->mousey = y;
59}
60
61void Game::Render()
62{
63    Scene *scene = new Scene();
64
65    data->map->Render(scene, data->mousex, data->mousey, 0);
66
67    scene->Render();
68    delete scene;
69
70    char buf[1024];
71    sprintf(buf, "Frame %i", data->frame++);
72    data->font->Print(10, 10, buf);
73}
74
75void Game::Quit()
76{
77    data->done = 1;
78}
79
80int Game::Finished()
81{
82    return data->done;
83}
84
Note: See TracBrowser for help on using the repository browser.