--- /dev/null
+(supertux-sprite
+ (action
+ (name "default")
+ (images "invisible.png")
+ )
+)
(x 3)
(y 28)
)
+ (level
+ (name "intro.stl")
+ (x 22)
+ (y 4)
+ (sprite "images/objects/invisible/invisible.sprite")
+ )
(special-tile
(teleport-to-x 9)
(teleport-to-y 15)
+
function get_gold_key()
{
add_key(KEY_GOLD);
Effect.four_to_three();
Tux.activate();
}
+
+// Initialize keys
+if(! ("world2_keys" in state))
+ state.world2_keys <- {}
+
+local keys = state.world2_keys;
+if(! ("brass" in keys))
+ keys.brass <- false;
+if(! ("gold" in keys))
+ keys.gold <- false;
+
+local x = 10;
+local y = 10;
+
+key_brass <- FloatingImage("images/objects/keys/key_brass.sprite");
+key_brass.set_anchor_point(ANCHOR_TOPLEFT);
+key_brass.set_pos(x, y);
+key_brass.set_visible(true);
+key_brass.set_action(keys.brass ? "display" : "outline");
+x += 30;
+
+key_gold <- FloatingImage("images/objects/keys/key_gold.sprite");
+key_gold.set_anchor_point(ANCHOR_TOPLEFT);
+key_gold.set_pos(x, y);
+key_gold.set_visible(true);
+key_gold.set_action(keys.gold ? "display" : "outline");
+x += 30;
+
)
(init-script "
import(\"levels/world2/default.nut\");
- import(\"scripts/default.nut\");
- level2_init();
")
(secretarea (x 673.0)
(y 1090.0)
void
BonusBlock::try_open()
{
- if(sprite->get_action_name() == "empty") {
+ if(sprite->get_action() == "empty") {
sound_manager->play("sounds/brick.wav");
return;
}
void
Brick::hit(Player& )
{
- if(sprite->get_action_name() == "empty")
+ if(sprite->get_action() == "empty")
return;
try_break(true);
void
Brick::try_break(bool playerhit)
{
- if(sprite->get_action_name() == "empty")
+ if(sprite->get_action() == "empty")
return;
sound_manager->play("sounds/brick.wav");
}
void
+FloatingImage::set_action(const std::string& action)
+{
+ sprite->set_action(action);
+}
+
+std::string
+FloatingImage::get_action()
+{
+ return sprite->get_action();
+}
+
+void
FloatingImage::draw(DrawingContext& context)
{
if(!visible)
return visible;
}
+ void set_action(const std::string& action);
+ std::string get_action();
+
void update(float elapsed_time);
void draw(DrawingContext& context);
std::string
ScriptedObject::get_action()
{
- return sprite->get_action_name();
+ return sprite->get_action();
}
std::string
context.draw_text(white_text, coinstext, Vector(SCREEN_WIDTH - white_text->get_text_width(coinstext) - gold_text->get_text_width(" 99999") - BORDER_X, BORDER_Y), LEFT_ALLIGN, LAYER_FOREGROUND1);
context.draw_text(gold_text, str, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y), RIGHT_ALLIGN, LAYER_FOREGROUND1);
- draw_keys(context);
+ //draw_keys(context);
context.pop_transform();
}
floating_image->set_visible(visible);
}
+void
+FloatingImage::set_action(const std::string& action)
+{
+ floating_image->set_action(action);
+}
+
+std::string
+FloatingImage::get_action()
+{
+ return floating_image->get_action();
+}
+
}
int get_anchor_point();
void set_visible(bool visible);
bool get_visible();
+ void set_action(const std::string& action);
+ std::string get_action();
#ifndef SCRIPTING_API
private:
}
+static int FloatingImage_set_action_wrapper(HSQUIRRELVM vm)
+{
+ Scripting::FloatingImage* _this;
+ if(SQ_FAILED(sq_getinstanceup(vm, 1, reinterpret_cast<SQUserPointer*> (&_this), 0))) {
+ sq_throwerror(vm, _SC("'set_action' called without instance"));
+ return SQ_ERROR;
+ }
+ const char* arg0;
+ if(SQ_FAILED(sq_getstring(vm, 2, &arg0))) {
+ sq_throwerror(vm, _SC("Argument 1 not a string"));
+ return SQ_ERROR;
+ }
+
+ try {
+ _this->set_action(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 'set_action'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static int FloatingImage_get_action_wrapper(HSQUIRRELVM vm)
+{
+ Scripting::FloatingImage* _this;
+ if(SQ_FAILED(sq_getinstanceup(vm, 1, reinterpret_cast<SQUserPointer*> (&_this), 0))) {
+ sq_throwerror(vm, _SC("'get_action' called without instance"));
+ return SQ_ERROR;
+ }
+
+ try {
+ std::string return_value = _this->get_action();
+
+ sq_pushstring(vm, return_value.c_str(), return_value.size());
+ return 1;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'get_action'"));
+ return SQ_ERROR;
+ }
+
+}
+
static int display_wrapper(HSQUIRRELVM vm)
{
return Scripting::display(vm);
throw SquirrelError(v, "Couldn't register function 'get_visible'");
}
+ sq_pushstring(v, "set_action", -1);
+ sq_newclosure(v, &FloatingImage_set_action_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'set_action'");
+ }
+
+ sq_pushstring(v, "get_action", -1);
+ sq_newclosure(v, &FloatingImage_get_action_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'get_action'");
+ }
+
if(SQ_FAILED(sq_createslot(v, -3))) {
throw SquirrelError(v, "Couldn't register class 'FloatingImage'");
}
update();
if((int)frame >= get_frames() || (int)frame < 0)
- log_warning << "frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() << "/" << get_action_name() << std::endl;
+ log_warning << "frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl;
else
context.draw_surface(action->surfaces[(int)frame],
pos - Vector(action->x_offset, action->y_offset),
const std::string& get_name() const
{ return data.name; }
/** Get current action name */
- const std::string& get_action_name() const
+ const std::string& get_action() const
{ return action->name; }
int get_width() const;