X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fsector.cpp;h=657996f33573f3074a494a53155dfdf785a84572;hb=8d1566374788e2c612b35d6b95463398a555b54a;hp=1d14695a6fbe874b5a84218e0956d0ace439dca7;hpb=4a54087f52d6a8a2e5b4c498e772685bb0885991;p=supertux.git diff --git a/src/sector.cpp b/src/sector.cpp index 1d14695a6..657996f33 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "sector.h" @@ -56,6 +57,7 @@ #include "badguy/spike.h" #include "trigger/sequence_trigger.h" #include "player_status.h" +#include "scripting/script_interpreter.h" //#define USE_GRID @@ -63,7 +65,7 @@ Sector* Sector::_current = 0; Sector::Sector() : gravity(10), player(0), solids(0), camera(0), - currentmusic(LEVEL_MUSIC) + interpreter(0), currentmusic(LEVEL_MUSIC) { song_title = "Mortimers_chipdisko.mod"; player = new Player(&player_status); @@ -147,6 +149,8 @@ Sector::parse(const lisp::Lisp& sector) spawnpoint_lisp->get("x", sp->pos.x); spawnpoint_lisp->get("y", sp->pos.y); spawnpoints.push_back(sp); + } else if(token == "init-script") { + iter.value()->get(init_script); } else { GameObject* object = parse_object(token, *(iter.lisp())); if(object) { @@ -411,6 +415,25 @@ Sector::activate(const std::string& spawnpoint) } else { activate(sp->pos); } + + // Run init script + if(init_script != "") { + try { + // TODO we should keep the interpreter across sessions (or some variables) + // so that you can store information across levels/sectors... + delete interpreter; + interpreter = 0; + interpreter = new ScriptInterpreter(); + std::string sourcename = std::string("Sector(") + name + ") - init"; + std::istringstream in(init_script); + printf("Load script.\n"); + interpreter->load_script(in, sourcename); + printf("run script.\n"); + interpreter->run_script(); + } catch(std::exception& e) { + std::cerr << "Couldn't execute init script: " << e.what() << "\n"; + } + } } void @@ -598,11 +621,15 @@ Sector::collision_tilemap(MovingObject* object, int depth) const Tile* tile = solids->get_tile(x, y); if(!tile) continue; + // skip non-solid tiles if(!(tile->getAttributes() & Tile::SOLID)) continue; - if(tile->getAttributes() & Tile::UNISOLID - && (object->movement.y < 0 || dest.p2.y > y*32)) - continue; + // only handle unisolid when the player is falling down and when he was + // above the tile before + if(tile->getAttributes() & Tile::UNISOLID) { + if(object->movement.y < 0 || object->get_bbox().p2.y > y*32) + continue; + } if(tile->getAttributes() & Tile::SLOPE) { // slope tile AATriangle triangle;