#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"
#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"
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";
Sector::~Sector()
{
+ update_game_objects();
+ assert(gameobjects_new.size() == 0);
+
for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end();
++i) {
delete *i;
_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);
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;
}
}
+ 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);
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);
}
|| 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)) {
}
// 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
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);
}
}
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<TileMap*> (*i);
- if(tilemap)
- {
- tilemap->do_vertical_flip();
- }
-
- BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
- if(badguy)
- badguy->start_position.y = solids->get_height()*32 - badguy->start_position.y - 32;
- Trampoline* trampoline = dynamic_cast<Trampoline*> (*i);
- if(trampoline)
- trampoline->base.y = solids->get_height()*32 - trampoline->base.y - 32;
- FlyingPlatform* flying_platform = dynamic_cast<FlyingPlatform*> (*i);
- if(flying_platform)
- flying_platform->base.y = solids->get_height()*32 - flying_platform->base.y - 32;
- Door* door = dynamic_cast<Door*> (*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
}
/* Handle all possible collisions. */
- collision_handler();
-
+ collision_handler();
update_game_objects();
}
std::remove(bullets.begin(), bullets.end(), bullet),
bullets.end());
}
-#if 0
- InteractiveObject* interactive_object =
- dynamic_cast<InteractiveObject*> (*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 {
for(std::vector<GameObject*>::iterator i = gameobjects_new.begin();
i != gameobjects_new.end(); ++i)
{
- Bullet* bullet = dynamic_cast<Bullet*> (*i);
- if(bullet)
- bullets.push_back(bullet);
-#if 0
- InteractiveObject* interactive_object
- = dynamic_cast<InteractiveObject*> (*i);
- if(interactive_object)
- interactive_objects.push_back(interactive_object);
-#endif
+ Bullet* bullet = dynamic_cast<Bullet*> (*i);
+ if(bullet)
+ bullets.push_back(bullet);
- gameobjects.push_back(*i);
+ TileMap* tilemap = dynamic_cast<TileMap*> (*i);
+ if(tilemap && tilemap->is_solid()) {
+ if(solids == 0) {
+ solids = tilemap;
+ } else {
+ std::cerr << "Another solid tilemaps added. Ignoring.";
+ }
+ }
+
+ Camera* camera = dynamic_cast<Camera*> (*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();
}
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)) {
}
}
-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)
{