// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <math.h>
+#include <sstream>
#include "audio/sound_manager.hpp"
-#include "lisp/lisp.hpp"
#include "util/writer.hpp"
-#include "supertux/main.hpp"
+#include "supertux/globals.hpp"
#include "supertux/player_status.hpp"
#include "supertux/resources.hpp"
#include "supertux/timer.hpp"
+#include "util/reader.hpp"
#include "video/drawing_context.hpp"
static const int START_COINS = 100;
static const int MAX_COINS = 9999;
+static const int DISPLAYED_COINS_UNSET = -1;
+
PlayerStatus* player_status = 0;
-PlayerStatus::PlayerStatus()
- : coins(START_COINS),
- bonus(NO_BONUS),
- max_fire_bullets(0),
- max_ice_bullets(0)
+PlayerStatus::PlayerStatus() :
+ /* Do we really want -Weffc++ to bully us into duplicating code from "reset" here? */
+ coins(START_COINS),
+ bonus(NO_BONUS),
+ max_fire_bullets(0),
+ max_ice_bullets(0),
+ max_air_time(0),
+ max_earth_time(0),
+ displayed_coins(DISPLAYED_COINS_UNSET),
+ displayed_coins_frame(0),
+ coin_surface()
{
reset();
- coin_surface.reset(new Surface("images/engine/hud/coins-0.png"));
- sound_manager->preload("sounds/coin.wav");
- sound_manager->preload("sounds/lifeup.wav");
+ coin_surface = Surface::create("images/engine/hud/coins-0.png");
+ SoundManager::current()->preload("sounds/coin.wav");
+ SoundManager::current()->preload("sounds/lifeup.wav");
}
PlayerStatus::~PlayerStatus()
{
coins = START_COINS;
bonus = NO_BONUS;
+ displayed_coins = DISPLAYED_COINS_UNSET;
}
void
coins = std::min(coins + count, MAX_COINS);
if(play_sound) {
if(count >= 100)
- sound_manager->play("sounds/lifeup.wav");
+ SoundManager::current()->play("sounds/lifeup.wav");
else if (real_time > sound_played_time + 0.010) {
- sound_manager->play("sounds/coin.wav");
+ SoundManager::current()->play("sounds/coin.wav");
sound_played_time = real_time;
}
}
case ICE_BONUS:
writer.write("bonus", "iceflower");
break;
+ case AIR_BONUS:
+ writer.write("bonus", "airflower");
+ break;
+ case EARTH_BONUS:
+ writer.write("bonus", "earthflower");
+ break;
default:
log_warning << "Unknown bonus type." << std::endl;
writer.write("bonus", "none");
}
writer.write("fireflowers", max_fire_bullets);
writer.write("iceflowers", max_ice_bullets);
+ writer.write("airflowers", max_air_time);
+ writer.write("earthflowers", max_earth_time);
writer.write("coins", coins);
}
bonus = FIRE_BONUS;
} else if(bonusname == "iceflower") {
bonus = ICE_BONUS;
+ } else if(bonusname == "airflower") {
+ bonus = AIR_BONUS;
+ } else if(bonusname == "earthflower") {
+ bonus = EARTH_BONUS;
} else {
log_warning << "Unknown bonus '" << bonusname << "' in savefile" << std::endl;
bonus = NO_BONUS;
}
lisp.get("fireflowers", max_fire_bullets);
lisp.get("iceflowers", max_ice_bullets);
+ lisp.get("airflowers", max_air_time);
+ lisp.get("earthflowers", max_earth_time);
lisp.get("coins", coins);
}
void
PlayerStatus::draw(DrawingContext& context)
{
- static int displayed_coins = -1;
- static int next_count = 0;
+ int player_id = 0;
- if ((displayed_coins == -1) || (fabsf(displayed_coins - coins) > 100)) {
+ if ((displayed_coins == DISPLAYED_COINS_UNSET) ||
+ (fabsf(displayed_coins - coins) > 100)) {
displayed_coins = coins;
+ displayed_coins_frame = 0;
}
- if (++next_count > 2) {
- next_count = 0;
+ if (++displayed_coins_frame > 2) {
+ displayed_coins_frame = 0;
if (displayed_coins < coins) displayed_coins++;
if (displayed_coins > coins) displayed_coins--;
}
context.push_transform();
context.set_translation(Vector(0, 0));
- 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);
+ if (coin_surface)
+ {
+ context.draw_surface(coin_surface,
+ Vector(SCREEN_WIDTH - BORDER_X - coin_surface->get_width() - Resources::fixed_font->get_text_width(coins_text),
+ BORDER_Y + 1 + (Resources::fixed_font->get_text_height(coins_text) + 5) * player_id),
+ LAYER_HUD);
}
- context.draw_text(fixed_font, coins_text, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y), ALIGN_RIGHT, LAYER_HUD, PlayerStatus::text_color);
+ context.draw_text(Resources::fixed_font,
+ coins_text,
+ Vector(SCREEN_WIDTH - BORDER_X - Resources::fixed_font->get_text_width(coins_text),
+ BORDER_Y + (Resources::fixed_font->get_text_height(coins_text) + 5) * player_id),
+ ALIGN_LEFT,
+ LAYER_HUD,
+ PlayerStatus::text_color);
context.pop_transform();
}
-void
-PlayerStatus::operator= (const PlayerStatus& other)
-{
- coins = other.coins;
- bonus = other.bonus;
-}
-
/* EOF */