void drawshape(float x, float y, unsigned int c)
{
- int z;
-
Tile* ptile = TileManager::instance()->get
(c);
if(ptile)
/* What shape is at some position? */
-
unsigned int shape(float x, float y)
{
return(c);
}
+Tile* gettile(float x, float y)
+{
+ return TileManager::instance()->get(shape(x, y));
+}
+
/* Is is ground? */
}
}
+bool isdistro(float x, float y)
+{
+ Tile* tile = TileManager::instance()->get(shape(x,y));
+ return tile && tile->distro;
+}
+
/* Break a brick: */
void trybreakbrick(float x, float y)
else
col_side = LEFT;
- switch(shape(x,y))
+ // FIXME: Content of boxes must be handled otherwise
+ switch(gettile(x,y)->data)
{
- case 'A': /* Box with a distro! */
+ case 1: //'A': /* Box with a distro! */
add_bouncy_distro(((int)(x + 1) / 32) * 32, (int)(y / 32) * 32 - 32);
play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
score = score + SCORE_DISTRO;
distros++;
break;
- case 'B': /* Add an upgrade! */
+ case 2: // 'B': /* Add an upgrade! */
if (tux.size == SMALL) /* Tux is small, add mints! */
add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, col_side, UPGRADE_MINTS);
else /* Tux is big, add coffee: */
add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, col_side, UPGRADE_COFFEE);
play_sound(sounds[SND_UPGRADE], SOUND_CENTER_SPEAKER);
break;
- case '!': /* Add a golden herring */
+ case 3:// '!': /* Add a golden herring */
add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, col_side, UPGRADE_HERRING);
break;
default:
void trygrabdistro(float x, float y, int bounciness)
{
- if (shape(x, y) == '$')
+ Tile* tile = gettile(x, y);
+ if (tile && tile->distro)
{
level_change(¤t_level,x, y, TM_IA, '.');
play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
int level_load(st_level* plevel, const char* filename)
{
- int x, y, j;
FILE * fi;
lisp_object_t* root_obj = 0;
fi = fopen(filename, "r");
vector<int> bg_tm;
vector<int> fg_tm;
+ int version = 0;
if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-level") == 0)
{
LispReader reader(lisp_cdr(root_obj));
+ reader.read_int("version", &version);
reader.read_int("width", &plevel->width);
reader.read_int("time", &plevel->time_left);
reader.read_int("bkgd_red", &plevel->bkgd_red);
reader.read_string("background", &plevel->bkgd_image);
reader.read_string("particle_system", &plevel->particle_system);
reader.read_int_vector("background-tm", &bg_tm);
- reader.read_int_vector("interactive-tm", &ia_tm);
- reader.read_int_vector("dynamic-tm", &dn_tm);
+ reader.read_int_vector("interactive-tm", &ia_tm);
+ reader.read_int_vector("dynamic-tm", &dn_tm);
reader.read_int_vector("foreground-tm", &fg_tm);
- }
+ // Convert old levels to the new tile numbers
+ if (version == 0)
+ {
+ int transtable[256];
+ transtable[(int)'.'] = 0;
+ transtable[(int)'0'] = 0;
+ transtable[(int)'1'] = 1;
+ transtable[(int)'2'] = 2;
+ transtable[(int)'x'] = 77;
+ transtable[(int)'X'] = 77;
+ transtable[(int)'y'] = 78;
+ transtable[(int)'Y'] = 78;
+ transtable[(int)'A'] = 83;
+ transtable[(int)'B'] = 102;
+ transtable[(int)'!'] = 103;
+ transtable[(int)'a'] = 84;
+ transtable[(int)'C'] = 85;
+ transtable[(int)'D'] = 86;
+ transtable[(int)'E'] = 87;
+ transtable[(int)'F'] = 88;
+ transtable[(int)'c'] = 89;
+ transtable[(int)'d'] = 90;
+ transtable[(int)'e'] = 91;
+ transtable[(int)'f'] = 92;
+
+ transtable[(int)'G'] = 93;
+ transtable[(int)'H'] = 94;
+ transtable[(int)'I'] = 95;
+ transtable[(int)'J'] = 96;
+
+ transtable[(int)'g'] = 97;
+ transtable[(int)'h'] = 98;
+ transtable[(int)'i'] = 99;
+ transtable[(int)'j'] = 100
+;
+ transtable[(int)'#'] = 11;
+ transtable[(int)'['] = 13;
+ transtable[(int)'='] = 14;
+ transtable[(int)']'] = 15;
+ transtable[(int)'$'] = 82;
+ transtable[(int)'^'] = 76;
+ transtable[(int)'*'] = 80;
+ transtable[(int)'|'] = 79;
+ transtable[(int)'\\'] = 81;
+ transtable[(int)'&'] = 75;
+
+ for(std::vector<int>::iterator i = ia_tm.begin(); i != ia_tm.end(); ++i)
+ if (*i < 256)
+ *i = transtable[*i];
+ else
+ puts("Error: Value to high, conversion will fail");
+ }
+ }
- int i;
- for( i = 0; i < 15; ++i)
+ for(int i = 0; i < 15; ++i)
{
plevel->dn_tiles[i] = (unsigned int*) calloc((plevel->width +1) , sizeof(unsigned int) );
plevel->ia_tiles[i] = (unsigned int*) calloc((plevel->width +1) , sizeof(unsigned int) );
plevel->fg_tiles[i] = (unsigned int*) calloc((plevel->width +1) , sizeof(unsigned int) );
}
- i = j = 0;
+ int i = 0;
+ int j = 0;
for(vector<int>::iterator it = ia_tm.begin(); it != ia_tm.end(); ++it, ++i)
{
-
plevel->ia_tiles[j][i] = (*it);
if(i == plevel->width - 1)
{
/* Mark the end position of this level! - Is a bit wrong here thought * /
for (y = 0; y < 15; ++y)
- {
- for (x = 0; x < plevel->width; ++x)
- {
- if(plevel->tiles[y][x] == '|')
- {
- if(x*32 > endpos)
- endpos = x*32;
- }
- }
- }*/
+ {
+ for (x = 0; x < plevel->width; ++x)
+ {
+ if(plevel->tiles[y][x] == '|')
+ {
+ if(x*32 > endpos)
+ endpos = x*32;
+ }
+ }
+ }*/
fclose(fi);
return 0;
fprintf(fi,";SuperTux-Level\n");
fprintf(fi,"(supertux-level\n");
+ fprintf(fi," (version %d)\n", 1);
fprintf(fi," (name \"%s\")\n", plevel->name.c_str());
fprintf(fi," (theme \"%s\")\n", plevel->theme.c_str());
fprintf(fi," (music \"%s\")\n", plevel->song_title.c_str());
size = SMALL;
got_coffee = false;
- base.x = 0;
+ // FIXME: Make the start position configurable via the levelfile
+ base.x = 100;
base.y = 240;
+
base.xm = 0;
base.ym = 0;
old_base = base;
void
Player::level_begin()
{
- base.x = 0;
- base.y = 240;
+ base.x = 100;
+ base.y = 240;
base.xm = 0;
base.ym = 0;
old_base = base;
if(size == SMALL)
{
/* Get a distro from a brick? */
-
if (shape(base.x, base.y) == 'x' ||
shape(base.x, base.y) == 'y')
{
TileManager::TileManager()
{
- std::string filename = datadir + "images/tilesets/main.stgt";
+ std::string filename = datadir + "images/tilesets/supertux.stgt";
load_tileset(filename);
}
tile->brick = false;
tile->ice = false;
tile->fullbox = false;
- tile->alpha = 0;
+ tile->alpha = 0;
+ tile->distro = 0;
+ tile->data = 0;
tile->anim_speed = 25;
LispReader reader(lisp_cdr(element));
reader.read_bool("brick", &tile->brick);
reader.read_bool("ice", &tile->ice);
reader.read_bool("fullbox", &tile->fullbox);
+ reader.read_bool("distro", &tile->distro);
+ reader.read_int("data", (int*)&tile->data);
reader.read_int("alpha", (int*)&tile->alpha);
reader.read_int("anim-speed", &tile->anim_speed);
reader.read_string_vector("images", &filenames);
for(std::vector<std::string>::iterator it = filenames.begin(); it != filenames.end(); ++it)
- {
- texture_type cur_image;
- tile->images.push_back(cur_image);
- texture_load(&tile->images[tile->images.size()-1],
- datadir + "images/tilesets/" + (*it),
- USE_ALPHA);
- }
+ {
+ texture_type cur_image;
+ tile->images.push_back(cur_image);
+ texture_load(&tile->images[tile->images.size()-1],
+ datadir + "images/tilesets/" + (*it),
+ USE_ALPHA);
+ }
if (id+tileset_id >= int(tiles.size()))
tiles.resize(id+tileset_id+1);
assert(0);
}
}
+
+// EOF //
+
*/
struct Tile
{
-std::vector<texture_type> images;
-bool solid;
-bool brick;
-bool ice;
-bool fullbox;
-int anim_speed;
-unsigned char alpha;
+ std::vector<texture_type> images;
+
+ /** solid tile that is indestructable by Tux */
+ bool solid;
+
+ /** a brick that can be destroyed by jumping under it */
+ bool brick;
+
+ /** FIXME: ? */
+ bool ice;
+
+ /** Bonusbox, content is stored in \a data */
+ bool fullbox;
+
+ /** Tile is a distro/coin */
+ bool distro;
+
+ /** General purpose data attached to a tile (content of a box, type of coin) */
+ int data;
+
+ int anim_speed;
+ unsigned char alpha;
};
class TileManager
{
-private:
- TileManager();
- std::vector<Tile*> tiles;
- static TileManager* instance_ ;
- void load_tileset(std::string filename);
+ private:
+ TileManager();
+ std::vector<Tile*> tiles;
+ static TileManager* instance_ ;
+ void load_tileset(std::string filename);
-public:
- static TileManager* instance() { return instance_ ? instance_ : instance_ = new TileManager(); }
- Tile* get(unsigned int id) { if( id < tiles.size()) { return tiles[id]; } else { return NULL; } } ;
-
+ public:
+ static TileManager* instance() { return instance_ ? instance_ : instance_ = new TileManager(); }
+ Tile* get(unsigned int id) { if( id < tiles.size()) { return tiles[id]; } else { return NULL; } }
};
#endif