}
void
-Sprite::draw(DrawingContext& context, const Vector& pos, int layer)
+Sprite::draw(DrawingContext& context, const Vector& pos, int layer,
+ DrawingEffect effect)
{
assert(action != 0);
update();
if((int)frame >= get_frames() || (int)frame < 0)
log_warning << "frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl;
- else
+ else {
+ context.set_drawing_effect(effect);
context.draw_surface(action->surfaces[(int)frame],
pos - Vector(action->x_offset, action->y_offset),
angle,
color,
blend,
layer + action->z_order);
+ }
}
void
SpritePtr clone() const;
/** Draw sprite, automatically calculates next frame */
- void draw(DrawingContext& context, const Vector& pos, int layer);
+ void draw(DrawingContext& context, const Vector& pos, int layer,
+ DrawingEffect effect = NO_EFFECT);
void draw_part(DrawingContext& context, const Vector& source,
const Vector& size, const Vector& pos, int layer);
#include "badguy/badguy.hpp"
#include "object/block.hpp"
#include "object/camera.hpp"
+#include "object/flower.hpp"
#include "object/platform.hpp"
#include "object/player.hpp"
#include "object/tilemap.hpp"
TileMap* tilemap = dynamic_cast<TileMap*> (object);
if(tilemap) {
- transform_tilemap(tilemap);
+ transform_tilemap(height, tilemap);
}
Player* player = dynamic_cast<Player*> (object);
if(player) {
if(badguy) {
transform_badguy(height, badguy);
}
+ Flower* flower = dynamic_cast<Flower*> (object);
+ if(flower) {
+ transform_flower(flower);
+ }
Platform* platform = dynamic_cast<Platform*> (object);
if(platform) {
transform_platform(height, *platform);
sector->camera->reset(sector->player->get_pos());
}
+DrawingEffect
+FlipLevelTransformer::transform_drawing_effect(DrawingEffect effect)
+{
+ if(effect != 0) {
+ return NO_EFFECT;
+ } else {
+ return VERTICAL_FLIP;
+ }
+}
+
+void
+FlipLevelTransformer::transform_path(float height, float obj_height, Path& path)
+{
+ for (std::vector<Path::Node>::iterator i = path.nodes.begin(); i != path.nodes.end(); i++) {
+ Vector& pos = i->position;
+ pos.y = height - pos.y - obj_height;
+ }
+}
+
void
-FlipLevelTransformer::transform_tilemap(TileMap* tilemap)
+FlipLevelTransformer::transform_tilemap(float height, TileMap* tilemap)
{
for(size_t x = 0; x < tilemap->get_width(); ++x) {
for(size_t y = 0; y < tilemap->get_height()/2; ++y) {
tilemap->change(x, y2, t1);
}
}
- if(tilemap->get_drawing_effect() != 0) {
- tilemap->set_drawing_effect(NO_EFFECT);
- } else {
- tilemap->set_drawing_effect(VERTICAL_FLIP);
- }
+ tilemap->set_drawing_effect(transform_drawing_effect(tilemap->get_drawing_effect()));
+ Vector offset = tilemap->get_offset();
+ offset.y = height - offset.y - tilemap->get_bbox().get_height();
+ tilemap->set_offset(offset);
+ Path *path = tilemap->get_path();
+ if (path)
+ transform_path(height, tilemap->get_bbox().get_height(), *path);
}
void
}
void
+FlipLevelTransformer::transform_flower(Flower* flower)
+{
+ flower->drawing_effect = transform_drawing_effect(flower->drawing_effect);
+}
+
+void
FlipLevelTransformer::transform_platform(float height, Platform& platform)
{
- Path& path = platform.get_path();
- for (std::vector<Path::Node>::iterator i = path.nodes.begin(); i != path.nodes.end(); i++) {
- Vector& pos = i->position;
- pos.y = height - pos.y - platform.get_bbox().get_height();
- }
+ transform_path(height, platform.get_bbox().get_height(), platform.get_path());
}
void
#define HEADER_SUPERTUX_SUPERTUX_FLIP_LEVEL_TRANSFORMER_HPP
#include "supertux/level_transformer.hpp"
+#include "video/drawing_context.hpp"
class TileMap;
class BadGuy;
class SpawnPoint;
class MovingObject;
+class Flower;
class Platform;
class Block;
+class Path;
/** Vertically or horizontally flip a level */
class FlipLevelTransformer : public LevelTransformer
virtual void transform_sector(Sector* sector);
private:
- void transform_tilemap(TileMap* tilemap);
+ 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);
};