From: Ryan Flegel Date: Sun, 16 May 2004 00:36:58 +0000 (+0000) Subject: - added support for different types of objects X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=e74e367f3e048b551d8b5d75236b76d7a771bc81;p=supertux.git - added support for different types of objects - working on adding trampoline SVN-Revision: 1203 --- diff --git a/src/gameobjs.cpp b/src/gameobjs.cpp index 010cf1d04..3c04c05ee 100644 --- a/src/gameobjs.cpp +++ b/src/gameobjs.cpp @@ -23,6 +23,8 @@ #include "tile.h" #include "gameloop.h" #include "gameobjs.h" +#include "sprite_manager.h" +#include "resources.h" void BouncyDistro::init(float x, float y) @@ -209,5 +211,45 @@ FloatingScore::draw() gold_text->draw(str, (int)base.x + 16 - strlen(str) * 8, (int)base.y, 1); } +/* Trampoline */ + +#define TRAMPOLINE_FRAMES 4 +Sprite *img_trampoline[TRAMPOLINE_FRAMES]; + +void load_trampoline_gfx() +{ + for (int i = 0; i < TRAMPOLINE_FRAMES; i++) + { + char sprite_name[16]; + sprintf(sprite_name, "trampoline-%i", i+1); + img_trampoline[0] = sprite_manager->load(sprite_name); + } +} + +void +Trampoline::init(float x, float y) +{ + base.x = x; + base.y = y; +} + +void +Trampoline::action(double frame_ratio) +{ + (void) frame_ratio; + // TODO: + // If HELD + // - move with tux + // If jumped on + // - compress springs (reduce height) +} + +void +Trampoline::draw() +{ + img_trampoline[0]->draw((int)base.x, (int)base.y); +} + + /* EOF */ diff --git a/src/gameobjs.h b/src/gameobjs.h index 92d311db3..69a84538f 100644 --- a/src/gameobjs.h +++ b/src/gameobjs.h @@ -27,6 +27,28 @@ #include "timer.h" #include "scene.h" +template +struct ObjectData +{ + int x; + int y; + 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_) {}; + + ObjectData() + : x(0), y(0), type_specific() {}; +}; + +struct TrampolineData +{ + unsigned int power; +}; + + /* Bounciness of distros: */ #define NO_BOUNCE 0 #define BOUNCE 1 @@ -85,6 +107,17 @@ class FloatingScore : public GameObject std::string type() { return "FloatingScore"; }; }; +class Trampoline : public GameObject +{ + public: + void init(float x, float y); + void action(double frame_ratio); + void draw(); + std::string type() { return "Trampoline"; }; +}; + +void load_trampoline_gfx(); + #endif /* Local Variables: */ diff --git a/src/level.cpp b/src/level.cpp index ce2414f28..869c1e2ba 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -33,6 +33,7 @@ #include "lispreader.h" #include "resources.h" #include "music_manager.h" +#include "gameobjs.h" using namespace std; @@ -391,15 +392,28 @@ Level::load(const std::string& filename) while (!lisp_nil_p(cur)) { lisp_object_t* data = lisp_car(cur); + std::string object_type = ""; - BadGuyData bg_data; - bg_data.kind = badguykind_from_string(lisp_symbol(lisp_car(data))); LispReader reader(lisp_cdr(data)); - reader.read_int("x", &bg_data.x); - reader.read_int("y", &bg_data.y); - reader.read_bool("stay-on-platform", &bg_data.stay_on_platform); + reader.read_string("type", &object_type); - badguy_data.push_back(bg_data); + if (object_type == "badguy" || object_type == "") + { + BadGuyData bg_data; + bg_data.kind = badguykind_from_string(lisp_symbol(lisp_car(data))); + reader.read_int("x", &bg_data.x); + reader.read_int("y", &bg_data.y); + reader.read_bool("stay-on-platform", &bg_data.stay_on_platform); + + badguy_data.push_back(bg_data); + } + else + { + if (lisp_symbol(lisp_car(data)) == "trampoline") + { + ObjectData _trampoline_data; + } + } cur = lisp_cdr(cur); } diff --git a/src/level.h b/src/level.h index 0a023a5f6..8e70354f0 100644 --- a/src/level.h +++ b/src/level.h @@ -26,6 +26,7 @@ #include "badguy.h" #include "lispreader.h" #include "musicref.h" +#include "gameobjs.h" class Tile; @@ -97,6 +98,7 @@ class Level float hor_autoscroll_speed; std::vector badguy_data; + std::vector< ObjectData > trampoline_data; /** A collection of points to which Tux can be reset after a lost live */ std::vector reset_points; diff --git a/src/resources.cpp b/src/resources.cpp index cdef725a5..b6fcf7065 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -175,6 +175,9 @@ void loadshared() /* Upgrades: */ load_special_gfx(); + /* Trampoline */ + load_trampoline_gfx(); + /* Distros: */ img_distro[0] = new Surface(datadir + "/images/tilesets/coin1.png", USE_ALPHA);