4
Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
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.
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
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
20
contact: plee-the-bear@gamned.org
22
Please add the tag [PTB] in the subject of your mails.
26
* \brief Implementation of the ptb::ray class.
27
* \author S�bastien Angibaud
29
#include "ptb/item/player/ray.hpp"
31
BASE_ITEM_EXPORT( ray, ptb )
33
/*----------------------------------------------------------------------------*/
34
const bear::universe::coordinate_type
35
ptb::ray::s_right_move_force_in_idle = 160000;
37
const bear::universe::coordinate_type
38
ptb::ray::s_right_move_force_in_jump = 64000;
40
const bear::universe::coordinate_type
41
ptb::ray::s_right_move_force_in_vertical_jump = 32000;
43
const bear::universe::coordinate_type
44
ptb::ray::s_right_move_force_in_run = 280000;
46
const bear::universe::coordinate_type
47
ptb::ray::s_right_move_force_in_swimming = 64000;
49
const bear::universe::coordinate_type
50
ptb::ray::s_right_move_force_min_in_walk = 24000;
52
const bear::universe::coordinate_type
53
ptb::ray::s_right_move_force_max_in_walk = 81000;
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;
61
const bear::universe::coordinate_type ptb::ray::s_speed_to_run = 170;
63
const double ptb::ray::s_mass = 80;
64
const double ptb::ray::s_density = 1.5;
66
/*----------------------------------------------------------------------------*/
74
set_density(s_density);
78
/*----------------------------------------------------------------------------*/
86
/*----------------------------------------------------------------------------*/
88
* \brief Load the media required by this class.
90
void ptb::ray::pre_cache()
95
get_level_globals().load_model("model/player/ray.cm");
98
get_level_globals().load_image("gfx/plee/misc.png");
101
/*----------------------------------------------------------------------------*/
103
* \brief Do post creation actions.
105
void ptb::ray::build()
109
set_model_actor( get_level_globals().get_model("model/player/ray.cm") );
110
start_action_model("idle");
111
m_wait_state_number = 0;
114
/*---------------------------------------------------------------------------*/
116
* \brief Indicate that Ray starts to cry.
118
void ptb::ray::start_cry()
123
} // ray::start_cry()
125
/*---------------------------------------------------------------------------*/
127
* \brief Indicate that Ray stops to cry.
129
void ptb::ray::stop_cry()
136
/*----------------------------------------------------------------------------*/
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.
143
bool ptb::ray::set_bool_field
144
( const std::string& name, bool value )
148
if (name == "ray.is_crying")
154
result = super::set_bool_field(name, value);
157
} // ray::set_bool_field()
159
/*---------------------------------------------------------------------------*/
161
* \brief Choose a wait state.
163
void ptb::ray::choose_wait_state()
166
super::choose_wait_state();
167
} // ray::choose_wait_state()
169
/*---------------------------------------------------------------------------*/
171
* \brief Choose an idle state.
173
void ptb::ray::choose_idle_state()
176
start_action_model("cry");
178
super::choose_idle_state();
179
} // ray::choose_idle_state()
181
/*---------------------------------------------------------------------------*/
183
* \brief Choose a walk state.
185
void ptb::ray::choose_walk_state()
188
start_action_model("walk-cry");
190
super::choose_walk_state();
191
} // ray::choose_walk_state()
193
/*---------------------------------------------------------------------------*/
195
* \brief Get the impulse force for vertical jumps.
197
bear::universe::coordinate_type
198
ptb::ray::get_vertical_jump_force() const
200
return s_vertical_jump_force;
201
} // ray::get_vertical_jump_force()
203
/*---------------------------------------------------------------------------*/
205
* \brief Get the right force in idle state.
207
bear::universe::coordinate_type ptb::ray::get_right_move_force_in_idle() const
209
return s_right_move_force_in_idle;
210
} // ray::get_right_move_force_in_idle()
212
/*---------------------------------------------------------------------------*/
214
* \brief Get the right force in jump state.
216
bear::universe::coordinate_type ptb::ray::get_right_move_force_in_jump() const
218
return s_right_move_force_in_jump;
219
} // ray::get_right_move_force_in_jump()
221
/*---------------------------------------------------------------------------*/
223
* \brief Get the right force in vertical jump state.
225
bear::universe::coordinate_type
226
ptb::ray::get_right_move_force_in_vertical_jump() const
228
return s_right_move_force_in_vertical_jump;
229
} // ray::get_right_move_force_in_vertical_jump()
231
/*---------------------------------------------------------------------------*/
233
* \brief Get the right force in run state.
235
bear::universe::coordinate_type ptb::ray::get_right_move_force_in_run() const
237
return s_right_move_force_in_run;
238
} // ray::get_right_move_force_in_run()
240
/*---------------------------------------------------------------------------*/
242
* \brief Get the right force in swimming state.
244
bear::universe::coordinate_type
245
ptb::ray::get_right_move_force_in_swimming() const
247
return s_right_move_force_in_swimming;
248
} // ray::get_right_move_force_in_swimming()
250
/*---------------------------------------------------------------------------*/
252
* \brief Get the right force in walk state.
254
bear::universe::coordinate_type
255
ptb::ray::get_right_move_force_in_walk() const
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)
261
} // ray::get_right_move_force_in_walk()
263
/*---------------------------------------------------------------------------*/
265
* \brief Get the impulse force when ray jumps.
267
bear::universe::coordinate_type
268
ptb::ray::get_jump_force() const
271
} // ray::get_jump_force()
273
/*---------------------------------------------------------------------------*/
275
* \brief Get the impulse force when ray jumps in float state.
277
bear::universe::coordinate_type
278
ptb::ray::get_jump_force_in_float() const
280
return s_jump_force_in_float;
281
} // ray::get_jump_force_in_float()
283
/*---------------------------------------------------------------------------*/
285
* \brief Get the speed over which Ray is running.
287
bear::universe::coordinate_type
288
ptb::ray::get_speed_to_run() const
290
return s_speed_to_run;
291
} // ray::get_speed_to_run()
293
/*----------------------------------------------------------------------------*/
295
* \brief Give a string representation of the item.
296
* \param str (out) The result of the convertion.
298
void ptb::ray::to_string( std::string& str ) const
300
std::ostringstream oss;
302
super::to_string(str);
313
} // player::to_string()
315
/*---------------------------------------------------------------------------*/
317
* \brief Get the sprite of the soul.
319
bear::visual::sprite ptb::ray::get_soul_sprite() const
321
return bear::visual::sprite
322
( get_level_globals().auto_sprite("gfx/plee/misc.png", "soul effet"));
323
} // ray::get_soul_sprite()
325
/*---------------------------------------------------------------------------*/
327
* \brief Update action when Ray changes its cry status.
329
void ptb::ray::update_cry_action()
331
if ( ( m_current_state == player::idle_state ) ||
332
( m_current_state == player::wait_state ) )
334
else if ( m_current_state == player::walk_state )
336
} // ray::update_cry_action()
338
/*----------------------------------------------------------------------------*/
340
* \brief Export the methods of the class.
342
void ptb::ray::init_exported_methods()
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()
350
/*----------------------------------------------------------------------------*/
351
TEXT_INTERFACE_IMPLEMENT_METHOD_LIST( ptb::ray )