lots of cool scripting stuff
authorMarek Moeckel <wansti@gmx.de>
Sun, 25 Sep 2005 23:55:41 +0000 (23:55 +0000)
committerMarek Moeckel <wansti@gmx.de>
Sun, 25 Sep 2005 23:55:41 +0000 (23:55 +0000)
SVN-Revision: 2786

data/levels/world2/default.nut [new file with mode: 0644]
data/levels/world2/level2.stl
data/script/default.nut
src/object/display_effect.cpp
src/object/display_effect.hpp
src/object/player.cpp
src/object/player.hpp
src/scripting/display_effect.hpp
src/scripting/player.hpp
src/scripting/script_interpreter.cpp
src/scripting/wrapper.cpp

diff --git a/data/levels/world2/default.nut b/data/levels/world2/default.nut
new file mode 100644 (file)
index 0000000..65ddc2c
--- /dev/null
@@ -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();
+}
index 6f920ae..3797a4b 100644 (file)
          (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")
index 5034bf3..2fded5b 100644 (file)
@@ -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);
+}
index 7a254c5..3c3bc4c 100644 (file)
@@ -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<uint8_t>
-                    (fading * 255.0 / fadetime);
-                break;
-            case FADE_OUT:
-                alpha = static_cast<uint8_t>
-                    ((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<uint8_t>
+                      (fading * 255.0 / fadetime);
+                  break;
+              case FADE_OUT:
+                  alpha = static_cast<uint8_t>
+                      ((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;
+}
index 612386a..f35dd52 100644 (file)
@@ -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
index 5892164..4242a16 100644 (file)
@@ -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);
+}
index ddf02b5..56f8269 100644 (file)
@@ -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;
index 74fad9c..01d4488 100644 (file)
@@ -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)
index 58f1041..fee8f69 100644 (file)
@@ -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;
 };
 
 }
index 4844656..af17653 100644 (file)
@@ -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<Scripting::Player*> (sector->player), "Tux");
   TextObject* text_object = new TextObject();
   sector->add_object(text_object);
   Scripting::Text* text = static_cast<Scripting::Text*> (text_object);
index 8eba394..56d56b2 100644 (file)
@@ -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<Scripting::Camera*> (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'";