[Super-tux-commit] supertux/src badguy.cpp,1.12,1.13 badguy.h,1.14,1.15 gameloop.cpp,1.27,1.28 level
Brought to you by:
wkendrick
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10704 Modified Files: badguy.cpp badguy.h gameloop.cpp level.cpp level.h leveleditor.cpp lispreader.cpp lispreader.h Log Message: - added alternative (more flexible) way to define badguys in a level Index: lispreader.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/lispreader.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- lispreader.h 22 Mar 2004 15:25:15 -0000 1.7 +++ lispreader.h 25 Mar 2004 11:36:05 -0000 1.8 @@ -176,6 +176,7 @@ bool read_int (const char* name, int* i); bool read_float (const char* name, float* f); bool read_bool (const char* name, bool* b); + bool read_lisp (const char* name, lisp_object_t** b); }; /** */ Index: level.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- level.h 24 Mar 2004 22:23:48 -0000 1.14 +++ level.h 25 Mar 2004 11:36:05 -0000 1.15 @@ -15,6 +15,7 @@ #include <string> #include "texture.h" +#include "badguy.h" #include "lispreader.h" /* This type holds meta-information about a level-subset. */ @@ -40,8 +41,22 @@ #define LEVEL_NAME_MAX 20 -struct st_level + +enum { + TM_BG, + TM_IA, + TM_DN, + TM_FG + }; + +extern texture_type img_bkgd; +extern texture_type img_bkgd_tile[2][4]; +extern texture_type img_solid[4]; +extern texture_type img_brick[2]; + +class st_level { + public: std::string name; std::string theme; std::string song_title; @@ -57,16 +72,10 @@ int bkgd_blue; int width; float gravity; -}; - -enum { - TM_BG, - TM_IA, - TM_DN, - TM_FG - }; -extern texture_type img_bkgd, img_bkgd_tile[2][4], img_solid[4], img_brick[2]; + std::vector<BadGuyData> badguy_data; + public: +}; void level_default (st_level* plevel); int level_load (st_level* plevel, const char * subset, int level); Index: badguy.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/badguy.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- badguy.h 24 Mar 2004 22:01:08 -0000 1.14 +++ badguy.h 25 Mar 2004 11:36:05 -0000 1.15 @@ -49,6 +49,22 @@ BAD_MONEY }; +BadGuyKind badguykind_from_string(const std::string& str); +std::string badguykind_to_string(BadGuyKind kind); + +struct BadGuyData +{ + BadGuyKind kind; + int x; + int y; + + BadGuyData(BadGuyKind kind_, int x_, int y_) + : kind(kind_), x(x_), y(y_) {} + + BadGuyData() + : kind(BAD_BSOD), x(0), y(0) {} +}; + /* Badguy type: */ class BadGuy { Index: badguy.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/badguy.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- badguy.cpp 24 Mar 2004 22:10:28 -0000 1.12 +++ badguy.cpp 25 Mar 2004 11:36:05 -0000 1.13 @@ -31,6 +31,39 @@ texture_type img_money_left[2]; texture_type img_money_right[2]; +BadGuyKind badguykind_from_string(const std::string& str) +{ + if (str == "money") + return BAD_MONEY; + else if (str == "laptop") + return BAD_LAPTOP; + else if (str == "bsod") + return BAD_BSOD; + else + { + printf("Couldn't convert badguy: %s\n", str.c_str()); + return BAD_BSOD; + } +} + +std::string badguykind_to_string(BadGuyKind kind) +{ + switch(kind) + { + case BAD_MONEY: + return "money"; + break; + case BAD_LAPTOP: + return "laptop"; + break; + case BAD_BSOD: + return "bsod"; + break; + default: + return "bsod"; + } +} + void BadGuy::init(float x, float y, BadGuyKind kind_) { Index: level.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- level.cpp 25 Mar 2004 11:07:02 -0000 1.15 +++ level.cpp 25 Mar 2004 11:36:05 -0000 1.16 @@ -298,6 +298,27 @@ reader.read_int_vector("dynamic-tm", &dn_tm); reader.read_int_vector("foreground-tm", &fg_tm); + { + lisp_object_t* cur = 0; + if (reader.read_lisp("objects", &cur)) + { + while (!lisp_nil_p(cur)) + { + lisp_object_t* data = lisp_car(cur); + + 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); + + plevel->badguy_data.push_back(bg_data); + + cur = lisp_cdr(cur); + } + } + } + // Convert old levels to the new tile numbers if (version == 0) { Index: leveleditor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- leveleditor.cpp 24 Mar 2004 22:23:48 -0000 1.18 +++ leveleditor.cpp 25 Mar 2004 11:36:05 -0000 1.19 @@ -597,7 +597,7 @@ void apply_level_settings_menu() { - int i,y,j; + int i; i = false; le_current_level->name = level_settings_menu->item[2].input; Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- gameloop.cpp 25 Mar 2004 11:07:02 -0000 1.27 +++ gameloop.cpp 25 Mar 2004 11:36:05 -0000 1.28 @@ -100,12 +100,19 @@ void activate_bad_guys(void) { - int x,y; + // Activate badguys the new style + for (std::vector<BadGuyData>::iterator i = current_level.badguy_data.begin(); + i != current_level.badguy_data.end(); + ++i) + { + add_bad_guy(i->x, i->y, i->kind); + } - /* Activate bad guys: */ - for (y = 0; y < 15; y++) + // FIXME: should be removed; + // Activate bad guys the old style + for (int y = 0; y < 15; y++) { - for (x = 0; x < current_level.width; x++) + for (int x = 0; x < current_level.width; x++) { if (current_level.ia_tiles[y][x] >= 1000 && current_level.ia_tiles[y][x] <= 1010) { Index: lispreader.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/lispreader.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- lispreader.cpp 22 Mar 2004 15:25:15 -0000 1.9 +++ lispreader.cpp 25 Mar 2004 11:36:05 -0000 1.10 @@ -1048,6 +1048,19 @@ } bool +LispReader::read_lisp(const char* name, lisp_object_t** b) +{ + lisp_object_t* obj = search_for (name); + if (obj) + { + *b = obj; + return true; + } + else + return false; +} + +bool LispReader::read_float (const char* name, float* f) { lisp_object_t* obj = search_for (name); |