// binary fraction...
static const float LOGICAL_FPS = 64.0;
-namespace {
- const char* consoleCommands[] = {
- "foo",
- "whereami",
- "camera",
- "grease",
- "invincible",
- "mortal",
- "shrink",
- "kill",
- "gotoend",
- "flip",
- "finish",
- "restart",
- "quit"
- };
-}
-
using namespace WorldMapNS;
GameSession* GameSession::current_ = 0;
game_pause = false;
fps_fps = 0;
- for (uint16_t i=0; i < sizeof(::consoleCommands)/sizeof(typeof(consoleCommands[0])); i++) {
- Console::instance->registerCommand(consoleCommands[i], this);
- }
-
statistics_backdrop.reset(new Surface("images/engine/menu/score-backdrop.png"));
restart_level(true);
}
}
-bool
-GameSession::consoleCommand(std::string command, std::vector<std::string>)
-{
- if (command == "foo") {
- log_info << "bar" << std::endl;
- return true;
- }
-
- if (currentsector == 0) return false;
- Player& tux = *currentsector->player;
-
- // Cheating words (the goal of this is really for debugging,
- // but could be used for some cheating, nothing wrong with that)
- if (command == "grease") {
- tux.physic.set_velocity_x(tux.physic.get_velocity_x()*3);
- return true;
- }
- if (command == "invincible") {
- // be invincle for the rest of the level
- tux.invincible_timer.start(10000);
- return true;
- }
- if (command == "mortal") {
- // give up invincibility
- tux.invincible_timer.stop();
- return true;
- }
- if (command == "shrink") {
- // remove powerups
- tux.kill(tux.SHRINK);
- return true;
- }
- if (command == "kill") {
- tux.kill(tux.KILL);
- return true;
- }
- if (command == "restart") {
- restart_level(true);
- return true;
- }
- if (command == "whereami") {
- log_info << "You are at x " << tux.get_pos().x << ", y " << tux.get_pos().y << std::endl;
- return true;
- }
- if (command == "gotoend") {
- // goes to the end of the level
- tux.move(Vector(
- (currentsector->solids->get_width()*32) - (SCREEN_WIDTH*2), 0));
- currentsector->camera->reset(
- Vector(tux.get_pos().x, tux.get_pos().y));
- return true;
- }
- if (command == "flip") {
- FlipLevelTransformer flip_transformer;
- flip_transformer.transform(GameSession::current()->get_current_level());
- return true;
- }
- if (command == "finish") {
- finish(true);
- return true;
- }
- if (command == "camera") {
- log_info << "Camera is at " << Sector::current()->camera->get_translation().x << "," << Sector::current()->camera->get_translation().y << std::endl;
- return true;
- }
- if (command == "quit") {
- main_loop->quit();
- return true;
- }
-
- return false;
-}
-
void
GameSession::check_end_conditions()
{
#include "worldmap.hpp"
#include "world.hpp"
#include "sector.hpp"
+#include "object/player.hpp"
+#include "object/tilemap.hpp"
+#include "main.hpp"
+#include "object/camera.hpp"
+#include "flip_level_transformer.hpp"
#include "squirrel_error.hpp"
#include "wrapper_util.hpp"
Sector::show_collrects = enable;
}
+void draw_solids_only(bool enable)
+{
+ Sector::draw_solids_only = enable;
+}
+
void save_state()
{
if(World::current() == NULL)
World::current()->save_state();
}
+// not added to header, function to only be used by others
+// in this file
+bool validate_sector_player()
+{
+ if (Sector::current() == 0)
+ {
+ log_info << "No current sector." << std::endl;
+ return false;
+ }
+
+ if (Sector::current()->player == 0)
+ {
+ log_info << "No player." << std::endl;
+ return false;
+ }
+ return true;
+}
+
+void grease()
+{
+ if (!validate_sector_player()) return;
+ ::Player* tux = Sector::current()->player; // Scripting::Player != ::Player
+ tux->physic.set_velocity_x(tux->physic.get_velocity_x()*3);
+}
+
+void invincible()
+{
+ if (!validate_sector_player()) return;
+ ::Player* tux = Sector::current()->player;
+ tux->invincible_timer.start(10000);
+}
+
+void mortal()
+{
+ if (!validate_sector_player()) return;
+ ::Player* tux = Sector::current()->player;
+ tux->invincible_timer.stop();
+}
+
+void shrink()
+{
+ if (!validate_sector_player()) return;
+ ::Player* tux = Sector::current()->player;
+ tux->kill(tux->SHRINK);
+}
+
+void kill()
+{
+ if (!validate_sector_player()) return;
+ ::Player* tux = Sector::current()->player;
+ tux->kill(tux->KILL);
+}
+
+void restart()
+{
+ if (GameSession::current() == 0)
+ {
+ log_info << "No game session" << std::endl;
+ return;
+ }
+ GameSession::current()->restart_level();
+}
+
+void whereami()
+{
+ if (!validate_sector_player()) return;
+ ::Player* tux = Sector::current()->player;
+ log_info << "You are at x " << tux->get_pos().x << ", y " << tux->get_pos().y << std::endl;
+}
+
+void gotoend()
+{
+ if (!validate_sector_player()) return;
+ ::Player* tux = Sector::current()->player;
+ tux->move(Vector(
+ (Sector::current()->solids->get_width()*32) - (SCREEN_WIDTH*2), 0));
+ Sector::current()->camera->reset(
+ Vector(tux->get_pos().x, tux->get_pos().y));
+}
+
+void flip()
+{
+ if (GameSession::current() == 0)
+ {
+ log_info << "No game session" << std::endl;
+ return;
+ }
+ if (GameSession::current()->get_current_level() == 0)
+ {
+ log_info << "No current level" << std::endl;
+ return;
+ }
+ FlipLevelTransformer flip_transformer;
+ flip_transformer.transform(GameSession::current()->get_current_level());
+}
+
+void finish()
+{
+ if (GameSession::current() == 0)
+ {
+ log_info << "No game session" << std::endl;
+ return;
+ }
+ GameSession::current()->finish(true);
+}
+
+void camera()
+{
+ if (!validate_sector_player()) return;
+ log_info << "Camera is at " << Sector::current()->camera->get_translation().x << "," << Sector::current()->camera->get_translation().y << std::endl;
+}
+
+void quit()
+{
+ main_loop->quit();
+}
+
}
}
+static int draw_solids_only_wrapper(HSQUIRRELVM vm)
+{
+ SQBool arg0;
+ if(SQ_FAILED(sq_getbool(vm, 2, &arg0))) {
+ sq_throwerror(vm, _SC("Argument 1 not a bool"));
+ return SQ_ERROR;
+ }
+
+ try {
+ Scripting::draw_solids_only(arg0);
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'draw_solids_only'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static int grease_wrapper(HSQUIRRELVM vm)
+{
+ (void) vm;
+
+ try {
+ Scripting::grease();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'grease'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static int invincible_wrapper(HSQUIRRELVM vm)
+{
+ (void) vm;
+
+ try {
+ Scripting::invincible();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'invincible'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static int mortal_wrapper(HSQUIRRELVM vm)
+{
+ (void) vm;
+
+ try {
+ Scripting::mortal();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'mortal'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static int shrink_wrapper(HSQUIRRELVM vm)
+{
+ (void) vm;
+
+ try {
+ Scripting::shrink();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'shrink'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static int kill_wrapper(HSQUIRRELVM vm)
+{
+ (void) vm;
+
+ try {
+ Scripting::kill();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'kill'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static int restart_wrapper(HSQUIRRELVM vm)
+{
+ (void) vm;
+
+ try {
+ Scripting::restart();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'restart'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static int whereami_wrapper(HSQUIRRELVM vm)
+{
+ (void) vm;
+
+ try {
+ Scripting::whereami();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'whereami'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static int gotoend_wrapper(HSQUIRRELVM vm)
+{
+ (void) vm;
+
+ try {
+ Scripting::gotoend();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'gotoend'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static int flip_wrapper(HSQUIRRELVM vm)
+{
+ (void) vm;
+
+ try {
+ Scripting::flip();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'flip'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static int finish_wrapper(HSQUIRRELVM vm)
+{
+ (void) vm;
+
+ try {
+ Scripting::finish();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'finish'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static int camera_wrapper(HSQUIRRELVM vm)
+{
+ (void) vm;
+
+ try {
+ Scripting::camera();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'camera'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static int quit_wrapper(HSQUIRRELVM vm)
+{
+ (void) vm;
+
+ try {
+ Scripting::quit();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'quit'"));
+ return SQ_ERROR;
+ }
+
+}
+
} // end of namespace Wrapper
void create_squirrel_instance(HSQUIRRELVM v, Scripting::DisplayEffect* object, bool setup_releasehook)
throw SquirrelError(v, "Couldn't register function 'debug_collrects'");
}
+ sq_pushstring(v, "draw_solids_only", -1);
+ sq_newclosure(v, &draw_solids_only_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'draw_solids_only'");
+ }
+
+ sq_pushstring(v, "grease", -1);
+ sq_newclosure(v, &grease_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'grease'");
+ }
+
+ sq_pushstring(v, "invincible", -1);
+ sq_newclosure(v, &invincible_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'invincible'");
+ }
+
+ sq_pushstring(v, "mortal", -1);
+ sq_newclosure(v, &mortal_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'mortal'");
+ }
+
+ sq_pushstring(v, "shrink", -1);
+ sq_newclosure(v, &shrink_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'shrink'");
+ }
+
+ sq_pushstring(v, "kill", -1);
+ sq_newclosure(v, &kill_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'kill'");
+ }
+
+ sq_pushstring(v, "restart", -1);
+ sq_newclosure(v, &restart_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'restart'");
+ }
+
+ sq_pushstring(v, "whereami", -1);
+ sq_newclosure(v, &whereami_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'whereami'");
+ }
+
+ sq_pushstring(v, "gotoend", -1);
+ sq_newclosure(v, &gotoend_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'gotoend'");
+ }
+
+ sq_pushstring(v, "flip", -1);
+ sq_newclosure(v, &flip_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'flip'");
+ }
+
+ sq_pushstring(v, "finish", -1);
+ sq_newclosure(v, &finish_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'finish'");
+ }
+
+ sq_pushstring(v, "camera", -1);
+ sq_newclosure(v, &camera_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'camera'");
+ }
+
+ sq_pushstring(v, "quit", -1);
+ sq_newclosure(v, &quit_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'quit'");
+ }
+
// Register class DisplayEffect
sq_pushstring(v, "DisplayEffect", -1);
if(sq_newclass(v, SQFalse) < 0) {