Gel2D - The free/open source game creation suite

gelGameState.h
Go to the documentation of this file.
00001 /*
00002 Gel2D Game Engine - Cross-platform 2D gaming middleware
00003 Copyright (C) 2011 Mark D. Procarione
00004 
00005 Gel2D is free software: you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation, either version 3 of the License, or
00008 (at your option) any later version.
00009 
00010 Gel2D is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 GNU General Public License for more details.
00014 */
00015 
00016 #ifndef __GELGAMESTATE_H__
00017 #define __GELGAMESTATE_H__
00018 
00019 #include "gelLinkedList.h"
00020 #include "gelEvent.h"
00021 
00022 namespace gel
00023 {
00025 
00032     class GelGameState : public GelEventReceiver
00033     {
00034         public:
00035             GelGameState();
00036             virtual ~GelGameState() {}
00037 
00038             virtual void init() = 0;
00039             virtual void cleanup() = 0;
00040 
00041             virtual void pause()  { paused = true; }
00042             virtual void resume() { paused = false; }
00043 
00044             virtual void restart() = 0;
00045 
00046             virtual void update() = 0;
00047                         virtual void render() = 0;
00048 
00049                         bool isPaused() { return paused; }
00050 
00051         private:
00052             bool paused;
00053 
00054     };
00055 
00057 
00060     class GelGameStateManager
00061     {
00062         public:
00064 
00065             GelGameStateManager() {};
00066 
00068 
00071             void addOverlayScene( GelGameState *scn ) { scene.append(scn); }
00072 
00074 
00077             void addUnderlayScene( GelGameState *scn ) { scene.prepend(scn); }
00078 
00080 
00083             void addScene( GelGameState *scn ) { addOverlayScene(scn); }
00084 
00086 
00087             void removeScene( int index ) { scene.remove(index); }
00088 
00090             void updateAll();
00091 
00093             void drawAll();
00094 
00096             void pauseAll();
00097 
00099             void resumeAll();
00100 
00102             void restartAll();
00103 
00105 
00106             void updateScene( int index ) { scene[index]->update(); }
00107 
00109 
00110             void drawScene( int index ) { scene[index]->render(); }
00111 
00113 
00114             void pauseScene( int index ) { scene[index]->pause(); }
00115 
00117 
00118             void resumeScene( int index ) { scene[index]->resume(); }
00119 
00121 
00122             void restartScene( int index ) { scene[index]->restart(); }
00123 
00124         private:
00125             GelLinkedList<GelGameState*> scene;
00126     };
00127 }
00128 
00129 #endif // __GELGAMESTATE_H__