}
Player::Player(PlayerStatus* _player_status)
- : player_status(_player_status), grabbed_object(NULL)
+ : player_status(_player_status), grabbed_object(NULL), ghost_mode(false)
{
controller = main_controller;
smalltux_gameover = sprite_manager->create("images/creatures/tux_small/smalltux-gameover.sprite");
void
Player::handle_input()
{
+ if (ghost_mode) {
+ handle_input_ghost();
+ return;
+ }
+
if(!controller->hold(Controller::ACTION) && grabbed_object) {
// move the grabbed object a bit away from tux
Vector pos = get_pos() +
}
void
+Player::handle_input_ghost()
+{
+ float vx = 0;
+ float vy = 0;
+ if (controller->hold(Controller::LEFT)) vx -= MAX_RUN_XM;
+ if (controller->hold(Controller::RIGHT)) vx += MAX_RUN_XM;
+ if ((controller->hold(Controller::UP)) || (controller->hold(Controller::JUMP))) vy += MAX_RUN_XM;
+ if (controller->hold(Controller::DOWN)) vy -= MAX_RUN_XM;
+ if (controller->hold(Controller::ACTION)) set_ghost_mode(false);
+ physic.set_velocity(vx, vy);
+ physic.set_acceleration(0, 0);
+}
+
+void
Player::add_coins(int count)
{
player_status->add_coins(count);
physic.set_velocity_x(speed);
}
+void
+Player::set_ghost_mode(bool enable)
+{
+ if (ghost_mode == enable) return;
+ if (enable) {
+ ghost_mode = true;
+ set_group(COLGROUP_DISABLED);
+ physic.enable_gravity(false);
+ log_debug << "You feel lightheaded. Use movement controls to float around, press ACTION to scare badguys." << std::endl;
+ } else {
+ ghost_mode = false;
+ set_group(COLGROUP_MOVING);
+ physic.enable_gravity(true);
+ log_debug << "You feel solid again." << std::endl;
+ }
+}
+
}
+static SQInteger Player_set_ghost_mode_wrapper(HSQUIRRELVM vm)
+{
+ Scripting::Player* _this;
+ if(SQ_FAILED(sq_getinstanceup(vm, 1, reinterpret_cast<SQUserPointer*> (&_this), 0))) {
+ sq_throwerror(vm, _SC("'set_ghost_mode' called without instance"));
+ return SQ_ERROR;
+ }
+ SQBool arg0;
+ if(SQ_FAILED(sq_getbool(vm, 2, &arg0))) {
+ sq_throwerror(vm, _SC("Argument 1 not a bool"));
+ return SQ_ERROR;
+ }
+
+ try {
+ _this->set_ghost_mode(arg0 == SQTrue);
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'set_ghost_mode'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static SQInteger Player_get_ghost_mode_wrapper(HSQUIRRELVM vm)
+{
+ Scripting::Player* _this;
+ if(SQ_FAILED(sq_getinstanceup(vm, 1, reinterpret_cast<SQUserPointer*> (&_this), 0))) {
+ sq_throwerror(vm, _SC("'get_ghost_mode' called without instance"));
+ return SQ_ERROR;
+ }
+
+ try {
+ bool return_value = _this->get_ghost_mode();
+
+ sq_pushbool(vm, return_value);
+ return 1;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'get_ghost_mode'"));
+ return SQ_ERROR;
+ }
+
+}
+
static SQInteger FloatingImage_release_hook(SQUserPointer ptr, SQInteger )
{
Scripting::FloatingImage* _this = reinterpret_cast<Scripting::FloatingImage*> (ptr);
}
+static SQInteger ghost_wrapper(HSQUIRRELVM vm)
+{
+ (void) vm;
+
+ try {
+ Scripting::ghost();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'ghost'"));
+ return SQ_ERROR;
+ }
+
+}
+
static SQInteger mortal_wrapper(HSQUIRRELVM vm)
{
(void) vm;
throw SquirrelError(v, "Couldn't register function 'invincible'");
}
+ sq_pushstring(v, "ghost", -1);
+ sq_newclosure(v, &ghost_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'ghost'");
+ }
+
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 'kill'");
}
+ sq_pushstring(v, "set_ghost_mode", -1);
+ sq_newclosure(v, &Player_set_ghost_mode_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'set_ghost_mode'");
+ }
+
+ sq_pushstring(v, "get_ghost_mode", -1);
+ sq_newclosure(v, &Player_get_ghost_mode_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'get_ghost_mode'");
+ }
+
if(SQ_FAILED(sq_createslot(v, -3))) {
throw SquirrelError(v, "Couldn't register class 'Player'");
}