Bug 474: Flip bonus-block flowers and partial-size tilemaps properly.
authorflorianf <florianf@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Sat, 30 Jan 2010 13:01:38 +0000 (13:01 +0000)
committerflorianf <florianf@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Sat, 30 Jan 2010 13:01:38 +0000 (13:01 +0000)
Resolves #474. Thanks to Matt McCutchen for this patch.

git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6298 837edb03-e0f3-0310-88ca-d4d4e8b29345

src/object/flower.cpp
src/object/flower.hpp
src/object/tilemap.hpp
src/sprite/sprite.cpp
src/sprite/sprite.hpp
src/supertux/flip_level_transformer.cpp
src/supertux/flip_level_transformer.hpp

index aaccbb3..eb54f9c 100644 (file)
@@ -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
index 1f3648a..ec72a64 100644 (file)
@@ -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
index 9c1f76e..ff6bd0b 100644 (file)
@@ -81,6 +81,9 @@ public:
     return movement;
   }
 
+  Path *get_path()
+  { return path.get(); }
+
   void set_offset(const Vector &offset)
   { this->offset = offset; }
 
index 01c41cf..abf3c93 100644 (file)
@@ -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
index 79d12ae..f5be38c 100644 (file)
@@ -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);
index 3f258e2..4d2445f 100644 (file)
@@ -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<TileMap*> (object);
     if(tilemap) {
-      transform_tilemap(tilemap);
+      transform_tilemap(height, tilemap);
     }
     Player* player = dynamic_cast<Player*> (object);
     if(player) {
@@ -48,6 +49,10 @@ FlipLevelTransformer::transform_sector(Sector* sector)
     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);
@@ -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<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) {
@@ -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<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
index ca4d4d9..b7bef11 100644 (file)
 #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);
 };