From DONOTREPLY at icculus.org Sun Jun 12 09:36:15 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 12 Jun 2005 09:36:15 -0400 Subject: r113 - trunk/src Message-ID: <20050612133615.27020.qmail@icculus.org> Author: jonas Date: 2005-06-12 09:36:15 -0400 (Sun, 12 Jun 2005) New Revision: 113 Modified: trunk/src/lost_penguins.cpp Log: 10l, cosmetics Modified: trunk/src/lost_penguins.cpp =================================================================== --- trunk/src/lost_penguins.cpp 2005-03-20 10:48:40 UTC (rev 112) +++ trunk/src/lost_penguins.cpp 2005-06-12 13:36:15 UTC (rev 113) @@ -32,7 +32,7 @@ exit(-1); } SDL_ShowCursor(SDL_DISABLE); - system(config.datadir.c_str()); + //Change directory to datadir cout << "ImageCache...\n"; imgcache=new ImageCache(); @@ -173,11 +173,11 @@ } void usage() { - cout << "Usage: lost_penguins [OPTIONS]\n"; + cout << "Usage: lost_penguins [OPTIONS]\n\n"; cout << " -w, -width Changes resolution (width) of game. Default: 640\n"; cout << " -h, -height Changes resolution (height) of game. Default: 480\n"; cout << " -bpp Specifies color depth (bpp) of screen. Default: 16\n"; - cout << " -fs, -full Enable fullscreen. Default: disabled\n"; + cout << " -fs, -full Enable fullscreen. Default: disabled\n"; cout << " -map Load specified map from data dir. Default: map1\n"; cout << " -h, --help Show this text \n"; quitGame(4); From DONOTREPLY at icculus.org Sun Jun 12 09:38:00 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 12 Jun 2005 09:38:00 -0400 Subject: r114 - trunk/tools Message-ID: <20050612133800.27177.qmail@icculus.org> Author: jonas Date: 2005-06-12 09:38:00 -0400 (Sun, 12 Jun 2005) New Revision: 114 Modified: trunk/tools/lvl2magick.c Log: cosmetics (forgot) Modified: trunk/tools/lvl2magick.c =================================================================== --- trunk/tools/lvl2magick.c 2005-06-12 13:36:15 UTC (rev 113) +++ trunk/tools/lvl2magick.c 2005-06-12 13:38:00 UTC (rev 114) @@ -148,7 +148,7 @@ void usage() { printf("Usage: lvl2magick [options] file.lvl\n"); - printf("Extracts images from file.lvl.\n\n\n"); + printf("Extracts images from file.lvl.\n\n"); printf("Options:\n"); printf(" -h, --help Print this help message\n\n"); printf(" -debug Create additional debug files (default: off)\n\n"); From DONOTREPLY at icculus.org Sun Jun 12 09:42:03 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 12 Jun 2005 09:42:03 -0400 Subject: r115 - trunk/src Message-ID: <20050612134203.27573.qmail@icculus.org> Author: jonas Date: 2005-06-12 09:42:03 -0400 (Sun, 12 Jun 2005) New Revision: 115 Modified: trunk/src/sfxeng.h trunk/src/sndcache.cpp Log: better handling of disabled sfxeng (no error message) Modified: trunk/src/sfxeng.h =================================================================== --- trunk/src/sfxeng.h 2005-06-12 13:38:00 UTC (rev 114) +++ trunk/src/sfxeng.h 2005-06-12 13:42:03 UTC (rev 115) @@ -16,6 +16,9 @@ void stopMusic(); void pauseMusic(); void resumeMusic(); + bool isEnabled() { + return (!disabled); + } private: /// Music: Theme of the current map Mix_Music* theme; Modified: trunk/src/sndcache.cpp =================================================================== --- trunk/src/sndcache.cpp 2005-06-12 13:38:00 UTC (rev 114) +++ trunk/src/sndcache.cpp 2005-06-12 13:42:03 UTC (rev 115) @@ -1,5 +1,6 @@ #include "common.h" #include "sndcache.h" +#include "sfxeng.h" SoundCache::SoundCache() { } @@ -12,22 +13,26 @@ } Mix_Chunk* SoundCache::loadWAV(string soundfile) { - map::iterator sndit=sndcache.find(soundfile); + if (sfxeng->isEnabled()) { + map::iterator sndit=sndcache.find(soundfile); - //load new sound - if (sndit==sndcache.end()) { - #ifdef SDL_MIXER - string loadfile=config.datadir+soundfile; - Mix_Chunk* tmpwav=NULL; - if ((tmpwav=Mix_LoadWAV(loadfile.c_str())) == NULL) { - cout << "Couldn't load the wav file: " << soundfile << " (" << Mix_GetError() << ")" << endl; + //load new sound + if (sndit==sndcache.end()) { + #ifdef SDL_MIXER + string loadfile=config.datadir+soundfile; + Mix_Chunk* tmpwav=NULL; + if ((tmpwav=Mix_LoadWAV(loadfile.c_str())) == NULL) { + cout << "Couldn't load the wav file: " << soundfile << " (" << Mix_GetError() << ")" << endl; + return NULL; + } + sndcache.insert(make_pair(soundfile,tmpwav)); + return tmpwav; + #else return NULL; - } - sndcache.insert(make_pair(soundfile,tmpwav)); - return tmpwav; - #else - return NULL; - #endif - //already there - } else return (*sndit).second; + #endif + //already there + } else return (*sndit).second; + } else { + return NULL; + } } From DONOTREPLY at icculus.org Sun Jun 12 09:43:42 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 12 Jun 2005 09:43:42 -0400 Subject: r116 - trunk Message-ID: <20050612134342.27667.qmail@icculus.org> Author: jonas Date: 2005-06-12 09:43:41 -0400 (Sun, 12 Jun 2005) New Revision: 116 Modified: trunk/TODO Log: more todo's Modified: trunk/TODO =================================================================== --- trunk/TODO 2005-06-12 13:42:03 UTC (rev 115) +++ trunk/TODO 2005-06-12 13:43:41 UTC (rev 116) @@ -33,12 +33,68 @@ o the collision detection and the move/fall code is all a big mess o Animations/Events: + o Allow as complex Images as possible: + Introduce some image info structure that gives an array of subimages + Animations can then easily be specified by giving the start and end number in the + array. A subimage is defined by sthg like SDL_rect relative to the base image + o As the images of an animation (as in above) may vary in size we should introduce + sthg like a "base point" type: center/left/right (x) center/top/bottom (y) + => total: 9 types. Find a default base point... + which is a point in the animation that stays fixed (related to pos) + o Using the "base point" type => introduce corresponding drawing methode, which + consists of a rule on how to map the base point to the position (allignment): + center/left/right (x) center/top/bottom (y) + maybe introduce delta values for correction shifts + => most times the x-alignment probably corresponds to the base point, but the + y-allignment will almost always be bottom (top: sthg that hangs on a rope) + o Is the alignment a property of the object (state) or of the animation? => suggest animation + o Idea: introduce two type of animation for a simple triggered anim: + still anim: eg. 1 image, trig anim: animation starting with the still one + => get rid of once, running + More generally: do the logic about that outside of the animation structure + o Maybe introduce an animation base class and do the base_point/allignment logic + in derived classes somehow? Or use another pattern for this... + o Allow empty animation, decouple (put more logic in) these relations: + object (pos, draw?), game(time, state, handler), gfxeng(draw), animation(empty, + frame, update, time, draw)?, frame, global/current (public, private) properties + + o New anim class/struct: + /* Global properties */ + SDL_Surface* base_image (or in Frame struct) + Uint16 start_pos + Uint16 end_pos / or Uint16 frames + enum base_point_type + enum allignment_type + Uint16 allignment_delta + Uint16 length + /* Global Helper values */ + // maybe: bool empty? + bool still (if frames==1) + (see above) Uint16 frames / or Uint16 end_pos + + /* (Current) public properties */ + void update(Uint16 dt) + void draw() <- friend in gfxeng (shift, screen, etc)? + //information about the current graphic (frame) + //information about where to draw it (draw_pos) + + /* Current private properties */ + Uint16 cur_im_pos / or Uint16 cur_frame / or Uint16 cur_time + SDL_Rect* owner_pos (position of the owner) / or const SDL_Rect& owner_pos + /* Current helper values */ + Frame cur_frame (using private + image info) => w,h (or + Base Image) + (see above) Uint16 cur_pos / or Uint16 cur_frame / or Uint16 cur_time + SDL_Rect* (or SDL_Rect& ) draw_pos (using + (allignment/base_point)_(type/delta) + frame + owner_pos) + o Make all events quite short, ie. almost all events become animation events o Maybe: Improve the (very simple) image format: - All frame in one sprite sheet for each character (image matrices using two description vectors or even more general: offset matrices) + => see above - store rects in an array/vector/whatever or use offset matrices + => see above - do some column/row logics to easy the access - eg. set offsets for left, right, mleft, mright... - IDEA: just store one side and add some flipping logic to the image From DONOTREPLY at icculus.org Sun Jun 12 09:48:51 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 12 Jun 2005 09:48:51 -0400 Subject: r117 - trunk/src Message-ID: <20050612134851.27929.qmail@icculus.org> Author: jonas Date: 2005-06-12 09:48:51 -0400 (Sun, 12 Jun 2005) New Revision: 117 Modified: trunk/src/gfxeng.cpp trunk/src/gfxeng.h Log: const color masks Modified: trunk/src/gfxeng.cpp =================================================================== --- trunk/src/gfxeng.cpp 2005-06-12 13:43:41 UTC (rev 116) +++ trunk/src/gfxeng.cpp 2005-06-12 13:48:51 UTC (rev 117) @@ -13,23 +13,23 @@ 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) { -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - rmask = 0xff000000; - gmask = 0x00ff0000; - bmask = 0x0000ff00; - amask = 0x000000ff; -#else - rmask = 0x000000ff; - gmask = 0x0000ff00; - bmask = 0x00ff0000; - amask = 0xff000000; -#endif resize(config.width, config.height); lifeimage=new Animation(imgcache->loadImage("life.bmp")); } Modified: trunk/src/gfxeng.h =================================================================== --- trunk/src/gfxeng.h 2005-06-12 13:43:41 UTC (rev 116) +++ trunk/src/gfxeng.h 2005-06-12 13:48:51 UTC (rev 117) @@ -31,10 +31,10 @@ void toggleFullScreen(); void setMenuBG(SDL_Surface* menu_background=NULL); protected: - Uint32 rmask; - Uint32 gmask; - Uint32 bmask; - Uint32 amask; + 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 From DONOTREPLY at icculus.org Sat Jun 18 11:22:43 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 18 Jun 2005 11:22:43 -0400 Subject: r118 - in trunk: . src Message-ID: <20050618152243.27890.qmail@icculus.org> 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"; From DONOTREPLY at icculus.org Sat Jun 18 11:49:04 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 18 Jun 2005 11:49:04 -0400 Subject: r119 - trunk/src Message-ID: <20050618154904.32230.qmail@icculus.org> Author: jonas Date: 2005-06-18 11:49:04 -0400 (Sat, 18 Jun 2005) New Revision: 119 Modified: trunk/src/common.cpp trunk/src/gfxeng.cpp trunk/src/input.cpp trunk/src/lost_penguins.cpp trunk/src/menu.cpp trunk/src/physics.cpp Log: use game_mode GAME_MENU Modified: trunk/src/common.cpp =================================================================== --- trunk/src/common.cpp 2005-06-18 15:22:43 UTC (rev 118) +++ trunk/src/common.cpp 2005-06-18 15:49:04 UTC (rev 119) @@ -11,7 +11,7 @@ Font* font2; Config config; Uint8 game_mode=NOTHING; -Menu* menu; +Menu* menu=NULL; string itos(int i) { std::stringstream s; Modified: trunk/src/gfxeng.cpp =================================================================== --- trunk/src/gfxeng.cpp 2005-06-18 15:22:43 UTC (rev 118) +++ trunk/src/gfxeng.cpp 2005-06-18 15:49:04 UTC (rev 119) @@ -47,7 +47,7 @@ void GraphicsEngine::draw() { //Menu - if (menu) { + if (game_mode&GAME_MENU) { //Assure we have a (correct) menu background if (!menubg) { if (game_mode&GAME_PLAY) { @@ -59,11 +59,10 @@ if (updatetype==UPDATE_ALL) { if (game_mode&GAME_PLAY) { setGameMenuBG(); - drawMenu(); } else { setMenuBG(); - drawMenu(); } + drawMenu(); } else if (updatetype==UPDATE_MENU) { drawMenu(); } Modified: trunk/src/input.cpp =================================================================== --- trunk/src/input.cpp 2005-06-18 15:22:43 UTC (rev 118) +++ trunk/src/input.cpp 2005-06-18 15:49:04 UTC (rev 119) @@ -28,12 +28,13 @@ } void InputHandler::update() { - if (menu) { + if (game_mode&GAME_MENU) { pollMenuEvents(); } else if (game_mode&GAME_PAUSED) { pollPausedEvents(); + } else if (game_mode&GAME_PLAY) { + pollGameEvents(); } else { - pollGameEvents(); } } Modified: trunk/src/lost_penguins.cpp =================================================================== --- trunk/src/lost_penguins.cpp 2005-06-18 15:22:43 UTC (rev 118) +++ trunk/src/lost_penguins.cpp 2005-06-18 15:49:04 UTC (rev 119) @@ -51,7 +51,6 @@ scenario=new Scenario(); gfxeng->setMenuBG(); - menu=NULL; setMenu(new StartMenu()); while (true) { Modified: trunk/src/menu.cpp =================================================================== --- trunk/src/menu.cpp 2005-06-18 15:22:43 UTC (rev 118) +++ trunk/src/menu.cpp 2005-06-18 15:49:04 UTC (rev 119) @@ -9,6 +9,8 @@ if (menu) gfxeng->update(UPDATE_MENU); else gfxeng->update(UPDATE_ALL); newmenu->setLast(menu); + if (newmenu) game_mode|=GAME_MENU; + else game_mode&=~GAME_MENU; return menu=newmenu; } @@ -18,6 +20,8 @@ Menu* tmp=menu->getLast(); delete menu; if (!tmp) gfxeng->update(UPDATE_ALL); + if (tmp) game_mode|=GAME_MENU; + else game_mode&=~GAME_MENU; return menu=tmp; } else { gfxeng->update(UPDATE_ALL); Modified: trunk/src/physics.cpp =================================================================== --- trunk/src/physics.cpp 2005-06-18 15:22:43 UTC (rev 118) +++ trunk/src/physics.cpp 2005-06-18 15:49:04 UTC (rev 119) @@ -22,12 +22,12 @@ } void PhysicHandler::update() { - if (menu) { + if (game_mode&GAME_MENU) { reset_time=true; } else if (game_mode&GAME_PAUSED ) { reset_time=true; updatePaused(); - } else { + } else if (game_mode&GAME_PLAY) { if (reset_time) { Dfps=Dframes=currentfps=dt=0; minfps=1000; @@ -38,6 +38,7 @@ reset_time=false; tcurrent=SDL_GetTicks(); updateGame(); + } else { } } From DONOTREPLY at icculus.org Sat Jun 18 18:47:14 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 18 Jun 2005 18:47:14 -0400 Subject: r120 - in trunk/src: . objects Message-ID: <20050618224714.30123.qmail@icculus.org> Author: jonas Date: 2005-06-18 18:47:14 -0400 (Sat, 18 Jun 2005) New Revision: 120 Modified: trunk/src/gfxeng.cpp trunk/src/gfxeng.h trunk/src/input.cpp trunk/src/input.h trunk/src/lost_penguins.cpp trunk/src/menu.cpp trunk/src/menu.h trunk/src/objects/olaf.cpp trunk/src/physics.cpp trunk/src/physics.h trunk/src/sfxeng.cpp Log: add a prelimenary map (game) edit mode, make shift a member variable of gfxeng, some sfxeng volume tweaks, option parsers fixes Modified: trunk/src/gfxeng.cpp =================================================================== --- trunk/src/gfxeng.cpp 2005-06-18 15:49:04 UTC (rev 119) +++ trunk/src/gfxeng.cpp 2005-06-18 22:47:14 UTC (rev 120) @@ -30,6 +30,8 @@ show_fps(true), fullscreen(config.full), vflags(SDL_HWSURFACE|SDL_RESIZABLE|SDL_DOUBLEBUF) { + shift.x=0; + shift.y=0; resize(config.width, config.height); lifeimage=new Animation(imgcache->loadImage("life.bmp")); } @@ -50,14 +52,14 @@ if (game_mode&GAME_MENU) { //Assure we have a (correct) menu background if (!menubg) { - if (game_mode&GAME_PLAY) { + if (game_mode&(GAME_PLAY|GAME_EDIT)) { setGameMenuBG(); } else { setMenuBG(); } } if (updatetype==UPDATE_ALL) { - if (game_mode&GAME_PLAY) { + if (game_mode&(GAME_PLAY|GAME_EDIT)) { setGameMenuBG(); } else { setMenuBG(); @@ -68,11 +70,8 @@ } //Paused game } else if (game_mode&GAME_PAUSED) { - if (updatetype==UPDATE_ALL) { - drawScene(); + if (updatetype==UPDATE_ALL || updatetype==UPDATE_BAR) { drawPlayerBar(); - } else if (updatetype==UPDATE_BAR) { - drawPlayerBar(); } //Not paused running game } else if (game_mode&GAME_PLAY) { @@ -80,6 +79,11 @@ drawPlayerBar(); drawFPS(); updatetype=UPDATE_ALL; + } else if (game_mode&GAME_EDIT) { + if (show_fps) toggleFPS(); + if (show_bar) togglePlayerBar(); + drawEditScene(); + updatetype=UPDATE_ALL; } else return; //This is the most time consuming operation if (updatetype!=UPDATE_NOTHING) SDL_Flip(screen); @@ -141,10 +145,8 @@ } void GraphicsEngine::drawScene() { - if (!(game_mode&GAME_PLAY)) return; - //We don't want to change pos! - SDL_Rect tmprect,shift,srcpos; + SDL_Rect tmprect,srcpos; if (scenario->player!=NULL) { shift=setShift(scenario->player->getCenter()); } else { @@ -174,6 +176,26 @@ } } +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; @@ -334,8 +356,10 @@ //this could probably be done much easier ;) inline void GraphicsEngine::setGameMenuBG() { if (menubg) SDL_FreeSurface(menubg); - drawScene(); - drawPlayerBar(); + if (game_mode&GAME_PLAY) { + drawScene(); + drawPlayerBar(); + } else if (game_mode&GAME_EDIT) drawEditScene(); SDL_Flip(screen); SDL_Surface* tmp = SDL_CreateRGBSurface ( @@ -386,3 +410,15 @@ menubg=NULL; } } + +const SDL_Rect& GraphicsEngine::addShift(Sint16 shiftx, Sint16 shifty) { + shift.x+=shiftx; + shift.y+=shifty; + return shift; +} + +const SDL_Rect& GraphicsEngine::setShift(Sint16 shiftx, Sint16 shifty) { + shift.x=shiftx; + shift.y=shifty; + return shift; +} Modified: trunk/src/gfxeng.h =================================================================== --- trunk/src/gfxeng.h 2005-06-18 15:49:04 UTC (rev 119) +++ trunk/src/gfxeng.h 2005-06-18 22:47:14 UTC (rev 120) @@ -30,6 +30,8 @@ void toggleFPS(); void toggleFullScreen(); void setMenuBG(SDL_Surface* menu_background=NULL); + const SDL_Rect& addShift(Sint16,Sint16); + const SDL_Rect& setShift(Sint16,Sint16); protected: const Uint32 rmask; const Uint32 gmask; @@ -53,10 +55,15 @@ 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 Modified: trunk/src/input.cpp =================================================================== --- trunk/src/input.cpp 2005-06-18 15:49:04 UTC (rev 119) +++ trunk/src/input.cpp 2005-06-18 22:47:14 UTC (rev 120) @@ -34,6 +34,8 @@ pollPausedEvents(); } else if (game_mode&GAME_PLAY) { pollGameEvents(); + } else if (game_mode&GAME_EDIT) { + pollEditEvents(); } else { } } @@ -174,3 +176,49 @@ } keystate = SDL_GetKeyState(NULL); } + +inline void InputHandler::pollEditEvents() { + for (Uint16 i=0; iresize(event.resize.w, event.resize.h); + break; + } + // keyboard events + case SDL_QUIT: { + quitGame(0); + } + case SDL_KEYDOWN: { + SDLKey key=event.key.keysym.sym; + keypressed[key]=true; + if (key==config.keybind[KEY_FULL]) { + gfxeng->toggleFullScreen(); + } else if (key==config.keybind[KEY_MENU]) { + sfxeng->pauseMusic(); + setMenu(new EditMenu()); + gfxeng->update(UPDATE_ALL); + } else if (key==config.keybind[KEY_QUIT]) { + quitGame(0); + } + break; + } + default: { + break; + } + } + } + keystate = SDL_GetKeyState(NULL); + if (keyState(KEY_LEFT)) { + gfxeng->addShift(-1,0); + } else if (keyState(KEY_RIGHT)) { + gfxeng->addShift(1,0); + } else if (keyState(KEY_UP)) { + gfxeng->addShift(0,-1); + } else if (keyState(KEY_DOWN)) { + gfxeng->addShift(0,1); + } +} Modified: trunk/src/input.h =================================================================== --- trunk/src/input.h 2005-06-18 15:49:04 UTC (rev 119) +++ trunk/src/input.h 2005-06-18 22:47:14 UTC (rev 120) @@ -28,6 +28,8 @@ inline void pollPausedEvents(); /// Check for keyboard events in menu inline void pollMenuEvents(); + /// Check for keyboard events in editing mode + inline void pollEditEvents(); }; #endif Modified: trunk/src/lost_penguins.cpp =================================================================== --- trunk/src/lost_penguins.cpp 2005-06-18 15:49:04 UTC (rev 119) +++ trunk/src/lost_penguins.cpp 2005-06-18 22:47:14 UTC (rev 120) @@ -55,7 +55,7 @@ while (true) { input->update(); - if (game_mode&GAME_PLAY) scenario->physic->update(); + scenario->physic->update(); gfxeng->draw(); } @@ -135,8 +135,9 @@ config.height=atoi(arg1.c_str()); } else if (option=="bpp") { config.bpp=atoi(arg1.c_str()); - } else if (option=="full" && arg1=="1") { - config.full=true; + } else if (option=="full") { + if (arg1=="1") config.full=true; + else config.full=false; } else if (option=="map") { config.map=arg1; //TODO: add keybindings Modified: trunk/src/menu.cpp =================================================================== --- trunk/src/menu.cpp 2005-06-18 15:49:04 UTC (rev 119) +++ trunk/src/menu.cpp 2005-06-18 22:47:14 UTC (rev 120) @@ -56,7 +56,7 @@ StartMenu::StartMenu(): Menu() { title="-== MAIN MENU ==-"; - entries.resize(4); + entries.resize(5); update(); } void StartMenu::act() { @@ -72,14 +72,25 @@ break; } case 1: { + //Add a proper Map creation menu, etc..., FIXME + if ((config.map!="") && (scenario->loadMap(config.map)==0)) { + closeMenu(); + game_mode|=GAME_EDIT; + cout << "Starting game...\n" << endl; + } else { + cout << "Select a valid map first...\n" << endl; + } + break; + } + case 2: { setMenu(new MapMenu()); break; } - case 2: { + case 3: { setMenu(new ConfigMenu()); break; } - case 3: { + case 4: { quitGame(0); break; } @@ -90,9 +101,10 @@ } void StartMenu::update() { entries[0]="Start Game"; - entries[1]="Map selection"; - entries[2]="Configuration"; - entries[3]="Quit"; + entries[1]="Edit Map"; + entries[2]="Map selection"; + entries[3]="Configuration"; + entries[4]="Quit"; } @@ -130,6 +142,40 @@ } +EditMenu::EditMenu(): Menu() { + title="-== EDIT MENU ==-"; + entries.resize(3); + update(); +} +void EditMenu::act() { + switch (currententry) { + case 0: { + if (!closeMenu()) { + gfxeng->update(UPDATE_ALL); + sfxeng->resumeMusic(); + } + break; + } + case 1: { + setMenu(new ConfigMenu()); + break; + } + case 2: { + quitGame(0); + break; + } + default: { + break; + } + } +} +void EditMenu::update() { + entries[0]="Resume"; + entries[1]="Configuration"; + entries[2]="Quit"; +} + + MapMenu::MapMenu(): Menu() { title="-== MAP SELECTION ==-"; //TODO: add common entries, check directory for map files, entries.push_back(name); Modified: trunk/src/menu.h =================================================================== --- trunk/src/menu.h 2005-06-18 15:49:04 UTC (rev 119) +++ trunk/src/menu.h 2005-06-18 22:47:14 UTC (rev 120) @@ -60,6 +60,15 @@ void update(); }; +class EditMenu : public Menu { + public: + EditMenu(); + virtual void act(); + private: + /// Helper function + void update(); +}; + class MapMenu : public Menu { public: MapMenu(); Modified: trunk/src/objects/olaf.cpp =================================================================== --- trunk/src/objects/olaf.cpp 2005-06-18 15:49:04 UTC (rev 119) +++ trunk/src/objects/olaf.cpp 2005-06-18 22:47:14 UTC (rev 120) @@ -161,7 +161,6 @@ else if (!(state&STATE_FALL)) { setState(STATE_ACT_2); } - //Can't fart anymore if (state&STATE_ACT_1) { //Fart Modified: trunk/src/physics.cpp =================================================================== --- trunk/src/physics.cpp 2005-06-18 15:49:04 UTC (rev 119) +++ trunk/src/physics.cpp 2005-06-18 22:47:14 UTC (rev 120) @@ -38,6 +38,15 @@ reset_time=false; tcurrent=SDL_GetTicks(); updateGame(); + } else if (game_mode&GAME_EDIT) { + if (reset_time) { + dt=0; + } else { + dt=(SDL_GetTicks()-tcurrent); + } + reset_time=false; + tcurrent=SDL_GetTicks(); + updateEdit(); } else { } } @@ -108,6 +117,38 @@ } } +inline void PhysicHandler::updateEdit() { + object_iterator obit=scenario->pool->objectspool.begin(); + while (obit!=scenario->pool->objectspool.end()) { + //remove marked objects + if ((*obit)->isDeleted()) { + obit=scenario->pool->removeObject(*obit); + } else ++obit; + } + obit=scenario->pool->objectspool.begin(); + while (obit!=scenario->pool->objectspool.end()) { + (*obit)->idle(dt); + (*obit)->updateEvents(dt); + ++obit; + } + //run end scenario->player effects + character_iterator cit=scenario->pool->characterspool.begin(); + while (cit!=scenario->pool->characterspool.end()) { + (*cit)->fall(dt); + (*cit)->updateAnimState(!((*cit)->getState(ESTATE_ANIM))); + ++cit; + } + //update the animations of all objects + obit=scenario->pool->objectspool.begin(); + while (obit!=scenario->pool->objectspool.end()) { + if ((*obit)->getState(ESTATE_ANIM)) { + bool runs=(*obit)->updateAnim(dt); + if (!runs) (*obit)->stopEvent(); + } else if ((*obit)->isRunning()) (*obit)->updateAnim(dt); + ++obit; + } +} + inline void PhysicHandler::updatePaused() { if (input->keyPressed(KEY_RIGHT)) { scenario->player->switchItem(true); Modified: trunk/src/physics.h =================================================================== --- trunk/src/physics.h 2005-06-18 15:49:04 UTC (rev 119) +++ trunk/src/physics.h 2005-06-18 22:47:14 UTC (rev 120) @@ -22,6 +22,7 @@ Uint16 Dfps,Dframes,currentfps,minfps; private: inline void updateGame(); + inline void updateEdit(); inline void updatePaused(); inline void updateFPS(); }; Modified: trunk/src/sfxeng.cpp =================================================================== --- trunk/src/sfxeng.cpp 2005-06-18 15:49:04 UTC (rev 119) +++ trunk/src/sfxeng.cpp 2005-06-18 22:47:14 UTC (rev 120) @@ -5,7 +5,7 @@ SoundsEngine::SoundsEngine() { #ifdef SDL_MIXER /* Open the audio device */ - if (Mix_OpenAudio(config.audio_rate, config.audio_format, config.audio_channels, 512) < 0) { + if (Mix_OpenAudio(config.audio_rate, config.audio_format, config.audio_channels, 256) < 0) { cout << "Couldn't open audio: " << SDL_GetError() << endl; cout << "Audio disabled!\n"; disabled=true; @@ -32,7 +32,7 @@ if (theme) Mix_FreeMusic(theme); theme = Mix_LoadMUS(name.c_str()); Mix_FadeInMusic(theme, -1, 5000); - Mix_VolumeMusic(MIX_MAX_VOLUME/4); + Mix_VolumeMusic(MIX_MAX_VOLUME/2); } #endif }