[Super-tux-commit] supertux/src gameobjs.h,1.10,1.11 level.cpp,1.72,1.73 world.cpp,1.91,1.92 world.h
Brought to you by:
wkendrick
From: Ryan F. <sik...@us...> - 2004-05-16 01:37:04
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30537 Modified Files: gameobjs.h level.cpp world.cpp world.h Log Message: - Made some changes to object code I'm Cleaning up object code to make it more flexible/reusable. It's currently in an unfinished state. Index: world.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/world.h,v retrieving revision 1.39 retrieving revision 1.40 diff -u -d -r1.39 -r1.40 --- world.h 10 May 2004 13:21:41 -0000 1.39 +++ world.h 16 May 2004 01:36:54 -0000 1.40 @@ -40,6 +40,8 @@ private: typedef std::list<BadGuy*> BadGuys; BadGuys bad_guys_to_add; + typedef std::list<Trampoline*> Trampolines; + Trampolines trampolines; Level* level; Player tux; @@ -91,6 +93,7 @@ void activate_particle_systems(); void activate_bad_guys(); + void activate_objects(); void add_score(float x, float y, int s); void add_bouncy_distro(float x, float y); @@ -99,6 +102,7 @@ void add_bouncy_brick(float x, float y); BadGuy* add_bad_guy(float x, float y, BadGuyKind kind, bool stay_on_platform = false); + template <class T, class U> T* add_object(U data); void add_upgrade(float x, float y, Direction dir, UpgradeKind kind); void add_bullet(float x, float y, float xm, Direction dir); Index: gameobjs.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameobjs.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- gameobjs.h 16 May 2004 00:36:58 -0000 1.10 +++ gameobjs.h 16 May 2004 01:36:54 -0000 1.11 @@ -27,25 +27,28 @@ #include "timer.h" #include "scene.h" +enum ObjectType { OBJ_NONE, OBJ_BADGUY, OBJ_TRAMPOLINE }; + template <class T> struct ObjectData { int x; int y; + ObjectType type; T type_specific; ObjectData(ObjectData* pobject) - : x((int)pobject->x), y((int)pobject->y) {}; - ObjectData(int x_, int y_, T type_specific_) - : x(x_), y(y_), type_specific(type_specific_) {}; + : x((int)pobject->x), y((int)pobject->y), type(pobject->type), type_specific(pobject->type_specific) {}; + ObjectData(int x_, int y_, ObjectType type_, T type_specific_) + : x(x_), y(y_), type(type_), type_specific(type_specific_) {}; ObjectData() - : x(0), y(0), type_specific() {}; + : x(0), y(0), type(OBJ_NONE), type_specific() {}; }; struct TrampolineData { - unsigned int power; + int power; }; @@ -114,6 +117,17 @@ void action(double frame_ratio); void draw(); std::string type() { return "Trampoline"; }; + + Trampoline(ObjectData<TrampolineData> data) + { + base.x = data.x; + base.y = data.y; + + power = data.type_specific.power; + } + + private: + int power; }; void load_trampoline_gfx(); Index: level.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.cpp,v retrieving revision 1.72 retrieving revision 1.73 diff -u -d -r1.72 -r1.73 --- level.cpp 16 May 2004 00:36:58 -0000 1.72 +++ level.cpp 16 May 2004 01:36:54 -0000 1.73 @@ -412,6 +412,13 @@ if (lisp_symbol(lisp_car(data)) == "trampoline") { ObjectData<TrampolineData> _trampoline_data; + + _trampoline_data.type = OBJ_TRAMPOLINE; + reader.read_int("x", &_trampoline_data.x); + reader.read_int("y", &_trampoline_data.y); + reader.read_int("power", &_trampoline_data.type_specific.power); + + trampoline_data.push_back(_trampoline_data); } } Index: world.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/world.cpp,v retrieving revision 1.91 retrieving revision 1.92 diff -u -d -r1.91 -r1.92 --- world.cpp 15 May 2004 12:08:57 -0000 1.91 +++ world.cpp 16 May 2004 01:36:54 -0000 1.92 @@ -156,6 +156,17 @@ } void +World::activate_objects() +{ + for (std::vector< ObjectData<TrampolineData> >::iterator i = level->trampoline_data.begin(); + i != level->trampoline_data.end(); + ++i) + { + add_object<Trampoline, ObjectData<TrampolineData> >(*i); + } +} + +void World::activate_particle_systems() { if (level->particle_system == "clouds") @@ -530,6 +541,16 @@ return badguy; } +template<class T, class U> +T* +World::add_object(U data) +{ + T* tobject = new T(data); + trampolines.push_back(tobject); + + return tobject; +} + void World::add_upgrade(float x, float y, Direction dir, UpgradeKind kind) { |