The Game Engine
1
Main Page
Related Pages
Classes
Files
File List
File Members
Game.h
Go to the documentation of this file.
1
#ifndef __GAME_H__
2
#define __GAME_H__
3
#include "
Texture.h
"
4
#include "
Level.h
"
5
#include "
Sprite.h
"
6
#include "
Camera.h
"
7
#include "
ParticleSystem.h
"
8
#include <vector>
9
#include <string>
10
24
class
Game
25
{
26
public
:
32
static
Game
*
game
();
33
35
static
const
int
FRAMES_PER_SECOND
= 60;
37
static
const
int
TICKS_PER_SECOND
= 30;
//can use 25 for small weaker hardware
38
40
bool
ShowCollisions
;
41
43
bool
ShowFPS
;
44
46
bool
FollowMouse
;
47
49
bool
Paused
;
50
52
bool
Focused
;
53
55
Camera
mCamera
;
56
58
friend
class
Camera
;
59
61
Level
*
CurrentLevel
;
62
64
Sprite
*
CurrentSprite
;
65
67
ParticleSystem
*
CurrentParticleSystem
;
68
70
ParticleSystem::Particle
*
CurrentParticle
;
71
73
Text
*
CurrentText
;
74
76
Level
*
LoadingLevel
;
77
79
FontType
Language
;
80
85
Level
*
getCurrentLevel
();
86
91
void
setCurrentLevel
(
string
name);
92
97
Level
*
loadLevel
(
string
name);
98
103
string
getLevelKey
();
104
109
int
getLevelCount
();
110
119
Font
*
getFont
(
FontType
type,
int
size);
120
126
void
removeFont
(
FontType
type,
int
size);
127
132
void
removeFont
(
Font
* font);
133
141
Texture
*
getTexture
(
string
filename,
Texture
* tex = NULL);
142
148
void
removeTexture
(
string
filename);
149
154
void
removeTexture
(
Texture
*
Texture
);
155
160
void
addAnimation
(
Animation
* anim);
161
167
Animation
*
getAnimation
(
string
name);
168
173
void
removeAnimation
(
Animation
* anim);
174
181
void
addActor
(
string
name,
Actor
actor);
182
187
void
removeActor
(
string
name);
188
194
void
addObject
(
WorldObject
* sp,
Level
* l = NULL);
195
201
void
removeObject
(
WorldObject
* sp,
Level
* l = NULL);
202
208
void
removeAllSprites
(
string
name,
Level
* l = NULL);
209
215
void
removeAllParticleSystems
(
string
name,
Level
* l = NULL);
216
220
void
run
();
221
225
void
stop
();
226
230
Uint32
getFPS
() {
return
avgFPS
; }
231
235
Point2D
getScreenSize
(){
return
Point2D
(
mScreen
->w,
mScreen
->h);}
236
237
protected
:
238
Game
();
239
~Game
();
240
242
bool
Running
;
243
245
bool
poll
;
246
248
bool
alwaysDraw
;
249
251
SDL_TimerID
timer
;
252
254
static
Game
*
m_instance
;
255
259
void
LoadResources
();
260
264
void
SetStaticObjectValues
();
265
269
void
addLevel
(
Level
* l);
270
272
map<string, Level*>
mLevels
;
273
275
map<string,Actor>
mActors
;
276
278
vector<Animation*>
mAnims
;
279
281
SDL_Surface *
mScreen
;
283
map<string,Behavior*>
mBehaviors
;
284
286
map<pair<FontType, int>,
Font
*>
mFonts
;
287
289
map<string, Texture* >
mTextures
;
290
292
Uint32
unfocusTime
;
293
295
296
static
const
int
FPSRANGE
= 1;
298
Uint32
nextSecondTick
;
300
Uint32
numFrames
;
302
Uint32
currentFPS
;
304
Uint32
avgFPS
;
306
Uint32
FPSs
[
FPSRANGE
];
308
Text
*
txtFPS
;
309
311
312
static
const
Uint32
drawInterval
= 1000/
FRAMES_PER_SECOND
;
314
Uint32
nextDrawTick
;
315
316
318
319
static
const
int
SKIP_TICKS
= 1000 /
TICKS_PER_SECOND
;
321
static
const
int
MAX_FRAMESKIP
= 5;
323
Uint32
nextGameTick
;
325
int
drawLoops
;
326
330
void
handleInput
(SDL_Event event);
331
335
void
draw
();
336
340
void
startDrawTimer
();
341
345
void
stopDrawTimer
();
346
352
void
resize
(
int
w ,
int
h);
353
357
static
Uint32
pushUserEvent
(Uint32 interval,
void
* data);
358
362
void
CalculateFramerate
();
363
};
364
365
#endif
Game.h
Generated on Tue Apr 16 2013 02:32:41 for The Game Engine by
1.8.3.1