FlipLevelTransformer Class Reference

Vertically or horizontally flip a level. More...

#include <flip_level_transformer.hpp>

Inherits LevelTransformer.

List of all members.

Public Member Functions

virtual void transform_sector (Sector *sector)

Private Member Functions

DrawingEffect transform_drawing_effect (DrawingEffect effect)
void transform_path (float height, float obj_height, Path &path)
void transform_tilemap (float height, TileMap *tilemap)
void transform_moving_object (float height, MovingObject *object)
void transform_badguy (float height, BadGuy *badguy)
void transform_spawnpoint (float height, SpawnPoint *spawnpoint)
void transform_flower (Flower *flower)
void transform_platform (float height, Platform &platform)
void transform_block (float height, Block &block)


Detailed Description

Vertically or horizontally flip a level.

Definition at line 33 of file flip_level_transformer.hpp.


Member Function Documentation

void FlipLevelTransformer::transform_sector ( Sector sector  )  [virtual]

Implements LevelTransformer.

Definition at line 29 of file flip_level_transformer.cpp.

References Sector::camera, Sector::gameobjects, MovingObject::get_bbox(), Rectf::get_height(), Sector::get_height(), MovingObject::get_pos(), Player::move(), Sector::player, Camera::reset(), Sector::spawnpoints, transform_badguy(), transform_block(), transform_flower(), transform_moving_object(), transform_platform(), transform_spawnpoint(), transform_tilemap(), and Vector::y.

00030 {
00031   float height = sector->get_height();
00032 
00033   for(Sector::GameObjects::iterator i = sector->gameobjects.begin();
00034       i != sector->gameobjects.end(); ++i) {
00035     GameObject* object = *i;
00036 
00037     TileMap* tilemap = dynamic_cast<TileMap*> (object);
00038     if(tilemap) {
00039       transform_tilemap(height, tilemap);
00040     }
00041     Player* player = dynamic_cast<Player*> (object);
00042     if(player) {
00043       Vector pos = player->get_pos();
00044       pos.y = height - pos.y - player->get_bbox().get_height();
00045       player->move(pos);
00046       continue;
00047     }
00048     BadGuy* badguy = dynamic_cast<BadGuy*> (object);
00049     if(badguy) {
00050       transform_badguy(height, badguy);
00051     }
00052     Flower* flower = dynamic_cast<Flower*> (object);
00053     if(flower) {
00054       transform_flower(flower);
00055     }
00056     Platform* platform = dynamic_cast<Platform*> (object);
00057     if(platform) {
00058       transform_platform(height, *platform);
00059     }
00060     Block* block = dynamic_cast<Block*> (object);
00061     if(block) {
00062       transform_block(height, *block);
00063     }
00064     MovingObject* mobject = dynamic_cast<MovingObject*> (object);
00065     if(mobject) {
00066       transform_moving_object(height, mobject);
00067     }
00068   }
00069   for(Sector::SpawnPoints::iterator i = sector->spawnpoints.begin();
00070       i != sector->spawnpoints.end(); ++i) {
00071     transform_spawnpoint(height, *i);
00072   }
00073 
00074   if(sector->camera != 0 && sector->player != 0)
00075     sector->camera->reset(sector->player->get_pos());
00076 }

DrawingEffect FlipLevelTransformer::transform_drawing_effect ( DrawingEffect  effect  )  [private]

Definition at line 79 of file flip_level_transformer.cpp.

References NO_EFFECT, and VERTICAL_FLIP.

Referenced by transform_flower(), and transform_tilemap().

00080 {
00081   if(effect != 0) {
00082     return NO_EFFECT;
00083   } else {
00084     return VERTICAL_FLIP;
00085   }
00086 }

void FlipLevelTransformer::transform_path ( float  height,
float  obj_height,
Path path 
) [private]

Definition at line 89 of file flip_level_transformer.cpp.

References Path::nodes.

Referenced by transform_platform(), and transform_tilemap().

00090 {
00091   for (std::vector<Path::Node>::iterator i = path.nodes.begin(); i != path.nodes.end(); i++) {
00092     Vector& pos = i->position;
00093     pos.y = height - pos.y - obj_height;
00094   }
00095 }

void FlipLevelTransformer::transform_tilemap ( float  height,
TileMap tilemap 
) [private]

Definition at line 98 of file flip_level_transformer.cpp.

References TileMap::change(), TileMap::get_bbox(), TileMap::get_drawing_effect(), Rectf::get_height(), TileMap::get_height(), TileMap::get_offset(), TileMap::get_path(), TileMap::get_tile_id(), TileMap::get_width(), TileMap::set_drawing_effect(), TileMap::set_offset(), transform_drawing_effect(), transform_path(), and Vector::y.

Referenced by transform_sector().

00099 {
00100   for(size_t x = 0; x < tilemap->get_width(); ++x) {
00101     for(size_t y = 0; y < tilemap->get_height()/2; ++y) {
00102       // swap tiles
00103       int y2 = tilemap->get_height()-1-y;
00104       uint32_t t1 = tilemap->get_tile_id(x, y);
00105       uint32_t t2 = tilemap->get_tile_id(x, y2);
00106       tilemap->change(x, y, t2);
00107       tilemap->change(x, y2, t1);
00108     }
00109   }
00110   tilemap->set_drawing_effect(transform_drawing_effect(tilemap->get_drawing_effect()));
00111   Vector offset = tilemap->get_offset();
00112   offset.y = height - offset.y - tilemap->get_bbox().get_height();
00113   tilemap->set_offset(offset);
00114   Path* path = tilemap->get_path().get();
00115   if (path)
00116     transform_path(height, tilemap->get_bbox().get_height(), *path);
00117 }

void FlipLevelTransformer::transform_moving_object ( float  height,
MovingObject object 
) [private]

Definition at line 136 of file flip_level_transformer.cpp.

References MovingObject::get_bbox(), Rectf::get_height(), MovingObject::get_pos(), MovingObject::set_pos(), and Vector::y.

Referenced by transform_sector().

00137 {
00138   Vector pos = object->get_pos();
00139   pos.y = height - pos.y - object->get_bbox().get_height();
00140   object->set_pos(pos);
00141 }

void FlipLevelTransformer::transform_badguy ( float  height,
BadGuy badguy 
) [private]

Definition at line 120 of file flip_level_transformer.cpp.

References BadGuy::get_start_position(), BadGuy::set_start_position(), and Vector::y.

Referenced by transform_sector().

00121 {
00122   Vector pos = badguy->get_start_position();
00123   pos.y = height - pos.y;
00124   badguy->set_start_position(pos);
00125 }

void FlipLevelTransformer::transform_spawnpoint ( float  height,
SpawnPoint spawnpoint 
) [private]

Definition at line 128 of file flip_level_transformer.cpp.

References SpawnPoint::pos, and Vector::y.

Referenced by transform_sector().

00129 {
00130   Vector pos = spawn->pos;
00131   pos.y = height - pos.y;
00132   spawn->pos = pos;
00133 }

void FlipLevelTransformer::transform_flower ( Flower flower  )  [private]

Definition at line 144 of file flip_level_transformer.cpp.

References Flower::drawing_effect, and transform_drawing_effect().

Referenced by transform_sector().

00145 {
00146   flower->drawing_effect = transform_drawing_effect(flower->drawing_effect);
00147 }

void FlipLevelTransformer::transform_platform ( float  height,
Platform platform 
) [private]

Definition at line 150 of file flip_level_transformer.cpp.

References MovingObject::get_bbox(), Rectf::get_height(), Platform::get_path(), and transform_path().

Referenced by transform_sector().

00151 {
00152   transform_path(height, platform.get_bbox().get_height(), platform.get_path());
00153 }

void FlipLevelTransformer::transform_block ( float  height,
Block block 
) [private]

Definition at line 156 of file flip_level_transformer.cpp.

References MovingObject::get_bbox(), Rectf::get_height(), and Block::original_y.

Referenced by transform_sector().

00157 {
00158   if (block.original_y != -1) block.original_y = height - block.original_y - block.get_bbox().get_height();
00159 }


The documentation for this class was generated from the following files:
Generated on Mon Apr 14 03:38:35 2014 for SuperTux by  doxygen 1.5.1