#include <vector>
#include <cassert>
+#include "defines.h"
#include "vector.h"
#include "game_object.h"
#include "serializable.h"
virtual void draw(DrawingContext& context)
{
- (void) context;
+ UNUSED_ARG(context);
}
void set_scrolling(int scroll_x, int scroll_y)
#define DEBUG_MSG( msg ) {}
#endif
+#define UNUSED_ARG(a) do {/* null */} while (&a == 0)
+
#endif /*SUPERTUX_DEFINES_H*/
}
BouncyBrick::BouncyBrick(const Vector& pos)
- : position(pos), offset(0), offset_m(-BOUNCY_BRICK_SPEED)
-{
- shape = Sector::current()->solids->get_tile_id_at(pos);
+ : position(pos), offset(0), offset_m(-BOUNCY_BRICK_SPEED),
+ shape(Sector::current()->solids->get_tile_id_at(pos))
+{
+ shape.hidden = true;
}
void
/* Stop bouncing? */
if (offset >= 0)
- remove_me();
+ {
+ shape.hidden = false;
+ remove_me();
+ }
}
void
BouncyBrick::draw(DrawingContext& context)
{
TileManager::instance()->
- draw_tile(context, shape, position + Vector(0, offset), LAYER_TILES+1);
+ draw_tile(context, shape.id, position + Vector(0, offset), LAYER_TILES+1);
}
FloatingScore::FloatingScore(const Vector& pos, int score)
#define NO_BOUNCE 0
#define BOUNCE 1
+struct TileId;
+
class BouncyDistro : public GameObject
{
public:
Vector position;
float offset;
float offset_m;
- int shape;
+ TileId& shape;
};
class FloatingScore : public GameObject
for(std::vector<int>::const_iterator sit = (*it).tiles.begin();
sit != (*it).tiles.end(); ++sit, ++i)
{
- Tile& tile = *(TileManager::instance()->get(*sit));
+ Tile& tile = TileManager::instance()->get(*sit);
Surface* image;
if(tile.editor_images.size() > 0)
image = tile.editor_images[0];
#define SUPERTUX_LISPWRITER_H
#include <iostream>
+#include <string>
#include <vector>
class LispWriter
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <memory>
+#include <algorithm>
#include <stdexcept>
#include <iostream>
#include <fstream>
throw SuperTuxException(errmsg, __FILE__, __LINE__); */
//Bad tiles (i.e. tiles that are not defined in supertux.stgt but appear in the map) are changed to ID 0 (blank tile)
- std::cout << "Warning: Undefined tile at " <<(int)pos.x/32 << "/" << (int)pos.y/32 << " (ID: " << (int)solids->get_tile_id_at(pos) << ")" << std::endl;
+ std::cout << "Warning: Undefined tile at " <<(int)pos.x/32 << "/" << (int)pos.y/32 << " (ID: " << (int)solids->get_tile_id_at(pos).id << ")" << std::endl;
solids->change_at(pos,0);
tile = solids->get_tile_at(pos);
}
std::vector<std::string> editor_filenames;
reader.read_string_vector("editor-images", editor_filenames);
+ std::vector<int> grid;
+ reader.read_int_vector("grid", grid);
+
// read images
for(std::vector<std::string>::iterator i = filenames.begin();
- i != filenames.end(); ++i) {
- Surface* surface
- = new Surface(datadir + "/images/tilesets/" + *i, USE_ALPHA);
- images.push_back(surface);
- }
+ i != filenames.end(); ++i)
+ {
+ if (grid.size() == 4)
+ {
+ Surface* surface = new Surface(datadir + "/images/tilesets/" + *i,
+ grid[0], grid[1], grid[2], grid[3],
+ USE_ALPHA);
+ images.push_back(surface);
+ }
+ else
+ {
+ Surface* surface = new Surface(datadir + "/images/tilesets/" + *i, USE_ALPHA);
+ images.push_back(surface);
+ }
+ }
+
for(std::vector<std::string>::iterator i = editor_filenames.begin();
i != editor_filenames.end(); ++i) {
Surface* surface
if(c == 0)
return;
- Tile* tile = get(c);
- if(!tile)
- return;
+ Tile& tile = get(c);
- if(!tile->images.size())
+ if(!tile.images.size())
return;
- if(tile->images.size() > 1)
+ if(tile.images.size() > 1)
{
size_t frame
- = ((global_frame_counter*25) / tile->anim_speed) % tile->images.size();
- context.draw_surface(tile->images[frame], pos, layer);
+ = ((global_frame_counter*25) / tile.anim_speed) % tile.images.size();
+ context.draw_surface(tile.images[frame], pos, layer);
}
- else if (tile->images.size() == 1)
+ else if (tile.images.size() == 1)
{
- context.draw_surface(tile->images[0], pos, layer);
+ context.draw_surface(tile.images[0], pos, layer);
}
}
const Vector& pos, int layer);
static std::set<TileGroup>* tilegroups() { if(!instance_) { instance_ = new TileManager(); } return tilegroups_ ? tilegroups_ : tilegroups_ = new std::set<TileGroup>; }
- Tile* get(unsigned int id) {
+ Tile& get(unsigned int id) {
+
if(id < tiles.size())
{
- return tiles[id];
+ 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];
+ return *tiles[0];
}
}
};
if(!reader.read_int("width", width) ||
!reader.read_int("height", height))
throw std::runtime_error("No width or height specified in tilemap.");
+
+ std::vector<unsigned int> tmp_tiles;
- if(!reader.read_int_vector("tiles", tiles))
+ if(!reader.read_int_vector("tiles", tmp_tiles))
throw std::runtime_error("No tiles in tilemap.");
+
+ tiles.resize(tmp_tiles.size());
+ for(unsigned int i = 0; i < tmp_tiles.size(); ++i)
+ {
+ tiles[i].hidden = false;
+ tiles[i].id = tmp_tiles[i];
+ }
+
if(int(tiles.size()) != width*height)
throw std::runtime_error("wrong number of tiles in tilemap.");
}
writer.write_float("speed", speed);
writer.write_int("width", width);
writer.write_int("height", height);
- writer.write_int_vector("tiles", tiles);
+
+ std::vector<unsigned int> tmp_tiles;
+ tmp_tiles.resize(tiles.size());
+ for(unsigned int i = 0; i < tmp_tiles.size(); ++i)
+ {
+ tmp_tiles[i] = tiles[i].id;
+ }
+ writer.write_int_vector("tiles", tmp_tiles);
writer.end_list("tilemap");
}
int tx, ty;
for(pos.x = start_x, tx = tsx; pos.x < end_x; pos.x += 32, ++tx) {
for(pos.y = start_y, ty = tsy; pos.y < end_y; pos.y += 32, ++ty) {
- tilemanager->draw_tile(context, tiles[ty*width + tx], pos, layer);
+ if (!tiles[ty*width + tx].hidden)
+ tilemanager->draw_tile(context, tiles[ty*width + tx].id, pos, layer);
}
}
}
{
assert(int(newt.size()) == newwidth * newheight);
- width = newwidth;
+ width = newwidth;
height = newheight;
- tiles = newt;
- layer = newlayer;
- solid = newsolid;
+
+ tiles.resize(newt.size());
+ for(unsigned int i = 0; i < newt.size(); ++i)
+ {
+ tiles[i].hidden = false;
+ tiles[i].id = newt[i];
+ }
+
+ layer = newlayer;
+ solid = newsolid;
}
void
for(int y = std::min(height, new_height)-1; y >= 0; --y) {
for(int x = new_width-1; x >= 0; --x) {
if(x >= width) {
- tiles[y * new_width + x] = 0;
+ tiles[y * new_width + x] = TileId();
} else {
tiles[y * new_width + x] = tiles[y * width + x];
}
TileMap::get_tile(int x, int y) const
{
if(x < 0 || x >= width || y < 0 || y >= height)
- return tilemanager->get(0);
+ return &tilemanager->get(0);
- return tilemanager->get(tiles[y*width + x]);
+ return &tilemanager->get(tiles[y*width + x].id);
}
Tile*
return get_tile(int(pos.x)/32, int(pos.y)/32);
}
-unsigned int
-TileMap::get_tile_id_at(const Vector& pos) const
+TileId&
+TileMap::get_tile_id_at(const Vector& pos)
{
int x = int(pos.x)/32;
int y = int(pos.y)/32;
+
return tiles[y*width + x];
}
TileMap::change(int x, int y, unsigned int newtile)
{
assert(x >= 0 && x < width && y >= 0 && y < height);
- tiles[y*width + x] = newtile;
+ tiles[y*width + x].id = newtile;
}
void
class LispReader;
class Tile;
+struct TileId
+{
+ TileId() : id(0), hidden(0) {}
+ explicit TileId(unsigned int i, bool hidden_ = false) : id(i), hidden(hidden_) {}
+
+ unsigned id :31;
+ unsigned hidden :1;
+};
+
/**
* This class is reponsible for drawing the level tiles
*/
bool is_solid() const
{ return solid; }
- unsigned int get_tile_id_at(const Vector& pos) const;
+ TileId& get_tile_id_at(const Vector& pos);
/// returns tile in row y and column y (of the tilemap)
Tile* get_tile(int x, int y) const;
void change_at(const Vector& pos, unsigned int newtile);
-public:
- std::vector<unsigned int> tiles;
+private:
+ std::vector<TileId> tiles;
private:
TileManager* tilemanager;