From: Florian Forster Date: Sat, 30 Jan 2010 13:01:38 +0000 (+0000) Subject: Bug 474: Flip bonus-block flowers and partial-size tilemaps properly. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=30e7ce8e8812f75334733830748a59731d99bf3f;p=supertux.git Bug 474: Flip bonus-block flowers and partial-size tilemaps properly. Resolves #474. Thanks to Matt McCutchen for this patch. SVN-Revision: 6298 --- diff --git a/src/object/flower.cpp b/src/object/flower.cpp index aaccbb3eb..eb54f9c28 100644 --- a/src/object/flower.cpp +++ b/src/object/flower.cpp @@ -21,7 +21,8 @@ Flower::Flower(BonusType _type) : type(_type), - sprite() + sprite(), + drawing_effect(NO_EFFECT) { bbox.set_size(32, 32); @@ -51,7 +52,7 @@ Flower::update(float ) void Flower::draw(DrawingContext& context) { - sprite->draw(context, get_pos(), LAYER_OBJECTS); + sprite->draw(context, get_pos(), LAYER_OBJECTS, drawing_effect); } HitResponse diff --git a/src/object/flower.hpp b/src/object/flower.hpp index 1f3648a30..ec72a643f 100644 --- a/src/object/flower.hpp +++ b/src/object/flower.hpp @@ -34,10 +34,13 @@ public: private: BonusType type; SpritePtr sprite; + DrawingEffect drawing_effect; private: Flower(const Flower&); Flower& operator=(const Flower&); + + friend class FlipLevelTransformer; }; #endif diff --git a/src/object/tilemap.hpp b/src/object/tilemap.hpp index 9c1f76ed7..ff6bd0b1c 100644 --- a/src/object/tilemap.hpp +++ b/src/object/tilemap.hpp @@ -81,6 +81,9 @@ public: return movement; } + Path *get_path() + { return path.get(); } + void set_offset(const Vector &offset) { this->offset = offset; } diff --git a/src/sprite/sprite.cpp b/src/sprite/sprite.cpp index 01c41cfe8..abf3c93de 100644 --- a/src/sprite/sprite.cpp +++ b/src/sprite/sprite.cpp @@ -123,20 +123,23 @@ Sprite::update() } 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 diff --git a/src/sprite/sprite.hpp b/src/sprite/sprite.hpp index 79d12ae71..f5be38c34 100644 --- a/src/sprite/sprite.hpp +++ b/src/sprite/sprite.hpp @@ -34,7 +34,8 @@ public: 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); diff --git a/src/supertux/flip_level_transformer.cpp b/src/supertux/flip_level_transformer.cpp index 3f258e27f..4d2445f13 100644 --- a/src/supertux/flip_level_transformer.cpp +++ b/src/supertux/flip_level_transformer.cpp @@ -17,6 +17,7 @@ #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" @@ -35,7 +36,7 @@ FlipLevelTransformer::transform_sector(Sector* sector) TileMap* tilemap = dynamic_cast (object); if(tilemap) { - transform_tilemap(tilemap); + transform_tilemap(height, tilemap); } Player* player = dynamic_cast (object); if(player) { @@ -48,6 +49,10 @@ FlipLevelTransformer::transform_sector(Sector* sector) if(badguy) { transform_badguy(height, badguy); } + Flower* flower = dynamic_cast (object); + if(flower) { + transform_flower(flower); + } Platform* platform = dynamic_cast (object); if(platform) { transform_platform(height, *platform); @@ -70,8 +75,27 @@ FlipLevelTransformer::transform_sector(Sector* sector) 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::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) { @@ -83,11 +107,13 @@ FlipLevelTransformer::transform_tilemap(TileMap* tilemap) 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 @@ -115,13 +141,15 @@ FlipLevelTransformer::transform_moving_object(float height, MovingObject*object) } 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::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 diff --git a/src/supertux/flip_level_transformer.hpp b/src/supertux/flip_level_transformer.hpp index ca4d4d966..b7bef11b4 100644 --- a/src/supertux/flip_level_transformer.hpp +++ b/src/supertux/flip_level_transformer.hpp @@ -18,13 +18,16 @@ #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 @@ -33,10 +36,13 @@ public: 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); };