~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/player/code/plee.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
/*
 
2
  Plee the Bear
 
3
 
 
4
  Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
 
5
 
 
6
  This program is free software; you can redistribute it and/or modify it
 
7
  under the terms of the GNU General Public License as published by the
 
8
  Free Software Foundation; either version 2 of the License, or (at your
 
9
  option) any later version.
 
10
 
 
11
  This program is distributed in the hope that it will be useful, but WITHOUT
 
12
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
13
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
14
  more details.
 
15
 
 
16
  You should have received a copy of the GNU General Public License along
 
17
  with this program; if not, write to the Free Software Foundation, Inc.,
 
18
  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 
 
20
  contact: plee-the-bear@gamned.org
 
21
 
 
22
  Please add the tag [PTB] in the subject of your mails.
 
23
*/
 
24
/**
 
25
 * \file plee.cpp
 
26
 * \brief Implementation of the ptb::plee class.
 
27
 * \author S�bastien Angibaud
 
28
 */
 
29
#include "ptb/item/player/plee.hpp"
 
30
#include "generic_items/decorative_item.hpp"
 
31
 
 
32
BASE_ITEM_EXPORT( plee, ptb )
 
33
 
 
34
/*----------------------------------------------------------------------------*/
 
35
const bear::universe::coordinate_type
 
36
ptb::plee::s_right_move_force_in_idle = 200000;
 
37
 
 
38
const bear::universe::coordinate_type
 
39
ptb::plee::s_right_move_force_in_jump = 100000;
 
40
 
 
41
const bear::universe::coordinate_type
 
42
ptb::plee::s_right_move_force_in_vertical_jump = 50000;
 
43
 
 
44
const bear::universe::coordinate_type
 
45
ptb::plee::s_right_move_force_in_run = 450000;
 
46
 
 
47
const bear::universe::coordinate_type
 
48
ptb::plee::s_right_move_force_in_swimming = 80000;
 
49
 
 
50
const bear::universe::coordinate_type
 
51
ptb::plee::s_right_move_force_min_in_walk = 50000;
 
52
 
 
53
const bear::universe::coordinate_type
 
54
ptb::plee::s_right_move_force_max_in_walk = 300000;
 
55
 
 
56
const bear::universe::coordinate_type ptb::plee::s_jump_force = 2600000;
 
57
const bear::universe::coordinate_type
 
58
ptb::plee::s_jump_force_in_float = 11500000;
 
59
const bear::universe::coordinate_type
 
60
ptb::plee::s_vertical_jump_force = 8500000;
 
61
 
 
62
const bear::universe::coordinate_type ptb::plee::s_speed_to_run = 580;
 
63
 
 
64
const double ptb::plee::s_mass = 100;
 
65
const double ptb::plee::s_density = 1.5;
 
66
 
 
67
/*----------------------------------------------------------------------------*/
 
68
/**
 
69
 * \brief Constructor.
 
70
 */
 
71
ptb::plee::plee()
 
72
{
 
73
  set_mass(s_mass);
 
74
  set_density(s_density);
 
75
  set_size( 50, 110 );
 
76
} // plee::plee()
 
77
 
 
78
/*----------------------------------------------------------------------------*/
 
79
/**
 
80
 * \brief Load the media required by this class.
 
81
 */
 
82
void ptb::plee::pre_cache()
 
83
{
 
84
  super::pre_cache();
 
85
 
 
86
  // plee
 
87
  get_level_globals().load_model("model/player/plee.cm");
 
88
  get_level_globals().load_model("model/player/plee-alt.cm");
 
89
 
 
90
  // halo for soul
 
91
  get_level_globals().load_image("gfx/plee/misc.png");
 
92
 
 
93
  // Bash cap
 
94
  get_level_globals().load_animation("animation/plee/bath-cap.canim");
 
95
} // plee::pre_cache()
 
96
 
 
97
/*----------------------------------------------------------------------------*/
 
98
/**
 
99
 * \brief Do post creation actions.
 
100
 */
 
101
void ptb::plee::build()
 
102
{
 
103
  super::build();
 
104
 
 
105
  if ( get_index() == 1)
 
106
    set_model_actor( get_level_globals().get_model("model/player/plee.cm") );
 
107
  else
 
108
    set_model_actor
 
109
      ( get_level_globals().get_model("model/player/plee-alt.cm") );
 
110
 
 
111
  start_action_model("idle");
 
112
 
 
113
  m_wait_state_number = 3;
 
114
  m_has_main_hat = true;
 
115
  m_has_hat = true;
 
116
} // plee::build()
 
117
 
 
118
/*---------------------------------------------------------------------------*/
 
119
/**
 
120
 * \brief Get the impulse force for vertical jumps.
 
121
 */
 
122
bear::universe::coordinate_type
 
123
ptb::plee::get_vertical_jump_force() const
 
124
{
 
125
  return s_vertical_jump_force;
 
126
} // plee::get_vertical_jump_force()
 
127
 
 
128
/*----------------------------------------------------------------------------*/
 
129
/**
 
130
 * \brief Call a function.
 
131
 * \param name The function to call.
 
132
 */
 
133
void ptb::plee::execute_function( const std::string& name )
 
134
{
 
135
  if ( name == "take_new_hat" )
 
136
    apply_take_new_hat();
 
137
  else if ( name == "start_take_hat" )
 
138
    apply_start_take_hat();
 
139
  else
 
140
    super::execute_function(name);
 
141
} // plee::execute_function()
 
142
 
 
143
/*---------------------------------------------------------------------------*/
 
144
/**
 
145
 * \brief Progress in the water.
 
146
 * \param elapsed_time Elapsed time since the last call.
 
147
 */
 
148
void ptb::plee::progress_in_water(bear::universe::time_type elapsed_time)
 
149
{
 
150
  super::progress_in_water(elapsed_time);
 
151
 
 
152
  if ( m_has_main_hat )
 
153
    take_out_hat();
 
154
} // plee::progress_in_water()
 
155
 
 
156
/*---------------------------------------------------------------------------*/
 
157
/**
 
158
 * \brief Get the right force in idle state.
 
159
 */
 
160
bear::universe::coordinate_type ptb::plee::get_right_move_force_in_idle() const
 
161
{
 
162
  return s_right_move_force_in_idle;
 
163
} // plee::get_right_move_force_in_idle()
 
164
 
 
165
/*---------------------------------------------------------------------------*/
 
166
/**
 
167
 * \brief Get the right force in jump state.
 
168
 */
 
169
bear::universe::coordinate_type ptb::plee::get_right_move_force_in_jump() const
 
170
{
 
171
  return s_right_move_force_in_jump;
 
172
} // plee::get_right_move_force_in_jump()
 
173
 
 
174
/*---------------------------------------------------------------------------*/
 
175
/**
 
176
 * \brief Get the right force in vertical jump state.
 
177
 */
 
178
bear::universe::coordinate_type
 
179
ptb::plee::get_right_move_force_in_vertical_jump() const
 
180
{
 
181
  return s_right_move_force_in_vertical_jump;
 
182
} // plee::get_right_move_force_in_vertical_jump()
 
183
 
 
184
/*---------------------------------------------------------------------------*/
 
185
/**
 
186
 * \brief Get the right force in run state.
 
187
 */
 
188
bear::universe::coordinate_type ptb::plee::get_right_move_force_in_run() const
 
189
{
 
190
  return s_right_move_force_in_run;
 
191
} // plee::get_right_move_force_in_run()
 
192
 
 
193
/*---------------------------------------------------------------------------*/
 
194
/**
 
195
 * \brief Get the right force in swimming state.
 
196
 */
 
197
bear::universe::coordinate_type
 
198
ptb::plee::get_right_move_force_in_swimming() const
 
199
{
 
200
  return s_right_move_force_in_swimming;
 
201
} // plee::get_right_move_force_in_swimming()
 
202
 
 
203
/*---------------------------------------------------------------------------*/
 
204
/**
 
205
 * \brief Get the right force in walk state.
 
206
 */
 
207
bear::universe::coordinate_type
 
208
ptb::plee::get_right_move_force_in_walk() const
 
209
{
 
210
  return s_right_move_force_min_in_walk +
 
211
    std::min(m_run_time,s_time_to_run)*
 
212
    (s_right_move_force_max_in_walk - s_right_move_force_min_in_walk)
 
213
    / s_time_to_run;
 
214
} // plee::get_right_move_force_in_walk()
 
215
 
 
216
/*---------------------------------------------------------------------------*/
 
217
/**
 
218
 * \brief Get the impulse force when ray jumps.
 
219
 */
 
220
bear::universe::coordinate_type
 
221
ptb::plee::get_jump_force() const
 
222
{
 
223
  return s_jump_force;
 
224
} // plee::get_jump_force()
 
225
 
 
226
/*---------------------------------------------------------------------------*/
 
227
/**
 
228
 * \brief Get the impulse force when ray jumps in float state.
 
229
 */
 
230
bear::universe::coordinate_type
 
231
ptb::plee::get_jump_force_in_float() const
 
232
{
 
233
  return s_jump_force_in_float;
 
234
} // plee::get_jump_force_in_float()
 
235
 
 
236
/*---------------------------------------------------------------------------*/
 
237
/**
 
238
 * \brief Get the speed over which Plee is running.
 
239
 */
 
240
bear::universe::coordinate_type
 
241
ptb::plee::get_speed_to_run() const
 
242
{
 
243
  return s_speed_to_run;
 
244
} // plee::get_speed_to_run()
 
245
 
 
246
/*---------------------------------------------------------------------------*/
 
247
/**
 
248
 * \brief Do one iteration when the player stay in the state idle.
 
249
 * \param elapsed_time Elapsed time since the last call.
 
250
 */
 
251
void ptb::plee::progress_continue_idle
 
252
( bear::universe::time_type elapsed_time )
 
253
{
 
254
  if ( get_current_action_name() != "take_hat" )
 
255
    {
 
256
      if ( !m_has_hat )
 
257
        start_action_model("take_hat");
 
258
      else if ( ( !m_has_main_hat ) &&
 
259
                ( !is_in_environment(bear::universe::water_environment) ) )
 
260
        start_action_model("take_hat");
 
261
    }
 
262
} // plee::progress_continue_idle()
 
263
 
 
264
/*---------------------------------------------------------------------------*/
 
265
/**
 
266
 * \brief Get the sprite of the soul.
 
267
 */
 
268
bear::visual::sprite ptb::plee::get_soul_sprite() const
 
269
{
 
270
  return bear::visual::sprite
 
271
    ( get_level_globals().auto_sprite("gfx/plee/misc.png", "soul effet"));
 
272
} // plee::get_soul_sprite()
 
273
 
 
274
/*----------------------------------------------------------------------------*/
 
275
/**
 
276
 * \brief Plee starts to take a new hat.
 
277
 */
 
278
void ptb::plee::apply_start_take_hat()
 
279
{
 
280
  if ( !m_has_hat )
 
281
    {
 
282
      if ( is_in_environment(bear::universe::water_environment) )
 
283
        set_global_substitute
 
284
          ("new_hat", new bear::visual::animation
 
285
           (get_level_globals().get_animation
 
286
            ("animation/plee/bath-cap.canim") ) );
 
287
      else
 
288
        set_global_substitute
 
289
            ("new_hat", new bear::visual::animation
 
290
             (get_level_globals().get_animation("animation/plee/cap.canim")) );
 
291
    }
 
292
  else if ( ( !m_has_main_hat ) &&
 
293
            ( !is_in_environment(bear::universe::water_environment) ) )
 
294
    set_global_substitute
 
295
        ("new_hat", new bear::visual::animation
 
296
         ( get_level_globals().get_animation("animation/plee/cap.canim") ) );
 
297
  else
 
298
    set_global_substitute("new_hat", new bear::visual::animation() );
 
299
} // plee::apply_start_take_hat()
 
300
 
 
301
/*----------------------------------------------------------------------------*/
 
302
/**
 
303
 * \brief Plee takes a new hat.
 
304
 */
 
305
void ptb::plee::apply_take_new_hat()
 
306
{
 
307
  if ( !m_has_hat )
 
308
    {
 
309
      m_has_hat = true;
 
310
 
 
311
      if ( is_in_environment(bear::universe::water_environment) )
 
312
        set_global_substitute
 
313
          ("hat", new bear::visual::animation
 
314
           (get_level_globals().get_animation
 
315
            ("animation/plee/bath-cap.canim") ) );
 
316
      else
 
317
        {
 
318
          m_has_main_hat = true;
 
319
          set_global_substitute
 
320
            ("hat", new bear::visual::animation
 
321
             (get_level_globals().get_animation("animation/plee/cap.canim")) );
 
322
        }
 
323
    }
 
324
  else if ( ( !m_has_main_hat ) &&
 
325
            ( !is_in_environment(bear::universe::water_environment) ) )
 
326
    {
 
327
      m_has_main_hat = true;
 
328
      m_has_hat = true;
 
329
      set_global_substitute
 
330
        ("hat", new bear::visual::animation
 
331
         ( get_level_globals().get_animation("animation/plee/cap.canim") ) );
 
332
    }
 
333
} // plee::apply_take_new_hat()
 
334
 
 
335
/*----------------------------------------------------------------------------*/
 
336
/**
 
337
 * \brief Take out the hat.
 
338
 */
 
339
void ptb::plee::take_out_hat()
 
340
{
 
341
  bear::engine::model_mark_placement m;
 
342
 
 
343
  if ( get_mark_placement("hat", m) )
 
344
    {
 
345
      m_has_main_hat = false;
 
346
      m_has_hat = false;
 
347
 
 
348
      bear::universe::position_type pos( m.get_position() );
 
349
      bear::decorative_item* item;
 
350
      item = new bear::decorative_item();
 
351
 
 
352
      bear::visual::sprite spr =
 
353
        get_action(get_current_action_name())->get_mark
 
354
        (m.get_mark_id()).get_main_animation()->get_sprite();
 
355
 
 
356
      spr.combine( get_rendering_attributes() );
 
357
      item->set_sprite(spr);
 
358
 
 
359
      item->set_z_position(get_z_position() + m.get_depth_position());
 
360
      item->set_phantom(false);
 
361
      item->set_can_move_items(false);
 
362
      item->set_artificial(true);
 
363
      item->set_kill_when_leaving(true);
 
364
      item->set_density(0.4);
 
365
      item->set_mass(2);
 
366
 
 
367
      new_item( *item );
 
368
 
 
369
      item->set_center_of_mass(pos);
 
370
 
 
371
      set_global_substitute
 
372
        ("hat", new bear::visual::animation() );
 
373
    }
 
374
} // plee::take_out_hat()