X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsupertux%2Fsector.cpp;h=519a2f4c8f2c56d505d97009ff66e7d4e44954f9;hb=04270f0886aa08cb8fee7dba58d41975ddb1cb72;hp=91b469d975f5ecca47912a1070f1d0cd5c1fce60;hpb=b6a563dd2856e3d45bb89b0fe91e8702fd71041c;p=supertux.git diff --git a/src/supertux/sector.cpp b/src/supertux/sector.cpp index 91b469d97..519a2f4c8 100644 --- a/src/supertux/sector.cpp +++ b/src/supertux/sector.cpp @@ -45,7 +45,8 @@ #include "object/snow_particle_system.hpp" #include "object/text_object.hpp" #include "object/tilemap.hpp" -#include "physfs/ifile_stream.hpp" +#include "physfs/ifile_streambuf.hpp" +#include "scripting/scripting.hpp" #include "scripting/squirrel_util.hpp" #include "supertux/collision.hpp" #include "supertux/constants.hpp" @@ -54,6 +55,7 @@ #include "supertux/level.hpp" #include "supertux/object_factory.hpp" #include "supertux/player_status.hpp" +#include "supertux/savegame.hpp" #include "supertux/spawn_point.hpp" #include "supertux/tile.hpp" #include "trigger/sequence_trigger.hpp" @@ -65,7 +67,7 @@ bool Sector::show_collrects = false; bool Sector::draw_solids_only = false; Sector::Sector(Level* parent) : - level(parent), + level(parent), name(), bullets(), init_script(), @@ -73,23 +75,23 @@ Sector::Sector(Level* parent) : currentmusic(LEVEL_MUSIC), sector_table(), scripts(), - ambient_light( 1.0f, 1.0f, 1.0f, 1.0f ), + ambient_light( 1.0f, 1.0f, 1.0f, 1.0f ), gameobjects(), moving_objects(), spawnpoints(), portables(), music(), - gravity(10.0), - player(0), + gravity(10.0), + player(0), solid_tilemaps(), - camera(0), + camera(0), effect(0) { - add_object(new Player(GameSession::current()->get_player_status(), "Tux")); + add_object(new Player(GameSession::current()->get_savegame().get_player_status(), "Tux")); add_object(new DisplayEffect("Effect")); add_object(new TextObject("Text")); - sound_manager->preload("sounds/shoot.wav"); + SoundManager::current()->preload("sounds/shoot.wav"); // create a new squirrel table for the sector using namespace scripting; @@ -144,37 +146,37 @@ Sector::get_level() } GameObject* -Sector::parse_object(const std::string& name, const Reader& reader) +Sector::parse_object(const std::string& name_, const Reader& reader) { - if(name == "camera") { - Camera* camera = new Camera(this, "Camera"); - camera->parse(reader); - return camera; - } else if(name == "particles-snow") { + if(name_ == "camera") { + Camera* camera_ = new Camera(this, "Camera"); + camera_->parse(reader); + return camera_; + } else if(name_ == "particles-snow") { SnowParticleSystem* partsys = new SnowParticleSystem(); partsys->parse(reader); return partsys; - } else if(name == "particles-rain") { + } else if(name_ == "particles-rain") { RainParticleSystem* partsys = new RainParticleSystem(); partsys->parse(reader); return partsys; - } else if(name == "particles-comets") { + } else if(name_ == "particles-comets") { CometParticleSystem* partsys = new CometParticleSystem(); partsys->parse(reader); return partsys; - } else if(name == "particles-ghosts") { + } else if(name_ == "particles-ghosts") { GhostParticleSystem* partsys = new GhostParticleSystem(); partsys->parse(reader); return partsys; - } else if(name == "particles-clouds") { + } else if(name_ == "particles-clouds") { CloudParticleSystem* partsys = new CloudParticleSystem(); partsys->parse(reader); return partsys; - } else if(name == "money") { // for compatibility with old maps + } else if(name_ == "money") { // for compatibility with old maps return new Jumpy(reader); } else { try { - return ObjectFactory::instance().create(name, reader); + return ObjectFactory::instance().create(name_, reader); } catch(std::exception& e) { log_warning << e.what() << "" << std::endl; return 0; @@ -229,7 +231,7 @@ Sector::parse(const Reader& sector) update_game_objects(); - if(solid_tilemaps.size() < 1) log_warning << "sector '" << name << "' does not contain a solid tile layer." << std::endl; + if(solid_tilemaps.size() < 1) { log_warning << "sector '" << name << "' does not contain a solid tile layer." << std::endl; } fix_old_tiles(); if(!camera) { @@ -389,12 +391,12 @@ Sector::parse_old_format(const Reader& reader) } // add a camera - Camera* camera = new Camera(this, "Camera"); - add_object(camera); + Camera* camera_ = new Camera(this, "Camera"); + add_object(camera_); update_game_objects(); - if(solid_tilemaps.size() < 1) log_warning << "sector '" << name << "' does not contain a solid tile layer." << std::endl; + if(solid_tilemaps.size() < 1) { log_warning << "sector '" << name << "' does not contain a solid tile layer." << std::endl; } fix_old_tiles(); update_game_objects(); @@ -421,7 +423,14 @@ Sector::fix_old_tiles() add_object(new BonusBlock(pos, tile->getData())); solids->change(x, y, 0); } else if(tile->getAttributes() & Tile::BRICK) { - add_object(new Brick(pos, tile->getData())); + if( ( id == 78 ) || ( id == 105 ) ){ + add_object( new Brick(pos, tile->getData(), "images/objects/bonus_block/brickIce.sprite") ); + } else if( ( id == 77 ) || ( id == 104 ) ){ + add_object( new Brick(pos, tile->getData(), "images/objects/bonus_block/brick.sprite") ); + } else { + log_warning << "attribute 'brick #t' is not supported for tile-id " << id << std::endl; + add_object( new Brick(pos, tile->getData(), "images/objects/bonus_block/brick.sprite") ); + } solids->change(x, y, 0); } else if(tile->getAttributes() & Tile::GOAL) { std::string sequence = tile->getData() == 0 ? "endsequence" : "stoptux"; @@ -600,7 +609,7 @@ Sector::activate(const Vector& player_pos) camera->update(1); player->move(player->get_pos()+(Vector(32, 0))); camera->update(1); - + update_game_objects(); //Run default.nut just before init script @@ -608,7 +617,8 @@ Sector::activate(const Vector& player_pos) std::string basedir = FileSystem::dirname(get_level()->filename); if(PHYSFS_exists((basedir + "/info").c_str())) { try { - IFileStream in(basedir + "/default.nut"); + IFileStreambuf ins(basedir + "/default.nut"); + std::istream in(&ins); run_script(in, "default.nut"); } catch(std::exception& ) { // doesn't exist or erroneous; do nothing @@ -742,31 +752,31 @@ Sector::before_object_add(GameObject* object) solid_tilemaps.push_back(tilemap); } - Camera* camera = dynamic_cast (object); - if(camera != NULL) { + Camera* camera_ = dynamic_cast (object); + if(camera_ != NULL) { if(this->camera != 0) { log_warning << "Multiple cameras added. Ignoring" << std::endl; return false; } - this->camera = camera; + this->camera = camera_; } - Player* player = dynamic_cast (object); - if(player != NULL) { + Player* player_ = dynamic_cast (object); + if(player_ != NULL) { if(this->player != 0) { log_warning << "Multiple players added. Ignoring" << std::endl; return false; } - this->player = player; + this->player = player_; } - DisplayEffect* effect = dynamic_cast (object); - if(effect != NULL) { + DisplayEffect* effect_ = dynamic_cast (object); + if(effect_ != NULL) { if(this->effect != 0) { log_warning << "Multiple DisplayEffects added. Ignoring" << std::endl; return false; } - this->effect = effect; + this->effect = effect_; } if(_current == this) { @@ -1005,7 +1015,7 @@ Sector::collision_tilemap(collision::Constraints* constraints, if(tile->is_slope ()) { // slope tile AATriangle triangle; int slope_data = tile->getData(); - if (solids->get_drawing_effect() == VERTICAL_FLIP) + if (solids->get_drawing_effect() & VERTICAL_FLIP) slope_data = AATriangle::vertical_flip(slope_data); triangle = AATriangle(tile_bbox, slope_data); @@ -1459,7 +1469,7 @@ Sector::add_bullet(const Vector& pos, const PlayerStatus* player_status, float x new_bullet = new Bullet(pos, xm, dir, player_status->bonus); add_object(new_bullet); - sound_manager->play("sounds/shoot.wav"); + SoundManager::current()->play("sounds/shoot.wav"); return true; } @@ -1477,16 +1487,16 @@ Sector::play_music(MusicType type) currentmusic = type; switch(currentmusic) { case LEVEL_MUSIC: - sound_manager->play_music(music); + SoundManager::current()->play_music(music); break; case HERRING_MUSIC: - sound_manager->play_music("music/invincible.ogg"); + SoundManager::current()->play_music("music/invincible.ogg"); break; case HERRING_WARNING_MUSIC: - sound_manager->stop_music(TUX_INVINCIBLE_TIME_WARNING); + SoundManager::current()->stop_music(TUX_INVINCIBLE_TIME_WARNING); break; default: - sound_manager->play_music(""); + SoundManager::current()->play_music(""); break; } } @@ -1588,10 +1598,10 @@ Sector::get_ambient_blue() } void -Sector::set_gravity(float gravity) +Sector::set_gravity(float gravity_) { log_warning << "Changing a Sector's gravitational constant might have unforeseen side-effects" << std::endl; - this->gravity = gravity; + this->gravity = gravity_; } float