~ubuntu-branches/ubuntu/trusty/plee-the-bear/trusty-proposed

« back to all changes in this revision

Viewing changes to plee-the-bear/src/ptb/item/code/floating_score.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge, Julien Jorge
  • Date: 2010-11-17 20:13:34 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101117201334-o4dp7uq437to7oxb
Tags: 0.5.1-1
[ Julien Jorge ]
* New upstream release (Closes: #565062, #546514).
* Add armhf architecture (Closes: #604689).
* Remove patches integrated upstream: rpath-editors.diff, rpath-game.diff,
  editors-menu-section.diff.
* Bump the Standard-Version, no changes.
* Update my email address.
* Set build dependency of libclaw to 1.6.0.
* Add the missing ${misc:Depends} in debian/control.
* List gettext translations in bear-factory.install and plee-the-bear.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
  Plee the Bear
3
3
 
4
 
  Copyright (C) 2005-2009 Julien Jorge, Sebastien Angibaud
 
4
  Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
5
5
 
6
6
  This program is free software; you can redistribute it and/or modify it
7
7
  under the terms of the GNU General Public License as published by the
28
28
 */
29
29
#include "ptb/item/floating_score.hpp"
30
30
 
 
31
#include "generic_items/decorative_effect.hpp"
 
32
 
 
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"
33
37
 
34
38
#include <sstream>
 
39
#include <limits>
35
40
 
36
41
BASE_ITEM_EXPORT( floating_score, ptb )
37
42
 
52
57
 */
53
58
void ptb::floating_score::pre_cache()
54
59
{
 
60
  super::pre_cache();
 
61
 
55
62
  get_level_globals().load_font("font/bouncy.fnt");
56
63
} // floating_score::pre_cache()
57
64
 
61
68
 */
62
69
void ptb::floating_score::build()
63
70
{
 
71
  super::build();
 
72
 
64
73
  set_font( get_level_globals().get_font("font/bouncy.fnt") );
65
74
} // floating_score::build()
66
75
 
74
83
( unsigned int player_index, unsigned int points )
75
84
{
76
85
  const unsigned int old_score( game_variables::get_score(player_index) );
 
86
  const unsigned int new_score( old_score + points );
77
87
 
78
 
  game_variables::set_score( player_index, old_score + points );
 
88
  game_variables::set_score( player_index, new_score );
79
89
 
80
90
  // check if the player wins a new try
81
91
 
 
92
  if ( (old_score / PTB_ONE_UP_POINTS_COUNT)
 
93
       < (new_score / PTB_ONE_UP_POINTS_COUNT) )
 
94
    give_one_up_to(player_index);
 
95
 
82
96
  const double intensity( (double)points / (double)PTB_MAX_POINTS_AT_ONCE );
83
97
 
84
98
  if ( player_index == 1 )
90
104
  oss << points;
91
105
  set_text( oss.str() );
92
106
 
 
107
  create_effect();
 
108
} // floating_score::add_points()
 
109
 
 
110
/*----------------------------------------------------------------------------*/
 
111
/**
 
112
 * \brief Give one more try to a player.
 
113
 * \param player_index The index of the player to which the points are given.
 
114
 */
 
115
void ptb::floating_score::one_up( unsigned int player_index )
 
116
{
 
117
  game_variables::set_lives_count
 
118
    ( player_index, game_variables::get_lives_count(player_index) + 1);
 
119
 
 
120
  if ( player_index == 1 )
 
121
    get_rendering_attributes().set_intensity(1, 0, 0);
 
122
  else
 
123
    get_rendering_attributes().set_intensity(0, 1, 1);
 
124
 
 
125
  set_text( "1up" );
 
126
 
 
127
  create_effect();
 
128
 
 
129
  get_level_globals().play_music("music/1-up.ogg", 1);
 
130
} // floating_score::one_up()
 
131
 
 
132
/*----------------------------------------------------------------------------*/
 
133
/**
 
134
 * \brief Set the displayed text.
 
135
 * \param text The text to display.
 
136
 */
 
137
void ptb::floating_score::set_score( const std::string& text )
 
138
{
 
139
  set_text( text );
 
140
 
 
141
  create_effect();
 
142
} // floating_score::set_score()
 
143
 
 
144
/*----------------------------------------------------------------------------*/
 
145
/**
 
146
 * \brief Create the effects on the score.
 
147
 */
 
148
void ptb::floating_score::create_effect()
 
149
{
 
150
  const bear::universe::position_type pos(get_center_of_mass());
93
151
  fit_to_text();
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 );
 
154
 
 
155
  bear::decorative_effect* decoration_effect = new bear::decorative_effect;
 
156
 
 
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);
 
161
 
 
162
  new_item(*decoration_effect);
 
163
} // floating_score::create_effect()
 
164
 
 
165
/*----------------------------------------------------------------------------*/
 
166
/**
 
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.
 
169
 */
 
170
void ptb::floating_score::give_one_up_to( unsigned int player_index ) const
 
171
{
 
172
  player* p = util::find_player( get_level_globals(), player_index );
 
173
 
 
174
  if ( p != NULL )
 
175
    {
 
176
      floating_score* s = new floating_score;
 
177
 
 
178
      new_item(*s);
 
179
 
 
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);
 
183
    }
 
184
} // floating_score::give_one_up_to()