4 // Copyright (C) 2005 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 #include "flip_level_transformer.h"
23 #include "object/tilemap.h"
24 #include "object/camera.h"
25 #include "badguy/badguy.h"
27 #include "tile_manager.h"
28 #include "spawn_point.h"
31 FlipLevelTransformer::transform_sector(Sector* sector)
33 float height = sector->solids->get_height()
34 * sector->solids->get_tilemanager()->get_default_height();
36 for(Sector::GameObjects::iterator i = sector->gameobjects.begin();
37 i != sector->gameobjects.end(); ++i) {
38 GameObject* object = *i;
40 TileMap* tilemap = dynamic_cast<TileMap*> (object);
42 transform_tilemap(tilemap);
44 Player* player = dynamic_cast<Player*> (object);
46 Vector pos = player->get_pos();
47 pos.y = height - pos.y;
51 BadGuy* badguy = dynamic_cast<BadGuy*> (object);
53 transform_badguy(height, badguy);
57 MovingObject* mobject = dynamic_cast<MovingObject*> (object);
59 transform_moving_object(height, mobject);
62 for(Sector::SpawnPoints::iterator i = sector->spawnpoints.begin();
63 i != sector->spawnpoints.end(); ++i) {
64 transform_spawnpoint(height, *i);
67 if(sector->camera != 0 && sector->player != 0)
68 sector->camera->reset(sector->player->get_pos());
72 FlipLevelTransformer::transform_tilemap(TileMap* tilemap)
74 for(size_t x = 0; x < tilemap->get_width(); ++x) {
75 for(size_t y = 0; y < tilemap->get_height()/2; ++y) {
77 int y2 = tilemap->get_height()-1-y;
78 const Tile* t1 = tilemap->get_tile(x, y);
79 const Tile* t2 = tilemap->get_tile(x, y2);
80 tilemap->change(x, y, t2->getID());
81 tilemap->change(x, y2, t1->getID());
84 if(tilemap->get_drawing_effect() != 0) {
85 tilemap->set_drawing_effect(0);
87 tilemap->set_drawing_effect(VERTICAL_FLIP);
92 FlipLevelTransformer::transform_badguy(float height, BadGuy* badguy)
94 Vector pos = badguy->get_start_position();
95 pos.y = height - pos.y;
96 badguy->set_start_position(pos);
100 FlipLevelTransformer::transform_spawnpoint(float height, SpawnPoint* spawn)
102 Vector pos = spawn->pos;
103 pos.y = height - pos.y;
108 FlipLevelTransformer::transform_moving_object(float height, MovingObject*object)
110 Vector pos = object->get_pos();
111 pos.y = height - pos.y;
112 object->set_pos(pos);