From 039ca92dfe9c4729ebbd599bf51dffcd8380e276 Mon Sep 17 00:00:00 2001 From: Ryan Flegel Date: Sun, 16 May 2004 01:36:54 +0000 Subject: [PATCH] - 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. SVN-Revision: 1204 --- src/gameobjs.h | 24 +++++++++++++++++++----- src/level.cpp | 7 +++++++ src/world.cpp | 21 +++++++++++++++++++++ src/world.h | 4 ++++ 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/gameobjs.h b/src/gameobjs.h index 69a84538f..8037db662 100644 --- a/src/gameobjs.h +++ b/src/gameobjs.h @@ -27,25 +27,28 @@ #include "timer.h" #include "scene.h" +enum ObjectType { OBJ_NONE, OBJ_BADGUY, OBJ_TRAMPOLINE }; + template 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 @@ class Trampoline : public GameObject void action(double frame_ratio); void draw(); std::string type() { return "Trampoline"; }; + + Trampoline(ObjectData data) + { + base.x = data.x; + base.y = data.y; + + power = data.type_specific.power; + } + + private: + int power; }; void load_trampoline_gfx(); diff --git a/src/level.cpp b/src/level.cpp index 869c1e2ba..e9612b110 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -412,6 +412,13 @@ Level::load(const std::string& filename) if (lisp_symbol(lisp_car(data)) == "trampoline") { ObjectData _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); } } diff --git a/src/world.cpp b/src/world.cpp index d795028f8..68dcb7a08 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -156,6 +156,17 @@ World::activate_bad_guys() } void +World::activate_objects() +{ + for (std::vector< ObjectData >::iterator i = level->trampoline_data.begin(); + i != level->trampoline_data.end(); + ++i) + { + add_object >(*i); + } +} + +void World::activate_particle_systems() { if (level->particle_system == "clouds") @@ -530,6 +541,16 @@ World::add_bad_guy(float x, float y, BadGuyKind kind, bool stay_on_platform) return badguy; } +template +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) { diff --git a/src/world.h b/src/world.h index e62ce664d..b2ce9c7bb 100644 --- a/src/world.h +++ b/src/world.h @@ -40,6 +40,8 @@ class World private: typedef std::list BadGuys; BadGuys bad_guys_to_add; + typedef std::list Trampolines; + Trampolines trampolines; Level* level; Player tux; @@ -91,6 +93,7 @@ public: 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 @@ public: void add_bouncy_brick(float x, float y); BadGuy* add_bad_guy(float x, float y, BadGuyKind kind, bool stay_on_platform = false); + template 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); -- 2.11.0