To enable it, add to the level file (flip #t) .
SVN-Revision: 1532
bool stay_on_platform;
Direction dir;
+ Vector start_position;
Timer frozen_timer; // gets frozen when a ice shot hits it
int squishcount; /// number of times this enemy was squiched
Vector target; // Target that badguy is aiming for (wingling uses this)
Timer timer;
- Vector start_position;
Physic physic;
float angle;
std::string(_("by ")) + level->get_author(),
Vector(0, 400), LAYER_FOREGROUND1);
+
+ if(level->is_level_flipped())
+ context.draw_text_center(white_text,
+ _("Level Vertically Flipped!"),
+ Vector(0, 310), LAYER_FOREGROUND1);
+
context.do_drawing();
SDL_Event event;
{
sprintf(str, "%2.1f", fps_fps);
context.draw_text(white_text, "FPS",
- Vector(screen->w - white_text->get_text_width("FPS "), 40),
+ Vector(screen->w - white_text->get_text_width("FPS "), 40),
LAYER_FOREGROUND1);
context.draw_text(gold_text, str,
Vector(screen->w-4*16, 40), LAYER_FOREGROUND1);
const base_type& get_area() const
{ return area; }
+ void set_area(float x, float y)
+ { area.x = x; area.y = y; }
+
protected:
base_type area;
};
Level::Level()
: name("noname"), author("mr. x"), time_left(500)
+
{
}
return;
}
+ vertical_flip = false;
+
for(lisp_object_t* cur = level->get_lisp(); !lisp_nil_p(cur);
cur = lisp_cdr(cur)) {
std::string token = lisp_symbol(lisp_car(lisp_car(cur)));
author = lisp_string(data);
} else if(token == "time") {
time_left = lisp_integer(data);
+ } else if(token == "flip") {
+ vertical_flip = lisp_boolean(data);
} else if(token == "sector") {
Sector* sector = new Sector;
sector->parse(reader);
}
delete level;
+
+ if(vertical_flip)
+ {
+ for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i)
+ i->second->do_vertical_flip();
+ }
}
void
reader.read_string("name", name);
reader.read_string("author", author);
reader.read_int("time", time_left);
+ vertical_flip = false;
+ reader.read_bool("flip", vertical_flip);
Sector* sector = new Sector;
sector->parse_old_format(reader);
add_sector(sector);
+
+ if(vertical_flip)
+ {
+ for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i)
+ i->second->do_vertical_flip();
+ }
}
void
for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i)
{
+ if(vertical_flip)
+ i->second->do_vertical_flip();
+
writer->start_list("sector");
i->second->write(*writer);
writer->end_list("sector");
const std::string& get_author() const
{ return author; }
+ bool is_level_flipped()
+ { return vertical_flip; }
+
void add_sector(Sector* sector);
Sector* get_sector(const std::string& name);
private:
void load_old_format(LispReader& reader);
+
+ /** If true, it will flip the level vertically, during the
+ parsing process */
+ bool vertical_flip;
};
#endif /*SUPERTUX_LEVEL_H*/
}
void
+Sector::do_vertical_flip()
+{
+ for(GameObjects::iterator i = gameobjects_new.begin(); i != gameobjects_new.end(); ++i)
+ {
+ TileMap* tilemap = dynamic_cast<TileMap*> (*i);
+ if(tilemap)
+ {
+ tilemap->do_vertical_flip();
+ }
+
+ BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
+ if(badguy)
+ badguy->start_position.y = solids->get_height()*32 - badguy->start_position.y - 32;
+ Trampoline* trampoline = dynamic_cast<Trampoline*> (*i);
+ if(trampoline)
+ trampoline->base.y = solids->get_height()*32 - trampoline->base.y;
+ FlyingPlatform* flying_platform = dynamic_cast<FlyingPlatform*> (*i);
+ if(flying_platform)
+ flying_platform->base.y = solids->get_height()*32 - flying_platform->base.y;
+ Door* door = dynamic_cast<Door*> (*i);
+ if(door)
+ door->set_area(door->get_area().x, solids->get_height()*32 - door->get_area().y);
+ }
+
+ for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
+ ++i) {
+ SpawnPoint* spawn = *i;
+ spawn->pos.y = solids->get_height()*32 - spawn->pos.y;
+ }
+}
+
+void
Sector::add_object(GameObject* object)
{
gameobjects_new.push_back(object);
the tile which the badguy is walking on an killing him this way */
void trybumpbadguy(const Vector& pos);
+ /** Flip the all the sector vertically. The purpose of this is to let
+ player to play the same level in a different way :) */
+ void do_vertical_flip();
+
/** @evil@ */
static Sector* current()
{ return _current; }
#include "lispwriter.h"
TileMap::TileMap()
- : solid(false), speed(1), width(0), height(0), layer(LAYER_TILES)
+ : solid(false), speed(1), width(0), height(0), layer(LAYER_TILES), vertical_flip(false)
{
tilemanager = TileManager::instance();
}
TileMap::TileMap(LispReader& reader)
- : solid(false), speed(1), width(0), height(0), layer(LAYER_TILES)
+ : solid(false), speed(1), width(0), height(0), layer(LAYER_TILES), vertical_flip(false)
{
tilemanager = TileManager::instance();
}
TileMap::TileMap(int layer_, bool solid_, size_t width_, size_t height_)
- : solid(solid_), speed(1), width(width_), height(height_), layer(layer_)
+ : solid(solid_), speed(1), width(width_), height(height_), layer(layer_), vertical_flip(false)
{
}
void
TileMap::draw(DrawingContext& context)
-{
+{
if (speed == 1.0)
{
+ if(vertical_flip) // flip vertically the tiles, in case we are playing this
+ { // level upside down
+ context.push_transform();
+ context.set_drawing_effect(VERTICAL_FLIP);
+ }
+
/** if we don't round here, we'll have a 1 pixel gap on screen sometimes.
* I have no idea why */
float start_x = roundf(context.get_translation().x);
tilemanager->draw_tile(context, tiles[ty*width + tx].id, pos, layer);
}
}
+
+ if(vertical_flip) // disable flipping, if applied
+ context.pop_transform();
}
else
{
context.push_transform();
context.set_translation(Vector(trans_x * speed, trans_y * speed));
+ if(vertical_flip)
+ context.set_drawing_effect(VERTICAL_FLIP);
float start_x = roundf(context.get_translation().x);
float start_y = roundf(context.get_translation().y);
width = new_width;
}
+void
+TileMap::do_vertical_flip()
+{
+ // remap tiles vertically flipped
+ for(int y = 0; y < height / 2; ++y) {
+ for(int x = 0; x < width; ++x) {
+ std::swap(tiles[y*width + x], tiles[(((height-1)*width) - (y*width)) + x]);
+ }
+ }
+
+ vertical_flip = true;
+}
+
Tile*
TileMap::get_tile(int x, int y) const
{
*/
void resize(int newwidth, int newheight);
+ /** Flip the all tile map vertically. The purpose of this is to let
+ player to play the same level in a different way :) */
+ void do_vertical_flip();
+
size_t get_width() const
{ return width; }
float speed;
int width, height;
int layer;
+
+ bool vertical_flip;
};
#endif /*SUPERTUX_TILEMAP_H*/