From c2155db91b3d63c975814a7045adfb541674798d Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Thu, 25 Mar 2004 11:36:05 +0000 Subject: [PATCH] - added alternative (more flexible) way to define badguys in a level SVN-Revision: 358 --- src/badguy.cpp | 33 +++++++++++++++++++++++++++++++++ src/badguy.h | 16 ++++++++++++++++ src/gameloop.cpp | 15 +++++++++++---- src/level.cpp | 21 +++++++++++++++++++++ src/level.h | 29 +++++++++++++++++++---------- src/leveleditor.cpp | 2 +- src/lispreader.cpp | 13 +++++++++++++ src/lispreader.h | 1 + 8 files changed, 115 insertions(+), 15 deletions(-) diff --git a/src/badguy.cpp b/src/badguy.cpp index d5a63e079..2b603a469 100644 --- a/src/badguy.cpp +++ b/src/badguy.cpp @@ -31,6 +31,39 @@ texture_type img_laptop_right[3]; 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_) { diff --git a/src/badguy.h b/src/badguy.h index f2919a161..6590fa654 100644 --- a/src/badguy.h +++ b/src/badguy.h @@ -49,6 +49,22 @@ enum BadGuyKind { 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 { diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 399671f17..099643af9 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -100,12 +100,19 @@ void start_timers(void) void activate_bad_guys(void) { - int x,y; + // Activate badguys the new style + for (std::vector::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) { diff --git a/src/level.cpp b/src/level.cpp index cc40d46db..e8940e64d 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -298,6 +298,27 @@ int level_load(st_level* plevel, const char* filename) 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) { diff --git a/src/level.h b/src/level.h index ed93b8b1f..486242ea3 100644 --- a/src/level.h +++ b/src/level.h @@ -15,6 +15,7 @@ #include #include "texture.h" +#include "badguy.h" #include "lispreader.h" /* This type holds meta-information about a level-subset. */ @@ -40,8 +41,22 @@ class st_subset #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 @@ struct st_level 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 badguy_data; + public: +}; void level_default (st_level* plevel); int level_load (st_level* plevel, const char * subset, int level); diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index 6fc2b3b55..0cb0282a8 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -597,7 +597,7 @@ void update_subset_settings_menu() void apply_level_settings_menu() { - int i,y,j; + int i; i = false; le_current_level->name = level_settings_menu->item[2].input; diff --git a/src/lispreader.cpp b/src/lispreader.cpp index db0b5c308..798118969 100644 --- a/src/lispreader.cpp +++ b/src/lispreader.cpp @@ -1048,6 +1048,19 @@ LispReader::read_int (const char* name, int* i) } 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); diff --git a/src/lispreader.h b/src/lispreader.h index 2438ba3ab..f18a2f0a6 100644 --- a/src/lispreader.h +++ b/src/lispreader.h @@ -176,6 +176,7 @@ class LispReader 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); }; /** */ -- 2.11.0