PlayerStatus Class Reference

This class keeps player status between different game sessions (for example when switching maps in the worldmap). More...

#include <player_status.hpp>

List of all members.

Public Member Functions

 PlayerStatus ()
 ~PlayerStatus ()
void reset ()
void add_coins (int count, bool play_sound=true)
void write (Writer &writer)
void read (const Reader &lisp)
void draw (DrawingContext &context)

Public Attributes

int coins
BonusType bonus
int max_fire_bullets
 maximum number of fire bullets in play
int max_ice_bullets
 maximum number of ice bullets in play

Private Member Functions

 PlayerStatus (const PlayerStatus &)
PlayerStatusoperator= (const PlayerStatus &)

Private Attributes

int displayed_coins
int displayed_coins_frame
SurfacePtr coin_surface

Static Private Attributes

static Color text_color


Detailed Description

This class keeps player status between different game sessions (for example when switching maps in the worldmap).

Definition at line 40 of file player_status.hpp.


Constructor & Destructor Documentation

PlayerStatus::PlayerStatus (  ) 

Definition at line 37 of file player_status.cpp.

References coin_surface, Surface::create(), SoundManager::preload(), reset(), and sound_manager.

00037                            :
00038   /* Do we really want -Weffc++ to bully us into duplicating code from "reset" here? */
00039   coins(START_COINS),
00040   bonus(NO_BONUS),
00041   max_fire_bullets(0),
00042   max_ice_bullets(0),
00043   displayed_coins(DISPLAYED_COINS_UNSET),
00044   displayed_coins_frame(0),
00045   coin_surface()
00046 {
00047   reset();
00048 
00049   coin_surface = Surface::create("images/engine/hud/coins-0.png");
00050   sound_manager->preload("sounds/coin.wav");
00051   sound_manager->preload("sounds/lifeup.wav");
00052 }

PlayerStatus::~PlayerStatus (  ) 

Definition at line 54 of file player_status.cpp.

00055 {
00056 }

PlayerStatus::PlayerStatus ( const PlayerStatus  )  [private]


Member Function Documentation

void PlayerStatus::reset (  ) 

Definition at line 58 of file player_status.cpp.

References bonus, coins, displayed_coins, DISPLAYED_COINS_UNSET, NO_BONUS, and START_COINS.

Referenced by PlayerStatus(), and read().

00059 {
00060   coins = START_COINS;
00061   bonus = NO_BONUS;
00062   displayed_coins = DISPLAYED_COINS_UNSET;
00063 }

void PlayerStatus::add_coins ( int  count,
bool  play_sound = true 
)

Definition at line 66 of file player_status.cpp.

References coins, MAX_COINS, SoundManager::play(), real_time, and sound_manager.

Referenced by Player::add_coins(), Coin::collect(), PowerUp::collision(), OneUp::collision(), Brick::try_break(), and BonusBlock::try_open().

00067 {
00068   static float sound_played_time = 0;
00069   coins = std::min(coins + count, MAX_COINS);
00070   if(play_sound) {
00071     if(count >= 100)
00072       sound_manager->play("sounds/lifeup.wav");
00073     else if (real_time > sound_played_time + 0.010) {
00074       sound_manager->play("sounds/coin.wav");
00075       sound_played_time = real_time;
00076     }
00077   }
00078 }

void PlayerStatus::write ( Writer writer  ) 

Definition at line 81 of file player_status.cpp.

References bonus, coins, FIRE_BONUS, GROWUP_BONUS, ICE_BONUS, log_warning, max_fire_bullets, max_ice_bullets, NO_BONUS, and lisp::Writer::write().

00082 {
00083   switch(bonus) {
00084     case NO_BONUS:
00085       writer.write("bonus", "none");
00086       break;
00087     case GROWUP_BONUS:
00088       writer.write("bonus", "growup");
00089       break;
00090     case FIRE_BONUS:
00091       writer.write("bonus", "fireflower");
00092       break;
00093     case ICE_BONUS:
00094       writer.write("bonus", "iceflower");
00095       break;
00096     default:
00097       log_warning << "Unknown bonus type." << std::endl;
00098       writer.write("bonus", "none");
00099   }
00100   writer.write("fireflowers", max_fire_bullets);
00101   writer.write("iceflowers", max_ice_bullets);
00102 
00103   writer.write("coins", coins);
00104 }

void PlayerStatus::read ( const Reader lisp  ) 

Definition at line 107 of file player_status.cpp.

References bonus, coins, FIRE_BONUS, lisp::Lisp::get(), GROWUP_BONUS, ICE_BONUS, log_warning, max_fire_bullets, max_ice_bullets, NO_BONUS, and reset().

00108 {
00109   reset();
00110 
00111   std::string bonusname;
00112   if(lisp.get("bonus", bonusname)) {
00113     if(bonusname == "none") {
00114       bonus = NO_BONUS;
00115     } else if(bonusname == "growup") {
00116       bonus = GROWUP_BONUS;
00117     } else if(bonusname == "fireflower") {
00118       bonus = FIRE_BONUS;
00119     } else if(bonusname == "iceflower") {
00120       bonus = ICE_BONUS;
00121     } else {
00122       log_warning << "Unknown bonus '" << bonusname << "' in savefile" << std::endl;
00123       bonus = NO_BONUS;
00124     }
00125   }
00126   lisp.get("fireflowers", max_fire_bullets);
00127   lisp.get("iceflowers", max_ice_bullets);
00128 
00129   lisp.get("coins", coins);
00130 }

void PlayerStatus::draw ( DrawingContext context  ) 

Definition at line 133 of file player_status.cpp.

References ALIGN_LEFT, BORDER_X, BORDER_Y, coin_surface, coins, displayed_coins, displayed_coins_frame, DISPLAYED_COINS_UNSET, DrawingContext::draw_surface(), DrawingContext::draw_text(), Resources::fixed_font, LAYER_HUD, DrawingContext::pop_transform(), DrawingContext::push_transform(), SCREEN_WIDTH, DrawingContext::set_translation(), and text_color.

Referenced by worldmap::WorldMap::draw_status(), and GameSession::drawstatus().

00134 {
00135   int player_id = 0;
00136 
00137   if ((displayed_coins == DISPLAYED_COINS_UNSET) ||
00138       (fabsf(displayed_coins - coins) > 100)) {
00139     displayed_coins = coins;
00140     displayed_coins_frame = 0;
00141   }
00142   if (++displayed_coins_frame > 2) {
00143     displayed_coins_frame = 0;
00144     if (displayed_coins < coins) displayed_coins++;
00145     if (displayed_coins > coins) displayed_coins--;
00146   }
00147   displayed_coins = std::min(std::max(displayed_coins, 0), 9999);
00148 
00149   std::stringstream ss;
00150   ss << displayed_coins;
00151   std::string coins_text = ss.str();
00152 
00153   context.push_transform();
00154   context.set_translation(Vector(0, 0));
00155 
00156   if (coin_surface)
00157   {
00158     context.draw_surface(coin_surface, 
00159                          Vector(SCREEN_WIDTH - BORDER_X - coin_surface->get_width() - Resources::fixed_font->get_text_width(coins_text), 
00160                                 BORDER_Y + 1 + (Resources::fixed_font->get_text_height(coins_text) + 5) * player_id),
00161                          LAYER_HUD);
00162   }
00163   context.draw_text(Resources::fixed_font, 
00164                     coins_text, 
00165                     Vector(SCREEN_WIDTH - BORDER_X - Resources::fixed_font->get_text_width(coins_text),
00166                            BORDER_Y + (Resources::fixed_font->get_text_height(coins_text) + 5) * player_id),
00167                     ALIGN_LEFT,
00168                     LAYER_HUD,
00169                     PlayerStatus::text_color);
00170 
00171   context.pop_transform();
00172 }

PlayerStatus& PlayerStatus::operator= ( const PlayerStatus  )  [private]


Member Data Documentation

Color PlayerStatus::text_color [static, private]

Definition at line 42 of file player_status.hpp.

Referenced by draw().

int PlayerStatus::coins

Definition at line 55 of file player_status.hpp.

Referenced by add_coins(), draw(), Player::get_coins(), read(), reset(), and write().

BonusType PlayerStatus::bonus

Definition at line 56 of file player_status.hpp.

Referenced by Player::add_bonus(), Sector::add_bullet(), worldmap::Tux::draw(), Player::draw(), Player::handle_input(), Player::is_big(), Player::kill(), read(), reset(), Player::set_bonus(), BonusBlock::try_open(), and write().

int PlayerStatus::max_fire_bullets

maximum number of fire bullets in play

Definition at line 57 of file player_status.hpp.

Referenced by Sector::add_bullet(), read(), Player::set_bonus(), and write().

int PlayerStatus::max_ice_bullets

maximum number of ice bullets in play

Definition at line 58 of file player_status.hpp.

Referenced by Sector::add_bullet(), read(), Player::set_bonus(), and write().

int PlayerStatus::displayed_coins [private]

Definition at line 61 of file player_status.hpp.

Referenced by draw(), and reset().

int PlayerStatus::displayed_coins_frame [private]

Definition at line 62 of file player_status.hpp.

Referenced by draw().

SurfacePtr PlayerStatus::coin_surface [private]

Definition at line 63 of file player_status.hpp.

Referenced by draw(), and PlayerStatus().


The documentation for this class was generated from the following files:
Generated on Mon Apr 21 03:38:27 2014 for SuperTux by  doxygen 1.5.1