--- /dev/null
+
+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();
+}
(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")
-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);
+}
DisplayEffect::DisplayEffect()
: type(NO_FADE), fadetime(0), fading(0), black(false)
{
+ cutscene_borders = false;
}
DisplayEffect::~DisplayEffect()
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();
}
return black;
}
+void
+DisplayEffect::sixteen_to_nine()
+{
+ cutscene_borders = true;
+}
+
+void
+DisplayEffect::four_to_three()
+{
+ cutscene_borders = false;
+}
void fade_in(float fadetime);
void set_black(bool enabled);
bool is_black();
+ void sixteen_to_nine();
+ void four_to_three();
private:
enum FadeType {
float fadetime;
float fading;
bool black;
+ bool cutscene_borders;
};
#endif
falling_from_flap = false;
enable_hover = false;
butt_jump = false;
+ deactivated = false;
flapping_velocity = 0;
}
}
- if(!dying)
+ if(!dying && !deactivated)
handle_input();
movement = physic.get_movement(elapsed_time);
void
Player::kill(HurtMode mode)
{
- if(dying)
+ if(dying || deactivated)
return;
if(mode != KILL &&
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);
+}
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;
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)
#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;
*/
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;
};
}
#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"
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);
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);
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;
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'";
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'";