+;; -*- mode: scheme -*-
+
(supertux-tiles
(properties
(id 0))
(images "bonus1.png")
(solid #t)
(fullbox #t)
+ (next-tile 84)
(data 1))
(tile (id 27)
(images "block1.png")
(tile (id 77)
(images "brick0.png")
- (brick #t)
+ (brick #t)
+ (data 1)
+ (next-tile 0)
(solid #t))
(tile (id 78)
(images "brick1.png")
(brick #t)
+ (data 1)
+ (next-tile 0)
(solid #t))
(tile (id 79)
(images "box-full.png")
(fullbox #t)
(solid #t)
+ (next-tile 84)
(data 1))
(tile (id 84)
(images "box-full.png")
(solid #t)
(fullbox #t)
- (data 2))
+ (data 2)
+ (next-tile 84))
(tile (id 103)
(images "box-full.png")
(solid #t)
(fullbox #t)
- (data 3))
+ (data 3)
+ (next-tile 84))
)
\ No newline at end of file
{
texture_draw(&ptile->images[( ((global_frame_counter*25) / ptile->anim_speed) % (ptile->images.size()))],x,y);
}
- else
+ else if (ptile->images.size() == 1)
{
texture_draw(&ptile->images[0],x,y);
}
+ else
+ {
+ printf("Tile not dravable %u\n", c);
+ }
}
}
void trybreakbrick(float x, float y)
{
- if (isbrick(x, y))
+ Tile* tile = gettile(x, y);
+ if (tile->brick)
{
- if (shape(x, y) == 'x' || shape(x, y) == 'y')
+ if (tile->data > 0)
{
/* Get a distro from it: */
-
add_bouncy_distro(((int)(x + 1) / 32) * 32,
(int)(y / 32) * 32);
}
if (distro_counter <= 0)
- level_change(¤t_level,x, y, TM_IA, 'a');
+ level_change(¤t_level,x, y, TM_IA, tile->next_tile2);
play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
score = score + SCORE_DISTRO;
else
{
/* Get rid of it: */
-
- level_change(¤t_level,x, y, TM_IA, '.');
+ level_change(¤t_level,x, y, TM_IA, tile->next_tile);
}
void tryemptybox(float x, float y, int col_side)
{
- if (!isfullbox(x, y))
+ Tile* tile = gettile(x,y);
+ if (!tile->fullbox)
return;
// according to the collision side, set the upgrade direction
col_side = LEFT;
// FIXME: Content of boxes must be handled otherwise
- switch(gettile(x,y)->data)
+ switch(tile->data)
{
case 1: //'A': /* Box with a distro! */
add_bouncy_distro(((int)(x + 1) / 32) * 32, (int)(y / 32) * 32 - 32);
}
/* Empty the box: */
- level_change(¤t_level,x, y, TM_IA, 'a');
+ level_change(¤t_level,x, y, TM_IA, tile->next_tile);
}
Tile* tile = gettile(x, y);
if (tile && tile->distro)
{
- level_change(¤t_level,x, y, TM_IA, '.');
+ level_change(¤t_level,x, y, TM_IA, tile->next_tile);
play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
if (bounciness == BOUNCE)
//
//
+#include <map>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
// 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;
+ std::map<char, int> transtable;
+ transtable['.'] = 0;
+ transtable['0'] = 0;
+ transtable['1'] = 1;
+ transtable['2'] = 2;
+ transtable['x'] = 77;
+ transtable['X'] = 77;
+ transtable['y'] = 78;
+ transtable['Y'] = 78;
+ transtable['A'] = 83;
+ transtable['B'] = 102;
+ transtable['!'] = 103;
+ transtable['a'] = 84;
+ transtable['C'] = 85;
+ transtable['D'] = 86;
+ transtable['E'] = 87;
+ transtable['F'] = 88;
+ transtable['c'] = 89;
+ transtable['d'] = 90;
+ transtable['e'] = 91;
+ transtable['f'] = 92;
+
+ transtable['G'] = 93;
+ transtable['H'] = 94;
+ transtable['I'] = 95;
+ transtable['J'] = 96;
+
+ transtable['g'] = 97;
+ transtable['h'] = 98;
+ transtable['i'] = 99;
+ transtable['j'] = 100
+ ;
+ transtable['#'] = 11;
+ transtable['['] = 13;
+ transtable['='] = 14;
+ transtable[']'] = 15;
+ transtable['$'] = 82;
+ transtable['^'] = 76;
+ transtable['*'] = 80;
+ transtable['|'] = 79;
+ transtable['\\'] = 81;
+ transtable['&'] = 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");
+ {
+ std::map<char, int>::iterator j = transtable.find(*i);
+ if (j != transtable.end())
+ *i = j->second;
+ else
+ printf("Error: conversion will fail, unsupported char: '%c' (%d)\n", *i, *i);
+ }
}
}
if (strcmp(lisp_symbol(lisp_car(element)), "tile") == 0)
{
- int id = 0;
- std::vector<std::string> filenames;
-
- Tile* tile = new Tile;
+ Tile* tile = new Tile;
+ tile->id = -1;
tile->solid = false;
tile->brick = false;
tile->ice = false;
tile->distro = false;
tile->data = 0;
tile->alpha = 0;
+ tile->next_tile = 0;
+ tile->next_tile2 = 0;
tile->anim_speed = 25;
LispReader reader(lisp_cdr(element));
- reader.read_int("id", &id);
+ assert(reader.read_int("id", &tile->id));
reader.read_bool("solid", &tile->solid);
reader.read_bool("brick", &tile->brick);
reader.read_bool("ice", &tile->ice);
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);
+ reader.read_int("next-tile", &tile->next_tile);
+ reader.read_int("next-tile2", &tile->next_tile2);
+ reader.read_string_vector("images", &tile->filenames);
- for(std::vector<std::string>::iterator it = filenames.begin(); it != filenames.end(); ++it)
+ for(std::vector<std::string>::iterator it = tile->filenames.begin();
+ it != tile->filenames.end();
+ ++it)
{
texture_type cur_image;
tile->images.push_back(cur_image);
USE_ALPHA);
}
- if (id+tileset_id >= int(tiles.size()))
- tiles.resize(id+tileset_id+1);
+ if (tile->id + tileset_id >= int(tiles.size()))
+ tiles.resize(tile->id + tileset_id+1);
- tiles[id+tileset_id] = tile;
+ tiles[tile->id + tileset_id] = tile;
}
else if (strcmp(lisp_symbol(lisp_car(element)), "tileset") == 0)
{
*/
struct Tile
{
+ int id;
+
std::vector<texture_type> images;
+ std::vector<std::string> filenames;
/** solid tile that is indestructable by Tux */
bool solid;
/** General purpose data attached to a tile (content of a box, type of coin) */
int data;
+ /** Id of the tile that is going to replace this tile once it has
+ been collected or jumped at */
+ int next_tile;
+ int next_tile2;
+
int anim_speed;
unsigned char alpha;
};
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; } }
+ Tile* get(unsigned int id) {
+ if(id < tiles.size())
+ {
+ return tiles[id];
+ }
+ else
+ {
+ // Never return 0, but return the 0th tile instead so that
+ // user code doesn't have to check for NULL pointers all over
+ // the place
+ return tiles[0];
+ }
+ }
};
#endif