(name "Icebridge")
(tiles 0 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551)
)
-(tile
+ (tile
(id 0)
- (editor-images "objects/bonus_block/bonus-fire_flower.png")
)
(tile
(id 1)
wait(6);
Effect.fade_out(2);
wait(2);
- Level.finish();
+ Level.finish(true);
}
function levelflip()
if (height == 0)
return;
+ int layer = LAYER_GUI + 1;
+
context.push_transform();
context.set_alpha(alpha);
- context.draw_surface(background2.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2 - background->get_width() + backgroundOffset, height - background->get_height()), LAYER_FOREGROUND1+1);
- context.draw_surface(background2.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2 + backgroundOffset, height - background->get_height()), LAYER_FOREGROUND1+1);
- context.draw_surface(background.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2, height - background->get_height()), LAYER_FOREGROUND1+1);
+ context.draw_surface(background2.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2 - background->get_width() + backgroundOffset, height - background->get_height()), layer);
+ context.draw_surface(background2.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2 + backgroundOffset, height - background->get_height()), layer);
+ context.draw_surface(background.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2, height - background->get_height()), layer);
backgroundOffset+=10;
if (backgroundOffset > (int)background->get_width()) backgroundOffset -= (int)background->get_width();
if (focused) {
lineNo++;
float py = height-4-1*9;
- context.draw_text(font.get(), "> "+inputBuffer.str()+"_", Vector(4, py), LEFT_ALLIGN, LAYER_FOREGROUND1+1);
+ context.draw_text(font.get(), "> "+inputBuffer.str()+"_", Vector(4, py), LEFT_ALLIGN, layer);
}
int skipLines = -offset;
lineNo++;
float py = height-4-lineNo*9;
if (py < -9) break;
- context.draw_text(font.get(), *i, Vector(4, py), LEFT_ALLIGN, LAYER_FOREGROUND1+1);
+ context.draw_text(font.get(), *i, Vector(4, py), LEFT_ALLIGN, layer);
}
context.pop_transform();
void
Menu::draw_item(DrawingContext& context, int index)
{
- int menu_height = get_height();
- int menu_width = get_width();
+ float menu_height = get_height();
+ float menu_width = get_width();
MenuItem& pitem = *(items[index]);
}
}
-int Menu::get_width() const
+float Menu::get_width() const
+{
+ /* The width of the menu has to be more than the width of the text
+ with the most characters */
+ float menu_width = 0;
+ for(unsigned int i = 0; i < items.size(); ++i)
{
- /* The width of the menu has to be more than the width of the text
- with the most characters */
- int menu_width = 0;
- for(unsigned int i = 0; i < items.size(); ++i)
- {
- int w = items[i]->text.size() + items[i]->input.size() + 1;
- if(w > menu_width)
- {
- menu_width = w;
- if( items[i]->kind == MN_TOGGLE)
- menu_width += 2;
- }
- }
-
- return (menu_width * 16 + 24);
+ Font* font = default_font;
+ if(items[i]->kind == MN_LABEL)
+ font = label_font;
+
+ float w = font->get_text_width(items[i]->text) +
+ label_font->get_text_width(items[i]->input) + 16;
+ if(items[i]->kind == MN_TOGGLE)
+ w += 32;
+
+ if(w > menu_width)
+ menu_width = w;
}
+
+ return menu_width + 24;
+}
-int Menu::get_height() const
- {
- return items.size() * 24;
- }
+float Menu::get_height() const
+{
+ return items.size() * 24;
+}
/* Draw the current menu. */
void
MouseCursor::current()->draw(context);
}
- int menu_height = get_height();
- int menu_width = get_width();
+ float menu_height = get_height();
+ float menu_width = get_width();
/* Draw a transparent background */
context.draw_filled_rect(
protected:
void additem(MenuItem* pmenu_item);
- int get_width() const;
- int get_height() const;
+ float get_width() const;
+ float get_height() const;
private:
void check_controlfield_change_event(const SDL_Event& event);
void
MainLoop::exit_screen()
{
- if (screen_stack.size() < 1)
- {
+ if (screen_stack.size() < 1) {
quit();
return;
}
switch(contents) {
case CONTENT_COIN:
Sector::current()->add_object(new BouncyCoin(get_pos()));
- player.get_status()->incCoins();
+ player.get_status()->add_coins(1);
break;
case CONTENT_FIREGROW:
if(coin_counter > 0) {
sector->add_object(new BouncyCoin(get_pos()));
coin_counter--;
- player.get_status()->incCoins();
+ player.get_status()->add_coins(1);
if(coin_counter == 0)
sprite->set_action("empty");
start_bounce();
void
Coin::collect()
{
- Sector::current()->player->get_status()->incCoins();
+ Sector::current()->player->get_status()->add_coins(1);
Sector::current()->add_object(new BouncyCoin(get_pos()));
global_stats.add_points(COINS_COLLECTED_STAT, 1);
remove_me();
{
Player* player = dynamic_cast<Player*> (&other);
if(player) {
- player->get_status()->incLives();
+ player->get_status()->add_coins(100);
remove_me();
return ABORT_MOVE;
}
}
void
+Player::add_coins(int count)
+{
+ player_status->add_coins(count);
+}
+
+void
+Player::set_bonus(const std::string& bonustype)
+{
+ if(bonustype == "grow")
+ set_bonus(GROWUP_BONUS);
+ else if(bonustype == "fireflower")
+ set_bonus(FIRE_BONUS);
+ else if(bonustype == "iceflower")
+ set_bonus(ICE_BONUS);
+ else if(bonustype == "none")
+ set_bonus(NO_BONUS);
+
+
+ std::ostringstream msg;
+ msg << "Unknown bonus type " << bonustype;
+ throw std::runtime_error(msg.str());
+}
+
+void
Player::set_bonus(BonusType type, bool animate)
{
if(player_status->bonus >= type)
void kill(HurtMode mode);
void check_bounds(Camera* camera);
void move(const Vector& vector);
+
+ virtual void set_bonus(const std::string& bonus);
+ virtual void add_coins(int count);
void set_bonus(BonusType type, bool animate = false);
PlayerStatus* get_status()
{
} else if (sprite_name == "images/powerups/star/star.sprite") {
player->make_invincible();
} else if (sprite_name == "images/powerups/1up/1up.sprite") {
- player->get_status()->incLives();
+ player->get_status()->add_coins(100);
}
return ABORT_MOVE;
}
}
void
-PlayerStatus::incLives()
+PlayerStatus::add_coins(int count)
{
- player_status->coins = std::min(player_status->coins+100, MAX_COINS);
- sound_manager->play("sounds/lifeup.wav");
-}
-
-void
-PlayerStatus::incCoins()
-{
- coins++;
- sound_manager->play("sounds/coin.wav");
+ coins = std::min(coins + count, MAX_COINS);
+ if(count > 100)
+ sound_manager->play("sounds/lifeup.wav");
+ else
+ sound_manager->play("sounds/coin.wav");
}
void
PlayerStatus();
~PlayerStatus();
void reset();
- void incLives();
- void incCoins();
+ void add_coins(int count);
void set_keys(int new_key);
void write(lisp::Writer& writer);
script_manager->set_wakeup_event(vm, ScriptManager::SCREEN_SWITCHED);
}
+void exit_screen()
+{
+ main_loop->exit_screen();
+}
+
std::string translate(const std::string& text)
{
return dictionary_manager.get_dictionary().translate(text);
void wait_for_screenswitch(HSQUIRRELVM vm) __suspend;
/**
+ * Exits the currently running screen (force exit from worldmap or scrolling
+ * text for example)
+ */
+void exit_screen();
+
+/**
* Translate a text into the users language (by looking it up in the .po
* files)
*/
{}
#endif
-#if 0
/**
* Set tux bonus.
* This can be "grow", "fireflower" or "iceflower" at the moment
*/
virtual void set_bonus(const std::string& bonus) = 0;
/**
- * Give tux another life
- */
- virtual void add_life() = 0;
- /**
* Give tux more coins
*/
virtual void add_coins(int count) = 0;
-#endif
/**
* Make tux invicible for a short amount of time
*/
return 0;
}
+static int Player_set_bonus_wrapper(HSQUIRRELVM vm)
+{
+ Scripting::Player* _this;
+ if(SQ_FAILED(sq_getinstanceup(vm, 1, reinterpret_cast<SQUserPointer*> (&_this), 0))) {
+ sq_throwerror(vm, _SC("'set_bonus' 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_bonus(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_bonus'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static int Player_add_coins_wrapper(HSQUIRRELVM vm)
+{
+ Scripting::Player* _this;
+ if(SQ_FAILED(sq_getinstanceup(vm, 1, reinterpret_cast<SQUserPointer*> (&_this), 0))) {
+ sq_throwerror(vm, _SC("'add_coins' called without instance"));
+ return SQ_ERROR;
+ }
+ int arg0;
+ if(SQ_FAILED(sq_getinteger(vm, 2, &arg0))) {
+ sq_throwerror(vm, _SC("Argument 1 not an integer"));
+ return SQ_ERROR;
+ }
+
+ try {
+ _this->add_coins(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 'add_coins'"));
+ return SQ_ERROR;
+ }
+
+}
+
static int Player_make_invincible_wrapper(HSQUIRRELVM vm)
{
Scripting::Player* _this;
}
+static int exit_screen_wrapper(HSQUIRRELVM vm)
+{
+ (void) vm;
+
+ try {
+ Scripting::exit_screen();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'exit_screen'"));
+ return SQ_ERROR;
+ }
+
+}
+
static int translate_wrapper(HSQUIRRELVM vm)
{
const char* arg0;
throw SquirrelError(v, "Couldn't register function 'wait_for_screenswitch'");
}
+ sq_pushstring(v, "exit_screen", -1);
+ sq_newclosure(v, &exit_screen_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'exit_screen'");
+ }
+
sq_pushstring(v, "translate", -1);
sq_newclosure(v, &translate_wrapper, 0);
if(SQ_FAILED(sq_createslot(v, -3))) {
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))) {
+ throw SquirrelError(v, "Couldn't register function 'set_bonus'");
+ }
+
+ sq_pushstring(v, "add_coins", -1);
+ sq_newclosure(v, &Player_add_coins_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'add_coins'");
+ }
+
sq_pushstring(v, "make_invincible", -1);
sq_newclosure(v, &Player_make_invincible_wrapper, 0);
if(SQ_FAILED(sq_createslot(v, -3))) {