~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/ray.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 ray.cpp
 
26
 * \brief Implementation of the ptb::ray class.
 
27
 * \author S�bastien Angibaud
 
28
 */
 
29
#include "ptb/item/player/ray.hpp"
 
30
 
 
31
BASE_ITEM_EXPORT( ray, ptb )
 
32
 
 
33
/*----------------------------------------------------------------------------*/
 
34
const bear::universe::coordinate_type
 
35
ptb::ray::s_right_move_force_in_idle = 160000;
 
36
 
 
37
const bear::universe::coordinate_type
 
38
ptb::ray::s_right_move_force_in_jump = 64000;
 
39
 
 
40
const bear::universe::coordinate_type
 
41
ptb::ray::s_right_move_force_in_vertical_jump = 32000;
 
42
 
 
43
const bear::universe::coordinate_type
 
44
ptb::ray::s_right_move_force_in_run = 280000;
 
45
 
 
46
const bear::universe::coordinate_type
 
47
ptb::ray::s_right_move_force_in_swimming = 64000;
 
48
 
 
49
const bear::universe::coordinate_type
 
50
ptb::ray::s_right_move_force_min_in_walk = 24000;
 
51
 
 
52
const bear::universe::coordinate_type
 
53
ptb::ray::s_right_move_force_max_in_walk = 81000;
 
54
 
 
55
const bear::universe::coordinate_type ptb::ray::s_jump_force = 1500000;
 
56
const bear::universe::coordinate_type
 
57
ptb::ray::s_jump_force_in_float = 9200000;
 
58
const bear::universe::coordinate_type
 
59
ptb::ray::s_vertical_jump_force = 5000000;
 
60
 
 
61
const bear::universe::coordinate_type ptb::ray::s_speed_to_run = 170;
 
62
 
 
63
const double ptb::ray::s_mass = 80;
 
64
const double ptb::ray::s_density = 1.5;
 
65
 
 
66
/*----------------------------------------------------------------------------*/
 
67
/**
 
68
 * \brief Constructor.
 
69
 */
 
70
ptb::ray::ray()
 
71
  : m_cry(false)
 
72
{
 
73
  set_mass(s_mass);
 
74
  set_density(s_density);
 
75
  set_size( 50, 110 );
 
76
} // ray::ray()
 
77
 
 
78
/*----------------------------------------------------------------------------*/
 
79
/**
 
80
 * \brief Destructor.
 
81
 */
 
82
ptb::ray::~ray()
 
83
{
 
84
} // ray::~ray()
 
85
 
 
86
/*----------------------------------------------------------------------------*/
 
87
/**
 
88
 * \brief Load the media required by this class.
 
89
 */
 
90
void ptb::ray::pre_cache()
 
91
{
 
92
  super::pre_cache();
 
93
 
 
94
  // ray
 
95
  get_level_globals().load_model("model/player/ray.cm");
 
96
 
 
97
  // halo for soul
 
98
  get_level_globals().load_image("gfx/plee/misc.png");
 
99
} // ray::pre_cache()
 
100
 
 
101
/*----------------------------------------------------------------------------*/
 
102
/**
 
103
 * \brief Do post creation actions.
 
104
 */
 
105
void ptb::ray::build()
 
106
{
 
107
  super::build();
 
108
 
 
109
  set_model_actor( get_level_globals().get_model("model/player/ray.cm") );
 
110
  start_action_model("idle");
 
111
  m_wait_state_number = 0;
 
112
} // ray::build()
 
113
 
 
114
/*---------------------------------------------------------------------------*/
 
115
/**
 
116
 * \brief Indicate that Ray starts to cry.
 
117
 */
 
118
void ptb::ray::start_cry()
 
119
{
 
120
  m_cry = true;
 
121
 
 
122
  update_cry_action();
 
123
} // ray::start_cry()
 
124
 
 
125
/*---------------------------------------------------------------------------*/
 
126
/**
 
127
 * \brief Indicate that Ray stops to cry.
 
128
 */
 
129
void ptb::ray::stop_cry()
 
130
{
 
131
  m_cry = false;
 
132
 
 
133
  update_cry_action();
 
134
} // ray::stop_cry()
 
135
 
 
136
/*----------------------------------------------------------------------------*/
 
137
/**
 
138
 * \brief Set a field of type <bool>.
 
139
 * \param name The name of the field.
 
140
 * \param value The new value of the field.
 
141
 * \return false if the field "name" is unknow, true otherwise.
 
142
 */
 
143
bool ptb::ray::set_bool_field
 
144
( const std::string& name, bool value )
 
145
{
 
146
  bool result = true;
 
147
 
 
148
  if (name == "ray.is_crying")
 
149
    {
 
150
      m_cry = value;
 
151
      update_cry_action();
 
152
    }
 
153
  else
 
154
    result = super::set_bool_field(name, value);
 
155
 
 
156
  return result;
 
157
} // ray::set_bool_field()
 
158
 
 
159
/*---------------------------------------------------------------------------*/
 
160
/**
 
161
 * \brief Choose a wait state.
 
162
 */
 
163
void ptb::ray::choose_wait_state()
 
164
{
 
165
  if ( !m_cry )
 
166
    super::choose_wait_state();
 
167
} // ray::choose_wait_state()
 
168
 
 
169
/*---------------------------------------------------------------------------*/
 
170
/**
 
171
 * \brief Choose an idle state.
 
172
 */
 
173
void ptb::ray::choose_idle_state()
 
174
{
 
175
  if ( m_cry )
 
176
    start_action_model("cry");
 
177
  else
 
178
    super::choose_idle_state();
 
179
} // ray::choose_idle_state()
 
180
 
 
181
/*---------------------------------------------------------------------------*/
 
182
/**
 
183
 * \brief Choose a walk state.
 
184
 */
 
185
void ptb::ray::choose_walk_state()
 
186
{
 
187
  if ( m_cry )
 
188
    start_action_model("walk-cry");
 
189
  else
 
190
    super::choose_walk_state();
 
191
} // ray::choose_walk_state()
 
192
 
 
193
/*---------------------------------------------------------------------------*/
 
194
/**
 
195
 * \brief Get the impulse force for vertical jumps.
 
196
 */
 
197
bear::universe::coordinate_type
 
198
ptb::ray::get_vertical_jump_force() const
 
199
{
 
200
  return s_vertical_jump_force;
 
201
} // ray::get_vertical_jump_force()
 
202
 
 
203
/*---------------------------------------------------------------------------*/
 
204
/**
 
205
 * \brief Get the right force in idle state.
 
206
 */
 
207
bear::universe::coordinate_type ptb::ray::get_right_move_force_in_idle() const
 
208
{
 
209
  return s_right_move_force_in_idle;
 
210
} // ray::get_right_move_force_in_idle()
 
211
 
 
212
/*---------------------------------------------------------------------------*/
 
213
/**
 
214
 * \brief Get the right force in jump state.
 
215
 */
 
216
bear::universe::coordinate_type ptb::ray::get_right_move_force_in_jump() const
 
217
{
 
218
  return s_right_move_force_in_jump;
 
219
} // ray::get_right_move_force_in_jump()
 
220
 
 
221
/*---------------------------------------------------------------------------*/
 
222
/**
 
223
 * \brief Get the right force in vertical jump state.
 
224
 */
 
225
bear::universe::coordinate_type
 
226
ptb::ray::get_right_move_force_in_vertical_jump() const
 
227
{
 
228
  return s_right_move_force_in_vertical_jump;
 
229
} // ray::get_right_move_force_in_vertical_jump()
 
230
 
 
231
/*---------------------------------------------------------------------------*/
 
232
/**
 
233
 * \brief Get the right force in run state.
 
234
 */
 
235
bear::universe::coordinate_type ptb::ray::get_right_move_force_in_run() const
 
236
{
 
237
  return s_right_move_force_in_run;
 
238
} // ray::get_right_move_force_in_run()
 
239
 
 
240
/*---------------------------------------------------------------------------*/
 
241
/**
 
242
 * \brief Get the right force in swimming state.
 
243
 */
 
244
bear::universe::coordinate_type
 
245
ptb::ray::get_right_move_force_in_swimming() const
 
246
{
 
247
  return s_right_move_force_in_swimming;
 
248
} // ray::get_right_move_force_in_swimming()
 
249
 
 
250
/*---------------------------------------------------------------------------*/
 
251
/**
 
252
 * \brief Get the right force in walk state.
 
253
 */
 
254
bear::universe::coordinate_type
 
255
ptb::ray::get_right_move_force_in_walk() const
 
256
{
 
257
  return s_right_move_force_min_in_walk +
 
258
    std::min(m_run_time,s_time_to_run)*
 
259
    (s_right_move_force_max_in_walk - s_right_move_force_min_in_walk)
 
260
    / s_time_to_run;
 
261
} // ray::get_right_move_force_in_walk()
 
262
 
 
263
/*---------------------------------------------------------------------------*/
 
264
/**
 
265
 * \brief Get the impulse force when ray jumps.
 
266
 */
 
267
bear::universe::coordinate_type
 
268
ptb::ray::get_jump_force() const
 
269
{
 
270
  return s_jump_force;
 
271
} // ray::get_jump_force()
 
272
 
 
273
/*---------------------------------------------------------------------------*/
 
274
/**
 
275
 * \brief Get the impulse force when ray jumps in float state.
 
276
 */
 
277
bear::universe::coordinate_type
 
278
ptb::ray::get_jump_force_in_float() const
 
279
{
 
280
  return s_jump_force_in_float;
 
281
} // ray::get_jump_force_in_float()
 
282
 
 
283
/*---------------------------------------------------------------------------*/
 
284
/**
 
285
 * \brief Get the speed over which Ray is running.
 
286
 */
 
287
bear::universe::coordinate_type
 
288
ptb::ray::get_speed_to_run() const
 
289
{
 
290
  return s_speed_to_run;
 
291
} // ray::get_speed_to_run()
 
292
 
 
293
/*----------------------------------------------------------------------------*/
 
294
/**
 
295
 * \brief Give a string representation of the item.
 
296
 * \param str (out) The result of the convertion.
 
297
 */
 
298
void ptb::ray::to_string( std::string& str ) const
 
299
{
 
300
  std::ostringstream oss;
 
301
 
 
302
  super::to_string(str);
 
303
 
 
304
  oss << "cry: ";
 
305
  if (m_cry )
 
306
    oss << "true";
 
307
  else
 
308
    oss << "false";
 
309
 
 
310
  oss << "\n";
 
311
 
 
312
  str += oss.str();
 
313
} // player::to_string()
 
314
 
 
315
/*---------------------------------------------------------------------------*/
 
316
/**
 
317
 * \brief Get the sprite of the soul.
 
318
 */
 
319
bear::visual::sprite ptb::ray::get_soul_sprite() const
 
320
{
 
321
  return bear::visual::sprite
 
322
    ( get_level_globals().auto_sprite("gfx/plee/misc.png", "soul effet"));
 
323
} // ray::get_soul_sprite()
 
324
 
 
325
/*---------------------------------------------------------------------------*/
 
326
/**
 
327
 * \brief Update action when Ray changes its cry status.
 
328
 */
 
329
void ptb::ray::update_cry_action()
 
330
{
 
331
  if ( ( m_current_state == player::idle_state ) ||
 
332
       ( m_current_state == player::wait_state ) )
 
333
    choose_idle_state();
 
334
  else if ( m_current_state == player::walk_state )
 
335
    choose_walk_state();
 
336
} // ray::update_cry_action()
 
337
 
 
338
/*----------------------------------------------------------------------------*/
 
339
/**
 
340
 * \brief Export the methods of the class.
 
341
 */
 
342
void ptb::ray::init_exported_methods()
 
343
{
 
344
  TEXT_INTERFACE_CONNECT_METHOD_0
 
345
    ( ptb::ray, start_cry, void );
 
346
  TEXT_INTERFACE_CONNECT_METHOD_0
 
347
    ( ptb::ray, stop_cry, void );
 
348
} // god::init_exported_methods()
 
349
 
 
350
/*----------------------------------------------------------------------------*/
 
351
TEXT_INTERFACE_IMPLEMENT_METHOD_LIST( ptb::ray )