29
29
#include "ptb/item/floating_score.hpp"
31
#include "generic_items/decorative_effect.hpp"
33
#include "ptb/defines.hpp"
31
34
#include "ptb/game_variables.hpp"
32
#include "ptb/defines.hpp"
35
#include "ptb/player.hpp"
36
#include "ptb/util.hpp"
36
41
BASE_ITEM_EXPORT( floating_score, ptb )
74
83
( unsigned int player_index, unsigned int points )
76
85
const unsigned int old_score( game_variables::get_score(player_index) );
86
const unsigned int new_score( old_score + points );
78
game_variables::set_score( player_index, old_score + points );
88
game_variables::set_score( player_index, new_score );
80
90
// check if the player wins a new try
92
if ( (old_score / PTB_ONE_UP_POINTS_COUNT)
93
< (new_score / PTB_ONE_UP_POINTS_COUNT) )
94
give_one_up_to(player_index);
82
96
const double intensity( (double)points / (double)PTB_MAX_POINTS_AT_ONCE );
84
98
if ( player_index == 1 )
91
105
set_text( oss.str() );
108
} // floating_score::add_points()
110
/*----------------------------------------------------------------------------*/
112
* \brief Give one more try to a player.
113
* \param player_index The index of the player to which the points are given.
115
void ptb::floating_score::one_up( unsigned int player_index )
117
game_variables::set_lives_count
118
( player_index, game_variables::get_lives_count(player_index) + 1);
120
if ( player_index == 1 )
121
get_rendering_attributes().set_intensity(1, 0, 0);
123
get_rendering_attributes().set_intensity(0, 1, 1);
129
get_level_globals().play_music("music/1-up.ogg", 1);
130
} // floating_score::one_up()
132
/*----------------------------------------------------------------------------*/
134
* \brief Set the displayed text.
135
* \param text The text to display.
137
void ptb::floating_score::set_score( const std::string& text )
142
} // floating_score::set_score()
144
/*----------------------------------------------------------------------------*/
146
* \brief Create the effects on the score.
148
void ptb::floating_score::create_effect()
150
const bear::universe::position_type pos(get_center_of_mass());
94
get_rendering_attributes().set_size( get_size() / 2 );
95
} // floating_score::add_points()
152
set_center_of_mass(pos);
153
get_rendering_attributes().set_size( get_size() / 2 );
155
bear::decorative_effect* decoration_effect = new bear::decorative_effect;
157
decoration_effect->set_duration(1);
158
decoration_effect->set_opacity_factor_init(1);
159
decoration_effect->set_opacity_factor_end(0);
160
decoration_effect->set_item(this, true);
162
new_item(*decoration_effect);
163
} // floating_score::create_effect()
165
/*----------------------------------------------------------------------------*/
167
* \brief Give a one up to a player, creating a new floating_score on him.
168
* \param player_index The index of the player to which the points are given.
170
void ptb::floating_score::give_one_up_to( unsigned int player_index ) const
172
player* p = util::find_player( get_level_globals(), player_index );
176
floating_score* s = new floating_score;
180
s->set_center_of_mass( p->get_center_of_mass() );
181
s->set_z_position( std::numeric_limits<int>::max() );
182
s->one_up(player_index);
184
} // floating_score::give_one_up_to()