|
The Game Engine
1
|
High-level controller for the game This class is tasked with the following: More...
#include <Game.h>
Collaboration diagram for Game:Public Member Functions | |
| Level * | getCurrentLevel () |
| Gets the current level being played. More... | |
| void | setCurrentLevel (string name) |
| Sets the current level to play. More... | |
| Level * | loadLevel (string name) |
| Loads content for the next level to play. More... | |
| string | getLevelKey () |
| Gets the index of the current level being played. More... | |
| int | getLevelCount () |
| Gets the total count of levels. More... | |
| Font * | getFont (FontType type, int size) |
| Gets a font to be used to display text. More... | |
| void | removeFont (FontType type, int size) |
| Removes the font if it has been loaded and nothing is using it. More... | |
| void | removeFont (Font *font) |
| Removes the font if it has been loaded and nothing is using it. More... | |
| Texture * | getTexture (string filename, Texture *tex=NULL) |
| Gets a Texture from the cache or generates it otherwise. More... | |
| void | removeTexture (string filename) |
| Removes the Texture if it has been loaded and nothing is using it. More... | |
| void | removeTexture (Texture *Texture) |
| Removes the Texture if it has been loaded and nothing is using it. More... | |
| void | addAnimation (Animation *anim) |
| add a Actor to the list of sprites More... | |
| Animation * | getAnimation (string name) |
| get a Actor* to the list of sprites More... | |
| void | removeAnimation (Animation *anim) |
| remove an Actor to the list of sprites More... | |
| void | addActor (string name, Actor actor) |
| add a Actor to the list of sprites More... | |
| void | removeActor (string name) |
| remove the Actor sp from the list of sprites More... | |
| void | addObject (WorldObject *sp, Level *l=NULL) |
| add a Object to the list of sprites More... | |
| void | removeObject (WorldObject *sp, Level *l=NULL) |
| remove the Object sp from the list of sprites More... | |
| void | removeAllSprites (string name, Level *l=NULL) |
| remove the Sprite sp from the list of sprites More... | |
| void | removeAllParticleSystems (string name, Level *l=NULL) |
| remove the ParticleSystem ps from the list of sprites More... | |
| void | run () |
| Makes the game loop begin and load objects. More... | |
| void | stop () |
| Makes the game loop stop. More... | |
| Uint32 | getFPS () |
| Returns the Current FPS of the game. More... | |
| Point2D | getScreenSize () |
| Gets the Screen's dimensions. More... | |
Static Public Member Functions | |
| static Game * | game () |
| This function is called to create an instance of the class. More... | |
Public Attributes | |
| bool | ShowCollisions |
| Decides whether or not to draw bounding boxes. More... | |
| bool | ShowFPS |
| Decides whether or not to output FPS. More... | |
| bool | FollowMouse |
| Decides whether or not the mouse should follow the cursor. More... | |
| bool | Paused |
| State of if the game should be paused or not. More... | |
| bool | Focused |
| Whether the game has focus or not. More... | |
| Camera | mCamera |
| Camera for the game. More... | |
| Level * | CurrentLevel |
| Stores the current level. More... | |
| Sprite * | CurrentSprite |
| Stores the current sprite while behaviors are being executed. More... | |
| ParticleSystem * | CurrentParticleSystem |
| Stores the current particle system while behaviors are being executed. More... | |
| ParticleSystem::Particle * | CurrentParticle |
| Stores the current particle while initialization or update functions are being executed. More... | |
| Text * | CurrentText |
| Stores the current text object while behaviors are being executed. More... | |
| Level * | LoadingLevel |
| The level that will be active next (for onloadFunctions) More... | |
| FontType | Language |
| The game's language. More... | |
Static Public Attributes | |
| static const int | FRAMES_PER_SECOND = 60 |
| Number of times the Screen is drawn per second. More... | |
| static const int | TICKS_PER_SECOND = 30 |
| Number of times the update loop is to run per second. More... | |
Protected Member Functions | |
| Game () | |
| ~Game () | |
| void | LoadResources () |
| Loads the game's resources. More... | |
| void | SetStaticObjectValues () |
| Sets up nondefault static values. More... | |
| void | addLevel (Level *l) |
| Adds a level safely. More... | |
| void | handleInput (SDL_Event event) |
| Handles input. More... | |
| void | draw () |
| draws More... | |
| void | startDrawTimer () |
| Starts Drawing Timer to limit number of draws. More... | |
| void | stopDrawTimer () |
| Stops the Drawing timer. More... | |
| void | resize (int w, int h) |
| Resizes the screen to wxh. More... | |
| void | CalculateFramerate () |
| Calculates our frame rate or FPS (may not mean anything since Updates are locked at 25 and draws are locked at 60 max) More... | |
Static Protected Member Functions | |
| static Uint32 | pushUserEvent (Uint32 interval, void *data) |
| Pushes user events (used in timer) More... | |
Protected Attributes | |
| bool | Running |
| Whether the game should keep running. More... | |
| bool | poll |
| Tells us whether to wait or poll. More... | |
| bool | alwaysDraw |
| Whether or not the game should draw as fast as possible. More... | |
| SDL_TimerID | timer |
| The drawing timer. More... | |
| map< string, Level * > | mLevels |
| Vector of pointers to all of the levels. More... | |
| map< string, Actor > | mActors |
| This level's actors. More... | |
| vector< Animation * > | mAnims |
| This level's Animations. More... | |
| SDL_Surface * | mScreen |
| The surface to draw to. More... | |
| map< string, Behavior * > | mBehaviors |
| This level's Behaviors. More... | |
| map< pair< FontType, int > , Font * > | mFonts |
| The fonts that exist (should be a small amount) More... | |
| map< string, Texture * > | mTextures |
| Textures that have been loaded (since we really don't want to delete them unless they're unused). More... | |
| Uint32 | unfocusTime |
| keeping all timing in sync More... | |
| Uint32 | nextSecondTick |
| estimated ticks to next second More... | |
| Uint32 | numFrames |
| current number of frames More... | |
| Uint32 | currentFPS |
| index into FPSs More... | |
| Uint32 | avgFPS |
| the fps we want to display More... | |
| Uint32 | FPSs [FPSRANGE] |
| list of frame values More... | |
| Text * | txtFPS |
| The fps text. More... | |
| Uint32 | nextDrawTick |
| Tick at which the game should update next. More... | |
| Uint32 | nextGameTick |
| Tick at which the game should update next. More... | |
| int | drawLoops |
| Number of times drawing has happened this frame (for limiting draw counts) More... | |
Static Protected Attributes | |
| static Game * | m_instance = NULL |
| Global static pointer used to ensure a single instance of the class. More... | |
| static const int | FPSRANGE = 1 |
| fps data calc More... | |
| static const Uint32 | drawInterval = 1000/FRAMES_PER_SECOND |
| Draw loop Throttling. More... | |
| static const int | SKIP_TICKS = 1000 / TICKS_PER_SECOND |
| Update loop Throttling. More... | |
| static const int | MAX_FRAMESKIP = 5 |
| Max number of frames we want to update in a tick. More... | |
Friends | |
| class | Camera |
| so that we can use the screen's dimensions More... | |
High-level controller for the game This class is tasked with the following:
|
protected |
| void Game::addActor | ( | string | name, |
| Actor | actor | ||
| ) |
| void Game::addAnimation | ( | Animation * | anim | ) |
|
protected |
| void Game::addObject | ( | WorldObject * | sp, |
| Level * | l = NULL |
||
| ) |
|
protected |
|
protected |
|
static |
| Animation * Game::getAnimation | ( | string | name | ) |
| Level * Game::getCurrentLevel | ( | ) |
| Font * Game::getFont | ( | FontType | type = Game::game()->Language, |
| int | size = 24 |
||
| ) |
|
inline |
| int Game::getLevelCount | ( | ) |
| string Game::getLevelKey | ( | ) |
|
inline |
Gets a Texture from the cache or generates it otherwise.
| filename | filename for the texture |
| tex | Pointer to the texture to use otherwise returns the Texture |
Definition at line 248 of file Game.cpp.
Here is the caller graph for this function:
|
protected |
Handles input.
If the event is a click on the close button in the top right corner of the window, we kill the application
Pause / unpause the game when window looses/gains focus
If our event reports a key being pressed down we process it
<
Definition at line 377 of file Game.cpp.
Here is the call graph for this function:
Here is the caller graph for this function:| Level * Game::loadLevel | ( | string | name | ) |
|
protected |
Loads the game's resources.
Definition at line 7 of file LoadResources.cpp.
Here is the call graph for this function:
Here is the caller graph for this function:
|
staticprotected |
| void Game::removeActor | ( | string | name | ) |
| void Game::removeAllParticleSystems | ( | string | name, |
| Level * | l = NULL |
||
| ) |
remove the ParticleSystem ps from the list of sprites
| name | ParticleSystems to remove |
| l | the level which to add the sprites to (defaults to CurrentLevel) |
Definition at line 357 of file Game.cpp.
Here is the call graph for this function:| void Game::removeAllSprites | ( | string | name, |
| Level * | l = NULL |
||
| ) |
| void Game::removeAnimation | ( | Animation * | anim | ) |
| void Game::removeFont | ( | Font * | font | ) |
| void Game::removeObject | ( | WorldObject * | sp, |
| Level * | l = NULL |
||
| ) |
| void Game::removeTexture | ( | string | filename | ) |
| void Game::removeTexture | ( | Texture * | Texture | ) |
|
protected |
| void Game::run | ( | ) |
| void Game::setCurrentLevel | ( | string | name | ) |
|
protected |
Sets up nondefault static values.
Definition at line 13 of file LoadResources.cpp.
Here is the caller graph for this function:
|
protected |
| void Game::stop | ( | ) |
|
protected |
|
friend |
|
protected |
| ParticleSystem::Particle* Game::CurrentParticle |
| ParticleSystem* Game::CurrentParticleSystem |
| Sprite* Game::CurrentSprite |
| Text* Game::CurrentText |
|
staticprotected |
|
protected |
| bool Game::FollowMouse |
|
staticprotected |
|
static |
| Level* Game::LoadingLevel |
|
staticprotected |
|
protected |
|
protected |
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
| bool Game::Paused |
|
protected |
| bool Game::ShowCollisions |
|
staticprotected |
|
static |
|
protected |