[Super-tux-commit] supertux/src gameobjs.cpp,1.16,1.17 gameobjs.h,1.9,1.10 level.cpp,1.71,1.72 level
Brought to you by:
wkendrick
From: Ryan F. <sik...@us...> - 2004-05-16 00:37:09
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20750 Modified Files: gameobjs.cpp gameobjs.h level.cpp level.h resources.cpp Log Message: - added support for different types of objects - working on adding trampoline Index: level.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.h,v retrieving revision 1.48 retrieving revision 1.49 diff -u -d -r1.48 -r1.49 --- level.h 14 May 2004 21:49:30 -0000 1.48 +++ level.h 16 May 2004 00:36:58 -0000 1.49 @@ -26,6 +26,7 @@ #include "badguy.h" #include "lispreader.h" #include "musicref.h" +#include "gameobjs.h" class Tile; @@ -97,6 +98,7 @@ float hor_autoscroll_speed; std::vector<BadGuyData> badguy_data; + std::vector< ObjectData<TrampolineData> > trampoline_data; /** A collection of points to which Tux can be reset after a lost live */ std::vector<ResetPoint> reset_points; Index: gameobjs.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameobjs.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- gameobjs.cpp 11 May 2004 21:53:50 -0000 1.16 +++ gameobjs.cpp 16 May 2004 00:36:58 -0000 1.17 @@ -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 @@ 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 */ Index: level.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.cpp,v retrieving revision 1.71 retrieving revision 1.72 diff -u -d -r1.71 -r1.72 --- level.cpp 14 May 2004 21:49:30 -0000 1.71 +++ level.cpp 16 May 2004 00:36:58 -0000 1.72 @@ -33,6 +33,7 @@ #include "lispreader.h" #include "resources.h" #include "music_manager.h" +#include "gameobjs.h" using namespace std; @@ -391,15 +392,28 @@ 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<TrampolineData> _trampoline_data; + } + } cur = lisp_cdr(cur); } Index: gameobjs.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameobjs.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- gameobjs.h 2 May 2004 21:28:32 -0000 1.9 +++ gameobjs.h 16 May 2004 00:36:58 -0000 1.10 @@ -27,6 +27,28 @@ #include "timer.h" #include "scene.h" +template <class T> +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 @@ 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: */ Index: resources.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/resources.cpp,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -r1.31 -r1.32 --- resources.cpp 12 May 2004 17:56:34 -0000 1.31 +++ resources.cpp 16 May 2004 00:36:58 -0000 1.32 @@ -175,6 +175,9 @@ /* Upgrades: */ load_special_gfx(); + /* Trampoline */ + load_trampoline_gfx(); + /* Distros: */ img_distro[0] = new Surface(datadir + "/images/tilesets/coin1.png", USE_ALPHA); |