// $Id$
//
-// SuperTux - A Jump'n Run
+// SuperTux
// Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.de>
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <config.h>
+#include <math.h>
#include "lisp/writer.hpp"
#include "lisp/lisp.hpp"
#include "player_status.hpp"
#include "sprite/sprite_manager.hpp"
#include "math/vector.hpp"
#include "main.hpp"
-#include "msg.hpp"
+#include "log.hpp"
+#include "timer.hpp"
static const int START_COINS = 100;
static const int MAX_COINS = 99999;
PlayerStatus::PlayerStatus()
: coins(START_COINS),
bonus(NO_BONUS),
+ max_fire_bullets(0),
+ max_ice_bullets(0),
score_multiplier(1),
max_score_multiplier(1)
{
reset();
- key_brass.reset(sprite_manager->create("images/objects/keys/key_brass.sprite"));
- key_iron.reset(sprite_manager->create("images/objects/keys/key_iron.sprite"));
- key_bronze.reset(sprite_manager->create("images/objects/keys/key_bronze.sprite"));
- key_silver.reset(sprite_manager->create("images/objects/keys/key_silver.sprite"));
- key_gold.reset(sprite_manager->create("images/objects/keys/key_gold.sprite"));
- 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");
-
- tux_life.reset(sprite_manager->create("images/creatures/tux_small/tux-life.sprite"));
+
+ coin_surface.reset(new Surface("images/engine/hud/coins-0.png"));
+ sound_manager->preload("sounds/coin.wav");
+ sound_manager->preload("sounds/lifeup.wav");
}
PlayerStatus::~PlayerStatus()
void PlayerStatus::reset()
{
coins = START_COINS;
- keys = 0;
bonus = NO_BONUS;
score_multiplier = 1;
max_score_multiplier = 1;
}
void
-PlayerStatus::incLives()
-{
- 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");
-}
-
-void
-PlayerStatus::set_keys(int new_key)
+PlayerStatus::add_coins(int count, bool play_sound)
{
- 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");
+ static float sound_played_time = 0;
+ coins = std::min(coins + count, MAX_COINS);
+ if(play_sound) {
+ if(count >= 100)
+ sound_manager->play("sounds/lifeup.wav");
+ else if (real_time > sound_played_time + 0.010) {
+ sound_manager->play("sounds/coin.wav");
+ sound_played_time = real_time;
+ }
+ }
}
void
writer.write_string("bonus", "iceflower");
break;
default:
- msg_warning << "Unknown bonus type." << std::endl;
+ log_warning << "Unknown bonus type." << std::endl;
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("fireflowers", max_fire_bullets);
+ writer.write_int("iceflowers", max_ice_bullets);
writer.write_int("coins", coins);
writer.write_int("max-score-multiplier", max_score_multiplier);
PlayerStatus::read(const lisp::Lisp& lisp)
{
reset();
-
+
std::string bonusname;
if(lisp.get("bonus", bonusname)) {
if(bonusname == "none") {
} else if(bonusname == "iceflower") {
bonus = ICE_BONUS;
} else {
- msg_warning << "Unknown bonus '" << bonusname << "' in savefile" << std::endl;
+ log_warning << "Unknown bonus '" << bonusname << "' in savefile" << std::endl;
bonus = NO_BONUS;
}
}
- bool val = false;
- 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("fireflowers", max_fire_bullets);
+ lisp.get("iceflowers", max_ice_bullets);
lisp.get("coins", coins);
lisp.get("max-score-multiplier", max_score_multiplier);
}
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)
{
+ static int displayed_coins = -1;
+ static int next_count = 0;
+
+ if ((displayed_coins == -1) || (fabsf(displayed_coins - coins) > 100)) {
+ displayed_coins = coins;
+ }
+ if (++next_count > 2) {
+ next_count = 0;
+ if (displayed_coins < coins) displayed_coins++;
+ if (displayed_coins > coins) displayed_coins--;
+ }
+ displayed_coins = std::min(std::max(displayed_coins, 0), 9999);
+
+ std::stringstream ss;
+ ss << displayed_coins;
+ std::string coins_text = ss.str();
+
context.push_transform();
context.set_translation(Vector(0, 0));
- char str[60];
-
- int displayCoins = std::max(player_status->coins, 0);
- sprintf(str, "%d", displayCoins);
- const char* coinstext = _("COINS");
- 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);
+ Surface* coin_surf = coin_surface.get();
+ if (coin_surf) {
+ context.draw_surface(coin_surf, Vector(SCREEN_WIDTH - BORDER_X - coin_surf->get_width() - fixed_font->get_text_width(coins_text), BORDER_Y + 1), LAYER_HUD);
+ }
+ context.draw_text(fixed_font, coins_text, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y), ALIGN_RIGHT, LAYER_HUD, PlayerStatus::text_color);
context.pop_transform();
}
bonus = other.bonus;
score_multiplier = other.score_multiplier;
max_score_multiplier = other.max_score_multiplier;
- keys = other.keys;
}
-