I'm Cleaning up object code to make it more flexible/reusable.
It's currently in an unfinished state.
SVN-Revision: 1204
#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;
};
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();
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);
}
}
}
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")
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)
{
private:
typedef std::list<BadGuy*> BadGuys;
BadGuys bad_guys_to_add;
+ typedef std::list<Trampoline*> Trampolines;
+ Trampolines trampolines;
Level* level;
Player tux;
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);
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);