#include "scripting/sound.hpp"
#include "scripting/scripted_object.hpp"
#include "scripting/text.hpp"
+#include "msg.hpp"
Sector* Sector::_current = 0;
: gravity(10), player(0), solids(0), camera(0),
currentmusic(LEVEL_MUSIC)
{
- song_title = "chipdisko.ogg";
player = new Player(player_status);
add_object(player);
try {
return create_object(name, reader);
} catch(std::exception& e) {
- std::cerr << e.what() << "\n";
+ msg_warning(e.what() << "");
}
return 0;
} else if(token == "gravity") {
iter.value()->get(gravity);
} else if(token == "music") {
- iter.value()->get(song_title);
+ iter.value()->get(music);
} else if(token == "spawnpoint") {
SpawnPoint* sp = new SpawnPoint(iter.lisp());
spawnpoints.push_back(sp);
fix_old_tiles();
if(!camera) {
- std::cerr << "sector '" << name << "' does not contain a camera.\n";
+ msg_warning("sector '" << name << "' does not contain a camera.");
update_game_objects();
add_object(new Camera(this));
}
if(backgroundimage != "") {
Background* background = new Background;
- background->set_image(backgroundimage, bgspeed);
+ background->set_image(
+ std::string("images/background/") + backgroundimage, bgspeed);
add_object(background);
} else {
Background* background = new Background;
spawn->name = "main";
spawnpoints.push_back(spawn);
- song_title = "chipdisko.ogg";
- reader.get("music", song_title);
+ music = "chipdisko.ogg";
+ reader.get("music", music);
+ music = "music/" + music;
int width = 30, height = 15;
reader.get("width", width);
spawnpoints.push_back(sp);
}
} else {
- std::cerr << "Unknown token '" << iter.item() << "' in reset-points.\n";
+ msg_warning("Unknown token '" << iter.item() << "' in reset-points.");
}
}
}
if(object) {
add_object(object);
} else {
- std::cerr << "Unknown object '" << iter.item() << "' in level.\n";
+ msg_warning("Unknown object '" << iter.item() << "' in level.");
}
}
}
{
writer.write_string("name", name);
writer.write_float("gravity", gravity);
- writer.write_string("music", song_title);
+ writer.write_string("music", music);
// write spawnpoints
for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
}
}
if(!sp) {
- std::cerr << "Spawnpoint '" << spawnpoint << "' not found.\n";
+ msg_warning("Spawnpoint '" << spawnpoint << "' not found.");
if(spawnpoint != "main") {
activate("main");
} else {
if(solids == 0) {
solids = tilemap;
} else {
- std::cerr << "Another solid tilemaps added. Ignoring.";
+ msg_warning("Another solid tilemaps added. Ignoring");
}
}
Camera* camera = dynamic_cast<Camera*> (object);
if(camera) {
if(this->camera != 0) {
- std::cerr << "Warning: Multiple cameras added. Ignoring.";
+ msg_warning("Multiple cameras added. Ignoring");
continue;
}
this->camera = camera;
}
bool
+Sector::is_free_space(const Rect& rect) const
+{
+ // test with all tiles in this rectangle
+ int starttilex = int(rect.p1.x) / 32;
+ int starttiley = int(rect.p1.y) / 32;
+ int max_x = int(rect.p2.x);
+ int max_y = int(rect.p2.y);
+
+ for(int x = starttilex; x*32 < max_x; ++x) {
+ for(int y = starttiley; y*32 < max_y; ++y) {
+ const Tile* tile = solids->get_tile(x, y);
+ if(!tile)
+ continue;
+ if(tile->getAttributes() & Tile::SOLID)
+ return false;
+ }
+ }
+
+ for(MovingObjects::const_iterator i = moving_objects.begin();
+ i != moving_objects.end(); ++i) {
+ const MovingObject* moving_object = *i;
+ if(moving_object->get_group() != COLGROUP_STATIC
+ || !moving_object->is_valid())
+ continue;
+
+ if(Collision::intersects(rect, moving_object->get_bbox()))
+ return false;
+ }
+
+ return true;
+}
+
+bool
Sector::add_bullet(const Vector& pos, float xm, Direction dir)
{
// TODO remove this function and move these checks elsewhere...
currentmusic = type;
switch(currentmusic) {
case LEVEL_MUSIC:
- sound_manager->play_music(std::string("music/") + song_title);
+ sound_manager->play_music(music);
break;
case HERRING_MUSIC:
sound_manager->play_music("music/salcon.ogg");