From: Marek Moeckel Date: Sun, 25 Sep 2005 16:49:21 +0000 (+0000) Subject: keys are displayed on the screen, they can be "collected" via a scripting function X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=b72c5d178e4cc95130735d8bf8716513c7cc28e1;p=supertux.git keys are displayed on the screen, they can be "collected" via a scripting function SVN-Revision: 2783 --- diff --git a/data/images/objects/keys/display_brass.png b/data/images/objects/keys/display_brass.png new file mode 100644 index 000000000..95c1fcbf2 Binary files /dev/null and b/data/images/objects/keys/display_brass.png differ diff --git a/data/images/objects/keys/display_bronze.png b/data/images/objects/keys/display_bronze.png new file mode 100644 index 000000000..9357c3e16 Binary files /dev/null and b/data/images/objects/keys/display_bronze.png differ diff --git a/data/images/objects/keys/display_gold.png b/data/images/objects/keys/display_gold.png new file mode 100644 index 000000000..1e5269e1c Binary files /dev/null and b/data/images/objects/keys/display_gold.png differ diff --git a/data/images/objects/keys/display_iron.png b/data/images/objects/keys/display_iron.png new file mode 100644 index 000000000..464779477 Binary files /dev/null and b/data/images/objects/keys/display_iron.png differ diff --git a/data/images/objects/keys/display_silver.png b/data/images/objects/keys/display_silver.png new file mode 100644 index 000000000..f51fec6a5 Binary files /dev/null and b/data/images/objects/keys/display_silver.png differ diff --git a/data/images/objects/keys/key_brass.png b/data/images/objects/keys/key_brass.png index 5cc296c06..4bb09f7ca 100644 Binary files a/data/images/objects/keys/key_brass.png and b/data/images/objects/keys/key_brass.png differ diff --git a/data/images/objects/keys/key_bronze.png b/data/images/objects/keys/key_bronze.png new file mode 100644 index 000000000..7ea1600eb Binary files /dev/null and b/data/images/objects/keys/key_bronze.png differ diff --git a/data/images/objects/keys/key_iron.png b/data/images/objects/keys/key_iron.png new file mode 100644 index 000000000..a398e4a62 Binary files /dev/null and b/data/images/objects/keys/key_iron.png differ diff --git a/data/images/objects/keys/outline_brass.png b/data/images/objects/keys/outline_brass.png new file mode 100644 index 000000000..ef4f19cf2 Binary files /dev/null and b/data/images/objects/keys/outline_brass.png differ diff --git a/data/images/objects/keys/outline_bronze.png b/data/images/objects/keys/outline_bronze.png new file mode 100644 index 000000000..350c5b66e Binary files /dev/null and b/data/images/objects/keys/outline_bronze.png differ diff --git a/data/images/objects/keys/outline_gold.png b/data/images/objects/keys/outline_gold.png new file mode 100644 index 000000000..27e4994b7 Binary files /dev/null and b/data/images/objects/keys/outline_gold.png differ diff --git a/data/images/objects/keys/outline_iron.png b/data/images/objects/keys/outline_iron.png new file mode 100644 index 000000000..bab8cf5df Binary files /dev/null and b/data/images/objects/keys/outline_iron.png differ diff --git a/data/images/objects/keys/outline_silver.png b/data/images/objects/keys/outline_silver.png new file mode 100644 index 000000000..bab8cf5df Binary files /dev/null and b/data/images/objects/keys/outline_silver.png differ diff --git a/data/images/sprites.strf b/data/images/sprites.strf index fb396a4bf..bbbc23692 100644 --- a/data/images/sprites.strf +++ b/data/images/sprites.strf @@ -1693,12 +1693,81 @@ (images "tiles/doodads/platter.png") ) ) - (sprite - (name "gold-key") + (sprite + (name "key-brass") + (action + (name "default") + (images "objects/keys/key_brass.png") + ) + (action + (name "display") + (images "objects/keys/display_brass.png") + ) + (action + (name "outline") + (images "objects/keys/outline_brass.png") + ) + + ) + (sprite + (name "key-iron") + (action + (name "default") + (images "objects/keys/key_iron.png") + ) + (action + (name "display") + (images "objects/keys/display_iron.png") + ) + (action + (name "outline") + (images "objects/keys/outline_iron.png") + ) + ) + (sprite + (name "key-bronze") + (action + (name "default") + (images "objects/keys/key_bronze.png") + ) + (action + (name "display") + (images "objects/keys/display_bronze.png") + ) + (action + (name "outline") + (images "objects/keys/outline_bronze.png") + ) + ) + (sprite + (name "key-silver") + (action + (name "default") + (images "objects/keys/key_silver.png") + ) + (action + (name "display") + (images "objects/keys/display_silver.png") + ) + (action + (name "outline") + (images "objects/keys/outline_silver.png") + ) + ) + (sprite + (name "key-gold") (action (name "default") (images "objects/keys/key_gold.png") ) + (action + (name "display") + (images "objects/keys/display_gold.png") + ) + (action + (name "outline") + (images "objects/keys/outline_gold.png") + ) ) ) diff --git a/data/levels/world2/level2.stl b/data/levels/world2/level2.stl index c8c755a75..90132a322 100644 --- a/data/levels/world2/level2.stl +++ b/data/levels/world2/level2.stl @@ -234,8 +234,12 @@ DisplayEffect.fade_in(1); ") ) (powerup (x 8000) (y 352) - (sprite "gold-key") - (script "wait(7); + (sprite "key-gold") + (script "add_key(KEY_GOLD); + Sound.play_music(\"leveldone\"); + wait(6); + DisplayEffect.fade_out(2); + wait(2); Level.finish();") ) (infoblock (x 2560) (y 320) diff --git a/src/game_session.cpp b/src/game_session.cpp index efbc9c558..b7985bbb6 100644 --- a/src/game_session.cpp +++ b/src/game_session.cpp @@ -200,7 +200,7 @@ GameSession::levelintro() context.draw_center_text(gold_text, level->get_name(), Vector(0, 160), LAYER_FOREGROUND1); - sprintf(str, "TUX x %d", player_status.lives); + sprintf(str, "TUX x %d", player_status->lives); context.draw_text(white_text, str, Vector(SCREEN_WIDTH/2, 210), CENTER_ALLIGN, LAYER_FOREGROUND1); @@ -324,10 +324,10 @@ GameSession::try_cheats() tux.set_bonus(ICE_BONUS, false); } if(main_controller->check_cheatcode("lifeup")) { - player_status.lives++; + player_status->lives++; } if(main_controller->check_cheatcode("lifedown")) { - player_status.lives--; + player_status->lives--; } if(main_controller->check_cheatcode("grease")) { tux.physic.set_velocity_x(tux.physic.get_velocity_x()*3); @@ -342,7 +342,7 @@ GameSession::try_cheats() } if(main_controller->check_cheatcode("kill")) { // kill Tux, but without losing a life - player_status.lives++; + player_status->lives++; tux.kill(tux.KILL); } #if 0 @@ -389,7 +389,7 @@ GameSession::check_end_conditions() exit_status = ES_LEVEL_FINISHED; return; } else if (!end_sequence && tux->is_dead()) { - if (player_status.lives < 0) { // No more lives!? + if (player_status->lives < 0) { // No more lives!? exit_status = ES_GAME_OVER; } else { // Still has lives, so reset Tux to the levelstart restart_level(); @@ -717,17 +717,17 @@ GameSession::start_sequence(const std::string& sequencename) void GameSession::drawstatus(DrawingContext& context) { - player_status.draw(context); + player_status->draw(context); if(config->show_fps) { char str[60]; snprintf(str, sizeof(str), "%2.1f", fps_fps); context.draw_text(white_text, "FPS", Vector(SCREEN_WIDTH - - white_text->get_text_width("FPS "), 40), + white_text->get_text_width("FPS ") - BORDER_X, BORDER_Y + 40), LEFT_ALLIGN, LAYER_FOREGROUND1); context.draw_text(gold_text, str, - Vector(SCREEN_WIDTH-4*16, 40), + Vector(SCREEN_WIDTH-4*16 - BORDER_X, BORDER_Y + 40), LEFT_ALLIGN, LAYER_FOREGROUND1); } } @@ -752,7 +752,7 @@ GameSession::drawresultscreen() sprintf(str, _("SCORE: %d"), global_stats.get_points(SCORE_STAT)); context.draw_text(gold_text, str, Vector(SCREEN_WIDTH/2, 224), CENTER_ALLIGN, LAYER_FOREGROUND1); - sprintf(str, _("COINS: %d"), player_status.coins); + sprintf(str, _("COINS: %d"), player_status->coins); context.draw_text(gold_text, str, Vector(SCREEN_WIDTH/2, 256), CENTER_ALLIGN, LAYER_FOREGROUND1); context.do_drawing(); diff --git a/src/object/player.hpp b/src/object/player.hpp index 451ed0535..ddf02b578 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -30,6 +30,7 @@ #include "physic.hpp" #include "control/controller.hpp" #include "player_status.hpp" +#include "scripting/player.hpp" class BadGuy; class Portable; @@ -78,7 +79,7 @@ extern TuxBodyParts* big_tux; extern TuxBodyParts* fire_tux; extern TuxBodyParts* ice_tux; -class Player : public MovingObject +class Player : public MovingObject, public Scripting::Player { public: enum HurtMode { KILL, SHRINK }; diff --git a/src/player_status.cpp b/src/player_status.cpp index 57acb9348..50623be8e 100644 --- a/src/player_status.cpp +++ b/src/player_status.cpp @@ -25,12 +25,14 @@ #include "gettext.hpp" #include "video/drawing_context.hpp" #include "audio/sound_manager.hpp" +#include "sprite/sprite_manager.hpp" +#include "math/vector.hpp" #include "main.hpp" static const int START_LIVES = 4; static const int MAX_LIVES = 99; -PlayerStatus player_status; +PlayerStatus* player_status = 0; PlayerStatus::PlayerStatus() : coins(0), @@ -39,11 +41,32 @@ PlayerStatus::PlayerStatus() score_multiplier(1), max_score_multiplier(1) { + reset(); + key_brass = sprite_manager->create("key-brass"); + key_iron = sprite_manager->create("key-iron"); + key_bronze = sprite_manager->create("key-bronze"); + key_silver = sprite_manager->create("key-silver"); + key_gold = sprite_manager->create("key-gold"); + key_brass->set_action("outline"); + key_iron->set_action("outline"); + key_bronze->set_action("outline"); + key_silver->set_action("outline"); + key_gold->set_action("outline"); +} + +PlayerStatus::~PlayerStatus() +{ + delete key_brass; + delete key_iron; + delete key_bronze; + delete key_silver; + delete key_gold; } void PlayerStatus::reset() { coins = 0; + keys = 0; lives = START_LIVES; bonus = NO_BONUS; score_multiplier = 1; @@ -70,6 +93,17 @@ PlayerStatus::incCoins() } void +PlayerStatus::set_keys(int new_key) +{ + keys |= new_key; + key_brass->set_action(keys & KEY_BRASS ? "display" : "outline"); + key_iron->set_action(keys & KEY_IRON ? "display" : "outline"); + key_bronze->set_action(keys & KEY_BRONZE ? "display" : "outline"); + key_silver->set_action(keys & KEY_SILVER ? "display" : "outline"); + key_gold->set_action(keys & KEY_GOLD ? "display" : "outline"); +} + +void PlayerStatus::write(lisp::Writer& writer) { switch(bonus) { @@ -89,6 +123,11 @@ PlayerStatus::write(lisp::Writer& writer) std::cerr << "Unknown bonus type.\n"; writer.write_string("bonus", "none"); } + writer.write_bool("key-brass", keys & KEY_BRASS); + writer.write_bool("key-iron", keys & KEY_IRON); + writer.write_bool("key-bronze", keys & KEY_BRONZE); + writer.write_bool("key-silver", keys & KEY_SILVER); + writer.write_bool("key-gold", keys & KEY_GOLD); writer.write_int("lives", lives); writer.write_int("coins", coins); @@ -115,6 +154,17 @@ PlayerStatus::read(const lisp::Lisp& lisp) bonus = NO_BONUS; } } + bool val; + if(lisp.get("key-brass", val) && val == true) + set_keys(KEY_BRASS); + if(lisp.get("key-iron", val) && val == true) + set_keys(KEY_IRON); + if(lisp.get("key-bronze", val) && val == true) + set_keys(KEY_BRONZE); + if(lisp.get("key-silver", val) && val == true) + set_keys(KEY_SILVER); + if(lisp.get("key-gold", val) && val == true) + set_keys(KEY_GOLD); lisp.get("lives", lives); lisp.get("coins", coins); @@ -122,6 +172,24 @@ PlayerStatus::read(const lisp::Lisp& lisp) } void +PlayerStatus::draw_keys(DrawingContext& context) +{ + const float SPACING = 10; + float x,y; + x = BORDER_X; y = BORDER_Y; + key_brass->draw(context, Vector(x, y), LAYER_FOREGROUND1); + x += key_brass->get_width() + SPACING; + key_iron->draw(context, Vector(x, y), LAYER_FOREGROUND1); + x += key_iron->get_width() + SPACING; + key_bronze->draw(context, Vector(x, y), LAYER_FOREGROUND1); + x += key_bronze->get_width() + SPACING; + key_silver->draw(context, Vector(x, y), LAYER_FOREGROUND1); + x += key_silver->get_width() + SPACING; + key_gold->draw(context, Vector(x, y), LAYER_FOREGROUND1); + x += key_gold->get_width() + SPACING; +} + +void PlayerStatus::draw(DrawingContext& context) { context.push_transform(); @@ -129,35 +197,37 @@ PlayerStatus::draw(DrawingContext& context) char str[60]; - sprintf(str, " %d", player_status.coins); + sprintf(str, " %d", player_status->coins); const char* coinstext = _("COINS"); context.draw_text(white_text, coinstext, Vector(SCREEN_WIDTH - white_text->get_text_width(coinstext) - - white_text->get_text_width(" 99"), 0), + - white_text->get_text_width(" 99") - BORDER_X, BORDER_Y), LEFT_ALLIGN, LAYER_FOREGROUND1); context.draw_text(gold_text, str, - Vector(SCREEN_WIDTH - gold_text->get_text_width(" 99"), 0), + Vector(SCREEN_WIDTH - gold_text->get_text_width(" 99") - BORDER_X, BORDER_Y), LEFT_ALLIGN, LAYER_FOREGROUND1); - if (player_status.lives >= 5) { - sprintf(str, "%dx", player_status.lives); + if (player_status->lives >= 5) { + sprintf(str, "%dx", player_status->lives); float x = SCREEN_WIDTH - gold_text->get_text_width(str) - tux_life->w; - context.draw_text(gold_text, str, Vector(x, 20), LEFT_ALLIGN, + context.draw_text(gold_text, str, Vector(x - BORDER_X, BORDER_Y + 20), LEFT_ALLIGN, LAYER_FOREGROUND1); - context.draw_surface(tux_life, Vector(SCREEN_WIDTH - 16, 20), + context.draw_surface(tux_life, Vector(SCREEN_WIDTH - 16 - BORDER_X, BORDER_Y + 20), LAYER_FOREGROUND1); } else { - for(int i= 0; i < player_status.lives; ++i) + for(int i= 0; i < player_status->lives; ++i) context.draw_surface(tux_life, - Vector(SCREEN_WIDTH - tux_life->w*4 +(tux_life->w*i), 20), + Vector(SCREEN_WIDTH - tux_life->w*4 +(tux_life->w*i) - BORDER_X, BORDER_Y + 20), LAYER_FOREGROUND1); } const char* livestext = _("LIVES"); context.draw_text(white_text, livestext, Vector(SCREEN_WIDTH - white_text->get_text_width(livestext) - - white_text->get_text_width(" 99"), 20), + - white_text->get_text_width(" 99") - BORDER_X, BORDER_Y + 20), LEFT_ALLIGN, LAYER_FOREGROUND1); + + draw_keys(context); context.pop_transform(); } diff --git a/src/player_status.hpp b/src/player_status.hpp index 4ad7a6800..06db4f1ce 100644 --- a/src/player_status.hpp +++ b/src/player_status.hpp @@ -22,6 +22,10 @@ #include "lisp/lisp.hpp" #include "timer.hpp" #include "serializable.hpp" +#include "sprite/sprite.hpp" + +static const float BORDER_X = 10; +static const float BORDER_Y = 10; enum BonusType { NO_BONUS, GROWUP_BONUS, FIRE_BONUS, ICE_BONUS @@ -36,14 +40,17 @@ class PlayerStatus : public Serializable { public: PlayerStatus(); + ~PlayerStatus(); void reset(); void incLives(); void incCoins(); + void set_keys(int new_key); void write(lisp::Writer& writer); void read(const lisp::Lisp& lisp); void draw(DrawingContext& context); + void draw_keys(DrawingContext& context); int coins; int lives; @@ -51,9 +58,25 @@ public: int score_multiplier; int max_score_multiplier; + + enum { + KEY_BRASS = 0x001, + KEY_IRON = 0x002, + KEY_BRONZE = 0x004, + KEY_SILVER = 0x008, + KEY_GOLD = 0x010, + }; + +private: + int keys; + Sprite* key_iron; + Sprite* key_brass; + Sprite* key_bronze; + Sprite* key_silver; + Sprite* key_gold; }; // global player state -extern PlayerStatus player_status; +extern PlayerStatus* player_status; #endif diff --git a/src/resources.cpp b/src/resources.cpp index 39cb26f20..92f2f41ef 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -116,31 +116,8 @@ void load_shared() /* Tux life: */ tux_life = new Surface("images/creatures/tux_small/tux-life.png", true); - -#if 0 - /* Sound effects: */ - sound_manager->preload_sound("jump"); - sound_manager->preload_sound("bigjump"); - sound_manager->preload_sound("skid"); - sound_manager->preload_sound("coin"); - sound_manager->preload_sound("invincible"); - sound_manager->preload_sound("brick"); - sound_manager->preload_sound("hurt"); - sound_manager->preload_sound("squish"); - sound_manager->preload_sound("fall"); - sound_manager->preload_sound("ricochet"); - sound_manager->preload_sound("bump-upgrade"); - sound_manager->preload_sound("upgrade"); - sound_manager->preload_sound("grow"); - sound_manager->preload_sound("fire-flower"); - sound_manager->preload_sound("shoot"); - sound_manager->preload_sound("lifeup"); - sound_manager->preload_sound("stomp"); - sound_manager->preload_sound("kick"); - sound_manager->preload_sound("explosion"); - sound_manager->preload_sound("warp"); - sound_manager->preload_sound("fireworks"); -#endif + + player_status = new PlayerStatus(); } /* Free shared data: */ diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index 2e51cad65..f62ef9227 100644 --- a/src/scripting/functions.cpp +++ b/src/scripting/functions.cpp @@ -47,5 +47,10 @@ void import(HSQUIRRELVM v, const std::string& filename) } } +void add_key(int new_key) +{ + player_status->set_keys(new_key); +} + } diff --git a/src/scripting/functions.hpp b/src/scripting/functions.hpp index 512c69ee6..ba0d36ab8 100644 --- a/src/scripting/functions.hpp +++ b/src/scripting/functions.hpp @@ -3,11 +3,19 @@ #ifndef SCRIPTING_API #define __suspend +#include "player_status.hpp" #endif namespace Scripting { +//TODO: Get this from PlayerStatus (update MiniSwig!) +static const int KEY_BRASS = 0x001; +static const int KEY_IRON = 0x002; +static const int KEY_BRONZE = 0x004; +static const int KEY_SILVER = 0x008; +static const int KEY_GOLD = 0x010; + /** displays a text file and scrolls it over the screen */ void display_text_file(const std::string& filename); /** @@ -22,6 +30,9 @@ std::string translate(const std::string& text); * This is typically used to import functions from external files. */ void import(HSQUIRRELVM v, const std::string& filename); +/** add a key to the inventory + */ +void add_key(int new_key); } diff --git a/src/scripting/player.hpp b/src/scripting/player.hpp index 9c1f009fe..58f10419f 100644 --- a/src/scripting/player.hpp +++ b/src/scripting/player.hpp @@ -12,6 +12,7 @@ public: {} #endif +#if 0 /** * Set tux bonus. * This can be "grow", "fireflow" or "iceflower" at the moment @@ -29,6 +30,7 @@ public: * Give tux more coins */ virtual void add_coins(int count) = 0; +#endif }; } diff --git a/src/scripting/script_interpreter.cpp b/src/scripting/script_interpreter.cpp index f3c8d0793..eb53a0c54 100644 --- a/src/scripting/script_interpreter.cpp +++ b/src/scripting/script_interpreter.cpp @@ -179,8 +179,18 @@ ScriptInterpreter::add_script_object(Sector* sector, const std::string& name, std::auto_ptr interpreter( new ScriptInterpreter(workdir)); interpreter->register_sector(sector); + + // load global default.nut file if it exists + //TODO: Load all .nut files from that directory + try { + std::string filename = "data/script/default.nut"; + IFileStream in(filename); + interpreter->run_script(in, filename, false); + } catch(std::exception& e) { + // nothing + } - // load default.nut file if it exists + // load world-specific default.nut file if it exists try { std::string filename = workdir + "/default.nut"; IFileStream in(filename); diff --git a/src/scripting/sound.cpp b/src/scripting/sound.cpp index bf1c1101e..6b2ac531f 100644 --- a/src/scripting/sound.cpp +++ b/src/scripting/sound.cpp @@ -21,7 +21,7 @@ namespace Scripting std::string filename = "music/"; filename += name; filename += ".ogg"; - sound_manager->play_music(name); + sound_manager->play_music(filename); } void diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index 0a7813d2c..8eba394b8 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -417,50 +417,6 @@ static int Player_release_hook(SQUserPointer ptr, int ) return 0; } -static int Player_set_bonus_wrapper(HSQUIRRELVM v) -{ - Scripting::Player* _this; - sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); - const char* arg0; - sq_getstring(v, 2, &arg0); - - _this->set_bonus(arg0); - - 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_add_life_wrapper(HSQUIRRELVM v) -{ - Scripting::Player* _this; - sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); - - _this->add_life(); - - return 0; -} - -static int Player_add_coins_wrapper(HSQUIRRELVM v) -{ - Scripting::Player* _this; - sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); - int arg0; - sq_getinteger(v, 2, &arg0); - - _this->add_coins(arg0); - - return 0; -} - static int display_text_file_wrapper(HSQUIRRELVM v) { const char* arg0; @@ -503,6 +459,16 @@ static int import_wrapper(HSQUIRRELVM v) return 0; } +static int add_key_wrapper(HSQUIRRELVM v) +{ + int arg0; + sq_getinteger(v, 2, &arg0); + + Scripting::add_key(arg0); + + return 0; +} + } // end of namespace Wrapper void create_squirrel_instance(HSQUIRRELVM v, Scripting::DisplayEffect* object, bool setup_releasehook) @@ -692,6 +658,46 @@ void register_supertux_wrapper(HSQUIRRELVM v) using namespace Wrapper; sq_pushroottable(v); + sq_pushstring(v, "KEY_BRASS", -1); + sq_pushinteger(v, 1); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'KEY_BRASS'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "KEY_IRON", -1); + sq_pushinteger(v, 2); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'KEY_IRON'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "KEY_BRONZE", -1); + sq_pushinteger(v, 4); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'KEY_BRONZE'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "KEY_SILVER", -1); + sq_pushinteger(v, 8); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'KEY_SILVER'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "KEY_GOLD", -1); + sq_pushinteger(v, 16); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'KEY_GOLD'"; + throw SquirrelError(v, msg.str()); + } + sq_pushstring(v, "display_text_file", -1); sq_newclosure(v, &display_text_file_wrapper, 0); if(SQ_FAILED(sq_createslot(v, -3))) { @@ -724,6 +730,14 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, msg.str()); } + sq_pushstring(v, "add_key", -1); + sq_newclosure(v, &add_key_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'add_key'"; + throw SquirrelError(v, msg.str()); + } + // Register class DisplayEffect sq_pushstring(v, "DisplayEffect", -1); if(sq_newclass(v, SQFalse) < 0) { @@ -1041,38 +1055,6 @@ void register_supertux_wrapper(HSQUIRRELVM v) msg << "Couldn't create new class 'Player'"; throw SquirrelError(v, msg.str()); } - sq_pushstring(v, "set_bonus", -1); - sq_newclosure(v, &Player_set_bonus_wrapper, 0); - if(SQ_FAILED(sq_createslot(v, -3))) { - std::ostringstream msg; - msg << "Couldn't register function'set_bonus'"; - 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, "add_life", -1); - sq_newclosure(v, &Player_add_life_wrapper, 0); - if(SQ_FAILED(sq_createslot(v, -3))) { - std::ostringstream msg; - msg << "Couldn't register function'add_life'"; - throw SquirrelError(v, msg.str()); - } - - sq_pushstring(v, "add_coins", -1); - sq_newclosure(v, &Player_add_coins_wrapper, 0); - if(SQ_FAILED(sq_createslot(v, -3))) { - std::ostringstream msg; - msg << "Couldn't register function'add_coins'"; - throw SquirrelError(v, msg.str()); - } - if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register class'Player'"; diff --git a/src/sector.cpp b/src/sector.cpp index 2230eca94..79d80c6f5 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -72,7 +72,7 @@ Sector::Sector() currentmusic(LEVEL_MUSIC) { song_title = "chipdisko.ogg"; - player = new Player(&player_status); + player = new Player(player_status); add_object(player); #ifdef USE_GRID @@ -750,11 +750,11 @@ Sector::add_bullet(const Vector& pos, float xm, Direction dir) static const size_t MAX_ICE_BULLETS = 1; Bullet* new_bullet = 0; - if(player_status.bonus == FIRE_BONUS) { + if(player_status->bonus == FIRE_BONUS) { if(bullets.size() > MAX_FIRE_BULLETS-1) return false; new_bullet = new Bullet(pos, xm, dir, FIRE_BULLET); - } else if(player_status.bonus == ICE_BONUS) { + } else if(player_status->bonus == ICE_BONUS) { if(bullets.size() > MAX_ICE_BULLETS-1) return false; new_bullet = new Bullet(pos, xm, dir, ICE_BULLET); diff --git a/src/title.cpp b/src/title.cpp index 537ff96e0..266b28b92 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -82,7 +82,7 @@ static int current_subset = -1; */ void resume_demo() { - player_status.reset(); + player_status->reset(); titlesession->get_current_sector()->activate("main"); titlesession->set_current(); @@ -232,7 +232,7 @@ void check_contrib_subset_menu() GameSession session( current_contrib_subset->get_level_filename(index), ST_GL_PLAY); session.run(); - player_status.reset(); + player_status->reset(); Menu::set_current(main_menu); resume_demo(); } diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 0123216c8..d31d4968f 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -132,7 +132,7 @@ Tux::~Tux() void Tux::draw(DrawingContext& context) { - switch (player_status.bonus) { + switch (player_status->bonus) { case GROWUP_BONUS: tux_sprite->set_action("large"); break; @@ -735,7 +735,7 @@ WorldMap::update(float delta) if (level->pos == tux->get_tile_pos()) { sound_manager->stop_music(); - PlayerStatus old_player_status = player_status; + PlayerStatus old_player_status = *player_status; // do a shriking fade to the level shrink_fade(Vector((level->pos.x*32 + 16 + offset.x), @@ -787,9 +787,9 @@ WorldMap::update(float delta) level_finished = false; /* In case the player's abort the level, keep it using the old status. But the minimum lives and no bonus. */ - player_status.coins = old_player_status.coins; - player_status.lives = std::min(old_player_status.lives, player_status.lives); - player_status.bonus = NO_BONUS; + player_status->coins = old_player_status.coins; + player_status->lives = std::min(old_player_status.lives, player_status->lives); + player_status->bonus = NO_BONUS; break; case GameSession::ES_GAME_OVER: @@ -808,7 +808,7 @@ WorldMap::update(float delta) context.draw_text(blue_text, _("GAMEOVER"), Vector(SCREEN_WIDTH/2, 200), CENTER_ALLIGN, LAYER_FOREGROUND1); - sprintf(str, _("COINS: %d"), player_status.coins); + sprintf(str, _("COINS: %d"), player_status->coins); context.draw_text(gold_text, str, Vector(SCREEN_WIDTH/2, SCREEN_WIDTH - 32), CENTER_ALLIGN, LAYER_FOREGROUND1); @@ -820,7 +820,7 @@ WorldMap::update(float delta) wait_for_event(2.0, 6.0); quit = true; - player_status.reset(); + player_status->reset(); break; } case GameSession::ES_NONE: @@ -936,7 +936,7 @@ WorldMap::draw_status(DrawingContext& context) context.push_transform(); context.set_translation(Vector(0, 0)); - player_status.draw(context); + player_status->draw(context); if (!tux->is_moving()) { @@ -1078,7 +1078,7 @@ WorldMap::savegame(const std::string& filename) writer.write_float("x", tux->get_tile_pos().x); writer.write_float("y", tux->get_tile_pos().y); writer.write_string("back", direction_to_string(tux->back_direction)); - player_status.write(writer); + player_status->write(writer); writer.write_string("back", direction_to_string(tux->back_direction)); writer.end_list("tux"); @@ -1124,11 +1124,11 @@ WorldMap::loadgame(const std::string& filename) load_map(); savegame->get("intro-displayed", intro_displayed); - savegame->get("lives", player_status.lives); - savegame->get("coins", player_status.coins); - savegame->get("max-score-multiplier", player_status.max_score_multiplier); - if (player_status.lives < 0) - player_status.reset(); + savegame->get("lives", player_status->lives); + savegame->get("coins", player_status->coins); + savegame->get("max-score-multiplier", player_status->max_score_multiplier); + if (player_status->lives < 0) + player_status->reset(); const lisp::Lisp* tux_lisp = savegame->get_lisp("tux"); if(tux) @@ -1139,7 +1139,7 @@ WorldMap::loadgame(const std::string& filename) tux_lisp->get("x", p.x); tux_lisp->get("y", p.y); tux_lisp->get("back", back_str); - player_status.read(*tux_lisp); + player_status->read(*tux_lisp); tux->back_direction = string_to_direction(back_str); tux->set_tile_pos(p); @@ -1176,7 +1176,7 @@ WorldMap::loadgame(const std::string& filename) std::cerr << "Problem loading game '" << filename << "': " << e.what() << "\n"; load_map(); - player_status.reset(); + player_status->reset(); } calculate_total_stats();