From: Marek Moeckel Date: Sun, 25 Sep 2005 23:55:41 +0000 (+0000) Subject: lots of cool scripting stuff X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=071c31e7fcf8bfbd00ec8d7d19313d7f6e433885;p=supertux.git lots of cool scripting stuff SVN-Revision: 2786 --- diff --git a/data/levels/world2/default.nut b/data/levels/world2/default.nut new file mode 100644 index 000000000..65ddc2cb6 --- /dev/null +++ b/data/levels/world2/default.nut @@ -0,0 +1,20 @@ + +function get_gold_key() +{ + add_key(KEY_GOLD); + end_level(); +} + +function level2_init() +{ + Tux.deactivate(); + DisplayEffect.sixteen_to_nine(); + Text.set_text(translate("---Insert Cutscene Here---")); + Tux.walk(100); + Text.fade_in(2); + wait(4); + Text.fade_out(1); + wait(1); + DisplayEffect.four_to_three(); + Tux.activate(); +} diff --git a/data/levels/world2/level2.stl b/data/levels/world2/level2.stl index 6f920ae10..3797a4b55 100644 --- a/data/levels/world2/level2.stl +++ b/data/levels/world2/level2.stl @@ -189,49 +189,30 @@ (image "forest1.jpg") (speed 1.000000) ) - (secretarea (x 673.0) + (init-script "level2_init();") + (secretarea (x 673.0) (y 1090.0) (width 24.0) (height 19.0) (message "Drink me")) (powerup (x 3168) (y 416) (sprite (_ "eat-me")) - (script " -DisplayEffect.fade_out(1); -wait(1); -Level.flip_vertically(); -DisplayEffect.fade_in(1); -") + (script "levelflip();") ) (bonusblock (x 672) (y 1056) (contents "custom") (powerup (sprite "red-potion") - (script " -DisplayEffect.fade_out(1); -wait(1); -Level.flip_vertically(); -DisplayEffect.fade_in(1); -") + (script "levelflip();") ) ) (powerup (x 8608) (y 1024) (sprite "red-potion") - (script " -DisplayEffect.fade_out(1); -wait(1); -Level.flip_vertically(); -DisplayEffect.fade_in(1); -") + (script "levelflip();") ) (powerup (x 9952) (y 416) (sprite "red-potion") - (script " -DisplayEffect.fade_out(1); -wait(1); -Level.flip_vertically(); -DisplayEffect.fade_in(1); -") + (script "levelflip();") ) (powerup (x 8000) (y 352) (sprite "key-gold") diff --git a/data/script/default.nut b/data/script/default.nut index 5034bf3b1..2fded5ba6 100644 --- a/data/script/default.nut +++ b/data/script/default.nut @@ -1,15 +1,18 @@ -function get_gold_key() -{ - add_key(KEY_GOLD); - end_level(); -} - function end_level() { Sound.play_music("leveldone"); + Tux.deactivate(); wait(6); DisplayEffect.fade_out(2); wait(2); Level.finish(); } + +function levelflip() +{ + DisplayEffect.fade_out(1); + wait(1); + Level.flip_vertically(); + DisplayEffect.fade_in(1); +} diff --git a/src/object/display_effect.cpp b/src/object/display_effect.cpp index 7a254c5dc..3c3bc4c5d 100644 --- a/src/object/display_effect.cpp +++ b/src/object/display_effect.cpp @@ -8,6 +8,7 @@ DisplayEffect::DisplayEffect() : type(NO_FADE), fadetime(0), fading(0), black(false) { + cutscene_borders = false; } DisplayEffect::~DisplayEffect() @@ -41,32 +42,39 @@ DisplayEffect::update(float elapsed_time) void DisplayEffect::draw(DrawingContext& context) { - if(!black && type == NO_FADE) - return; - context.push_transform(); context.set_translation(Vector(0, 0)); - uint8_t alpha; - if(black) { - alpha = 255; - } else { - switch(type) { - case FADE_IN: - alpha = static_cast - (fading * 255.0 / fadetime); - break; - case FADE_OUT: - alpha = static_cast - ((fadetime-fading) * 255.0 / fadetime); - break; - default: - alpha = 0; - assert(false); - } + if(black || type != NO_FADE) { + uint8_t alpha; + if(black) { + alpha = 255; + } else { + switch(type) { + case FADE_IN: + alpha = static_cast + (fading * 255.0 / fadetime); + break; + case FADE_OUT: + alpha = static_cast + ((fadetime-fading) * 255.0 / fadetime); + break; + default: + alpha = 0; + assert(false); + } + } + context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT), + Color(0, 0, 0, alpha), LAYER_GUI-10); } - context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT), - Color(0, 0, 0, alpha), LAYER_GUI-10); + + if (cutscene_borders) { + context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, 75), + Color(0, 0, 0, 255), LAYER_GUI-10); + context.draw_filled_rect(Vector(0, SCREEN_HEIGHT - 75), Vector(SCREEN_WIDTH, 75), + Color(0, 0, 0, 255), LAYER_GUI-10); + } + context.pop_transform(); } @@ -100,3 +108,14 @@ DisplayEffect::is_black() return black; } +void +DisplayEffect::sixteen_to_nine() +{ + cutscene_borders = true; +} + +void +DisplayEffect::four_to_three() +{ + cutscene_borders = false; +} diff --git a/src/object/display_effect.hpp b/src/object/display_effect.hpp index 612386a4b..f35dd528e 100644 --- a/src/object/display_effect.hpp +++ b/src/object/display_effect.hpp @@ -17,6 +17,8 @@ public: void fade_in(float fadetime); void set_black(bool enabled); bool is_black(); + void sixteen_to_nine(); + void four_to_three(); private: enum FadeType { @@ -26,6 +28,7 @@ private: float fadetime; float fading; bool black; + bool cutscene_borders; }; #endif diff --git a/src/object/player.cpp b/src/object/player.cpp index 5892164d7..4242a168c 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -132,6 +132,7 @@ Player::init() falling_from_flap = false; enable_hover = false; butt_jump = false; + deactivated = false; flapping_velocity = 0; @@ -177,7 +178,7 @@ Player::update(float elapsed_time) } } - if(!dying) + if(!dying && !deactivated) handle_input(); movement = physic.get_movement(elapsed_time); @@ -810,7 +811,7 @@ Player::make_invincible() void Player::kill(HurtMode mode) { - if(dying) + if(dying || deactivated) return; if(mode != KILL && @@ -922,3 +923,23 @@ Player::bounce(BadGuy& ) physic.set_velocity_y(300); } +//Scripting Functions Below + +void +Player::deactivate() +{ + deactivated = true; + physic.set_velocity_x(0); + physic.set_velocity_y(0); +} + +void +Player::activate() +{ + deactivated = false; +} + +void Player::walk(float speed) +{ + physic.set_velocity_x(WALK_SPEED); +} diff --git a/src/object/player.hpp b/src/object/player.hpp index ddf02b578..56f8269d2 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -168,12 +168,17 @@ public: private: void handle_input(); bool on_ground(); + bool deactivated; void init(); void handle_horizontal_input(); void handle_vertical_input(); + void activate(); + void deactivate(); + void walk(float speed); + Portable* grabbed_object; Sprite* smalltux_gameover; diff --git a/src/scripting/display_effect.hpp b/src/scripting/display_effect.hpp index 74fad9cf9..01d448823 100644 --- a/src/scripting/display_effect.hpp +++ b/src/scripting/display_effect.hpp @@ -20,6 +20,10 @@ public: virtual void set_black(bool enabled) = 0; /// check if display is set to black virtual bool is_black() = 0; + /// set black borders for cutscenes + virtual void sixteen_to_nine() = 0; + /// deactivate borders + virtual void four_to_three() = 0; // fade display until just a small visible circle is left // (like what happens in some cartoons at the end) diff --git a/src/scripting/player.hpp b/src/scripting/player.hpp index 58f10419f..fee8f69ee 100644 --- a/src/scripting/player.hpp +++ b/src/scripting/player.hpp @@ -15,14 +15,10 @@ public: #if 0 /** * Set tux bonus. - * This can be "grow", "fireflow" or "iceflower" at the moment + * This can be "grow", "fireflower" or "iceflower" at the moment */ virtual void set_bonus(const std::string& bonus) = 0; /** - * Make tux invicible for a short amount of time - */ - virtual void make_invincible() = 0; - /** * Give tux another life */ virtual void add_life() = 0; @@ -31,6 +27,22 @@ public: */ virtual void add_coins(int count) = 0; #endif + /** + * Make tux invicible for a short amount of time + */ + virtual void make_invincible() = 0; + /** + * Deactivate user input for Tux + */ + virtual void deactivate() = 0; + /** + * Give control back to user + */ + virtual void activate() = 0; + /** + * Make Tux walk + */ + virtual void walk(float speed) = 0; }; } diff --git a/src/scripting/script_interpreter.cpp b/src/scripting/script_interpreter.cpp index 484465682..af17653c8 100644 --- a/src/scripting/script_interpreter.cpp +++ b/src/scripting/script_interpreter.cpp @@ -23,6 +23,7 @@ #include "object/text_object.hpp" #include "object/scripted_object.hpp" #include "object/display_effect.hpp" +#include "object/player.hpp" #include "scripting/sound.hpp" #include "scripting/scripted_object.hpp" #include "scripting/display_effect.hpp" @@ -89,6 +90,7 @@ ScriptInterpreter::register_sector(Sector* sector) expose_object(scripted_object, scripted_object->get_name()); } + expose_object(static_cast (sector->player), "Tux"); TextObject* text_object = new TextObject(); sector->add_object(text_object); Scripting::Text* text = static_cast (text_object); diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index 8eba394b8..56d56b2c9 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -72,6 +72,26 @@ static int DisplayEffect_is_black_wrapper(HSQUIRRELVM v) return 1; } +static int DisplayEffect_sixteen_to_nine_wrapper(HSQUIRRELVM v) +{ + Scripting::DisplayEffect* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + + _this->sixteen_to_nine(); + + return 0; +} + +static int DisplayEffect_four_to_three_wrapper(HSQUIRRELVM v) +{ + Scripting::DisplayEffect* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + + _this->four_to_three(); + + return 0; +} + static int Camera_release_hook(SQUserPointer ptr, int ) { Scripting::Camera* _this = reinterpret_cast (ptr); @@ -417,6 +437,48 @@ static int Player_release_hook(SQUserPointer ptr, int ) return 0; } +static int Player_make_invincible_wrapper(HSQUIRRELVM v) +{ + Scripting::Player* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + + _this->make_invincible(); + + return 0; +} + +static int Player_deactivate_wrapper(HSQUIRRELVM v) +{ + Scripting::Player* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + + _this->deactivate(); + + return 0; +} + +static int Player_activate_wrapper(HSQUIRRELVM v) +{ + Scripting::Player* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + + _this->activate(); + + return 0; +} + +static int Player_walk_wrapper(HSQUIRRELVM v) +{ + Scripting::Player* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + float arg0; + sq_getfloat(v, 2, &arg0); + + _this->walk(arg0); + + return 0; +} + static int display_text_file_wrapper(HSQUIRRELVM v) { const char* arg0; @@ -777,6 +839,22 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, msg.str()); } + sq_pushstring(v, "sixteen_to_nine", -1); + sq_newclosure(v, &DisplayEffect_sixteen_to_nine_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'sixteen_to_nine'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "four_to_three", -1); + sq_newclosure(v, &DisplayEffect_four_to_three_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'four_to_three'"; + throw SquirrelError(v, msg.str()); + } + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register class'DisplayEffect'"; @@ -1055,6 +1133,38 @@ void register_supertux_wrapper(HSQUIRRELVM v) msg << "Couldn't create new class 'Player'"; throw SquirrelError(v, msg.str()); } + sq_pushstring(v, "make_invincible", -1); + sq_newclosure(v, &Player_make_invincible_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'make_invincible'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "deactivate", -1); + sq_newclosure(v, &Player_deactivate_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'deactivate'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "activate", -1); + sq_newclosure(v, &Player_activate_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'activate'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "walk", -1); + sq_newclosure(v, &Player_walk_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'walk'"; + throw SquirrelError(v, msg.str()); + } + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register class'Player'";