X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fsector.cpp;h=2cefe8b73421315053e4308482ab014557dfd2f1;hb=2d97548e5cded4b201bbc10d6cec6232df03e9a4;hp=809b119b074e80f1a4491e52af6f0c67529b24be;hpb=a705cb038b55f5d7634c646c134abaa7d16aee2b;p=supertux.git diff --git a/src/sector.cpp b/src/sector.cpp index 809b119b0..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" @@ -55,6 +55,7 @@ #include "badguy/mrbomb.h" #include "badguy/dispenser.h" #include "badguy/spike.h" +#include "badguy/nolok_01.h" #include "trigger/door.h" #include "trigger/sequence_trigger.h" #include "trigger/secretarea_trigger.h" @@ -62,7 +63,7 @@ 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"; @@ -72,6 +73,9 @@ Sector::Sector() Sector::~Sector() { + update_game_objects(); + assert(gameobjects_new.size() == 0); + for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end(); ++i) { delete *i; @@ -85,49 +89,17 @@ 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") { - if(camera) { - std::cerr << "Warning: More than 1 camera defined in sector.\n"; - return 0; - } - camera = new Camera(this); - camera->read(reader); + Camera* camera = new Camera(this); + camera->parse(reader); return camera; } else if(name == "tilemap") { - TileMap* tilemap = new TileMap(reader); - - if(tilemap->is_solid()) { - if(solids) { - std::cerr << "Warning multiple solid tilemaps in sector.\n"; - return 0; - } - solids = tilemap; - fix_old_tiles(); - } - return tilemap; + return new TileMap(reader); } else if(name == "particles-snow") { SnowParticleSystem* partsys = new SnowParticleSystem(); partsys->parse(reader); @@ -158,15 +130,9 @@ Sector::parse_object(const std::string& name, LispReader& reader) return new Dispenser(reader); } else if(name == "spike") { return new Spike(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; @@ -205,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); @@ -245,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); } @@ -283,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)) { @@ -346,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 @@ -359,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); } @@ -419,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 @@ -544,8 +481,7 @@ Sector::action(float elapsed_time) } /* Handle all possible collisions. */ - collision_handler(); - + collision_handler(); update_game_objects(); } @@ -562,15 +498,6 @@ Sector::update_game_objects() std::remove(bullets.begin(), bullets.end(), bullet), bullets.end()); } -#if 0 - InteractiveObject* interactive_object = - dynamic_cast (*i); - if(interactive_object) { - interactive_objects.erase( - std::remove(interactive_objects.begin(), interactive_objects.end(), - interactive_object), interactive_objects.end()); - } -#endif delete *i; i = gameobjects.erase(i); } else { @@ -582,17 +509,29 @@ Sector::update_game_objects() for(std::vector::iterator i = gameobjects_new.begin(); i != gameobjects_new.end(); ++i) { - Bullet* bullet = dynamic_cast (*i); - if(bullet) - bullets.push_back(bullet); -#if 0 - InteractiveObject* interactive_object - = dynamic_cast (*i); - if(interactive_object) - interactive_objects.push_back(interactive_object); -#endif + Bullet* bullet = dynamic_cast (*i); + if(bullet) + bullets.push_back(bullet); - gameobjects.push_back(*i); + TileMap* tilemap = dynamic_cast (*i); + if(tilemap && tilemap->is_solid()) { + if(solids == 0) { + solids = tilemap; + } else { + std::cerr << "Another solid tilemaps added. Ignoring."; + } + } + + Camera* camera = dynamic_cast (*i); + if(camera) { + if(this->camera != 0) { + std::cerr << "Warning: Multiple cameras added. Ignoring."; + continue; + } + this->camera = camera; + } + + gameobjects.push_back(*i); } gameobjects_new.clear(); } @@ -661,32 +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); - switch(tile->data) { - case 0: - triangle = AATriangle(p1, p2, AATriangle::SOUTHWEST); - break; - case 1: - triangle = AATriangle(p1, p2, AATriangle::NORTHEAST); - break; - case 2: - triangle = AATriangle(p1, p2, AATriangle::SOUTHEAST); - break; - case 3: - triangle = AATriangle(p1, p2, AATriangle::NORTHWEST); - break; - default: - printf("Invalid slope angle in tile %d !\n", tile->id); - break; - } + triangle = AATriangle(p1, p2, tile->getData()); if(Collision::rectangle_aatriangle(temphit, dest, object->movement, triangle)) { @@ -794,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) {