r85 - in trunk: . src src/objects
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Wed Feb 9 16:41:07 EST 2005
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<Object *> 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<Character *> targets=curmap->getCharactersIn(mask,*owner->getPos(),true,range,direction);
+ std::set<Character *> 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.x<vis_map.w) shift.x=vis_map.w-maparea->w;
- if (maparea->h+shift.y<vis_map.h) shift.y=vis_map.h-maparea->h;
+ if (scenario->area->w+shift.x<vis_map.w) shift.x=vis_map.w-scenario->area->w;
+ if (scenario->area->h+shift.y<vis_map.h) shift.y=vis_map.h-scenario->area->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<Character *> Map::getCharactersIn(Uint16 mask, const SDL_Rect& rect, bool touch, Uint16 distance, Uint16 dir) const {
+std::set<Character *> 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<Monster*>(*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<Monster*>(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<Character *> targets=curmap->getCharactersIn(OTYPE_MONSTER,getCenter(),true,pos.w+1,dir);
+ std::set<Character *> 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<Character *> characters=curmap->getCharactersIn(OTYPE_PLAYER,pos,true);
+ std::set<Character *> characters=scenario->getCharactersIn(OTYPE_PLAYER,pos,true);
std::set<Character *>::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<Player*>(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<Character *> cset=curmap->getCharactersIn(enemy_types,pos,true);
+ std::set<Character *> 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<Character*>(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<Character *> cset=curmap->getCharactersIn(enemy_types,pos,true,20);
+ std::set<Character *> 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));
More information about the lostpenguins-commits
mailing list