r118 - in trunk: . src

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sat Jun 18 11:22:43 EDT 2005


Author: jonas
Date: 2005-06-18 11:22:43 -0400 (Sat, 18 Jun 2005)
New Revision: 118

Modified:
   trunk/TODO
   trunk/src/common.cpp
   trunk/src/common.h
   trunk/src/gfxeng.cpp
   trunk/src/input.cpp
   trunk/src/lost_penguins.cpp
   trunk/src/menu.cpp
   trunk/src/physics.cpp
   trunk/src/scenario.cpp
Log:
introduced game_mode global variable to indicate the current game mode (paused, playing, editing, menu)

Modified: trunk/TODO
===================================================================
--- trunk/TODO	2005-06-12 13:48:51 UTC (rev 117)
+++ trunk/TODO	2005-06-18 15:22:43 UTC (rev 118)
@@ -16,6 +16,8 @@
        This would help in many ways and should be a frame information and not an
        image as done for players atm!
      o Use Singletons
+     o Introduce abstract classes for all engines and load the corresponding
+       concrete class depending on the game_mode instead of using if...
 
  o Move/Fall/push/crash/collisions:
      o the character should have more information what he hits

Modified: trunk/src/common.cpp
===================================================================
--- trunk/src/common.cpp	2005-06-12 13:48:51 UTC (rev 117)
+++ trunk/src/common.cpp	2005-06-18 15:22:43 UTC (rev 118)
@@ -10,8 +10,7 @@
 Font* font;
 Font* font2;
 Config config;
-bool paused=false;
-bool running=false;
+Uint8 game_mode=NOTHING;
 Menu* menu;
 
 string itos(int i) {

Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h	2005-06-12 13:48:51 UTC (rev 117)
+++ trunk/src/common.h	2005-06-18 15:22:43 UTC (rev 118)
@@ -61,6 +61,11 @@
 #define DIR_DWL         0x0000000A
 #define DIR_LR          0x00000003
 
+#define GAME_PAUSED     0x00000001
+#define GAME_PLAY       0x00000002
+#define GAME_EDIT       0x00000004
+#define GAME_MENU       0x00000008
+
 enum ConfigKey {
     KEY_START,
     KEY_LEFT,
@@ -165,10 +170,8 @@
 extern Font* font;
 /// Font2
 extern Font* font2;
-/// True if the game is paused
-extern bool paused;
-/// True if a map is currently running
-extern bool running;
+/// Game state
+extern Uint8 game_mode;
 /// Currently used menu, NULL if not inside a menu
 extern Menu* menu;
 //@}

Modified: trunk/src/gfxeng.cpp
===================================================================
--- trunk/src/gfxeng.cpp	2005-06-12 13:48:51 UTC (rev 117)
+++ trunk/src/gfxeng.cpp	2005-06-18 15:22:43 UTC (rev 118)
@@ -50,14 +50,14 @@
     if (menu) {
         //Assure we have a (correct) menu background
         if (!menubg) {
-            if (running) {
+            if (game_mode&GAME_PLAY) {
                 setGameMenuBG();
             } else {
                 setMenuBG();
             }
         }
         if (updatetype==UPDATE_ALL) {
-            if (running) {
+            if (game_mode&GAME_PLAY) {
                 setGameMenuBG();
                 drawMenu();
             } else {
@@ -68,7 +68,7 @@
             drawMenu();
         }
     //Paused game
-    } else if (paused) {
+    } else if (game_mode&GAME_PAUSED) {
         if (updatetype==UPDATE_ALL) {
             drawScene();
             drawPlayerBar();
@@ -76,7 +76,7 @@
             drawPlayerBar();
         }
     //Not paused running game
-    } else if (running) {
+    } else if (game_mode&GAME_PLAY) {
         drawScene();
         drawPlayerBar();
         drawFPS();
@@ -142,7 +142,7 @@
 }
 
 void GraphicsEngine::drawScene() {
-    if (!running) return;
+    if (!(game_mode&GAME_PLAY)) return;
 
     //We don't want to change pos!
     SDL_Rect tmprect,shift,srcpos;

Modified: trunk/src/input.cpp
===================================================================
--- trunk/src/input.cpp	2005-06-12 13:48:51 UTC (rev 117)
+++ trunk/src/input.cpp	2005-06-18 15:22:43 UTC (rev 118)
@@ -30,7 +30,7 @@
 void InputHandler::update() {
     if (menu) {
         pollMenuEvents();
-    } else if (paused) {
+    } else if (game_mode&GAME_PAUSED) {
         pollPausedEvents();
     } else {
         pollGameEvents();
@@ -63,7 +63,7 @@
                     menu->act();
                 } else if (key==config.keybind[KEY_MENU]) {
                      if (!closeMenu()) {
-                         if (running) {
+                         if (game_mode&GAME_PLAY) {
                              sfxeng->resumeMusic();
                          } else {
                              quitGame(0);
@@ -106,7 +106,7 @@
                 if (key==config.keybind[KEY_SWITCH]) {
                      scenario->pool->switchPlayer();
                 } else if (key==config.keybind[KEY_PAUSE]) {
-                     paused=false;
+                     game_mode&=~GAME_PAUSED;
                      sfxeng->resumeMusic();
                 } else if (key==config.keybind[KEY_MENU]) {
                      sfxeng->pauseMusic();
@@ -148,7 +148,7 @@
                 if (key==config.keybind[KEY_SWITCH]) {
                      scenario->pool->switchPlayer();
                 } else if (key==config.keybind[KEY_PAUSE]) {  
-                     paused=true;
+                     game_mode|=GAME_PAUSED;
                      sfxeng->playWAV(au_pause);
                      sfxeng->pauseMusic();
                 } else if (key==config.keybind[KEY_MENU]) {

Modified: trunk/src/lost_penguins.cpp
===================================================================
--- trunk/src/lost_penguins.cpp	2005-06-12 13:48:51 UTC (rev 117)
+++ trunk/src/lost_penguins.cpp	2005-06-18 15:22:43 UTC (rev 118)
@@ -56,7 +56,7 @@
 
     while (true) {
         input->update();
-        if (running) scenario->physic->update();
+        if (game_mode&GAME_PLAY) scenario->physic->update();
         gfxeng->draw();
     }
 

Modified: trunk/src/menu.cpp
===================================================================
--- trunk/src/menu.cpp	2005-06-12 13:48:51 UTC (rev 117)
+++ trunk/src/menu.cpp	2005-06-18 15:22:43 UTC (rev 118)
@@ -60,6 +60,7 @@
     case 0: {
         if ((config.map!="") && (scenario->loadMap(config.map)==0)) {
             closeMenu();
+            game_mode|=GAME_PLAY;
             cout << "Starting game...\n" << endl;
         } else {
             cout << "Select a valid map first...\n" << endl;

Modified: trunk/src/physics.cpp
===================================================================
--- trunk/src/physics.cpp	2005-06-12 13:48:51 UTC (rev 117)
+++ trunk/src/physics.cpp	2005-06-18 15:22:43 UTC (rev 118)
@@ -24,7 +24,7 @@
 void PhysicHandler::update() {
     if (menu) {
         reset_time=true;
-    } else if (paused) {
+    } else if (game_mode&GAME_PAUSED ) {
         reset_time=true;
         updatePaused();
     } else {

Modified: trunk/src/scenario.cpp
===================================================================
--- trunk/src/scenario.cpp	2005-06-12 13:48:51 UTC (rev 117)
+++ trunk/src/scenario.cpp	2005-06-18 15:22:43 UTC (rev 118)
@@ -126,7 +126,6 @@
         if (pool->playerspool.size()>0) player=*pool->playerspool.begin();
         else player=NULL;
         if (player==NULL) cout << "No player found!\n";
-        running=true;
         return 0;
     } else {
        cout << "Map loading failed: No background found!\n";




More information about the lostpenguins-commits mailing list