improved flipping and rotating tiles in brushes in level editor
authorHolger Schemel <holger.schemel@virtion.de>
Tue, 16 May 2023 18:09:54 +0000 (20:09 +0200)
committerHolger Schemel <holger.schemel@virtion.de>
Tue, 16 May 2023 18:09:54 +0000 (20:09 +0200)
src/editor.c

index c01689237136127918ef39267e0e587b895e1c9f..7c9020702bf6c9aa3d99ca61f41b597a45aa983d 100644 (file)
@@ -12356,280 +12356,144 @@ static void SelectArea(int from_x, int from_y, int to_x, int to_y,
                                 MAX_CB_NUM_LINES *     \
                                 MAX_CB_PART_SIZE)
 
-static int getFlippedTileX(int element)
+static int getFlippedTileExt(int map[], int element)
 {
-  switch (element)
-  {
-    case EL_BD_BUTTERFLY_LEFT:         return EL_BD_BUTTERFLY_RIGHT;
-    case EL_BD_BUTTERFLY_RIGHT:                return EL_BD_BUTTERFLY_LEFT;
-
-    case EL_BD_FIREFLY_LEFT:           return EL_BD_FIREFLY_RIGHT;
-    case EL_BD_FIREFLY_RIGHT:          return EL_BD_FIREFLY_LEFT;
-
-    case EL_BUG_LEFT:                  return EL_BUG_RIGHT;
-    case EL_BUG_RIGHT:                 return EL_BUG_LEFT;
-
-    case EL_SPACESHIP_LEFT:            return EL_SPACESHIP_RIGHT;
-    case EL_SPACESHIP_RIGHT:           return EL_SPACESHIP_LEFT;
-
-    case EL_PACMAN_LEFT:               return EL_PACMAN_RIGHT;
-    case EL_PACMAN_RIGHT:              return EL_PACMAN_LEFT;
-
-    case EL_ARROW_LEFT:                        return EL_ARROW_RIGHT;
-    case EL_ARROW_RIGHT:               return EL_ARROW_LEFT;
-
-    case EL_MOLE_LEFT:                 return EL_MOLE_RIGHT;
-    case EL_MOLE_RIGHT:                        return EL_MOLE_LEFT;
-
-    case EL_BALLOON_SWITCH_LEFT:       return EL_BALLOON_SWITCH_RIGHT;
-    case EL_BALLOON_SWITCH_RIGHT:      return EL_BALLOON_SWITCH_LEFT;
-
-    case EL_YAMYAM_LEFT:               return EL_YAMYAM_RIGHT;
-    case EL_YAMYAM_RIGHT:              return EL_YAMYAM_LEFT;
-
-    case EL_SP_PORT_LEFT:              return EL_SP_PORT_RIGHT;
-    case EL_SP_PORT_RIGHT:             return EL_SP_PORT_LEFT;
-
-    case EL_SP_GRAVITY_PORT_LEFT:      return EL_SP_GRAVITY_PORT_RIGHT;
-    case EL_SP_GRAVITY_PORT_RIGHT:     return EL_SP_GRAVITY_PORT_LEFT;
-
-    case EL_SP_GRAVITY_ON_PORT_LEFT:   return EL_SP_GRAVITY_ON_PORT_RIGHT;
-    case EL_SP_GRAVITY_ON_PORT_RIGHT:  return EL_SP_GRAVITY_ON_PORT_LEFT;
-
-    case EL_SP_GRAVITY_OFF_PORT_LEFT:  return EL_SP_GRAVITY_OFF_PORT_RIGHT;
-    case EL_SP_GRAVITY_OFF_PORT_RIGHT: return EL_SP_GRAVITY_OFF_PORT_LEFT;
-
-    case EL_CONVEYOR_BELT_1_LEFT:      return EL_CONVEYOR_BELT_1_RIGHT;
-    case EL_CONVEYOR_BELT_1_RIGHT:     return EL_CONVEYOR_BELT_1_LEFT;
-
-    case EL_CONVEYOR_BELT_2_LEFT:      return EL_CONVEYOR_BELT_2_RIGHT;
-    case EL_CONVEYOR_BELT_2_RIGHT:     return EL_CONVEYOR_BELT_2_LEFT;
-
-    case EL_CONVEYOR_BELT_3_LEFT:      return EL_CONVEYOR_BELT_3_RIGHT;
-    case EL_CONVEYOR_BELT_3_RIGHT:     return EL_CONVEYOR_BELT_3_LEFT;
-
-    case EL_CONVEYOR_BELT_4_LEFT:      return EL_CONVEYOR_BELT_4_RIGHT;
-    case EL_CONVEYOR_BELT_4_RIGHT:     return EL_CONVEYOR_BELT_4_LEFT;
-
-    case EL_SPRING_LEFT:               return EL_SPRING_RIGHT;
-    case EL_SPRING_RIGHT:              return EL_SPRING_LEFT;
-
-    case EL_SP_CHIP_LEFT:              return EL_SP_CHIP_RIGHT;
-    case EL_SP_CHIP_RIGHT:             return EL_SP_CHIP_LEFT;
-
-    case EL_TUBE_VERTICAL_LEFT:                return EL_TUBE_VERTICAL_RIGHT;
-    case EL_TUBE_VERTICAL_RIGHT:       return EL_TUBE_VERTICAL_LEFT;
-    case EL_TUBE_LEFT_UP:              return EL_TUBE_RIGHT_UP;
-    case EL_TUBE_LEFT_DOWN:            return EL_TUBE_RIGHT_DOWN;
-    case EL_TUBE_RIGHT_UP:             return EL_TUBE_LEFT_UP;
-    case EL_TUBE_RIGHT_DOWN:           return EL_TUBE_LEFT_DOWN;
-
-    case EL_DC_STEELWALL_1_LEFT:       return EL_DC_STEELWALL_1_RIGHT;
-    case EL_DC_STEELWALL_1_RIGHT:      return EL_DC_STEELWALL_1_LEFT;
-    case EL_DC_STEELWALL_1_TOPLEFT:    return EL_DC_STEELWALL_1_TOPRIGHT;
-    case EL_DC_STEELWALL_1_TOPRIGHT:   return EL_DC_STEELWALL_1_TOPLEFT;
-    case EL_DC_STEELWALL_1_BOTTOMLEFT: return EL_DC_STEELWALL_1_BOTTOMRIGHT;
-    case EL_DC_STEELWALL_1_BOTTOMRIGHT:        return EL_DC_STEELWALL_1_BOTTOMLEFT;
-    case EL_DC_STEELWALL_1_TOPLEFT_2:  return EL_DC_STEELWALL_1_TOPRIGHT_2;
-    case EL_DC_STEELWALL_1_TOPRIGHT_2: return EL_DC_STEELWALL_1_TOPLEFT_2;
-    case EL_DC_STEELWALL_1_BOTTOMLEFT_2: return EL_DC_STEELWALL_1_BOTTOMRIGHT_2;
-    case EL_DC_STEELWALL_1_BOTTOMRIGHT_2: return EL_DC_STEELWALL_1_BOTTOMLEFT_2;
-
-    case EL_DC_STEELWALL_2_LEFT:       return EL_DC_STEELWALL_2_RIGHT;
-    case EL_DC_STEELWALL_2_RIGHT:      return EL_DC_STEELWALL_2_LEFT;
+  int i;
 
-    case EL_ACID_POOL_TOPLEFT:         return EL_ACID_POOL_TOPRIGHT;
-    case EL_ACID_POOL_TOPRIGHT:                return EL_ACID_POOL_TOPLEFT;
-    case EL_ACID_POOL_BOTTOMLEFT:      return EL_ACID_POOL_BOTTOMRIGHT;
-    case EL_ACID_POOL_BOTTOMRIGHT:     return EL_ACID_POOL_BOTTOMLEFT;
-  }
+  for (i = 0; map[i] != -1; i++)
+    if (map[i] == element)
+      return map[i ^ 1];       // get flipped element by flipping LSB of index
 
   return element;
 }
 
-static int getFlippedTileY(int element)
+static int getFlippedTileX(int element)
 {
-  switch (element)
-  {
-    case EL_BD_BUTTERFLY_UP:           return EL_BD_BUTTERFLY_DOWN;
-    case EL_BD_BUTTERFLY_DOWN:         return EL_BD_BUTTERFLY_UP;
-
-    case EL_BD_FIREFLY_UP:             return EL_BD_FIREFLY_DOWN;
-    case EL_BD_FIREFLY_DOWN:           return EL_BD_FIREFLY_UP;
-
-    case EL_BUG_UP:                    return EL_BUG_DOWN;
-    case EL_BUG_DOWN:                  return EL_BUG_UP;
-
-    case EL_SPACESHIP_UP:              return EL_SPACESHIP_DOWN;
-    case EL_SPACESHIP_DOWN:            return EL_SPACESHIP_UP;
-
-    case EL_PACMAN_UP:                 return EL_PACMAN_DOWN;
-    case EL_PACMAN_DOWN:               return EL_PACMAN_UP;
-
-    case EL_ARROW_UP:                  return EL_ARROW_DOWN;
-    case EL_ARROW_DOWN:                        return EL_ARROW_UP;
-
-    case EL_MOLE_UP:                   return EL_MOLE_DOWN;
-    case EL_MOLE_DOWN:                 return EL_MOLE_UP;
-
-    case EL_BALLOON_SWITCH_UP:         return EL_BALLOON_SWITCH_DOWN;
-    case EL_BALLOON_SWITCH_DOWN:       return EL_BALLOON_SWITCH_UP;
-
-    case EL_YAMYAM_UP:                 return EL_YAMYAM_DOWN;
-    case EL_YAMYAM_DOWN:               return EL_YAMYAM_UP;
-
-    case EL_SP_PORT_UP:                        return EL_SP_PORT_DOWN;
-    case EL_SP_PORT_DOWN:              return EL_SP_PORT_UP;
-
-    case EL_SP_GRAVITY_PORT_UP:                return EL_SP_GRAVITY_PORT_DOWN;
-    case EL_SP_GRAVITY_PORT_DOWN:      return EL_SP_GRAVITY_PORT_UP;
-
-    case EL_SP_GRAVITY_ON_PORT_UP:     return EL_SP_GRAVITY_ON_PORT_DOWN;
-    case EL_SP_GRAVITY_ON_PORT_DOWN:   return EL_SP_GRAVITY_ON_PORT_UP;
-
-    case EL_SP_GRAVITY_OFF_PORT_UP:    return EL_SP_GRAVITY_OFF_PORT_DOWN;
-    case EL_SP_GRAVITY_OFF_PORT_DOWN:  return EL_SP_GRAVITY_OFF_PORT_UP;
-
-    case EL_SP_CHIP_TOP:               return EL_SP_CHIP_BOTTOM;
-    case EL_SP_CHIP_BOTTOM:            return EL_SP_CHIP_TOP;
-
-    case EL_TUBE_HORIZONTAL_UP:                return EL_TUBE_HORIZONTAL_DOWN;
-    case EL_TUBE_HORIZONTAL_DOWN:      return EL_TUBE_HORIZONTAL_UP;
-    case EL_TUBE_LEFT_UP:              return EL_TUBE_LEFT_DOWN;
-    case EL_TUBE_LEFT_DOWN:            return EL_TUBE_LEFT_UP;
-    case EL_TUBE_RIGHT_UP:             return EL_TUBE_RIGHT_DOWN;
-    case EL_TUBE_RIGHT_DOWN:           return EL_TUBE_RIGHT_UP;
-
-    case EL_DC_STEELWALL_1_TOP:                return EL_DC_STEELWALL_1_BOTTOM;
-    case EL_DC_STEELWALL_1_BOTTOM:     return EL_DC_STEELWALL_1_TOP;
-    case EL_DC_STEELWALL_1_TOPLEFT:    return EL_DC_STEELWALL_1_BOTTOMLEFT;
-    case EL_DC_STEELWALL_1_TOPRIGHT:   return EL_DC_STEELWALL_1_BOTTOMRIGHT;
-    case EL_DC_STEELWALL_1_BOTTOMLEFT: return EL_DC_STEELWALL_1_TOPLEFT;
-    case EL_DC_STEELWALL_1_BOTTOMRIGHT:        return EL_DC_STEELWALL_1_TOPRIGHT;
-    case EL_DC_STEELWALL_1_TOPLEFT_2:  return EL_DC_STEELWALL_1_BOTTOMLEFT_2;
-    case EL_DC_STEELWALL_1_TOPRIGHT_2: return EL_DC_STEELWALL_1_BOTTOMRIGHT_2;
-    case EL_DC_STEELWALL_1_BOTTOMLEFT_2: return EL_DC_STEELWALL_1_TOPLEFT_2;
-    case EL_DC_STEELWALL_1_BOTTOMRIGHT_2: return EL_DC_STEELWALL_1_TOPRIGHT_2;
+  int map[] =
+  {
+    EL_BD_BUTTERFLY_LEFT,              EL_BD_BUTTERFLY_RIGHT,
+    EL_BD_FIREFLY_LEFT,                        EL_BD_FIREFLY_RIGHT,
+    EL_BUG_LEFT,                       EL_BUG_RIGHT,
+    EL_SPACESHIP_LEFT,                 EL_SPACESHIP_RIGHT,
+    EL_PACMAN_LEFT,                    EL_PACMAN_RIGHT,
+    EL_ARROW_LEFT,                     EL_ARROW_RIGHT,
+    EL_MOLE_LEFT,                      EL_MOLE_RIGHT,
+    EL_BALLOON_SWITCH_LEFT,            EL_BALLOON_SWITCH_RIGHT,
+    EL_YAMYAM_LEFT,                    EL_YAMYAM_RIGHT,
+    EL_SP_PORT_LEFT,                   EL_SP_PORT_RIGHT,
+    EL_SP_GRAVITY_PORT_LEFT,           EL_SP_GRAVITY_PORT_RIGHT,
+    EL_SP_GRAVITY_ON_PORT_LEFT,                EL_SP_GRAVITY_ON_PORT_RIGHT,
+    EL_SP_GRAVITY_OFF_PORT_LEFT,       EL_SP_GRAVITY_OFF_PORT_RIGHT,
+    EL_CONVEYOR_BELT_1_LEFT,           EL_CONVEYOR_BELT_1_RIGHT,
+    EL_CONVEYOR_BELT_2_LEFT,           EL_CONVEYOR_BELT_2_RIGHT,
+    EL_CONVEYOR_BELT_3_LEFT,           EL_CONVEYOR_BELT_3_RIGHT,
+    EL_CONVEYOR_BELT_4_LEFT,           EL_CONVEYOR_BELT_4_RIGHT,
+    EL_SPRING_LEFT,                    EL_SPRING_RIGHT,
+    EL_SP_CHIP_LEFT,                   EL_SP_CHIP_RIGHT,
+    EL_TUBE_VERTICAL_LEFT,             EL_TUBE_VERTICAL_RIGHT,
+    EL_TUBE_LEFT_UP,                   EL_TUBE_RIGHT_UP,
+    EL_TUBE_LEFT_DOWN,                 EL_TUBE_RIGHT_DOWN,
+    EL_DC_STEELWALL_1_LEFT,            EL_DC_STEELWALL_1_RIGHT,
+    EL_DC_STEELWALL_1_TOPLEFT,         EL_DC_STEELWALL_1_TOPRIGHT,
+    EL_DC_STEELWALL_1_BOTTOMLEFT,      EL_DC_STEELWALL_1_BOTTOMRIGHT,
+    EL_DC_STEELWALL_1_TOPLEFT_2,       EL_DC_STEELWALL_1_TOPRIGHT_2,
+    EL_DC_STEELWALL_1_BOTTOMLEFT_2,    EL_DC_STEELWALL_1_BOTTOMRIGHT_2,
+    EL_DC_STEELWALL_2_LEFT,            EL_DC_STEELWALL_2_RIGHT,
+    EL_ACID_POOL_TOPLEFT,              EL_ACID_POOL_TOPRIGHT,
+    EL_ACID_POOL_BOTTOMLEFT,           EL_ACID_POOL_BOTTOMRIGHT,
+
+    -1
+  };
 
-    case EL_DC_STEELWALL_2_TOP:                return EL_DC_STEELWALL_2_BOTTOM;
-    case EL_DC_STEELWALL_2_BOTTOM:     return EL_DC_STEELWALL_2_TOP;
+  return getFlippedTileExt(map, element);
+}
 
-    case EL_EMC_WALL_1:                        return EL_EMC_WALL_3;
-    case EL_EMC_WALL_3:                        return EL_EMC_WALL_1;
-  }
+static int getFlippedTileY(int element)
+{
+  int map[] =
+  {
+    EL_BD_BUTTERFLY_UP,                        EL_BD_BUTTERFLY_DOWN,
+    EL_BD_FIREFLY_UP,                  EL_BD_FIREFLY_DOWN,
+    EL_BUG_UP,                         EL_BUG_DOWN,
+    EL_SPACESHIP_UP,                   EL_SPACESHIP_DOWN,
+    EL_PACMAN_UP,                      EL_PACMAN_DOWN,
+    EL_ARROW_UP,                       EL_ARROW_DOWN,
+    EL_MOLE_UP,                                EL_MOLE_DOWN,
+    EL_BALLOON_SWITCH_UP,              EL_BALLOON_SWITCH_DOWN,
+    EL_YAMYAM_UP,                      EL_YAMYAM_DOWN,
+    EL_SP_PORT_UP,                     EL_SP_PORT_DOWN,
+    EL_SP_GRAVITY_PORT_UP,             EL_SP_GRAVITY_PORT_DOWN,
+    EL_SP_GRAVITY_ON_PORT_UP,          EL_SP_GRAVITY_ON_PORT_DOWN,
+    EL_SP_GRAVITY_OFF_PORT_UP,         EL_SP_GRAVITY_OFF_PORT_DOWN,
+    EL_SP_CHIP_TOP,                    EL_SP_CHIP_BOTTOM,
+    EL_TUBE_HORIZONTAL_UP,             EL_TUBE_HORIZONTAL_DOWN,
+    EL_TUBE_LEFT_UP,                   EL_TUBE_LEFT_DOWN,
+    EL_TUBE_RIGHT_UP,                  EL_TUBE_RIGHT_DOWN,
+    EL_DC_STEELWALL_1_TOP,             EL_DC_STEELWALL_1_BOTTOM,
+    EL_DC_STEELWALL_1_TOPLEFT,         EL_DC_STEELWALL_1_BOTTOMLEFT,
+    EL_DC_STEELWALL_1_TOPRIGHT,                EL_DC_STEELWALL_1_BOTTOMRIGHT,
+    EL_DC_STEELWALL_1_TOPLEFT_2,       EL_DC_STEELWALL_1_BOTTOMLEFT_2,
+    EL_DC_STEELWALL_1_TOPRIGHT_2,      EL_DC_STEELWALL_1_BOTTOMRIGHT_2,
+    EL_DC_STEELWALL_2_TOP,             EL_DC_STEELWALL_2_BOTTOM,
+    EL_EMC_WALL_1,                     EL_EMC_WALL_3,
+
+    -1
+  };
 
-  return element;
+  return getFlippedTileExt(map, element);
 }
 
 static int getFlippedTileXY(int element)
 {
-  switch (element)
-  {
-    case EL_BD_BUTTERFLY_LEFT:         return EL_BD_BUTTERFLY_UP;
-    case EL_BD_BUTTERFLY_RIGHT:                return EL_BD_BUTTERFLY_DOWN;
-    case EL_BD_BUTTERFLY_UP:           return EL_BD_BUTTERFLY_LEFT;
-    case EL_BD_BUTTERFLY_DOWN:         return EL_BD_BUTTERFLY_RIGHT;
-
-    case EL_BD_FIREFLY_LEFT:           return EL_BD_FIREFLY_UP;
-    case EL_BD_FIREFLY_RIGHT:          return EL_BD_FIREFLY_DOWN;
-    case EL_BD_FIREFLY_UP:             return EL_BD_FIREFLY_LEFT;
-    case EL_BD_FIREFLY_DOWN:           return EL_BD_FIREFLY_RIGHT;
-
-    case EL_BUG_LEFT:                  return EL_BUG_UP;
-    case EL_BUG_RIGHT:                 return EL_BUG_DOWN;
-    case EL_BUG_UP:                    return EL_BUG_LEFT;
-    case EL_BUG_DOWN:                  return EL_BUG_RIGHT;
-
-    case EL_SPACESHIP_LEFT:            return EL_SPACESHIP_UP;
-    case EL_SPACESHIP_RIGHT:           return EL_SPACESHIP_DOWN;
-    case EL_SPACESHIP_UP:              return EL_SPACESHIP_LEFT;
-    case EL_SPACESHIP_DOWN:            return EL_SPACESHIP_RIGHT;
-
-    case EL_PACMAN_LEFT:               return EL_PACMAN_UP;
-    case EL_PACMAN_RIGHT:              return EL_PACMAN_DOWN;
-    case EL_PACMAN_UP:                 return EL_PACMAN_LEFT;
-    case EL_PACMAN_DOWN:               return EL_PACMAN_RIGHT;
-
-    case EL_ARROW_LEFT:                        return EL_ARROW_UP;
-    case EL_ARROW_RIGHT:               return EL_ARROW_DOWN;
-    case EL_ARROW_UP:                  return EL_ARROW_LEFT;
-    case EL_ARROW_DOWN:                        return EL_ARROW_RIGHT;
-
-    case EL_MOLE_LEFT:                 return EL_MOLE_UP;
-    case EL_MOLE_RIGHT:                        return EL_MOLE_DOWN;
-    case EL_MOLE_UP:                   return EL_MOLE_LEFT;
-    case EL_MOLE_DOWN:                 return EL_MOLE_RIGHT;
-
-    case EL_BALLOON_SWITCH_LEFT:       return EL_BALLOON_SWITCH_UP;
-    case EL_BALLOON_SWITCH_RIGHT:      return EL_BALLOON_SWITCH_DOWN;
-    case EL_BALLOON_SWITCH_UP:         return EL_BALLOON_SWITCH_LEFT;
-    case EL_BALLOON_SWITCH_DOWN:       return EL_BALLOON_SWITCH_RIGHT;
-
-    case EL_YAMYAM_LEFT:               return EL_YAMYAM_UP;
-    case EL_YAMYAM_RIGHT:              return EL_YAMYAM_DOWN;
-    case EL_YAMYAM_UP:                 return EL_YAMYAM_LEFT;
-    case EL_YAMYAM_DOWN:               return EL_YAMYAM_RIGHT;
-
-    case EL_SP_PORT_LEFT:              return EL_SP_PORT_UP;
-    case EL_SP_PORT_RIGHT:             return EL_SP_PORT_DOWN;
-    case EL_SP_PORT_UP:                        return EL_SP_PORT_LEFT;
-    case EL_SP_PORT_DOWN:              return EL_SP_PORT_RIGHT;
-
-    case EL_SP_GRAVITY_PORT_LEFT:      return EL_SP_GRAVITY_PORT_UP;
-    case EL_SP_GRAVITY_PORT_RIGHT:     return EL_SP_GRAVITY_PORT_DOWN;
-    case EL_SP_GRAVITY_PORT_UP:                return EL_SP_GRAVITY_PORT_LEFT;
-    case EL_SP_GRAVITY_PORT_DOWN:      return EL_SP_GRAVITY_PORT_RIGHT;
-
-    case EL_SP_GRAVITY_ON_PORT_LEFT:   return EL_SP_GRAVITY_ON_PORT_UP;
-    case EL_SP_GRAVITY_ON_PORT_RIGHT:  return EL_SP_GRAVITY_ON_PORT_DOWN;
-    case EL_SP_GRAVITY_ON_PORT_UP:     return EL_SP_GRAVITY_ON_PORT_LEFT;
-    case EL_SP_GRAVITY_ON_PORT_DOWN:   return EL_SP_GRAVITY_ON_PORT_RIGHT;
-
-    case EL_SP_GRAVITY_OFF_PORT_LEFT:  return EL_SP_GRAVITY_OFF_PORT_UP;
-    case EL_SP_GRAVITY_OFF_PORT_RIGHT: return EL_SP_GRAVITY_OFF_PORT_DOWN;
-    case EL_SP_GRAVITY_OFF_PORT_UP:    return EL_SP_GRAVITY_OFF_PORT_LEFT;
-    case EL_SP_GRAVITY_OFF_PORT_DOWN:  return EL_SP_GRAVITY_OFF_PORT_RIGHT;
-
-    case EL_SP_CHIP_LEFT:              return EL_SP_CHIP_TOP;
-    case EL_SP_CHIP_RIGHT:             return EL_SP_CHIP_BOTTOM;
-    case EL_SP_CHIP_TOP:               return EL_SP_CHIP_LEFT;
-    case EL_SP_CHIP_BOTTOM:            return EL_SP_CHIP_RIGHT;
-
-    case EL_TUBE_VERTICAL:             return EL_TUBE_HORIZONTAL;
-    case EL_TUBE_HORIZONTAL:           return EL_TUBE_VERTICAL;
-    case EL_TUBE_VERTICAL_LEFT:                return EL_TUBE_HORIZONTAL_UP;
-    case EL_TUBE_VERTICAL_RIGHT:       return EL_TUBE_HORIZONTAL_DOWN;
-    case EL_TUBE_HORIZONTAL_UP:                return EL_TUBE_VERTICAL_LEFT;
-    case EL_TUBE_HORIZONTAL_DOWN:      return EL_TUBE_VERTICAL_RIGHT;
-    case EL_TUBE_LEFT_DOWN:            return EL_TUBE_RIGHT_UP;
-    case EL_TUBE_RIGHT_UP:             return EL_TUBE_LEFT_DOWN;
-
-    case EL_DC_STEELWALL_1_LEFT:       return EL_DC_STEELWALL_1_TOP;
-    case EL_DC_STEELWALL_1_RIGHT:      return EL_DC_STEELWALL_1_BOTTOM;
-    case EL_DC_STEELWALL_1_TOP:                return EL_DC_STEELWALL_1_LEFT;
-    case EL_DC_STEELWALL_1_BOTTOM:     return EL_DC_STEELWALL_1_RIGHT;
-    case EL_DC_STEELWALL_1_HORIZONTAL: return EL_DC_STEELWALL_1_VERTICAL;
-    case EL_DC_STEELWALL_1_VERTICAL:   return EL_DC_STEELWALL_1_HORIZONTAL;
-    case EL_DC_STEELWALL_1_TOPRIGHT:   return EL_DC_STEELWALL_1_BOTTOMLEFT;
-    case EL_DC_STEELWALL_1_BOTTOMLEFT: return EL_DC_STEELWALL_1_TOPRIGHT;
-    case EL_DC_STEELWALL_1_TOPRIGHT_2: return EL_DC_STEELWALL_1_BOTTOMLEFT_2;
-    case EL_DC_STEELWALL_1_BOTTOMLEFT_2: return EL_DC_STEELWALL_1_TOPRIGHT_2;
-
-    case EL_DC_STEELWALL_2_LEFT:       return EL_DC_STEELWALL_2_TOP;
-    case EL_DC_STEELWALL_2_RIGHT:      return EL_DC_STEELWALL_2_BOTTOM;
-    case EL_DC_STEELWALL_2_TOP:                return EL_DC_STEELWALL_2_LEFT;
-    case EL_DC_STEELWALL_2_BOTTOM:     return EL_DC_STEELWALL_2_RIGHT;
-    case EL_DC_STEELWALL_2_HORIZONTAL: return EL_DC_STEELWALL_2_VERTICAL;
-    case EL_DC_STEELWALL_2_VERTICAL:   return EL_DC_STEELWALL_2_HORIZONTAL;
-
-    case EL_EXPANDABLE_WALL_HORIZONTAL:        return EL_EXPANDABLE_WALL_VERTICAL;
-    case EL_EXPANDABLE_WALL_VERTICAL:  return EL_EXPANDABLE_WALL_HORIZONTAL;
-
-    case EL_EXPANDABLE_STEELWALL_HORIZONTAL:   return EL_EXPANDABLE_STEELWALL_VERTICAL;
-    case EL_EXPANDABLE_STEELWALL_VERTICAL:     return EL_EXPANDABLE_STEELWALL_HORIZONTAL;
-  }
+  int map[] =
+  {
+    EL_BD_BUTTERFLY_LEFT,              EL_BD_BUTTERFLY_UP,
+    EL_BD_BUTTERFLY_RIGHT,             EL_BD_BUTTERFLY_DOWN,
+    EL_BD_FIREFLY_LEFT,                        EL_BD_FIREFLY_UP,
+    EL_BD_FIREFLY_RIGHT,               EL_BD_FIREFLY_DOWN,
+    EL_BUG_LEFT,                       EL_BUG_UP,
+    EL_BUG_RIGHT,                      EL_BUG_DOWN,
+    EL_SPACESHIP_LEFT,                 EL_SPACESHIP_UP,
+    EL_SPACESHIP_RIGHT,                        EL_SPACESHIP_DOWN,
+    EL_PACMAN_LEFT,                    EL_PACMAN_UP,
+    EL_PACMAN_RIGHT,                   EL_PACMAN_DOWN,
+    EL_ARROW_LEFT,                     EL_ARROW_UP,
+    EL_ARROW_RIGHT,                    EL_ARROW_DOWN,
+    EL_MOLE_LEFT,                      EL_MOLE_UP,
+    EL_MOLE_RIGHT,                     EL_MOLE_DOWN,
+    EL_BALLOON_SWITCH_LEFT,            EL_BALLOON_SWITCH_UP,
+    EL_BALLOON_SWITCH_RIGHT,           EL_BALLOON_SWITCH_DOWN,
+    EL_YAMYAM_LEFT,                    EL_YAMYAM_UP,
+    EL_YAMYAM_RIGHT,                   EL_YAMYAM_DOWN,
+    EL_SP_PORT_LEFT,                   EL_SP_PORT_UP,
+    EL_SP_PORT_RIGHT,                  EL_SP_PORT_DOWN,
+    EL_SP_GRAVITY_PORT_LEFT,           EL_SP_GRAVITY_PORT_UP,
+    EL_SP_GRAVITY_PORT_RIGHT,          EL_SP_GRAVITY_PORT_DOWN,
+    EL_SP_GRAVITY_ON_PORT_LEFT,                EL_SP_GRAVITY_ON_PORT_UP,
+    EL_SP_GRAVITY_ON_PORT_RIGHT,       EL_SP_GRAVITY_ON_PORT_DOWN,
+    EL_SP_GRAVITY_OFF_PORT_LEFT,       EL_SP_GRAVITY_OFF_PORT_UP,
+    EL_SP_GRAVITY_OFF_PORT_RIGHT,      EL_SP_GRAVITY_OFF_PORT_DOWN,
+    EL_SP_CHIP_LEFT,                   EL_SP_CHIP_TOP,
+    EL_SP_CHIP_RIGHT,                  EL_SP_CHIP_BOTTOM,
+    EL_TUBE_VERTICAL,                  EL_TUBE_HORIZONTAL,
+    EL_TUBE_VERTICAL_LEFT,             EL_TUBE_HORIZONTAL_UP,
+    EL_TUBE_VERTICAL_RIGHT,            EL_TUBE_HORIZONTAL_DOWN,
+    EL_TUBE_LEFT_DOWN,                 EL_TUBE_RIGHT_UP,
+    EL_DC_STEELWALL_1_LEFT,            EL_DC_STEELWALL_1_TOP,
+    EL_DC_STEELWALL_1_RIGHT,           EL_DC_STEELWALL_1_BOTTOM,
+    EL_DC_STEELWALL_1_HORIZONTAL,      EL_DC_STEELWALL_1_VERTICAL,
+    EL_DC_STEELWALL_1_TOPRIGHT,                EL_DC_STEELWALL_1_BOTTOMLEFT,
+    EL_DC_STEELWALL_1_TOPRIGHT_2,      EL_DC_STEELWALL_1_BOTTOMLEFT_2,
+    EL_DC_STEELWALL_2_LEFT,            EL_DC_STEELWALL_2_TOP,
+    EL_DC_STEELWALL_2_RIGHT,           EL_DC_STEELWALL_2_BOTTOM,
+    EL_DC_STEELWALL_2_HORIZONTAL,      EL_DC_STEELWALL_2_VERTICAL,
+    EL_EXPANDABLE_WALL_HORIZONTAL,     EL_EXPANDABLE_WALL_VERTICAL,
+    EL_EXPANDABLE_STEELWALL_HORIZONTAL,        EL_EXPANDABLE_STEELWALL_VERTICAL,
+
+    -1
+  };
 
-  return element;
+  return getFlippedTileExt(map, element);
 }
 
 static int getFlippedTile(int element, int mode)