r124 - in trunk: . src

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Tue Aug 30 12:48:54 EDT 2005


Author: jonas
Date: 2005-08-30 12:48:53 -0400 (Tue, 30 Aug 2005)
New Revision: 124

Modified:
   trunk/TODO
   trunk/src/common.cpp
   trunk/src/common.h
   trunk/src/gfxeng.cpp
   trunk/src/gfxeng.h
   trunk/src/input.cpp
   trunk/src/lost_penguins.cpp
   trunk/src/menu.cpp
   trunk/src/menu.h
   trunk/src/objectpools.cpp
Log:
updated TODO, improved/added edit mode, added Box class for edit mode...

Modified: trunk/TODO
===================================================================
--- trunk/TODO	2005-07-10 10:09:34 UTC (rev 123)
+++ trunk/TODO	2005-08-30 16:48:53 UTC (rev 124)
@@ -12,27 +12,26 @@
      o pointers => references where possible
      o Describe everything using Doxygen styles, move the documentation from
       *.cpp to the headers...
-     o Idea: _all_ objects should have a "kore" like the players (curpos thing)
+     o Idea: _all_ objects should have a "core" like the players (curpos thing)
        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
+     o IDEA: 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
-     o movements into dense objects should involve a push()
-     o I have no idea about how the push should look like, elevators can be pushed
-       up, even though you don't collide with them on top
-     o characters should be "pushable", eg. a stone that falls down pushes the
-       character down or better: an elevator should push the characters up
+     o IDEA: movements into dense objects should involve a push()
+       -> I have no idea about how the push should look like, elevators can be pushed
+          up, even though you don't collide with them on top
+       -> characters should be "pushable", eg. a stone that falls down pushes the
+          character down or better: an elevator should push the characters up
      o In case of the elevator, the players are somehow "bound" to the elevator (ie.
        it's not like: the elevator moves, the character falls, but they move together)
        Solution: The elevators move function checks all objects it would
          hit, if they are pushable (not dense) they are moved first if
          possible. If it's not possible, do sthg else (stop the elevator and hit the
          object/whatever)...
-     o the collision detection and the move/fall code is all a big mess
 
  o Animations/Events:
      o Allow as complex Images as possible:
@@ -116,7 +115,7 @@
           illegaly placed!
         - the placement should somehow involve checkPlace...
 
- o Plugins:
+ o (Plugins):
      o move object creation code (addObjectByName) to the objects
      o create dynamical plugins for all objects (or compile all in)
 
@@ -145,12 +144,10 @@
 ==============
 
  o Make water movements possible (eric)
- o Improve player bar management
  o Add better graphics
  o finnish the map editor
  o OpenGL
  o Simple AI
- o Menu
 
  o Finnish the vikings:
      - weapons: run, jump2, fart, sword, arm, fire, claws
@@ -182,6 +179,3 @@
 
  o Items?:
     - special items
-
- o IDEA: add horizontal gravity that slows objects down??
-

Modified: trunk/src/common.cpp
===================================================================
--- trunk/src/common.cpp	2005-07-10 10:09:34 UTC (rev 123)
+++ trunk/src/common.cpp	2005-08-30 16:48:53 UTC (rev 124)
@@ -12,6 +12,19 @@
 Config config;
 Uint8 game_mode=NOTHING;
 Menu* menu=NULL;
+Box* box=NULL;
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+const Uint32 rmask=0xff000000;
+const Uint32 gmask=0x00ff0000;
+const Uint32 bmask=0x0000ff00;
+const Uint32 amask=0x000000ff;
+#else
+const Uint32 rmask=0x000000ff;
+const Uint32 gmask=0x0000ff00;
+const Uint32 bmask=0x00ff0000;
+const Uint32 amask=0xff000000;
+#endif
+Uint32 vflags=SDL_HWSURFACE|SDL_RESIZABLE|SDL_DOUBLEBUF;
 
 string itos(int i) {
     std::stringstream s;

Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h	2005-07-10 10:09:34 UTC (rev 123)
+++ trunk/src/common.h	2005-08-30 16:48:53 UTC (rev 124)
@@ -41,6 +41,7 @@
 class Weapon;
 class Animation;
 class Menu;
+class Box;
 
 typedef std::set<Object *>::iterator object_iterator;
 typedef std::set<Character *>::iterator character_iterator;
@@ -147,10 +148,19 @@
 Menu* closeMenu();
 /// Close all menus (menu=NULL)
 void closeMenus();
+/// Set the current box
+Box* setBox(Box* newbox);
+/// Close the current box
+void closeBox();
 //@}
 
 //global variables
 //@{
+extern const Uint32 rmask;
+extern const Uint32 gmask;
+extern const Uint32 bmask;
+extern const Uint32 amask;
+extern Uint32 vflags;
 /// Game configuration
 extern Config config;
 /// Image Cache
@@ -173,6 +183,8 @@
 extern Uint8 game_mode;
 /// Currently used menu, NULL if not inside a menu
 extern Menu* menu;
+/// Currently used box, NULL if there is no box
+extern Box* box;
 //@}
 
 #endif

Modified: trunk/src/gfxeng.cpp
===================================================================
--- trunk/src/gfxeng.cpp	2005-07-10 10:09:34 UTC (rev 123)
+++ trunk/src/gfxeng.cpp	2005-08-30 16:48:53 UTC (rev 124)
@@ -13,23 +13,11 @@
 
 
 GraphicsEngine::GraphicsEngine():
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-  rmask(0xff000000),
-  gmask(0x00ff0000),
-  bmask(0x0000ff00),
-  amask(0x000000ff),
-#else
-  rmask(0x000000ff),
-  gmask(0x0000ff00),
-  bmask(0x00ff0000),
-  amask(0xff000000),
-#endif
   screen(NULL),
   menubg(NULL),
   show_bar(true),
   show_fps(true),
-  fullscreen(config.full),
-  vflags(SDL_HWSURFACE|SDL_RESIZABLE|SDL_DOUBLEBUF) {
+  fullscreen(config.full) {
     shift.x=0;
     shift.y=0;
     resize(config.width, config.height);
@@ -82,7 +70,8 @@
     } else if (game_mode&GAME_EDIT) {
         if (show_fps) toggleFPS();
         if (show_bar) togglePlayerBar();
-        drawEditScene();
+        drawScene();
+        drawBox();
         updatetype=UPDATE_ALL;
     } else return;
     //This is the most time consuming operation
@@ -147,11 +136,15 @@
 void GraphicsEngine::drawScene() {
     //We don't want to change pos!
     SDL_Rect tmprect,srcpos;
-    if (scenario->player!=NULL) {
-        shift=setShift(scenario->player->getCenter());
-    } else {
-        shift.x=0;
-        shift.y=0;
+    if (game_mode&GAME_PLAY) {
+        if (scenario->player!=NULL) {
+            shift=setShift(scenario->player->getCenter());
+        } else {
+            shift.x=0;
+            shift.y=0;
+        }
+    } else if (game_mode&GAME_EDIT) {
+        SDL_FillRect(screen,NULL,0);
     }
 
     tmprect=*scenario->area;
@@ -168,7 +161,7 @@
         ++obit;
     }
 
-    if (scenario->player!=NULL) {
+    if (game_mode&GAME_PLAY && scenario->player!=NULL) {
         tmprect=*(scenario->player->getPos());
         srcpos=scenario->player->getFrame().pos;
         shiftMapArea(tmprect,*(scenario->player->getCurPos()));
@@ -176,26 +169,6 @@
     }
 }
 
-void GraphicsEngine::drawEditScene() {
-    //We don't want to change pos!
-    SDL_Rect tmprect,srcpos;
-
-    SDL_FillRect(screen,NULL,0);
-    tmprect=*scenario->area;
-    srcpos=scenario->background->getFrame().pos;
-    shiftMapArea(tmprect,*scenario->background->getCurPos());
-    SDL_BlitSurface(scenario->background->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift));
-    
-    object_iterator obit=scenario->pool->objectspool.begin();
-    while (obit!=scenario->pool->objectspool.end()) {
-        tmprect=*((*obit)->getPos());
-        srcpos=(*obit)->getFrame().pos;
-        shiftMapArea(tmprect,*((*obit)->getCurPos()));
-        SDL_BlitSurface((*obit)->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift));
-        ++obit;
-    }
-}
-
 //TODO don't draw the whole screen, just till bar, just upgrade certain regions of the bar
 void GraphicsEngine::drawPlayerBar() {
     if (!show_bar) return;
@@ -353,13 +326,21 @@
     }
 }
 
+void GraphicsEngine::drawBox() {
+    if (box && box->surface) {
+        SDL_Rect tmprect;
+        tmprect=box->area;
+        SDL_BlitSurface(box->surface,0,screen,&tmprect);
+    }
+}
+
 //this could probably be done much easier ;)
 inline void GraphicsEngine::setGameMenuBG() {
     if (menubg) SDL_FreeSurface(menubg);
     if (game_mode&GAME_PLAY) {
         drawScene();
         drawPlayerBar();
-    } else if (game_mode&GAME_EDIT) drawEditScene();
+    } else if (game_mode&GAME_EDIT) drawScene();
     SDL_Flip(screen);
     
     SDL_Surface* tmp = SDL_CreateRGBSurface (

Modified: trunk/src/gfxeng.h
===================================================================
--- trunk/src/gfxeng.h	2005-07-10 10:09:34 UTC (rev 123)
+++ trunk/src/gfxeng.h	2005-08-30 16:48:53 UTC (rev 124)
@@ -32,15 +32,14 @@
         void setMenuBG(SDL_Surface* menu_background=NULL);
         const SDL_Rect& addShift(Sint16,Sint16);
         const SDL_Rect& setShift(Sint16,Sint16);
+        const SDL_Rect& getShift() {
+            return shift;
+        }
     protected:
-        const Uint32 rmask;
-        const Uint32 gmask;
-        const Uint32 bmask;
-        const Uint32 amask;
-        /// currently visible part of the map area
-        SDL_Rect vis_map;
         /// main screen
         SDL_Surface* screen;
+        /// currently visible part of the map area
+        SDL_Rect vis_map;
         /// menu background
         SDL_Surface* menubg;
         /// player bar
@@ -53,17 +52,12 @@
         bool fullscreen;
         //update state
         Uint8 updatetype;
-        //video flags
-        Uint32 vflags;
         // current shift
         SDL_Rect shift;
     protected:
         /// Draw the background and all objects in the pool. This is a very time
         /// consuming function...
         inline void drawScene();
-        /// Draw the background and all objects in the pool in map editor mode.
-        /// This is a very time consuming function...
-        inline void drawEditScene();
         /// Draw player bar
         inline void drawPlayerBar();
         /// Draw the frames per second
@@ -73,6 +67,7 @@
         /// If no scenario is running or the scenario was interrupted this will
         /// draw the menu.
         inline void drawMenu();
+        inline void drawBox();
         inline void resetMenuBG();
         inline SDL_Rect clipToBG(SDL_Rect dest) const;
         /// updates backpos and returns the new shift vector (ignore w,h)

Modified: trunk/src/input.cpp
===================================================================
--- trunk/src/input.cpp	2005-07-10 10:09:34 UTC (rev 123)
+++ trunk/src/input.cpp	2005-08-30 16:48:53 UTC (rev 124)
@@ -46,11 +46,11 @@
     }
     while(SDL_PollEvent(&event)) {
         switch(event.type) {
-           // special events
-         case SDL_VIDEORESIZE: {
-             gfxeng->resize(event.resize.w, event.resize.h);
-             break;
-         }
+            // special events
+            case SDL_VIDEORESIZE: {
+                gfxeng->resize(event.resize.w, event.resize.h);
+                break;
+            }
             // keyboard events
             case SDL_QUIT: {
                 quitGame(0);
@@ -94,11 +94,11 @@
     }
     while(SDL_PollEvent(&event)) {
         switch(event.type) {
-           // special events
-         case SDL_VIDEORESIZE: {
-             gfxeng->resize(event.resize.w, event.resize.h);
-             break;
-         }
+             // special events
+             case SDL_VIDEORESIZE: {
+                gfxeng->resize(event.resize.w, event.resize.h);
+                break;
+            }
             // keyboard events
             case SDL_QUIT: {
                 quitGame(0);
@@ -136,11 +136,11 @@
     }
     while(SDL_PollEvent(&event)) {
         switch(event.type) {
-           // special events
-         case SDL_VIDEORESIZE: {
-             gfxeng->resize(event.resize.w, event.resize.h);
-             break;
-         }
+            // special events
+            case SDL_VIDEORESIZE: {
+                gfxeng->resize(event.resize.w, event.resize.h);
+                break;
+            }
             // keyboard events
             case SDL_QUIT: {
                 quitGame(0);
@@ -183,15 +183,52 @@
     }
     while(SDL_PollEvent(&event)) {
         switch(event.type) {
-           // special events
-         case SDL_VIDEORESIZE: {
-             gfxeng->resize(event.resize.w, event.resize.h);
-             break;
-         }
+            // special events
+            case SDL_VIDEORESIZE: {
+                gfxeng->resize(event.resize.w, event.resize.h);
+                break;
+            }
             // keyboard events
             case SDL_QUIT: {
                 quitGame(0);
             }
+            case SDL_MOUSEBUTTONUP: {
+                switch (event.button.button) {
+                    case SDL_BUTTON_LEFT: {
+                        break;
+                    }
+                    case SDL_BUTTON_RIGHT: {
+                        if (box) box->act(box->getCurrentEntry(event.button.x,event.button.y));
+                        break;
+                    }
+                    case SDL_BUTTON_MIDDLE: {
+                        break;
+                    }
+                    default: {
+                        break;
+                    }
+                }
+                break;
+            }
+            case SDL_MOUSEBUTTONDOWN: {
+                switch (event.button.button) {
+                    case SDL_BUTTON_LEFT: {
+                        if (box) box->act(box->getCurrentEntry(event.button.x,event.button.y));
+                        break;
+                    }
+                    case SDL_BUTTON_RIGHT: {
+                        setBox(new EditBox(event.button.x,event.button.y));
+                        break;
+                    }
+                    case SDL_BUTTON_MIDDLE: {
+                        break;
+                    }
+                    default: {
+                        break;
+                    }
+                }
+                break;
+            }
             case SDL_KEYDOWN: {
                 SDLKey key=event.key.keysym.sym;
                 keypressed[key]=true;

Modified: trunk/src/lost_penguins.cpp
===================================================================
--- trunk/src/lost_penguins.cpp	2005-07-10 10:09:34 UTC (rev 123)
+++ trunk/src/lost_penguins.cpp	2005-08-30 16:48:53 UTC (rev 124)
@@ -31,7 +31,7 @@
         cout << "Couldn't initialize SDL!\n";
         exit(-1);
     }
-    SDL_ShowCursor(SDL_DISABLE);
+    SDL_ShowCursor(SDL_ENABLE);
     //Change directory to datadir
 
     cout << "ImageCache...\n";
@@ -64,6 +64,7 @@
 
 int quitGame(int errorcode=0) {
     cout << endl << "Quitting game (exit code: " << errorcode << ")...\n";
+    closeBox();
     closeMenus();
     delete scenario;
     cout << "Scenario closed...\n";

Modified: trunk/src/menu.cpp
===================================================================
--- trunk/src/menu.cpp	2005-07-10 10:09:34 UTC (rev 123)
+++ trunk/src/menu.cpp	2005-08-30 16:48:53 UTC (rev 124)
@@ -3,6 +3,7 @@
 #include "physics.h"
 #include "gfxeng.h"
 #include "sfxeng.h"
+#include "font.h"
 #include "menu.h"
 
 Menu* setMenu(Menu* newmenu) {
@@ -283,3 +284,122 @@
     }
 */
 }
+
+Box* setBox(Box* newbox) {
+    gfxeng->update(UPDATE_ALL);
+    return box=newbox;   
+}
+ 
+void closeBox() {
+    if (box) delete box;
+    box=NULL;
+    gfxeng->update(UPDATE_ALL);
+}
+
+Box::Box(Sint16 x, Sint16 y):
+  title("MENU"),
+  //don't forget the "::"
+  font(::font),
+  font_title(font),
+  font_high(font2),
+  surface(NULL) {
+    area.x=x;
+    area.y=y;
+}
+Box::~Box() {
+}
+
+void Box::act(Sint8) {
+    closeBox();
+}
+
+const SDL_Rect& Box::getArea() {
+    Uint16 tmp=0;
+    Uint16 maxwidth=font_title->getTextWidth(title);
+    for (Uint8 i=0; i<entries.size(); i++) {
+        tmp=max(font->getTextWidth(entries[i]),font_high->getTextWidth(entries[i]));
+        maxwidth=max(maxwidth,tmp);
+    }
+    area.w=maxwidth+2*WFONT;
+    area.h=entries.size()*(DFONT+font->getHeight())+2*WFONT+font_title->getHeight();
+    return area;
+}
+
+Sint8 Box::getCurrentEntry(Sint16 x, Sint16 y) {
+    getArea();
+    if (
+      (x>=(area.x+area.w)) ||
+      (x<=area.x) ||
+      (y>=(area.y+area.h)) ||
+      (y<=(area.y+WFONT+font_title->getHeight()+(int)(DFONT/2)))) {
+        return -1;
+    }
+    Sint16 tmp=y-area.y-WFONT-font_title->getHeight()-(int)(DFONT/2);
+    Uint16 entrysize=DFONT+font->getHeight();
+    Uint8 currententry=0;
+    while (tmp>entrysize) {
+        tmp-=entrysize;
+        ++currententry;
+    }
+    return currententry;
+}
+
+void Box::update() {
+    if (surface==NULL) {
+        getArea();
+        SDL_Surface* tmp=SDL_CreateRGBSurface(vflags, area.w, area.h, 32, rmask, gmask, bmask, amask);
+        surface=SDL_DisplayFormatAlpha(tmp);
+        SDL_FreeSurface(tmp);
+        SDL_FillRect(surface,0,SDL_MapRGBA(surface->format,200,200,200,180));
+
+        /* create a border */
+        Sint16 tmph=0;
+        SDL_Rect line;
+        line.x=0;
+        line.y=0;
+        line.w=BORDERSIZE;
+        line.h=area.h;
+        SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));        
+        line.x=area.w-BORDERSIZE;
+        SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));        
+        line.x=0;
+        line.y=0;
+        line.w=area.w;
+        line.h=BORDERSIZE;
+        SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));        
+        line.y=area.h-BORDERSIZE;
+        SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));        
+        
+        /* write title */
+        font_title->writeCenter(surface,title,WFONT);
+        line.y=font_title->getHeight()+(int)((DFONT-line.h)/2);
+        SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));
+        line.h=LINESIZE;
+    
+        /* write entries */
+        for (Uint8 i=0; i<entries.size(); i++) {
+            tmph=DFONT*(i+1)+font->getHeight()*i+WFONT+font_title->getHeight();
+            font->writeCenter(surface,entries[i],tmph);
+            line.y=tmph+font->getHeight()+(int)((DFONT-line.h)/2);
+            SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,180));
+        }
+    }
+}
+
+EditBox::EditBox(Sint16 x, Sint16 y): Box(x,y) {
+    title="PLACE";
+    entries.resize(4);
+    entries[0]="Olaf";
+    entries[1]="Water";
+    entries[2]="Zombie";
+    entries[3]="Exit";
+    update();
+}
+
+void EditBox::act(Sint8 curentry) {
+    if (curentry==1) {
+        setBox(new EditBox(area.x+10,area.y+10));
+    } else {
+        closeBox();
+    }
+}

Modified: trunk/src/menu.h
===================================================================
--- trunk/src/menu.h	2005-07-10 10:09:34 UTC (rev 123)
+++ trunk/src/menu.h	2005-08-30 16:48:53 UTC (rev 124)
@@ -1,6 +1,11 @@
 #ifndef DEF_MENU_H
 #define DEF_MENU_H 1
 
+#define WFONT 4
+#define DFONT 10
+#define BORDERSIZE 2
+#define LINESIZE 1
+
 /** \brief abstract menu base class
 
     Abstract base class for menus. The main part is in the constructor and in the
@@ -105,4 +110,46 @@
         void update();
 };
 
+
+/** \brief abstract selection box base class
+
+*/
+class Box {
+    friend class GraphicsEngine;
+    friend class InputHandler;
+    public:
+        Box(Sint16,Sint16);
+        virtual ~Box();
+        /// Name of the menu
+        string title;
+        /// Main menu function, depends on currententry (changed by input), overload this.
+        virtual void act(Sint8) = 0;
+        Uint8 getSize() {
+            return entries.size();
+        }
+        const SDL_Rect& getArea();
+        Sint8 getCurrentEntry(Sint16,Sint16);
+    protected:
+        /// List of all Box entry names
+        std::vector<string> entries;
+        /// Font for non highlighted menu entries
+        Font* font;   
+        /// Font for the menu title
+        Font* font_title;
+        /// Font for the selected menu entry
+        Font* font_high;
+        /// Area occupied by the selection box
+        SDL_Rect area;
+        /// Menu surface to be drawn
+        SDL_Surface* surface;
+        /// Draw the box surface
+        void update();
+};
+
+class EditBox : public Box {
+    public:
+        EditBox(Sint16,Sint16);
+        virtual void act(Sint8);
+};
+
 #endif

Modified: trunk/src/objectpools.cpp
===================================================================
--- trunk/src/objectpools.cpp	2005-07-10 10:09:34 UTC (rev 123)
+++ trunk/src/objectpools.cpp	2005-08-30 16:48:53 UTC (rev 124)
@@ -1,5 +1,7 @@
 #include "common.h"
 #include "scenario.h"
+//HACK
+#include "gfxeng.h"
 #include "sfxeng.h"
 #include "sndcache.h"
 #include "objectpools.h"
@@ -37,6 +39,8 @@
 }
 
 Object* ObjectsPool::addObjectbyName(const string& obj, const string& image, Sint16 x, Sint16 y, const string& arg1, const string& arg2, const string& arg3) {
+    x-=gfxeng->getShift().x;
+    y-=gfxeng->getShift().y;
     //Set names...
     string name=obj;
     if (arg1!="0") {




More information about the lostpenguins-commits mailing list