#include <float.h>
#include <math.h>
#include <limits>
+#include <physfs.h>
#include "sector.hpp"
#include "object/player.hpp"
Sector::Sector(Level* parent)
: level(parent), currentmusic(LEVEL_MUSIC),
- ambient_light( 1.0f, 1.0f, 1.0f, 1.0f ), gravity(10), player(0), camera(0)
+ ambient_light( 1.0f, 1.0f, 1.0f, 1.0f ), gravity(10.0), player(0), camera(0)
{
add_object(new Player(player_status, "Tux"));
add_object(new DisplayEffect("Effect"));
reader.get("gravity", gravity);
std::string backgroundimage;
- reader.get("background", backgroundimage);
- if (backgroundimage == "arctis2.jpg") backgroundimage = "arctis.jpg";
+ if (reader.get("background", backgroundimage) && (backgroundimage != "")) {
+ if (backgroundimage == "arctis.png") backgroundimage = "arctis.jpg";
+ if (backgroundimage == "arctis2.jpg") backgroundimage = "arctis.jpg";
+ if (backgroundimage == "ocean.png") backgroundimage = "ocean.jpg";
+ backgroundimage = "images/background/" + backgroundimage;
+ if (!PHYSFS_exists(backgroundimage.c_str())) {
+ log_warning << "Background image \"" << backgroundimage << "\" not found. Ignoring." << std::endl;
+ backgroundimage = "";
+ }
+ }
+
float bgspeed = .5;
reader.get("bkgd_speed", bgspeed);
bgspeed /= 100;
if(backgroundimage != "") {
Background* background = new Background();
- background->set_image(
- std::string("images/background/") + backgroundimage, bgspeed);
+ background->set_image(backgroundimage, bgspeed);
add_object(background);
} else {
Gradient* gradient = new Gradient();
spawnpoints.push_back(spawn);
music = "chipdisko.ogg";
+ // skip reading music filename. It's all .ogg now, anyway
+ /*
reader.get("music", music);
+ */
music = "music/" + music;
int width = 30, height = 15;
}
}
+ if (height < 19) tilemap->resize(width, 19);
add_object(tilemap);
}
if(reader.get_vector("background-tm", tiles)) {
TileMap* tilemap = new TileMap();
tilemap->set(width, height, tiles, LAYER_BACKGROUNDTILES, false);
+ if (height < 19) tilemap->resize(width, 19);
add_object(tilemap);
}
if(reader.get_vector("foreground-tm", tiles)) {
TileMap* tilemap = new TileMap();
tilemap->set(width, height, tiles, LAYER_FOREGROUNDTILES, false);
+
+ // fill additional space in foreground with tiles of ID 2035 (lightmap/black)
+ if (height < 19) tilemap->resize(width, 19, 2035);
+
add_object(tilemap);
}
{
for(std::list<TileMap*>::iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
-
for(size_t x=0; x < solids->get_width(); ++x) {
for(size_t y=0; y < solids->get_height(); ++y) {
const Tile* tile = solids->get_tile(x, y);
camera->get_translation() + Vector(1600, 1200));
}
-namespace {
- bool is_tilemap_solid(const TileMap* tm) { return tm->is_solid(); }
- bool is_tilemap_nonsolid(const TileMap* tm) { return !tm->is_solid(); }
-}
-
-void
-Sector::update_solid_tilemap_list()
-{
-
- // remove non-solid tilemaps from list
- solid_tilemaps.erase(std::remove_if(solid_tilemaps.begin(), solid_tilemaps.end(), is_tilemap_nonsolid), solid_tilemaps.end());
-
- // if tilemaps are to be added, create new list of solid tilemaps
- if (solid_tilemaps.size() != (unsigned int)std::count_if(tilemaps.begin(), tilemaps.end(), is_tilemap_solid)) {
- log_debug << "Found new solid tilemaps - this is eeevil! Re-creating list of solid tilemaps." << std::endl;
- solid_tilemaps.clear();
- for(std::list<TileMap*>::iterator i = tilemaps.begin(); i != tilemaps.end(); i++) {
- TileMap* tm = *i;
- if (tm->is_solid()) solid_tilemaps.push_back(tm);
- }
- }
-
-}
-
void
Sector::update(float elapsed_time)
{
player->check_bounds(camera);
- // update solid_tilemaps list
- update_solid_tilemap_list();
-
/* update objects */
for(GameObjects::iterator i = gameobjects.begin();
i != gameobjects.end(); ++i) {
}
TileMap* tilemap = dynamic_cast<TileMap*> (object);
- if(tilemap != NULL) {
- tilemaps.push_back(tilemap);
- if (tilemap->is_solid()) solid_tilemaps.push_back(tilemap);
+ if(tilemap != NULL && tilemap->is_solid()) {
+ solid_tilemaps.push_back(tilemap);
}
Camera* camera = dynamic_cast<Camera*> (object);
this->player = player;
}
+ UsesPhysic *physic_object = dynamic_cast<UsesPhysic *>(object);
+ if(physic_object)
+ {
+ physic_object->physic.set_gravity(gravity);
+ }
+
+
if(_current == this) {
try_expose(object);
}
if(portable != NULL) {
portables.erase(std::find(portables.begin(), portables.end(), portable));
}
- TileMap* tilemap = dynamic_cast<TileMap*> (object);
- if(tilemap != NULL) {
- tilemaps.erase(std::find(tilemaps.begin(), tilemaps.end(), tilemap));
- if (tilemap->is_solid()) solid_tilemaps.erase(std::find(solid_tilemaps.begin(), solid_tilemaps.end(), tilemap));
- }
Bullet* bullet = dynamic_cast<Bullet*> (object);
if(bullet != NULL) {
bullets.erase(std::find(bullets.begin(), bullets.end(), bullet));
{
for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
-
bool horizontally = ((rect.p2.x >= 0 + solids->get_x_offset()) && (rect.p1.x <= solids->get_width() * 32 + solids->get_x_offset()));
bool vertically = (rect.p1.y <= solids->get_height() * 32 + solids->get_y_offset());
if (horizontally && vertically) return true;
float width = 0;
for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
-
if ((solids->get_width() * 32 + solids->get_x_offset()) > width) width = (solids->get_width() * 32 + solids->get_x_offset());
}
return width;
float height = 0;
for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
-
if ((solids->get_height() * 32 + solids->get_y_offset()) > height) height = (solids->get_height() * 32 + solids->get_y_offset());
}
return height;
{
for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
-
solids->change_all(old_tile_id, new_tile_id);
}
}