X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fsector.cpp;h=2cefe8b73421315053e4308482ab014557dfd2f1;hb=2d97548e5cded4b201bbc10d6cec6232df03e9a4;hp=fedeee512618286e9dfccfd4640f543306645964;hpb=6e843b1780f62f45b7021bd8c38181aa211588ee;p=supertux.git diff --git a/src/sector.cpp b/src/sector.cpp index fedeee512..2cefe8b73 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -29,12 +29,12 @@ #include "app/globals.h" #include "sector.h" #include "utils/lispreader.h" -#include "gameobjs.h" -#include "camera.h" -#include "background.h" -#include "particlesystem.h" +#include "object/gameobjs.h" +#include "object/camera.h" +#include "object/background.h" +#include "object/particlesystem.h" +#include "object/tilemap.h" #include "tile.h" -#include "tilemap.h" #include "audio/sound_manager.h" #include "gameloop.h" #include "resources.h" @@ -63,19 +63,19 @@ Sector* Sector::_current = 0; Sector::Sector() - : gravity(10), player(0), solids(0), background(0), camera(0), + : gravity(10), player(0), solids(0), camera(0), currentmusic(LEVEL_MUSIC) { song_title = "Mortimers_chipdisko.mod"; player = new Player(); add_object(player); - - printf("seccreated: %p.\n", this); } Sector::~Sector() { - printf("secdel: %p.\n", this); + update_game_objects(); + assert(gameobjects_new.size() == 0); + for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end(); ++i) { delete *i; @@ -89,29 +89,11 @@ Sector::~Sector() _current = 0; } -Sector *Sector::create(const std::string& name, size_t width, size_t height) -{ - Sector *sector = new Sector; - sector->name = name; - TileMap *background = new TileMap(LAYER_BACKGROUNDTILES, false, width, height); - TileMap *interactive = new TileMap(LAYER_TILES, true, width, height); - TileMap *foreground = new TileMap(LAYER_FOREGROUNDTILES, false, width, height); - sector->add_object(background); - sector->add_object(interactive); - sector->add_object(foreground); - sector->solids = interactive; - sector->camera = new Camera(sector); - sector->add_object(sector->camera); - sector->update_game_objects(); - return sector; -} - GameObject* Sector::parse_object(const std::string& name, LispReader& reader) { if(name == "background") { - background = new Background(reader); - return background; + return new Background(reader); } else if(name == "camera") { Camera* camera = new Camera(this); camera->parse(reader); @@ -151,14 +133,6 @@ Sector::parse_object(const std::string& name, LispReader& reader) } else if(name == "nolok_01") { return new Nolok_01(reader); } -#if 0 - else if(badguykind_from_string(name) != BAD_INVALID) { - return new BadGuy(badguykind_from_string(name), reader); - } else if(name == "trampoline") { - return new Trampoline(reader); - } else if(name == "flying-platform") { - return new FlyingPlatform(reader); -#endif std::cerr << "Unknown object type '" << name << "'.\n"; return 0; @@ -197,6 +171,9 @@ Sector::parse(LispReader& lispreader) } } + update_game_objects(); + fix_old_tiles(); + update_game_objects(); if(!camera) { std::cerr << "sector '" << name << "' does not contain a camera.\n"; camera = new Camera(this); @@ -237,11 +214,11 @@ Sector::parse_old_format(LispReader& reader) bkgd_bottom.blue = b; if(backgroundimage != "") { - background = new Background; + Background* background = new Background; background->set_image(backgroundimage, bgspeed); add_object(background); } else { - background = new Background; + Background* background = new Background; background->set_gradient(bkgd_top, bkgd_bottom); add_object(background); } @@ -275,10 +252,7 @@ Sector::parse_old_format(LispReader& reader) || reader.read_int_vector("tilemap", tiles)) { TileMap* tilemap = new TileMap(); tilemap->set(width, height, tiles, LAYER_TILES, true); - solids = tilemap; add_object(tilemap); - - fix_old_tiles(); } if(reader.read_int_vector("background-tm", tiles)) { @@ -338,8 +312,14 @@ Sector::parse_old_format(LispReader& reader) } // add a camera - camera = new Camera(this); + Camera* camera = new Camera(this); add_object(camera); + + update_game_objects(); + fix_old_tiles(); + update_game_objects(); + if(solids == 0) + throw std::runtime_error("sector does not contain a solid tile layer."); } void @@ -351,31 +331,31 @@ Sector::fix_old_tiles() const Tile* tile = solids->get_tile(x, y); Vector pos(x*32, y*32); - if(tile->id == 112) { + if(tile->getID() == 112) { add_object(new InvisibleBlock(pos)); solids->change(x, y, 0); - } else if(tile->id == 295) { + } else if(tile->getID() == 295) { add_object(new Spike(pos, Spike::NORTH)); solids->change(x, y, 0); - } else if(tile->id == 296) { + } else if(tile->getID() == 296) { add_object(new Spike(pos, Spike::EAST)); solids->change(x, y, 0); - } else if(tile->id == 297) { + } else if(tile->getID() == 297) { add_object(new Spike(pos, Spike::SOUTH)); solids->change(x, y, 0); - } else if(tile->id == 298) { + } else if(tile->getID() == 298) { add_object(new Spike(pos, Spike::WEST)); solids->change(x, y, 0); - } else if(tile->attributes & Tile::COIN) { + } else if(tile->getAttributes() & Tile::COIN) { add_object(new Coin(pos)); solids->change(x, y, 0); - } else if(tile->attributes & Tile::FULLBOX) { - add_object(new BonusBlock(pos, tile->data)); + } else if(tile->getAttributes() & Tile::FULLBOX) { + add_object(new BonusBlock(pos, tile->getData())); solids->change(x, y, 0); - } else if(tile->attributes & Tile::BRICK) { - add_object(new Brick(pos, tile->data)); + } else if(tile->getAttributes() & Tile::BRICK) { + add_object(new Brick(pos, tile->getData())); solids->change(x, y, 0); - } else if(tile->attributes & Tile::GOAL) { + } else if(tile->getAttributes() & Tile::GOAL) { add_object(new SequenceTrigger(pos, "endsequence")); solids->change(x, y, 0); } @@ -411,41 +391,6 @@ Sector::write(LispWriter& writer) } void -Sector::do_vertical_flip() -{ - // remove or fix later -#if 0 - for(GameObjects::iterator i = gameobjects_new.begin(); i != gameobjects_new.end(); ++i) - { - TileMap* tilemap = dynamic_cast (*i); - if(tilemap) - { - tilemap->do_vertical_flip(); - } - - BadGuy* badguy = dynamic_cast (*i); - if(badguy) - badguy->start_position.y = solids->get_height()*32 - badguy->start_position.y - 32; - Trampoline* trampoline = dynamic_cast (*i); - if(trampoline) - trampoline->base.y = solids->get_height()*32 - trampoline->base.y - 32; - FlyingPlatform* flying_platform = dynamic_cast (*i); - if(flying_platform) - flying_platform->base.y = solids->get_height()*32 - flying_platform->base.y - 32; - Door* door = dynamic_cast (*i); - if(door) - door->set_area(door->get_area().x, solids->get_height()*32 - door->get_area().y - 32); - } - - for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end(); - ++i) { - SpawnPoint* spawn = *i; - spawn->pos.y = solids->get_height()*32 - spawn->pos.y - 32; - } -#endif -} - -void Sector::add_object(GameObject* object) { // make sure the object isn't already in the list @@ -536,8 +481,7 @@ Sector::action(float elapsed_time) } /* Handle all possible collisions. */ - collision_handler(); - + collision_handler(); update_game_objects(); } @@ -573,7 +517,6 @@ Sector::update_game_objects() if(tilemap && tilemap->is_solid()) { if(solids == 0) { solids = tilemap; - fix_old_tiles(); } else { std::cerr << "Another solid tilemaps added. Ignoring."; } @@ -657,16 +600,16 @@ Sector::collision_tilemap(MovingObject* object, int depth) const Tile* tile = solids->get_tile(x, y); if(!tile) continue; - if(!(tile->attributes & Tile::SOLID)) + if(!(tile->getAttributes() & Tile::SOLID)) continue; - if((tile->attributes & Tile::UNISOLID) && object->movement.y < 0) + if((tile->getAttributes() & Tile::UNISOLID) && object->movement.y < 0) continue; - if(tile->attributes & Tile::SLOPE) { // slope tile + if(tile->getAttributes() & Tile::SLOPE) { // slope tile AATriangle triangle; Vector p1(x*32, y*32); Vector p2((x+1)*32, (y+1)*32); - triangle = AATriangle(p1, p2, tile->data); + triangle = AATriangle(p1, p2, tile->getData()); if(Collision::rectangle_aatriangle(temphit, dest, object->movement, triangle)) { @@ -774,14 +717,6 @@ Sector::collision_handler() } } -void -Sector::add_score(const Vector& pos, int s) -{ - global_stats.add_points(SCORE_STAT, s); - - add_object(new FloatingText(pos, s)); -} - bool Sector::add_bullet(const Vector& pos, float xm, Direction dir) {