From: Christoph Sommer Date: Sat, 16 Dec 2006 14:47:31 +0000 (+0000) Subject: Merged floating image patch by DirtY iCE X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=128e58285d549dd6214a9340590387c6b353589b;p=supertux.git Merged floating image patch by DirtY iCE SVN-Revision: 4463 --- diff --git a/data/levels/world1/intro.nut b/data/levels/world1/intro.nut index b38be37be..45cc16b5c 100644 --- a/data/levels/world1/intro.nut +++ b/data/levels/world1/intro.nut @@ -14,20 +14,24 @@ function intro() Effect.fade_in(2); Camera.scroll_to(0, 945, 15); wait(3); - Text.set_text("Somewhere at the shores\nof Antarctica..."); + Text.set_text(translate ("Somewhere at the shores\nof Antarctica...")); Text.fade_in(2); wait(3); Text.fade_out(2); wait(10); SUPERTUX.set_velocity(50,0); Camera.scroll_to(3100, 945, 18); - wait(10); + wait(6); logo.set_anchor_point(ANCHOR_TOP); - logo.set_pos(0, 90); + logo.set_pos(0, -120); logo.set_visible(true); - wait(5); - logo.set_visible(false); + logo.fade_in(2); + logo_in(); wait(6); + logo.fade_out(2); + wait(2); + logo.set_visible(false); + wait(5.3); //begin conversation and Tux rap SUPERTUX.set_velocity(0,0); @@ -101,3 +105,11 @@ function tux_upset() wait(0.3); } +function logo_in() +{ + local i; + for(local i = -120; i <= 90; i+=2) { + logo.set_pos(0, i); + wait(0.01); + } +} diff --git a/src/object/floating_image.cpp b/src/object/floating_image.cpp index 579878471..00782af1f 100644 --- a/src/object/floating_image.cpp +++ b/src/object/floating_image.cpp @@ -29,8 +29,9 @@ #include "lisp/lisp.hpp" #include "floating_image.hpp" + FloatingImage::FloatingImage(const std::string& spritefile) - : layer(LAYER_FOREGROUND1 + 1), visible(false), anchor(ANCHOR_MIDDLE) + : layer(LAYER_FOREGROUND1 + 1), visible(false), anchor(ANCHOR_MIDDLE), fading(0), fadetime(0) { sprite.reset(sprite_manager->create(spritefile)); } @@ -42,7 +43,21 @@ FloatingImage::~FloatingImage() void FloatingImage::update(float elapsed_time) { - (void) elapsed_time; + if(fading > 0) { + fading -= elapsed_time; + if(fading <= 0) { + fading = 0; + visible = true; + } + } else if(fading < 0) { + fading += elapsed_time; + if(fading >= 0) { + fading = 0; + visible = false; + } + } + +// (void) elapsed_time; } void @@ -58,14 +73,35 @@ FloatingImage::get_action() } void -FloatingImage::draw(DrawingContext& context) +FloatingImage::fade_in(float fadetime) { - if(!visible) - return; + this->fadetime = fadetime; + fading = fadetime; +} +void +FloatingImage::fade_out(float fadetime) +{ + this->fadetime = fadetime; + fading = -fadetime; +} + + +void +FloatingImage::draw(DrawingContext& context) +{ context.push_transform(); context.set_translation(Vector(0, 0)); + if(fading > 0) { + context.set_alpha((fadetime-fading) / fadetime); + } else if(fading < 0) { + context.set_alpha(-fading / fadetime); + } else if(!visible) { + context.pop_transform(); + return; + } + Vector spos = pos + get_anchor_pos(Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT), sprite->get_width(), sprite->get_height(), anchor); diff --git a/src/object/floating_image.hpp b/src/object/floating_image.hpp index db37066d9..897e879ff 100644 --- a/src/object/floating_image.hpp +++ b/src/object/floating_image.hpp @@ -64,6 +64,9 @@ public: void set_action(const std::string& action); std::string get_action(); + + void fade_in(float fadetime); + void fade_out(float fadetime); void update(float elapsed_time); void draw(DrawingContext& context); @@ -74,6 +77,8 @@ private: bool visible; AnchorPoint anchor; Vector pos; + float fading; + float fadetime; }; #endif diff --git a/src/scripting/floating_image.cpp b/src/scripting/floating_image.cpp index 3b4034476..1cb0c02be 100644 --- a/src/scripting/floating_image.cpp +++ b/src/scripting/floating_image.cpp @@ -113,4 +113,17 @@ FloatingImage::get_action() return floating_image->get_action(); } +void +FloatingImage::fade_in(float fadetime) +{ + floating_image->fade_in(fadetime); +} + +void +FloatingImage::fade_out(float fadetime) +{ + floating_image->fade_out(fadetime); +} + + } diff --git a/src/scripting/floating_image.hpp b/src/scripting/floating_image.hpp index 7434a842a..7fd920654 100644 --- a/src/scripting/floating_image.hpp +++ b/src/scripting/floating_image.hpp @@ -49,6 +49,8 @@ public: bool get_visible(); void set_action(const std::string& action); std::string get_action(); + void fade_in(float fadetime); + void fade_out(float fadetime); #ifndef SCRIPTING_API private: diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index 8307bacc4..0a0e47358 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -1802,6 +1802,64 @@ static SQInteger FloatingImage_get_action_wrapper(HSQUIRRELVM vm) } +static SQInteger FloatingImage_fade_in_wrapper(HSQUIRRELVM vm) +{ + SQUserPointer data; + if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0))) { + sq_throwerror(vm, _SC("'fade_in' called without instance")); + return SQ_ERROR; + } + Scripting::FloatingImage* _this = reinterpret_cast (data); + SQFloat arg0; + if(SQ_FAILED(sq_getfloat(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a float")); + return SQ_ERROR; + } + + try { + _this->fade_in(static_cast (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 'fade_in'")); + return SQ_ERROR; + } + +} + +static SQInteger FloatingImage_fade_out_wrapper(HSQUIRRELVM vm) +{ + SQUserPointer data; + if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0))) { + sq_throwerror(vm, _SC("'fade_out' called without instance")); + return SQ_ERROR; + } + Scripting::FloatingImage* _this = reinterpret_cast (data); + SQFloat arg0; + if(SQ_FAILED(sq_getfloat(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a float")); + return SQ_ERROR; + } + + try { + _this->fade_out(static_cast (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 'fade_out'")); + return SQ_ERROR; + } + +} + static SQInteger Platform_release_hook(SQUserPointer ptr, SQInteger ) { Scripting::Platform* _this = reinterpret_cast (ptr); @@ -4215,6 +4273,18 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, "Couldn't register function 'get_action'"); } + sq_pushstring(v, "fade_in", -1); + sq_newclosure(v, &FloatingImage_fade_in_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'fade_in'"); + } + + sq_pushstring(v, "fade_out", -1); + sq_newclosure(v, &FloatingImage_fade_out_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'fade_out'"); + } + if(SQ_FAILED(sq_createslot(v, -3))) { throw SquirrelError(v, "Couldn't register class 'FloatingImage'"); }