From DONOTREPLY at icculus.org Tue Feb 1 08:33:04 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 1 Feb 2005 08:33:04 -0500 Subject: r79 - in trunk/src: . objects Message-ID: <20050201133304.20657.qmail@icculus.org> Author: jonas Date: 2005-02-01 08:33:04 -0500 (Tue, 01 Feb 2005) New Revision: 79 Modified: trunk/src/characters_common.cpp trunk/src/characters_common.h trunk/src/events.cpp trunk/src/events.h trunk/src/objects/erik.cpp trunk/src/objects/fang.cpp trunk/src/objects/olaf.cpp trunk/src/objects/scorch.cpp trunk/src/objects/water.cpp trunk/src/objects/zombie.cpp trunk/src/players_common.cpp Log: Changed the horizontal speed management to be similar to the vertical: - Introduced a horizontal inert mass - Introduced a constant horizontal air resistance - Removed all occurencies of Speed modifiers, increased/decreased the maximal horizonzal speed instead - simplified (or removed) Speed/Run events - tweaked ?\209?\155ome speed settings for zombies and olaf (small) Modified: trunk/src/characters_common.cpp =================================================================== --- trunk/src/characters_common.cpp 2005-01-31 19:16:29 UTC (rev 78) +++ trunk/src/characters_common.cpp 2005-02-01 13:33:04 UTC (rev 79) @@ -16,7 +16,6 @@ hspeed(0), speed(0), gravity(900), - speedmod(100), Dgrav(0), im_die(NULL), dense_types(NOTHING), @@ -86,8 +85,8 @@ Hit Character::move(Uint16 dt, bool check) { SDL_Rect dest=pos; - dest.x+=Sint16((hspeed*speedmod*dt)/100000); - dest.y+=Sint16((speed*speedmod*dt)/100000); + dest.x+=Sint16((hspeed*dt)/1000); + dest.y+=Sint16((speed*dt)/1000); Hit hit=checkMove(dest,check); Modified: trunk/src/characters_common.h =================================================================== --- trunk/src/characters_common.h 2005-01-31 19:16:29 UTC (rev 78) +++ trunk/src/characters_common.h 2005-02-01 13:33:04 UTC (rev 79) @@ -9,6 +9,7 @@ #define V_KRIT 1000 #define T_GRAV_EFFECT 10 #define T_AI_EFFECT 20 +#define SPEED_STEP 10 //Character states //facing: either left or right (not left) @@ -60,11 +61,11 @@ } //@} //@{ - void applySpeedMod(Uint16 speedm) { - speedmod=Uint16(speedmod*speedm/100); + Uint16 addMaxSpeed(Sint16 dmax) { + return maxspeedx=max(0,maxspeedx+dmax); } - void setSpeedMod(Uint16 speedm) { - speedmod=speedm; + Uint16 setMaxSpeed(Uint16 maxs) { + return maxspeedx=maxs; } //@} //@{ @@ -165,8 +166,6 @@ Sint16 speed; //current gravity Sint16 gravity; - //current speedmod - Uint16 speedmod; //temporary attributes Sint16 Dgrav; //Die animation Modified: trunk/src/events.cpp =================================================================== --- trunk/src/events.cpp 2005-01-31 19:16:29 UTC (rev 78) +++ trunk/src/events.cpp 2005-02-01 13:33:04 UTC (rev 79) @@ -124,37 +124,32 @@ CEvent::cancel(); } -ESpeed::ESpeed(Character* chr, Uint16 length, Sint16 avspeed, Sint16 ahspeed, Uint16 edelay, Uint32 switchstate, Mix_Chunk* esound, Animation* runanim, bool delanim): - CAnimEvent(chr,length,edelay,switchstate,esound,runanim,delanim), - vspeed(avspeed), - hspeed(ahspeed) { } -void ESpeed::start() { - charowner->addSpeed(vspeed); - charowner->addHSpeed(hspeed); - CAnimEvent::start(); -} -void ESpeed::end() { - if (started) charowner->addHSpeed(-hspeed); - CAnimEvent::end(); -} -void ESpeed::cancel() { - if (started) charowner->addHSpeed(-hspeed); - CAnimEvent::cancel(); -} - -ERun::ERun(Character* chr, Uint16 length, Sint16 inispeed, Sint16 ahspeed, Uint16 edelay, Uint32 switchstate, Mix_Chunk* esound, Animation* runanim, bool delanim): - ESpeed(chr,length,0,ahspeed,edelay,(switchstate|STATE_PRESS_LR),esound,runanim,delanim), - ispeed(inispeed), +ERun::ERun(Character* chr, Uint16 length, Sint16 edmax, Uint16 edelay, Uint32 switchstate, Mix_Chunk* esound, Animation* runanim, bool delanim): + CAnimEvent(chr,length,edelay,(switchstate|STATE_PRESS_LR),esound,runanim,delanim), + dmax(edmax), t_reset(0) { charowner->setState(STATE_RUN); - charowner->addHSpeed(ispeed); } ERun::~ERun() { charowner->unsetState(STATE_RUN); - charowner->addHSpeed(-ispeed); owner->clearEvents(); } +void ERun::start() { + charowner->addMaxSpeed(dmax); + CAnimEvent::start(); +} + +void ERun::end() { + if (started) charowner->addMaxSpeed(-dmax); + CAnimEvent::end(); +} + +void ERun::cancel() { + if (started) charowner->addMaxSpeed(-dmax); + CAnimEvent::cancel(); +} + void ERun::reset() { t_reset=0; } @@ -164,7 +159,7 @@ if (t_reset>100) { evstate=EV_CANCEL; } else { - evstate=ESpeed::update(dt); + evstate=CAnimEvent::update(dt); } return evstate; } Modified: trunk/src/events.h =================================================================== --- trunk/src/events.h 2005-01-31 19:16:29 UTC (rev 78) +++ trunk/src/events.h 2005-02-01 13:33:04 UTC (rev 79) @@ -113,43 +113,28 @@ Uint16 mask; }; -/** \brief Speed modification event - - Modifies the vertical and/or the horizontal speed. -*/ -class ESpeed : public CAnimEvent { - public: - /// \param avspeed Vertical speed to be add when the event starts - /// \param ahspeed Horizontal speed to be add when the event starts - ESpeed(Character* chr, Uint16 length, Sint16 avspeed, Sint16 ahspeed=0, Uint16 edelay=0, - Uint32 switchstate=0, Mix_Chunk* esound=NULL, Animation* runanim=NULL, bool delanim=false); - virtual void start(); - virtual void end(); - virtual void cancel(); - protected: - Sint16 vspeed; - Sint16 hspeed; -}; - /** \brief Delayed (accelerated) run event A special speed event that increases the horizontal speed after a while, has to be constantly maintained using reset(). */ -class ERun : public ESpeed { +class ERun : public CAnimEvent { public: /// Adds the initial speed /// \param inispeed Initial horizontal speed to be added /// \param ahspeed Horizontal speed to be added when the event starts - ERun(Character* chr, Uint16 length, Sint16 inispeed, Sint16 ahspeed, Uint16 edelay=0, + ERun(Character* chr, Uint16 length, Sint16 edmax, Uint16 edelay=0, Uint32 switchstate=0, Mix_Chunk* esound=NULL, Animation* runanim=NULL, bool delanim=false); virtual ~ERun(); /// Forces the event to continue + virtual void start(); + virtual void end(); + virtual void cancel(); virtual void reset(); /// If the event wasn't forced to continue it will shortly end virtual Uint16 update(Uint16 dt); protected: - Sint16 ispeed; + Sint16 dmax; Sint16 t_reset; }; Modified: trunk/src/objects/erik.cpp =================================================================== --- trunk/src/objects/erik.cpp 2005-01-31 19:16:29 UTC (rev 78) +++ trunk/src/objects/erik.cpp 2005-02-01 13:33:04 UTC (rev 79) @@ -46,10 +46,12 @@ if (state&STATE_ACT_2) { } else if (state&STATE_ACT_1) { setState(STATE_ACT_2); - setEvent(new ESpeed(this,DE_JUMP,jump2,0,0,0,au_jump)); + addSpeed(jump2); + setEvent(new CAnimEvent(this,DE_JUMP,0,0,au_jump)); } else { setState(STATE_ACT_1); - setEvent(new ESpeed(this,DE_JUMP,jump)); + addSpeed(jump); + setEvent(new CAnimEvent(this,DE_JUMP)); } } @@ -61,15 +63,11 @@ if (state&STATE_RUN) cancelEvent(); return; } - dense_types|=OTYPE_MONSTER; if (state&STATE_RUN) { + dense_types|=OTYPE_MONSTER; if (state&STATE_FALL) cancelEvent(); - } else if (state&STATE_MLEFT) { - sfxeng->playWAV(au_run); - setEvent(new ERun(this,10000,Sint16(-1/2*maxspeedx),-maxspeedx,500,ESTATE_ABORT,au_run)); - } else if (state&STATE_MRIGHT) { - sfxeng->playWAV(au_run); - setEvent(new ERun(this,10000,Sint16(1/2*maxspeedx),maxspeedx,500,ESTATE_ABORT,au_run)); + } else if (state&(STATE_MLEFT|STATE_MRIGHT)) { + setEvent(new ERun(this,10000,maxspeedx,500,ESTATE_ABORT,au_run)); } } Modified: trunk/src/objects/fang.cpp =================================================================== --- trunk/src/objects/fang.cpp 2005-01-31 19:16:29 UTC (rev 78) +++ trunk/src/objects/fang.cpp 2005-02-01 13:33:04 UTC (rev 79) @@ -48,6 +48,10 @@ } void Fang::fall(Uint16 dt) { + if (!getState(STATE_MRIGHT|STATE_MLEFT)) { + if (!getState(STATE_FALL)) hspeed*=0.9; + else hspeed*=0.96; + } Dgrav+=dt; if (Dgrav>T_GRAV_EFFECT) { if (state&STATE_FALL) { @@ -74,15 +78,20 @@ unsetState(STATE_LEFT); unsetState(STATE_CLIMB_L); setState(STATE_ACT_1); - setEvent(new ESpeed(this,T_JUMPOFF,V_JUMPOFF,Sint16(maxspeedx*1.5),0,0,au_jump)); + addSpeed(V_JUMPOFF); + addHSpeed(maxspeedx); + setEvent(new CAnimEvent(this,T_JUMPOFF,0,0,au_jump)); } else if (state&STATE_CLIMB_R) { setState(STATE_LEFT); unsetState(STATE_CLIMB_R); setState(STATE_ACT_1); - setEvent(new ESpeed(this,T_JUMPOFF,V_JUMPOFF,Sint16(-maxspeedx*1.5),0,0,au_jump)); + addSpeed(V_JUMPOFF); + addHSpeed(-maxspeedx); + setEvent(new CAnimEvent(this,T_JUMPOFF,0,0,au_jump)); } else if ((!(state&STATE_FALL)) && (!(state&STATE_ACT_1))){ setState(STATE_ACT_1); - setEvent(new ESpeed(this,DE_JUMP,V_JUMP,0,0,0,au_jump)); + addSpeed(V_JUMP); + setEvent(new CAnimEvent(this,DE_JUMP,0,0,au_jump)); } } Modified: trunk/src/objects/olaf.cpp =================================================================== --- trunk/src/objects/olaf.cpp 2005-01-31 19:16:29 UTC (rev 78) +++ trunk/src/objects/olaf.cpp 2005-02-01 13:33:04 UTC (rev 79) @@ -124,11 +124,11 @@ //as we don't fall most states are off anyway unsetState(STATE_SHIELD); setState(STATE_SMALL); - maxspeedx/=4; + addMaxSpeed(-200); } else { sfxeng->playWAV(au_big); unsetState(STATE_SMALL); - maxspeedx*=4; + addMaxSpeed(200); } return true; } else return false; @@ -174,12 +174,17 @@ //Fart } else { setState(STATE_ACT_1); - setEvent(new ESpeed(this,DE_JUMP,fart,0,0,0,au_fart)); + addSpeed(fart); + setEvent(new CAnimEvent(this,DE_JUMP,0,0,au_fart)); } } } void Olaf::fall(Uint16 dt) { + if (!getState(STATE_MRIGHT|STATE_MLEFT)) { + if (!getState(STATE_FALL)) hspeed*=0.9; + else hspeed*=0.96; + } Dgrav+=dt; if (Dgrav>T_GRAV_EFFECT) { if (state&STATE_FALL) { Modified: trunk/src/objects/scorch.cpp =================================================================== --- trunk/src/objects/scorch.cpp 2005-01-31 19:16:29 UTC (rev 78) +++ trunk/src/objects/scorch.cpp 2005-02-01 13:33:04 UTC (rev 79) @@ -35,6 +35,10 @@ } void Scorch::fall(Uint16 dt) { + if (!getState(STATE_MRIGHT|STATE_MLEFT)) { + if (!getState(STATE_FALL)) hspeed*=0.9; + else hspeed*=0.96; + } Dgrav+=dt; if (Dgrav>T_GRAV_EFFECT) { if (state&STATE_FALL) { @@ -65,12 +69,14 @@ setState(STATE_ACT_1); setState(STATE_ACT_2); unsetState(STATE_GLIDE); - setEvent(new ESpeed(this,DE_WING,V_FLY,0,0,0,au_tired)); + addSpeed(V_FLY); + setEvent(new CAnimEvent(this,DE_WING,0,0,au_tired)); //Use Wings } else { setState(STATE_ACT_1); left_wings--; - setEvent(new ESpeed(this,DE_WING,V_FLY,0,0,0,au_swing)); + addSpeed(V_FLY); + setEvent(new CAnimEvent(this,DE_WING,0,0,au_swing)); } } Modified: trunk/src/objects/water.cpp =================================================================== --- trunk/src/objects/water.cpp 2005-01-31 19:16:29 UTC (rev 78) +++ trunk/src/objects/water.cpp 2005-02-01 13:33:04 UTC (rev 79) @@ -19,7 +19,7 @@ if(Character* ptr = dynamic_cast(obj)) { sfxeng->playWAV(au_water); ptr->setState(STATE_WATER); - ptr->applySpeedMod(50); + ptr->addMaxSpeed(-200); ptr->hit(DIR_ALL,weapon); } } @@ -27,7 +27,7 @@ void Water::leave(Object* obj) { if(Character* ptr = dynamic_cast(obj)) { sfxeng->playWAV(au_water); - ptr->applySpeedMod(200); + ptr->addMaxSpeed(200); ptr->unsetState(STATE_WATER); } } Modified: trunk/src/objects/zombie.cpp =================================================================== --- trunk/src/objects/zombie.cpp 2005-01-31 19:16:29 UTC (rev 78) +++ trunk/src/objects/zombie.cpp 2005-02-01 13:33:04 UTC (rev 79) @@ -14,7 +14,7 @@ Monster(imagename,xcord,ycord,mname), au_attack(sndcache->loadWAV("clang.wav")), T_Attack_Bite(1500) { - maxspeedx=100; + maxspeedx=80; im_left=new Animation(imgcache->loadImage("olaf1_left.bmp"),2,1000); im_right=new Animation(imgcache->loadImage("olaf1_right.bmp"),2,1000); weapon=Weapon(-1,W_STRIKE); @@ -26,14 +26,14 @@ } void Zombie::idle(Uint16 dt) { - hspeed=0; Character::idle(dt); runAI(dt); } void Zombie::ai_left(Uint16 dt) { SDL_Rect oldpos=pos; - hspeed-=maxspeedx; + if ((hspeed-SPEED_STEP)>maxspeedx) hspeed-=SPEED_STEP; + else if (hspeed>(-maxspeedx)) hspeed=-maxspeedx; Hit hit=move(dt,true); if (hit.touch&enemy_types) { move(dt); @@ -52,7 +52,8 @@ void Zombie::ai_right(Uint16 dt) { SDL_Rect oldpos=pos; - hspeed+=maxspeedx; + if ((hspeed+SPEED_STEP)(-maxspeedx)) hspeed-=SPEED_STEP; + else if (hspeed>(-maxspeedx)) hspeed=-maxspeedx; } void Player::in_up(Sint16) { } void Player::in_down(Sint16) { } @@ -236,6 +228,10 @@ } void Player::fall(Uint16 dt) { + if (!getState(STATE_MRIGHT|STATE_MLEFT)) { + if (!getState(STATE_FALL)) hspeed*=0.9; + else hspeed*=0.96; + } Character::fall(dt); } @@ -358,8 +354,15 @@ case W_TOUCH: { //TODO: play animations (make new Event for this) if (direction&(DIR_UP|DIR_DOWN)) sfxeng->playWAV(aud_hit); - if (direction&DIR_LEFT) setEvent(new ESpeed(this,TSTRIKE,-200,-400,0,ESTATE_BUSY,aud_hit)); - else setEvent(new ESpeed(this,TSTRIKE,-200,400,0,ESTATE_BUSY,aud_hit)); + if (direction&DIR_LEFT) { + addSpeed(-200); + addHSpeed(-400); + setEvent(new CAnimEvent(this,TSTRIKE,0,ESTATE_BUSY,aud_hit)); + } else { + addSpeed(-200); + addHSpeed(400); + setEvent(new CAnimEvent(this,TSTRIKE,0,ESTATE_BUSY,aud_hit)); + } break; } case W_WATER: { From DONOTREPLY at icculus.org Tue Feb 1 13:55:46 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 1 Feb 2005 13:55:46 -0500 Subject: r80 - trunk/src Message-ID: <20050201185546.16445.qmail@icculus.org> Author: jonas Date: 2005-02-01 13:55:46 -0500 (Tue, 01 Feb 2005) New Revision: 80 Modified: trunk/src/objects_common.cpp trunk/src/objects_common.h Log: moved setPos out of the header files Modified: trunk/src/objects_common.cpp =================================================================== --- trunk/src/objects_common.cpp 2005-02-01 13:33:04 UTC (rev 79) +++ trunk/src/objects_common.cpp 2005-02-01 18:55:46 UTC (rev 80) @@ -40,6 +40,23 @@ } } +bool Object::setPos(Sint16 xcord,Sint16 ycord) { + bool ok=true; + //Did we hit a maparea? + if (xcord < 0) { + pos.x=0; + ok=false; + } else if (xcord > (maparea->w-pos.w)) { + pos.x=maparea->w-pos.w; + ok=false; + } else pos.x=xcord; + if (ycord>(maparea->h-pos.h)) { + pos.y=maparea->h-pos.h; + ok=false; + } else pos.y=ycord; + return ok; +} + const Frame& Object::getFrame() const { return animation->getFrame(); } Modified: trunk/src/objects_common.h =================================================================== --- trunk/src/objects_common.h 2005-02-01 13:33:04 UTC (rev 79) +++ trunk/src/objects_common.h 2005-02-01 18:55:46 UTC (rev 80) @@ -41,24 +41,7 @@ /// Sets the new position. If the coordinates are not in the map area /// they are corrected to fit into it. /// \return True if no correction was needed - bool setPos(Sint16 xcord,Sint16 ycord) { - bool ok=true; - //Did we hit a maparea? - if (xcord < 0) { - pos.x=0; - ok=false; - } else if (xcord > (maparea->w-pos.w)) { - pos.x=maparea->w-pos.w; - ok=false; - } else pos.x=xcord; - - if (ycord>(maparea->h-pos.h)) { - pos.y=maparea->h-pos.h; - ok=false; - } else pos.y=ycord; - - return ok; - } + bool setPos(Sint16 xcord,Sint16 ycord); /// \brief Returns the center of an object /// \return Center position of the object with width=height=0 SDL_Rect getCenter() { From DONOTREPLY at icculus.org Wed Feb 2 12:40:44 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 2 Feb 2005 12:40:44 -0500 Subject: r81 - trunk/src Message-ID: <20050202174044.27027.qmail@icculus.org> Author: jonas Date: 2005-02-02 12:40:44 -0500 (Wed, 02 Feb 2005) New Revision: 81 Modified: trunk/src/characters_common.h Log: reduce speed when changing the maximal speed Modified: trunk/src/characters_common.h =================================================================== --- trunk/src/characters_common.h 2005-02-01 18:55:46 UTC (rev 80) +++ trunk/src/characters_common.h 2005-02-02 17:40:44 UTC (rev 81) @@ -62,10 +62,16 @@ //@} //@{ Uint16 addMaxSpeed(Sint16 dmax) { - return maxspeedx=max(0,maxspeedx+dmax); + maxspeedx=max(0,maxspeedx+dmax); + if (hspeed>maxspeedx) hspeed=maxspeedx; + if (hspeed<-maxspeedx) hspeed=-maxspeedx; + return maxspeedx; } Uint16 setMaxSpeed(Uint16 maxs) { - return maxspeedx=maxs; + maxspeedx=maxs; + if (hspeed>maxspeedx) hspeed=maxspeedx; + if (hspeed<-maxspeedx) hspeed=-maxspeedx; + return maxspeedx; } //@} //@{ From DONOTREPLY at icculus.org Wed Feb 2 15:27:44 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 2 Feb 2005 15:27:44 -0500 Subject: r82 - in trunk: . src src/objects Message-ID: <20050202202744.10474.qmail@icculus.org> Author: jonas Date: 2005-02-02 15:27:43 -0500 (Wed, 02 Feb 2005) New Revision: 82 Modified: trunk/TODO trunk/src/characters_common.h trunk/src/common.cpp trunk/src/common.h trunk/src/objects/fang.cpp trunk/src/objects/olaf.cpp trunk/src/objects/scorch.cpp trunk/src/objects/zombie.cpp trunk/src/players_common.cpp Log: - Made the air resistance less frame rate dependant - Introduced a helper function boost that increases resp. decreases the absolute value of an integer (used for air resistance) Modified: trunk/TODO =================================================================== --- trunk/TODO 2005-02-02 17:40:44 UTC (rev 81) +++ trunk/TODO 2005-02-02 20:27:43 UTC (rev 82) @@ -1,6 +1,6 @@ Bugs ==== - o rewrite zombie (attacks too often, use events, etc...) + o rewrite zombie (bug in movement!, attacks too often, use events, etc...) o memleaks, segfaults? @@ -15,7 +15,7 @@ This would help in many ways and should be a frame information and not an image as done for players atm! - o Fall/push/crash/collisions: + 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 Modified: trunk/src/characters_common.h =================================================================== --- trunk/src/characters_common.h 2005-02-02 17:40:44 UTC (rev 81) +++ trunk/src/characters_common.h 2005-02-02 20:27:43 UTC (rev 82) @@ -9,7 +9,7 @@ #define V_KRIT 1000 #define T_GRAV_EFFECT 10 #define T_AI_EFFECT 20 -#define SPEED_STEP 10 +#define HSPEED_MULT 100 //Character states //facing: either left or right (not left) Modified: trunk/src/common.cpp =================================================================== --- trunk/src/common.cpp 2005-02-02 17:40:44 UTC (rev 81) +++ trunk/src/common.cpp 2005-02-02 20:27:43 UTC (rev 82) @@ -22,3 +22,9 @@ s << i; return s.str(); } + +int boost(int a, int b) { + if (a>=0) return a=max(0,a+b); + else return a=min(0,a-b); +} + Modified: trunk/src/common.h =================================================================== --- trunk/src/common.h 2005-02-02 17:40:44 UTC (rev 81) +++ trunk/src/common.h 2005-02-02 20:27:43 UTC (rev 82) @@ -108,6 +108,8 @@ void usage(); /// Helper function that converts an integer to a string string itos(int); +/// Helper function boost that increases/decreases the absolute value +int boost(int,int); //@} //global variables Modified: trunk/src/objects/fang.cpp =================================================================== --- trunk/src/objects/fang.cpp 2005-02-02 17:40:44 UTC (rev 81) +++ trunk/src/objects/fang.cpp 2005-02-02 20:27:43 UTC (rev 82) @@ -49,8 +49,8 @@ void Fang::fall(Uint16 dt) { if (!getState(STATE_MRIGHT|STATE_MLEFT)) { - if (!getState(STATE_FALL)) hspeed*=0.9; - else hspeed*=0.96; + if (!getState(STATE_FALL)) hspeed=boost(hspeed,-dt*HSPEED_MULT/100); + else hspeed=boost(hspeed,-dt*HSPEED_MULT/200); } Dgrav+=dt; if (Dgrav>T_GRAV_EFFECT) { Modified: trunk/src/objects/olaf.cpp =================================================================== --- trunk/src/objects/olaf.cpp 2005-02-02 17:40:44 UTC (rev 81) +++ trunk/src/objects/olaf.cpp 2005-02-02 20:27:43 UTC (rev 82) @@ -182,8 +182,8 @@ void Olaf::fall(Uint16 dt) { if (!getState(STATE_MRIGHT|STATE_MLEFT)) { - if (!getState(STATE_FALL)) hspeed*=0.9; - else hspeed*=0.96; + if (!getState(STATE_FALL)) hspeed=boost(hspeed,-dt*HSPEED_MULT/100); + else hspeed=boost(hspeed,-dt*HSPEED_MULT/200); } Dgrav+=dt; if (Dgrav>T_GRAV_EFFECT) { Modified: trunk/src/objects/scorch.cpp =================================================================== --- trunk/src/objects/scorch.cpp 2005-02-02 17:40:44 UTC (rev 81) +++ trunk/src/objects/scorch.cpp 2005-02-02 20:27:43 UTC (rev 82) @@ -36,8 +36,8 @@ void Scorch::fall(Uint16 dt) { if (!getState(STATE_MRIGHT|STATE_MLEFT)) { - if (!getState(STATE_FALL)) hspeed*=0.9; - else hspeed*=0.96; + if (!getState(STATE_FALL)) hspeed=boost(hspeed,-dt*HSPEED_MULT/100); + else hspeed=boost(hspeed,-dt*HSPEED_MULT/200); } Dgrav+=dt; if (Dgrav>T_GRAV_EFFECT) { Modified: trunk/src/objects/zombie.cpp =================================================================== --- trunk/src/objects/zombie.cpp 2005-02-02 17:40:44 UTC (rev 81) +++ trunk/src/objects/zombie.cpp 2005-02-02 20:27:43 UTC (rev 82) @@ -32,7 +32,7 @@ void Zombie::ai_left(Uint16 dt) { SDL_Rect oldpos=pos; - if ((hspeed-SPEED_STEP)>maxspeedx) hspeed-=SPEED_STEP; + if ((hspeed-HSPEED_MULT*dt/100)>(-maxspeedx)) hspeed-=HSPEED_MULT*dt/100; else if (hspeed>(-maxspeedx)) hspeed=-maxspeedx; Hit hit=move(dt,true); if (hit.touch&enemy_types) { @@ -52,7 +52,7 @@ void Zombie::ai_right(Uint16 dt) { SDL_Rect oldpos=pos; - if ((hspeed+SPEED_STEP)(-maxspeedx)) hspeed-=SPEED_STEP; + if ((hspeed-HSPEED_MULT*dt/100)>(-maxspeedx)) hspeed-=HSPEED_MULT*dt/100; else if (hspeed>(-maxspeedx)) hspeed=-maxspeedx; } void Player::in_up(Sint16) { } @@ -229,8 +229,8 @@ void Player::fall(Uint16 dt) { if (!getState(STATE_MRIGHT|STATE_MLEFT)) { - if (!getState(STATE_FALL)) hspeed*=0.9; - else hspeed*=0.96; + if (!getState(STATE_FALL)) hspeed=boost(hspeed,-dt*HSPEED_MULT/100); + else hspeed=boost(hspeed,-dt*HSPEED_MULT/200); } Character::fall(dt); } From DONOTREPLY at icculus.org Wed Feb 2 16:54:06 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 2 Feb 2005 16:54:06 -0500 Subject: r83 - in trunk: . src Message-ID: <20050202215406.17118.qmail@icculus.org> Author: jonas Date: 2005-02-02 16:54:06 -0500 (Wed, 02 Feb 2005) New Revision: 83 Modified: trunk/lost_penguins.conf trunk/src/common.h trunk/src/gfxeng.cpp trunk/src/lost_penguins.cpp Log: configurable color depth... Modified: trunk/lost_penguins.conf =================================================================== --- trunk/lost_penguins.conf 2005-02-02 20:27:43 UTC (rev 82) +++ trunk/lost_penguins.conf 2005-02-02 21:54:06 UTC (rev 83) @@ -4,3 +4,4 @@ full 1 width 1024 height 768 +bpp 32 \ No newline at end of file Modified: trunk/src/common.h =================================================================== --- trunk/src/common.h 2005-02-02 20:27:43 UTC (rev 82) +++ trunk/src/common.h 2005-02-02 21:54:06 UTC (rev 83) @@ -71,6 +71,7 @@ struct Config { Uint16 width; Uint16 height; + Uint8 bpp; bool full; Uint16 audio_format; int audio_rate; Modified: trunk/src/gfxeng.cpp =================================================================== --- trunk/src/gfxeng.cpp 2005-02-02 20:27:43 UTC (rev 82) +++ trunk/src/gfxeng.cpp 2005-02-02 21:54:06 UTC (rev 83) @@ -27,7 +27,7 @@ void GraphicsEngine::resize(Uint16 width, Uint16 height) { if (screen) SDL_FreeSurface(screen); - if ((screen=SDL_SetVideoMode(width,height,16,SDL_HWSURFACE|SDL_RESIZABLE|SDL_DOUBLEBUF|(fullscreen ? SDL_FULLSCREEN : 0))) != NULL) { + if ((screen=SDL_SetVideoMode(width,height,config.bpp,SDL_HWSURFACE|SDL_RESIZABLE|SDL_DOUBLEBUF|(fullscreen ? SDL_FULLSCREEN : 0))) != NULL) { } else { cout << "Couldn't set VideoMode: " << SDL_GetError() << endl; quitGame(-1); Modified: trunk/src/lost_penguins.cpp =================================================================== --- trunk/src/lost_penguins.cpp 2005-02-02 20:27:43 UTC (rev 82) +++ trunk/src/lost_penguins.cpp 2005-02-02 21:54:06 UTC (rev 83) @@ -95,6 +95,7 @@ //default values config.width=640; config.height=480; + config.bpp=16; config.full=false; config.audio_rate = MIX_DEFAULT_FREQUENCY; config.audio_format = MIX_DEFAULT_FORMAT; @@ -120,6 +121,8 @@ config.width=atoi(arg1.c_str()); } else if (option=="height") { 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=="map") { @@ -140,6 +143,9 @@ } else if ( strcmp(argv[i], "-height") == 0 || strcmp(argv[i], "-h") == 0) { config.height=atoi(argv[i+1]); i++; + } else if ( strcmp(argv[i], "-bpp") == 0 ) { + config.bpp=atoi(argv[i+1]); + i++; } else if ( strcmp(argv[i], "-full") == 0 || strcmp(argv[i], "-fs") == 0) { config.full=SDL_FULLSCREEN; } else if ( strcmp(argv[i], "-map") == 0 ) { @@ -154,10 +160,11 @@ void usage() { cout << "Usage: lost_penguins [OPTIONS]\n"; - cout << " -w, -width Changes resolution (width) of game. Default: 640\n"; - cout << " -h, -height Changes resolution (height) of game. Default: 480\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"; + 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 << " -map Load specified map from data dir. Default: map1\n"; + cout << " -h, --help Show this text \n"; quitGame(4); } From DONOTREPLY at icculus.org Thu Feb 3 10:43:28 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 3 Feb 2005 10:43:28 -0500 Subject: r84 - trunk/src Message-ID: <20050203154328.20672.qmail@icculus.org> Author: jonas Date: 2005-02-03 10:43:27 -0500 (Thu, 03 Feb 2005) New Revision: 84 Modified: trunk/src/monsters_common.cpp Log: monsters normally shouldn't be able to pass players... Modified: trunk/src/monsters_common.cpp =================================================================== --- trunk/src/monsters_common.cpp 2005-02-02 21:54:06 UTC (rev 83) +++ trunk/src/monsters_common.cpp 2005-02-03 15:43:27 UTC (rev 84) @@ -19,6 +19,7 @@ state=STATE_FALL; otype|=OTYPE_MONSTER; enemy_types|=OTYPE_PLAYER; + dense_types|=OTYPE_PLAYER; im_left=animation; im_right=animation; au_hit=sndcache->loadWAV("monhit.wav"); From DONOTREPLY at icculus.org Wed Feb 9 16:41:07 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 9 Feb 2005 16:41:07 -0500 Subject: r85 - in trunk: . src src/objects Message-ID: <20050209214107.2588.qmail@icculus.org> Author: jonas Date: 2005-02-09 16:41:07 -0500 (Wed, 09 Feb 2005) New Revision: 85 Modified: trunk/TODO trunk/src/anim.cpp trunk/src/characters_common.cpp trunk/src/common.cpp trunk/src/common.h trunk/src/events.cpp trunk/src/gfxeng.cpp trunk/src/gfxeng.h trunk/src/input.cpp trunk/src/lost_penguins.cpp trunk/src/map.cpp trunk/src/map.h trunk/src/monsters_common.cpp trunk/src/objectpools.cpp trunk/src/objectpools.h trunk/src/objects/baleog.cpp trunk/src/objects/bomb.cpp trunk/src/objects/door.cpp trunk/src/objects/erik.cpp trunk/src/objects/exit.cpp trunk/src/objects/fang.cpp trunk/src/objects/geyser.cpp trunk/src/objects/olaf.cpp trunk/src/objects/plant.cpp trunk/src/objects/scorch.cpp trunk/src/objects/spike.cpp trunk/src/objects/teleport.cpp trunk/src/objects/trigger.cpp trunk/src/objects/triggered_bomb.cpp trunk/src/objects/water.cpp trunk/src/objects/zombie.cpp trunk/src/objects_common.cpp trunk/src/players_common.cpp Log: Reorganized the map class: - Moved/Renamed the following global variables into the map class: maparea -> area, pool, player, background, anim, failed, *cache - Renamed Map to Scenario, curmap to scenario - Added (kept) global image/sound caches Modified: trunk/TODO =================================================================== --- trunk/TODO 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/TODO 2005-02-09 21:41:07 UTC (rev 85) @@ -14,6 +14,7 @@ o Idea: _all_ objects should have a "kore" 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 Move/Fall/push/crash/collisions: o the character should have more information what he hits Modified: trunk/src/anim.cpp =================================================================== --- trunk/src/anim.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/anim.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -3,6 +3,7 @@ #include "gfxeng.h" #include "objectpools.h" #include "players_common.h" +#include "map.h" #include "anim.h" @@ -88,61 +89,61 @@ if (!paused) { //released keys of player - if (player != NULL) { - if (input->getState(INPUTR_USE)) player->in_use(-1); + if (scenario->player != NULL) { + if (input->getState(INPUTR_USE)) scenario->player->in_use(-1); input->unsetState(INPUTR_USE); - if (input->getState(INPUTR_ACT)) player->in_act(-1); + if (input->getState(INPUTR_ACT)) scenario->player->in_act(-1); input->unsetState(INPUTR_ACT); - if (input->getState(INPUTR_RIGHT)) player->in_right(-1); + if (input->getState(INPUTR_RIGHT)) scenario->player->in_right(-1); input->unsetState(INPUTR_RIGHT); - if (input->getState(INPUTR_LEFT)) player->in_left(-1); + if (input->getState(INPUTR_LEFT)) scenario->player->in_left(-1); input->unsetState(INPUTR_LEFT); - if (input->getState(INPUTR_SP1)) player->in_sp1(-1); + if (input->getState(INPUTR_SP1)) scenario->player->in_sp1(-1); input->unsetState(INPUTR_SP1); - if (input->getState(INPUTR_SP2)) player->in_sp2(-1); + if (input->getState(INPUTR_SP2)) scenario->player->in_sp2(-1); input->unsetState(INPUTR_SP2); - if (input->getState(INPUTR_UP)) player->in_up(-1); + if (input->getState(INPUTR_UP)) scenario->player->in_up(-1); input->unsetState(INPUTR_UP); - if (input->getState(INPUTR_DOWN)) player->in_down(-1); + if (input->getState(INPUTR_DOWN)) scenario->player->in_down(-1); input->unsetState(INPUTR_DOWN); input->unsetState(INPUTR_DEL); } - object_iterator obit=pool->objectspool.begin(); - while (obit!=pool->objectspool.end()) { + object_iterator obit=scenario->pool->objectspool.begin(); + while (obit!=scenario->pool->objectspool.end()) { //remove marked objects if ((*obit)->isDeleted()) { - obit=pool->removeObject(*obit); + obit=scenario->pool->removeObject(*obit); } else ++obit; } - obit=pool->objectspool.begin(); - while (obit!=pool->objectspool.end()) { + obit=scenario->pool->objectspool.begin(); + while (obit!=scenario->pool->objectspool.end()) { (*obit)->idle(dt); (*obit)->updateEvents(dt); ++obit; } - //handle current (new) player - if ((player!=NULL) && (!(player->getState(ESTATE_BUSY)))) { - if (input->getState(INPUT_USE)) player->in_use(dt); - if (input->getState(INPUT_ACT)) player->in_act(dt); - if (input->getState(INPUT_RIGHT)) player->in_right(dt); - if (input->getState(INPUT_LEFT)) player->in_left(dt); - if ((!(player->getState(ESTATE_RUN)))||player->getState(ESTATE_ABORT)) { - if (input->getState(INPUT_SP1)) player->in_sp1(dt); - if (input->getState(INPUT_SP2)) player->in_sp2(dt); + //handle current (new) scenario->player + if ((scenario->player!=NULL) && (!(scenario->player->getState(ESTATE_BUSY)))) { + if (input->getState(INPUT_USE)) scenario->player->in_use(dt); + if (input->getState(INPUT_ACT)) scenario->player->in_act(dt); + if (input->getState(INPUT_RIGHT)) scenario->player->in_right(dt); + if (input->getState(INPUT_LEFT)) scenario->player->in_left(dt); + if ((!(scenario->player->getState(ESTATE_RUN)))||scenario->player->getState(ESTATE_ABORT)) { + if (input->getState(INPUT_SP1)) scenario->player->in_sp1(dt); + if (input->getState(INPUT_SP2)) scenario->player->in_sp2(dt); } - if (input->getState(INPUT_UP)) player->in_up(dt); - if (input->getState(INPUT_DOWN)) player->in_down(dt); + if (input->getState(INPUT_UP)) scenario->player->in_up(dt); + if (input->getState(INPUT_DOWN)) scenario->player->in_down(dt); } - //run end player effects - character_iterator cit=pool->characterspool.begin(); - while (cit!=pool->characterspool.end()) { + //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=pool->objectspool.begin(); - while (obit!=pool->objectspool.end()) { + 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(); @@ -152,15 +153,15 @@ } else { if (input->getState(INPUT_RIGHT)) { input->unsetState(INPUT_RIGHT); - player->switchItem(true); + scenario->player->switchItem(true); } if (input->getState(INPUT_LEFT)) { input->unsetState(INPUT_LEFT); - player->switchItem(false); + scenario->player->switchItem(false); } if (input->getState(INPUT_DEL)) { input->unsetState(INPUT_DEL); - player->dropItem(); + scenario->player->dropItem(); gfxeng->renderScene(true); } } Modified: trunk/src/characters_common.cpp =================================================================== --- trunk/src/characters_common.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/characters_common.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -142,8 +142,8 @@ void Character::die() { mark_delete(); - character_iterator cit=pool->characterspool.begin(); - while (cit != pool->characterspool.end()) { + character_iterator cit=scenario->pool->characterspool.begin(); + while (cit != scenario->pool->characterspool.end()) { (*cit)->removedObject(this); ++cit; } @@ -218,7 +218,7 @@ if (pos.x<(opos->x+opos->w)) hitdir.enter&=~DIR_LEFT; if (pos.y<(opos->y+opos->h)) hitdir.enter&=~DIR_UP; if ((pos.y+pos.h)>opos->y) hitdir.enter&=~DIR_DOWN; - hitdir.enter&=curmap->getDirection(pos,dest); + hitdir.enter&=scenario->getDirection(pos,dest); } //=== From this point on movement hit directions are set ===// @@ -258,8 +258,8 @@ std::set newenter; //Change destination based on enter hits on normal objects - object_iterator obit=pool->objectspool.begin(); - while (obit!=pool->objectspool.end()) { + object_iterator obit=scenario->pool->objectspool.begin(); + while (obit!=scenario->pool->objectspool.end()) { //blocked directions == movement direction in this case if (!((*obit)->isDeleted())) { opos=*((*obit)->getPos()); @@ -275,18 +275,18 @@ } //Check map boundary - hit=curmap->checkPlace(dest,(*maparea)); + hit=scenario->checkPlace(dest,(*scenario->area)); if (hit.enter&DIR_RIGHT) { colltype.enter|=DIR_RIGHT; colltype.touch|=DIR_RIGHT; - dest.x=maparea->x+maparea->w-dest.w; + dest.x=scenario->area->x+scenario->area->w-dest.w; } else if (hit.touch&DIR_RIGHT) { colltype.touch|=DIR_RIGHT; } if (hit.enter&DIR_LEFT) { colltype.enter|=DIR_LEFT; colltype.touch|=DIR_LEFT; - dest.x=maparea->x; + dest.x=scenario->area->x; } else if (hit.touch&DIR_LEFT) { colltype.touch|=DIR_LEFT; } @@ -294,7 +294,7 @@ if (hit.enter&DIR_DOWN) { colltype.enter|=DIR_DOWN; colltype.touch|=DIR_DOWN; - dest.y=maparea->y+maparea->h-dest.h; + dest.y=scenario->area->y+scenario->area->h-dest.h; } else if (hit.touch&DIR_DOWN) { colltype.touch|=DIR_DOWN; } @@ -302,8 +302,8 @@ //=== From this point on the new destination is calculated ===// //check touching - obit=pool->objectspool.begin(); - while (obit!=pool->objectspool.end()) { + obit=scenario->pool->objectspool.begin(); + while (obit!=scenario->pool->objectspool.end()) { //blocked directions == movement direction in this case if (!((*obit)->isDeleted())) { hit=checkHit(dest,(*obit)); Modified: trunk/src/common.cpp =================================================================== --- trunk/src/common.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/common.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -4,18 +4,12 @@ SoundCache* sndcache; GraphicsEngine* gfxeng; SoundsEngine* sfxeng; -ObjectsPool* pool; -Player* player; -Background* background; -Map* curmap; +Scenario* scenario; InputHandler* input; -AnimHandler* anim; Font* font; Font* font2; -SDL_Rect* maparea; Config config; bool paused=false; -bool failed=false; string itos(int i) { std::stringstream s; Modified: trunk/src/common.h =================================================================== --- trunk/src/common.h 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/common.h 2005-02-09 21:41:07 UTC (rev 85) @@ -30,7 +30,7 @@ class SoundsEngine; class ObjectsPool; class Background; -class Map; +class Scenario; class InputHandler; class AnimHandler; class Font; @@ -117,8 +117,6 @@ //@{ /// Game configuration extern Config config; -/// Size of the background (map area) -extern SDL_Rect* maparea; /// Image Cache extern ImageCache* imgcache; /// Sound Cache @@ -127,26 +125,16 @@ extern GraphicsEngine* gfxeng; /// Sounds Engine extern SoundsEngine* sfxeng; -/// Object pool -extern ObjectsPool* pool; -/// Current player -extern Player* player; -/// Background -extern Background* background; /// Current map -extern Map* curmap; +extern Scenario* scenario; /// Input Handler extern InputHandler* input; -/// Animation Handler -extern AnimHandler* anim; /// Font1 extern Font* font; /// Font2 extern Font* font2; /// True if the game is paused extern bool paused; -/// True if the mission failed -extern bool failed; //@} #endif Modified: trunk/src/events.cpp =================================================================== --- trunk/src/events.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/events.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -172,7 +172,7 @@ range(weap_range), mask(target_mask) { } void EAttack::end() { - std::set targets=curmap->getCharactersIn(mask,*owner->getPos(),true,range,direction); + std::set targets=scenario->getCharactersIn(mask,*owner->getPos(),true,range,direction); if (!targets.empty()) { (*targets.begin())->hit(direction,*weapon); } Modified: trunk/src/gfxeng.cpp =================================================================== --- trunk/src/gfxeng.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/gfxeng.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -4,6 +4,7 @@ #include "objectpools.h" #include "players_common.h" #include "imgcache.h" +#include "map.h" #include "gfxeng.h" @@ -66,8 +67,8 @@ SDL_Rect shift=center; shift.x=Uint16(vis_map.w/2)-shift.x; shift.y=Uint16(vis_map.h/2)-shift.y; - if (maparea->w+shift.xw; - if (maparea->h+shift.yh; + if (scenario->area->w+shift.xarea->w; + if (scenario->area->h+shift.yarea->h; if (shift.x>=0) shift.x=0; if (shift.y>=0) shift.y=0; vis_map.x=-shift.x; @@ -77,7 +78,7 @@ inline void GraphicsEngine::drawPlayerBar() { //#players - Uint8 pnum=pool->playerspool.size(); + Uint8 pnum=scenario->pool->playerspool.size(); //temporary dest pos, source pos, copy of dest pos SDL_Rect dpos,spos,ppos; dpos.h=BAR_HEIGHT; @@ -93,13 +94,13 @@ SDL_FillRect(screen,&bar,SDL_MapRGB(screen->format,100,100,100)); //draw each player status - player_iterator plit=pool->playerspool.begin(); - while (plit != pool->playerspool.end()) { + player_iterator plit=scenario->pool->playerspool.begin(); + while (plit != scenario->pool->playerspool.end()) { //temp. variables spos=(*plit)->getIcon().pos; //enlight current player - if ((*plit)==player) { + if ((*plit)==scenario->player) { ppos=dpos; SDL_FillRect(screen,&ppos,SDL_MapRGB(screen->format,120,120,120)); } @@ -132,7 +133,7 @@ ppos.h=ICON_SIZE; item=(*plit)->getItem(j); - if ((j==(*plit)->getItemNum()) && (*plit)==player) { + if ((j==(*plit)->getItemNum()) && (*plit)==scenario->player) { SDL_FillRect(screen,&ppos,SDL_MapRGB(screen->format,200,200,200)); } if (item) { @@ -147,23 +148,23 @@ } void GraphicsEngine::renderScene(bool insist) { - if (!paused || insist) { + if (scenario->background && (!paused || insist)) { //We don't want to change pos! SDL_Rect tmprect,shift,srcpos; - if (player!=NULL) { - shift=setShift(player->getCenter()); + if (scenario->player!=NULL) { + shift=setShift(scenario->player->getCenter()); } else { shift.x=0; shift.y=0; } - tmprect=*maparea; - srcpos=background->getFrame().pos; - shiftMapArea(tmprect,*background->getCurPos()); - SDL_BlitSurface(background->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift)); + 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=pool->objectspool.begin(); - while (obit!=pool->objectspool.end()) { + object_iterator obit=scenario->pool->objectspool.begin(); + while (obit!=scenario->pool->objectspool.end()) { tmprect=*((*obit)->getPos()); srcpos=(*obit)->getFrame().pos; shiftMapArea(tmprect,*((*obit)->getCurPos())); @@ -171,11 +172,11 @@ ++obit; } - if (player!=NULL) { - tmprect=*(player->getPos()); - srcpos=player->getFrame().pos; - shiftMapArea(tmprect,*(player->getCurPos())); - SDL_BlitSurface(player->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift)); + if (scenario->player!=NULL) { + tmprect=*(scenario->player->getPos()); + srcpos=scenario->player->getFrame().pos; + shiftMapArea(tmprect,*(scenario->player->getCurPos())); + SDL_BlitSurface(scenario->player->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift)); } } Modified: trunk/src/gfxeng.h =================================================================== --- trunk/src/gfxeng.h 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/gfxeng.h 2005-02-09 21:41:07 UTC (rev 85) @@ -34,7 +34,7 @@ inline SDL_Rect* shiftMapArea(SDL_Rect& area, const SDL_Rect& shift); //draw player bar inline void drawPlayerBar(); - //currently visible part of the maparea + //currently visible part of the map area SDL_Rect vis_map; //main screen SDL_Surface* screen; Modified: trunk/src/input.cpp =================================================================== --- trunk/src/input.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/input.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -5,6 +5,7 @@ #include "sndcache.h" #include "gfxeng.h" #include "sfxeng.h" +#include "map.h" #include "objectpools.h" #include "objects_common.h" @@ -93,7 +94,7 @@ case SDL_KEYDOWN: { switch(event.key.keysym.sym) { case SDLK_LCTRL: { - pool->switchPlayer(); + scenario->pool->switchPlayer(); state=NOTHING; break; } @@ -140,7 +141,7 @@ } else if (paused) { state|=INPUT_PAUSE; paused=false; - anim->resetTime(); + scenario->anim->resetTime(); sfxeng->resumeMusic(); } else { state|=INPUT_PAUSE; Modified: trunk/src/lost_penguins.cpp =================================================================== --- trunk/src/lost_penguins.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/lost_penguins.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -33,25 +33,23 @@ SDL_ShowCursor(SDL_DISABLE); SDL_SetEventFilter(filterEvents); - maparea=NULL; cout << "ImageCache...\n"; imgcache=new ImageCache(); cout << "SoundCache...\n"; sndcache=new SoundCache(); cout << "GraphicsEngine...\n"; gfxeng=new GraphicsEngine(); + cout << "SoundEngine...\n"; + sfxeng=new SoundsEngine(); cout << "Fonts...\n"; font=new Font(imgcache->loadImage("font_arial_white_16_01.png")); font2=new Font(imgcache->loadImage("font_arial_12_01.bmp")); - cout << "SoundEngine...\n"; - sfxeng=new SoundsEngine(); - cout << "ObjectsPool and Map...\n"; - pool=new ObjectsPool(); - curmap=new Map(config.map); cout << "InputHandler...\n"; input=new InputHandler(); - cout << "AnimHandler...\n"; - anim=new AnimHandler(); + //TODO: menu, szenarios, etc + cout << "Initializing Scenario...\n"; + scenario=new Scenario(); + scenario->loadMap(config.map); cout << "Starting game...\n" << endl; while (true) { @@ -60,7 +58,7 @@ //Check input input->pollEvents(); //Run Animations - anim->runAnims(); + scenario->anim->runAnims(); } quitGame(-2); @@ -68,16 +66,13 @@ int quitGame(int errorcode=0) { cout << endl << "Quitting game (exit code: " << errorcode << ")...\n"; - delete curmap; - delete pool; - cout << "Pools deleted...\n"; + delete scenario; + cout << "Scenario closed...\n"; delete sfxeng; delete gfxeng; cout << "GraphicsEngine deleted...\n"; delete input; - delete anim; delete font; - delete background; cout << "Deleting SoundCache...\n"; delete sndcache; cout << "Deleting ImageCache...\n"; Modified: trunk/src/map.cpp =================================================================== --- trunk/src/map.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/map.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -1,39 +1,73 @@ #include "common.h" #include "objectpools.h" #include "players_common.h" +#include "imgcache.h" +#include "sndcache.h" +#include "anim.h" #include "map.h" -Map::Map(string mapname) { - if (loadMapData(mapname)==0) { - cout << "Map loaded.\n"; - } else { - quitGame(3); - } - - if (pool->playerspool.size()>0) player=*pool->playerspool.begin(); - else player=NULL; +Scenario::Scenario(): + background(NULL), + area(NULL), + player(NULL), + failed(false), + name("") { + cout << "Scenario: ImageCache...\n"; + imgcache=new ImageCache(); + cout << "Scenario: SoundCache...\n"; + sndcache=new SoundCache(); + cout << "Scenario: AnimHandler...\n"; + anim=new AnimHandler(); + cout << "Map: ObjectsPool...\n"; + pool=new ObjectsPool(); } -Map::~Map() { +Scenario::~Scenario() { + cout << endl << "Closing map...\n"; + delete pool; + cout << "Map: Deleted Pools...\n"; + if (background) delete background; + cout << "Map: Deleted Background...\n"; + delete anim; + cout << "Scenario: Deleted Animhandler...\n"; + delete sndcache; + cout << "Scenario: Deleted SoundCache...\n"; + delete imgcache; + cout << "Scenario: Deleted ImageCache... (Scenario closed)\n"; } +inline void Scenario::reinitMap() { + if (pool && !(pool->empty())) { + delete pool; + pool=new ObjectsPool(); + } else if (!pool) pool=new ObjectsPool(); + if (background) delete background; + background=NULL; + area=NULL; + player=NULL; + name=""; +} -inline int Map::loadMapData(const string& mapname) { +int Scenario::loadMap(string mapname) { + reinitMap(); + cout << "Loading Map data...\n"; + name=mapname; ifstream mapfile; string tmpline; - string name, image; + string image; string arg1,arg2,arg3; Uint16 x,y; background=NULL; - string loadfile=config.datadir+mapname; + area=NULL; + string loadfile=config.datadir+name; bool header=false; mapfile.open(loadfile.c_str()); if (mapfile) { cout << "Loading map configuration file...\n"; } else { - cout << "Map loading failed: " << (config.datadir+mapname) << " not found!\n"; + cout << "Map loading failed: " << (config.datadir+name) << " not found!\n"; return -2; } @@ -72,7 +106,7 @@ if (name=="Background" && (!background)) { background=new Background(image); - if (background) maparea=background->getPos(); + if (background) area=background->getPos(); //Background has to be first! } else if (background) { pool->addObjectbyName(name,image,x,y,arg1,arg2,arg3); @@ -85,14 +119,18 @@ mapfile.clear(); //Has a background been found? - if (background) return 0; - else { + if (background) { + if (pool->playerspool.size()>0) player=*pool->playerspool.begin(); + else player=NULL; + if (player==NULL) cout << "No player found!\n"; + return 0; + } else { cout << "Map loading failed: No background found!\n"; return -1; } } -Uint16 Map::getDirection(const SDL_Rect& src, const SDL_Rect& dest) const { +Uint16 Scenario::getDirection(const SDL_Rect& src, const SDL_Rect& dest) const { Uint16 dir=NOTHING; if ((src.x+src.w) < (dest.x+dest.w)) dir|=DIR_RIGHT; if (src.x > dest.x) dir|=DIR_LEFT; @@ -101,7 +139,7 @@ return dir; } -Hit Map::checkPlace(const SDL_Rect& src, const SDL_Rect& dest) const { +Hit Scenario::checkPlace(const SDL_Rect& src, const SDL_Rect& dest) const { Hit hit; hit.enter=NOTHING; hit.touch=NOTHING; @@ -117,7 +155,7 @@ } -std::set Map::getCharactersIn(Uint16 mask, const SDL_Rect& rect, bool touch, Uint16 distance, Uint16 dir) const { +std::set Scenario::getCharactersIn(Uint16 mask, const SDL_Rect& rect, bool touch, Uint16 distance, Uint16 dir) const { SDL_Rect tmprect=rect; if (dir&DIR_LEFT) { tmprect.x-=distance; Modified: trunk/src/map.h =================================================================== --- trunk/src/map.h 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/map.h 2005-02-09 21:41:07 UTC (rev 85) @@ -1,7 +1,7 @@ #ifndef _MAP_H #define _MAP_H 1 -/** \brief Map organization +/** \brief Scenario organization Loads the corresponding map data (objects) and performs location checks. \remarks MAP FORMAT: @@ -15,12 +15,14 @@ \remarks Background background.bmp \remarks Teleporter teleporter.bmp 0 0 20 100 teleporter1 \todo Improve the map format (eg. support headers) - \todo Idea: move all map depending things (eg. ObjectsPool) inside Map + \todo Move the Caches into the current map as well? + \todo Create a map class inside Scenario? */ -class Map { +class Scenario { public: - Map(string mapname); - ~Map(); + /// Creates a new scenario. To load a specific map, use loadMap(mapname). + Scenario(); + ~Scenario(); /// Checks where the source rectangle overlaps the destination rectangle. /// \param src Source rectangle /// \param dest Destination rectangle @@ -44,13 +46,33 @@ /// \param src Source rectangle /// \param dest Destination rectangle Uint16 getDirection(const SDL_Rect& src, const SDL_Rect& dest) const; - private: + + /// Background + Background* background; + /// Size of the background (map area) + SDL_Rect* area; + /// Current player + Player* player; + /// Image Cache + ImageCache* imgcache; + /// Sound Cache + SoundCache* sndcache; + /// Object pool + ObjectsPool* pool; + /// Animation Handler + AnimHandler* anim; + /// True if the mission failed + bool failed; ///\brief Loads and initializes the map data /// /// Parses the map file and tries to add the objects by using addObjectByName() /// \param mapname Map file name without the data directory in it /// \return 0 if a Background was found, -1 if not, -2 if the loading failed - inline int loadMapData(const string& mapname); + int loadMap(string mapname); + /// Name of the map file + string name; + private: + inline void reinitMap(); }; #endif Modified: trunk/src/monsters_common.cpp =================================================================== --- trunk/src/monsters_common.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/monsters_common.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -6,6 +6,7 @@ #include "sndcache.h" #include "monsters_common.h" //shouldn't be here... +#include "map.h" #include "players_common.h" @@ -22,7 +23,7 @@ dense_types|=OTYPE_PLAYER; im_left=animation; im_right=animation; - au_hit=sndcache->loadWAV("monhit.wav"); + au_hit=scenario->sndcache->loadWAV("monhit.wav"); } Monster::~Monster() { } Modified: trunk/src/objectpools.cpp =================================================================== --- trunk/src/objectpools.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objectpools.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -97,7 +97,7 @@ } Object* ObjectsPool::addObject(Object* object) { - if ( (object!=NULL) && (maparea==NULL || (curmap->checkPlace(*(object->getPos()),*maparea).enter==NOTHING)) ) { + if ( (object!=NULL) && (scenario->area==NULL || (scenario->checkPlace(*(object->getPos()),*scenario->area).enter==NOTHING)) ) { objectspool.insert(object); return object; } else { @@ -118,9 +118,9 @@ if (playerspool.erase(ptrv)) { currentplayer=playerspool.begin(); if (currentplayer!=playerspool.end()) { - if (player) player->clearStates(false); - player=*currentplayer; - } else player=NULL; + if (scenario->player) scenario->player->clearStates(false); + scenario->player=*currentplayer; + } else scenario->player=NULL; } } else if (Monster* ptrm = dynamic_cast(*it)) monsterspool.erase(ptrm); } @@ -142,9 +142,9 @@ if (playerspool.erase(ptrv)) { currentplayer=playerspool.begin(); if (currentplayer!=playerspool.end()) { - if (player) player->clearStates(false); - player=*currentplayer; - } else player=NULL; + if (scenario->player) scenario->player->clearStates(false); + scenario->player=*currentplayer; + } else scenario->player=NULL; } } else if (Monster* ptrm = dynamic_cast(object)) monsterspool.erase(ptrm); } @@ -153,9 +153,9 @@ Character* ObjectsPool::addCharacter(Character* newcharacter) { - if ( (newcharacter!=NULL) && (curmap->checkPlace(*(newcharacter->getPos()),*maparea).enter==NOTHING) ) { + if ( (newcharacter!=NULL) && (scenario->checkPlace(*(newcharacter->getPos()),*scenario->area).enter==NOTHING) ) { characterspool.insert(newcharacter); - pool->addObject(newcharacter); + scenario->pool->addObject(newcharacter); return newcharacter; } else { cout << "Couldn't place character!\n"; @@ -164,10 +164,10 @@ } Player* ObjectsPool::addPlayer(Player* newplayer) { - if ( (newplayer!=NULL) && (curmap->checkPlace(*(newplayer->getPos()),*maparea).enter==NOTHING) ) { + if ( (newplayer!=NULL) && (scenario->checkPlace(*(newplayer->getPos()),*scenario->area).enter==NOTHING) ) { playerspool.insert(newplayer); currentplayer=playerspool.begin(); - pool->addCharacter(newplayer); + scenario->pool->addCharacter(newplayer); return newplayer; } else { cout << "Couldn't place player!\n"; @@ -181,22 +181,27 @@ ++currentplayer; if (currentplayer == playerspool.end()) currentplayer=playerspool.begin(); if (currentplayer != playerspool.end()) { - if (player) player->clearStates(false); - player=*currentplayer; + if (scenario->player) scenario->player->clearStates(false); + scenario->player=*currentplayer; } - else player=NULL; - return player; - } else return (player=NULL); + else scenario->player=NULL; + return scenario->player; + } else return (scenario->player=NULL); } Monster* ObjectsPool::addMonster(Monster* newmonster) { - if ( (newmonster!=NULL) && (curmap->checkPlace(*(newmonster->getPos()),*maparea).enter==NOTHING) ) { + if ( (newmonster!=NULL) && (scenario->checkPlace(*(newmonster->getPos()),*scenario->area).enter==NOTHING) ) { monsterspool.insert(newmonster); - pool->addCharacter(newmonster); + scenario->pool->addCharacter(newmonster); return newmonster; } else { cout << "Couldn't place monster!\n"; return NULL; } } + +bool ObjectsPool::empty() { + if (scenario->pool->objectspool.empty()) return true; + else return false; +} Modified: trunk/src/objectpools.h =================================================================== --- trunk/src/objectpools.h 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objectpools.h 2005-02-09 21:41:07 UTC (rev 85) @@ -14,6 +14,8 @@ public: ObjectsPool(); ~ObjectsPool(); + ///\brief Returns true if no objects were loaded so far... + bool empty(); ///\todo Move this code to the objects ///\brief Add objects by their names /// Modified: trunk/src/objects/baleog.cpp =================================================================== --- trunk/src/objects/baleog.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objects/baleog.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -4,25 +4,26 @@ #include "imgcache.h" #include "sndcache.h" #include "input.h" +#include "map.h" #include "baleog.h" Baleog::Baleog(string imagename, Sint16 xcord, Sint16 ycord, string pname): Player(imagename,xcord,ycord,pname) { - im_left=new Animation(imgcache->loadImage("baleog1_left.bmp")); - im_right=new Animation(imgcache->loadImage("baleog1_right.bmp")); - im_run_left=new Animation(imgcache->loadImage("baleog1-run_left.png"),8,1000); - im_run_right=new Animation(imgcache->loadImage("baleog1-run_right.png"),8,1000); + im_left=new Animation(scenario->imgcache->loadImage("baleog1_left.bmp")); + im_right=new Animation(scenario->imgcache->loadImage("baleog1_right.bmp")); + im_run_left=new Animation(scenario->imgcache->loadImage("baleog1-run_left.png"),8,1000); + im_run_right=new Animation(scenario->imgcache->loadImage("baleog1-run_right.png"),8,1000); im_fall_left=im_left; im_fall_right=im_right; im_krit_left=im_left; im_krit_right=im_right; - im_land_left=new Animation(imgcache->loadImage("olaf1_land_left.bmp"),1,T_IRR,true); - im_land_right=new Animation(imgcache->loadImage("olaf1_land_right.bmp"),1,T_IRR,true); + im_land_left=new Animation(scenario->imgcache->loadImage("olaf1_land_left.bmp"),1,T_IRR,true); + im_land_right=new Animation(scenario->imgcache->loadImage("olaf1_land_right.bmp"),1,T_IRR,true); weapon=Weapon(-1,W_STRIKE); - im_sword_left=new Animation(imgcache->loadImage("BaleogCyborg_Slash_left.png"),8,1000,true); - im_sword_right=new Animation(imgcache->loadImage("BaleogCyborg_Slash_right.png"),8,1000,true); - au_sword=sndcache->loadWAV("swrdsw2.wav"); + im_sword_left=new Animation(scenario->imgcache->loadImage("BaleogCyborg_Slash_left.png"),8,1000,true); + im_sword_right=new Animation(scenario->imgcache->loadImage("BaleogCyborg_Slash_right.png"),8,1000,true); + au_sword=scenario->sndcache->loadWAV("swrdsw2.wav"); } Baleog::~Baleog() { Modified: trunk/src/objects/bomb.cpp =================================================================== --- trunk/src/objects/bomb.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objects/bomb.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -1,6 +1,7 @@ #include "common.h" //shouldn't be here... #include "objectpools.h" +#include "map.h" #include "players_common.h" #include "triggered_bomb.h" #include "bomb.h" @@ -11,7 +12,7 @@ Bomb::~Bomb() { } bool Bomb::act(Object*) { - if (pool->addCharacter(new TriggeredBomb("bomb_fire.bmp",owner->getPos()->x,owner->getPos()->y,countdown,"TriggeredBomb"))) { + if (scenario->pool->addCharacter(new TriggeredBomb("bomb_fire.bmp",owner->getPos()->x,owner->getPos()->y,countdown,"TriggeredBomb"))) { owner->removeItem(); return true; } else { Modified: trunk/src/objects/door.cpp =================================================================== --- trunk/src/objects/door.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objects/door.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -10,7 +10,7 @@ Object(imagename,xcord,ycord,oname), open(false), key(keyname), - au_open(sndcache->loadWAV("dooropn.wav")), + au_open(scenario->sndcache->loadWAV("dooropn.wav")), au_close(au_open) { otype=OTYPE_DENSE; } @@ -19,7 +19,7 @@ bool Door::act(Object* obj) { //sanity check if (!(obj && obj->getName()==key)) return false; - if (!(curmap->getCharactersIn(OTYPE_PLAYER|OTYPE_MONSTER,pos,true).empty())) return false; + if (!(scenario->getCharactersIn(OTYPE_PLAYER|OTYPE_MONSTER,pos,true).empty())) return false; //switch state if (open) { Modified: trunk/src/objects/erik.cpp =================================================================== --- trunk/src/objects/erik.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objects/erik.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -15,18 +15,18 @@ jump(V_JUMP), jump2(V_JUMP2) { weapon=Weapon(-1,W_PRESSURE,WS_PRESSURE); - im_left=new Animation(imgcache->loadImage("erik1_left.bmp")); - im_right=new Animation(imgcache->loadImage("erik1_right.bmp")); + im_left=new Animation(scenario->imgcache->loadImage("erik1_left.bmp")); + im_right=new Animation(scenario->imgcache->loadImage("erik1_right.bmp")); im_run_right=im_right; im_run_left=im_left; im_fall_left=im_left; im_fall_right=im_right; im_krit_left=im_left; im_krit_right=im_right; - im_land_left=new Animation(imgcache->loadImage("olaf1_land_left.bmp"),1,T_IRR,true); - im_land_right=new Animation(imgcache->loadImage("olaf1_land_right.bmp"),1,T_IRR,true); - au_jump=sndcache->loadWAV("rboots.wav"); - au_hit=sndcache->loadWAV("erikhit.wav"); + im_land_left=new Animation(scenario->imgcache->loadImage("olaf1_land_left.bmp"),1,T_IRR,true); + im_land_right=new Animation(scenario->imgcache->loadImage("olaf1_land_right.bmp"),1,T_IRR,true); + au_jump=scenario->sndcache->loadWAV("rboots.wav"); + au_hit=scenario->sndcache->loadWAV("erikhit.wav"); au_run=NULL; } Erik::~Erik() { @@ -97,7 +97,7 @@ void Erik::crash(Uint16 dir) { if ((state&(STATE_PRESS_LR|STATE_ACT_2)) && (!(dir&DIR_DOWN))) { - std::set targets=curmap->getCharactersIn(OTYPE_MONSTER,getCenter(),true,pos.w+1,dir); + std::set targets=scenario->getCharactersIn(OTYPE_MONSTER,getCenter(),true,pos.w+1,dir); ///\bug This might get the wrong target if (!targets.empty()) (*targets.begin())->hit(dir,weapon); } Modified: trunk/src/objects/exit.cpp =================================================================== --- trunk/src/objects/exit.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objects/exit.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -1,6 +1,7 @@ #include "common.h" #include "objectpools.h" //shouldn't be here... +#include "map.h" #include "players_common.h" #include "exit.h" @@ -10,12 +11,12 @@ Exit::~Exit() { } bool Exit::act(Object*) { - player_iterator it=pool->playerspool.begin(); - while (it!=pool->playerspool.end()) { + player_iterator it=scenario->pool->playerspool.begin(); + while (it!=scenario->pool->playerspool.end()) { if (!((*it)->isIn(pos))) return false; ++it; } - if (failed) cout << "Again?\n"; + if (scenario->failed) cout << "Again?\n"; else cout << "You won!!!!\n"; quitGame(0); return true; Modified: trunk/src/objects/fang.cpp =================================================================== --- trunk/src/objects/fang.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objects/fang.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -4,6 +4,7 @@ #include "input.h" #include "imgcache.h" #include "sndcache.h" +#include "map.h" #include "fang.h" @@ -11,21 +12,21 @@ Player(imagename,xcord,ycord,pname), jump(V_JUMP) { weapon=Weapon(-1,W_STRIKE); - im_left=new Animation(imgcache->loadImage("Fang_Breath_left.png"),4,1000); - im_right=new Animation(imgcache->loadImage("Fang_Breath_right.png"),4,1000); - im_run_left=new Animation(imgcache->loadImage("Fang_walk_left.png"),8,1000); - im_run_right=new Animation(imgcache->loadImage("Fang_walk_right.png"),8,1000); + im_left=new Animation(scenario->imgcache->loadImage("Fang_Breath_left.png"),4,1000); + im_right=new Animation(scenario->imgcache->loadImage("Fang_Breath_right.png"),4,1000); + im_run_left=new Animation(scenario->imgcache->loadImage("Fang_walk_left.png"),8,1000); + im_run_right=new Animation(scenario->imgcache->loadImage("Fang_walk_right.png"),8,1000); im_fall_left=im_left; im_fall_right=im_right; im_krit_left=im_left; im_krit_right=im_right; - im_land_left=new Animation(imgcache->loadImage("olaf1_land_left.bmp"),1,T_IRR,true); - im_land_right=new Animation(imgcache->loadImage("olaf1_land_right.bmp"),1,T_IRR,true); - im_claw_left=new Animation(imgcache->loadImage("Fang_Clawslash_left.png"),8,1000,true); - im_claw_right=new Animation(imgcache->loadImage("Fang_Clawslash_right.png"),8,1000,true); - au_hit=sndcache->loadWAV("wolfhit.wav"); - au_claw=sndcache->loadWAV("wolfjmp1.wav"); - au_jump=sndcache->loadWAV("fangjump.wav"); + im_land_left=new Animation(scenario->imgcache->loadImage("olaf1_land_left.bmp"),1,T_IRR,true); + im_land_right=new Animation(scenario->imgcache->loadImage("olaf1_land_right.bmp"),1,T_IRR,true); + im_claw_left=new Animation(scenario->imgcache->loadImage("Fang_Clawslash_left.png"),8,1000,true); + im_claw_right=new Animation(scenario->imgcache->loadImage("Fang_Clawslash_right.png"),8,1000,true); + au_hit=scenario->sndcache->loadWAV("wolfhit.wav"); + au_claw=scenario->sndcache->loadWAV("wolfjmp1.wav"); + au_jump=scenario->sndcache->loadWAV("fangjump.wav"); } Fang::~Fang() { delete im_left; Modified: trunk/src/objects/geyser.cpp =================================================================== --- trunk/src/objects/geyser.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objects/geyser.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -11,7 +11,7 @@ Geyser::Geyser(string imagename, Sint16 xcord, Sint16 ycord, Sint16 yAdd, string oname): Object(imagename,xcord,ycord,oname), aspeed(yAdd), - au_geyser(sndcache->loadWAV("geyser.wav")), + au_geyser(scenario->sndcache->loadWAV("geyser.wav")), Deffect(0) { } Geyser::~Geyser() { } @@ -21,7 +21,7 @@ if (Deffect>T_GEYSIR) { Deffect=0; sfxeng->playWAV(au_geyser); - std::set characters=curmap->getCharactersIn(OTYPE_PLAYER,pos,true); + std::set characters=scenario->getCharactersIn(OTYPE_PLAYER,pos,true); std::set::iterator chrit=characters.begin(); while (chrit!=characters.end()) { (*chrit)->addSpeed(aspeed); Modified: trunk/src/objects/olaf.cpp =================================================================== --- trunk/src/objects/olaf.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objects/olaf.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -4,6 +4,7 @@ #include "input.h" #include "imgcache.h" #include "sndcache.h" +#include "map.h" #include "sfxeng.h" #include "olaf.h" @@ -11,32 +12,32 @@ Olaf::Olaf(string imagename, Sint16 xcord, Sint16 ycord, string pname): Player(imagename,xcord,ycord,pname), fart(V_FART) { - im_left=new Animation(imgcache->loadImage("olaf1_left.bmp")); - im_right=new Animation(imgcache->loadImage("olaf1_right.bmp")); - im_run_left=new Animation(imgcache->loadImage("olaf1-run_left.png"),8,1000); - im_run_right=new Animation(imgcache->loadImage("olaf1-run_right.png"),8,1000); + im_left=new Animation(scenario->imgcache->loadImage("olaf1_left.bmp")); + im_right=new Animation(scenario->imgcache->loadImage("olaf1_right.bmp")); + im_run_left=new Animation(scenario->imgcache->loadImage("olaf1-run_left.png"),8,1000); + im_run_right=new Animation(scenario->imgcache->loadImage("olaf1-run_right.png"),8,1000); im_fall_left=im_left; im_fall_right=im_right; im_krit_left=im_left; im_krit_right=im_right; - im_land_left=new Animation(imgcache->loadImage("olaf1_land_left.bmp"),1,T_IRR,true); - im_land_right=new Animation(imgcache->loadImage("olaf1_land_right.bmp"),1,T_IRR,true); + im_land_left=new Animation(scenario->imgcache->loadImage("olaf1_land_left.bmp"),1,T_IRR,true); + im_land_right=new Animation(scenario->imgcache->loadImage("olaf1_land_right.bmp"),1,T_IRR,true); - im_small_left=new Animation(imgcache->loadImage("Olaf_Small_Walk_left.png"),7,0); - im_small_right=new Animation(imgcache->loadImage("Olaf_Small_Walk_right.png"),7,0); - im_run_small_left=new Animation(imgcache->loadImage("Olaf_Small_Walk_left.png"),7,500); - im_run_small_right=new Animation(imgcache->loadImage("Olaf_Small_Walk_right.png"),7,500); - im_shield_right=new Animation(imgcache->loadImage("olaf1_fall_shield_right.bmp")); - im_shield_left=new Animation(imgcache->loadImage("olaf1_fall_shield_left.bmp")); + im_small_left=new Animation(scenario->imgcache->loadImage("Olaf_Small_Walk_left.png"),7,0); + im_small_right=new Animation(scenario->imgcache->loadImage("Olaf_Small_Walk_right.png"),7,0); + im_run_small_left=new Animation(scenario->imgcache->loadImage("Olaf_Small_Walk_left.png"),7,500); + im_run_small_right=new Animation(scenario->imgcache->loadImage("Olaf_Small_Walk_right.png"),7,500); + im_shield_right=new Animation(scenario->imgcache->loadImage("olaf1_fall_shield_right.bmp")); + im_shield_left=new Animation(scenario->imgcache->loadImage("olaf1_fall_shield_left.bmp")); im_run_shield_right=im_shield_right; im_run_shield_left=im_shield_left; im_fall_shield_left=im_shield_left; im_fall_shield_right=im_shield_right; - im_die=new Animation(60,imgcache->loadImage("kuru.bmp"),12,2000,true); - au_small=sndcache->loadWAV("blob.wav"); - au_big=sndcache->loadWAV("unblob.wav"); - au_fart=sndcache->loadWAV("fart1.wav"); - au_hit=sndcache->loadWAV("fathit.wav"); + im_die=new Animation(60,scenario->imgcache->loadImage("kuru.bmp"),12,2000,true); + au_small=scenario->sndcache->loadWAV("blob.wav"); + au_big=scenario->sndcache->loadWAV("unblob.wav"); + au_fart=scenario->sndcache->loadWAV("fart1.wav"); + au_hit=scenario->sndcache->loadWAV("fathit.wav"); } Olaf::~Olaf() { delete im_left; Modified: trunk/src/objects/plant.cpp =================================================================== --- trunk/src/objects/plant.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objects/plant.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -13,7 +13,7 @@ tcur(trecover) { maxhealth=1; weapon=Weapon(-1,W_TOUCH); - au_hit=sndcache->loadWAV("creeper.wav"); + au_hit=scenario->sndcache->loadWAV("creeper.wav"); au_recover=au_hit; enemy_types|=(OTYPE_PLAYER); } @@ -22,7 +22,7 @@ void Plant::touch(Object* obj) { if (health==0) return; if(Player* ptr = dynamic_cast(obj)) { - Uint16 adir=(DIR_UP|curmap->getDirection(getCenter(),ptr->getCenter())); + Uint16 adir=(DIR_UP|scenario->getDirection(getCenter(),ptr->getCenter())); if (!(adir&DIR_LR)) adir|=DIR_LEFT; ptr->hit(adir,weapon); } @@ -35,10 +35,10 @@ sfxeng->playWAV(au_recover); tcur=recover; setHealth(maxhealth); - std::set cset=curmap->getCharactersIn(enemy_types,pos,true); + std::set cset=scenario->getCharactersIn(enemy_types,pos,true); character_iterator cit=cset.begin(); while (cit!=cset.end()) { - (*cit)->hit(curmap->getDirection(pos,*(*cit)->getPos()),weapon); + (*cit)->hit(scenario->getDirection(pos,*(*cit)->getPos()),weapon); ++cit; } } Modified: trunk/src/objects/scorch.cpp =================================================================== --- trunk/src/objects/scorch.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objects/scorch.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -3,6 +3,7 @@ #include "anim.h" #include "input.h" #include "imgcache.h" +#include "map.h" #include "sndcache.h" #include "scorch.h" @@ -11,19 +12,19 @@ Player(imagename,xcord,ycord,pname), left_wings(SCORCH_MAX_WINGS), wing(V_FLY) { - im_left=new Animation(imgcache->loadImage("baleog1_left.bmp")); - im_right=new Animation(imgcache->loadImage("baleog1_right.bmp")); - im_run_left=new Animation(imgcache->loadImage("baleog1-run_left.png"),8,1000); - im_run_right=new Animation(imgcache->loadImage("baleog1-run_right.png"),8,1000); + im_left=new Animation(scenario->imgcache->loadImage("baleog1_left.bmp")); + im_right=new Animation(scenario->imgcache->loadImage("baleog1_right.bmp")); + im_run_left=new Animation(scenario->imgcache->loadImage("baleog1-run_left.png"),8,1000); + im_run_right=new Animation(scenario->imgcache->loadImage("baleog1-run_right.png"),8,1000); im_fall_left=im_left; im_fall_right=im_right; im_krit_left=im_left; im_krit_right=im_right; - im_land_left=new Animation(imgcache->loadImage("olaf1_land_left.bmp"),1,T_IRR,true); - im_land_right=new Animation(imgcache->loadImage("olaf1_land_right.bmp"),1,T_IRR,true); - au_swing=sndcache->loadWAV("flapwngs.wav"); - au_tired=sndcache->loadWAV("flwings.wav"); - au_hit=sndcache->loadWAV("draghit.wav"); + im_land_left=new Animation(scenario->imgcache->loadImage("olaf1_land_left.bmp"),1,T_IRR,true); + im_land_right=new Animation(scenario->imgcache->loadImage("olaf1_land_right.bmp"),1,T_IRR,true); + au_swing=scenario->sndcache->loadWAV("flapwngs.wav"); + au_tired=scenario->sndcache->loadWAV("flwings.wav"); + au_hit=scenario->sndcache->loadWAV("draghit.wav"); } Scorch::~Scorch() { delete im_left; Modified: trunk/src/objects/spike.cpp =================================================================== --- trunk/src/objects/spike.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objects/spike.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -17,7 +17,7 @@ void Spike::touch(Object* obj) { if(Character* ptr = dynamic_cast(obj)) { - Uint16 adir=(curmap->getDirection(getCenter(),ptr->getCenter())); + Uint16 adir=(scenario->getDirection(getCenter(),ptr->getCenter())); if (dir&adir) ptr->hit(adir,weapon); } } Modified: trunk/src/objects/teleport.cpp =================================================================== --- trunk/src/objects/teleport.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objects/teleport.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -4,12 +4,13 @@ #include "objects_common.h" //shouldn't be here... #include "players_common.h" +#include "map.h" #include "teleport.h" Teleporter::Teleporter(string imagename, Sint16 xcord, Sint16 ycord, Sint16 xExit, Sint16 yExit, string oname): Object(imagename,xcord,ycord,oname), - au_tele(sndcache->loadWAV("teleprt.wav")) { + au_tele(scenario->sndcache->loadWAV("teleprt.wav")) { exit.x=xExit; exit.y=yExit; exit.w=exit.h=0; Modified: trunk/src/objects/trigger.cpp =================================================================== --- trunk/src/objects/trigger.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objects/trigger.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -1,5 +1,6 @@ #include "common.h" #include "objectpools.h" +#include "map.h" #include "objects_common.h" #include "trigger.h" @@ -7,7 +8,7 @@ Trigger::Trigger(string imagename, Sint16 xcord, Sint16 ycord, string targetname, string oname, string keyname): Object(imagename,xcord,ycord,oname), key(keyname) { - target=pool->getObject(targetname); + target=scenario->pool->getObject(targetname); } Trigger::~Trigger() { } Modified: trunk/src/objects/triggered_bomb.cpp =================================================================== --- trunk/src/objects/triggered_bomb.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objects/triggered_bomb.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -9,7 +9,7 @@ TriggeredBomb::TriggeredBomb(string imagename, Sint16 xcord, Sint16 ycord, Uint16 tleft, string cname): Character(imagename,xcord,ycord,cname), countdown(tleft), - au_bomb(sndcache->loadWAV("explsn.wav")) { + au_bomb(scenario->sndcache->loadWAV("explsn.wav")) { weapon=Weapon(-1,W_EXPLOSION); enemy_types|=(OTYPE_PLAYER|OTYPE_MONSTER); } @@ -20,10 +20,10 @@ if (countdown<=0) { cout << "Booom!\n"; sfxeng->playWAV(au_bomb); - std::set cset=curmap->getCharactersIn(enemy_types,pos,true,20); + std::set cset=scenario->getCharactersIn(enemy_types,pos,true,20); character_iterator cit=cset.begin(); while (cit!=cset.end()) { - (*cit)->hit(curmap->getDirection(pos,*(*cit)->getPos()),weapon); + (*cit)->hit(scenario->getDirection(pos,*(*cit)->getPos()),weapon); ++cit; } die(); Modified: trunk/src/objects/water.cpp =================================================================== --- trunk/src/objects/water.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objects/water.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -4,13 +4,14 @@ #include "sndcache.h" #include "weapons.h" //shouldn't be here... +#include "map.h" #include "characters_common.h" #include "water.h" Water::Water(string imagename, Sint16 xcord, Sint16 ycord, string oname): Object(imagename,xcord,ycord,oname), - au_water(sndcache->loadWAV("splash2.wav")) { + au_water(scenario->sndcache->loadWAV("splash2.wav")) { weapon=Weapon(-1,W_WATER,WS_WATER); } Water::~Water() { } Modified: trunk/src/objects/zombie.cpp =================================================================== --- trunk/src/objects/zombie.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objects/zombie.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -12,11 +12,11 @@ Zombie::Zombie(string imagename, Sint16 xcord, Sint16 ycord, string mname): Monster(imagename,xcord,ycord,mname), - au_attack(sndcache->loadWAV("clang.wav")), + au_attack(scenario->sndcache->loadWAV("clang.wav")), T_Attack_Bite(1500) { maxspeedx=80; - im_left=new Animation(imgcache->loadImage("olaf1_left.bmp"),2,1000); - im_right=new Animation(imgcache->loadImage("olaf1_right.bmp"),2,1000); + im_left=new Animation(scenario->imgcache->loadImage("olaf1_left.bmp"),2,1000); + im_right=new Animation(scenario->imgcache->loadImage("olaf1_right.bmp"),2,1000); weapon=Weapon(-1,W_STRIKE); } @@ -82,7 +82,7 @@ unsetState(STATE_ATTACK); } else { Player* target=*(targets.begin()); - Uint16 dir=curmap->getDirection(getCenter(),target->getCenter()); + Uint16 dir=scenario->getDirection(getCenter(),target->getCenter()); dir&=~(DIR_UP|DIR_DOWN); if (dir&DIR_LEFT) setState(STATE_LEFT); else unsetState(STATE_LEFT); Modified: trunk/src/objects_common.cpp =================================================================== --- trunk/src/objects_common.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/objects_common.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -3,13 +3,15 @@ #include "anim.h" #include "events.h" #include "objects_common.h" +//HACK! +#include "map.h" Object::Object(string imagename, Sint16 xcord, Sint16 ycord, string oname): tbirth(SDL_GetTicks()), state(NOTHING), event(NULL), - im_orig(new Animation(imgcache->loadImage(imagename))), + im_orig(new Animation(scenario->imgcache->loadImage(imagename))), otype(NOTHING), name(oname), delete_flag(false) { @@ -42,16 +44,16 @@ bool Object::setPos(Sint16 xcord,Sint16 ycord) { bool ok=true; - //Did we hit a maparea? + //Did we hit a map area? if (xcord < 0) { pos.x=0; ok=false; - } else if (xcord > (maparea->w-pos.w)) { - pos.x=maparea->w-pos.w; + } else if (xcord > (scenario->area->w-pos.w)) { + pos.x=scenario->area->w-pos.w; ok=false; } else pos.x=xcord; - if (ycord>(maparea->h-pos.h)) { - pos.y=maparea->h-pos.h; + if (ycord>(scenario->area->h-pos.h)) { + pos.y=scenario->area->h-pos.h; ok=false; } else pos.y=ycord; return ok; Modified: trunk/src/players_common.cpp =================================================================== --- trunk/src/players_common.cpp 2005-02-03 15:43:27 UTC (rev 84) +++ trunk/src/players_common.cpp 2005-02-09 21:41:07 UTC (rev 85) @@ -7,6 +7,7 @@ #include "imgcache.h" #include "sndcache.h" #include "objectpools.h" +#include "map.h" #include "players_common.h" @@ -33,16 +34,16 @@ im_krit_right=animation; im_land_left=animation; im_land_right=animation; - au_land=sndcache->loadWAV("dizzy.wav"); - au_act=sndcache->loadWAV("button.wav"); - au_useerror=sndcache->loadWAV("useerror.wav"); - au_newitem=sndcache->loadWAV("pickup.wav"); - au_hit=sndcache->loadWAV("vikhit.wav"); - au_elec=sndcache->loadWAV("elecdth.wav"); - au_drown=sndcache->loadWAV("drown.wav"); - au_fire=sndcache->loadWAV("fireball.wav"); - au_die=sndcache->loadWAV("bones.wav"); - au_heal=sndcache->loadWAV("usefood1.wav"); + au_land=scenario->sndcache->loadWAV("dizzy.wav"); + au_act=scenario->sndcache->loadWAV("button.wav"); + au_useerror=scenario->sndcache->loadWAV("useerror.wav"); + au_newitem=scenario->sndcache->loadWAV("pickup.wav"); + au_hit=scenario->sndcache->loadWAV("vikhit.wav"); + au_elec=scenario->sndcache->loadWAV("elecdth.wav"); + au_drown=scenario->sndcache->loadWAV("drown.wav"); + au_fire=scenario->sndcache->loadWAV("fireball.wav"); + au_die=scenario->sndcache->loadWAV("bones.wav"); + au_heal=scenario->sndcache->loadWAV("usefood1.wav"); } Player::~Player() { @@ -87,7 +88,7 @@ sfxeng->playWAV(au_newitem); newitem->setOwner(this); newitem->setPos(0,0); - pool->moveObject(newitem); + scenario->pool->moveObject(newitem); items[i]=newitem; return true; } @@ -127,7 +128,7 @@ if (state&STATE_LEFT) ok=tmpit->setPos(pos.x - tmpit->getPos()->w - 1, Uint16(getCenter().y-tmpit->getPos()->h/2)); else ok=tmpit->setPos(pos.x + pos.w + 1, Uint16(getCenter().y-tmpit->getPos()->h/2)); //new position in map and valid - if (ok && ((tmpobj=pool->addObject(tmpit))!=NULL)) return tmpobj; + if (ok && ((tmpobj=scenario->pool->addObject(tmpit))!=NULL)) return tmpobj; else { pickupItem(tmpit); return NULL; @@ -270,7 +271,7 @@ } void Player::die() { - failed=true; + scenario->failed=true; Character::die(); } @@ -296,7 +297,7 @@ if (newhealth==0) { die(); //should be !=NULL or sthg is wrong with the placement code... - Character* deadplr=pool->addCharacter(new DeadPlayer("dead_player.bmp",pos.x,pos.y)); + Character* deadplr=scenario->pool->addCharacter(new DeadPlayer("dead_player.bmp",pos.x,pos.y)); switch(weap.getSubType()) { case WS_FIRE: { if (deadplr) deadplr->setEvent(new CAnimEvent(deadplr,10,0,ESTATE_BUSY,au_fire,im_die)); From DONOTREPLY at icculus.org Wed Feb 9 17:08:47 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 9 Feb 2005 17:08:47 -0500 Subject: r86 - in trunk/src: . objects Message-ID: <20050209220847.5940.qmail@icculus.org> Author: jonas Date: 2005-02-09 17:08:47 -0500 (Wed, 09 Feb 2005) New Revision: 86 Added: trunk/src/scenario.cpp trunk/src/scenario.h Removed: trunk/src/map.cpp trunk/src/map.h Modified: trunk/src/Makefile trunk/src/anim.cpp trunk/src/characters_common.cpp trunk/src/events.cpp trunk/src/gfxeng.cpp trunk/src/input.cpp trunk/src/lost_penguins.cpp trunk/src/monsters_common.cpp trunk/src/objectpools.cpp trunk/src/objects/baleog.cpp trunk/src/objects/bomb.cpp trunk/src/objects/door.cpp trunk/src/objects/erik.cpp trunk/src/objects/exit.cpp trunk/src/objects/fang.cpp trunk/src/objects/geyser.cpp trunk/src/objects/olaf.cpp trunk/src/objects/plant.cpp trunk/src/objects/scorch.cpp trunk/src/objects/spike.cpp trunk/src/objects/teleport.cpp trunk/src/objects/trigger.cpp trunk/src/objects/triggered_bomb.cpp trunk/src/objects/water.cpp trunk/src/objects/zombie.cpp trunk/src/objects_common.cpp trunk/src/players_common.cpp Log: renamed map.* to scenario.* Modified: trunk/src/Makefile =================================================================== --- trunk/src/Makefile 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/Makefile 2005-02-09 22:08:47 UTC (rev 86) @@ -6,7 +6,7 @@ SDL = `sdl-config --cflags` SDL_LINK = `sdl-config --libs` -lSDL_mixer -lSDL_image -ldl -rdynamic -OBJS = common.o anim.o gfxeng.o input.o font.o lost_penguins.o map.o\ +OBJS = common.o anim.o gfxeng.o input.o font.o lost_penguins.o scenario.o\ objects_common.o sfxeng.o players_common.o monsters_common.o\ characters_common.o objectpools.o weapons.o events.o imgcache.o\ sndcache.o Modified: trunk/src/anim.cpp =================================================================== --- trunk/src/anim.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/anim.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -3,7 +3,7 @@ #include "gfxeng.h" #include "objectpools.h" #include "players_common.h" -#include "map.h" +#include "scenario.h" #include "anim.h" Modified: trunk/src/characters_common.cpp =================================================================== --- trunk/src/characters_common.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/characters_common.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -1,7 +1,7 @@ #include "common.h" #include "anim.h" #include "events.h" -#include "map.h" +#include "scenario.h" #include "weapons.h" #include "objectpools.h" #include "characters_common.h" Modified: trunk/src/events.cpp =================================================================== --- trunk/src/events.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/events.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -2,7 +2,7 @@ #include "events.h" #include "anim.h" #include "weapons.h" -#include "map.h" +#include "scenario.h" #include "sfxeng.h" #include "characters_common.h" Modified: trunk/src/gfxeng.cpp =================================================================== --- trunk/src/gfxeng.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/gfxeng.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -4,7 +4,7 @@ #include "objectpools.h" #include "players_common.h" #include "imgcache.h" -#include "map.h" +#include "scenario.h" #include "gfxeng.h" Modified: trunk/src/input.cpp =================================================================== --- trunk/src/input.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/input.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -5,7 +5,7 @@ #include "sndcache.h" #include "gfxeng.h" #include "sfxeng.h" -#include "map.h" +#include "scenario.h" #include "objectpools.h" #include "objects_common.h" Modified: trunk/src/lost_penguins.cpp =================================================================== --- trunk/src/lost_penguins.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/lost_penguins.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -3,7 +3,7 @@ #include "anim.h" #include "input.h" #include "font.h" -#include "map.h" +#include "scenario.h" #include "imgcache.h" #include "sndcache.h" #include "gfxeng.h" Deleted: trunk/src/map.cpp =================================================================== --- trunk/src/map.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/map.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -1,183 +0,0 @@ -#include "common.h" -#include "objectpools.h" -#include "players_common.h" -#include "imgcache.h" -#include "sndcache.h" -#include "anim.h" -#include "map.h" - - -Scenario::Scenario(): - background(NULL), - area(NULL), - player(NULL), - failed(false), - name("") { - cout << "Scenario: ImageCache...\n"; - imgcache=new ImageCache(); - cout << "Scenario: SoundCache...\n"; - sndcache=new SoundCache(); - cout << "Scenario: AnimHandler...\n"; - anim=new AnimHandler(); - cout << "Map: ObjectsPool...\n"; - pool=new ObjectsPool(); -} - -Scenario::~Scenario() { - cout << endl << "Closing map...\n"; - delete pool; - cout << "Map: Deleted Pools...\n"; - if (background) delete background; - cout << "Map: Deleted Background...\n"; - delete anim; - cout << "Scenario: Deleted Animhandler...\n"; - delete sndcache; - cout << "Scenario: Deleted SoundCache...\n"; - delete imgcache; - cout << "Scenario: Deleted ImageCache... (Scenario closed)\n"; -} - -inline void Scenario::reinitMap() { - if (pool && !(pool->empty())) { - delete pool; - pool=new ObjectsPool(); - } else if (!pool) pool=new ObjectsPool(); - if (background) delete background; - background=NULL; - area=NULL; - player=NULL; - name=""; -} - -int Scenario::loadMap(string mapname) { - reinitMap(); - cout << "Loading Map data...\n"; - name=mapname; - ifstream mapfile; - string tmpline; - string image; - string arg1,arg2,arg3; - Uint16 x,y; - background=NULL; - area=NULL; - string loadfile=config.datadir+name; - bool header=false; - - mapfile.open(loadfile.c_str()); - if (mapfile) { - cout << "Loading map configuration file...\n"; - } else { - cout << "Map loading failed: " << (config.datadir+name) << " not found!\n"; - return -2; - } - - //check every line - while (getline(mapfile,tmpline)) { - //parse the header, always start a header with #HEADER and end it with #ENDHEADER! - if (header) { - name.erase(); - arg1.erase(); - arg2.erase(); - arg3.erase(); - std::istringstream tmpstream(tmpline); - tmpstream >> name >> arg1 >> arg2 >> arg3; - if (name[0]=='#') { - if (name=="#ENDHEADER") header=false; - continue; - } - continue; - } - name.erase(); - image.erase(); - x=0; - y=0; - arg1=arg2="0"; - arg3=""; - std::istringstream tmpstream(tmpline); - tmpstream >> name >> image >> x >> y >> arg1 >> arg2 >> arg3; - - //Skip empty lines - if (name.empty()) continue; - //Skip comments - if (name[0]=='#') { - if (name=="#HEADER") header=true; - continue; - } - - if (name=="Background" && (!background)) { - background=new Background(image); - if (background) area=background->getPos(); - //Background has to be first! - } else if (background) { - pool->addObjectbyName(name,image,x,y,arg1,arg2,arg3); - } else { - cout << "No background found yet, skipping " << name << " ...\n"; - } - } - - mapfile.close(); - mapfile.clear(); - - //Has a background been found? - if (background) { - if (pool->playerspool.size()>0) player=*pool->playerspool.begin(); - else player=NULL; - if (player==NULL) cout << "No player found!\n"; - return 0; - } else { - cout << "Map loading failed: No background found!\n"; - return -1; - } -} - -Uint16 Scenario::getDirection(const SDL_Rect& src, const SDL_Rect& dest) const { - Uint16 dir=NOTHING; - if ((src.x+src.w) < (dest.x+dest.w)) dir|=DIR_RIGHT; - if (src.x > dest.x) dir|=DIR_LEFT; - if ((src.y+src.h) < (dest.y+dest.h)) dir|=DIR_DOWN; - if (src.y > dest.y) dir|=DIR_UP; - return dir; -} - -Hit Scenario::checkPlace(const SDL_Rect& src, const SDL_Rect& dest) const { - Hit hit; - hit.enter=NOTHING; - hit.touch=NOTHING; - if (src.x < dest.x) hit.enter|=DIR_LEFT; - if (src.x==dest.x) hit.touch|=DIR_LEFT; - if (src.y < dest.y) hit.enter|=DIR_UP; - if (src.y==dest.y) hit.touch|=DIR_UP; - if ((src.x+src.w) > (dest.x+dest.w)) hit.enter|=DIR_RIGHT; - if ((src.x+src.w)==(dest.x+dest.w)) hit.touch|=DIR_RIGHT; - if ((src.y+src.h) > (dest.y+dest.h)) hit.enter|=DIR_DOWN; - if ((src.y+src.h)==(dest.y+dest.h)) hit.touch|=DIR_DOWN; - return hit; -} - - -std::set Scenario::getCharactersIn(Uint16 mask, const SDL_Rect& rect, bool touch, Uint16 distance, Uint16 dir) const { - SDL_Rect tmprect=rect; - if (dir&DIR_LEFT) { - tmprect.x-=distance; - tmprect.w+=distance; - } - if (dir&DIR_RIGHT) { - tmprect.x+=distance; - tmprect.w+=distance; - } - if (dir&DIR_UP) { - tmprect.y-=distance; - tmprect.h+=distance; - } - if (dir&DIR_DOWN) { - tmprect.y+=distance; - tmprect.h+=distance; - } - std::set tmpset; - character_iterator cit=pool->characterspool.begin(); - while (cit != pool->characterspool.end()) { - if ((((*cit)->getType())&mask) && ((*cit)->isIn(tmprect,touch))) tmpset.insert(*cit); - ++cit; - } - return tmpset; -} Deleted: trunk/src/map.h =================================================================== --- trunk/src/map.h 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/map.h 2005-02-09 22:08:47 UTC (rev 86) @@ -1,78 +0,0 @@ -#ifndef _MAP_H -#define _MAP_H 1 - -/** \brief Scenario organization - - Loads the corresponding map data (objects) and performs location checks. - \remarks MAP FORMAT: - \remarks "Object class name" "Base image name" "x position" "y position" - "Arg1" "Arg2" "Arg3" - \remarks Each Object handels the arguments for itself, usually "Arg1" - specifies the object name (if the object has no further parameters) - \remarks Defaults: - \remarks x and y default to 0 - \remarks Example: - \remarks Background background.bmp - \remarks Teleporter teleporter.bmp 0 0 20 100 teleporter1 - \todo Improve the map format (eg. support headers) - \todo Move the Caches into the current map as well? - \todo Create a map class inside Scenario? -*/ -class Scenario { - public: - /// Creates a new scenario. To load a specific map, use loadMap(mapname). - Scenario(); - ~Scenario(); - /// Checks where the source rectangle overlaps the destination rectangle. - /// \param src Source rectangle - /// \param dest Destination rectangle - /// \return Hit Directions of overlapping. DIR_ALL if the destination rectangle is inside - /// the source rectangle, NOTHING if the source rectangle is inside the destionation - /// rectangle. - Hit checkPlace(const SDL_Rect& src, const SDL_Rect& dest) const; - /// \param mask Mask for the object types that this function should match - /// (default: all Characters). - /// \param rect Base region of the target area that should be checked. - /// \param touch If true an touch (overlapping of area) is enough for a match, otherwise - /// the center of the specified rectangle has to be inside the target. - /// \param radius This enlarges the base area by this amount into all specified directions - /// (default: 0) - /// \param dir Search directions (default: all) - /// \return A set of characters that are inside the enlarged source rectangle - /// and that match the specified mask. - std::set getCharactersIn(Uint16 mask, const SDL_Rect& rect, bool touch=false, Uint16 radius=0, Uint16 dir=DIR_ALL) const; - /// Returns the directions from the source rectangle to the destination rectangle - /// \remark This may include an enlargment (eg. Olaf) - /// \param src Source rectangle - /// \param dest Destination rectangle - Uint16 getDirection(const SDL_Rect& src, const SDL_Rect& dest) const; - - /// Background - Background* background; - /// Size of the background (map area) - SDL_Rect* area; - /// Current player - Player* player; - /// Image Cache - ImageCache* imgcache; - /// Sound Cache - SoundCache* sndcache; - /// Object pool - ObjectsPool* pool; - /// Animation Handler - AnimHandler* anim; - /// True if the mission failed - bool failed; - ///\brief Loads and initializes the map data - /// - /// Parses the map file and tries to add the objects by using addObjectByName() - /// \param mapname Map file name without the data directory in it - /// \return 0 if a Background was found, -1 if not, -2 if the loading failed - int loadMap(string mapname); - /// Name of the map file - string name; - private: - inline void reinitMap(); -}; - -#endif Modified: trunk/src/monsters_common.cpp =================================================================== --- trunk/src/monsters_common.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/monsters_common.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -6,7 +6,7 @@ #include "sndcache.h" #include "monsters_common.h" //shouldn't be here... -#include "map.h" +#include "scenario.h" #include "players_common.h" Modified: trunk/src/objectpools.cpp =================================================================== --- trunk/src/objectpools.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objectpools.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -1,5 +1,5 @@ #include "common.h" -#include "map.h" +#include "scenario.h" #include "sfxeng.h" #include "sndcache.h" #include "objectpools.h" Modified: trunk/src/objects/baleog.cpp =================================================================== --- trunk/src/objects/baleog.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objects/baleog.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -4,7 +4,7 @@ #include "imgcache.h" #include "sndcache.h" #include "input.h" -#include "map.h" +#include "scenario.h" #include "baleog.h" Modified: trunk/src/objects/bomb.cpp =================================================================== --- trunk/src/objects/bomb.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objects/bomb.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -1,7 +1,7 @@ #include "common.h" //shouldn't be here... #include "objectpools.h" -#include "map.h" +#include "scenario.h" #include "players_common.h" #include "triggered_bomb.h" #include "bomb.h" Modified: trunk/src/objects/door.cpp =================================================================== --- trunk/src/objects/door.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objects/door.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -2,7 +2,7 @@ #include "sndcache.h" #include "sfxeng.h" #include "objects_common.h" -#include "map.h" +#include "scenario.h" #include "door.h" Modified: trunk/src/objects/erik.cpp =================================================================== --- trunk/src/objects/erik.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objects/erik.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -2,7 +2,7 @@ #include "events.h" #include "anim.h" #include "input.h" -#include "map.h" +#include "scenario.h" #include "weapons.h" #include "imgcache.h" #include "sndcache.h" Modified: trunk/src/objects/exit.cpp =================================================================== --- trunk/src/objects/exit.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objects/exit.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -1,7 +1,7 @@ #include "common.h" #include "objectpools.h" //shouldn't be here... -#include "map.h" +#include "scenario.h" #include "players_common.h" #include "exit.h" Modified: trunk/src/objects/fang.cpp =================================================================== --- trunk/src/objects/fang.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objects/fang.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -4,7 +4,7 @@ #include "input.h" #include "imgcache.h" #include "sndcache.h" -#include "map.h" +#include "scenario.h" #include "fang.h" Modified: trunk/src/objects/geyser.cpp =================================================================== --- trunk/src/objects/geyser.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objects/geyser.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -4,7 +4,7 @@ #include "objects_common.h" //shouldn't be here... #include "players_common.h" -#include "map.h" +#include "scenario.h" #include "geyser.h" Modified: trunk/src/objects/olaf.cpp =================================================================== --- trunk/src/objects/olaf.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objects/olaf.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -4,7 +4,7 @@ #include "input.h" #include "imgcache.h" #include "sndcache.h" -#include "map.h" +#include "scenario.h" #include "sfxeng.h" #include "olaf.h" Modified: trunk/src/objects/plant.cpp =================================================================== --- trunk/src/objects/plant.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objects/plant.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -4,7 +4,7 @@ #include "weapons.h" #include "players_common.h" #include "monsters_common.h" -#include "map.h" +#include "scenario.h" #include "plant.h" Plant::Plant(string imagename, Sint16 xcord, Sint16 ycord, Uint16 trecover, string cname): Modified: trunk/src/objects/scorch.cpp =================================================================== --- trunk/src/objects/scorch.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objects/scorch.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -3,7 +3,7 @@ #include "anim.h" #include "input.h" #include "imgcache.h" -#include "map.h" +#include "scenario.h" #include "sndcache.h" #include "scorch.h" Modified: trunk/src/objects/spike.cpp =================================================================== --- trunk/src/objects/spike.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objects/spike.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -4,7 +4,7 @@ #include "weapons.h" #include "players_common.h" #include "monsters_common.h" -#include "map.h" +#include "scenario.h" #include "spike.h" Spike::Spike(string imagename, Sint16 xcord, Sint16 ycord, Uint16 sdir, string oname): Modified: trunk/src/objects/teleport.cpp =================================================================== --- trunk/src/objects/teleport.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objects/teleport.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -4,7 +4,7 @@ #include "objects_common.h" //shouldn't be here... #include "players_common.h" -#include "map.h" +#include "scenario.h" #include "teleport.h" Modified: trunk/src/objects/trigger.cpp =================================================================== --- trunk/src/objects/trigger.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objects/trigger.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -1,6 +1,6 @@ #include "common.h" #include "objectpools.h" -#include "map.h" +#include "scenario.h" #include "objects_common.h" #include "trigger.h" Modified: trunk/src/objects/triggered_bomb.cpp =================================================================== --- trunk/src/objects/triggered_bomb.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objects/triggered_bomb.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -3,7 +3,7 @@ #include "sfxeng.h" #include "weapons.h" #include "characters_common.h" -#include "map.h" +#include "scenario.h" #include "triggered_bomb.h" TriggeredBomb::TriggeredBomb(string imagename, Sint16 xcord, Sint16 ycord, Uint16 tleft, string cname): Modified: trunk/src/objects/water.cpp =================================================================== --- trunk/src/objects/water.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objects/water.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -4,7 +4,7 @@ #include "sndcache.h" #include "weapons.h" //shouldn't be here... -#include "map.h" +#include "scenario.h" #include "characters_common.h" #include "water.h" Modified: trunk/src/objects/zombie.cpp =================================================================== --- trunk/src/objects/zombie.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objects/zombie.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -6,7 +6,7 @@ #include "sndcache.h" #include "sfxeng.h" #include "players_common.h" -#include "map.h" +#include "scenario.h" #include "zombie.h" Modified: trunk/src/objects_common.cpp =================================================================== --- trunk/src/objects_common.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/objects_common.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -4,7 +4,7 @@ #include "events.h" #include "objects_common.h" //HACK! -#include "map.h" +#include "scenario.h" Object::Object(string imagename, Sint16 xcord, Sint16 ycord, string oname): Modified: trunk/src/players_common.cpp =================================================================== --- trunk/src/players_common.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/players_common.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -7,7 +7,7 @@ #include "imgcache.h" #include "sndcache.h" #include "objectpools.h" -#include "map.h" +#include "scenario.h" #include "players_common.h" Copied: trunk/src/scenario.cpp (from rev 85, trunk/src/map.cpp) =================================================================== --- trunk/src/map.cpp 2005-02-09 21:41:07 UTC (rev 85) +++ trunk/src/scenario.cpp 2005-02-09 22:08:47 UTC (rev 86) @@ -0,0 +1,183 @@ +#include "common.h" +#include "objectpools.h" +#include "players_common.h" +#include "imgcache.h" +#include "sndcache.h" +#include "anim.h" +#include "scenario.h" + + +Scenario::Scenario(): + background(NULL), + area(NULL), + player(NULL), + failed(false), + name("") { + cout << "Scenario: ImageCache...\n"; + imgcache=new ImageCache(); + cout << "Scenario: SoundCache...\n"; + sndcache=new SoundCache(); + cout << "Scenario: AnimHandler...\n"; + anim=new AnimHandler(); + cout << "Map: ObjectsPool...\n"; + pool=new ObjectsPool(); +} + +Scenario::~Scenario() { + cout << endl << "Closing map...\n"; + delete pool; + cout << "Map: Deleted Pools...\n"; + if (background) delete background; + cout << "Map: Deleted Background...\n"; + delete anim; + cout << "Scenario: Deleted Animhandler...\n"; + delete sndcache; + cout << "Scenario: Deleted SoundCache...\n"; + delete imgcache; + cout << "Scenario: Deleted ImageCache... (Scenario closed)\n"; +} + +inline void Scenario::reinitMap() { + if (pool && !(pool->empty())) { + delete pool; + pool=new ObjectsPool(); + } else if (!pool) pool=new ObjectsPool(); + if (background) delete background; + background=NULL; + area=NULL; + player=NULL; + name=""; +} + +int Scenario::loadMap(string mapname) { + reinitMap(); + cout << "Loading Map data...\n"; + name=mapname; + ifstream mapfile; + string tmpline; + string image; + string arg1,arg2,arg3; + Uint16 x,y; + background=NULL; + area=NULL; + string loadfile=config.datadir+name; + bool header=false; + + mapfile.open(loadfile.c_str()); + if (mapfile) { + cout << "Loading map configuration file...\n"; + } else { + cout << "Map loading failed: " << (config.datadir+name) << " not found!\n"; + return -2; + } + + //check every line + while (getline(mapfile,tmpline)) { + //parse the header, always start a header with #HEADER and end it with #ENDHEADER! + if (header) { + name.erase(); + arg1.erase(); + arg2.erase(); + arg3.erase(); + std::istringstream tmpstream(tmpline); + tmpstream >> name >> arg1 >> arg2 >> arg3; + if (name[0]=='#') { + if (name=="#ENDHEADER") header=false; + continue; + } + continue; + } + name.erase(); + image.erase(); + x=0; + y=0; + arg1=arg2="0"; + arg3=""; + std::istringstream tmpstream(tmpline); + tmpstream >> name >> image >> x >> y >> arg1 >> arg2 >> arg3; + + //Skip empty lines + if (name.empty()) continue; + //Skip comments + if (name[0]=='#') { + if (name=="#HEADER") header=true; + continue; + } + + if (name=="Background" && (!background)) { + background=new Background(image); + if (background) area=background->getPos(); + //Background has to be first! + } else if (background) { + pool->addObjectbyName(name,image,x,y,arg1,arg2,arg3); + } else { + cout << "No background found yet, skipping " << name << " ...\n"; + } + } + + mapfile.close(); + mapfile.clear(); + + //Has a background been found? + if (background) { + if (pool->playerspool.size()>0) player=*pool->playerspool.begin(); + else player=NULL; + if (player==NULL) cout << "No player found!\n"; + return 0; + } else { + cout << "Map loading failed: No background found!\n"; + return -1; + } +} + +Uint16 Scenario::getDirection(const SDL_Rect& src, const SDL_Rect& dest) const { + Uint16 dir=NOTHING; + if ((src.x+src.w) < (dest.x+dest.w)) dir|=DIR_RIGHT; + if (src.x > dest.x) dir|=DIR_LEFT; + if ((src.y+src.h) < (dest.y+dest.h)) dir|=DIR_DOWN; + if (src.y > dest.y) dir|=DIR_UP; + return dir; +} + +Hit Scenario::checkPlace(const SDL_Rect& src, const SDL_Rect& dest) const { + Hit hit; + hit.enter=NOTHING; + hit.touch=NOTHING; + if (src.x < dest.x) hit.enter|=DIR_LEFT; + if (src.x==dest.x) hit.touch|=DIR_LEFT; + if (src.y < dest.y) hit.enter|=DIR_UP; + if (src.y==dest.y) hit.touch|=DIR_UP; + if ((src.x+src.w) > (dest.x+dest.w)) hit.enter|=DIR_RIGHT; + if ((src.x+src.w)==(dest.x+dest.w)) hit.touch|=DIR_RIGHT; + if ((src.y+src.h) > (dest.y+dest.h)) hit.enter|=DIR_DOWN; + if ((src.y+src.h)==(dest.y+dest.h)) hit.touch|=DIR_DOWN; + return hit; +} + + +std::set Scenario::getCharactersIn(Uint16 mask, const SDL_Rect& rect, bool touch, Uint16 distance, Uint16 dir) const { + SDL_Rect tmprect=rect; + if (dir&DIR_LEFT) { + tmprect.x-=distance; + tmprect.w+=distance; + } + if (dir&DIR_RIGHT) { + tmprect.x+=distance; + tmprect.w+=distance; + } + if (dir&DIR_UP) { + tmprect.y-=distance; + tmprect.h+=distance; + } + if (dir&DIR_DOWN) { + tmprect.y+=distance; + tmprect.h+=distance; + } + std::set tmpset; + character_iterator cit=pool->characterspool.begin(); + while (cit != pool->characterspool.end()) { + if ((((*cit)->getType())&mask) && ((*cit)->isIn(tmprect,touch))) tmpset.insert(*cit); + ++cit; + } + return tmpset; +} Copied: trunk/src/scenario.h (from rev 85, trunk/src/map.h) From DONOTREPLY at icculus.org Wed Feb 9 17:35:03 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 9 Feb 2005 17:35:03 -0500 Subject: r87 - trunk/src Message-ID: <20050209223503.7904.qmail@icculus.org> Author: jonas Date: 2005-02-09 17:35:03 -0500 (Wed, 09 Feb 2005) New Revision: 87 Modified: trunk/src/scenario.cpp Log: small stuff about map loading Modified: trunk/src/scenario.cpp =================================================================== --- trunk/src/scenario.cpp 2005-02-09 22:08:47 UTC (rev 86) +++ trunk/src/scenario.cpp 2005-02-09 22:35:03 UTC (rev 87) @@ -43,6 +43,8 @@ pool=new ObjectsPool(); } else if (!pool) pool=new ObjectsPool(); if (background) delete background; + if (anim) delete anim; + anim=new AnimHandler(); background=NULL; area=NULL; player=NULL; @@ -51,7 +53,6 @@ int Scenario::loadMap(string mapname) { reinitMap(); - cout << "Loading Map data...\n"; name=mapname; ifstream mapfile; string tmpline; @@ -65,9 +66,9 @@ mapfile.open(loadfile.c_str()); if (mapfile) { - cout << "Loading map configuration file...\n"; + cout << "Loading new map: " << loadfile << endl; } else { - cout << "Map loading failed: " << (config.datadir+name) << " not found!\n"; + cout << "Map loading failed: " << loadfile << " not found!\n"; return -2; } From DONOTREPLY at icculus.org Thu Feb 10 18:45:16 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 10 Feb 2005 18:45:16 -0500 Subject: r88 - in trunk: . src Message-ID: <20050210234516.16737.qmail@icculus.org> Author: jonas Date: 2005-02-10 18:45:16 -0500 (Thu, 10 Feb 2005) New Revision: 88 Added: trunk/src/menu.cpp trunk/src/menu.h Modified: trunk/lost_penguins.conf trunk/src/Makefile trunk/src/anim.cpp trunk/src/common.cpp trunk/src/common.h trunk/src/gfxeng.cpp trunk/src/gfxeng.h trunk/src/input.cpp trunk/src/input.h trunk/src/lost_penguins.cpp trunk/src/scenario.cpp Log: Introduced prelimenary menu support: - Added a new abstract class Menu and created a derived TestMenu - The main game loop now checks for the existence of a menu - In game menu switching can be done using the "Escape" key... - InputHandler has now a separate pollMEvents() for menu - The menu has a semitransparent background when used during the game - Most menu related code is either in menu.* (format) or gfxeng.* (displaying) Modified: trunk/lost_penguins.conf =================================================================== --- trunk/lost_penguins.conf 2005-02-09 22:35:03 UTC (rev 87) +++ trunk/lost_penguins.conf 2005-02-10 23:45:16 UTC (rev 88) @@ -1,7 +1,7 @@ #General configuration file datadir /usr/local/share/lost_penguins/ map map2.cfg -full 1 +full 0 width 1024 height 768 bpp 32 \ No newline at end of file Modified: trunk/src/Makefile =================================================================== --- trunk/src/Makefile 2005-02-09 22:35:03 UTC (rev 87) +++ trunk/src/Makefile 2005-02-10 23:45:16 UTC (rev 88) @@ -9,7 +9,7 @@ OBJS = common.o anim.o gfxeng.o input.o font.o lost_penguins.o scenario.o\ objects_common.o sfxeng.o players_common.o monsters_common.o\ characters_common.o objectpools.o weapons.o events.o imgcache.o\ - sndcache.o + sndcache.o menu.o PLUGS = objects.a BIN = ../lost_penguins Modified: trunk/src/anim.cpp =================================================================== --- trunk/src/anim.cpp 2005-02-09 22:35:03 UTC (rev 87) +++ trunk/src/anim.cpp 2005-02-10 23:45:16 UTC (rev 88) @@ -87,6 +87,7 @@ dt=(SDL_GetTicks()-tcurrent); tcurrent=SDL_GetTicks(); + //Game is running normally if (!paused) { //released keys of player if (scenario->player != NULL) { @@ -150,6 +151,7 @@ } else if ((*obit)->isRunning()) (*obit)->updateAnim(dt); ++obit; } + //Game is paused } else { if (input->getState(INPUT_RIGHT)) { input->unsetState(INPUT_RIGHT); Modified: trunk/src/common.cpp =================================================================== --- trunk/src/common.cpp 2005-02-09 22:35:03 UTC (rev 87) +++ trunk/src/common.cpp 2005-02-10 23:45:16 UTC (rev 88) @@ -1,4 +1,5 @@ #include "common.h" +#include "menu.h" ImageCache* imgcache; SoundCache* sndcache; @@ -10,6 +11,8 @@ Font* font2; Config config; bool paused=false; +bool running=false; +Menu* menu; string itos(int i) { std::stringstream s; @@ -22,3 +25,23 @@ else return a=min(0,a-b); } +Menu* setMenu(Menu* newmenu) { + newmenu->setLast(menu); + return menu=newmenu; +} + +Menu* closeMenu() { + if (menu) { + Menu* tmp=menu->getLast(); + delete menu; + return menu=tmp; + } else { + return NULL; + } +} + +void closeMenus() { + while (menu) { + closeMenu(); + } +} Modified: trunk/src/common.h =================================================================== --- trunk/src/common.h 2005-02-09 22:35:03 UTC (rev 87) +++ trunk/src/common.h 2005-02-10 23:45:16 UTC (rev 88) @@ -2,6 +2,9 @@ #define _COMMON_H 1 /// Common header file +/// +/// \todo Create a game class and move almost all remaining global +/// variables/functions there... #include #include #include @@ -37,6 +40,7 @@ class Event; class Weapon; class Animation; +class Menu; typedef std::set::iterator object_iterator; typedef std::set::iterator character_iterator; @@ -111,6 +115,13 @@ string itos(int); /// Helper function boost that increases/decreases the absolute value int boost(int,int); + +/// Set the current menu +Menu* setMenu(Menu* newmenu); +/// Close the current menus +Menu* closeMenu(); +/// Close all menus (menu=NULL) +void closeMenus(); //@} //global variables @@ -135,6 +146,10 @@ extern Font* font2; /// True if the game is paused extern bool paused; +/// True if a map is currently running +extern bool running; +/// Currently used menu, NULL if not inside a menu +extern Menu* menu; //@} #endif Modified: trunk/src/gfxeng.cpp =================================================================== --- trunk/src/gfxeng.cpp 2005-02-09 22:35:03 UTC (rev 87) +++ trunk/src/gfxeng.cpp 2005-02-10 23:45:16 UTC (rev 88) @@ -5,23 +5,39 @@ #include "players_common.h" #include "imgcache.h" #include "scenario.h" +#include "menu.h" #include "gfxeng.h" GraphicsEngine::GraphicsEngine(): + screen(NULL), + menubg(NULL), Dfps(0), Dframes(0), currentfps(0), tcurrent(SDL_GetTicks()), + menu_done(false), show_bar(true), show_fps(true), fullscreen(config.full) { +#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")); } GraphicsEngine::~GraphicsEngine() { delete lifeimage; + if (menubg) SDL_FreeSurface(menubg); SDL_FreeSurface(screen); } @@ -148,6 +164,7 @@ } void GraphicsEngine::renderScene(bool insist) { + resetMenuBG(); if (scenario->background && (!paused || insist)) { //We don't want to change pos! SDL_Rect tmprect,shift,srcpos; @@ -231,3 +248,80 @@ resize(screen->w,screen->h); } } + +void GraphicsEngine::drawMenu() { + if (!menu_done) { + menu_done=true; + //Semitransparent background + setGameMenuBG(); + SDL_BlitSurface(menubg,NULL,screen,NULL); + + menu->font_title->writeCenter(screen,menu->title,0); + + Uint16 h; + for (Uint8 i=0; i< menu->getSize(); i++) { + if (i<=menu->currententry) { + h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-i-1)*DFONT-(menu->getSize()-i-1)*(menu->font->getHeight())-menu->font_high->getHeight())/2; + } else { + h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-i-1)*DFONT-(menu->getSize()-i)*(menu->font->getHeight()))/2; + } + if (i==menu->currententry) menu->font_high->writeCenter(screen,menu->entries[i],h); + else menu->font->writeCenter(screen,menu->entries[i],h); + } + + SDL_Flip(screen); + } +} + +//this could probably be done much easier ;) +inline void GraphicsEngine::setGameMenuBG() { + if (!menubg) { + SDL_Surface* tmp = SDL_CreateRGBSurface ( + SDL_HWSURFACE, + screen->w, + screen->h, + 32, + rmask,gmask,bmask,0); +#ifdef ALPHA + menubg = SDL_CreateRGBSurface ( + SDL_HWSURFACE, + screen->w, + screen->h, + 32, + rmask,gmask,bmask,0); + SDL_BlitSurface(screen,NULL,menubg,NULL); + SDL_SetAlpha(menubg,SDL_SRCALPHA,60); + SDL_FillRect(tmp,NULL,SDL_MapRGB(screen->format,0,0,0)); + SDL_BlitSurface(menubg,NULL,tmp,NULL); + SDL_FreeSurface(menubg); + menubg=SDL_DisplayFormatAlpha(tmp); +#else + SDL_FillRect(tmp,NULL,SDL_MapRGB(screen->format,0,0,0)); + menubg=SDL_DisplayFormat(tmp); +#endif + SDL_FreeSurface(tmp); + } +} + +void GraphicsEngine::setMenuBG(SDL_Surface* menu_background) { + if (menubg) SDL_FreeSurface(menubg); + if (menu_background) { + menubg=menu_background; + } else { + SDL_Surface* tmp = SDL_CreateRGBSurface ( + SDL_HWSURFACE, + screen->w, + screen->h, + 32, + rmask,gmask,bmask,0); + SDL_FillRect(tmp,NULL,SDL_MapRGB(screen->format,0,0,0)); + menubg=SDL_DisplayFormat(tmp); + } +} + +void GraphicsEngine::resetMenuBG() { + if (menubg) { + SDL_FreeSurface(menubg); + menubg=NULL; + } +} Modified: trunk/src/gfxeng.h =================================================================== --- trunk/src/gfxeng.h 2005-02-09 22:35:03 UTC (rev 87) +++ trunk/src/gfxeng.h 2005-02-10 23:45:16 UTC (rev 88) @@ -3,6 +3,7 @@ #define BAR_HEIGHT 138 #define ICON_SIZE 46 +#define DFONT 40 /** \brief Graphics engine @@ -15,35 +16,61 @@ ~GraphicsEngine(); /// Runs SDL_SetVideoMode with the new parameters. void resize(Uint16 width, Uint16 height); - ///\brief update the scene + ///\brief update the scene in a running scenario /// - /// Draws the background and all objects in the pool if the game isn't - /// paused. Optionally also the player bar and/or the current frames per - /// second. + /// If a scenario is running this draws the background and all objects + /// in the pool. If the game is paused, only the player bar is drawn. + /// Optionally also the player bar and/or the current frames per second + /// are displayed. /// \param insist True if the objects should be drawn even if the game /// is paused - void renderScene(bool insist=true); + void renderScene(bool insist=false); void togglePlayerBar(); void toggleFPS(); void toggleFullScreen(); + ///\brief draw the menu + /// + /// If no scenario is running or the scenario was interrupted this will + /// draw the menu. + void drawMenu(); + void updateMenu() { + menu_done=false; + } + void setMenuBG(SDL_Surface* menu_background=NULL); + void resetMenuBG(); + Uint16 getFPS() { + if (show_fps) return currentfps; + else return 0; + } private: + Uint32 rmask; + Uint32 gmask; + Uint32 bmask; + Uint32 amask; inline SDL_Rect clipToBG(SDL_Rect dest) const; - //updates backpos and returns the new shift vector (ignore w,h) + /// updates backpos and returns the new shift vector (ignore w,h) inline SDL_Rect setShift(SDL_Rect center); - //simple vector addition, should be replaced by operator + /// simple vector addition, should be replaced by operator inline SDL_Rect* shiftMapArea(SDL_Rect& area, const SDL_Rect& shift); - //draw player bar + /// draw player bar inline void drawPlayerBar(); - //currently visible part of the map area + /// currently visible part of the map area SDL_Rect vis_map; - //main screen + /// main screen SDL_Surface* screen; - //player bar + /// menu background + SDL_Surface* menubg; + /// sets the menu background while playing a scenario + inline void setGameMenuBG(); + /// player bar SDL_Rect bar; - //player bar + /// symbol for one life of a player Animation* lifeimage; //fps stuff Uint16 Dfps,Dframes,currentfps,tcurrent; + //for drawMenu + bool menu_done; + //visual flags bool show_bar; bool show_fps; bool fullscreen; Modified: trunk/src/input.cpp =================================================================== --- trunk/src/input.cpp 2005-02-09 22:35:03 UTC (rev 87) +++ trunk/src/input.cpp 2005-02-10 23:45:16 UTC (rev 88) @@ -7,6 +7,7 @@ #include "sfxeng.h" #include "scenario.h" #include "objectpools.h" +#include "menu.h" #include "objects_common.h" @@ -19,6 +20,176 @@ InputHandler::~InputHandler() { } +void InputHandler::pollMEvents() { + SDL_Event event; + + while(SDL_PollEvent(&event)) { + switch(event.type) { + // special events + case SDL_VIDEORESIZE: { + gfxeng->resize(event.resize.w, event.resize.h); + gfxeng->renderScene(true); + gfxeng->updateMenu(); + gfxeng->drawMenu(); + break; + } + // keyboard events + case SDL_QUIT: { + quitGame(0); + } + case SDL_KEYUP: { + switch(event.key.keysym.sym) { + case SDLK_LEFT: { + if (state&INPUT_LEFT) setState(INPUTR_LEFT); + state&=~INPUT_LEFT; + break; + } + case SDLK_RIGHT: { + if (state&INPUT_RIGHT) state|=INPUTR_RIGHT; + state&=~INPUT_RIGHT; + break; + } + case SDLK_UP: { + if (state&INPUT_UP) setState(INPUTR_UP); + state&=~INPUT_UP; + break; + } + case SDLK_DOWN: { + if (state&INPUT_DOWN) setState(INPUTR_DOWN); + state&=~INPUT_DOWN; + break; + } + case SDLK_SPACE: { + if (state&INPUT_SP1) setState(INPUTR_SP1); + state&=~INPUT_SP1; + break; + } + case SDLK_LSHIFT: { + if (state&INPUT_SP2) setState(INPUTR_SP2); + state&=~INPUT_SP2; + break; + } + case SDLK_TAB: { + state&=~INPUT_PAUSE; + break; + } + case SDLK_ESCAPE: { + state&=~INPUT_MENU; + break; + } + case SDLK_RETURN: { + if (state&INPUT_ACT) setState(INPUTR_ACT); + state&=~INPUT_ACT; + break; + } + case SDLK_INSERT: { + if (state&INPUT_USE) setState(INPUTR_USE); + state&=~INPUT_USE; + break; + } + case SDLK_DELETE: { + if (state&INPUT_DEL) setState(INPUTR_DEL); + state&=~INPUT_DEL; + break; + } + default: { + break; + } + } + break; + } + case SDL_KEYDOWN: { + switch(event.key.keysym.sym) { + case SDLK_LEFT: { + state|=INPUT_LEFT; + gfxeng->updateMenu(); + break; + } + case SDLK_RIGHT: { + state|=INPUT_RIGHT; + gfxeng->updateMenu(); + break; + } + case SDLK_UP: { + if (state&INPUT_UP) break; + menu->increaseEntry(false); + state|=INPUT_UP; + gfxeng->updateMenu(); + break; + } + case SDLK_DOWN: { + if (state&INPUT_DOWN) break; + menu->increaseEntry(); + state|=INPUT_DOWN; + gfxeng->updateMenu(); + break; + } + case SDLK_SPACE: { + state|=INPUT_SP1; + gfxeng->updateMenu(); + break; + } + case SDLK_LSHIFT: { + state|=INPUT_SP2; + gfxeng->updateMenu(); + break; + } + case SDLK_RETURN: { + state|=INPUT_ACT; + gfxeng->updateMenu(); + break; + } + case SDLK_INSERT: { + state|=INPUT_USE; + gfxeng->updateMenu(); + break; + } + case SDLK_DELETE: { + state|=INPUT_DEL; + gfxeng->updateMenu(); + break; + } + case SDLK_ESCAPE: { + if (state&INPUT_MENU) { + break; + } else if (menu) { + state|=INPUT_MENU; + if (!closeMenu()) { + gfxeng->renderScene(true); + scenario->anim->resetTime(); + sfxeng->resumeMusic(); + } + } else { + state|=INPUT_MENU; + sfxeng->pauseMusic(); + menu=new TestMenu(); + } + gfxeng->updateMenu(); + break; + } + case SDLK_f: { + gfxeng->toggleFullScreen(); + gfxeng->updateMenu(); + break; + } + case SDLK_q: { + quitGame(0); + gfxeng->updateMenu(); + break; + } + default: { + break; + } + } + break; + } + default: { + break; + } + } + } +} + void InputHandler::pollEvents() { SDL_Event event; @@ -30,7 +201,7 @@ gfxeng->renderScene(true); break; } - // keyboard events + // keyboard events case SDL_QUIT: { quitGame(0); } @@ -70,6 +241,10 @@ state&=~INPUT_PAUSE; break; } + case SDLK_ESCAPE: { + state&=~INPUT_MENU; + break; + } case SDLK_RETURN: { if (state&INPUT_ACT) setState(INPUTR_ACT); state&=~INPUT_ACT; @@ -151,6 +326,23 @@ } break; } + case SDLK_ESCAPE: { + if (state&INPUT_MENU) { + break; + } else if (menu) { + state|=INPUT_MENU; + if (!closeMenu()) { + gfxeng->renderScene(true); + scenario->anim->resetTime(); + sfxeng->resumeMusic(); + } + } else { + state|=INPUT_MENU; + sfxeng->pauseMusic(); + menu=new TestMenu(); + } + break; + } case SDLK_F1: { gfxeng->togglePlayerBar(); break; Modified: trunk/src/input.h =================================================================== --- trunk/src/input.h 2005-02-09 22:35:03 UTC (rev 87) +++ trunk/src/input.h 2005-02-10 23:45:16 UTC (rev 88) @@ -21,16 +21,22 @@ #define INPUTR_USE 0x00800000 #define INPUTR_DEL 0x01000000 #define INPUT_PAUSE 0x10000000 +#define INPUT_MENU 0x20000000 /** \brief Handels keyboard events + \remark A key release event which is passed on to the AnimHandler + mustn't be cummulative (see player code as well). Ie. If the event + is triggered twice it should do the same as if once... */ class InputHandler { public: InputHandler(); ~InputHandler(); - /// Check for keyboard events + /// Check for keyboard events in game void pollEvents(); + /// Check for keyboard events in menu + void pollMEvents(); bool getState(Uint32 cstate) { return (state&cstate); } @@ -40,6 +46,9 @@ void unsetState(Uint32 cstate) { state&=~cstate; } + void clearStates() { + state=NOTHING; + } private: /// Information about which buttons are pressed Uint32 state; Modified: trunk/src/lost_penguins.cpp =================================================================== --- trunk/src/lost_penguins.cpp 2005-02-09 22:35:03 UTC (rev 87) +++ trunk/src/lost_penguins.cpp 2005-02-10 23:45:16 UTC (rev 88) @@ -9,6 +9,7 @@ #include "gfxeng.h" #include "sfxeng.h" #include "objectpools.h" +#include "menu.h" #include "players_common.h" @@ -43,22 +44,33 @@ sfxeng=new SoundsEngine(); cout << "Fonts...\n"; font=new Font(imgcache->loadImage("font_arial_white_16_01.png")); - font2=new Font(imgcache->loadImage("font_arial_12_01.bmp")); + font2=new Font(imgcache->loadImage("font_arial_red_16_01.png")); cout << "InputHandler...\n"; input=new InputHandler(); - //TODO: menu, szenarios, etc cout << "Initializing Scenario...\n"; scenario=new Scenario(); + + //TODO: menu, szenarios, etc + + //gfxeng->setMenuBG(); + //menu=new TestMenu(); + scenario->loadMap(config.map); + cout << "Starting game...\n" << endl; - cout << "Starting game...\n" << endl; while (true) { - //Drawing - gfxeng->renderScene(); - //Check input - input->pollEvents(); - //Run Animations - scenario->anim->runAnims(); + if (menu) { + gfxeng->drawMenu(); + input->pollMEvents(); + } else if (running) { + gfxeng->renderScene(); + //Check input + input->pollEvents(); + //Run Animations + scenario->anim->runAnims(); + } else { + quitGame(-6); + } } quitGame(-2); @@ -66,6 +78,7 @@ int quitGame(int errorcode=0) { cout << endl << "Quitting game (exit code: " << errorcode << ")...\n"; + closeMenus(); delete scenario; cout << "Scenario closed...\n"; delete sfxeng; Added: trunk/src/menu.cpp =================================================================== --- trunk/src/menu.cpp 2005-02-09 22:35:03 UTC (rev 87) +++ trunk/src/menu.cpp 2005-02-10 23:45:16 UTC (rev 88) @@ -0,0 +1,32 @@ +#include "common.h" +#include "gfxeng.h" +#include "menu.h" + +Menu::Menu(): + title("MENU"), + last(NULL), + currententry(0), + //don't forget the "::" + font(::font), + font_title(font), + font_high(font2) { +} +Menu::~Menu() { } +void Menu::increaseEntry(bool forward) { + if (forward) { + if (currententry<(entries.size()-1)) currententry++; + } else { + if (currententry>0) currententry--; + } +} + +TestMenu::TestMenu(): Menu() { init(); } +void TestMenu::act() { } +void TestMenu::init() { + title="-== TEST MENU ==-"; + entries.resize(4); + entries[0]="FPS: " + itos(gfxeng->getFPS()); + entries[1]="Start Game"; + entries[2]="Configuration"; + entries[3]="Quit"; +} Added: trunk/src/menu.h =================================================================== --- trunk/src/menu.h 2005-02-09 22:35:03 UTC (rev 87) +++ trunk/src/menu.h 2005-02-10 23:45:16 UTC (rev 88) @@ -0,0 +1,66 @@ +#ifndef _MENU_H +#define _MENU_H 1 + +/** \brief abstract menu base class + + Abstract base class for menus. The main part is in the constructor and in the + virtual function act(), overload it in the child classes. Only the base class + is needed to draw the menu in gfxeng. The background depends from where the + menu is called. + + \todo Create the actual menus (StartMenu, etc)... +*/ +class Menu { + friend class GraphicsEngine; + public: + Menu(); + virtual ~Menu(); + /// Name of the menu + string title; + /// Main menu function, depends on currententry (changed by input), overload this. + virtual void act() = 0; + void setLast(Menu* lastmenu) { + last=lastmenu; + } + Menu* getLast() { + return last; + } + Uint8 getSize() { + return entries.size(); + } + void increaseEntry(bool forward=true); + protected: + /// Pointer to the last used menu. NULL if there is no last menu. + Menu* last; + /// Currently selected menu entry + Uint8 currententry; + /// List of all Menu entry names + std::vector 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; +}; + +class StartMenu : public Menu { + public: + StartMenu(); + virtual ~StartMenu(); + virtual void act(); + private: + /// Helper function + void init(); +}; + +class TestMenu : public Menu { + public: + TestMenu(); + virtual void act(); + private: + /// Helper function + void init(); +}; + +#endif Modified: trunk/src/scenario.cpp =================================================================== --- trunk/src/scenario.cpp 2005-02-09 22:35:03 UTC (rev 87) +++ trunk/src/scenario.cpp 2005-02-10 23:45:16 UTC (rev 88) @@ -124,6 +124,7 @@ 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 Fri Feb 18 05:27:33 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 18 Feb 2005 05:27:33 -0500 Subject: r89 - trunk/src Message-ID: <20050218102733.3344.qmail@icculus.org> Author: jonas Date: 2005-02-18 05:27:33 -0500 (Fri, 18 Feb 2005) New Revision: 89 Modified: trunk/src/gfxeng.h trunk/src/input.cpp trunk/src/lost_penguins.cpp trunk/src/menu.cpp trunk/src/menu.h Log: more menu stuff Modified: trunk/src/gfxeng.h =================================================================== --- trunk/src/gfxeng.h 2005-02-10 23:45:16 UTC (rev 88) +++ trunk/src/gfxeng.h 2005-02-18 10:27:33 UTC (rev 89) @@ -11,6 +11,7 @@ frames per seconds. Always run time resizing and fullscreen switching. */ class GraphicsEngine { + friend class ConfigMenu; public: GraphicsEngine(); ~GraphicsEngine(); @@ -42,7 +43,7 @@ if (show_fps) return currentfps; else return 0; } - private: + protected: Uint32 rmask; Uint32 gmask; Uint32 bmask; Modified: trunk/src/input.cpp =================================================================== --- trunk/src/input.cpp 2005-02-10 23:45:16 UTC (rev 88) +++ trunk/src/input.cpp 2005-02-18 10:27:33 UTC (rev 89) @@ -135,7 +135,9 @@ break; } case SDLK_RETURN: { + if (state&INPUT_ACT) break; state|=INPUT_ACT; + menu->act(); gfxeng->updateMenu(); break; } @@ -162,7 +164,7 @@ } else { state|=INPUT_MENU; sfxeng->pauseMusic(); - menu=new TestMenu(); + menu=new GameMenu(); } gfxeng->updateMenu(); break; @@ -339,7 +341,7 @@ } else { state|=INPUT_MENU; sfxeng->pauseMusic(); - menu=new TestMenu(); + menu=new GameMenu(); } break; } Modified: trunk/src/lost_penguins.cpp =================================================================== --- trunk/src/lost_penguins.cpp 2005-02-10 23:45:16 UTC (rev 88) +++ trunk/src/lost_penguins.cpp 2005-02-18 10:27:33 UTC (rev 89) @@ -33,6 +33,7 @@ } SDL_ShowCursor(SDL_DISABLE); SDL_SetEventFilter(filterEvents); + system(config.datadir.c_str()); cout << "ImageCache...\n"; imgcache=new ImageCache(); @@ -50,14 +51,9 @@ cout << "Initializing Scenario...\n"; scenario=new Scenario(); - //TODO: menu, szenarios, etc + gfxeng->setMenuBG(); + menu=new StartMenu(); - //gfxeng->setMenuBG(); - //menu=new TestMenu(); - - scenario->loadMap(config.map); - cout << "Starting game...\n" << endl; - while (true) { if (menu) { gfxeng->drawMenu(); Modified: trunk/src/menu.cpp =================================================================== --- trunk/src/menu.cpp 2005-02-10 23:45:16 UTC (rev 88) +++ trunk/src/menu.cpp 2005-02-18 10:27:33 UTC (rev 89) @@ -1,5 +1,8 @@ #include "common.h" +#include "scenario.h" +#include "anim.h" #include "gfxeng.h" +#include "sfxeng.h" #include "menu.h" Menu::Menu(): @@ -20,13 +23,122 @@ } } -TestMenu::TestMenu(): Menu() { init(); } -void TestMenu::act() { } -void TestMenu::init() { - title="-== TEST MENU ==-"; + +StartMenu::StartMenu(): Menu() { + title="-== MAIN MENU ==-"; entries.resize(4); - entries[0]="FPS: " + itos(gfxeng->getFPS()); - entries[1]="Start Game"; + update(); +} +void StartMenu::act() { + switch (currententry) { + case 0: { + if ((config.map!="") && (scenario->loadMap(config.map)==0)) { + closeMenu(); + cout << "Starting game...\n" << endl; + } else { + cout << "Select a valid map first...\n" << endl; + } + break; + } + case 1: { + setMenu(new MapMenu()); + break; + } + case 2: { + setMenu(new ConfigMenu()); + break; + } + case 3: { + quitGame(0); + break; + } + default: { + break; + } + } +} +void StartMenu::update() { + entries[0]="Start Game"; + entries[1]="Map selection"; entries[2]="Configuration"; entries[3]="Quit"; } + + +GameMenu::GameMenu(): Menu() { + title="-== GAME MENU ==-"; + entries.resize(3); + update(); +} +void GameMenu::act() { + switch (currententry) { + case 0: { + if (!closeMenu()) { + gfxeng->renderScene(true); + scenario->anim->resetTime(); + sfxeng->resumeMusic(); + } + break; + } + case 1: { + setMenu(new ConfigMenu()); + break; + } + case 2: { + quitGame(0); + break; + } + default: { + break; + } + } +} +void GameMenu::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); + update(); +} +void MapMenu::act() { +//TODO: if (currententry>C) open entries[currententry] + .cfg... +} +void MapMenu::update() { +} + + +ConfigMenu::ConfigMenu(): Menu() { + title="-== CONFIGURATION MENU ==-"; + entries.resize(2); + update(); +} +void ConfigMenu::act() { + switch (currententry) { + case 0: { + gfxeng->toggleFPS(); + update(); + gfxeng->updateMenu(); + break; + } + case 1: { + gfxeng->togglePlayerBar(); + gfxeng->renderScene(true); + update(); + gfxeng->updateMenu(); + break; + } + default: { + break; + } + } +} +void ConfigMenu::update() { + entries[0]="Show FPS: "+string((gfxeng->show_fps) ? "ON" : "OFF"); + entries[1]="Show Player Bar: "+string((gfxeng->show_bar) ? "ON" : "OFF"); +} + Modified: trunk/src/menu.h =================================================================== --- trunk/src/menu.h 2005-02-10 23:45:16 UTC (rev 88) +++ trunk/src/menu.h 2005-02-18 10:27:33 UTC (rev 89) @@ -47,20 +47,37 @@ class StartMenu : public Menu { public: StartMenu(); - virtual ~StartMenu(); virtual void act(); private: /// Helper function - void init(); + void update(); }; -class TestMenu : public Menu { +class GameMenu : public Menu { public: - TestMenu(); + GameMenu(); virtual void act(); private: /// Helper function - void init(); + void update(); }; +class MapMenu : public Menu { + public: + MapMenu(); + virtual void act(); + private: + /// Helper function + void update(); +}; + +class ConfigMenu : public Menu { + public: + ConfigMenu(); + virtual void act(); + private: + /// Helper function + void update(); +}; + #endif From DONOTREPLY at icculus.org Fri Feb 18 08:39:13 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 18 Feb 2005 08:39:13 -0500 Subject: r90 - tags Message-ID: <20050218133913.14957.qmail@icculus.org> Author: jonas Date: 2005-02-18 08:39:13 -0500 (Fri, 18 Feb 2005) New Revision: 90 Added: tags/rel-0-1-6/ Log: Released version 0.1.6 Copied: tags/rel-0-1-6 (from rev 89, trunk) From DONOTREPLY at icculus.org Sun Feb 20 16:39:26 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 20 Feb 2005 16:39:26 -0500 Subject: r91 - in trunk/src: . objects Message-ID: <20050220213926.17159.qmail@icculus.org> Author: jonas Date: 2005-02-20 16:39:26 -0500 (Sun, 20 Feb 2005) New Revision: 91 Added: trunk/src/physics.cpp trunk/src/physics.h Removed: trunk/src/anim.cpp trunk/src/anim.h Modified: trunk/src/Makefile trunk/src/characters_common.cpp trunk/src/common.h trunk/src/events.cpp trunk/src/events.h trunk/src/gfxeng.cpp trunk/src/input.cpp trunk/src/input.h trunk/src/lost_penguins.cpp trunk/src/menu.cpp trunk/src/monsters_common.cpp trunk/src/objects/baleog.cpp trunk/src/objects/erik.cpp trunk/src/objects/fang.cpp trunk/src/objects/olaf.cpp trunk/src/objects/scorch.cpp trunk/src/objects/zombie.cpp trunk/src/objects_common.cpp trunk/src/objects_common.h trunk/src/players_common.cpp trunk/src/scenario.cpp trunk/src/scenario.h Log: Divided anim.* into animation.* and physics.*. Renamed AnimHandler into PhysicHandler. The name is a bit misleading (bad): PhysicHandler is responsible for changing (updating) the game state during one time period (one game loop). It might be used later to work as a mediator between objects... Modified: trunk/src/Makefile =================================================================== --- trunk/src/Makefile 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/Makefile 2005-02-20 21:39:26 UTC (rev 91) @@ -6,10 +6,10 @@ SDL = `sdl-config --cflags` SDL_LINK = `sdl-config --libs` -lSDL_mixer -lSDL_image -ldl -rdynamic -OBJS = common.o anim.o gfxeng.o input.o font.o lost_penguins.o scenario.o\ +OBJS = common.o gfxeng.o input.o font.o lost_penguins.o scenario.o\ objects_common.o sfxeng.o players_common.o monsters_common.o\ characters_common.o objectpools.o weapons.o events.o imgcache.o\ - sndcache.o menu.o + sndcache.o physics.o animation.o menu.o PLUGS = objects.a BIN = ../lost_penguins Deleted: trunk/src/anim.cpp =================================================================== --- trunk/src/anim.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/anim.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -1,170 +0,0 @@ -#include "common.h" -#include "input.h" -#include "gfxeng.h" -#include "objectpools.h" -#include "players_common.h" -#include "scenario.h" -#include "anim.h" - - -Animation::Animation(SDL_Surface* anim_image, Uint16 max_num, Uint16 total_time, bool an_once): - size(max_num), - time(total_time), - num(0), - tcurrent(0), - once(an_once) { - if (time==0 || once) running=false; - else running=true; - frame.image=anim_image; - w=(Uint16)((frame.image->w)/size); - h=frame.image->h; - frame.pos.x=0; - frame.pos.y=0; - frame.pos.w=w; - frame.pos.h=h; -} - -Animation::Animation(Uint16 width, SDL_Surface* anim_image, Uint16 max_num, Uint16 total_time, bool an_once): - size(max_num), - time(total_time), - num(0), - tcurrent(0), - once(an_once) { - if (time==0 || once) running=false; - else running=true; - frame.image=anim_image; - w=width; - h=frame.image->h; - frame.pos.x=0; - frame.pos.y=0; - frame.pos.w=w; - frame.pos.h=h; -} - -Animation::~Animation() { } - -bool Animation::updateAnim(Uint16 dt) { - if (!running) return false; - tcurrent+=dt; - if (tcurrent < time) { - num=(Uint16)((tcurrent*size)/time); - if (num>=size) num=0; - } else if (once || time==0) { - num=size; - tcurrent=time; - running=false; - } else { - num=0; - tcurrent=0; - } - frame.pos.x=num*w; - if (running) return true; - else return false; -//The solution below would be better but it won't work with the 2nd constructor -// frame.pos.x=(Uint16)((num*frame.image->w)/size); -} - -const Frame& Animation::setFrame(Uint16 num) { - frame.pos.x=num*w; - return frame; -} - -AnimHandler::AnimHandler(): - tstart(SDL_GetTicks()), - dt(0) { - tcurrent=tstart; -} - -AnimHandler::~AnimHandler() { -} - -Uint16 AnimHandler::resetTime() { - dt=0; - return (tcurrent=SDL_GetTicks()); -} - -void AnimHandler::runAnims() { - dt=(SDL_GetTicks()-tcurrent); - tcurrent=SDL_GetTicks(); - - //Game is running normally - if (!paused) { - //released keys of player - if (scenario->player != NULL) { - if (input->getState(INPUTR_USE)) scenario->player->in_use(-1); - input->unsetState(INPUTR_USE); - if (input->getState(INPUTR_ACT)) scenario->player->in_act(-1); - input->unsetState(INPUTR_ACT); - if (input->getState(INPUTR_RIGHT)) scenario->player->in_right(-1); - input->unsetState(INPUTR_RIGHT); - if (input->getState(INPUTR_LEFT)) scenario->player->in_left(-1); - input->unsetState(INPUTR_LEFT); - if (input->getState(INPUTR_SP1)) scenario->player->in_sp1(-1); - input->unsetState(INPUTR_SP1); - if (input->getState(INPUTR_SP2)) scenario->player->in_sp2(-1); - input->unsetState(INPUTR_SP2); - if (input->getState(INPUTR_UP)) scenario->player->in_up(-1); - input->unsetState(INPUTR_UP); - if (input->getState(INPUTR_DOWN)) scenario->player->in_down(-1); - input->unsetState(INPUTR_DOWN); - input->unsetState(INPUTR_DEL); - } - 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; - } - //handle current (new) scenario->player - if ((scenario->player!=NULL) && (!(scenario->player->getState(ESTATE_BUSY)))) { - if (input->getState(INPUT_USE)) scenario->player->in_use(dt); - if (input->getState(INPUT_ACT)) scenario->player->in_act(dt); - if (input->getState(INPUT_RIGHT)) scenario->player->in_right(dt); - if (input->getState(INPUT_LEFT)) scenario->player->in_left(dt); - if ((!(scenario->player->getState(ESTATE_RUN)))||scenario->player->getState(ESTATE_ABORT)) { - if (input->getState(INPUT_SP1)) scenario->player->in_sp1(dt); - if (input->getState(INPUT_SP2)) scenario->player->in_sp2(dt); - } - if (input->getState(INPUT_UP)) scenario->player->in_up(dt); - if (input->getState(INPUT_DOWN)) scenario->player->in_down(dt); - } - //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; - } - //Game is paused - } else { - if (input->getState(INPUT_RIGHT)) { - input->unsetState(INPUT_RIGHT); - scenario->player->switchItem(true); - } - if (input->getState(INPUT_LEFT)) { - input->unsetState(INPUT_LEFT); - scenario->player->switchItem(false); - } - if (input->getState(INPUT_DEL)) { - input->unsetState(INPUT_DEL); - scenario->player->dropItem(); - gfxeng->renderScene(true); - } - } -} Deleted: trunk/src/anim.h =================================================================== --- trunk/src/anim.h 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/anim.h 2005-02-20 21:39:26 UTC (rev 91) @@ -1,92 +0,0 @@ -#ifndef _ANIM_H -#define _ANIM_H 1 - -/** \brief A container for frames. - - Animation format: a horizontal strip (image) with (num) frames - \todo Change this to an offset matrix or something similar or give each row a different animation -*/ -class Animation { - public: - /// \brief Initialize the animation - /// \param image Image used for the animation - /// \param max_num Number of frames (will devide the image horizontally accordingly) - /// \param total_time Duration of the animation, if set to 0 assume it's one still image - /// \param once If true it run the animation only once when called by \fn start() - Animation(SDL_Surface* image, Uint16 max_num=1, Uint16 total_time=0, bool once=false); - /// \brief Initialize the animation - /// \param width Image width used from the left side - /// \param image Image used for the animation - /// \param max_num Number of frames (will devide the image horizontally accordingly) - /// \param total_time Duration of the animation, if set to 0 assume it's one still image - /// \param once If true: Run the animation only once when called by \fn start() - Animation(Uint16 width, SDL_Surface* image, Uint16 max_num=1, Uint16 total_time=0, bool once=false); - ~Animation(); - /// Updates a running animation and stops it if necessary - /// return True if the animation is still running - /// \todo This should be more advanced - bool updateAnim(Uint16 dt); - /// Updates the frame status of a frame series (usually when not running) - /// return Current frame - const Frame& setFrame(Uint16 nr); - /// Starts an (usually non running) animation - void start() { - num=0; - tcurrent=0; - running=true; - } - const Frame& getFrame() const { - return frame; - } - Frame getFrame(Uint16 nr) const { - Frame newframe=frame; - newframe.pos.x=nr*w; - return newframe; - } - Uint16 getWidth() const { - return w; - } - Uint16 getHeight() const { - return h; - } - /// return True if the animation is running - bool isRunning() const { - return running; - } - private: - /// Frame pointer - Frame frame; - /// Number of frames - Uint16 size; - /// Total time (in ms) - Uint16 time; - /// Frame size - Uint16 w; - Uint16 h; - /// Current frame number - Uint16 num; - /// Current time position (in ms) - Uint16 tcurrent; - /// frame series or running? - bool running; - /// play the animation only once? - bool once; -}; - -/** \brief Updates all game states and animations - -*/ -class AnimHandler { - public: - AnimHandler(); - ~AnimHandler(); - /// Updates all game states and animations - void runAnims(); - /// Resets the current time - /// \return New current time - Uint16 resetTime(); - private: - Uint16 tstart, tcurrent, dt; -}; - -#endif Modified: trunk/src/characters_common.cpp =================================================================== --- trunk/src/characters_common.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/characters_common.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -1,5 +1,5 @@ #include "common.h" -#include "anim.h" +#include "animation.h" #include "events.h" #include "scenario.h" #include "weapons.h" Modified: trunk/src/common.h =================================================================== --- trunk/src/common.h 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/common.h 2005-02-20 21:39:26 UTC (rev 91) @@ -35,7 +35,7 @@ class Background; class Scenario; class InputHandler; -class AnimHandler; +class PhysicHandler; class Font; class Event; class Weapon; Modified: trunk/src/events.cpp =================================================================== --- trunk/src/events.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/events.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -1,6 +1,6 @@ #include "common.h" #include "events.h" -#include "anim.h" +#include "animation.h" #include "weapons.h" #include "scenario.h" #include "sfxeng.h" Modified: trunk/src/events.h =================================================================== --- trunk/src/events.h 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/events.h 2005-02-20 21:39:26 UTC (rev 91) @@ -9,7 +9,7 @@ /** \brief Base class for events (non instantanious effects) - Organize effects that aren't instantanious. Updated by AnimHandler, usually + Organize effects that aren't instantanious. Updated by PhysicHandler, usually a member of an Object (controlled by the object). An effect can be delayed and has a certain run period (marked by a state). */ Modified: trunk/src/gfxeng.cpp =================================================================== --- trunk/src/gfxeng.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/gfxeng.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -1,6 +1,6 @@ #include "common.h" #include "font.h" -#include "anim.h" +#include "animation.h" #include "objectpools.h" #include "players_common.h" #include "imgcache.h" Modified: trunk/src/input.cpp =================================================================== --- trunk/src/input.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/input.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -1,6 +1,5 @@ #include "common.h" #include "events.h" -#include "anim.h" #include "input.h" #include "sndcache.h" #include "gfxeng.h" @@ -8,6 +7,7 @@ #include "scenario.h" #include "objectpools.h" #include "menu.h" +#include "physics.h" #include "objects_common.h" @@ -158,7 +158,7 @@ state|=INPUT_MENU; if (!closeMenu()) { gfxeng->renderScene(true); - scenario->anim->resetTime(); + scenario->physic->resetTime(); sfxeng->resumeMusic(); } } else { @@ -318,7 +318,7 @@ } else if (paused) { state|=INPUT_PAUSE; paused=false; - scenario->anim->resetTime(); + scenario->physic->resetTime(); sfxeng->resumeMusic(); } else { state|=INPUT_PAUSE; @@ -335,7 +335,7 @@ state|=INPUT_MENU; if (!closeMenu()) { gfxeng->renderScene(true); - scenario->anim->resetTime(); + scenario->physic->resetTime(); sfxeng->resumeMusic(); } } else { Modified: trunk/src/input.h =================================================================== --- trunk/src/input.h 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/input.h 2005-02-20 21:39:26 UTC (rev 91) @@ -25,7 +25,7 @@ /** \brief Handels keyboard events - \remark A key release event which is passed on to the AnimHandler + \remark A key release event which is passed on to the PhysicHandler mustn't be cummulative (see player code as well). Ie. If the event is triggered twice it should do the same as if once... */ Modified: trunk/src/lost_penguins.cpp =================================================================== --- trunk/src/lost_penguins.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/lost_penguins.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -1,6 +1,6 @@ #include "common.h" #include "events.h" -#include "anim.h" +#include "physics.h" #include "input.h" #include "font.h" #include "scenario.h" @@ -63,7 +63,7 @@ //Check input input->pollEvents(); //Run Animations - scenario->anim->runAnims(); + scenario->physic->update(); } else { quitGame(-6); } Modified: trunk/src/menu.cpp =================================================================== --- trunk/src/menu.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/menu.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -1,6 +1,6 @@ #include "common.h" #include "scenario.h" -#include "anim.h" +#include "physics.h" #include "gfxeng.h" #include "sfxeng.h" #include "menu.h" @@ -75,7 +75,7 @@ case 0: { if (!closeMenu()) { gfxeng->renderScene(true); - scenario->anim->resetTime(); + scenario->physic->resetTime(); sfxeng->resumeMusic(); } break; Modified: trunk/src/monsters_common.cpp =================================================================== --- trunk/src/monsters_common.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/monsters_common.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -1,5 +1,5 @@ #include "common.h" -#include "anim.h" +#include "animation.h" #include "weapons.h" #include "events.h" #include "sfxeng.h" Modified: trunk/src/objects/baleog.cpp =================================================================== --- trunk/src/objects/baleog.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/objects/baleog.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -1,6 +1,6 @@ #include "common.h" #include "events.h" -#include "anim.h" +#include "animation.h" #include "imgcache.h" #include "sndcache.h" #include "input.h" Modified: trunk/src/objects/erik.cpp =================================================================== --- trunk/src/objects/erik.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/objects/erik.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -1,6 +1,6 @@ #include "common.h" #include "events.h" -#include "anim.h" +#include "animation.h" #include "input.h" #include "scenario.h" #include "weapons.h" Modified: trunk/src/objects/fang.cpp =================================================================== --- trunk/src/objects/fang.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/objects/fang.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -1,6 +1,6 @@ #include "common.h" #include "events.h" -#include "anim.h" +#include "animation.h" #include "input.h" #include "imgcache.h" #include "sndcache.h" Modified: trunk/src/objects/olaf.cpp =================================================================== --- trunk/src/objects/olaf.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/objects/olaf.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -1,6 +1,6 @@ #include "common.h" #include "events.h" -#include "anim.h" +#include "animation.h" #include "input.h" #include "imgcache.h" #include "sndcache.h" Modified: trunk/src/objects/scorch.cpp =================================================================== --- trunk/src/objects/scorch.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/objects/scorch.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -1,6 +1,6 @@ #include "common.h" #include "events.h" -#include "anim.h" +#include "animation.h" #include "input.h" #include "imgcache.h" #include "scenario.h" Modified: trunk/src/objects/zombie.cpp =================================================================== --- trunk/src/objects/zombie.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/objects/zombie.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -1,6 +1,6 @@ #include "common.h" #include "events.h" -#include "anim.h" +#include "animation.h" #include "weapons.h" #include "imgcache.h" #include "sndcache.h" Modified: trunk/src/objects_common.cpp =================================================================== --- trunk/src/objects_common.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/objects_common.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -1,6 +1,6 @@ #include "common.h" #include "imgcache.h" -#include "anim.h" +#include "animation.h" #include "events.h" #include "objects_common.h" //HACK! Modified: trunk/src/objects_common.h =================================================================== --- trunk/src/objects_common.h 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/objects_common.h 2005-02-20 21:39:26 UTC (rev 91) @@ -118,7 +118,7 @@ /// Schedules a new event and cancels any currently running event /// \param ev New event virtual void setEvent(Event* ev); - /// Updates the event (run by the AnimHandler) and react on the new event + /// Updates the event (run by the PhysicHandler) and react on the new event /// state (start, end or cancel an event). /// \return New event state Uint16 updateEvents(Uint16 dt); Copied: trunk/src/physics.cpp (from rev 90, trunk/src/anim.cpp) =================================================================== --- trunk/src/anim.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/physics.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -0,0 +1,108 @@ +#include "common.h" +#include "input.h" +#include "gfxeng.h" +#include "objectpools.h" +#include "players_common.h" +#include "scenario.h" +#include "physics.h" + + +PhysicHandler::PhysicHandler(): + tstart(SDL_GetTicks()), + dt(0) { + tcurrent=tstart; +} + +PhysicHandler::~PhysicHandler() { +} + +Uint16 PhysicHandler::resetTime() { + dt=0; + return (tcurrent=SDL_GetTicks()); +} + +void PhysicHandler::update() { + dt=(SDL_GetTicks()-tcurrent); + tcurrent=SDL_GetTicks(); + + //Game is running normally + if (!paused) { + //released keys of player + if (scenario->player != NULL) { + if (input->getState(INPUTR_USE)) scenario->player->in_use(-1); + input->unsetState(INPUTR_USE); + if (input->getState(INPUTR_ACT)) scenario->player->in_act(-1); + input->unsetState(INPUTR_ACT); + if (input->getState(INPUTR_RIGHT)) scenario->player->in_right(-1); + input->unsetState(INPUTR_RIGHT); + if (input->getState(INPUTR_LEFT)) scenario->player->in_left(-1); + input->unsetState(INPUTR_LEFT); + if (input->getState(INPUTR_SP1)) scenario->player->in_sp1(-1); + input->unsetState(INPUTR_SP1); + if (input->getState(INPUTR_SP2)) scenario->player->in_sp2(-1); + input->unsetState(INPUTR_SP2); + if (input->getState(INPUTR_UP)) scenario->player->in_up(-1); + input->unsetState(INPUTR_UP); + if (input->getState(INPUTR_DOWN)) scenario->player->in_down(-1); + input->unsetState(INPUTR_DOWN); + input->unsetState(INPUTR_DEL); + } + 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; + } + //handle current (new) scenario->player + if ((scenario->player!=NULL) && (!(scenario->player->getState(ESTATE_BUSY)))) { + if (input->getState(INPUT_USE)) scenario->player->in_use(dt); + if (input->getState(INPUT_ACT)) scenario->player->in_act(dt); + if (input->getState(INPUT_RIGHT)) scenario->player->in_right(dt); + if (input->getState(INPUT_LEFT)) scenario->player->in_left(dt); + if ((!(scenario->player->getState(ESTATE_RUN)))||scenario->player->getState(ESTATE_ABORT)) { + if (input->getState(INPUT_SP1)) scenario->player->in_sp1(dt); + if (input->getState(INPUT_SP2)) scenario->player->in_sp2(dt); + } + if (input->getState(INPUT_UP)) scenario->player->in_up(dt); + if (input->getState(INPUT_DOWN)) scenario->player->in_down(dt); + } + //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; + } + //Game is paused + } else { + if (input->getState(INPUT_RIGHT)) { + input->unsetState(INPUT_RIGHT); + scenario->player->switchItem(true); + } + if (input->getState(INPUT_LEFT)) { + input->unsetState(INPUT_LEFT); + scenario->player->switchItem(false); + } + if (input->getState(INPUT_DEL)) { + input->unsetState(INPUT_DEL); + scenario->player->dropItem(); + gfxeng->renderScene(true); + } + } +} Copied: trunk/src/physics.h (from rev 90, trunk/src/anim.h) =================================================================== --- trunk/src/anim.h 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/physics.h 2005-02-20 21:39:26 UTC (rev 91) @@ -0,0 +1,20 @@ +#ifndef _PHYSICS_H +#define _PHYSICS_H 1 + +/** \brief Updates all game states and animations, acts as a Mediator between objects + +*/ +class PhysicHandler { + public: + PhysicHandler(); + ~PhysicHandler(); + /// Updates all game states and animations + void update(); + /// Resets the current time + /// \return New current time + Uint16 resetTime(); + private: + Uint16 tstart, tcurrent, dt; +}; + +#endif Modified: trunk/src/players_common.cpp =================================================================== --- trunk/src/players_common.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/players_common.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -1,7 +1,7 @@ #include "common.h" #include "events.h" #include "input.h" -#include "anim.h" +#include "animation.h" #include "weapons.h" #include "sfxeng.h" #include "imgcache.h" Modified: trunk/src/scenario.cpp =================================================================== --- trunk/src/scenario.cpp 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/scenario.cpp 2005-02-20 21:39:26 UTC (rev 91) @@ -3,7 +3,7 @@ #include "players_common.h" #include "imgcache.h" #include "sndcache.h" -#include "anim.h" +#include "physics.h" #include "scenario.h" @@ -17,8 +17,8 @@ imgcache=new ImageCache(); cout << "Scenario: SoundCache...\n"; sndcache=new SoundCache(); - cout << "Scenario: AnimHandler...\n"; - anim=new AnimHandler(); + cout << "Scenario: PhysicHandler...\n"; + physic=new PhysicHandler(); cout << "Map: ObjectsPool...\n"; pool=new ObjectsPool(); } @@ -29,8 +29,8 @@ cout << "Map: Deleted Pools...\n"; if (background) delete background; cout << "Map: Deleted Background...\n"; - delete anim; - cout << "Scenario: Deleted Animhandler...\n"; + delete physic; + cout << "Scenario: Deleted PhysicHandler...\n"; delete sndcache; cout << "Scenario: Deleted SoundCache...\n"; delete imgcache; @@ -43,8 +43,8 @@ pool=new ObjectsPool(); } else if (!pool) pool=new ObjectsPool(); if (background) delete background; - if (anim) delete anim; - anim=new AnimHandler(); + if (physic) delete physic; + physic=new PhysicHandler(); background=NULL; area=NULL; player=NULL; Modified: trunk/src/scenario.h =================================================================== --- trunk/src/scenario.h 2005-02-18 13:39:13 UTC (rev 90) +++ trunk/src/scenario.h 2005-02-20 21:39:26 UTC (rev 91) @@ -59,16 +59,16 @@ SoundCache* sndcache; /// Object pool ObjectsPool* pool; - /// Animation Handler - AnimHandler* anim; - /// True if the mission failed - bool failed; + /// Physic Handler + PhysicHandler* physic; ///\brief Loads and initializes the map data /// /// Parses the map file and tries to add the objects by using addObjectByName() /// \param mapname Map file name without the data directory in it /// \return 0 if a Background was found, -1 if not, -2 if the loading failed int loadMap(string mapname); + /// True if the mission failed + bool failed; /// Name of the map file string name; private: From DONOTREPLY at icculus.org Tue Feb 22 08:36:33 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 22 Feb 2005 08:36:33 -0500 Subject: r92 - trunk/src Message-ID: <20050222133633.31490.qmail@icculus.org> Author: jonas Date: 2005-02-22 08:36:33 -0500 (Tue, 22 Feb 2005) New Revision: 92 Added: trunk/src/animation.cpp trunk/src/animation.h Log: 100l, forgot the animation.* stuff Added: trunk/src/animation.cpp =================================================================== --- trunk/src/animation.cpp 2005-02-20 21:39:26 UTC (rev 91) +++ trunk/src/animation.cpp 2005-02-22 13:36:33 UTC (rev 92) @@ -0,0 +1,65 @@ +#include "common.h" +#include "animation.h" + +Animation::Animation(SDL_Surface* anim_image, Uint16 max_num, Uint16 total_time, bool an_once): + size(max_num), + time(total_time), + num(0), + tcurrent(0), + once(an_once) { + if (time==0 || once) running=false; + else running=true; + frame.image=anim_image; + w=(Uint16)((frame.image->w)/size); + h=frame.image->h; + frame.pos.x=0; + frame.pos.y=0; + frame.pos.w=w; + frame.pos.h=h; +} + +Animation::Animation(Uint16 width, SDL_Surface* anim_image, Uint16 max_num, Uint16 total_time, bool an_once): + size(max_num), + time(total_time), + num(0), + tcurrent(0), + once(an_once) { + if (time==0 || once) running=false; + else running=true; + frame.image=anim_image; + w=width; + h=frame.image->h; + frame.pos.x=0; + frame.pos.y=0; + frame.pos.w=w; + frame.pos.h=h; +} + +Animation::~Animation() { } + +bool Animation::updateAnim(Uint16 dt) { + if (!running) return false; + tcurrent+=dt; + if (tcurrent < time) { + num=(Uint16)((tcurrent*size)/time); + if (num>=size) num=0; + } else if (once || time==0) { + num=size; + tcurrent=time; + running=false; + } else { + num=0; + tcurrent=0; + } + frame.pos.x=num*w; + if (running) return true; + else return false; +//The solution below would be better but it won't work with the 2nd constructor +// frame.pos.x=(Uint16)((num*frame.image->w)/size); +} + +const Frame& Animation::setFrame(Uint16 num) { + frame.pos.x=num*w; + return frame; +} + Added: trunk/src/animation.h =================================================================== --- trunk/src/animation.h 2005-02-20 21:39:26 UTC (rev 91) +++ trunk/src/animation.h 2005-02-22 13:36:33 UTC (rev 92) @@ -0,0 +1,76 @@ +#ifndef _ANIMATION_H +#define _ANIMATION_H 1 + +/** \brief A container for frames. + + Animation format: a horizontal strip (image) with (num) frames + \todo Change this to an offset matrix or something similar or give each row a different animation +*/ +class Animation { + public: + /// \brief Initialize the animation + /// \param image Image used for the animation + /// \param max_num Number of frames (will devide the image horizontally accordingly) + /// \param total_time Duration of the animation, if set to 0 assume it's one still image + /// \param once If true it run the animation only once when called by \fn start() + Animation(SDL_Surface* image, Uint16 max_num=1, Uint16 total_time=0, bool once=false); + /// \brief Initialize the animation + /// \param width Image width used from the left side + /// \param image Image used for the animation + /// \param max_num Number of frames (will devide the image horizontally accordingly) + /// \param total_time Duration of the animation, if set to 0 assume it's one still image + /// \param once If true: Run the animation only once when called by \fn start() + Animation(Uint16 width, SDL_Surface* image, Uint16 max_num=1, Uint16 total_time=0, bool once=false); + ~Animation(); + /// Updates a running animation and stops it if necessary + /// return True if the animation is still running + /// \todo This should be more advanced + bool updateAnim(Uint16 dt); + /// Updates the frame status of a frame series (usually when not running) + /// return Current frame + const Frame& setFrame(Uint16 nr); + /// Starts an (usually non running) animation + void start() { + num=0; + tcurrent=0; + running=true; + } + const Frame& getFrame() const { + return frame; + } + Frame getFrame(Uint16 nr) const { + Frame newframe=frame; + newframe.pos.x=nr*w; + return newframe; + } + Uint16 getWidth() const { + return w; + } + Uint16 getHeight() const { + return h; + } + /// return True if the animation is running + bool isRunning() const { + return running; + } + private: + /// Frame pointer + Frame frame; + /// Number of frames + Uint16 size; + /// Total time (in ms) + Uint16 time; + /// Frame size + Uint16 w; + Uint16 h; + /// Current frame number + Uint16 num; + /// Current time position (in ms) + Uint16 tcurrent; + /// frame series or running? + bool running; + /// play the animation only once? + bool once; +}; + +#endif From DONOTREPLY at icculus.org Tue Feb 22 08:51:28 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 22 Feb 2005 08:51:28 -0500 Subject: r93 - trunk/src Message-ID: <20050222135128.32616.qmail@icculus.org> Author: jonas Date: 2005-02-22 08:51:28 -0500 (Tue, 22 Feb 2005) New Revision: 93 Modified: trunk/src/input.cpp trunk/src/input.h trunk/src/lost_penguins.cpp Log: moved game state decisions up to the main loop, reorganized input.* Modified: trunk/src/input.cpp =================================================================== --- trunk/src/input.cpp 2005-02-22 13:36:33 UTC (rev 92) +++ trunk/src/input.cpp 2005-02-22 13:51:28 UTC (rev 93) @@ -69,14 +69,6 @@ state&=~INPUT_SP2; break; } - case SDLK_TAB: { - state&=~INPUT_PAUSE; - break; - } - case SDLK_ESCAPE: { - state&=~INPUT_MENU; - break; - } case SDLK_RETURN: { if (state&INPUT_ACT) setState(INPUTR_ACT); state&=~INPUT_ACT; @@ -152,19 +144,10 @@ break; } case SDLK_ESCAPE: { - if (state&INPUT_MENU) { - break; - } else if (menu) { - state|=INPUT_MENU; - if (!closeMenu()) { - gfxeng->renderScene(true); - scenario->physic->resetTime(); - sfxeng->resumeMusic(); - } - } else { - state|=INPUT_MENU; - sfxeng->pauseMusic(); - menu=new GameMenu(); + if (!closeMenu()) { + gfxeng->renderScene(true); + scenario->physic->resetTime(); + sfxeng->resumeMusic(); } gfxeng->updateMenu(); break; @@ -192,7 +175,7 @@ } } -void InputHandler::pollEvents() { +void InputHandler::pollPEvents() { SDL_Event event; while(SDL_PollEvent(&event)) { @@ -239,14 +222,6 @@ state&=~INPUT_SP2; break; } - case SDLK_TAB: { - state&=~INPUT_PAUSE; - break; - } - case SDLK_ESCAPE: { - state&=~INPUT_MENU; - break; - } case SDLK_RETURN: { if (state&INPUT_ACT) setState(INPUTR_ACT); state&=~INPUT_ACT; @@ -313,36 +288,14 @@ } //change game state! case SDLK_TAB: { - if (state&INPUT_PAUSE) { - break; - } else if (paused) { - state|=INPUT_PAUSE; - paused=false; - scenario->physic->resetTime(); - sfxeng->resumeMusic(); - } else { - state|=INPUT_PAUSE; - paused=true; - sfxeng->playWAV(au_pause); - sfxeng->pauseMusic(); - } + paused=false; + scenario->physic->resetTime(); + sfxeng->resumeMusic(); break; } case SDLK_ESCAPE: { - if (state&INPUT_MENU) { - break; - } else if (menu) { - state|=INPUT_MENU; - if (!closeMenu()) { - gfxeng->renderScene(true); - scenario->physic->resetTime(); - sfxeng->resumeMusic(); - } - } else { - state|=INPUT_MENU; - sfxeng->pauseMusic(); - menu=new GameMenu(); - } + sfxeng->pauseMusic(); + menu=new GameMenu(); break; } case SDLK_F1: { @@ -374,34 +327,155 @@ } } +void InputHandler::pollEvents() { + SDL_Event event; -int filterEvents(const SDL_Event*) { -/* -int filterEvents(const SDL_Event *event) { - switch(event->type) { - case SDL_QUIT: { - quitGame(0); - break; - } - case SDL_KEYDOWN: { - switch(event->key.keysym.sym) { - case SDLK_p: { - input->resume(); - break; + while(SDL_PollEvent(&event)) { + switch(event.type) { + // special events + case SDL_VIDEORESIZE: { + gfxeng->resize(event.resize.w, event.resize.h); + gfxeng->renderScene(true); + break; + } + // keyboard events + case SDL_QUIT: { + quitGame(0); + } + case SDL_KEYUP: { + switch(event.key.keysym.sym) { + case SDLK_LEFT: { + if (state&INPUT_LEFT) setState(INPUTR_LEFT); + state&=~INPUT_LEFT; + break; + } + case SDLK_RIGHT: { + if (state&INPUT_RIGHT) state|=INPUTR_RIGHT; + state&=~INPUT_RIGHT; + break; + } + case SDLK_UP: { + if (state&INPUT_UP) setState(INPUTR_UP); + state&=~INPUT_UP; + break; + } + case SDLK_DOWN: { + if (state&INPUT_DOWN) setState(INPUTR_DOWN); + state&=~INPUT_DOWN; + break; + } + case SDLK_SPACE: { + if (state&INPUT_SP1) setState(INPUTR_SP1); + state&=~INPUT_SP1; + break; + } + case SDLK_LSHIFT: { + if (state&INPUT_SP2) setState(INPUTR_SP2); + state&=~INPUT_SP2; + break; + } + case SDLK_RETURN: { + if (state&INPUT_ACT) setState(INPUTR_ACT); + state&=~INPUT_ACT; + break; + } + case SDLK_INSERT: { + if (state&INPUT_USE) setState(INPUTR_USE); + state&=~INPUT_USE; + break; + } + case SDLK_DELETE: { + if (state&INPUT_DEL) setState(INPUTR_DEL); + state&=~INPUT_DEL; + break; + } + default: { + break; + } } - case SDLK_q: { - quitGame(0); - break; + break; + } + case SDL_KEYDOWN: { + switch(event.key.keysym.sym) { + case SDLK_LCTRL: { + scenario->pool->switchPlayer(); + state=NOTHING; + break; + } + case SDLK_LEFT: { + state|=INPUT_LEFT; + break; + } + case SDLK_RIGHT: { + state|=INPUT_RIGHT; + break; + } + case SDLK_UP: { + state|=INPUT_UP; + break; + } + case SDLK_DOWN: { + state|=INPUT_DOWN; + break; + } + case SDLK_SPACE: { + state|=INPUT_SP1; + break; + } + case SDLK_LSHIFT: { + state|=INPUT_SP2; + break; + } + case SDLK_RETURN: { + state|=INPUT_ACT; + break; + } + case SDLK_INSERT: { + state|=INPUT_USE; + break; + } + case SDLK_DELETE: { + state|=INPUT_DEL; + break; + } + //change game state! + case SDLK_TAB: { + paused=true; + sfxeng->playWAV(au_pause); + sfxeng->pauseMusic(); + break; + } + case SDLK_ESCAPE: { + sfxeng->pauseMusic(); + menu=new GameMenu(); + break; + } + case SDLK_F1: { + gfxeng->togglePlayerBar(); + break; + } + case SDLK_F2: { + gfxeng->toggleFPS(); + break; + } + case SDLK_f: { + gfxeng->toggleFullScreen(); + break; + } + case SDLK_q: { + quitGame(0); + break; + } + default: { + break; + } } - default: { - break; - } + break; } + default: { + break; + } } - default: { - break; - } - } -*/ - return 1; + } } + Modified: trunk/src/input.h =================================================================== --- trunk/src/input.h 2005-02-22 13:36:33 UTC (rev 92) +++ trunk/src/input.h 2005-02-22 13:51:28 UTC (rev 93) @@ -20,8 +20,6 @@ #define INPUTR_ACT 0x00400000 #define INPUTR_USE 0x00800000 #define INPUTR_DEL 0x01000000 -#define INPUT_PAUSE 0x10000000 -#define INPUT_MENU 0x20000000 /** \brief Handels keyboard events @@ -35,6 +33,8 @@ ~InputHandler(); /// Check for keyboard events in game void pollEvents(); + /// Check for keyboard events in paused game + void pollPEvents(); /// Check for keyboard events in menu void pollMEvents(); bool getState(Uint32 cstate) { @@ -56,8 +56,4 @@ Mix_Chunk* au_pause; }; -/// \obsolete This isn't used at the moment -/// \brief SDL event filter -int filterEvents(const SDL_Event *event); - #endif Modified: trunk/src/lost_penguins.cpp =================================================================== --- trunk/src/lost_penguins.cpp 2005-02-22 13:36:33 UTC (rev 92) +++ trunk/src/lost_penguins.cpp 2005-02-22 13:51:28 UTC (rev 93) @@ -32,7 +32,6 @@ exit(-1); } SDL_ShowCursor(SDL_DISABLE); - SDL_SetEventFilter(filterEvents); system(config.datadir.c_str()); cout << "ImageCache...\n"; @@ -57,13 +56,19 @@ while (true) { if (menu) { gfxeng->drawMenu(); + //Check menu input input->pollMEvents(); } else if (running) { - gfxeng->renderScene(); - //Check input - input->pollEvents(); - //Run Animations - scenario->physic->update(); + if (paused) { + //Check pause input + input->pollPEvents(); + } else { + gfxeng->renderScene(); + //Check normal input + input->pollEvents(); + //Run Animations + scenario->physic->update(); + } } else { quitGame(-6); } From DONOTREPLY at icculus.org Wed Feb 23 07:47:08 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 23 Feb 2005 07:47:08 -0500 Subject: r94 - in trunk/src: . objects Message-ID: <20050223124708.22027.qmail@icculus.org> Author: jonas Date: 2005-02-23 07:47:07 -0500 (Wed, 23 Feb 2005) New Revision: 94 Modified: trunk/src/common.cpp trunk/src/common.h 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/objects/baleog.cpp trunk/src/objects/baleog.h trunk/src/objects/erik.cpp trunk/src/objects/erik.h trunk/src/objects/fang.cpp trunk/src/objects/fang.h trunk/src/objects/olaf.cpp trunk/src/objects/olaf.h trunk/src/objects/scorch.cpp trunk/src/objects/scorch.h trunk/src/physics.cpp trunk/src/physics.h trunk/src/players_common.cpp trunk/src/players_common.h Log: MAJOR INTERNAL UPDATE: ---------------------- Common updates: - Moved menu changes from common.cpp to menu.cpp - Introduced an enumerated ConfigKey list, see below - Simpler game loop, logic moved back to the individual handlers, see below Object (Player) updates: - Changed player objects according to the changes to the Input/PhysicHandler, see below - idle is now responsible for updating player specific states/events - Menus now handle more by themself (they call the update the gfxeng if they are changed, etc) Rewrite of the InputHandler: - Removed all input states - Introduced the arrays keystate (which keys are currently pressed) and keypressed (which keys were just pressed as an event in this loop) - Key bindings can be done in Config (keybind) using an enumerated list ConfigKey, example: config.keybind[KEY_SP1]=SDLK_LCTRL - ?\208?\134nputHandler is now simply called by update() which then chooses the right poll function (depending on game state) to update the key arrays. Big change to the PhysicHandler (as the InputHandler changed): - PhysicHandler is now simply called by update() which then chooses the right Handler function (depending on game state) to update the game state. - No more key release events are passed to the objects - in_act,in_use,in_sp1,in_sp2 are just called if a key was pressed as an event, the virtual functions are all changed accordingly... - The only events that are catched and passed to the current player are: key press events, updates on left/right/up/down - The objects are responsible for updating their state in idle, querying the InputHandler - PhysicHandler now manages the FPS code, introduced minimal FPS Big change to the GraphicsEngine: - GraphicsEngine is now simply called by draw() which then chooses the right draw function (depending on game state) to update the screen. - GraphicsEngine just draws as much as necessary (depending on game state). update(UpdateState) can be used to query for specific screen updates. - The background logic/functions is/are much simpler - Removed the fps handling code (see PhysicHandler) Modified: trunk/src/common.cpp =================================================================== --- trunk/src/common.cpp 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/common.cpp 2005-02-23 12:47:07 UTC (rev 94) @@ -24,24 +24,3 @@ if (a>=0) return a=max(0,a+b); else return a=min(0,a-b); } - -Menu* setMenu(Menu* newmenu) { - newmenu->setLast(menu); - return menu=newmenu; -} - -Menu* closeMenu() { - if (menu) { - Menu* tmp=menu->getLast(); - delete menu; - return menu=tmp; - } else { - return NULL; - } -} - -void closeMenus() { - while (menu) { - closeMenu(); - } -} Modified: trunk/src/common.h =================================================================== --- trunk/src/common.h 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/common.h 2005-02-23 12:47:07 UTC (rev 94) @@ -61,6 +61,26 @@ #define DIR_DWL 0x0000000A #define DIR_LR 0x00000003 +enum ConfigKey { + KEY_START, + KEY_LEFT, + KEY_RIGHT, + KEY_UP, + KEY_DOWN, + KEY_SP1, + KEY_SP2, + KEY_ACT, + KEY_USE, + KEY_DROP, + KEY_SWITCH, + KEY_PAUSE, + KEY_MENU, + KEY_FPS, + KEY_BAR, + KEY_FULL, + KEY_QUIT +}; + /**\brief Collision type */ @@ -82,6 +102,7 @@ int audio_channels; string datadir; string map; + SDLKey keybind[30]; }; /**\brief Frame format Modified: trunk/src/gfxeng.cpp =================================================================== --- trunk/src/gfxeng.cpp 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/gfxeng.cpp 2005-02-23 12:47:07 UTC (rev 94) @@ -6,17 +6,15 @@ #include "imgcache.h" #include "scenario.h" #include "menu.h" +//Only needed for fps +#include "scenario.h" +#include "physics.h" #include "gfxeng.h" GraphicsEngine::GraphicsEngine(): screen(NULL), menubg(NULL), - Dfps(0), - Dframes(0), - currentfps(0), - tcurrent(SDL_GetTicks()), - menu_done(false), show_bar(true), show_fps(true), fullscreen(config.full) { @@ -41,6 +39,53 @@ SDL_FreeSurface(screen); } +void GraphicsEngine::update(Uint8 upd) { + if (updatetype==UPDATE_ALL) return; + else updatetype=upd; +} + +void GraphicsEngine::draw() { + //Menu + if (menu) { + //Assure we have a (correct) menu background + if (!menubg) { + if (running) { + setGameMenuBG(); + } else { + setMenuBG(); + } + } + if (updatetype==UPDATE_ALL) { + if (running) { + setGameMenuBG(); + drawMenu(); + } else { + setMenuBG(); + drawMenu(); + } + } else if (updatetype==UPDATE_MENU) { + drawMenu(); + } + //Paused game + } else if (paused) { + if (updatetype==UPDATE_ALL) { + drawScene(); + drawPlayerBar(); + } else if (updatetype==UPDATE_BAR) { + drawPlayerBar(); + } + //Not paused running game + } else if (running) { + drawScene(); + drawPlayerBar(); + drawFPS(); + updatetype=UPDATE_ALL; + } else return; + //This is the most time consuming operation + if (updatetype!=UPDATE_NOTHING) SDL_Flip(screen); + updatetype=UPDATE_NOTHING; +} + void GraphicsEngine::resize(Uint16 width, Uint16 height) { if (screen) SDL_FreeSurface(screen); @@ -59,6 +104,7 @@ vis_map.y=0; vis_map.w=screen->w; vis_map.h=screen->h-bar.h; + update(UPDATE_ALL); } inline SDL_Rect GraphicsEngine::clipToBG(SDL_Rect dest) const { @@ -92,7 +138,43 @@ return shift; } -inline void GraphicsEngine::drawPlayerBar() { +void GraphicsEngine::drawScene() { + if (!running) return; + + //We don't want to change pos! + SDL_Rect tmprect,shift,srcpos; + if (scenario->player!=NULL) { + shift=setShift(scenario->player->getCenter()); + } else { + shift.x=0; + shift.y=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; + } + + if (scenario->player!=NULL) { + tmprect=*(scenario->player->getPos()); + srcpos=scenario->player->getFrame().pos; + shiftMapArea(tmprect,*(scenario->player->getCurPos())); + SDL_BlitSurface(scenario->player->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift)); + } +} + +//TODO don't draw the whole screen, just till bar, just upgrade certain regions of the bar +void GraphicsEngine::drawPlayerBar() { + if (!show_bar) return; //#players Uint8 pnum=scenario->pool->playerspool.size(); //temporary dest pos, source pos, copy of dest pos @@ -163,54 +245,9 @@ } } -void GraphicsEngine::renderScene(bool insist) { - resetMenuBG(); - if (scenario->background && (!paused || insist)) { - //We don't want to change pos! - SDL_Rect tmprect,shift,srcpos; - if (scenario->player!=NULL) { - shift=setShift(scenario->player->getCenter()); - } else { - shift.x=0; - shift.y=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; - } - - if (scenario->player!=NULL) { - tmprect=*(scenario->player->getPos()); - srcpos=scenario->player->getFrame().pos; - shiftMapArea(tmprect,*(scenario->player->getCurPos())); - SDL_BlitSurface(scenario->player->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift)); - } - } - - //TODO don't draw the whole screen, just till bar, just upgrade certain regions of the bar - if (show_bar) drawPlayerBar(); - if (show_fps) { - Dfps+=(SDL_GetTicks()-tcurrent); - tcurrent=SDL_GetTicks(); - ++Dframes; - if (Dfps>=100) { - currentfps=Uint16(Dframes*1000/Dfps); - Dfps=0; - Dframes=0; - } - font->write(screen,"FPS: " + itos(currentfps),screen->w-150,0); - } - SDL_Flip(screen); +void GraphicsEngine::drawFPS() { + if (!show_fps) return; + font->write(screen,"FPS: " + itos(scenario->physic->getFPS()) + " [" + itos(scenario->physic->getMinFPS()) + "]",screen->w-170,0); } void GraphicsEngine::togglePlayerBar() { @@ -250,57 +287,53 @@ } void GraphicsEngine::drawMenu() { - if (!menu_done) { - menu_done=true; - //Semitransparent background - setGameMenuBG(); - SDL_BlitSurface(menubg,NULL,screen,NULL); + if (menubg) SDL_BlitSurface(menubg,NULL,screen,NULL); - menu->font_title->writeCenter(screen,menu->title,0); + menu->font_title->writeCenter(screen,menu->title,0); - Uint16 h; - for (Uint8 i=0; i< menu->getSize(); i++) { - if (i<=menu->currententry) { - h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-i-1)*DFONT-(menu->getSize()-i-1)*(menu->font->getHeight())-menu->font_high->getHeight())/2; - } else { - h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-i-1)*DFONT-(menu->getSize()-i)*(menu->font->getHeight()))/2; - } - if (i==menu->currententry) menu->font_high->writeCenter(screen,menu->entries[i],h); - else menu->font->writeCenter(screen,menu->entries[i],h); + Uint16 h; + for (Uint8 i=0; i< menu->getSize(); i++) { + if (i<=menu->currententry) { + h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-i-1)*DFONT-(menu->getSize()-i-1)*(menu->font->getHeight())-menu->font_high->getHeight())/2; + } else { + h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-i-1)*DFONT-(menu->getSize()-i)*(menu->font->getHeight()))/2; } - - SDL_Flip(screen); + if (i==menu->currententry) menu->font_high->writeCenter(screen,menu->entries[i],h); + else menu->font->writeCenter(screen,menu->entries[i],h); } } //this could probably be done much easier ;) inline void GraphicsEngine::setGameMenuBG() { - if (!menubg) { - SDL_Surface* tmp = SDL_CreateRGBSurface ( - SDL_HWSURFACE, - screen->w, - screen->h, - 32, - rmask,gmask,bmask,0); + if (menubg) SDL_FreeSurface(menubg); + drawScene(); + drawPlayerBar(); + SDL_Flip(screen); + + SDL_Surface* tmp = SDL_CreateRGBSurface ( + SDL_HWSURFACE, + screen->w, + screen->h, + 32, + rmask,gmask,bmask,0); #ifdef ALPHA - menubg = SDL_CreateRGBSurface ( - SDL_HWSURFACE, - screen->w, - screen->h, - 32, - rmask,gmask,bmask,0); - SDL_BlitSurface(screen,NULL,menubg,NULL); - SDL_SetAlpha(menubg,SDL_SRCALPHA,60); - SDL_FillRect(tmp,NULL,SDL_MapRGB(screen->format,0,0,0)); - SDL_BlitSurface(menubg,NULL,tmp,NULL); - SDL_FreeSurface(menubg); - menubg=SDL_DisplayFormatAlpha(tmp); + menubg = SDL_CreateRGBSurface ( + SDL_HWSURFACE, + screen->w, + screen->h, + 32, + rmask,gmask,bmask,0); + SDL_BlitSurface(screen,NULL,menubg,NULL); + SDL_SetAlpha(menubg,SDL_SRCALPHA,60); + SDL_FillRect(tmp,NULL,SDL_MapRGB(screen->format,0,0,0)); + SDL_BlitSurface(menubg,NULL,tmp,NULL); + SDL_FreeSurface(menubg); + menubg=SDL_DisplayFormatAlpha(tmp); #else - SDL_FillRect(tmp,NULL,SDL_MapRGB(screen->format,0,0,0)); - menubg=SDL_DisplayFormat(tmp); + SDL_FillRect(tmp,NULL,SDL_MapRGB(screen->format,0,0,0)); + menubg=SDL_DisplayFormat(tmp); #endif - SDL_FreeSurface(tmp); - } + SDL_FreeSurface(tmp); } void GraphicsEngine::setMenuBG(SDL_Surface* menu_background) { Modified: trunk/src/gfxeng.h =================================================================== --- trunk/src/gfxeng.h 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/gfxeng.h 2005-02-23 12:47:07 UTC (rev 94) @@ -5,6 +5,11 @@ #define ICON_SIZE 46 #define DFONT 40 +#define UPDATE_NOTHING 0x00 +#define UPDATE_BAR 0x01 +#define UPDATE_MENU 0x02 +#define UPDATE_ALL 0x03 + /** \brief Graphics engine Draws each object in the pool and optionally a player bar and/or @@ -15,66 +20,58 @@ public: GraphicsEngine(); ~GraphicsEngine(); + /// Update what should be drawn to the screen + void update(Uint8); + /// Update the screen drawings... + void draw(); /// Runs SDL_SetVideoMode with the new parameters. void resize(Uint16 width, Uint16 height); - ///\brief update the scene in a running scenario - /// - /// If a scenario is running this draws the background and all objects - /// in the pool. If the game is paused, only the player bar is drawn. - /// Optionally also the player bar and/or the current frames per second - /// are displayed. - /// \param insist True if the objects should be drawn even if the game - /// is paused - void renderScene(bool insist=false); void togglePlayerBar(); void toggleFPS(); void toggleFullScreen(); - ///\brief draw the menu - /// - /// If no scenario is running or the scenario was interrupted this will - /// draw the menu. - void drawMenu(); - void updateMenu() { - menu_done=false; - } void setMenuBG(SDL_Surface* menu_background=NULL); - void resetMenuBG(); - Uint16 getFPS() { - if (show_fps) return currentfps; - else return 0; - } protected: Uint32 rmask; Uint32 gmask; Uint32 bmask; Uint32 amask; - inline SDL_Rect clipToBG(SDL_Rect dest) const; - /// updates backpos and returns the new shift vector (ignore w,h) - inline SDL_Rect setShift(SDL_Rect center); - /// simple vector addition, should be replaced by operator - inline SDL_Rect* shiftMapArea(SDL_Rect& area, const SDL_Rect& shift); - /// draw player bar - inline void drawPlayerBar(); /// currently visible part of the map area SDL_Rect vis_map; /// main screen SDL_Surface* screen; /// menu background SDL_Surface* menubg; - /// sets the menu background while playing a scenario - inline void setGameMenuBG(); /// player bar SDL_Rect bar; /// symbol for one life of a player Animation* lifeimage; - //fps stuff - Uint16 Dfps,Dframes,currentfps,tcurrent; - //for drawMenu - bool menu_done; - //visual flags bool show_bar; bool show_fps; + //visual flags bool fullscreen; + //update state + Uint8 updatetype; + protected: + /// Draw the background and all objects in the pool. This is a very time + /// consuming function... + inline void drawScene(); + /// Draw player bar + inline void drawPlayerBar(); + /// Draw the frames per second + inline void drawFPS(); + ///\brief draw the menu + /// + /// If no scenario is running or the scenario was interrupted this will + /// draw the menu. + inline void drawMenu(); + inline void resetMenuBG(); + inline SDL_Rect clipToBG(SDL_Rect dest) const; + /// updates backpos and returns the new shift vector (ignore w,h) + inline SDL_Rect setShift(SDL_Rect center); + /// simple vector addition, should be replaced by operator + inline SDL_Rect* shiftMapArea(SDL_Rect& area, const SDL_Rect& shift); + /// sets the menu background while playing a scenario + inline void setGameMenuBG(); }; #endif Modified: trunk/src/input.cpp =================================================================== --- trunk/src/input.cpp 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/input.cpp 2005-02-23 12:47:07 UTC (rev 94) @@ -11,161 +11,66 @@ #include "objects_common.h" -InputHandler::InputHandler(): - state(NOTHING) { - paused=false; +InputHandler::InputHandler() { au_pause=sndcache->loadWAV("pause.wav"); + SDL_PumpEvents(); + keystate = SDL_GetKeyState(NULL); } InputHandler::~InputHandler() { } -void InputHandler::pollMEvents() { - SDL_Event event; +bool InputHandler::keyPressed(ConfigKey key) { + return keypressed[config.keybind[key]]; +} +bool InputHandler::keyState(ConfigKey key) { + return keystate[config.keybind[key]]; +} +void InputHandler::update() { + if (menu) { + pollMenuEvents(); + } else if (paused) { + pollPausedEvents(); + } else { + pollGameEvents(); + } +} + +inline void InputHandler::pollMenuEvents() { while(SDL_PollEvent(&event)) { switch(event.type) { // special events case SDL_VIDEORESIZE: { gfxeng->resize(event.resize.w, event.resize.h); - gfxeng->renderScene(true); - gfxeng->updateMenu(); - gfxeng->drawMenu(); break; } // keyboard events case SDL_QUIT: { quitGame(0); } - case SDL_KEYUP: { - switch(event.key.keysym.sym) { - case SDLK_LEFT: { - if (state&INPUT_LEFT) setState(INPUTR_LEFT); - state&=~INPUT_LEFT; - break; - } - case SDLK_RIGHT: { - if (state&INPUT_RIGHT) state|=INPUTR_RIGHT; - state&=~INPUT_RIGHT; - break; - } - case SDLK_UP: { - if (state&INPUT_UP) setState(INPUTR_UP); - state&=~INPUT_UP; - break; - } - case SDLK_DOWN: { - if (state&INPUT_DOWN) setState(INPUTR_DOWN); - state&=~INPUT_DOWN; - break; - } - case SDLK_SPACE: { - if (state&INPUT_SP1) setState(INPUTR_SP1); - state&=~INPUT_SP1; - break; - } - case SDLK_LSHIFT: { - if (state&INPUT_SP2) setState(INPUTR_SP2); - state&=~INPUT_SP2; - break; - } - case SDLK_RETURN: { - if (state&INPUT_ACT) setState(INPUTR_ACT); - state&=~INPUT_ACT; - break; - } - case SDLK_INSERT: { - if (state&INPUT_USE) setState(INPUTR_USE); - state&=~INPUT_USE; - break; - } - case SDLK_DELETE: { - if (state&INPUT_DEL) setState(INPUTR_DEL); - state&=~INPUT_DEL; - break; - } - default: { - break; - } - } - break; - } case SDL_KEYDOWN: { - switch(event.key.keysym.sym) { - case SDLK_LEFT: { - state|=INPUT_LEFT; - gfxeng->updateMenu(); - break; - } - case SDLK_RIGHT: { - state|=INPUT_RIGHT; - gfxeng->updateMenu(); - break; - } - case SDLK_UP: { - if (state&INPUT_UP) break; - menu->increaseEntry(false); - state|=INPUT_UP; - gfxeng->updateMenu(); - break; - } - case SDLK_DOWN: { - if (state&INPUT_DOWN) break; - menu->increaseEntry(); - state|=INPUT_DOWN; - gfxeng->updateMenu(); - break; - } - case SDLK_SPACE: { - state|=INPUT_SP1; - gfxeng->updateMenu(); - break; - } - case SDLK_LSHIFT: { - state|=INPUT_SP2; - gfxeng->updateMenu(); - break; - } - case SDLK_RETURN: { - if (state&INPUT_ACT) break; - state|=INPUT_ACT; - menu->act(); - gfxeng->updateMenu(); - break; - } - case SDLK_INSERT: { - state|=INPUT_USE; - gfxeng->updateMenu(); - break; - } - case SDLK_DELETE: { - state|=INPUT_DEL; - gfxeng->updateMenu(); - break; - } - case SDLK_ESCAPE: { - if (!closeMenu()) { - gfxeng->renderScene(true); - scenario->physic->resetTime(); + SDLKey key=event.key.keysym.sym; + if (key==config.keybind[KEY_UP]) { + menu->increaseEntry(false); + } else if (key==config.keybind[KEY_DOWN]) { + menu->increaseEntry(); + } else if (key==config.keybind[KEY_ACT]) { + menu->act(); + } else if (key==config.keybind[KEY_MENU]) { + if (!closeMenu()) { + if (running) { sfxeng->resumeMusic(); + } else { + quitGame(0); } - gfxeng->updateMenu(); - break; - } - case SDLK_f: { - gfxeng->toggleFullScreen(); - gfxeng->updateMenu(); - break; - } - case SDLK_q: { - quitGame(0); - gfxeng->updateMenu(); - break; - } - default: { - break; - } + } + } else if (key==config.keybind[KEY_FULL]) { + gfxeng->toggleFullScreen(); + } else if (key==config.keybind[KEY_QUIT]) { + quitGame(0); } + gfxeng->update(UPDATE_MENU); break; } default: { @@ -175,149 +80,34 @@ } } -void InputHandler::pollPEvents() { - SDL_Event event; - +inline void InputHandler::pollPausedEvents() { while(SDL_PollEvent(&event)) { switch(event.type) { // special events case SDL_VIDEORESIZE: { gfxeng->resize(event.resize.w, event.resize.h); - gfxeng->renderScene(true); break; } // keyboard events case SDL_QUIT: { quitGame(0); } - case SDL_KEYUP: { - switch(event.key.keysym.sym) { - case SDLK_LEFT: { - if (state&INPUT_LEFT) setState(INPUTR_LEFT); - state&=~INPUT_LEFT; - break; - } - case SDLK_RIGHT: { - if (state&INPUT_RIGHT) state|=INPUTR_RIGHT; - state&=~INPUT_RIGHT; - break; - } - case SDLK_UP: { - if (state&INPUT_UP) setState(INPUTR_UP); - state&=~INPUT_UP; - break; - } - case SDLK_DOWN: { - if (state&INPUT_DOWN) setState(INPUTR_DOWN); - state&=~INPUT_DOWN; - break; - } - case SDLK_SPACE: { - if (state&INPUT_SP1) setState(INPUTR_SP1); - state&=~INPUT_SP1; - break; - } - case SDLK_LSHIFT: { - if (state&INPUT_SP2) setState(INPUTR_SP2); - state&=~INPUT_SP2; - break; - } - case SDLK_RETURN: { - if (state&INPUT_ACT) setState(INPUTR_ACT); - state&=~INPUT_ACT; - break; - } - case SDLK_INSERT: { - if (state&INPUT_USE) setState(INPUTR_USE); - state&=~INPUT_USE; - break; - } - case SDLK_DELETE: { - if (state&INPUT_DEL) setState(INPUTR_DEL); - state&=~INPUT_DEL; - break; - } - default: { - break; - } - } - break; - } case SDL_KEYDOWN: { - switch(event.key.keysym.sym) { - case SDLK_LCTRL: { - scenario->pool->switchPlayer(); - state=NOTHING; - break; - } - case SDLK_LEFT: { - state|=INPUT_LEFT; - break; - } - case SDLK_RIGHT: { - state|=INPUT_RIGHT; - break; - } - case SDLK_UP: { - state|=INPUT_UP; - break; - } - case SDLK_DOWN: { - state|=INPUT_DOWN; - break; - } - case SDLK_SPACE: { - state|=INPUT_SP1; - break; - } - case SDLK_LSHIFT: { - state|=INPUT_SP2; - break; - } - case SDLK_RETURN: { - state|=INPUT_ACT; - break; - } - case SDLK_INSERT: { - state|=INPUT_USE; - break; - } - case SDLK_DELETE: { - state|=INPUT_DEL; - break; - } - //change game state! - case SDLK_TAB: { - paused=false; - scenario->physic->resetTime(); - sfxeng->resumeMusic(); - break; - } - case SDLK_ESCAPE: { - sfxeng->pauseMusic(); - menu=new GameMenu(); - break; - } - case SDLK_F1: { - gfxeng->togglePlayerBar(); - break; - } - case SDLK_F2: { - gfxeng->toggleFPS(); - break; - } - case SDLK_f: { - gfxeng->toggleFullScreen(); - break; - } - case SDLK_q: { - quitGame(0); - break; - } - default: { - break; - } + SDLKey key=event.key.keysym.sym; + if (key==config.keybind[KEY_SWITCH]) { + scenario->pool->switchPlayer(); + } else if (key==config.keybind[KEY_PAUSE]) { + paused=false; + sfxeng->resumeMusic(); + } else if (key==config.keybind[KEY_MENU]) { + sfxeng->pauseMusic(); + setMenu(new GameMenu()); + } else if (key==config.keybind[KEY_FULL]) { + gfxeng->toggleFullScreen(); + } else if (key==config.keybind[KEY_QUIT]) { + quitGame(0); } + gfxeng->update(UPDATE_BAR); break; } default: { @@ -327,148 +117,42 @@ } } -void InputHandler::pollEvents() { - SDL_Event event; - +inline void InputHandler::pollGameEvents() { + for (Uint16 i=0; iresize(event.resize.w, event.resize.h); - gfxeng->renderScene(true); break; } // keyboard events case SDL_QUIT: { quitGame(0); } - case SDL_KEYUP: { - switch(event.key.keysym.sym) { - case SDLK_LEFT: { - if (state&INPUT_LEFT) setState(INPUTR_LEFT); - state&=~INPUT_LEFT; - break; - } - case SDLK_RIGHT: { - if (state&INPUT_RIGHT) state|=INPUTR_RIGHT; - state&=~INPUT_RIGHT; - break; - } - case SDLK_UP: { - if (state&INPUT_UP) setState(INPUTR_UP); - state&=~INPUT_UP; - break; - } - case SDLK_DOWN: { - if (state&INPUT_DOWN) setState(INPUTR_DOWN); - state&=~INPUT_DOWN; - break; - } - case SDLK_SPACE: { - if (state&INPUT_SP1) setState(INPUTR_SP1); - state&=~INPUT_SP1; - break; - } - case SDLK_LSHIFT: { - if (state&INPUT_SP2) setState(INPUTR_SP2); - state&=~INPUT_SP2; - break; - } - case SDLK_RETURN: { - if (state&INPUT_ACT) setState(INPUTR_ACT); - state&=~INPUT_ACT; - break; - } - case SDLK_INSERT: { - if (state&INPUT_USE) setState(INPUTR_USE); - state&=~INPUT_USE; - break; - } - case SDLK_DELETE: { - if (state&INPUT_DEL) setState(INPUTR_DEL); - state&=~INPUT_DEL; - break; - } - default: { - break; - } - } - break; - } case SDL_KEYDOWN: { - switch(event.key.keysym.sym) { - case SDLK_LCTRL: { - scenario->pool->switchPlayer(); - state=NOTHING; - break; - } - case SDLK_LEFT: { - state|=INPUT_LEFT; - break; - } - case SDLK_RIGHT: { - state|=INPUT_RIGHT; - break; - } - case SDLK_UP: { - state|=INPUT_UP; - break; - } - case SDLK_DOWN: { - state|=INPUT_DOWN; - break; - } - case SDLK_SPACE: { - state|=INPUT_SP1; - break; - } - case SDLK_LSHIFT: { - state|=INPUT_SP2; - break; - } - case SDLK_RETURN: { - state|=INPUT_ACT; - break; - } - case SDLK_INSERT: { - state|=INPUT_USE; - break; - } - case SDLK_DELETE: { - state|=INPUT_DEL; - break; - } - //change game state! - case SDLK_TAB: { - paused=true; - sfxeng->playWAV(au_pause); - sfxeng->pauseMusic(); - break; - } - case SDLK_ESCAPE: { - sfxeng->pauseMusic(); - menu=new GameMenu(); - break; - } - case SDLK_F1: { - gfxeng->togglePlayerBar(); - break; - } - case SDLK_F2: { - gfxeng->toggleFPS(); - break; - } - case SDLK_f: { - gfxeng->toggleFullScreen(); - break; - } - case SDLK_q: { - quitGame(0); - break; - } - default: { - break; - } + SDLKey key=event.key.keysym.sym; + keypressed[key]=true; + if (key==config.keybind[KEY_SWITCH]) { + scenario->pool->switchPlayer(); + } else if (key==config.keybind[KEY_PAUSE]) { + paused=true; + sfxeng->playWAV(au_pause); + sfxeng->pauseMusic(); + } else if (key==config.keybind[KEY_MENU]) { + sfxeng->pauseMusic(); + setMenu(new GameMenu()); + gfxeng->update(UPDATE_ALL); + } else if (key==config.keybind[KEY_BAR]) { + gfxeng->togglePlayerBar(); + } else if (key==config.keybind[KEY_FPS]) { + gfxeng->toggleFPS(); + } else if (key==config.keybind[KEY_FULL]) { + gfxeng->toggleFullScreen(); + } else if (key==config.keybind[KEY_QUIT]) { + quitGame(0); } break; } @@ -477,5 +161,5 @@ } } } + keystate = SDL_GetKeyState(NULL); } - Modified: trunk/src/input.h =================================================================== --- trunk/src/input.h 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/input.h 2005-02-23 12:47:07 UTC (rev 94) @@ -1,26 +1,6 @@ #ifndef _INPUT_H #define _INPUT_H 1 -//Input events -#define INPUT_LEFT 0x00000001 -#define INPUT_RIGHT 0x00000002 -#define INPUT_UP 0x00000004 -#define INPUT_DOWN 0x00000008 -#define INPUT_SP1 0x00000010 -#define INPUT_SP2 0x00000020 -#define INPUT_ACT 0x00000040 -#define INPUT_USE 0x00000080 -#define INPUT_DEL 0x00000100 -#define INPUTR_LEFT 0x00010000 -#define INPUTR_RIGHT 0x00020000 -#define INPUTR_UP 0x00040000 -#define INPUTR_DOWN 0x00080000 -#define INPUTR_SP1 0x00100000 -#define INPUTR_SP2 0x00200000 -#define INPUTR_ACT 0x00400000 -#define INPUTR_USE 0x00800000 -#define INPUTR_DEL 0x01000000 - /** \brief Handels keyboard events \remark A key release event which is passed on to the PhysicHandler @@ -31,29 +11,23 @@ public: InputHandler(); ~InputHandler(); - /// Check for keyboard events in game - void pollEvents(); - /// Check for keyboard events in paused game - void pollPEvents(); - /// Check for keyboard events in menu - void pollMEvents(); - bool getState(Uint32 cstate) { - return (state&cstate); - } - void setState(Uint32 cstate) { - state|=cstate; - } - void unsetState(Uint32 cstate) { - state&=~cstate; - } - void clearStates() { - state=NOTHING; - } + /// Update the input status + void update(); + bool keyPressed(ConfigKey key); + bool keyState(ConfigKey key); private: - /// Information about which buttons are pressed - Uint32 state; /// Sound: When the game is paused Mix_Chunk* au_pause; + Uint8* keystate; + bool keypressed[SDLK_LAST]; + private: + SDL_Event event; + /// Check for keyboard events in game + inline void pollGameEvents(); + /// Check for keyboard events in paused game + inline void pollPausedEvents(); + /// Check for keyboard events in menu + inline void pollMenuEvents(); }; #endif Modified: trunk/src/lost_penguins.cpp =================================================================== --- trunk/src/lost_penguins.cpp 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/lost_penguins.cpp 2005-02-23 12:47:07 UTC (rev 94) @@ -51,27 +51,13 @@ scenario=new Scenario(); gfxeng->setMenuBG(); - menu=new StartMenu(); + menu=NULL; + setMenu(new StartMenu()); while (true) { - if (menu) { - gfxeng->drawMenu(); - //Check menu input - input->pollMEvents(); - } else if (running) { - if (paused) { - //Check pause input - input->pollPEvents(); - } else { - gfxeng->renderScene(); - //Check normal input - input->pollEvents(); - //Run Animations - scenario->physic->update(); - } - } else { - quitGame(-6); - } + input->update(); + if (running) scenario->physic->update(); + gfxeng->draw(); } quitGame(-2); @@ -112,6 +98,24 @@ config.datadir="data/"; config.map="map1.cfg"; + //key bindings + config.keybind[KEY_LEFT] = SDLK_LEFT; + config.keybind[KEY_RIGHT] = SDLK_RIGHT; + config.keybind[KEY_UP] = SDLK_UP; + config.keybind[KEY_DOWN] = SDLK_DOWN; + config.keybind[KEY_SP1] = SDLK_SPACE; + config.keybind[KEY_SP2] = SDLK_LSHIFT; + config.keybind[KEY_ACT] = SDLK_RETURN; + config.keybind[KEY_USE] = SDLK_INSERT; + config.keybind[KEY_DROP] = SDLK_DELETE; + config.keybind[KEY_SWITCH] = SDLK_LCTRL; + config.keybind[KEY_PAUSE] = SDLK_TAB; + config.keybind[KEY_MENU] = SDLK_ESCAPE; + config.keybind[KEY_FPS] = SDLK_F2; + config.keybind[KEY_BAR] = SDLK_F1; + config.keybind[KEY_FULL] = SDLK_f; + config.keybind[KEY_QUIT] = SDLK_q; + configfile.open(filename.c_str()); if (!configfile) return 0; @@ -136,6 +140,7 @@ config.full=true; } else if (option=="map") { config.map=arg1; + //TODO: add keybindings } else { cout << "Unknown option: " << option << endl; } Modified: trunk/src/menu.cpp =================================================================== --- trunk/src/menu.cpp 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/menu.cpp 2005-02-23 12:47:07 UTC (rev 94) @@ -5,6 +5,32 @@ #include "sfxeng.h" #include "menu.h" +Menu* setMenu(Menu* newmenu) { + if (menu) gfxeng->update(UPDATE_MENU); + else gfxeng->update(UPDATE_ALL); + newmenu->setLast(menu); + return menu=newmenu; +} + +Menu* closeMenu() { + gfxeng->update(UPDATE_MENU); + if (menu) { + Menu* tmp=menu->getLast(); + delete menu; + if (!tmp) gfxeng->update(UPDATE_ALL); + return menu=tmp; + } else { + gfxeng->update(UPDATE_ALL); + return NULL; + } +} + +void closeMenus() { + while (menu) { + closeMenu(); + } +} + Menu::Menu(): title("MENU"), last(NULL), @@ -74,8 +100,7 @@ switch (currententry) { case 0: { if (!closeMenu()) { - gfxeng->renderScene(true); - scenario->physic->resetTime(); + gfxeng->update(UPDATE_ALL); sfxeng->resumeMusic(); } break; @@ -121,21 +146,19 @@ switch (currententry) { case 0: { gfxeng->toggleFPS(); - update(); - gfxeng->updateMenu(); + gfxeng->update(UPDATE_MENU); break; } case 1: { gfxeng->togglePlayerBar(); - gfxeng->renderScene(true); - update(); - gfxeng->updateMenu(); + gfxeng->update(UPDATE_ALL); break; } default: { break; } } + update(); } void ConfigMenu::update() { entries[0]="Show FPS: "+string((gfxeng->show_fps) ? "ON" : "OFF"); Modified: trunk/src/objects/baleog.cpp =================================================================== --- trunk/src/objects/baleog.cpp 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/objects/baleog.cpp 2005-02-23 12:47:07 UTC (rev 94) @@ -38,9 +38,6 @@ } //Baleog1: Sword attack -void Baleog::in_sp1(Sint16 dt) { - if (dt < 0) return; - input->unsetState(INPUT_SP1); - +void Baleog::in_sp1() { setEvent(new EAttack(this,10,&weapon,(state&STATE_LEFT) ? DIR_LEFT : DIR_RIGHT,10,enemy_types,0,0,au_sword,(state&STATE_LEFT) ? im_sword_left : im_sword_right)); } Modified: trunk/src/objects/baleog.h =================================================================== --- trunk/src/objects/baleog.h 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/objects/baleog.h 2005-02-23 12:47:07 UTC (rev 94) @@ -8,7 +8,7 @@ Baleog(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Baleog"); virtual ~Baleog(); /// \brief Baleog attacks with a sword - virtual void in_sp1(Sint16); + virtual void in_sp1(); private: Mix_Chunk* au_sword; Animation* im_sword_left; Modified: trunk/src/objects/erik.cpp =================================================================== --- trunk/src/objects/erik.cpp 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/objects/erik.cpp 2005-02-23 12:47:07 UTC (rev 94) @@ -36,11 +36,29 @@ delete im_land_right; } -void Erik::in_sp1(Sint16 dt) { +void Erik::idle(Uint16 dt) { + Player::idle(dt); + //TODO: this is an ugly hack... + if (!input->keyState(KEY_SP2)) { + dense_types&=~OTYPE_MONSTER; + if (state&STATE_RUN) cancelEvent(); + } else if (state&STATE_RUN) { + dense_types|=OTYPE_MONSTER; + if (state&STATE_FALL) cancelEvent(); + if ((!state&STATE_MRIGHT) && run_right) cancelEvent(); + if ((!state&STATE_MLEFT) && (!run_right)) cancelEvent(); + } else { + //TODO: check STATE_WATER + if (state&(STATE_MLEFT|STATE_MRIGHT)) { + if (state&STATE_MRIGHT) run_right=true; + else run_right=false; + setEvent(new ERun(this,10000,maxspeedx,500,ESTATE_ABORT,au_run)); + } + } +} + +void Erik::in_sp1() { //TODO: check STATE_WATER - if (dt < 0) return; - input->unsetState(INPUT_SP1); - if (state&STATE_FALL) setState(STATE_ACT_1); if (state&STATE_ACT_2) { @@ -55,27 +73,17 @@ } } -void Erik::in_sp2(Sint16 dt) { +void Erik::in_sp2() { //TODO: check STATE_WATER - if (dt < 0) { - input->unsetState(INPUT_SP2); - dense_types&=~OTYPE_MONSTER; - if (state&STATE_RUN) cancelEvent(); - return; - } - if (state&STATE_RUN) { - dense_types|=OTYPE_MONSTER; - if (state&STATE_FALL) cancelEvent(); - } else if (state&(STATE_MLEFT|STATE_MRIGHT)) { + if (state&(STATE_MLEFT|STATE_MRIGHT)) { + if (state&STATE_MRIGHT) run_right=true; + else run_right=false; setEvent(new ERun(this,10000,maxspeedx,500,ESTATE_ABORT,au_run)); } } -void Erik::in_left(Sint16 dt) { - if (dt < 0) { - //TODO: play decelerate animation (setEvent instead) - if (state&STATE_RUN) cancelEvent(); - } else if (state&STATE_RUN) { +void Erik::in_left(Uint16 dt) { + if (state&STATE_RUN) { if (state&STATE_LEFT) event->reset(); //changed directions, TODO: play decelerate animation else cancelEvent(); @@ -83,11 +91,8 @@ Player::in_left(dt); } -void Erik::in_right(Sint16 dt) { - if (dt < 0) { - //TODO: play decelerate animation (setEvent instead) - if (state&STATE_RUN) cancelEvent(); - } else if (state&STATE_RUN) { +void Erik::in_right(Uint16 dt) { + if (state&STATE_RUN) { if (!(state&STATE_LEFT)) event->reset(); //changed directions, TODO: play decelerate animation else cancelEvent(); Modified: trunk/src/objects/erik.h =================================================================== --- trunk/src/objects/erik.h 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/objects/erik.h 2005-02-23 12:47:07 UTC (rev 94) @@ -15,16 +15,18 @@ public: Erik(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Erik"); virtual ~Erik(); - /// \brief Erik jumps - virtual void in_sp1(Sint16); - // \brief Erik runs - virtual void in_sp2(Sint16); - virtual void in_left(Sint16); - virtual void in_right(Sint16); + virtual void idle(Uint16); + /// \brief Erik jumps + virtual void in_sp1(); + /// \brief Erik runs + virtual void in_sp2(); + virtual void in_left(Uint16); + virtual void in_right(Uint16); virtual void crash(Uint16 dir); virtual Uint16 hit(Uint16 direction,Weapon& weap); private: Mix_Chunk* au_jump; Mix_Chunk* au_run; Sint16 jump,jump2; + bool run_right; }; Modified: trunk/src/objects/fang.cpp =================================================================== --- trunk/src/objects/fang.cpp 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/objects/fang.cpp 2005-02-23 12:47:07 UTC (rev 94) @@ -39,13 +39,13 @@ delete im_claw_right; } -void Fang::in_left(Sint16 dt) { +void Fang::in_left(Uint16 dt) { Player::in_left(dt); - if (dt >= 0) unsetState(STATE_CLIMB_R); + unsetState(STATE_CLIMB_R); } -void Fang::in_right(Sint16 dt) { +void Fang::in_right(Uint16 dt) { Player::in_right(dt); - if (dt >= 0) unsetState(STATE_CLIMB_L); + unsetState(STATE_CLIMB_L); } void Fang::fall(Uint16 dt) { @@ -71,10 +71,7 @@ } } -void Fang::in_sp1(Sint16 dt) { - if (dt < 0) return; - input->unsetState(INPUT_SP1); - +void Fang::in_sp1() { if (state&STATE_CLIMB_L) { unsetState(STATE_LEFT); unsetState(STATE_CLIMB_L); @@ -96,10 +93,7 @@ } } -void Fang::in_sp2(Sint16 dt) { - if (dt < 0) return; - input->unsetState(INPUT_SP2); - +void Fang::in_sp2() { setEvent(new EAttack(this,10,&weapon,(state&STATE_LEFT) ? DIR_LEFT : DIR_RIGHT,10,enemy_types,0,0,au_claw,(state&STATE_LEFT) ? im_claw_left : im_claw_right)); } Modified: trunk/src/objects/fang.h =================================================================== --- trunk/src/objects/fang.h 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/objects/fang.h 2005-02-23 12:47:07 UTC (rev 94) @@ -25,12 +25,12 @@ Fang(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Fang"); virtual ~Fang(); virtual void fall(Uint16); - virtual void in_left(Sint16); - virtual void in_right(Sint16); + virtual void in_left(Uint16); + virtual void in_right(Uint16); /// \brief Fang jumps - virtual void in_sp1(Sint16); + virtual void in_sp1(); /// \brief Fang attacks - virtual void in_sp2(Sint16); + virtual void in_sp2(); virtual void clearStates(bool reset=false); private: virtual void crash(Uint16 dir=DIR_DOWN); Modified: trunk/src/objects/olaf.cpp =================================================================== --- trunk/src/objects/olaf.cpp 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/objects/olaf.cpp 2005-02-23 12:47:07 UTC (rev 94) @@ -91,15 +91,15 @@ curpos.y=(pos.h-curpos.h); } -void Olaf::in_left(Sint16 dt) { +void Olaf::in_left(Uint16 dt) { //No navigation while farting from ground (replace this by a busy event) - if ((dt < 0) || (!(state&STATE_ACT_2))) { + if (!(state&STATE_ACT_2)) { Player::in_left(dt); } } -void Olaf::in_right(Sint16 dt) { +void Olaf::in_right(Uint16 dt) { //No navigation while farting from ground (replace this by a busy event) - if ((dt < 0) || (!(state&STATE_ACT_2))) { + if (!(state&STATE_ACT_2)) { Player::in_right(dt); } } @@ -135,32 +135,24 @@ } else return false; } -void Olaf::in_down(Sint16 dt) { - if (dt < 0) return; - input->unsetState(INPUT_DOWN); +void Olaf::in_down() { //TODO: ladder if (!(state&STATE_FALL)) trySmall(true); } -void Olaf::in_up(Sint16 dt) { - if (dt < 0) return; - input->unsetState(INPUT_UP); +void Olaf::in_up() { //TODO: ladder if (!(state&STATE_FALL)) trySmall(false); } -void Olaf::in_sp1(Sint16 dt) { - if (dt < 0) return; - input->unsetState(INPUT_SP1); +void Olaf::in_sp1() { //no specials while small if (!(state&STATE_SMALL)) { switchState(STATE_SHIELD); } } -void Olaf::in_sp2(Sint16 dt) { - if (dt < 0) return; - input->unsetState(INPUT_SP2); +void Olaf::in_sp2() { //no specials while small if (!(state&STATE_SMALL)) { //Don't fart while falling without shield Modified: trunk/src/objects/olaf.h =================================================================== --- trunk/src/objects/olaf.h 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/objects/olaf.h 2005-02-23 12:47:07 UTC (rev 94) @@ -20,17 +20,17 @@ virtual ~Olaf(); /// Additionally checks if Olaf is small and how he wears his shield virtual void updateAnimState(bool change=true); - virtual void in_left(Sint16); - virtual void in_right(Sint16); + virtual void in_left(Uint16); + virtual void in_right(Uint16); /// \brief Olaf tries to shrink (if he was big) - virtual void in_down(Sint16); + virtual void in_down(); /// \brief Olaf tries to get big again (if he was small) - virtual void in_up(Sint16); - virtual void fall(Uint16); + virtual void in_up(); /// \brief Olaf switches his shield state if possible - virtual void in_sp1(Sint16); + virtual void in_sp1(); /// \brief Olaf farts - virtual void in_sp2(Sint16); + virtual void in_sp2(); + virtual void fall(Uint16); virtual Uint16 hit(Uint16 direction,Weapon& weap); private: /// \brief Tries to change the size Modified: trunk/src/objects/scorch.cpp =================================================================== --- trunk/src/objects/scorch.cpp 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/objects/scorch.cpp 2005-02-23 12:47:07 UTC (rev 94) @@ -35,6 +35,15 @@ delete im_land_right; } +void Scorch::idle(Uint16 dt) { + Player::idle(dt); + if (!input->keyState(KEY_SP1)) { + unsetState(STATE_GLIDE); + } else if (!(state&STATE_ACT_2)) { + setState(STATE_GLIDE); + } +} + void Scorch::fall(Uint16 dt) { if (!getState(STATE_MRIGHT|STATE_MLEFT)) { if (!getState(STATE_FALL)) hspeed=boost(hspeed,-dt*HSPEED_MULT/100); @@ -52,29 +61,17 @@ } } -void Scorch::in_sp1(Sint16 dt) { - if (dt < 0) { - unsetState(STATE_ACT_1); - unsetState(STATE_GLIDE); - input->unsetState(INPUT_SP1); - return; - } +void Scorch::in_sp1() { setState(STATE_FALL); - //if not exhausted -> glide - if (!(state&STATE_ACT_2)) { - setState(STATE_GLIDE); - } //Can't fly anymore - if ((state&STATE_ACT_1)||(state&STATE_ACT_2)) { + if (state&STATE_ACT_2) { } else if (left_wings<=0) { - setState(STATE_ACT_1); setState(STATE_ACT_2); unsetState(STATE_GLIDE); addSpeed(V_FLY); setEvent(new CAnimEvent(this,DE_WING,0,0,au_tired)); //Use Wings } else { - setState(STATE_ACT_1); left_wings--; addSpeed(V_FLY); setEvent(new CAnimEvent(this,DE_WING,0,0,au_swing)); @@ -85,7 +82,6 @@ Player::clearStates(reset); if (reset) { unsetState(STATE_GLIDE); - input->unsetState(INPUT_SP1); left_wings=SCORCH_MAX_WINGS; } } Modified: trunk/src/objects/scorch.h =================================================================== --- trunk/src/objects/scorch.h 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/objects/scorch.h 2005-02-23 12:47:07 UTC (rev 94) @@ -20,7 +20,8 @@ virtual ~Scorch(); virtual void fall(Uint16); /// \brief Scorch uses his wings - virtual void in_sp1(Sint16); + virtual void idle(Uint16); + virtual void in_sp1(); virtual void clearStates(bool reset=false); private: Uint8 left_wings; Modified: trunk/src/physics.cpp =================================================================== --- trunk/src/physics.cpp 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/physics.cpp 2005-02-23 12:47:07 UTC (rev 94) @@ -9,100 +9,124 @@ PhysicHandler::PhysicHandler(): tstart(SDL_GetTicks()), - dt(0) { + dt(0), + reset_time(true), + Dfps(0), + Dframes(0), + currentfps(0), + minfps(1000) { tcurrent=tstart; } PhysicHandler::~PhysicHandler() { } -Uint16 PhysicHandler::resetTime() { - dt=0; - return (tcurrent=SDL_GetTicks()); +void PhysicHandler::update() { + if (menu) { + reset_time=true; + } else if (paused) { + reset_time=true; + updatePaused(); + } else { + if (reset_time) { + Dfps=Dframes=currentfps=dt=0; + minfps=1000; + } else { + dt=(SDL_GetTicks()-tcurrent); + updateFPS(); + } + reset_time=false; + tcurrent=SDL_GetTicks(); + updateGame(); + } } -void PhysicHandler::update() { - dt=(SDL_GetTicks()-tcurrent); - tcurrent=SDL_GetTicks(); +inline void PhysicHandler::updateGame() { + 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; + } + //handle current (new) scenario->player - //Game is running normally - if (!paused) { - //released keys of player - if (scenario->player != NULL) { - if (input->getState(INPUTR_USE)) scenario->player->in_use(-1); - input->unsetState(INPUTR_USE); - if (input->getState(INPUTR_ACT)) scenario->player->in_act(-1); - input->unsetState(INPUTR_ACT); - if (input->getState(INPUTR_RIGHT)) scenario->player->in_right(-1); - input->unsetState(INPUTR_RIGHT); - if (input->getState(INPUTR_LEFT)) scenario->player->in_left(-1); - input->unsetState(INPUTR_LEFT); - if (input->getState(INPUTR_SP1)) scenario->player->in_sp1(-1); - input->unsetState(INPUTR_SP1); - if (input->getState(INPUTR_SP2)) scenario->player->in_sp2(-1); - input->unsetState(INPUTR_SP2); - if (input->getState(INPUTR_UP)) scenario->player->in_up(-1); - input->unsetState(INPUTR_UP); - if (input->getState(INPUTR_DOWN)) scenario->player->in_down(-1); - input->unsetState(INPUTR_DOWN); - input->unsetState(INPUTR_DEL); + if ((scenario->player!=NULL) && (!(scenario->player->getState(ESTATE_BUSY)))) { + if (input->keyPressed(KEY_USE)) scenario->player->in_use(); + if (input->keyPressed(KEY_ACT)) scenario->player->in_act(); + if (input->keyPressed(KEY_LEFT)) scenario->player->in_left(); + if (input->keyPressed(KEY_RIGHT)) scenario->player->in_right(); + if (input->keyPressed(KEY_UP)) scenario->player->in_up(); + if (input->keyPressed(KEY_DOWN)) scenario->player->in_down(); + if (input->keyState(KEY_LEFT)) { + scenario->player->unsetState(STATE_MRIGHT); + scenario->player->setState(STATE_MLEFT); + } else { + scenario->player->unsetState(STATE_MLEFT); } - 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; + if (input->keyState(KEY_RIGHT)) { + scenario->player->unsetState(STATE_MLEFT); + scenario->player->setState(STATE_MRIGHT); + } else { + scenario->player->unsetState(STATE_MRIGHT); } - obit=scenario->pool->objectspool.begin(); - while (obit!=scenario->pool->objectspool.end()) { - (*obit)->idle(dt); - (*obit)->updateEvents(dt); - ++obit; + if ((!(scenario->player->getState(ESTATE_RUN)))||scenario->player->getState(ESTATE_ABORT)) { + if (input->keyPressed(KEY_SP1)) scenario->player->in_sp1(); + if (input->keyPressed(KEY_SP2)) scenario->player->in_sp2(); } - //handle current (new) scenario->player - if ((scenario->player!=NULL) && (!(scenario->player->getState(ESTATE_BUSY)))) { - if (input->getState(INPUT_USE)) scenario->player->in_use(dt); - if (input->getState(INPUT_ACT)) scenario->player->in_act(dt); - if (input->getState(INPUT_RIGHT)) scenario->player->in_right(dt); - if (input->getState(INPUT_LEFT)) scenario->player->in_left(dt); - if ((!(scenario->player->getState(ESTATE_RUN)))||scenario->player->getState(ESTATE_ABORT)) { - if (input->getState(INPUT_SP1)) scenario->player->in_sp1(dt); - if (input->getState(INPUT_SP2)) scenario->player->in_sp2(dt); - } - if (input->getState(INPUT_UP)) scenario->player->in_up(dt); - if (input->getState(INPUT_DOWN)) scenario->player->in_down(dt); - } - //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; - } - //Game is paused + + if (input->keyState(KEY_LEFT)) scenario->player->in_left(dt); + if (input->keyState(KEY_RIGHT)) scenario->player->in_right(dt); + if (input->keyState(KEY_UP)) scenario->player->in_up(dt); + if (input->keyState(KEY_DOWN)) scenario->player->in_down(dt); } else { - if (input->getState(INPUT_RIGHT)) { - input->unsetState(INPUT_RIGHT); - scenario->player->switchItem(true); - } - if (input->getState(INPUT_LEFT)) { - input->unsetState(INPUT_LEFT); - scenario->player->switchItem(false); - } - if (input->getState(INPUT_DEL)) { - input->unsetState(INPUT_DEL); - scenario->player->dropItem(); - gfxeng->renderScene(true); - } + scenario->player->unsetState(STATE_MLEFT); + scenario->player->unsetState(STATE_MRIGHT); } + //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); + } + if (input->keyPressed(KEY_LEFT)) { + scenario->player->switchItem(false); + } + if (input->keyPressed(KEY_DROP)) { + scenario->player->dropItem(); + gfxeng->update(UPDATE_ALL); + } +} + +inline void PhysicHandler::updateFPS() { + Dfps+=dt; + ++Dframes; + if (Dfps>=100) { + currentfps=Uint16(Dframes*1000/Dfps); + if (currentfps < minfps) minfps=currentfps; + Dfps=Dframes=0; + } + +} Modified: trunk/src/physics.h =================================================================== --- trunk/src/physics.h 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/physics.h 2005-02-23 12:47:07 UTC (rev 94) @@ -10,11 +10,20 @@ ~PhysicHandler(); /// Updates all game states and animations void update(); - /// Resets the current time - /// \return New current time - Uint16 resetTime(); + Uint16 getFPS() { + return currentfps; + } + Uint16 getMinFPS() { + return minfps; + } private: Uint16 tstart, tcurrent, dt; + bool reset_time; + Uint16 Dfps,Dframes,currentfps,minfps; + private: + inline void updateGame(); + inline void updatePaused(); + inline void updateFPS(); }; #endif Modified: trunk/src/players_common.cpp =================================================================== --- trunk/src/players_common.cpp 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/players_common.cpp 2005-02-23 12:47:07 UTC (rev 94) @@ -177,9 +177,7 @@ Character::idle(dt); } -void Player::in_act(Sint16 dt) { - if (dt < 0) return; - input->unsetState(INPUT_ACT); +void Player::in_act() { object_iterator i=enter.begin(); while (i!=enter.end()) { if ((*i)->act(this)) { @@ -190,39 +188,23 @@ } } -void Player::in_use(Sint16 dt) { - if (dt < 0) return; - input->unsetState(INPUT_USE); +void Player::in_use() { if (items[currentitem]) { if (!(items[currentitem]->act(this))) sfxeng->playWAV(au_useerror); } } -void Player::in_right(Sint16 dt) { - if (dt < 0) { - unsetState(STATE_MRIGHT); - return; - } +void Player::in_right(Uint16 dt) { unsetState(STATE_LEFT); - setState(STATE_MRIGHT); if ((hspeed+HSPEED_MULT*dt/100)(-maxspeedx)) hspeed-=HSPEED_MULT*dt/100; else if (hspeed>(-maxspeedx)) hspeed=-maxspeedx; } -void Player::in_up(Sint16) { } -void Player::in_down(Sint16) { } -void Player::in_sp1(Sint16) { } -void Player::in_sp2(Sint16) { } Hit Player::move(Uint16 dt, bool check) { return Character::move(dt,check); @@ -276,10 +258,6 @@ } void Player::clearStates(bool reset) { - if (getState(STATE_MLEFT)) in_left(-1); - if (getState(STATE_MRIGHT)) in_right(-1); - if (getState(STATE_MUP)) in_up(-1); - if (getState(STATE_MDOWN)) in_down(-1); if (reset) { unsetState(STATE_ACT_1); unsetState(STATE_ACT_2); Modified: trunk/src/players_common.h =================================================================== --- trunk/src/players_common.h 2005-02-22 13:51:28 UTC (rev 93) +++ trunk/src/players_common.h 2005-02-23 12:47:07 UTC (rev 94) @@ -68,23 +68,27 @@ //Input methods //@{ /// \brief Called when using the move right key (right arrow) - virtual void in_right(Sint16); + virtual void in_right() { } + virtual void in_right(Uint16); /// \brief Called when using the move left key (left arrow) - virtual void in_left(Sint16); + virtual void in_left() { } + virtual void in_left(Uint16); /// \brief Called when using the move up key (up arrow) - virtual void in_up(Sint16); + virtual void in_up() { } + virtual void in_up(Uint16) { } /// \brief Called when using the move down key (down arrow) - virtual void in_down(Sint16); + virtual void in_down() { } + virtual void in_down(Uint16) { } /// \brief Called when using the special 1 key (space) - virtual void in_sp1(Sint16); + virtual void in_sp1() { } /// \brief Called when using the special 2 key (left shift) - virtual void in_sp2(Sint16); + virtual void in_sp2() { } /// \brief Called when using the activation key (enter) /// /// This should be the same for all players. - virtual void in_act(Sint16); + virtual void in_act(); /// \brief Called when using the use key (insert) - virtual void in_use(Sint16); + virtual void in_use(); //@} protected: //@{ From DONOTREPLY at icculus.org Wed Feb 23 10:06:42 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 23 Feb 2005 10:06:42 -0500 Subject: r95 - trunk/src Message-ID: <20050223150642.31942.qmail@icculus.org> Author: jonas Date: 2005-02-23 10:06:42 -0500 (Wed, 23 Feb 2005) New Revision: 95 Modified: trunk/src/gfxeng.cpp trunk/src/gfxeng.h trunk/src/menu.cpp trunk/src/menu.h trunk/src/scenario.cpp trunk/src/sfxeng.cpp trunk/src/sfxeng.h Log: - Enhanced the ConfigMenu - Improved the menu position code - Introduced music playback functions, moved decision to Scenario (Map) Modified: trunk/src/gfxeng.cpp =================================================================== --- trunk/src/gfxeng.cpp 2005-02-23 12:47:07 UTC (rev 94) +++ trunk/src/gfxeng.cpp 2005-02-23 15:06:42 UTC (rev 95) @@ -294,9 +294,16 @@ Uint16 h; for (Uint8 i=0; i< menu->getSize(); i++) { if (i<=menu->currententry) { - h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-i-1)*DFONT-(menu->getSize()-i-1)*(menu->font->getHeight())-menu->font_high->getHeight())/2; + h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-1)*DFONT-(menu->getSize()-1)*(menu->font->getHeight())-menu->font_high->getHeight())/2 + -DFONT + +i*DFONT + +i*(menu->font->getHeight()); } else { - h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-i-1)*DFONT-(menu->getSize()-i)*(menu->font->getHeight()))/2; + h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-1)*DFONT-(menu->getSize()-1)*(menu->font->getHeight())-menu->font_high->getHeight())/2 + -DFONT + +i*DFONT + +(i-1)*(menu->font->getHeight()) + +(menu->font_high->getHeight()); } if (i==menu->currententry) menu->font_high->writeCenter(screen,menu->entries[i],h); else menu->font->writeCenter(screen,menu->entries[i],h); Modified: trunk/src/gfxeng.h =================================================================== --- trunk/src/gfxeng.h 2005-02-23 12:47:07 UTC (rev 94) +++ trunk/src/gfxeng.h 2005-02-23 15:06:42 UTC (rev 95) @@ -3,7 +3,7 @@ #define BAR_HEIGHT 138 #define ICON_SIZE 46 -#define DFONT 40 +#define DFONT 10 #define UPDATE_NOTHING 0x00 #define UPDATE_BAR 0x01 @@ -16,7 +16,7 @@ frames per seconds. Always run time resizing and fullscreen switching. */ class GraphicsEngine { - friend class ConfigMenu; + friend class GraphicConfigMenu; public: GraphicsEngine(); ~GraphicsEngine(); Modified: trunk/src/menu.cpp =================================================================== --- trunk/src/menu.cpp 2005-02-23 12:47:07 UTC (rev 94) +++ trunk/src/menu.cpp 2005-02-23 15:06:42 UTC (rev 95) @@ -139,17 +139,70 @@ ConfigMenu::ConfigMenu(): Menu() { title="-== CONFIGURATION MENU ==-"; - entries.resize(2); + entries.resize(3); update(); } void ConfigMenu::act() { switch (currententry) { case 0: { + setMenu(new GraphicConfigMenu()); + break; + } + case 1: { + setMenu(new KeyConfigMenu()); + break; + } + default: { + break; + } + } +} +void ConfigMenu::update() { + entries[0]="Graphic settings"; + entries[1]="Keyboard settings"; + entries[2]="Save settings"; +} + + +KeyConfigMenu::KeyConfigMenu(): Menu() { + title="-== KEYBOARD SETTINGS ==-"; + entries.resize(11); + update(); +} +void KeyConfigMenu::act() { } +void KeyConfigMenu::update() { + entries[0]="Move left: [" + string(SDL_GetKeyName(config.keybind[KEY_LEFT])) + "]"; + entries[1]="Move right: [" + string(SDL_GetKeyName(config.keybind[KEY_RIGHT])) + "]"; + entries[2]="Move up: [" + string(SDL_GetKeyName(config.keybind[KEY_UP])) + "]"; + entries[3]="Move down: [" + string(SDL_GetKeyName(config.keybind[KEY_DOWN])) + "]"; + entries[4]="Special 1: [" + string(SDL_GetKeyName(config.keybind[KEY_SP1])) + "]"; + entries[5]="Special 2: [" + string(SDL_GetKeyName(config.keybind[KEY_SP2])) + "]"; + entries[6]="Activate: [" + string(SDL_GetKeyName(config.keybind[KEY_ACT])) + "]"; + entries[7]="Use item: [" + string(SDL_GetKeyName(config.keybind[KEY_USE])) + "]"; + entries[8]="Switch player: [" + string(SDL_GetKeyName(config.keybind[KEY_SWITCH])) + "]"; + entries[9]="Drop item: [" + string(SDL_GetKeyName(config.keybind[KEY_DROP])) + "]"; + entries[10]="Pause game: [" + string(SDL_GetKeyName(config.keybind[KEY_PAUSE])) + "]"; +} + + +GraphicConfigMenu::GraphicConfigMenu(): Menu() { + title="-== GRAPHIC SETTINGS ==-"; + entries.resize(4); + update(); +} +void GraphicConfigMenu::act() { + switch (currententry) { + case 1: { + gfxeng->toggleFullScreen(); + gfxeng->update(UPDATE_ALL); + break; + } + case 2: { gfxeng->toggleFPS(); gfxeng->update(UPDATE_MENU); break; } - case 1: { + case 3: { gfxeng->togglePlayerBar(); gfxeng->update(UPDATE_ALL); break; @@ -160,8 +213,9 @@ } update(); } -void ConfigMenu::update() { - entries[0]="Show FPS: "+string((gfxeng->show_fps) ? "ON" : "OFF"); - entries[1]="Show Player Bar: "+string((gfxeng->show_bar) ? "ON" : "OFF"); +void GraphicConfigMenu::update() { + entries[0]="Resolution: " + itos(gfxeng->screen->w) + " x " + itos(gfxeng->screen->h) + " (" + itos(config.bpp) + " bpp)"; + entries[1]="Fullscreen: " + string((gfxeng->fullscreen) ? "ON" : "OFF"); + entries[2]="Show FPS: "+string((gfxeng->show_fps) ? "ON" : "OFF"); + entries[3]="Show Player Bar: "+string((gfxeng->show_bar) ? "ON" : "OFF"); } - Modified: trunk/src/menu.h =================================================================== --- trunk/src/menu.h 2005-02-23 12:47:07 UTC (rev 94) +++ trunk/src/menu.h 2005-02-23 15:06:42 UTC (rev 95) @@ -80,4 +80,22 @@ void update(); }; +class GraphicConfigMenu : public Menu { + public: + GraphicConfigMenu(); + virtual void act(); + private: + /// Helper function + void update(); +}; + +class KeyConfigMenu : public Menu { + public: + KeyConfigMenu(); + virtual void act(); + private: + /// Helper function + void update(); +}; + #endif Modified: trunk/src/scenario.cpp =================================================================== --- trunk/src/scenario.cpp 2005-02-23 12:47:07 UTC (rev 94) +++ trunk/src/scenario.cpp 2005-02-23 15:06:42 UTC (rev 95) @@ -3,6 +3,7 @@ #include "players_common.h" #include "imgcache.h" #include "sndcache.h" +#include "sfxeng.h" #include "physics.h" #include "scenario.h" @@ -53,6 +54,7 @@ int Scenario::loadMap(string mapname) { reinitMap(); + sfxeng->playMusic((config.datadir + "01theme.wav").c_str()); name=mapname; ifstream mapfile; string tmpline; Modified: trunk/src/sfxeng.cpp =================================================================== --- trunk/src/sfxeng.cpp 2005-02-23 12:47:07 UTC (rev 94) +++ trunk/src/sfxeng.cpp 2005-02-23 15:06:42 UTC (rev 95) @@ -14,10 +14,7 @@ cout << "Opened audio at " << config.audio_rate << " Hz " << (config.audio_format&0xFF) << " bit " << ((config.audio_channels > 1) ? "stereo" : "mono") << endl; disabled=false; } - - if (!disabled) theme = Mix_LoadMUS("data/01theme.wav"); - if (!disabled) Mix_FadeInMusic(theme, -1, 5000); - if (!disabled) Mix_VolumeMusic(MIX_MAX_VOLUME/4); + theme=NULL; #endif } @@ -29,6 +26,24 @@ } #endif } +void SoundsEngine::playMusic(string name) { +#ifdef SDL_MIXER + if (!disabled) { + if (theme) Mix_FreeMusic(theme); + theme = Mix_LoadMUS(name.c_str()); + Mix_FadeInMusic(theme, -1, 5000); + Mix_VolumeMusic(MIX_MAX_VOLUME/4); + } +#endif +} +void SoundsEngine::stopMusic() { +#ifdef SDL_MIXER + if (!disabled) { + if (theme) Mix_FreeMusic(theme); + theme=NULL; + } +#endif +} void SoundsEngine::pauseMusic() { #ifdef SDL_MIXER if (!disabled) Mix_PauseMusic(); Modified: trunk/src/sfxeng.h =================================================================== --- trunk/src/sfxeng.h 2005-02-23 12:47:07 UTC (rev 94) +++ trunk/src/sfxeng.h 2005-02-23 15:06:42 UTC (rev 95) @@ -12,6 +12,8 @@ ~SoundsEngine(); /// Play the specified sound void playWAV(Mix_Chunk* wav); + void playMusic(string); + void stopMusic(); void pauseMusic(); void resumeMusic(); private: From DONOTREPLY at icculus.org Wed Feb 23 10:16:14 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 23 Feb 2005 10:16:14 -0500 Subject: r96 - trunk/src Message-ID: <20050223151614.765.qmail@icculus.org> Author: jonas Date: 2005-02-23 10:16:13 -0500 (Wed, 23 Feb 2005) New Revision: 96 Modified: trunk/src/input.cpp Log: 100l, forgot keypressed/keystate for Menu/Paused... Modified: trunk/src/input.cpp =================================================================== --- trunk/src/input.cpp 2005-02-23 15:06:42 UTC (rev 95) +++ trunk/src/input.cpp 2005-02-23 15:16:13 UTC (rev 96) @@ -38,6 +38,9 @@ } inline void InputHandler::pollMenuEvents() { + for (Uint16 i=0; iincreaseEntry(false); } else if (key==config.keybind[KEY_DOWN]) { @@ -78,9 +82,13 @@ } } } + keystate = SDL_GetKeyState(NULL); } inline void InputHandler::pollPausedEvents() { + for (Uint16 i=0; ipool->switchPlayer(); } else if (key==config.keybind[KEY_PAUSE]) { @@ -115,6 +124,7 @@ } } } + keystate = SDL_GetKeyState(NULL); } inline void InputHandler::pollGameEvents() { From DONOTREPLY at icculus.org Thu Feb 24 06:55:38 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 24 Feb 2005 06:55:38 -0500 Subject: r97 - trunk/src Message-ID: <20050224115538.1550.qmail@icculus.org> Author: jonas Date: 2005-02-24 06:55:38 -0500 (Thu, 24 Feb 2005) New Revision: 97 Modified: trunk/src/font.cpp trunk/src/font.h trunk/src/gfxeng.cpp trunk/src/gfxeng.h trunk/src/menu.cpp Log: support for large menus, introduced a private vflag for gfxeng which represents the currently used video flags Modified: trunk/src/font.cpp =================================================================== --- trunk/src/font.cpp 2005-02-23 15:16:13 UTC (rev 96) +++ trunk/src/font.cpp 2005-02-24 11:55:38 UTC (rev 97) @@ -103,6 +103,10 @@ write(surface, text, surface->w/2 - getTextWidth(text)/2, y); } +void Font::writeCenter(SDL_Surface *surface, string text, int x, int y) const { + write(surface, text, x - getTextWidth(text)/2, y); +} + Uint32 Font::getPixel(SDL_Surface *surface, Sint32 X, Sint32 Y) { Uint8 *bits; Uint32 Bpp; Modified: trunk/src/font.h =================================================================== --- trunk/src/font.h 2005-02-23 15:16:13 UTC (rev 96) +++ trunk/src/font.h 2005-02-24 11:55:38 UTC (rev 97) @@ -40,6 +40,7 @@ int getTextWidth(std::string text) const; void write(SDL_Surface* surface, std::string text, int x, int y) const; void writeCenter(SDL_Surface* surface, std::string text, int y) const; + void writeCenter(SDL_Surface* surface, std::string text, int x, int y) const; private: SFont_Font* initFont(SDL_Surface* Font); static Uint32 getPixel(SDL_Surface* surface, Sint32 X, Sint32 Y); Modified: trunk/src/gfxeng.cpp =================================================================== --- trunk/src/gfxeng.cpp 2005-02-23 15:16:13 UTC (rev 96) +++ trunk/src/gfxeng.cpp 2005-02-24 11:55:38 UTC (rev 97) @@ -17,7 +17,8 @@ menubg(NULL), show_bar(true), show_fps(true), - fullscreen(config.full) { + fullscreen(config.full), + vflags(SDL_HWSURFACE|SDL_RESIZABLE|SDL_DOUBLEBUF) { #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; @@ -88,8 +89,10 @@ void GraphicsEngine::resize(Uint16 width, Uint16 height) { if (screen) SDL_FreeSurface(screen); - - if ((screen=SDL_SetVideoMode(width,height,config.bpp,SDL_HWSURFACE|SDL_RESIZABLE|SDL_DOUBLEBUF|(fullscreen ? SDL_FULLSCREEN : 0))) != NULL) { + if (fullscreen) vflags|=SDL_FULLSCREEN; + else vflags&=~SDL_FULLSCREEN; + + if ((screen=SDL_SetVideoMode(width,height,config.bpp,vflags)) != NULL) { } else { cout << "Couldn't set VideoMode: " << SDL_GetError() << endl; quitGame(-1); @@ -291,22 +294,41 @@ menu->font_title->writeCenter(screen,menu->title,0); + //size of the menu in pixels if it was just one row + Uint16 menu_pix_size = (menu->getSize()-1)*DFONT+(menu->getSize()-1)*(menu->font->getHeight())+menu->font_high->getHeight(); + //number of rows to use + Uint8 rows = menu_pix_size/(screen->h-menu->font_title->getHeight()-DFONT)+1; + //number of entries per row + Uint8 row_size = menu->getSize()/rows+1; + //size of one row in pixels, differs from menu_pix_size/rows and depends on the currententry + Uint16 row_pix_size = (row_size-1)*DFONT+row_size*(menu->font->getHeight()); + Uint16 currow_pix_size = (row_size-1)*DFONT+(row_size-1)*(menu->font->getHeight())+menu->font_high->getHeight(); + //current height of the text Uint16 h; + //current row + Uint8 currow = 0; + //true if the currententry is in the current row + bool current_row = false; + for (Uint8 i=0; i< menu->getSize(); i++) { - if (i<=menu->currententry) { - h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-1)*DFONT-(menu->getSize()-1)*(menu->font->getHeight())-menu->font_high->getHeight())/2 + if (i>=row_size*(currow+1)) currow++; + if (menu->currententry>=row_size*currow && menu->currententrycurrententry || (!current_row)) { + h=(screen->h+menu->font_title->getHeight()-(current_row ? currow_pix_size : row_pix_size))/2 -DFONT - +i*DFONT - +i*(menu->font->getHeight()); + +(i-row_size*currow)*DFONT + +(i-row_size*currow)*(menu->font->getHeight()); } else { - h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-1)*DFONT-(menu->getSize()-1)*(menu->font->getHeight())-menu->font_high->getHeight())/2 + h=(screen->h+menu->font_title->getHeight()-currow_pix_size)/2 -DFONT - +i*DFONT - +(i-1)*(menu->font->getHeight()) + +(i-row_size*currow)*DFONT + +(i-1-row_size*currow)*(menu->font->getHeight()) +(menu->font_high->getHeight()); } - if (i==menu->currententry) menu->font_high->writeCenter(screen,menu->entries[i],h); - else menu->font->writeCenter(screen,menu->entries[i],h); + if (i==menu->currententry) menu->font_high->writeCenter(screen,menu->entries[i],currow*(screen->w)/rows+(screen->w)/rows/2,h); + else menu->font->writeCenter(screen,menu->entries[i],currow*(screen->w)/rows+(screen->w)/rows/2,h); } } Modified: trunk/src/gfxeng.h =================================================================== --- trunk/src/gfxeng.h 2005-02-23 15:16:13 UTC (rev 96) +++ trunk/src/gfxeng.h 2005-02-24 11:55:38 UTC (rev 97) @@ -51,6 +51,8 @@ bool fullscreen; //update state Uint8 updatetype; + //video flags + Uint32 vflags; protected: /// Draw the background and all objects in the pool. This is a very time /// consuming function... Modified: trunk/src/menu.cpp =================================================================== --- trunk/src/menu.cpp 2005-02-23 15:16:13 UTC (rev 96) +++ trunk/src/menu.cpp 2005-02-24 11:55:38 UTC (rev 97) @@ -187,22 +187,21 @@ GraphicConfigMenu::GraphicConfigMenu(): Menu() { title="-== GRAPHIC SETTINGS ==-"; - entries.resize(4); update(); } void GraphicConfigMenu::act() { switch (currententry) { - case 1: { + case 0: { gfxeng->toggleFullScreen(); gfxeng->update(UPDATE_ALL); break; } - case 2: { + case 1: { gfxeng->toggleFPS(); gfxeng->update(UPDATE_MENU); break; } - case 3: { + case 2: { gfxeng->togglePlayerBar(); gfxeng->update(UPDATE_ALL); break; @@ -214,8 +213,22 @@ update(); } void GraphicConfigMenu::update() { - entries[0]="Resolution: " + itos(gfxeng->screen->w) + " x " + itos(gfxeng->screen->h) + " (" + itos(config.bpp) + " bpp)"; - entries[1]="Fullscreen: " + string((gfxeng->fullscreen) ? "ON" : "OFF"); - entries[2]="Show FPS: "+string((gfxeng->show_fps) ? "ON" : "OFF"); - entries[3]="Show Player Bar: "+string((gfxeng->show_bar) ? "ON" : "OFF"); + entries.resize(4); + char driver_name[10]; + SDL_VideoDriverName(driver_name, 10); + + entries[0]="Fullscreen: " + string((gfxeng->fullscreen) ? "ON" : "OFF"); + entries[1]="Show FPS: "+string((gfxeng->show_fps) ? "ON" : "OFF"); + entries[2]="Show Player Bar: "+string((gfxeng->show_bar) ? "ON" : "OFF"); + entries[3]="Video settings: [" + string(driver_name) + "] " + itos(gfxeng->screen->w) + " x " + itos(gfxeng->screen->h) + " (" + itos(config.bpp) + " bpp)"; +/* + entries.push_back(""); + + SDL_Rect** modes=SDL_ListModes(NULL, gfxeng->vflags); + if(modes == (SDL_Rect **)0) entries.push_back("No modes available"); + else if(modes == (SDL_Rect **)-1) entries.push_back("All resolutions available"); + else { + for(Uint16 i=0;modes[i];++i) entries.push_back(itos(modes[i]->w) + " x " + itos(modes[i]->h)); + } +*/ }