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::plee class.
27
* \author S�bastien Angibaud
29
#include "ptb/item/player/plee.hpp"
30
#include "generic_items/decorative_item.hpp"
32
BASE_ITEM_EXPORT( plee, ptb )
34
/*----------------------------------------------------------------------------*/
35
const bear::universe::coordinate_type
36
ptb::plee::s_right_move_force_in_idle = 200000;
38
const bear::universe::coordinate_type
39
ptb::plee::s_right_move_force_in_jump = 100000;
41
const bear::universe::coordinate_type
42
ptb::plee::s_right_move_force_in_vertical_jump = 50000;
44
const bear::universe::coordinate_type
45
ptb::plee::s_right_move_force_in_run = 450000;
47
const bear::universe::coordinate_type
48
ptb::plee::s_right_move_force_in_swimming = 80000;
50
const bear::universe::coordinate_type
51
ptb::plee::s_right_move_force_min_in_walk = 50000;
53
const bear::universe::coordinate_type
54
ptb::plee::s_right_move_force_max_in_walk = 300000;
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;
62
const bear::universe::coordinate_type ptb::plee::s_speed_to_run = 580;
64
const double ptb::plee::s_mass = 100;
65
const double ptb::plee::s_density = 1.5;
67
/*----------------------------------------------------------------------------*/
74
set_density(s_density);
78
/*----------------------------------------------------------------------------*/
80
* \brief Load the media required by this class.
82
void ptb::plee::pre_cache()
87
get_level_globals().load_model("model/player/plee.cm");
88
get_level_globals().load_model("model/player/plee-alt.cm");
91
get_level_globals().load_image("gfx/plee/misc.png");
94
get_level_globals().load_animation("animation/plee/bath-cap.canim");
95
} // plee::pre_cache()
97
/*----------------------------------------------------------------------------*/
99
* \brief Do post creation actions.
101
void ptb::plee::build()
105
if ( get_index() == 1)
106
set_model_actor( get_level_globals().get_model("model/player/plee.cm") );
109
( get_level_globals().get_model("model/player/plee-alt.cm") );
111
start_action_model("idle");
113
m_wait_state_number = 3;
114
m_has_main_hat = true;
118
/*---------------------------------------------------------------------------*/
120
* \brief Get the impulse force for vertical jumps.
122
bear::universe::coordinate_type
123
ptb::plee::get_vertical_jump_force() const
125
return s_vertical_jump_force;
126
} // plee::get_vertical_jump_force()
128
/*----------------------------------------------------------------------------*/
130
* \brief Call a function.
131
* \param name The function to call.
133
void ptb::plee::execute_function( const std::string& name )
135
if ( name == "take_new_hat" )
136
apply_take_new_hat();
137
else if ( name == "start_take_hat" )
138
apply_start_take_hat();
140
super::execute_function(name);
141
} // plee::execute_function()
143
/*---------------------------------------------------------------------------*/
145
* \brief Progress in the water.
146
* \param elapsed_time Elapsed time since the last call.
148
void ptb::plee::progress_in_water(bear::universe::time_type elapsed_time)
150
super::progress_in_water(elapsed_time);
152
if ( m_has_main_hat )
154
} // plee::progress_in_water()
156
/*---------------------------------------------------------------------------*/
158
* \brief Get the right force in idle state.
160
bear::universe::coordinate_type ptb::plee::get_right_move_force_in_idle() const
162
return s_right_move_force_in_idle;
163
} // plee::get_right_move_force_in_idle()
165
/*---------------------------------------------------------------------------*/
167
* \brief Get the right force in jump state.
169
bear::universe::coordinate_type ptb::plee::get_right_move_force_in_jump() const
171
return s_right_move_force_in_jump;
172
} // plee::get_right_move_force_in_jump()
174
/*---------------------------------------------------------------------------*/
176
* \brief Get the right force in vertical jump state.
178
bear::universe::coordinate_type
179
ptb::plee::get_right_move_force_in_vertical_jump() const
181
return s_right_move_force_in_vertical_jump;
182
} // plee::get_right_move_force_in_vertical_jump()
184
/*---------------------------------------------------------------------------*/
186
* \brief Get the right force in run state.
188
bear::universe::coordinate_type ptb::plee::get_right_move_force_in_run() const
190
return s_right_move_force_in_run;
191
} // plee::get_right_move_force_in_run()
193
/*---------------------------------------------------------------------------*/
195
* \brief Get the right force in swimming state.
197
bear::universe::coordinate_type
198
ptb::plee::get_right_move_force_in_swimming() const
200
return s_right_move_force_in_swimming;
201
} // plee::get_right_move_force_in_swimming()
203
/*---------------------------------------------------------------------------*/
205
* \brief Get the right force in walk state.
207
bear::universe::coordinate_type
208
ptb::plee::get_right_move_force_in_walk() const
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)
214
} // plee::get_right_move_force_in_walk()
216
/*---------------------------------------------------------------------------*/
218
* \brief Get the impulse force when ray jumps.
220
bear::universe::coordinate_type
221
ptb::plee::get_jump_force() const
224
} // plee::get_jump_force()
226
/*---------------------------------------------------------------------------*/
228
* \brief Get the impulse force when ray jumps in float state.
230
bear::universe::coordinate_type
231
ptb::plee::get_jump_force_in_float() const
233
return s_jump_force_in_float;
234
} // plee::get_jump_force_in_float()
236
/*---------------------------------------------------------------------------*/
238
* \brief Get the speed over which Plee is running.
240
bear::universe::coordinate_type
241
ptb::plee::get_speed_to_run() const
243
return s_speed_to_run;
244
} // plee::get_speed_to_run()
246
/*---------------------------------------------------------------------------*/
248
* \brief Do one iteration when the player stay in the state idle.
249
* \param elapsed_time Elapsed time since the last call.
251
void ptb::plee::progress_continue_idle
252
( bear::universe::time_type elapsed_time )
254
if ( get_current_action_name() != "take_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");
262
} // plee::progress_continue_idle()
264
/*---------------------------------------------------------------------------*/
266
* \brief Get the sprite of the soul.
268
bear::visual::sprite ptb::plee::get_soul_sprite() const
270
return bear::visual::sprite
271
( get_level_globals().auto_sprite("gfx/plee/misc.png", "soul effet"));
272
} // plee::get_soul_sprite()
274
/*----------------------------------------------------------------------------*/
276
* \brief Plee starts to take a new hat.
278
void ptb::plee::apply_start_take_hat()
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") ) );
288
set_global_substitute
289
("new_hat", new bear::visual::animation
290
(get_level_globals().get_animation("animation/plee/cap.canim")) );
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") ) );
298
set_global_substitute("new_hat", new bear::visual::animation() );
299
} // plee::apply_start_take_hat()
301
/*----------------------------------------------------------------------------*/
303
* \brief Plee takes a new hat.
305
void ptb::plee::apply_take_new_hat()
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") ) );
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")) );
324
else if ( ( !m_has_main_hat ) &&
325
( !is_in_environment(bear::universe::water_environment) ) )
327
m_has_main_hat = true;
329
set_global_substitute
330
("hat", new bear::visual::animation
331
( get_level_globals().get_animation("animation/plee/cap.canim") ) );
333
} // plee::apply_take_new_hat()
335
/*----------------------------------------------------------------------------*/
337
* \brief Take out the hat.
339
void ptb::plee::take_out_hat()
341
bear::engine::model_mark_placement m;
343
if ( get_mark_placement("hat", m) )
345
m_has_main_hat = false;
348
bear::universe::position_type pos( m.get_position() );
349
bear::decorative_item* item;
350
item = new bear::decorative_item();
352
bear::visual::sprite spr =
353
get_action(get_current_action_name())->get_mark
354
(m.get_mark_id()).get_main_animation()->get_sprite();
356
spr.combine( get_rendering_attributes() );
357
item->set_sprite(spr);
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);
369
item->set_center_of_mass(pos);
371
set_global_substitute
372
("hat", new bear::visual::animation() );
374
} // plee::take_out_hat()