#include <stdexcept>
#include <iostream>
#include <fstream>
+#include <sstream>
#include <stdexcept>
#include "sector.h"
#include "badguy/spike.h"
#include "trigger/sequence_trigger.h"
#include "player_status.h"
+#include "scripting/script_interpreter.h"
//#define USE_GRID
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);
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) {
} 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
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;