r157 - in trunk: . src src/objects
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Thu Sep 8 06:09:02 EDT 2005
Author: jonas
Date: 2005-09-08 06:09:00 -0400 (Thu, 08 Sep 2005)
New Revision: 157
Modified:
trunk/TODO
trunk/src/characters_common.cpp
trunk/src/characters_common.h
trunk/src/common.cpp
trunk/src/common.h
trunk/src/editor.cpp
trunk/src/editor.h
trunk/src/gfxeng.h
trunk/src/monsters_common.cpp
trunk/src/monsters_common.h
trunk/src/objectpools.cpp
trunk/src/objectpools.h
trunk/src/objects/baleog.cpp
trunk/src/objects/baleog.h
trunk/src/objects/bomb.cpp
trunk/src/objects/bomb.h
trunk/src/objects/door.cpp
trunk/src/objects/door.h
trunk/src/objects/erik.cpp
trunk/src/objects/erik.h
trunk/src/objects/exit.cpp
trunk/src/objects/exit.h
trunk/src/objects/fang.cpp
trunk/src/objects/fang.h
trunk/src/objects/geyser.cpp
trunk/src/objects/geyser.h
trunk/src/objects/heart.cpp
trunk/src/objects/heart.h
trunk/src/objects/key.cpp
trunk/src/objects/key.h
trunk/src/objects/olaf.cpp
trunk/src/objects/olaf.h
trunk/src/objects/plant.cpp
trunk/src/objects/plant.h
trunk/src/objects/scorch.cpp
trunk/src/objects/scorch.h
trunk/src/objects/spike.cpp
trunk/src/objects/spike.h
trunk/src/objects/teleport.cpp
trunk/src/objects/teleport.h
trunk/src/objects/trigger.cpp
trunk/src/objects/trigger.h
trunk/src/objects/triggered_bomb.cpp
trunk/src/objects/triggered_bomb.h
trunk/src/objects/wall.cpp
trunk/src/objects/wall.h
trunk/src/objects/water.cpp
trunk/src/objects/water.h
trunk/src/objects/wind.cpp
trunk/src/objects/wind.h
trunk/src/objects/zombie.cpp
trunk/src/objects/zombie.h
trunk/src/objects_common.cpp
trunk/src/objects_common.h
trunk/src/players_common.cpp
trunk/src/players_common.h
trunk/src/scenario.cpp
trunk/src/scenario.h
Log:
Big rewrite of the map/object loading:
o Introduced a ParameterMap (map<string option,string value>) to be
used for specifying object (and other) parameters in a common way
o An object constructor now has only 3 arguments:
Object(Sint16 x, Sint16 y, ParameterMap& parameters)
o All or many of the objects parameter can now be passed using the new
ParameterMap. If the parameter was not specified it will fallback to
a default parameter.
o Introduced static member default_parameters to each object and set the
values in objectspool ctor. This is used in the map editor...
o Added prelimenary loadAnimation(ParameterMap&) support (atm it only is
capable of loading a single image, using option "image")
o Changed the map format (see scenario.h)
-> There is now only one header at the beginning
-> Background belongs to the header now
-> Added getParameters() to get a ParameterMap from a paramlist string
-> Added putParameters() to get a paramlist string from a ParameterMap
o Added various helper functions: hasParam, getDirFromString, ObjectsPool::
setDefaultObjParam and getDefaultObjParambyName, GraphicsEngine::resetShift
o Editor saves map to the data directory now...
o Fixed a bug that caused the map editor to restart with a shift!=0
o Bomb places the TriggeredBomb useing addObjectbyName(), actually _only_
this function should be used from now on as the other functions don't
set the correct name...
o All Object ctor, ObjectsPool, Editor, map file parsing code has been
changed accordingly
o updated TODO
Modified: trunk/TODO
===================================================================
--- trunk/TODO 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/TODO 2005-09-08 10:09:00 UTC (rev 157)
@@ -1,11 +1,7 @@
Bugs
====
o zombie (bug in movement!, attacks too often, use events, etc...)
- o key vs. trigger in map2
- o fall event (DONE?)
- o players die event segfault (eg. olaf)
-
Code
====
@@ -16,7 +12,6 @@
o Use Singletons
o Create a better class hierarchy so we don't have a class playground...
o Better handle the different game states and replace the current conditional model
- o IDEA: Use boost to support better constructors (name loading)
o IDEA: create dynamical plugins for all objects (or compile all in)
o Move/crash/collisions:
@@ -63,7 +58,8 @@
with animations!!!
o REWRITE: the whole event system!!!
- o Scenario:
+ o Scenario / Map:
+ o Specify Background in header
o Add some nice animation, text box, etc when a level was completed (including printing
the map name).
o Simplify the scenario class and drastically reduce the public variables!!
@@ -83,7 +79,6 @@
o Monsters / AI: VERY BAD
o Game functionality (): BAD
o Events / Effects: BAD, MESS, NESTED
- o Object (including parameter) loading: BAD
o Move logic: ACCEPTABLE, BUGGED, NESTED
o Objects (players, items, etc): ACCEPTABLE
o Physic Handler: ACCEPTABLE, NESTED
@@ -91,6 +86,7 @@
o Scenario: OK, MESS, WORKS
o Collision detection: OK
o Fall logic: GOOD
+ o Object loading (parameters) loading: GOOD
o Animation / Image structure: VERY GOOD
Modified: trunk/src/characters_common.cpp
===================================================================
--- trunk/src/characters_common.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/characters_common.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -7,8 +7,8 @@
#include "characters_common.h"
-Character::Character(string imagename, Sint16 xcord, Sint16 ycord, string pname):
- Object(imagename,xcord,ycord,pname),
+Character::Character(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Object(xcord,ycord,parameters),
health(1),
maxhealth(1),
maxspeedx(300),
@@ -22,6 +22,16 @@
weapon(Weapon(0)) {
state=STATE_FALL;
otype|=OTYPE_CHARACTER;
+
+ /* Parameters */
+ if (hasParam(parameters,"maxhealth")) health=atoi(parameters["maxhealth"].c_str());
+ else maxhealth=1;
+ if (hasParam(parameters,"health")) health=min((int)maxhealth,atoi(parameters["health"].c_str()));
+ else health=min(1,(int)maxhealth);
+ if (hasParam(parameters,"maxspeedx")) health=atoi(parameters["maxspeedx"].c_str());
+ else maxspeedx=300;
+ if (hasParam(parameters,"maxspeedy")) health=atoi(parameters["maxspeedy"].c_str());
+ else maxspeedy=0;
}
Character::~Character() { }
Modified: trunk/src/characters_common.h
===================================================================
--- trunk/src/characters_common.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/characters_common.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -35,8 +35,9 @@
*/
class Character : public Object {
public:
- Character(string img, Sint16 xpos=0, Sint16 ypos=0, string name="Character");
+ Character(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Character();
+ static ParameterMap default_parameters;
Uint8 getHealth();
//@{
Sint16 getSpeed() const {
Modified: trunk/src/common.cpp
===================================================================
--- trunk/src/common.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/common.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -26,7 +26,7 @@
const Uint32 bmask=0x00ff0000;
const Uint32 amask=0xff000000;
#endif
-Uint32 vflags=SDL_HWSURFACE|SDL_RESIZABLE|SDL_DOUBLEBUF;
+Uint32 vflags=SDL_HWSURFACE|SDL_RESIZABLE|SDL_DOUBLEBUF|SDL_HWACCEL;
string itos(int i) {
std::stringstream s;
@@ -34,6 +34,65 @@
return s.str();
}
+ParameterMap getParameters(const string& parameterlist, char delim, char delimsub) {
+ ParameterMap parameters;
+ istringstream parameterlist_s(parameterlist);
+ string parameter,name,value,tmpstr;
+
+ while (std::getline(parameterlist_s,parameter,delim)) {
+ istringstream parameter_s(parameter);
+ std::getline(parameter_s,name,delimsub);
+ std::getline(parameter_s,value);
+
+ /* get rid of leading and trailing spaces: this part is silly ;)
+ all spaces, tabs, etc are converted to one single space */
+ istringstream name_s(name);
+ name="";
+ while (name_s >> tmpstr) {
+ if (!name.empty()) name+=" ";
+ name+=tmpstr;
+ }
+ istringstream value_s(value);
+ value="";
+ while (value_s >> tmpstr) {
+ if (!value.empty()) value+=" ";
+ value+=tmpstr;
+ }
+ parameters[name]=value;
+ }
+ return parameters;
+}
+
+string putParameters(const ParameterMap& parameters, char delim, char delimsub) {
+ string parameterlist;
+ ParameterMap::const_iterator it=parameters.begin();
+ while (it!=parameters.end()) {
+ if (!parameterlist.empty()) {
+ parameterlist+=delim;
+ parameterlist+=" ";
+ }
+ parameterlist+=(*it).first;
+ parameterlist+=delimsub;
+ parameterlist+=(*it).second;
+ ++it;
+ }
+ return parameterlist;
+}
+
+bool hasParam(ParameterMap& parameters, const string& str) {
+ if (parameters.find(str)!=parameters.end()) return true;
+ else return false;
+}
+
+Uint16 getDirFromString(const string& str) {
+ Uint16 direction=NOTHING;
+ if (str.find("up") !=string::npos) direction|=DIR_UP;
+ if (str.find("down") !=string::npos) direction|=DIR_DOWN;
+ if (str.find("left") !=string::npos) direction|=DIR_LEFT;
+ if (str.find("right") !=string::npos) direction|=DIR_RIGHT;
+ return direction;
+}
+
int addAbsolute(int a, int b) {
if (a>=0) return a=max(0,a+b);
else return a=min(0,a-b);
@@ -48,6 +107,7 @@
if (game_mode&GAME_EDIT && !(game_mode&GAME_MENU)) {
gfxeng->setShowDebug();
SDL_ShowCursor(SDL_ENABLE);
+ gfxeng->resetShift();
} else {
gfxeng->unsetShowDebug();
SDL_ShowCursor(SDL_DISABLE);
Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/common.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -50,10 +50,13 @@
typedef std::set<Player *>::iterator player_iterator;
typedef std::set<Monster *>::iterator monster_iterator;
typedef boost::shared_ptr<EmptyAnimation> EmptyAnimationPtr;
+typedef std::map<string,string> ParameterMap;
//Data
#define DATA_LVLFPS 6
#define DATA_LVLDUR 1000
+#define DATA_LVLPLAYER_W 25
+#define DATA_LVLPLAYER_H 30
//General definitions
#define NOTHING 0x00000000
@@ -207,6 +210,15 @@
/// \return 1 if the file was found, 0 otherwise
/// \todo Create a better config format
int readConfig(const string& filename);
+/// Parse a string parameter list and return it as a map<string,string>
+ParameterMap getParameters(const string& parameterlist, char delim=',', char delimsub='=');
+/// Convert the parameter map to a string
+string putParameters(const ParameterMap& parameters, char delim=',', char delimsub='=');
+/// Returns true if the parameter was found
+bool hasParam(ParameterMap& parameters, const string& str);
+/// Returns the direction from the given string: simply include one or a
+/// combination of "up", "down", "left", "right" in the string
+Uint16 getDirFromString(const string& str);
/// Parse the command line options
void parseInput(int argc,char* argv[]);
Modified: trunk/src/editor.cpp
===================================================================
--- trunk/src/editor.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/editor.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -12,7 +12,6 @@
string place_name="";
save_name="newmap.cfg";
box=NULL;
- place_obj_name=NULL;
}
Editor::~Editor() {
@@ -39,11 +38,10 @@
if (box) box->act(box->getCurrentEntry(x,y));
} else if (action&EDIT_PLACE_OBJECT) {
scenario->reloadMap();
- if (scenario->pool->addObjectbyName(place_name,place_image,xs,ys,place_arg1,place_arg2,place_arg3)) {
- appendtoBuf(place_name+" "+place_image+" "+itos(xs)+" "+itos(ys)+" "+place_arg1+" "+place_arg2+" "+place_arg3);
+ if (scenario->pool->addObjectbyName(place_name,xs,ys,place_parameters)) {
+ appendtoBuf(place_name+" "+itos(xs)+" "+itos(ys)+" "+putParameters(place_parameters));
}
- if (place_obj_name) (*place_obj_name)=scenario->pool->getNextObjectName(place_name);
-// action_mouse_pressed[SDL_BUTTON_LEFT]=EDIT_ACT_BOX;
+ place_parameters["name"]=scenario->pool->getNextObjectName(place_name);
} else { }
}
@@ -269,67 +267,9 @@
gfxeng->update(UPDATE_ALL);
if (curentry==-1 || curentry >= (Sint8)entries.size()) {
} else {
- string next_name=scenario->pool->getNextObjectName(entries[curentry]);
- if (entries[curentry]=="Wall") {
- editor->place_obj_name=&editor->place_arg1;
- editor->setBox(new ObjectBox(entries[curentry],"viking1.bmp",area.x,area.y,"Name: ",next_name));
- } else if (entries[curentry]=="Water") {
- editor->place_obj_name=&editor->place_arg1;
- editor->setBox(new ObjectBox(entries[curentry],"water.bmp",area.x,area.y,"Name: ",next_name));
- } else if (entries[curentry]=="Exit") {
- editor->setBox(new ObjectBox(entries[curentry],"exit.bmp",area.x,area.y,"Name: ",next_name));
- } else if (entries[curentry]=="Teleporter") {
- editor->place_obj_name=&editor->place_arg3;
- editor->setBox(new ObjectBox(entries[curentry],"viking1.bmp",area.x,area.y,"Teleport Destination (x coordinate): ","0","Teleport Destination (y coordinate): ","0","Name: ",next_name));
- } else if (entries[curentry]=="Wind") {
- editor->place_obj_name=&editor->place_arg2;
- editor->setBox(new ObjectBox(entries[curentry],"teleport_01.bmp",area.x,area.y,"Wind acceleration: ","0","Name: ",next_name));
- } else if (entries[curentry]=="Geyser") {
- editor->place_obj_name=&editor->place_arg2;
- editor->setBox(new ObjectBox(entries[curentry],"viking1.bmp",area.x,area.y,"Geyser force: ","0","Name: ",next_name));
- } else if (entries[curentry]=="Trigger") {
- editor->place_obj_name=&editor->place_arg2;
- editor->setBox(new ObjectBox(entries[curentry],"key.bmp",area.x,area.y,"Trigger target name: ","","Name: ",next_name,"Key name: ",""));
- } else if (entries[curentry]=="Door") {
- editor->place_obj_name=&editor->place_arg2;
- editor->setBox(new ObjectBox(entries[curentry],"viking1.bmp",area.x,area.y,"Key name: ","","Name: ",next_name));
- } else if (entries[curentry]=="Spike") {
- editor->place_obj_name=&editor->place_arg2;
- editor->setBox(new ObjectBox(entries[curentry],"viking1.bmp",area.x,area.y,"Direction (R=1,L=2,U=4,D=8): ","4","Name: ",next_name));
- } else if (entries[curentry]=="Heart") {
- editor->place_obj_name=&editor->place_arg1;
- editor->setBox(new ObjectBox(entries[curentry],"heart.bmp",area.x,area.y,"Name: ",next_name));
- } else if (entries[curentry]=="Key") {
- editor->place_obj_name=&editor->place_arg1;
- editor->setBox(new ObjectBox(entries[curentry],"key.bmp",area.x,area.y,"Name: ",next_name));
- } else if (entries[curentry]=="Bomb") {
- editor->place_obj_name=&editor->place_arg2;
- editor->setBox(new ObjectBox(entries[curentry],"bomb_fire.bmp",area.x,area.y,"Exploding time (in ms): ","0","Name: ",next_name));
- } else if (entries[curentry]=="Erik") {
- editor->place_obj_name=&editor->place_arg1;
- editor->setBox(new ObjectBox(entries[curentry],"viking.bmp",area.x,area.y,"Name: ",next_name));
- } else if (entries[curentry]=="Olaf") {
- editor->place_obj_name=&editor->place_arg1;
- editor->setBox(new ObjectBox(entries[curentry],"viking.bmp",area.x,area.y,"Name: ",next_name));
- } else if (entries[curentry]=="Baleog") {
- editor->place_obj_name=&editor->place_arg1;
- editor->setBox(new ObjectBox(entries[curentry],"viking.bmp",area.x,area.y,"Name: ",next_name));
- } else if (entries[curentry]=="Fang") {
- editor->place_obj_name=&editor->place_arg1;
- editor->setBox(new ObjectBox(entries[curentry],"viking.bmp",area.x,area.y,"Name: ",next_name));
- } else if (entries[curentry]=="Scorch") {
- editor->place_obj_name=&editor->place_arg1;
- editor->setBox(new ObjectBox(entries[curentry],"viking.bmp",area.x,area.y,"Name: ",next_name));
- } else if (entries[curentry]=="Plant") {
- editor->place_obj_name=&editor->place_arg2;
- editor->setBox(new ObjectBox(entries[curentry],"viking1.bmp",area.x,area.y,"Recovery time (in ms): ","0","Name: ",next_name));
- } else if (entries[curentry]=="Zombie") {
- editor->place_obj_name=&editor->place_arg1;
- editor->setBox(new ObjectBox(entries[curentry],"viking.bmp",area.x,area.y,"Name: ",next_name));
- } else {
- editor->run_action(EDIT_RESET_ACTIONS);
- editor->closeBox();
- }
+ ParameterMap parameters=scenario->pool->getDefaultObjParambyName(entries[curentry]);
+ parameters["name"]=scenario->pool->getNextObjectName(entries[curentry]);
+ editor->setBox(new ObjectBox(entries[curentry],area.x,area.y,parameters));
}
}
@@ -400,22 +340,32 @@
void SaveAsBox::evaluateEntry() {
editor->save_name=einput[0];
- editor->saveBuf(editor->save_name);
+ editor->saveBuf(config.datadir+editor->save_name);
editor->closeBox();
}
OpenMapBox::OpenMapBox(Sint16 x, Sint16 y): TextInputBox(x,y) {
title="Open Map";
+ currententry=0;
einput.push_back(scenario->mapname);
update();
}
void OpenMapBox::evaluateEntry() {
scenario->resetScenario();
- scenario->loadMap(einput[0]);
+ string oldname=scenario->mapname;
+ if (scenario->loadMap(einput[0])!=0) {
+ cout << "Map loading failed!" << endl;
+ if (scenario->loadMap(oldname)!=0) {
+ cout << "Couldn't even load the original map!" << endl;
+ startScreen();
+ }
+ }
editor->closeBox();
}
+/* TODO: support not just image bgs
+ TODO: support additional header options */
NewMapBox::NewMapBox(Sint16 x, Sint16 y): TextInputBox(x,y) {
title="New Map";
centered=false;
@@ -427,39 +377,34 @@
void NewMapBox::evaluateEntry() {
scenario->resetScenario();
+ ParameterMap bg_parameters;
+ bg_parameters["image"]=einput[1];
scenario->mapname=einput[0];
- scenario->newMap(einput[1]);
+ scenario->newMap(bg_parameters);
scenario->reloadMap();
editor->closeBox();
}
-ObjectBox::ObjectBox(string name, string image, Sint16 x, Sint16 y, string targ1, string arg1, string targ2, string arg2, string targ3, string arg3): TextInputBox(x,y),
+ObjectBox::ObjectBox(string name, Sint16 x, Sint16 y, ParameterMap& parameters): TextInputBox(x,y),
objname(name) {
title=name+" Properties";
centered=false;
currententry=0;
- etitles.push_back("Image name: "); einput.push_back(image);
- if (targ1!="" || arg1!="") {
- etitles.push_back(targ1);
- einput.push_back(arg1);
+ ParameterMap::iterator it=parameters.begin();
+ while (it!=parameters.end()) {
+ etitles.push_back((*it).first);
+ einput.push_back((*it).second);
+ ++it;
}
- if (targ2!="" || arg2!="") {
- etitles.push_back(targ2);
- einput.push_back(arg2);
- }
- if (targ3!="" || arg3!="") {
- etitles.push_back(targ3);
- einput.push_back(arg3);
- }
update();
}
void ObjectBox::evaluateEntry() {
editor->place_name=objname;
- editor->place_image=einput[0];
- if (einput.size()>=2) editor->place_arg1=einput[1];
- if (einput.size()>=3) editor->place_arg2=einput[2];
- if (einput.size()>=4) editor->place_arg3=einput[3];
+ editor->place_parameters.clear();
+ for (Uint8 i=0; i<einput.size(); ++i) {
+ if (!einput[i].empty()) editor->place_parameters[etitles[i]]=einput[i];
+ }
editor->action_mouse_pressed[SDL_BUTTON_LEFT]=EDIT_PLACE_OBJECT;
editor->closeBox();
}
Modified: trunk/src/editor.h
===================================================================
--- trunk/src/editor.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/editor.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -84,7 +84,7 @@
*/
class ObjectBox : public TextInputBox {
public:
- ObjectBox(string,string,Sint16,Sint16,string targ1="",string arg1="",string targ2="",string arg2="",string targ3="",string arg3="");
+ ObjectBox(string,Sint16,Sint16,ParameterMap& parameters);
protected:
virtual void evaluateEntry();
string objname;
@@ -150,16 +150,8 @@
string save_name;
/// Object to place when clicking the left mouse button
string place_name;
- /// Image name of the placed object
- string place_image;
- /// Object name to place when clicking the left mouse button
- string* place_obj_name;
- /// First additonal parameter of the placed object
- string place_arg1;
- /// Seconds additional parameter of the placed object
- string place_arg2;
- /// Third additional parameter of the placed object
- string place_arg3;
+ /// Parameter list used to create the object
+ ParameterMap place_parameters;
/// Append a command to the buffered map file
void appendtoBuf(string);
/* TODO: add header modifiers */
Modified: trunk/src/gfxeng.h
===================================================================
--- trunk/src/gfxeng.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/gfxeng.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -38,6 +38,9 @@
const SDL_Rect& getShift() {
return shift;
}
+ void resetShift() {
+ shift.x=shift.y=0;
+ }
void drawRectangle(SDL_Rect rect, Uint8 border=1, Uint32 color=0);
protected:
/// main screen
Modified: trunk/src/monsters_common.cpp
===================================================================
--- trunk/src/monsters_common.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/monsters_common.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -10,20 +10,24 @@
#include "players_common.h"
-Monster::Monster(string imagename, Sint16 xcord, Sint16 ycord, string pname):
- Character(imagename,xcord,ycord,pname),
+Monster::Monster(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Character(xcord,ycord,parameters),
Dai(0),
Dattack(0),
anim_left(new EmptyAnimation(&anim_right)),
anim_right(new EmptyAnimation()) {
- health=1;
- maxspeedx=50;
- maxspeedy=0;
state=STATE_FALL;
otype|=OTYPE_MONSTER;
enemy_types|=OTYPE_PLAYER;
dense_types|=OTYPE_PLAYER;
- au_hit=scenario->sndcache->loadWAV("monhit.wav");
+
+ /* Parameters */
+ if (!hasParam(parameters,"maxhealth")) maxhealth=1;
+ if (!hasParam(parameters,"health")) health=min(1,(int)maxhealth);
+ if (!hasParam(parameters,"maxspeedx")) maxspeedx=50;
+ if (!hasParam(parameters,"maxspeedy")) maxspeedy=0;
+ if (hasParam(parameters,"audio_hit")) au_hit=scenario->sndcache->loadWAV(parameters["audio_hit"]);
+ else au_hit=scenario->sndcache->loadWAV("monhit.wav");
}
Monster::~Monster() {
Modified: trunk/src/monsters_common.h
===================================================================
--- trunk/src/monsters_common.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/monsters_common.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -9,8 +9,9 @@
*/
class Monster : public Character {
public:
- Monster(string img, Sint16 xpos=0, Sint16 ypos=0, string name="Monster");
+ Monster(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Monster();
+ static ParameterMap default_parameters;
virtual void removedObject(Object*);
virtual void updateAnimState();
virtual void idle(Uint16);
Modified: trunk/src/objectpools.cpp
===================================================================
--- trunk/src/objectpools.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objectpools.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -30,6 +30,37 @@
#include "objects/zombie.h"
+ParameterMap Object::default_parameters;
+ParameterMap Background::default_parameters;
+ParameterMap Trigger::default_parameters;
+ParameterMap Door::default_parameters;
+ParameterMap Exit::default_parameters;
+ParameterMap Teleporter::default_parameters;
+ParameterMap Wall::default_parameters;
+ParameterMap Water::default_parameters;
+ParameterMap Wind::default_parameters;
+ParameterMap Spike::default_parameters;
+
+ParameterMap Item::default_parameters;
+ParameterMap Heart::default_parameters;
+ParameterMap Key::default_parameters;
+ParameterMap Bomb::default_parameters;
+
+ParameterMap Character::default_parameters;
+ParameterMap DeadPlayer::default_parameters;
+ParameterMap TriggeredBomb::default_parameters;
+
+ParameterMap Monster::default_parameters;
+ParameterMap Plant::default_parameters;
+ParameterMap Zombie::default_parameters;
+
+ParameterMap Player::default_parameters;
+ParameterMap Erik::default_parameters;
+ParameterMap Olaf::default_parameters;
+ParameterMap Scorch::default_parameters;
+ParameterMap Fang::default_parameters;
+ParameterMap Baleog::default_parameters;
+
bool Compare::operator()(const Object* obj1, const Object* obj2) {
if (obj1->onum<obj2->onum) return true;
else return false;
@@ -37,60 +68,148 @@
ObjectsPool::ObjectsPool():
currentplayer(playerspool.begin()),
- au_switch(sndcache->loadWAV("newchar.wav")) { }
+ au_switch(sndcache->loadWAV("newchar.wav")) {
+ setDefaultObjParam();
+}
ObjectsPool::~ObjectsPool() {
object_iterator i=objectspool.begin();
while (i!=objectspool.end()) i=removeObject(i);
}
+void ObjectsPool::setDefaultObjParam() {
+ Object::default_parameters["name"]="";
+ Object::default_parameters["w"]="";
+ Object::default_parameters["h"]="";
+ Object::default_parameters["image"]="";
+ Background::default_parameters=Object::default_parameters;
+ Exit::default_parameters=Object::default_parameters;
+ Exit::default_parameters["image"]="exit.bmp";
+ Wall::default_parameters=Object::default_parameters;
+ Door::default_parameters=Object::default_parameters;
+ Door::default_parameters["key"]="Key";
+ Door::default_parameters["start_open"]="";
+ Door::default_parameters["audio_open"]="dooropn.wav";
+ Door::default_parameters["audio_close"]="dooropn.wav";
+ Teleporter::default_parameters=Object::default_parameters;
+ Teleporter::default_parameters["exitx"]="0";
+ Teleporter::default_parameters["exity"]="0";
+ Teleporter::default_parameters["audio_teleport"]="teleprt.wav";
+ Water::default_parameters=Object::default_parameters;
+ Water::default_parameters["audio_water_land"]="splash2.wav";
+ Wind::default_parameters=Object::default_parameters;
+ Wind::default_parameters["accel"]="0";
+ Trigger::default_parameters=Object::default_parameters;
+ Trigger::default_parameters["image"]="key.bmp";
+ Trigger::default_parameters["key"]="Key";
+ Trigger::default_parameters["target"]="Target";
+ Spike::default_parameters=Object::default_parameters;
+ Spike::default_parameters["direction"]="up";
-Object* ObjectsPool::addObjectbyName(const string& obj, const string& image, Sint16 x, Sint16 y, string& arg1, string& arg2, const string& arg3) {
- //Set names...
- string name=getNextObjectName(obj);
- if (!arg1.empty()) {
- //one additional parameter
- if (obj=="Trigger" || obj=="Door" || obj=="Bomb" || obj=="TriggeredBomb" || obj=="Plant" || obj=="Geyser" || obj=="Wind" || obj=="Spike") {
- if (!arg2.empty()) name=arg2;
- //two additional parameter
- } else if (obj=="Teleporter") {
- if (!arg3.empty()) name=arg3;
- //no additional parameters
- } else {
- name=arg1;
- }
- }
- if (arg1.empty()) arg1="0";
- if (arg2.empty()) arg2="0";
+ Item::default_parameters=Object::default_parameters;
+ Heart::default_parameters=Item::default_parameters;
+ Heart::default_parameters["image"]="heart.bmp";
+ Heart::default_parameters["alife"]="1";
+ Key::default_parameters=Item::default_parameters;
+ Key::default_parameters["image"]="key.bmp";
+ Key::default_parameters["audio_key"]="";
+ Bomb::default_parameters=Item::default_parameters;
+ Bomb::default_parameters["image"]="bomb_fire.bmp";
+ Bomb::default_parameters["image_bomb"]="bomb_fire.bmp";
+ Bomb::default_parameters["countdown"]="3000";
+ Bomb::default_parameters["audio_bomb"]="explsn.wav";
- //normal objects
- if (obj=="Wall") return (addObject(new Wall(image,x,y,name)));
- else if (obj=="Exit") return (addObject(new Exit(image,x,y,name)));
- else if (obj=="Water") return (addObject(new Water(image,x,y,name)));
- else if (obj=="Teleporter") return (addObject(new Teleporter(image,x,y,atoi(arg1.c_str()),atoi(arg2.c_str()),name)));
- else if (obj=="Wind") return (addObject(new Wind(image,x,y,atoi(arg1.c_str()),name)));
- else if (obj=="Geyser") return (addObject(new Geyser(image,x,y,atoi(arg1.c_str()),name)));
- else if (obj=="Trigger") return (addObject(new Trigger(image,x,y,arg1,name,arg3)));
- else if (obj=="Door") return (addObject(new Door(image,x,y,arg1,name)));
- else if (obj=="Spike") return (addObject(new Spike(image,x,y,atoi(arg1.c_str()),name)));
- //Items
- else if (obj=="Heart") return (addObject(new Heart(image,x,y,name)));
- else if (obj=="Key") return (addObject(new Key(image,x,y,name)));
- else if (obj=="Bomb") return (addObject(new Bomb(image,x,y,atoi(arg1.c_str()),name)));
+ Character::default_parameters=Object::default_parameters;
+ Character::default_parameters["maxhealth"]=1;
+ Character::default_parameters["health"]="1";
+ Character::default_parameters["maxspeedx"]="300";
+ Character::default_parameters["maxspeedy"]="0";
+ DeadPlayer::default_parameters=Character::default_parameters;
+ TriggeredBomb::default_parameters=Character::default_parameters;
+ TriggeredBomb::default_parameters["image"]="bomb_fire.bmp";
+ TriggeredBomb::default_parameters["countdown"]="3000";
+ TriggeredBomb::default_parameters["audio_bomb"]="explsn.wav";
- //normal characters
- else if (obj=="TriggeredBomb") return (addCharacter(new TriggeredBomb(image,x,y,atoi(arg1.c_str()),name)));
+ Monster::default_parameters=Character::default_parameters;
+ Monster::default_parameters["maxhealth"]=1;
+ Monster::default_parameters["health"]="1";
+ Monster::default_parameters["maxspeedx"]="50";
+ Monster::default_parameters["maxspeedy"]="0";
+ Monster::default_parameters["audio_hit"]="monhit.wav";
+ Plant::default_parameters=Character::default_parameters;
+ Plant::default_parameters["audio_hit"]="creeper.wav";
+ Plant::default_parameters["audio_recover"]="creeper.wav";
+ Plant::default_parameters["time_recover"]="3000";
+ Zombie::default_parameters=Character::default_parameters;
+ Zombie::default_parameters["maxspeedx"]="80";
+ Zombie::default_parameters["audio_attack"]="clang.wav";
- //Players
- else if (obj=="Erik") return (addPlayer(new Erik(image,x,y,name)));
- else if (obj=="Olaf") return (addPlayer(new Olaf(image,x,y,name)));
- else if (obj=="Baleog") return (addPlayer(new Baleog(image,x,y,name)));
- else if (obj=="Fang") return (addPlayer(new Fang(image,x,y,name)));
- else if (obj=="Scorch") return (addPlayer(new Scorch(image,x,y,name)));
+ Player::default_parameters=Character::default_parameters;
+ Player::default_parameters["maxhealth"]="4";
+ Player::default_parameters["health"]="3";
+ Player::default_parameters["maxspeedx"]="300";
+ Player::default_parameters["maxspeedy"]="200";
+ Erik::default_parameters=Player::default_parameters;
+ Olaf::default_parameters=Player::default_parameters;
+ Scorch::default_parameters=Player::default_parameters;
+ Fang::default_parameters=Player::default_parameters;
+ Baleog::default_parameters=Player::default_parameters;
+}
- //Monsters
- else if (obj=="Plant") return (addMonster(new Plant(image,x,y,atoi(arg1.c_str()),name)));
- else if (obj=="Zombie") return (addMonster(new Zombie(image,x,y,name)));
+const ParameterMap& ObjectsPool::getDefaultObjParambyName(const string& obj) {
+ if (obj=="Object") return Object::default_parameters;
+ else if (obj=="Background") return Background::default_parameters;
+ else if (obj=="Trigger") return Trigger::default_parameters;
+ else if (obj=="Door") return Door::default_parameters;
+ else if (obj=="Exit") return Exit::default_parameters;
+ else if (obj=="Teleporter") return Teleporter::default_parameters;
+ else if (obj=="Wall") return Wall::default_parameters;
+ else if (obj=="Water") return Water::default_parameters;
+ else if (obj=="Wind") return Wind::default_parameters;
+ else if (obj=="Spike") return Spike::default_parameters;
- //not recognized
+ else if (obj=="Item") return Item::default_parameters;
+ else if (obj=="Heart") return Heart::default_parameters;
+ else if (obj=="Key") return Key::default_parameters;
+ else if (obj=="Bomb") return Bomb::default_parameters;
+
+ else if (obj=="Character") return Character::default_parameters;
+ else if (obj=="DeadPlayer") return DeadPlayer::default_parameters;
+ else if (obj=="TriggeredBomb") return TriggeredBomb::default_parameters;
+ else if (obj=="Plant") return Plant::default_parameters;
+ else if (obj=="Zombie") return Zombie::default_parameters;
+
+ else if (obj=="Player") return Player::default_parameters;
+ else if (obj=="Erik") return Erik::default_parameters;
+ else if (obj=="Olaf") return Olaf::default_parameters;
+ else if (obj=="Scorch") return Scorch::default_parameters;
+ else if (obj=="Fang") return Fang::default_parameters;
+ else if (obj=="Baleog") return Baleog::default_parameters;
+ else return empty_parameter;
+}
+
+Object* ObjectsPool::addObjectbyName(const string& obj, Sint16 x, Sint16 y, ParameterMap& parameters) {
+ //Set names...
+ if (!hasParam(parameters,"name")) parameters["name"]=getNextObjectName(obj);
+
+ if (obj=="Wall") return (addObject(new Wall(x,y,parameters)));
+ else if (obj=="Exit") return (addObject(new Exit(x,y,parameters)));
+ else if (obj=="Water") return (addObject(new Water(x,y,parameters)));
+ else if (obj=="Teleporter") return (addObject(new Teleporter(x,y,parameters)));
+ else if (obj=="Wind") return (addObject(new Wind(x,y,parameters)));
+ else if (obj=="Geyser") return (addObject(new Geyser(x,y,parameters)));
+ else if (obj=="Trigger") return (addObject(new Trigger(x,y,parameters)));
+ else if (obj=="Door") return (addObject(new Door(x,y,parameters)));
+ else if (obj=="Spike") return (addObject(new Spike(x,y,parameters)));
+ else if (obj=="Heart") return (addObject(new Heart(x,y,parameters)));
+ else if (obj=="Key") return (addObject(new Key(x,y,parameters)));
+ else if (obj=="Bomb") return (addObject(new Bomb(x,y,parameters)));
+ else if (obj=="TriggeredBomb") return (addCharacter(new TriggeredBomb(x,y,parameters)));
+ else if (obj=="Erik") return (addPlayer(new Erik(x,y,parameters)));
+ else if (obj=="Olaf") return (addPlayer(new Olaf(x,y,parameters)));
+ else if (obj=="Baleog") return (addPlayer(new Baleog(x,y,parameters)));
+ else if (obj=="Fang") return (addPlayer(new Fang(x,y,parameters)));
+ else if (obj=="Scorch") return (addPlayer(new Scorch(x,y,parameters)));
+ else if (obj=="Plant") return (addMonster(new Plant(x,y,parameters)));
+ else if (obj=="Zombie") return (addMonster(new Zombie(x,y,parameters)));
else {
cout << "Object " << obj << " unknown, skipping...\n";
return NULL;
Modified: trunk/src/objectpools.h
===================================================================
--- trunk/src/objectpools.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objectpools.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -18,6 +18,10 @@
public:
ObjectsPool();
~ObjectsPool();
+ ///\brief sets the static default_parameters variable of all objects
+ void setDefaultObjParam();
+ ///\brief Returns the default_parameters of the corresponding obj or an empty map
+ const ParameterMap& getDefaultObjParambyName(const string& obj);
///\brief Returns true if no objects were loaded so far...
bool empty();
///\todo Move this code to the objects
@@ -26,15 +30,12 @@
/// Add an Object by it's name to the corresponding pool if it was
/// recognized, initialized with the parsed options.
/// \param obj Name of the Object class
- /// \param image Name of the base image to be load
/// \param x x coordinate
/// \param y y coordinate
- /// \param arg1 First argument as string
- /// \param arg2 Second argument as string
- /// \param arg3 Third argument as string
+ /// \param parameters A map<string,string> of all parameters
/// \return Pointer to the new entry in the objectspool or NULL if
/// the object was not recognized
- Object* addObjectbyName(const string& obj, const string& image, Sint16 x=0, Sint16 y=0, string& arg1="", string& arg2="", const string& arg3="");
+ Object* addObjectbyName(const string& obj, Sint16 x=0, Sint16 y=0, ParameterMap& parameters=ParameterMap());
//@{
/// Add an Object to the objectspool
/// \return Pointer to the new entry in the objectspool or NULL if it failed
@@ -91,6 +92,7 @@
//player number of the currently selected player
player_iterator currentplayer;
Mix_Chunk* au_switch;
+ const ParameterMap empty_parameter;
};
#endif
Modified: trunk/src/objects/baleog.cpp
===================================================================
--- trunk/src/objects/baleog.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/baleog.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -8,8 +8,8 @@
#include "baleog.h"
-Baleog::Baleog(string imagename, Sint16 xcord, Sint16 ycord, string pname):
- Player(imagename,xcord,ycord,pname) {
+Baleog::Baleog(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Player(xcord,ycord,parameters) {
anim_left=loadAnimation(scenario->imgcache->loadImage(1,"baleog1_left.bmp"));
anim_right=loadAnimation(scenario->imgcache->loadImage(1,"baleog1_right.bmp"));
anim_walk_left=loadAnimation(scenario->imgcache->loadImage("baleog1-run_left.png"),8);
Modified: trunk/src/objects/baleog.h
===================================================================
--- trunk/src/objects/baleog.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/baleog.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -5,8 +5,9 @@
*/
class Baleog : public Player {
public:
- Baleog(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Baleog");
+ Baleog(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Baleog();
+ static ParameterMap default_parameters;
/// \brief Baleog attacks with a sword
virtual void in_sp1();
private:
Modified: trunk/src/objects/bomb.cpp
===================================================================
--- trunk/src/objects/bomb.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/bomb.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -3,16 +3,25 @@
#include "objectpools.h"
#include "scenario.h"
#include "players_common.h"
+#include "imgcache.h"
#include "triggered_bomb.h"
#include "bomb.h"
-Bomb::Bomb(string imagename, Sint16 xcord, Sint16 ycord, Uint16 explode_time, string iname):
- Item(imagename,xcord,ycord,iname),
- countdown(explode_time) { }
+Bomb::Bomb(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Item(xcord,ycord,parameters) {
+ /* Parameters */
+ if (!hasParam(parameters,"image")) anim_orig=loadAnimation(scenario->imgcache->loadImage(1,"bomb_fire.bmp"));
+ if (hasParam(parameters,"image_bomb")) triggered_bomb_param["image"]=parameters["image_bomb"];
+ else triggered_bomb_param["image"]="bomb_fire.bmp";
+ if (hasParam(parameters,"countdown")) triggered_bomb_param["countdown"]="3000";
+ else triggered_bomb_param["countdown"]=parameters["countdown"];
+ if (hasParam(parameters,"audio_bomb")) triggered_bomb_param["audio_bomb"]=parameters["audio_bomb"];
+ else triggered_bomb_param["audio_bomb"]="explsn.wav";
+}
Bomb::~Bomb() { }
bool Bomb::act(Object*) {
- if (scenario->pool->addCharacter(new TriggeredBomb("bomb_fire.bmp",owner->getPos()->x,owner->getPos()->y,countdown,"TriggeredBomb"))) {
+ if (scenario->pool->addObjectbyName("TriggeredBomb",owner->getPos()->x,owner->getPos()->y-20,triggered_bomb_param)) {
owner->removeItem();
return true;
} else {
Modified: trunk/src/objects/bomb.h
===================================================================
--- trunk/src/objects/bomb.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/bomb.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -8,10 +8,10 @@
*/
class Bomb : public Item {
public:
- Bomb(string imagename, Sint16 xpos=0, Sint16 ypos=0, Uint16 explode_time=3000, string name="Bomb");
+ Bomb(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Bomb();
+ static ParameterMap default_parameters;
virtual bool act(Object* obj);
private:
- Uint16 countdown;
- Mix_Chunk* au_bomb;
+ ParameterMap triggered_bomb_param;
};
Modified: trunk/src/objects/door.cpp
===================================================================
--- trunk/src/objects/door.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/door.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -6,13 +6,19 @@
#include "door.h"
-Door::Door(string imagename, Sint16 xcord, Sint16 ycord, string keyname, string oname):
- Object(imagename,xcord,ycord,oname),
- open(false),
- key(keyname),
- au_open(scenario->sndcache->loadWAV("dooropn.wav")),
- au_close(au_open) {
+Door::Door(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Object(xcord,ycord,parameters) {
otype=OTYPE_DENSE;
+
+ /* Parameters */
+ if (hasParam(parameters,"key")) key=parameters["key"];
+ else key="Key";
+ if (hasParam(parameters,"audio_open")) au_open =scenario->sndcache->loadWAV(parameters["audio_open"]);
+ else au_open=scenario->sndcache->loadWAV("dooropn.wav");
+ if (hasParam(parameters,"audio_close")) au_close=scenario->sndcache->loadWAV(parameters["audio_close"]);
+ else au_close=scenario->sndcache->loadWAV("dooropn.wav");
+ if (hasParam(parameters,"start_open")) open=true;
+ else open=false;
}
Door::~Door() { }
Modified: trunk/src/objects/door.h
===================================================================
--- trunk/src/objects/door.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/door.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -5,8 +5,9 @@
*/
class Door : public Object {
public:
- Door(string imagename, Sint16 xcord=0, Sint16 ycord=0, string keyname="Key", string oname="Door");
+ Door(Sint16 xcord=0, Sint16 ycord=0, ParameterMap& parameters=ParameterMap());
virtual ~Door();
+ static ParameterMap default_parameters;
virtual bool act(Object* obj);
private:
bool open;
Modified: trunk/src/objects/erik.cpp
===================================================================
--- trunk/src/objects/erik.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/erik.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -10,8 +10,8 @@
#include "erik.h"
-Erik::Erik(string imagename, Sint16 xcord, Sint16 ycord, string pname):
- Player(imagename,xcord,ycord,pname),
+Erik::Erik(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Player(xcord,ycord,parameters),
jump(V_JUMP),
jump2(V_JUMP2) {
weapon=Weapon(-1,W_PRESSURE,WS_PRESSURE);
Modified: trunk/src/objects/erik.h
===================================================================
--- trunk/src/objects/erik.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/erik.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -13,8 +13,9 @@
*/
class Erik : public Player {
public:
- Erik(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Erik");
+ Erik(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Erik();
+ static ParameterMap default_parameters;
virtual void idle(Uint16);
/// \brief Erik jumps
virtual void in_sp1();
Modified: trunk/src/objects/exit.cpp
===================================================================
--- trunk/src/objects/exit.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/exit.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -2,12 +2,16 @@
#include "objectpools.h"
//shouldn't be here...
#include "scenario.h"
+#include "imgcache.h"
#include "players_common.h"
#include "exit.h"
-Exit::Exit(string imagename, Sint16 xcord, Sint16 ycord, string oname):
- Object(imagename,xcord,ycord,oname) { }
+Exit::Exit(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Object(xcord,ycord,parameters) {
+ /* Parameters */
+ if (!hasParam(parameters,"image")) anim_orig=loadAnimation(scenario->imgcache->loadImage(1,"exit.bmp"));
+}
Exit::~Exit() { }
bool Exit::act(Object*) {
Modified: trunk/src/objects/exit.h
===================================================================
--- trunk/src/objects/exit.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/exit.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -6,7 +6,8 @@
*/
class Exit : public Object {
public:
- Exit(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Exit");
+ Exit(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Exit();
+ static ParameterMap default_parameters;
virtual bool act(Object* obj);
};
Modified: trunk/src/objects/fang.cpp
===================================================================
--- trunk/src/objects/fang.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/fang.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -8,8 +8,8 @@
#include "fang.h"
-Fang::Fang(string imagename, Sint16 xcord, Sint16 ycord, string pname):
- Player(imagename,xcord,ycord,pname),
+Fang::Fang(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Player(xcord,ycord,parameters),
jump(V_JUMP) {
weapon=Weapon(-1,W_STRIKE);
anim_left=loadAnimation(scenario->imgcache->loadImage(4,"Fang_Breath_left.png"),4);
Modified: trunk/src/objects/fang.h
===================================================================
--- trunk/src/objects/fang.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/fang.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -22,8 +22,9 @@
*/
class Fang : public Player {
public:
- Fang(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Fang");
+ Fang(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Fang();
+ static ParameterMap default_parameters;
virtual void fall(Uint16);
virtual void in_left(Uint16);
virtual void in_right(Uint16);
Modified: trunk/src/objects/geyser.cpp
===================================================================
--- trunk/src/objects/geyser.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/geyser.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -8,11 +8,15 @@
#include "geyser.h"
-Geyser::Geyser(string imagename, Sint16 xcord, Sint16 ycord, Sint16 yAdd, string oname):
- Object(imagename,xcord,ycord,oname),
- aspeed(yAdd),
- au_geyser(scenario->sndcache->loadWAV("geyser.wav")),
- Deffect(0) { }
+Geyser::Geyser(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Object(xcord,ycord,parameters),
+ Deffect(0) {
+ /* Parameters */
+ if (hasParam(parameters,"aspeed")) aspeed=atoi(parameters["aspeed"].c_str());
+ else aspeed=0;
+ if (hasParam(parameters,"audio_geyser")) au_geyser=scenario->sndcache->loadWAV(parameters["audio_geyser"]);
+ else au_geyser=scenario->sndcache->loadWAV("geyser.wav");
+}
Geyser::~Geyser() { }
void Geyser::idle(Uint16 dt) {
Modified: trunk/src/objects/geyser.h
===================================================================
--- trunk/src/objects/geyser.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/geyser.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -9,8 +9,9 @@
*/
class Geyser : public Object {
public:
- Geyser(string imagename, Sint16 xpos=0, Sint16 ypos=0, Sint16 yAdd=0, string name="Geyser");
+ Geyser(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Geyser();
+ static ParameterMap default_parameters;
virtual void idle(Uint16 dt);
private:
Sint16 aspeed;
Modified: trunk/src/objects/heart.cpp
===================================================================
--- trunk/src/objects/heart.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/heart.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -2,17 +2,24 @@
#include "weapons.h"
#include "objects_common.h"
//shouldn't be here...
+#include "scenario.h"
+#include "imgcache.h"
#include "players_common.h"
#include "heart.h"
-Heart::Heart(string imagename, Sint16 xcord, Sint16 ycord, string iname):
- Item(imagename,xcord,ycord,iname) { }
+Heart::Heart(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Item(xcord,ycord,parameters) {
+ /* Parameters */
+ if (!hasParam(parameters,"image")) anim_orig=loadAnimation(scenario->imgcache->loadImage(1,"heart.bmp"));
+ if (hasParam(parameters,"alife")) alife=atoi(parameters["alife"].c_str());
+ else alife=1;
+}
Heart::~Heart() { }
bool Heart::act(Object* obj) {
if ((obj==NULL) || (obj!=owner)) return false;
- Weapon tmpheal(1,W_HEAL,WS_HEAL);
+ Weapon tmpheal(alife,W_HEAL,WS_HEAL);
owner->hit(DIR_ALL,tmpheal);
owner->removeItem();
return true;
Modified: trunk/src/objects/heart.h
===================================================================
--- trunk/src/objects/heart.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/heart.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -7,7 +7,10 @@
*/
class Heart : public Item {
public:
- Heart(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Heart");
+ Heart(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Heart();
+ static ParameterMap default_parameters;
virtual bool act(Object* obj);
+ private:
+ Uint8 alife;
};
Modified: trunk/src/objects/key.cpp
===================================================================
--- trunk/src/objects/key.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/key.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -3,12 +3,19 @@
#include "objects_common.h"
//this shouldn't be here
#include "players_common.h"
+#include "scenario.h"
+#include "imgcache.h"
+#include "sndcache.h"
#include "key.h"
-Key::Key(string imagename, Sint16 xcord, Sint16 ycord, string iname):
- Item(imagename,xcord,ycord,iname),
- au_key(NULL) { }
+Key::Key(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Item(xcord,ycord,parameters) {
+ /* Parameters */
+ if (!hasParam(parameters,"image")) anim_orig=loadAnimation(scenario->imgcache->loadImage(1,"key.bmp"));
+ if (hasParam(parameters,"audio_key")) au_key=scenario->sndcache->loadWAV(parameters["audio_key"]);
+ else au_key=NULL;
+}
Key::~Key() { }
bool Key::act(Object* obj) {
Modified: trunk/src/objects/key.h
===================================================================
--- trunk/src/objects/key.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/key.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -7,8 +7,9 @@
*/
class Key : public Item {
public:
- Key(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Key");
+ Key(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Key();
+ static ParameterMap default_parameters;
virtual bool act(Object* obj);
private:
Mix_Chunk* au_key;
Modified: trunk/src/objects/olaf.cpp
===================================================================
--- trunk/src/objects/olaf.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/olaf.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -9,8 +9,8 @@
#include "olaf.h"
-Olaf::Olaf(string imagename, Sint16 xcord, Sint16 ycord, string pname):
- Player(imagename,xcord,ycord,pname),
+Olaf::Olaf(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Player(xcord,ycord,parameters),
fart(V_FART) {
anim_left=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_left.bmp"));
anim_right=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_right.bmp"));
@@ -34,7 +34,7 @@
au_big=scenario->sndcache->loadWAV("unblob.wav");
au_fart=scenario->sndcache->loadWAV("fart1.wav");
au_hit=scenario->sndcache->loadWAV("fathit.wav");
- normal_size=anim_orig->getFrameDim();
+ normal_size=pos;
small_size=anim_small_right->getFrameDim();
}
Modified: trunk/src/objects/olaf.h
===================================================================
--- trunk/src/objects/olaf.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/olaf.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -16,8 +16,9 @@
*/
class Olaf : public Player {
public:
- Olaf(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Olaf");
+ Olaf(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Olaf();
+ static ParameterMap default_parameters;
/// Additionally checks if Olaf is small and how he wears his shield
virtual void updateAnimState();
virtual void in_left(Uint16);
Modified: trunk/src/objects/plant.cpp
===================================================================
--- trunk/src/objects/plant.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/plant.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -7,15 +7,19 @@
#include "scenario.h"
#include "plant.h"
-Plant::Plant(string imagename, Sint16 xcord, Sint16 ycord, Uint16 trecover, string cname):
- Monster(imagename,xcord,ycord,cname),
- recover(trecover),
- tcur(trecover) {
- maxhealth=1;
+Plant::Plant(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Monster(xcord,ycord,parameters) {
+ enemy_types|=(OTYPE_PLAYER);
weapon=Weapon(-1,W_TOUCH);
- au_hit=scenario->sndcache->loadWAV("creeper.wav");
- au_recover=au_hit;
- enemy_types|=(OTYPE_PLAYER);
+ tcur=recover;
+
+ /* Parameters */
+ if (!hasParam(parameters,"health")) health=min(1,(int)maxhealth);
+ if (!hasParam(parameters,"audio_hit")) au_hit=scenario->sndcache->loadWAV("creeper.wav");
+ if (hasParam(parameters,"audio_recover")) au_recover=scenario->sndcache->loadWAV(parameters["audio_recover"]);
+ else au_recover=au_hit;
+ if (hasParam(parameters,"time_recover")) recover=atoi(parameters["recover"].c_str());
+ else recover=3000;
}
Plant::~Plant() { }
Modified: trunk/src/objects/plant.h
===================================================================
--- trunk/src/objects/plant.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/plant.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -5,8 +5,9 @@
*/
class Plant : public Monster {
public:
- Plant(string imagename, Sint16 xpos=0, Sint16 ypos=0, Uint16 dleft=3000, string name="Plant");
+ Plant(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Plant();
+ static ParameterMap default_parameters;
virtual void touch(Object*);
virtual void idle(Uint16);
virtual Uint16 hit(Uint16 direction, Weapon& weap);
Modified: trunk/src/objects/scorch.cpp
===================================================================
--- trunk/src/objects/scorch.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/scorch.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -8,8 +8,8 @@
#include "scorch.h"
-Scorch::Scorch(string imagename, Sint16 xcord, Sint16 ycord, string pname):
- Player(imagename,xcord,ycord,pname),
+Scorch::Scorch(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Player(xcord,ycord,parameters),
left_wings(SCORCH_MAX_WINGS),
wing(V_FLY) {
anim_left=loadAnimation(scenario->imgcache->loadImage(1,"baleog1_left.bmp"));
Modified: trunk/src/objects/scorch.h
===================================================================
--- trunk/src/objects/scorch.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/scorch.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -16,8 +16,9 @@
*/
class Scorch : public Player {
public:
- Scorch(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Scorch");
+ Scorch(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Scorch();
+ static ParameterMap default_parameters;
virtual void fall(Uint16);
/// \brief Scorch uses his wings
virtual void idle(Uint16);
Modified: trunk/src/objects/spike.cpp
===================================================================
--- trunk/src/objects/spike.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/spike.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -7,10 +7,13 @@
#include "scenario.h"
#include "spike.h"
-Spike::Spike(string imagename, Sint16 xcord, Sint16 ycord, Uint16 sdir, string oname):
- Object(imagename,xcord,ycord,oname),
- dir(sdir) {
+Spike::Spike(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Object(xcord,ycord,parameters) {
weapon=Weapon(-10,W_TOUCH,WS_SPIKE);
+
+ /* Parameters */
+ if (hasParam(parameters,"direction")) dir=getDirFromString(parameters["direction"]);
+ else dir=DIR_UP;
otype|=(DIR_ALL&(~dir));
}
Spike::~Spike() { }
Modified: trunk/src/objects/spike.h
===================================================================
--- trunk/src/objects/spike.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/spike.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -5,8 +5,9 @@
*/
class Spike : public Object {
public:
- Spike(string imagename, Sint16 xpos=0, Sint16 ypos=0, Uint16 dir=DIR_UP, string name="Spike");
+ Spike(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Spike();
+ static ParameterMap default_parameters;
virtual void touch(Object*);
private:
Weapon weapon;
Modified: trunk/src/objects/teleport.cpp
===================================================================
--- trunk/src/objects/teleport.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/teleport.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -8,11 +8,15 @@
#include "teleport.h"
-Teleporter::Teleporter(string imagename, Sint16 xcord, Sint16 ycord, Sint16 xExit, Sint16 yExit, string oname):
- Object(imagename,xcord,ycord,oname),
- au_tele(scenario->sndcache->loadWAV("teleprt.wav")) {
- exit.x=xExit;
- exit.y=yExit;
+Teleporter::Teleporter(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Object(xcord,ycord,parameters) {
+ /* Parameters */
+ if (hasParam(parameters,"audio_teleport")) au_tele=scenario->sndcache->loadWAV(parameters["audio_teleport"]);
+ else au_tele=scenario->sndcache->loadWAV("teleprt.wav");
+ if (hasParam(parameters,"exitx")) exit.x=atoi(parameters["exitx"].c_str());
+ else exit.x=0;
+ if (hasParam(parameters,"exity")) exit.y=atoi(parameters["exity"].c_str());
+ else exit.y=0;
exit.w=exit.h=0;
}
Teleporter::~Teleporter() { }
Modified: trunk/src/objects/teleport.h
===================================================================
--- trunk/src/objects/teleport.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/teleport.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -12,8 +12,9 @@
/// \param xExit x coordinate of the exit position
/// \param yExit y coordinate of the exit position
/// \param name Name of this object
- Teleporter(string imagename, Sint16 xpos=0, Sint16 ypos=0, Sint16 xExit=0, Sint16 yExit=0, string name="Teleporter");
+ Teleporter(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Teleporter();
+ static ParameterMap default_parameters;
virtual bool act(Object* obj);
private:
/// \brief Exit position
Modified: trunk/src/objects/trigger.cpp
===================================================================
--- trunk/src/objects/trigger.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/trigger.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -2,13 +2,18 @@
#include "objectpools.h"
#include "scenario.h"
#include "objects_common.h"
+#include "imgcache.h"
#include "trigger.h"
-Trigger::Trigger(string imagename, Sint16 xcord, Sint16 ycord, string targetname, string oname, string keyname):
- Object(imagename,xcord,ycord,oname),
- key(keyname) {
- target=scenario->pool->getObject(targetname);
+Trigger::Trigger(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Object(xcord,ycord,parameters) {
+ /* Parameters */
+ if (!hasParam(parameters,"image")) anim_orig=loadAnimation(scenario->imgcache->loadImage(1,"key.bmp"));
+ if (hasParam(parameters,"key")) key=parameters["key"];
+ else key="Key";
+ if (hasParam(parameters,"target")) target=scenario->pool->getObject(parameters["target"]);
+ else target=scenario->pool->getObject("Target");
}
Trigger::~Trigger() { }
Modified: trunk/src/objects/trigger.h
===================================================================
--- trunk/src/objects/trigger.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/trigger.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -3,11 +3,13 @@
/** \brief Trigger
+ Always add triggers after their related objects!
*/
class Trigger : public Object {
public:
- Trigger(string imagename, Sint16 xcord=0, Sint16 ycord=0, string targetname="DefaultTarget", string oname="Trigger", string keyname="");
+ Trigger(Sint16 xcord=0, Sint16 ycord=0, ParameterMap& parameters=ParameterMap());
virtual ~Trigger();
+ static ParameterMap default_parameters;
virtual bool act(Object* obj);
private:
Object* target;
Modified: trunk/src/objects/triggered_bomb.cpp
===================================================================
--- trunk/src/objects/triggered_bomb.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/triggered_bomb.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -6,12 +6,16 @@
#include "scenario.h"
#include "triggered_bomb.h"
-TriggeredBomb::TriggeredBomb(string imagename, Sint16 xcord, Sint16 ycord, Uint16 tleft, string cname):
- Character(imagename,xcord,ycord,cname),
- countdown(tleft),
- au_bomb(scenario->sndcache->loadWAV("explsn.wav")) {
+TriggeredBomb::TriggeredBomb(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Character(xcord,ycord,parameters) {
weapon=Weapon(-1,W_EXPLOSION);
enemy_types|=(OTYPE_PLAYER|OTYPE_MONSTER);
+
+ /* Parameters */
+ if (hasParam(parameters,"audio_bomb")) au_bomb=scenario->sndcache->loadWAV(parameters["audio_bomb"]);
+ else au_bomb=scenario->sndcache->loadWAV("explsn.wav");
+ if (hasParam(parameters,"countdown")) countdown=atoi(parameters["countdown"].c_str());
+ else countdown=3000;
}
TriggeredBomb::~TriggeredBomb() { }
Modified: trunk/src/objects/triggered_bomb.h
===================================================================
--- trunk/src/objects/triggered_bomb.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/triggered_bomb.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -5,8 +5,9 @@
*/
class TriggeredBomb : public Character {
public:
- TriggeredBomb(string imagename, Sint16 xpos=0, Sint16 ypos=0, Uint16 dleft=3000, string name="TriggeredBomb");
+ TriggeredBomb(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~TriggeredBomb();
+ static ParameterMap default_parameters;
virtual void idle(Uint16);
private:
Sint16 countdown;
Modified: trunk/src/objects/wall.cpp
===================================================================
--- trunk/src/objects/wall.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/wall.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -3,8 +3,8 @@
#include "wall.h"
-Wall::Wall(string imagename, Sint16 xcord, Sint16 ycord, string oname):
- Object(imagename,xcord,ycord,oname) {
+Wall::Wall(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Object(xcord,ycord,parameters) {
otype=OTYPE_DENSE;
}
Wall::~Wall() { }
Modified: trunk/src/objects/wall.h
===================================================================
--- trunk/src/objects/wall.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/wall.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -5,6 +5,7 @@
*/
class Wall : public Object {
public:
- Wall(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Wall");
+ Wall(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Wall();
+ static ParameterMap default_parameters;
};
Modified: trunk/src/objects/water.cpp
===================================================================
--- trunk/src/objects/water.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/water.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -9,10 +9,12 @@
#include "water.h"
-Water::Water(string imagename, Sint16 xcord, Sint16 ycord, string oname):
- Object(imagename,xcord,ycord,oname),
- au_water(scenario->sndcache->loadWAV("splash2.wav")) {
+Water::Water(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Object(xcord,ycord,parameters) {
weapon=Weapon(-1,W_WATER,WS_WATER);
+ /* Parameters */
+ if (hasParam(parameters,"audio_water_land")) au_water=scenario->sndcache->loadWAV(parameters["audio_water_land"]);
+ else au_water=scenario->sndcache->loadWAV("splash2.wav");
}
Water::~Water() { }
Modified: trunk/src/objects/water.h
===================================================================
--- trunk/src/objects/water.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/water.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -6,8 +6,9 @@
*/
class Water : public Object {
public:
- Water(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Water");
+ Water(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Water();
+ static ParameterMap default_parameters;
virtual void enter(Object* obj);
virtual void leave(Object* obj);
protected:
Modified: trunk/src/objects/wind.cpp
===================================================================
--- trunk/src/objects/wind.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/wind.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -4,9 +4,12 @@
#include "characters_common.h"
#include "wind.h"
-Wind::Wind(string imagename, Sint16 xcord, Sint16 ycord, Sint16 Accel, string oname):
- Object(imagename,xcord,ycord,oname),
- gravitymod(Accel) { }
+Wind::Wind(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Object(xcord,ycord,parameters) {
+ /* Parameters */
+ if (hasParam(parameters,"accel")) gravitymod=atoi(parameters["accel"].c_str());
+ else gravitymod=0;
+}
Wind::~Wind() { }
void Wind::enter(Object *obj) {
Modified: trunk/src/objects/wind.h
===================================================================
--- trunk/src/objects/wind.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/wind.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -6,8 +6,9 @@
*/
class Wind : public Object {
public:
- Wind(string imagename, Sint16 xpos=0, Sint16 ypos=0, Sint16 Accel=0, string name="Wind");
+ Wind(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Wind();
+ static ParameterMap default_parameters;
virtual void enter(Object* obj);
virtual void leave(Object* obj);
private:
Modified: trunk/src/objects/zombie.cpp
===================================================================
--- trunk/src/objects/zombie.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/zombie.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -10,14 +10,17 @@
#include "zombie.h"
-Zombie::Zombie(string imagename, Sint16 xcord, Sint16 ycord, string mname):
- Monster(imagename,xcord,ycord,mname),
- au_attack(scenario->sndcache->loadWAV("clang.wav")),
+Zombie::Zombie(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Monster(xcord,ycord,parameters),
T_Attack_Bite(1500) {
- maxspeedx=80;
anim_left=loadAnimation(scenario->imgcache->loadImage(2,"olaf1_left.bmp"),2,BP_MD,ATYPE_LOOP,2);
anim_right=loadAnimation(scenario->imgcache->loadImage(2,"olaf1_right.bmp"),2,BP_MD,ATYPE_LOOP,2);
weapon=Weapon(-1,W_STRIKE);
+
+ /* Parameters */
+ if (!hasParam(parameters,"maxspeedx")) maxspeedx=80;
+ if (hasParam(parameters,"audio_attack")) au_attack=scenario->sndcache->loadWAV(parameters["audio_attack"]);
+ else au_attack=scenario->sndcache->loadWAV("clang.wav");
}
Zombie::~Zombie() { }
Modified: trunk/src/objects/zombie.h
===================================================================
--- trunk/src/objects/zombie.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects/zombie.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -8,8 +8,9 @@
*/
class Zombie : public Monster {
public:
- Zombie(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Zombie");
+ Zombie(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Zombie();
+ static ParameterMap default_parameters;
virtual void idle(Uint16);
private:
virtual void runAI(Uint16);
Modified: trunk/src/objects_common.cpp
===================================================================
--- trunk/src/objects_common.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects_common.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -7,18 +7,26 @@
#include "scenario.h"
-Object::Object(string imagename, Sint16 xcord, Sint16 ycord, string oname):
+Object::Object(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
state(NOTHING),
event(NULL),
otype(NOTHING),
- name(oname),
- delete_flag(false),
- anim_orig(loadAnimation(scenario->imgcache->loadImage(1,imagename))) {
- animation=anim_orig;
- pos=animation->getFrameDim();
+ delete_flag(false) {
+ onum=++scenario->max_obj_num;
+ animation.reset(new EmptyAnimation(&anim_orig));
+
+ /* Parameters */
+ anim_orig=loadAnimation(parameters);
+ if (hasParam(parameters,"name")) name=parameters["name"];
+ else name="Object";
+ if (hasParam(parameters,"w")) pos.w=atoi(parameters["w"].c_str());
+ else if (anim_orig->isValid()) pos.w=anim_orig->getFrameDim().w;
+ else pos.w=(Uint16)(DATA_LVLPLAYER_W*sqrt(config.lvlscale>=0 ? config.lvlscale : -1/config.lvlscale)+0.5);
+ if (hasParam(parameters,"h")) pos.h=atoi(parameters["h"].c_str());
+ else if (anim_orig->isValid()) pos.h=anim_orig->getFrameDim().h;
+ else pos.h=(Uint16)(DATA_LVLPLAYER_H*sqrt(config.lvlscale>=0 ? config.lvlscale : -1/config.lvlscale)+0.5);
pos.x=xcord;
pos.y=ycord;
- onum=++scenario->max_obj_num;
}
Object::~Object() {
@@ -30,7 +38,7 @@
else return false;
}
-bool Object::isIn(const SDL_Rect& rect, bool touch) {
+bool Object::isIn(const SDL_Rect& rect, bool touch) const {
if (touch) {
if ((pos.x+pos.w) > rect.x && pos.x < (rect.x+rect.w) && (pos.y+pos.h) > rect.y && pos.y < (rect.y+rect.h)) return true;
else return false;
@@ -128,6 +136,11 @@
return anim;
}
+EmptyAnimationPtr Object::loadAnimation(ParameterMap& parameters) {
+ if (hasParam(parameters,"image")) return loadAnimation(scenario->imgcache->loadImage(1,parameters["image"]));
+ return EmptyAnimationPtr(new EmptyAnimation());
+}
+
SDL_Rect Object::getDrawPos() const {
return animation->getDrawPos();
}
@@ -197,15 +210,21 @@
}
-Item::Item(string imagename, Sint16 xcord, Sint16 ycord, string iname):
- Object(imagename,xcord,ycord,iname), owner(NULL) {
+Item::Item(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Object(xcord,ycord,parameters), owner(NULL) {
otype|=OTYPE_ITEM;
}
Item::~Item() { }
-Background::Background(string imagename):
- Object(imagename,0,0,"Background") {
+Background::Background(ParameterMap& parameters):
+ Object(0,0,parameters) {
otype=NOTHING;
+ name="Background";
+
+ /* Parameters */
+ /* TODO: support surface creation and use it as a fallback if no image was specified */
+ anim_orig=loadAnimation(parameters);
+ pos=anim_orig->getFrameDim();
}
Background::~Background() { }
Modified: trunk/src/objects_common.h
===================================================================
--- trunk/src/objects_common.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/objects_common.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -36,15 +36,16 @@
*/
class Object {
public:
- Object(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Object");
+ Object(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Object();
+ static ParameterMap default_parameters;
/// 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);
/// \brief Returns the center of an object
/// \return Center position of the object with width=height=0
- SDL_Rect getCenter() {
+ SDL_Rect getCenter() const {
SDL_Rect tmprect;
tmprect.x=pos.x+Uint16(pos.w/2);
tmprect.y=pos.y+Uint16(pos.h/2);
@@ -57,7 +58,7 @@
/// \param touch If true an overlapping region is enough, if false
/// the object center has to be inside the specified area.
/// \return True if the object is inside
- bool isIn(const SDL_Rect& rect, bool touch=false);
+ bool isIn(const SDL_Rect& rect, bool touch=false) const;
SDL_Rect* getPos() {
return &pos;
}
@@ -120,6 +121,8 @@
double afps=0,
Uint16 astart_pos=0,
AllignType aallign_type=AT_MD);
+ /// Load an animation based on a parameter map
+ EmptyAnimationPtr loadAnimation(ParameterMap& parameters=ParameterMap());
//Events (triggered animations/effects)
//@{
/// Clears the event field (sets it to NULL). This should only be used by
@@ -199,8 +202,9 @@
*/
class Item : public Object {
public:
- Item(string img, Sint16 xpos=0, Sint16 ypos=0, string name="Item");
+ Item(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Item();
+ static ParameterMap default_parameters;
virtual bool act(Object*) { return false; }
/// Assigns the item a new (player) owner
void setOwner(Player* plr) {
@@ -215,8 +219,9 @@
*/
class Background : public Object {
public:
- Background(string imagename);
+ Background(ParameterMap& parameters=ParameterMap());
virtual ~Background();
+ static ParameterMap default_parameters;
};
#endif
Modified: trunk/src/players_common.cpp
===================================================================
--- trunk/src/players_common.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/players_common.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -13,8 +13,8 @@
#include "players_common.h"
-Player::Player(string imagename, Sint16 xcord, Sint16 ycord, string pname):
- Character(imagename,xcord,ycord,pname),
+Player::Player(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Character(xcord,ycord,parameters),
currentitem(0),
anim_left(new EmptyAnimation(&anim_right)),
anim_right(new EmptyAnimation()),
@@ -49,10 +49,6 @@
anim_fall_middle(new EmptyAnimation(&anim_fall_right)),
anim_climb(new EmptyAnimation(&anim_right)),
anim_bar(new EmptyAnimation(&anim_right)) {
- health=3;
- maxhealth=4;
- maxspeedx=300;
- maxspeedy=200;
for (Uint8 i=0; i<MAX_ITEMS; i++) {
items[i]=NULL;
}
@@ -69,6 +65,12 @@
au_fire=scenario->sndcache->loadWAV("fireball.wav");
au_die=scenario->sndcache->loadWAV("bones.wav");
au_heal=scenario->sndcache->loadWAV("usefood1.wav");
+
+ /* Parameters */
+ if (!hasParam(parameters,"maxhealth")) maxhealth=4;
+ if (!hasParam(parameters,"health")) health=min(3,(int)maxhealth);
+ if (!hasParam(parameters,"maxspeedx")) maxspeedx=300;
+ if (!hasParam(parameters,"maxspeedy")) maxspeedy=200;
}
Player::~Player() {
@@ -309,7 +311,9 @@
if (newhealth==0) {
die();
//should be !=NULL or sthg is wrong with the placement code...
- Character* deadplr=scenario->pool->addCharacter(new DeadPlayer("dead_player.bmp",pos.x,pos.y));
+ ParameterMap deadplr_parameters;
+ deadplr_parameters["image"]="dead_player.bmp";
+ Character* deadplr=scenario->pool->addCharacter(new DeadPlayer(pos.x,pos.y,deadplr_parameters));
switch(weap.getSubType()) {
case WS_FIRE: {
if (deadplr) deadplr->setEvent(new CAnimEvent(deadplr,10,0,ESTATE_BUSY,au_fire,(state&STATE_LEFT) ? anim_die_burn_left : anim_die_burn_right));
@@ -390,6 +394,7 @@
return newhealth;
}
-DeadPlayer::DeadPlayer(string imagename, Sint16 xcord, Sint16 ycord, string name):
- Character(imagename,xcord,ycord,name) { }
+DeadPlayer::DeadPlayer(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
+ Character(xcord,ycord,parameters) {
+}
DeadPlayer::~DeadPlayer() { }
Modified: trunk/src/players_common.h
===================================================================
--- trunk/src/players_common.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/players_common.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -17,8 +17,9 @@
*/
class Player : public Character {
public:
- Player(string img, Sint16 xpos=0, Sint16 ypos=0, string name="Player");
+ Player(Sint16 xpos=0, Sint16 ypos=0, ParameterMap& parameters=ParameterMap());
virtual ~Player();
+ static ParameterMap default_parameters;
//@{
/// \brief Returns the icon of this Player
/// \return Single icon frame of this player (used for the player bar)
@@ -174,8 +175,9 @@
*/
class DeadPlayer : public Character {
public:
- DeadPlayer(string imagename, Sint16 xcord=0, Sint16 ycord=0, string name="DeadPlayer");
+ DeadPlayer(Sint16 xcord=0, Sint16 ycord=0, ParameterMap& parameters=ParameterMap());
virtual ~DeadPlayer();
+ static ParameterMap default_parameters;
};
#endif
Modified: trunk/src/scenario.cpp
===================================================================
--- trunk/src/scenario.cpp 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/scenario.cpp 2005-09-08 10:09:00 UTC (rev 157)
@@ -60,9 +60,10 @@
failed=false;
}
-void Scenario::newMap(string bgimage) {
+void Scenario::newMap(const ParameterMap& bg_parameters) {
mapbuf.clear();
- mapbuf.push_back("Background "+bgimage);
+ mapbuf.push_back("Background "+putParameters(bg_parameters));
+ mapbuf.push_back("#ENDHEADER");
}
int Scenario::loadMapBuf(string mapn) {
mapname=mapn;
@@ -90,69 +91,55 @@
int Scenario::reloadMap() {
reinitMap();
- string image;
- string cname,arg1,arg2,arg3;
+ string cname;
Uint16 x,y;
- bool header=false;
+ ParameterMap parameters;
+ bool header=true;
//check every line
for (Uint16 linenum=0; linenum<mapbuf.size(); linenum++) {
- //parse the header, always start a header with #HEADER and end it with #ENDHEADER!
+ //parse the header first, end it with #ENDHEADER!
if (header) {
- cname.erase();
- arg1.erase();
- arg2.erase();
- arg3.erase();
std::istringstream tmpstream(mapbuf[linenum]);
- tmpstream >> cname >> arg1 >> arg2 >> arg3;
+ tmpstream >> cname;
if (cname[0]=='#') {
if (cname=="#ENDHEADER") header=false;
continue;
+ } else {
+ string parameterlist((istreambuf_iterator<char>(tmpstream)), istreambuf_iterator<char>());
+ parameters=getParameters(parameterlist);
+ if (cname=="Background" && (!background)) {
+ background=new Background(parameters);
+ if (background) {
+ area=background->getPos();
+ bgimage=parameters["image"];
+ }
+ }
}
- continue;
- }
- cname.erase();
- image.erase();
- x=0;
- y=0;
- arg1=arg2=arg3="";
- std::istringstream tmpstream(mapbuf[linenum]);
- tmpstream >> cname >> image >> x >> y >> arg1 >> arg2 >> arg3;
-
- //Skip empty lines
- if (cname.empty()) continue;
- //Skip comments
- if (cname[0]=='#') {
- if (cname=="#HEADER") header=true;
- continue;
- }
-
- if (cname=="Background" && (!background)) {
- background=new Background(image);
- if (background) {
- area=background->getPos();
- bgimage=image;
- }
- //Background has to be first!
+ // Background has to be loaded...
} else if (background) {
- pool->addObjectbyName(cname,image,x,y,arg1,arg2,arg3);
+ cname.erase();
+ x=y=0;
+ std::istringstream tmpstream(mapbuf[linenum]);
+ tmpstream >> cname >> x >> y;
+ //Skip empty lines
+ if (cname.empty()) continue;
+ if (cname[0]=='#') continue;
+
+ string parameterlist((istreambuf_iterator<char>(tmpstream)), istreambuf_iterator<char>());
+ parameters=getParameters(parameterlist);
+ pool->addObjectbyName(cname,x,y,parameters);
} else {
- cout << "No background found yet, skipping " << cname << " ...\n";
+ cout << "Map loading failed: No background found!" << endl;
+ return 1;
}
}
sfxeng->playMusic((config.datadir + "01theme.wav").c_str());
-
- //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;
- }
+ if (pool->playerspool.size()>0) player=*pool->playerspool.begin();
+ else player=NULL;
+ if (player==NULL) cout << "No player found!\n";
+ return 0;
}
int Scenario::loadMap(string mapn) {
Modified: trunk/src/scenario.h
===================================================================
--- trunk/src/scenario.h 2005-09-06 20:16:53 UTC (rev 156)
+++ trunk/src/scenario.h 2005-09-08 10:09:00 UTC (rev 157)
@@ -5,18 +5,23 @@
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 HeaderOption "parameters"
+ \remarks Background "parameters"
+ \remarks #ENDHEADER
+ \remarks "Object class name" "x position" "y position" "parameters"
+ \remarks The parameters depend on the object: Each object checks it's
+ corresponding parameters.
+ \remarks The parameter format is like this:
+ \remarks option1=value1,option2=value2,...
+ \remakrs A value may be a parameterlist of suboptions:
+ \remarks option1=subopt1=subval1:subopt2=subval2:...,option2=value2
\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)
+ \remarks Background image=background.bmp
+ \remarks #ENDHEADER
+ \remarks Teleporter 0 0 image=teleporter.bmp,exitx=20,exity=100,name=teleporter1
\todo Move the Caches into the current map as well?
- \todo Create a map class inside Scenario?
*/
class Scenario {
public:
@@ -64,7 +69,7 @@
/// Physic Handler
PhysicHandler* physic;
/// Create a new empty map with the specified background
- void newMap(string bgname);
+ void newMap(const ParameterMap& bg_parameters);
/// Used to load the map file into a buffer
int loadMapBuf(string mapname);
/// Reload the map file using the buffered map file
More information about the lostpenguins-commits
mailing list