source: trunk/src/game.cpp @ 106

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

Make the Game class an asset like the others.

  • Property svn:keywords set to Id
File size: 1.3 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
55Asset::Group Game::GetGroup()
56{
57    return Asset::GetGroup();
58}
59
60void Game::TickGame(float delta_time)
61{
62    Asset::TickGame(delta_time);
63}
64
65void Game::TickRender(float delta_time)
66{
67    Asset::TickRender(delta_time);
68
69    Scene *scene = new Scene();
70
71    data->map->Render(scene, data->mousex, data->mousey, 0);
72
73    scene->Render();
74    delete scene;
75
76    char buf[1024];
77    sprintf(buf, "Frame %i", data->frame++);
78    data->font->Print(10, 10, buf);
79}
80
81void Game::SetMouse(int x, int y)
82{
83    data->mousex = x;
84    data->mousey = y;
85}
86
87void Game::Quit()
88{
89    data->done = 1;
90}
91
92int Game::Finished()
93{
94    return data->done;
95}
96
Note: See TracBrowser for help on using the repository browser.