From 3715e3bc1c852448660c443876b3e3054d332d82 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Sun, 23 Apr 2006 14:49:35 +0000 Subject: [PATCH] make igloo the first level SVN-Revision: 3386 --- data/images/objects/invisible/invisible.png | Bin 0 -> 182 bytes data/images/objects/invisible/invisible.sprite | 6 +++ data/levels/world1/worldmap.stwm | 6 +++ data/levels/world2/default.nut | 29 +++++++++++ data/levels/world2/level2.stl | 2 - src/object/block.cpp | 6 +-- src/object/floating_image.cpp | 12 +++++ src/object/floating_image.hpp | 3 ++ src/object/scripted_object.cpp | 2 +- src/player_status.cpp | 2 +- src/scripting/floating_image.cpp | 12 +++++ src/scripting/floating_image.hpp | 2 + src/scripting/wrapper.cpp | 64 +++++++++++++++++++++++++ src/sprite/sprite.cpp | 2 +- src/sprite/sprite.hpp | 2 +- 15 files changed, 141 insertions(+), 9 deletions(-) create mode 100644 data/images/objects/invisible/invisible.png create mode 100644 data/images/objects/invisible/invisible.sprite diff --git a/data/images/objects/invisible/invisible.png b/data/images/objects/invisible/invisible.png new file mode 100644 index 0000000000000000000000000000000000000000..a587ad9cc981d45c562de976e2a2b725c2d38e21 GIT binary patch literal 182 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&kwOMVwDxeDxZhD?lOH64!_l=ltB<)VvY~=c3falGGH1 z^30M9g^-L?1$R&1fcGh?c|e6yo-U3d5r^L%WMl;LniT%8&+~8qG2gQZC@?Ti{~mrF P$YJnw^>bP0l+XkKfK4yy literal 0 HcmV?d00001 diff --git a/data/images/objects/invisible/invisible.sprite b/data/images/objects/invisible/invisible.sprite new file mode 100644 index 000000000..a9cce7c06 --- /dev/null +++ b/data/images/objects/invisible/invisible.sprite @@ -0,0 +1,6 @@ +(supertux-sprite + (action + (name "default") + (images "invisible.png") + ) +) diff --git a/data/levels/world1/worldmap.stwm b/data/levels/world1/worldmap.stwm index 7062bce8b..f01f3e0f2 100644 --- a/data/levels/world1/worldmap.stwm +++ b/data/levels/world1/worldmap.stwm @@ -152,6 +152,12 @@ (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) diff --git a/data/levels/world2/default.nut b/data/levels/world2/default.nut index 0713e291c..091e665b7 100644 --- a/data/levels/world2/default.nut +++ b/data/levels/world2/default.nut @@ -1,4 +1,5 @@ + function get_gold_key() { add_key(KEY_GOLD); @@ -20,3 +21,31 @@ function level2_init() 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; + diff --git a/data/levels/world2/level2.stl b/data/levels/world2/level2.stl index b83076954..9a9f08d00 100644 --- a/data/levels/world2/level2.stl +++ b/data/levels/world2/level2.stl @@ -191,8 +191,6 @@ ) (init-script " import(\"levels/world2/default.nut\"); - import(\"scripts/default.nut\"); - level2_init(); ") (secretarea (x 673.0) (y 1090.0) diff --git a/src/object/block.cpp b/src/object/block.cpp index 7f6e9f407..6d0c5f4a6 100644 --- a/src/object/block.cpp +++ b/src/object/block.cpp @@ -204,7 +204,7 @@ BonusBlock::hit(Player& ) void BonusBlock::try_open() { - if(sprite->get_action_name() == "empty") { + if(sprite->get_action() == "empty") { sound_manager->play("sounds/brick.wav"); return; } @@ -282,7 +282,7 @@ Brick::Brick(const Vector& pos, int data) void Brick::hit(Player& ) { - if(sprite->get_action_name() == "empty") + if(sprite->get_action() == "empty") return; try_break(true); @@ -291,7 +291,7 @@ Brick::hit(Player& ) void Brick::try_break(bool playerhit) { - if(sprite->get_action_name() == "empty") + if(sprite->get_action() == "empty") return; sound_manager->play("sounds/brick.wav"); diff --git a/src/object/floating_image.cpp b/src/object/floating_image.cpp index 4dc8c6ae7..6041baec2 100644 --- a/src/object/floating_image.cpp +++ b/src/object/floating_image.cpp @@ -46,6 +46,18 @@ FloatingImage::update(float elapsed_time) } 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) diff --git a/src/object/floating_image.hpp b/src/object/floating_image.hpp index 0c827faf5..7e7ddc3a2 100644 --- a/src/object/floating_image.hpp +++ b/src/object/floating_image.hpp @@ -62,6 +62,9 @@ public: return visible; } + void set_action(const std::string& action); + std::string get_action(); + void update(float elapsed_time); void draw(DrawingContext& context); diff --git a/src/object/scripted_object.cpp b/src/object/scripted_object.cpp index 07eebb352..47839d289 100644 --- a/src/object/scripted_object.cpp +++ b/src/object/scripted_object.cpp @@ -142,7 +142,7 @@ ScriptedObject::set_action(const std::string& animation) std::string ScriptedObject::get_action() { - return sprite->get_action_name(); + return sprite->get_action(); } std::string diff --git a/src/player_status.cpp b/src/player_status.cpp index 432640cbf..edd22cee3 100644 --- a/src/player_status.cpp +++ b/src/player_status.cpp @@ -199,7 +199,7 @@ PlayerStatus::draw(DrawingContext& context) 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(); } diff --git a/src/scripting/floating_image.cpp b/src/scripting/floating_image.cpp index db8292e9b..8b09e64f8 100644 --- a/src/scripting/floating_image.cpp +++ b/src/scripting/floating_image.cpp @@ -94,4 +94,16 @@ FloatingImage::set_visible(bool visible) 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(); +} + } diff --git a/src/scripting/floating_image.hpp b/src/scripting/floating_image.hpp index 42dcf365f..78f39df74 100644 --- a/src/scripting/floating_image.hpp +++ b/src/scripting/floating_image.hpp @@ -46,6 +46,8 @@ public: 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: diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index d28de4793..57d74ed9d 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -1413,6 +1413,58 @@ static int FloatingImage_get_visible_wrapper(HSQUIRRELVM vm) } +static int FloatingImage_set_action_wrapper(HSQUIRRELVM vm) +{ + Scripting::FloatingImage* _this; + if(SQ_FAILED(sq_getinstanceup(vm, 1, reinterpret_cast (&_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 (&_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); @@ -2843,6 +2895,18 @@ void register_supertux_wrapper(HSQUIRRELVM v) 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'"); } diff --git a/src/sprite/sprite.cpp b/src/sprite/sprite.cpp index 4d6898033..3ab455423 100644 --- a/src/sprite/sprite.cpp +++ b/src/sprite/sprite.cpp @@ -100,7 +100,7 @@ Sprite::draw(DrawingContext& context, const Vector& pos, int layer) 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), diff --git a/src/sprite/sprite.hpp b/src/sprite/sprite.hpp index e86a58b58..229f6340b 100644 --- a/src/sprite/sprite.hpp +++ b/src/sprite/sprite.hpp @@ -64,7 +64,7 @@ public: 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; -- 2.11.0