Merged floating image patch by DirtY iCE
authorChristoph Sommer <mail@christoph-sommer.de>
Sat, 16 Dec 2006 14:47:31 +0000 (14:47 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Sat, 16 Dec 2006 14:47:31 +0000 (14:47 +0000)
SVN-Revision: 4463

data/levels/world1/intro.nut
src/object/floating_image.cpp
src/object/floating_image.hpp
src/scripting/floating_image.cpp
src/scripting/floating_image.hpp
src/scripting/wrapper.cpp

index b38be37..45cc16b 100644 (file)
@@ -14,20 +14,24 @@ function intro()
   Effect.fade_in(2);
   Camera.scroll_to(0, 945, 15);
   wait(3);
   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);
   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_anchor_point(ANCHOR_TOP);
-  logo.set_pos(0, 90);
+  logo.set_pos(0, -120);
   logo.set_visible(true);
   logo.set_visible(true);
-  wait(5);
-  logo.set_visible(false);
+  logo.fade_in(2);
+  logo_in();
   wait(6);
   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);
   
   //begin conversation and Tux rap
   SUPERTUX.set_velocity(0,0);
@@ -101,3 +105,11 @@ function tux_upset()
   wait(0.3);
 }
 
   wait(0.3);
 }
 
+function logo_in()
+{
+  local i;
+  for(local i = -120; i <= 90; i+=2) {
+    logo.set_pos(0, i);
+    wait(0.01);
+  }
+}
index 5798784..00782af 100644 (file)
@@ -29,8 +29,9 @@
 #include "lisp/lisp.hpp"
 #include "floating_image.hpp"
 
 #include "lisp/lisp.hpp"
 #include "floating_image.hpp"
 
+
 FloatingImage::FloatingImage(const std::string& spritefile)
 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));
 }
 {
   sprite.reset(sprite_manager->create(spritefile));
 }
@@ -42,7 +43,21 @@ FloatingImage::~FloatingImage()
 void
 FloatingImage::update(float elapsed_time)
 {
 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
 }
 
 void
@@ -58,14 +73,35 @@ FloatingImage::get_action()
 }
 
 void
 }
 
 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));
 
   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);
 
   Vector spos = pos + get_anchor_pos(Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
       sprite->get_width(), sprite->get_height(), anchor);
 
index db37066..897e879 100644 (file)
@@ -64,6 +64,9 @@ public:
 
   void set_action(const std::string& action);
   std::string get_action();
 
   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);
 
   void update(float elapsed_time);
   void draw(DrawingContext& context);
@@ -74,6 +77,8 @@ private:
   bool visible;
   AnchorPoint anchor;
   Vector pos;
   bool visible;
   AnchorPoint anchor;
   Vector pos;
+  float fading;
+  float fadetime;
 };
 
 #endif
 };
 
 #endif
index 3b40344..1cb0c02 100644 (file)
@@ -113,4 +113,17 @@ FloatingImage::get_action()
   return floating_image->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);
+}
+
+
 }
 }
index 7434a84..7fd9206 100644 (file)
@@ -49,6 +49,8 @@ public:
   bool get_visible();
   void set_action(const std::string& action);
   std::string get_action();
   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:
 
 #ifndef SCRIPTING_API
 private:
index 8307bac..0a0e473 100644 (file)
@@ -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<Scripting::FloatingImage*> (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<float> (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<Scripting::FloatingImage*> (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<float> (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<Scripting::Platform*> (ptr);
 static SQInteger Platform_release_hook(SQUserPointer ptr, SQInteger )
 {
   Scripting::Platform* _this = reinterpret_cast<Scripting::Platform*> (ptr);
@@ -4215,6 +4273,18 @@ void register_supertux_wrapper(HSQUIRRELVM v)
     throw SquirrelError(v, "Couldn't register function 'get_action'");
   }
 
     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'");
   }
   if(SQ_FAILED(sq_createslot(v, -3))) {
     throw SquirrelError(v, "Couldn't register class 'FloatingImage'");
   }