4
Copyright (C) 2005-2009 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 Julien Jorge
29
#include "ptb/item/plee/plee.hpp"
33
#include "engine/game.hpp"
34
#include "engine/world.hpp"
35
#include "engine/message/transition_effect_message.hpp"
37
#include "ptb/defines.hpp"
38
#include "ptb/monster.hpp"
39
#include "ptb/player_action.hpp"
41
#include "ptb/item/shared_camera.hpp"
42
#include "ptb/item/small_honeypot.hpp"
43
#include "ptb/item/stone/air_fire_stone.hpp"
44
#include "ptb/item/stone/air_fire_water_stone.hpp"
45
#include "ptb/item/stone/air_water_stone.hpp"
46
#include "ptb/item/stone/air_stone.hpp"
47
#include "ptb/item/stone/water_fire_stone.hpp"
48
#include "ptb/item/stone/water_stone.hpp"
49
#include "ptb/item/stone/fire_stone.hpp"
50
#include "ptb/item/azelnut.hpp"
51
#include "ptb/item/plee/state_roar.hpp"
52
#include "ptb/item/plee/state_walk.hpp"
53
#include "ptb/item/plee/state_idle.hpp"
54
#include "ptb/item/plee/state_jump.hpp"
55
#include "ptb/item/plee/state_fall.hpp"
56
#include "ptb/item/plee/state_dead.hpp"
57
#include "ptb/item/plee/state_game_over.hpp"
58
#include "ptb/item/plee/state_run.hpp"
59
#include "ptb/item/plee/state_slap.hpp"
60
#include "ptb/item/plee/state_start_jump.hpp"
61
#include "ptb/item/plee/state_vertical_jump.hpp"
62
#include "ptb/item/plee/state_look_upward.hpp"
63
#include "ptb/item/plee/state_crouch.hpp"
64
#include "ptb/item/plee/state_captive.hpp"
65
#include "ptb/item/plee/state_throw.hpp"
66
#include "ptb/item/plee/state_maintain.hpp"
67
#include "ptb/item/plee/state_wait.hpp"
68
#include "ptb/item/plee/state_start_cling.hpp"
69
#include "ptb/item/plee/state_cling.hpp"
70
#include "ptb/item/plee/state_clung_jump.hpp"
71
#include "ptb/item/plee/state_start_hang.hpp"
72
#include "ptb/item/plee/state_hang.hpp"
73
#include "ptb/item/plee/state_sink.hpp"
74
#include "ptb/item/plee/state_swimming.hpp"
75
#include "ptb/item/plee/state_float.hpp"
76
#include "ptb/item/plee/state_injured.hpp"
78
#include "ptb/transition_effect/game_over_effect.hpp"
79
#include "ptb/transition_effect/invincibility_effect.hpp"
81
BASE_ITEM_IMPLEMENT( plee, ptb )
83
/*----------------------------------------------------------------------------*/
84
const double ptb::plee::s_max_oxygen = 10000;
85
const double ptb::plee::s_max_fire_gauge = 10000;
86
const double ptb::plee::s_max_ice_gauge = 10000;
87
const double ptb::plee::s_mass = 100;
88
const double ptb::plee::s_density = 2;
90
const unsigned int ptb::plee::s_states_cardinality = 26;
91
const unsigned int ptb::plee::s_gauges_cardinality = 3;
92
const int ptb::plee::s_speed_to_run = 580;
93
const double ptb::plee::s_oxygen_loss_speed = 200;
94
const double ptb::plee::s_oxygen_inspiration_speed = 1500;
95
const double ptb::plee::s_fire_loss_speed = 200;
96
const double ptb::plee::s_fire_increase_speed = 1500;
97
const double ptb::plee::s_ice_loss_speed = 200;
98
const double ptb::plee::s_ice_increase_speed = 1500;
100
const bear::universe::size_type ptb::plee::s_max_halo_height = 64;
101
const bear::universe::size_type ptb::plee::s_max_halo_hand_width = 35;
103
const bear::universe::time_type ptb::plee::s_time_to_crouch = 0.5;
104
const bear::universe::time_type ptb::plee::s_time_to_look_upward = 0.5;
105
const bear::universe::time_type ptb::plee::s_time_to_wait = 3;
106
const bear::universe::time_type ptb::plee::s_time_to_jump = 1;
107
const bear::universe::time_type ptb::plee::s_time_to_run = 1.2;
108
const bear::universe::time_type ptb::plee::s_time_to_start_throw = 0.34;
109
const bear::universe::time_type ptb::plee::s_max_time_to_cling = 0.3;
110
const bear::universe::time_type ptb::plee::s_max_time_to_hang = 1;
111
const bear::universe::time_type ptb::plee::s_max_time_air_float = 1;
113
/*----------------------------------------------------------------------------*/
115
* \brief Constructor.
117
ptb::plee::get_instance_message::get_instance_message()
118
: m_plee_instance(NULL)
121
} // get_instance_message::get_instance_message()
123
/*----------------------------------------------------------------------------*/
125
* \brief Re-initialise the message.
127
void ptb::plee::get_instance_message::clear()
129
m_plee_instance = NULL;
130
} // get_instance_message::clear()
132
/*----------------------------------------------------------------------------*/
134
* \brief Apply the message to a player.
135
* \param that The player to apply the message to.
137
bool ptb::plee::get_instance_message::apply_to( plee& that )
139
m_plee_instance = &that;
141
} // get_instance_message::apply_to()
143
/*----------------------------------------------------------------------------*/
145
* \brief Get the instance of the player.
148
ptb::plee::get_instance_message::get_instance() const
150
return m_plee_instance;
151
} // get_instance_message::get_instance()
158
/*----------------------------------------------------------------------------*/
160
* \brief Constructor.
163
: m_current_state(roar_state), m_progress(&plee::progress_roar),
164
m_last_visual_time(0),
165
m_status_look_upward(false), m_status_crouch(false), m_can_cling(false),
166
m_halo_animation(NULL), m_halo_hand_animation(NULL),
167
m_move_right(false), m_move_left(false),
168
m_right_move_force(0),
169
m_index(0), m_nb_bottom_contact(0),
170
m_marionette(false), m_animation_to_throw(NULL),
171
m_hot_spot_position(0, 0), m_hot_spot_minimum(0, 0),
172
m_hot_spot_maximum(0, 0), m_hot_spot_balance_move(0, 0)
175
set_speaker_item(this);
177
set_density(s_density);
182
set_spot_minimum(-150, -250);
183
set_spot_maximum(150, 300);
184
set_spot_balance_move(3, 15);
186
m_offensive_force = 10;
188
if ( get_index() == 1 )
189
m_monster_type = monster::player_1_monster;
191
m_monster_type = monster::player_2_monster;
192
m_offensive_phase = false;
193
m_offensive_coefficients[normal_attack] = 1;
195
m_gauges.resize(s_gauges_cardinality);
196
m_gauges[oxygen_gauge] = new gauge(s_max_oxygen);
197
m_gauges[fire_gauge] = new gauge(s_max_fire_gauge);
198
m_gauges[ice_gauge] = new gauge(s_max_ice_gauge);
200
save_position( get_center_of_mass() );
201
m_last_bottom_left = bear::universe::position_type(0,0);
203
m_invincible_time = 0;
206
m_states.resize(s_states_cardinality);
207
m_states[walk_state] = new state_walk(this);
208
m_states[idle_state] = new state_idle(this);
209
m_states[jump_state] = new state_jump(this);
210
m_states[fall_state] = new state_fall(this);
211
m_states[dead_state] = new state_dead(this);
212
m_states[game_over_state] = new state_game_over(this);
213
m_states[roar_state] = new state_roar(this);
214
m_states[run_state] = new state_run(this);
215
m_states[slap_state] = new state_slap(this);
216
m_states[start_jump_state] = new state_start_jump(this);
217
m_states[vertical_jump_state] = new state_vertical_jump(this);
218
m_states[look_upward_state] = new state_look_upward(this);
219
m_states[crouch_state] = new state_crouch(this);
220
m_states[captive_state] = new state_captive(this);
221
m_states[throw_state] = new state_throw(this);
222
m_states[wait_state] = new state_wait(this);
223
m_states[start_cling_state] = new state_start_cling(this);
224
m_states[cling_state] = new state_cling(this);
225
m_states[clung_jump_state] = new state_clung_jump(this);
226
m_states[start_hang_state] = new state_start_hang(this);
227
m_states[hang_state] = new state_hang(this);
228
m_states[swimming_state] = new state_swimming(this);
229
m_states[sink_state] = new state_sink(this);
230
m_states[float_state] = new state_float(this);
231
m_states[maintain_state] = new state_maintain(this);
232
m_states[injured_state] = new state_injured(this);
235
/*----------------------------------------------------------------------------*/
243
for (i=0; i!=s_states_cardinality; ++i)
246
for (i=0; i!=s_gauges_cardinality; ++i)
249
if ( m_halo_animation )
250
delete m_halo_animation;
252
if ( m_halo_hand_animation )
253
delete m_halo_hand_animation;
255
if ( m_animation_to_throw )
257
delete m_animation_to_throw;
258
m_animation_to_throw = NULL;
262
/*---------------------------------------------------------------------------*/
264
* \brief Do one iteration in the progression of the item.
265
* \param elapsed_time Elapsed time since the last call.
267
void ptb::plee::progress( bear::universe::time_type elapsed_time )
269
// THIS CONDITION MUST BE DONE IN FIRST
270
if ( ! m_marionette )
271
progress_input_reader(elapsed_time);
273
super::progress(elapsed_time);
275
m_state_time += elapsed_time;
276
m_run_time += elapsed_time;
279
progress_air_float(elapsed_time);
281
progress_invincibility(elapsed_time);
287
if ( m_progress != NULL )
288
(this->*m_progress)(elapsed_time);
291
progress_spot( elapsed_time );
292
progress_gauges( elapsed_time );
293
update_orientation();
296
if ( ( m_current_state == plee::maintain_state ) ||
297
( m_current_state == plee::throw_state ) )
298
m_halo_hand_animation->next(elapsed_time);
300
if ( m_animation_to_throw != NULL )
301
m_animation_to_throw->next(elapsed_time);
304
m_last_bottom_left = get_bottom_left();
305
m_can_throw_power[air_attack] = true;
306
m_can_throw_power[fire_attack] = true;
307
m_can_throw_power[water_attack] = true;
308
} // plee::progress()
310
/*----------------------------------------------------------------------------*/
312
* \brief Get the sprite representing the item.
313
* \param visuals (out) The sprites of the item, and their positions.
316
ptb::plee::get_visual( std::list<bear::engine::scene_visual>& visuals ) const
318
get_visuals_without_invincibility(visuals);
320
std::list< std::list<bear::engine::scene_visual> >::const_iterator it;
322
for ( it = m_last_visuals.begin(); it != m_last_visuals.end(); ++it )
324
std::list<bear::engine::scene_visual>::const_iterator it2;
325
for (it2 = it->begin(); it2 != it->end(); ++it2 )
326
visuals.push_front(*it2);
328
} // plee::get_visual()
330
/*----------------------------------------------------------------------------*/
332
* \brief Load the media required by this class.
334
void ptb::plee::pre_cache()
337
get_level_globals().load_model("model/plee/plee.cm");
339
// halo for vertical jump
340
get_level_globals().load_animation("animation/plee/halo.canim");
341
get_level_globals().load_animation("animation/plee/halo_hand.canim");
344
get_level_globals().load_animation("animation/powerup/life_bonus/run.canim");
345
get_level_globals().load_animation
346
("animation/powerup/life_bonus/jump.canim");
349
get_level_globals().load_animation("animation/powerup/small_fire.canim");
350
get_level_globals().load_animation("animation/powerup/small_air.canim");
351
get_level_globals().load_animation("animation/powerup/small_water.canim");
354
get_level_globals().load_model("model/stones/stone.cm");
355
get_level_globals().load_model("model/stones/air_stone.cm");
356
get_level_globals().load_model("model/stones/water_stone.cm");
357
get_level_globals().load_model("model/stones/fire_stone.cm");
358
get_level_globals().load_model("model/stones/air_fire_stone.cm");
359
get_level_globals().load_model("model/stones/air_water_stone.cm");
360
get_level_globals().load_model("model/stones/water_fire_stone.cm");
361
get_level_globals().load_model("model/stones/air_fire_water_stone.cm");
362
get_level_globals().load_animation("animation/stones/sliver_1.canim");
363
get_level_globals().load_animation("animation/stones/sliver_2.canim");
364
get_level_globals().load_animation("animation/stones/sliver_3.canim");
365
get_level_globals().load_animation("animation/stones/sliver_4.canim");
366
get_level_globals().load_animation("animation/stones/sliver_5.canim");
367
} // plee::pre_cache()
369
/*----------------------------------------------------------------------------*/
371
* \brief Do post creation actions.
373
void ptb::plee::build()
377
game_variables::set_lives_count(m_index, 3);
379
set_model_actor( get_level_globals().get_model("model/plee/plee.cm") );
382
m_monster_type = monster::player_1_monster;
385
m_monster_type = monster::player_2_monster;
386
get_rendering_attributes().set_intensity(1, 1, 0.7);
390
save_position( get_center_of_mass() );
391
start_action_model("idle");
393
bear::engine::level_globals& glob = get_level_globals();
395
m_halo_animation = new bear::visual::animation
396
( glob.get_animation("animation/plee/halo.canim") );
398
m_halo_hand_animation = new bear::visual::animation
399
( glob.get_animation("animation/plee/halo_hand.canim") );
401
get_level().add_interest_around(this);
403
m_can_throw_power[air_attack] = true;
404
m_can_throw_power[fire_attack] = true;
405
m_can_throw_power[water_attack] = true;
408
/*----------------------------------------------------------------------------*/
410
* \brief Tell if the item is correctly initialized.
412
bool ptb::plee::is_valid() const
414
return (m_index != 0) && super::is_valid();
415
} // player::is_valid()
417
/*----------------------------------------------------------------------------*/
419
* \brief Set a field of type <unsigned integer>.
420
* \param name The name of the field.
421
* \param value The new value of the field.
422
* \return false if the field "name" is unknow, true otherwise.
424
bool ptb::plee::set_u_integer_field
425
( const std::string& name, unsigned int value )
432
result = super::set_u_integer_field(name, value);
435
} // player::set_u_integer_field()
437
/*----------------------------------------------------------------------------*/
439
* \brief Save the position of the plee.
440
* \param p The center of mass to remember.
442
void ptb::plee::save_position( const bear::universe::position_type& p )
444
m_saved_position = p;
445
} // plee::save_position()
447
/*----------------------------------------------------------------------------*/
449
* \brief Tell to Plee to start an action.
450
* \param a The action to start.
452
void ptb::plee::start_action( player_action::value_type a )
456
case player_action::idle : break;
457
case player_action::move_left : break;
458
case player_action::move_right : break;
459
case player_action::jump :
460
m_states[m_current_state]->do_jump(); break;
461
case player_action::get_camera : do_get_camera(); break;
462
case player_action::slap :
463
m_states[m_current_state]->do_slap(); break;
464
case player_action::look_upward : do_start_look_upward(); break;
465
case player_action::crouch : do_start_crouch(); break;
466
case player_action::drop : do_start_drop(); break;
467
case player_action::chain : break;
468
case player_action::unchain : break;
469
case player_action::throw_stone : do_start_throw(); break;
470
case player_action::die : apply_die(); break;
471
case player_action::roar : start_action_model("roar"); break;
472
case player_action::action_null: break;
474
claw::logger << claw::log_warning << "Action ignored (start): " << a
477
} // plee::start_action()
479
/*----------------------------------------------------------------------------*/
481
* \brief Tell to the plee to do an action.
482
* \param elapsed_time How long the action is done.
483
* \param a The action to do.
485
void ptb::plee::do_action
486
( bear::universe::time_type elapsed_time, player_action::value_type a )
490
case player_action::idle : set_state(idle_state); break;
491
case player_action::move_left :
492
m_states[m_current_state]->do_move_left(); break;
493
case player_action::move_right :
494
m_states[m_current_state]->do_move_right(); break;
495
case player_action::jump : break;
496
case player_action::get_camera : break;
497
case player_action::slap : break;
498
case player_action::look_upward :
499
m_states[m_current_state]->do_continue_look_upward(); break;
500
case player_action::crouch :
501
m_states[m_current_state]->do_continue_crouch(); break;
502
case player_action::drop : break;
503
case player_action::chain :
504
m_states[m_current_state]->chain(); break;
505
case player_action::unchain :
506
m_states[m_current_state]->unchain(); break;
507
case player_action::throw_stone : break;
508
case player_action::die : break;
509
case player_action::action_null: break;
511
claw::logger << claw::log_warning << "Action ignored: " << a
514
} // plee::do_action()
516
/*----------------------------------------------------------------------------*/
518
* \brief Tell to plee to stop an action.
519
* \param a The action to stop.
521
void ptb::plee::stop_action( player_action::value_type a )
525
case player_action::idle : break;
526
case player_action::move_left : break;
527
case player_action::move_right : break;
528
case player_action::jump :
529
m_states[m_current_state]->do_stop_vertical_jump(); break;
530
case player_action::get_camera : break;
531
case player_action::slap : break;
532
case player_action::look_upward : do_stop_look_upward(); break;
533
case player_action::crouch :
534
do_stop_crouch(); break;
535
case player_action::throw_stone :
536
m_states[m_current_state]->do_stop_throw(); break;
537
case player_action::drop :
538
m_states[m_current_state]->do_stop_throw(); break;
539
case player_action::chain : break;
540
case player_action::unchain : break;
541
case player_action::die : break;
542
case player_action::action_null: break;
544
claw::logger << claw::log_warning << "Action ignored (stop): " << a
547
} // plee::stop_action()
549
/*----------------------------------------------------------------------------*/
551
* \brief Start a new action of model.
553
void ptb::plee::start_action_model(const std::string& action)
555
start_model_action(action);
556
} // plee::start_action_model()
558
/*----------------------------------------------------------------------------*/
560
* \brief Give a gauge.
561
* \param t The type of the gauge
563
const ptb::gauge* ptb::plee::get_gauge(gauge_type t) const
565
if ( (unsigned int)t >= s_gauges_cardinality )
567
claw::logger << claw::log_verbose << "It is not a valid gauge_type."
573
} // plee::get_gauge()
575
/*----------------------------------------------------------------------------*/
577
* \brief Give the ratio of the length of preparation of the jump.
579
bear::universe::time_type ptb::plee::get_jump_time_ratio() const
581
return m_jump_time_ratio;
582
} // plee::get_jump_time_ratio()
584
/*----------------------------------------------------------------------------*/
586
* \brief Updtae the ratio of the preparation of throw state.
588
void ptb::plee::update_throw_time_ratio()
590
m_throw_time_ratio = m_state_time / s_time_to_start_throw;
591
} // plee::update_throw_time_ratio()
593
/*----------------------------------------------------------------------------*/
595
* \brief Set the value of throw_down.
596
* \param value The state of throw_down.
598
void ptb::plee::set_throw_down(bool value)
600
m_throw_down = value;
601
} // plee::set_throw_down()
603
/*----------------------------------------------------------------------------*/
605
* \brief Start to throw an azelnut
607
void ptb::plee::throw_azelnut()
609
m_current_object = azelnut_object;
610
m_animation_to_throw = new bear::visual::animation
611
( get_level_globals().get_animation
612
("animation/owl/azelnut.canim") );
613
m_states[m_current_state]->do_start_throw();
614
} // plee::throw_azelnut()
616
/*----------------------------------------------------------------------------*/
618
* \brief Set the value of throw_up.
619
* \param value The state of throw_up.
621
void ptb::plee::set_throw_up(bool value)
624
} // plee::set_throw_up()
626
/*----------------------------------------------------------------------------*/
628
* \brief Indicates if Plee is a marionette.
630
bool ptb::plee::is_a_marionette() const
633
} // plee::is_a_marionette()
635
/*----------------------------------------------------------------------------*/
637
* \brief Turn on/off the marionette state of Plee.
638
* \param b The new value of the state.
640
void ptb::plee::set_marionette( bool b )
643
} // plee::set_marionette()
645
/*----------------------------------------------------------------------------*/
647
* \brief Turn on/off the air_float status of Plee.
648
* \param b The new value of the state.
650
void ptb::plee::set_air_float( bool b )
653
m_air_float_time = 0;
654
} // plee::set_air_float()
656
/*----------------------------------------------------------------------------*/
658
* \brief Set the look up status.
660
void ptb::plee::set_status_look_upward(bool status)
662
m_status_look_upward = status;
663
} // plee::set_status_look_upward()
665
/*----------------------------------------------------------------------------*/
667
* \brief Give the look up status.
669
bool ptb::plee::get_status_look_upward() const
671
return m_status_look_upward;
672
} // plee::get_status_look_upward()
674
/*----------------------------------------------------------------------------*/
676
* \brief Set the crouch status.
678
void ptb::plee::set_status_crouch(bool status)
680
m_status_crouch = status;
681
} // plee::set_status_crouch()
683
/*----------------------------------------------------------------------------*/
685
* \brief Give the crouch status.
687
bool ptb::plee::get_status_crouch() const
689
return m_status_crouch;
690
} // plee::get_status_crouch()
692
/*----------------------------------------------------------------------------*/
694
* \brief Make the plee start to look up.
696
void ptb::plee::do_start_look_upward()
698
m_status_look_upward = true;
699
m_look_upward_time = 0;
700
m_states[m_current_state]->do_look_upward();
701
} // plee::do_start_look_upward()
703
/*----------------------------------------------------------------------------*/
705
* \brief Make the plee start to crouch.
707
void ptb::plee::do_start_crouch()
709
m_status_crouch = true;
711
m_states[m_current_state]->do_crouch();
712
} // plee::do_start_crouch()
714
/*----------------------------------------------------------------------------*/
716
* \brief Make the plee start to crouch.
718
void ptb::plee::do_start_throw()
720
if ( ( game_variables::get_stones_count(m_index) > 0 )
721
&& m_air_stones.empty() )
723
m_current_object = stone_object;
725
if ( game_variables::get_air_power(m_index) )
726
if ( game_variables::get_fire_power(m_index) )
727
if ( game_variables::get_water_power(m_index) )
728
m_animation_to_throw = new bear::visual::animation
729
( get_level_globals().get_animation
730
("animation/stones/air_fire_water_stone.canim") );
732
m_animation_to_throw = new bear::visual::animation
733
( get_level_globals().get_animation
734
("animation/stones/air_fire_stone.canim") );
736
if ( game_variables::get_water_power(m_index) )
737
m_animation_to_throw = new bear::visual::animation
738
( get_level_globals().get_animation
739
("animation/stones/air_water_stone.canim") );
741
m_animation_to_throw = new bear::visual::animation
742
( get_level_globals().get_animation
743
("animation/stones/air_stone.canim") );
745
if ( game_variables::get_fire_power(m_index) )
746
if ( game_variables::get_water_power(m_index) )
747
m_animation_to_throw = new bear::visual::animation
748
( get_level_globals().get_animation
749
("animation/stones/water_fire_stone.canim") );
751
m_animation_to_throw = new bear::visual::animation
752
( get_level_globals().get_animation
753
("animation/stones/fire_stone.canim") );
755
if ( game_variables::get_water_power(m_index) )
756
m_animation_to_throw = new bear::visual::animation
757
( get_level_globals().get_animation
758
("animation/stones/water_stone.canim") );
760
m_animation_to_throw = new bear::visual::animation
761
( get_level_globals().get_animation
762
("animation/stones/stone.canim") );
764
m_states[m_current_state]->do_start_throw();
768
} // plee::do_start_throw()
770
/*----------------------------------------------------------------------------*/
772
* \brief Make the plee start to drop.
774
void ptb::plee::do_start_drop()
777
m_states[m_current_state]->do_start_drop();
778
} // plee::do_start_drop()
780
/*----------------------------------------------------------------------------*/
782
* \brief Set if Plee can cling.
783
* \param status The new status.
785
void ptb::plee::set_can_cling(bool status)
787
m_can_cling = status;
788
} // plee::set_can_cling()
790
/*----------------------------------------------------------------------------*/
792
* \brief Plee receives energy.
794
* \param energy The energy received.
796
void ptb::plee::receive_energy(double energy)
800
if ( m_energy > game_variables::get_max_energy(m_index) )
801
m_energy = game_variables::get_max_energy(m_index);
802
} // plee::receive_energy()
804
/*----------------------------------------------------------------------------*/
806
* \brief Set the invincible status.
807
* \param invincible The new invincible status.
809
void ptb::plee::set_invincible(const bool invincible)
811
super::set_invincible(invincible);
815
m_invincible_time = 0;
816
m_last_visual_time = 0;
817
m_last_visuals.clear();
819
bear::engine::transition_effect_message<invincibility_effect> msg;
820
get_level_globals().send_message
821
( PTB_TRANSITION_EFFECT_DEFAULT_TARGET_NAME, msg );
823
} // plee::set_invincible()
825
/*----------------------------------------------------------------------------*/
827
* \brief Plee receives oxygen.
829
* \param oxygen The oxygen received.
831
void ptb::plee::receive_oxygen(double oxygen)
833
m_gauges[oxygen_gauge]->add_value(oxygen);
834
} // plee::receive_oxygen()
836
/*----------------------------------------------------------------------------*/
838
* \brief Add a air_stone in the air stone set.
840
* \param s The stone to add.
842
void ptb::plee::add_air_stone(ptb::stone* s)
844
m_air_stones.insert(s);
845
} // plee::add_air_stone()
847
/*----------------------------------------------------------------------------*/
849
* \brief Remove a air_stone in the air stone set.
851
* \param s The stone to remove.
853
void ptb::plee::remove_air_stone( ptb::stone* s)
855
std::set< ptb::stone* >::iterator it;
856
it = m_air_stones.find(s);
858
if ( it != m_air_stones.end() )
859
m_air_stones.erase(it);
860
} // plee::remove_air_stone()
862
/*----------------------------------------------------------------------------*/
864
* \brief Indicates if Plee can throw a given power.
865
* \param p The status.
866
* \param a The corresponding attack
868
void ptb::plee::can_throw_power( bool b, monster::attack_type a)
870
m_can_throw_power[a] = b;
871
} // plee::can_throw_power()
873
/*----------------------------------------------------------------------------*/
875
* \brief Get the coordinates of the point to target to (for camera or active
878
bear::universe::position_type ptb::plee::hot_spot() const
880
bear::universe::position_type p;
882
bear::universe::size_type w,h;
883
get_action("idle")->get_max_size(w,h);
884
const bear::universe::size_box_type half_plee( w / 2, h / 2 );
886
if ( get_rendering_attributes().is_mirrored() )
888
p = get_bottom_right();
893
p = get_bottom_left();
899
return p + m_hot_spot_position;
900
} // player::hot_spot()
902
/*----------------------------------------------------------------------------*/
904
* \brief Get the index of this player.
906
unsigned int ptb::plee::get_index() const
909
} // player::get_index()
911
/*----------------------------------------------------------------------------*/
913
* \brief Set the index of this player.
914
* \param index The index of the player.
916
void ptb::plee::set_index( unsigned int index )
919
set_name( player_name(index) );
920
set_player_index(index);
921
} // player::set_index()
923
/*----------------------------------------------------------------------------*/
925
* \brief Get the name of the player associated to an index.
926
* \param player_index The index of the player.
928
std::string ptb::plee::player_name( unsigned int player_index )
930
std::ostringstream oss;
931
oss << "player_" << player_index;
934
} // player::player_name()
936
/*----------------------------------------------------------------------------*/
938
* \brief Set the minimum acceptable value for the position of the hot spot.
939
* \param x Minimum value on the X-axis.
940
* \param y Minimum value on the Y-axis.
942
void ptb::plee::set_spot_minimum
943
( bear::universe::coordinate_type x, bear::universe::coordinate_type y )
945
m_hot_spot_minimum.set
946
( std::min(x, m_hot_spot_maximum.x), std::min(y, m_hot_spot_maximum.y) );
947
} // player::set_spot_minimum()
949
/*----------------------------------------------------------------------------*/
951
* \brief Set the maximum acceptable value for the position of the hot spot.
952
* \param x Maximum value on the X-axis.
953
* \param y Maximum value on the Y-axis.
955
void ptb::plee::set_spot_maximum
956
( bear::universe::coordinate_type x, bear::universe::coordinate_type y )
958
m_hot_spot_maximum.set
959
( std::max(x, m_hot_spot_minimum.x), std::max(y, m_hot_spot_minimum.y) );
960
} // player::set_spot_maximum()
962
/*----------------------------------------------------------------------------*/
964
* \brief Set the maximum movement allowed when balancing the hot spot.
965
* \param x Maximum movement on the X-axis.
966
* \param y Maximum movement on the Y-axis.
968
void ptb::plee::set_spot_balance_move
969
( bear::universe::coordinate_type x, bear::universe::coordinate_type y )
971
m_hot_spot_balance_move.set(std::abs(x), std::abs(y));
972
} // player::set_spot_balance_move()
974
/*----------------------------------------------------------------------------*/
976
* \brief Change the gap of the spot.
977
* \param gap The vector of gap.
979
void ptb::plee::add_spot_gap( const bear::universe::position_type& gap )
981
m_hot_spot_position += gap;
983
if ( m_hot_spot_position.x > m_hot_spot_maximum.x )
984
m_hot_spot_position.x = m_hot_spot_maximum.x;
985
else if ( m_hot_spot_position.x < m_hot_spot_minimum.x )
986
m_hot_spot_position.x = m_hot_spot_minimum.x;
988
if ( m_hot_spot_position.y > m_hot_spot_maximum.y )
989
m_hot_spot_position.y = m_hot_spot_maximum.y;
990
else if ( m_hot_spot_position.y < m_hot_spot_minimum.y )
991
m_hot_spot_position.y = m_hot_spot_minimum.y;
992
} // player::add_spot_gap()
994
/*----------------------------------------------------------------------------*/
996
* \brief Balance the gap of the spot.
997
* \param x Tell if we balance on the X-axis.
998
* \param y Tell if we balance on the Y-axis.
1000
void ptb::plee::balance_spot(bool x, bool y)
1004
if ( m_hot_spot_position.x > m_hot_spot_balance_move.x )
1005
m_hot_spot_position.x -= m_hot_spot_balance_move.x;
1006
else if ( m_hot_spot_position.x < -m_hot_spot_balance_move.x)
1007
m_hot_spot_position.x += m_hot_spot_balance_move.x;
1009
m_hot_spot_position.x = 0;
1014
if ( m_hot_spot_position.y > m_hot_spot_balance_move.y )
1015
m_hot_spot_position.y -= m_hot_spot_balance_move.y;
1016
else if ( m_hot_spot_position.y < -m_hot_spot_balance_move.y)
1017
m_hot_spot_position.y += m_hot_spot_balance_move.y;
1019
m_hot_spot_position.y = 0;
1021
} // player::balance_spot()
1023
/*----------------------------------------------------------------------------*/
1025
* \brief Drops one power.
1027
void ptb::plee::apply_drop()
1029
std::vector<std::string> powers;
1031
if ( game_variables::get_air_power(m_index) &&
1032
m_can_throw_power[monster::air_attack] )
1033
powers.push_back("air");
1035
if ( game_variables::get_fire_power(m_index) &&
1036
m_can_throw_power[monster::air_attack] )
1037
powers.push_back("fire");
1039
if ( game_variables::get_water_power(m_index) &&
1040
m_can_throw_power[monster::air_attack] )
1041
powers.push_back("water");
1043
if ( ! powers.empty() )
1045
unsigned int a = (unsigned int)(powers.size() * rand() / RAND_MAX);
1046
std::string drop_power;
1048
if ( a < powers.size() )
1049
drop_power = powers[a];
1051
drop_power = powers[0];
1053
if ( drop_power == "air" )
1055
m_current_object = air_honeypot_object;
1056
m_animation_to_throw = new bear::visual::animation
1057
( get_level_globals().get_animation
1058
("animation/powerup/small_air.canim") );
1059
game_variables::set_air_power(m_index, false);
1060
m_air_float = false;
1062
else if ( drop_power == "fire" )
1064
m_current_object = fire_honeypot_object;
1065
m_animation_to_throw = new bear::visual::animation
1066
( get_level_globals().get_animation
1067
("animation/powerup/small_fire.canim") );
1068
game_variables::set_fire_power(m_index, false);
1070
else if ( drop_power == "water" )
1072
m_current_object = water_honeypot_object;
1073
m_animation_to_throw = new bear::visual::animation
1074
( get_level_globals().get_animation
1075
("animation/powerup/small_water.canim") );
1076
game_variables::set_water_power(m_index, false);
1080
m_states[m_current_state]->do_start_throw();
1083
start_action_model("idle");
1084
} // plee::apply_drop()
1086
/*----------------------------------------------------------------------------*/
1088
* \brief Apply the action move_right.
1090
void ptb::plee::apply_move_right()
1092
m_move_right = true;
1093
add_internal_force( bear::universe::force_type(m_right_move_force, 0) );
1094
} // plee::apply_move_right()
1096
/*----------------------------------------------------------------------------*/
1098
* \brief Apply the action move_left.
1100
void ptb::plee::apply_move_left()
1103
add_internal_force( bear::universe::force_type(-m_right_move_force, 0) );
1104
} // plee::apply_move_left()
1106
/*----------------------------------------------------------------------------*/
1108
* \brief Apply impulsion of a jump.
1110
void ptb::plee::apply_impulse_jump()
1112
if ( m_current_state == float_state )
1113
add_internal_force( bear::universe::force_type(0, 7500000) );
1116
add_external_force( bear::universe::force_type(0, 5750000) );
1117
add_internal_force( bear::universe::force_type(0, 5750000) );
1119
} // plee::apply_impulse_jump()
1122
/*----------------------------------------------------------------------------*/
1124
* \brief Apply the action jump.
1126
void ptb::plee::apply_jump()
1128
m_right_move_force = 100000;
1129
set_state(plee::jump_state);
1130
m_progress = &plee::progress_jump;
1131
} // plee::apply_jump()
1133
/*----------------------------------------------------------------------------*/
1135
* \brief Apply the action start_jump.
1137
void ptb::plee::apply_start_jump()
1139
set_state(plee::start_jump_state);
1140
m_progress = &plee::progress_start_jump;
1141
m_halo_animation->reset();
1142
} // plee::apply_start_jump()
1144
/*----------------------------------------------------------------------------*/
1146
* \brief Apply the action vertical_jump.
1149
void ptb::plee::apply_vertical_jump()
1151
m_right_move_force = 50000;
1154
if ( m_state_time >= s_time_to_jump )
1155
m_jump_time_ratio = 1;
1157
m_jump_time_ratio = m_state_time / s_time_to_jump;
1159
set_state(plee::vertical_jump_state);
1160
m_progress = &plee::progress_vertical_jump;
1161
} // plee::apply_vertical_jump()
1163
/*----------------------------------------------------------------------------*/
1165
* \brief Apply the action fall.
1168
void ptb::plee::apply_fall()
1170
m_right_move_force = 100000;
1171
set_state(plee::fall_state);
1172
m_progress = &plee::progress_fall;
1173
} // plee::apply_fall()
1175
/*----------------------------------------------------------------------------*/
1177
* \brief Apply the action idle.
1180
void ptb::plee::apply_idle()
1182
m_right_move_force = 200000;
1183
set_state(plee::idle_state);
1184
m_progress = &plee::progress_idle;
1185
} // plee::apply_idle()
1187
/*----------------------------------------------------------------------------*/
1189
* \brief Apply the action walk.
1192
void ptb::plee::apply_walk()
1194
m_right_move_force = 200000;
1195
set_state(plee::walk_state);
1196
m_progress = &plee::progress_walk;
1197
} // plee::apply_walk()
1199
/*----------------------------------------------------------------------------*/
1201
* \brief Apply the action run.
1204
void ptb::plee::apply_run()
1206
m_right_move_force = 450000;
1207
set_state(plee::run_state);
1208
m_progress = &plee::progress_run;
1209
} // plee::apply_run()
1211
/*----------------------------------------------------------------------------*/
1213
* \brief Apply the action slap.
1216
void ptb::plee::apply_slap()
1218
m_right_move_force = 200000;
1219
set_state(plee::slap_state);
1220
m_progress = &plee::progress_slap;
1221
} // plee::apply_slap()
1223
/*----------------------------------------------------------------------------*/
1225
* \brief Turn the attack mode.
1228
void ptb::plee::apply_attack()
1230
set_offensive_phase(true);
1231
set_defensive_power(monster::normal_attack,true);
1232
} // plee::apply_attack()
1234
/*----------------------------------------------------------------------------*/
1236
* \brief Apply the action chain.
1239
void ptb::plee::apply_chain()
1241
set_state(plee::captive_state);
1242
m_progress = &plee::progress_captive;
1243
} // plee::apply_chain()
1245
/*----------------------------------------------------------------------------*/
1247
* \brief Apply the action unchain.
1250
void ptb::plee::apply_unchain()
1252
set_state(plee::idle_state);
1253
m_progress = &plee::progress_idle;
1254
} // plee::apply_unchain()
1256
/*----------------------------------------------------------------------------*/
1258
* \brief Apply the action throw.
1261
void ptb::plee::apply_throw()
1263
if ( get_current_action_name() == "throw_and_fall" )
1264
m_right_move_force = 100000;
1266
m_right_move_force = 200000;
1268
set_state(plee::throw_state);
1269
m_progress = &plee::progress_throw;
1270
} // plee::apply_throw()
1272
/*----------------------------------------------------------------------------*/
1274
* \brief Apply the action maintain.
1277
void ptb::plee::apply_maintain()
1279
if ( get_current_action_name() == "maintain_and_fall" )
1280
m_right_move_force = 100000;
1282
m_right_move_force = 200000;
1284
m_throw_time_ratio = 0;
1285
set_state(plee::maintain_state);
1286
m_progress = &plee::progress_maintain;
1287
} // plee::apply_maintain()
1289
/*----------------------------------------------------------------------------*/
1291
* \brief Throw an object.
1294
void ptb::plee::apply_throw_object()
1296
if ( m_throw_time_ratio == 0 )
1297
m_throw_time_ratio = 1;
1299
if ( m_current_object == stone_object )
1300
create_stone( get_stone_force() );
1301
else if ( m_current_object == air_honeypot_object )
1302
create_small_honeypot( get_stone_force() );
1303
else if ( m_current_object == fire_honeypot_object )
1304
create_small_honeypot( get_stone_force() );
1305
else if ( m_current_object == water_honeypot_object )
1306
create_small_honeypot( get_stone_force() );
1307
else if ( m_current_object == azelnut_object )
1310
m_current_object = none_object;
1311
if ( m_animation_to_throw != NULL )
1313
delete m_animation_to_throw;
1314
m_animation_to_throw = NULL;
1316
} // plee::apply_throw_object()
1318
/*----------------------------------------------------------------------------*/
1320
* \brief Apply the action blast_stone.
1323
void ptb::plee::apply_blast_stone()
1325
if ( ! m_air_stones.empty() )
1327
std::set<ptb::stone*> save_stones(m_air_stones);
1328
std::set<ptb::stone*>::iterator it;
1329
for ( it = save_stones.begin(); it != save_stones.end(); ++it )
1331
// the call can change the set m_air_stones
1332
(*it)->inform_new_stone();
1335
} // plee::apply_blast_stone()
1337
/*----------------------------------------------------------------------------*/
1339
* \brief Apply the action wait. *
1341
void ptb::plee::apply_wait()
1343
set_state(plee::wait_state);
1344
m_progress = &plee::progress_wait;
1345
} // plee::apply_wait()
1347
/*----------------------------------------------------------------------------*/
1349
* \brief Apply the action crouch.
1352
void ptb::plee::apply_crouch()
1354
m_right_move_force = 200000;
1355
set_state(plee::crouch_state);
1356
m_progress = &plee::progress_crouch;
1357
} // plee::apply_crouch()
1359
/*----------------------------------------------------------------------------*/
1361
* \brief Apply the action look_upward.
1364
void ptb::plee::apply_look_upward()
1366
m_right_move_force = 200000;
1367
set_state(plee::look_upward_state);
1368
m_progress = &plee::progress_look_upward;
1369
} // plee::apply_look_upward()
1371
/*----------------------------------------------------------------------------*/
1375
void ptb::plee::apply_die()
1377
game_variables::set_lives_count
1378
( m_index, game_variables::get_lives_count(m_index) - 1);
1380
if ( game_variables::get_lives_count( m_index ) == 0 )
1382
bear::engine::transition_effect_message<game_over_effect> msg;
1383
get_level_globals().send_message
1384
( PTB_TRANSITION_EFFECT_DEFAULT_TARGET_NAME, msg );
1385
start_action_model("game_over");
1390
bear::engine::transition_effect_message<bear::engine::fade_effect> msg;
1391
msg.get_effect().set_duration(0, 0.25, 0.75);
1392
msg.get_effect().set_color( 1, 1, 1 );
1393
get_level_globals().send_message
1394
( PTB_TRANSITION_EFFECT_DEFAULT_TARGET_NAME, msg );
1395
set_state(dead_state);
1396
m_progress = &plee::progress_dead;
1398
} // plee::apply_die()
1400
/*----------------------------------------------------------------------------*/
1404
void ptb::plee::apply_roar()
1406
set_state(roar_state);
1407
m_progress = &plee::progress_roar;
1408
} // plee::apply_roar()
1410
/*----------------------------------------------------------------------------*/
1412
* \brief Start the state "game over".
1414
void ptb::plee::apply_game_over()
1416
m_right_move_force = 0;
1417
set_state(game_over_state);
1418
m_progress = &plee::progress_game_over;
1419
} // plee::apply_game_over()
1421
/*----------------------------------------------------------------------------*/
1423
* \brief Start to cling.
1425
void ptb::plee::apply_start_cling()
1427
set_state(start_cling_state);
1428
m_progress = &plee::progress_start_cling;
1429
} // plee::apply_start_cling()
1431
/*----------------------------------------------------------------------------*/
1433
* \brief Plee cling.
1435
void ptb::plee::apply_cling()
1438
set_state(cling_state);
1439
m_progress = &plee::progress_cling;
1440
} // plee::apply_cling()
1442
/*----------------------------------------------------------------------------*/
1444
* \brief Plee is clung and jump.
1446
void ptb::plee::apply_clung_jump()
1448
if ( get_rendering_attributes().is_mirrored() )
1449
add_internal_force( bear::universe::force_type(5000000, 10000000) );
1451
add_internal_force( bear::universe::force_type(-5000000, 10000000) );
1452
} // plee::apply_clung_jump()
1454
/*----------------------------------------------------------------------------*/
1456
* \brief Start to hang.
1458
void ptb::plee::apply_start_hang()
1460
set_state(start_hang_state);
1461
m_progress = &plee::progress_start_hang;
1462
} // plee::apply_start_hang()
1464
/*----------------------------------------------------------------------------*/
1468
void ptb::plee::apply_hang()
1470
set_state(hang_state);
1471
m_progress = &plee::progress_hang;
1472
} // plee::apply_hang()
1474
/*----------------------------------------------------------------------------*/
1478
void ptb::plee::apply_swimming()
1480
m_right_move_force = 150000;
1481
set_state(swimming_state);
1482
m_progress = &plee::progress_swimming;
1483
} // plee::apply_swimming()
1485
/*----------------------------------------------------------------------------*/
1489
void ptb::plee::apply_sink()
1491
m_right_move_force = 150000;
1492
set_state(sink_state);
1493
m_progress = &plee::progress_sink;
1494
} // plee::apply_swimming()
1496
/*----------------------------------------------------------------------------*/
1498
* \brief Apply the action swim_up.
1501
void ptb::plee::apply_swim_up()
1503
add_internal_force( bear::universe::force_type(0, 300000) );
1504
} // plee::apply_swim_up()
1506
/*----------------------------------------------------------------------------*/
1508
* \brief Apply the action swim_down.
1511
void ptb::plee::apply_swim_down()
1513
add_internal_force( bear::universe::force_type(0,-50000) );
1514
} // plee::apply_swim_down()
1517
/*----------------------------------------------------------------------------*/
1519
* \brief Apply the action swim_down.
1522
void ptb::plee::apply_swim_jump()
1524
if ( get_rendering_attributes().is_mirrored() )
1525
add_internal_force( bear::universe::force_type(-4000000, 7000000));
1527
add_internal_force( bear::universe::force_type(4000000, 7000000));
1528
} // plee::apply_swim_down()
1530
/*----------------------------------------------------------------------------*/
1532
* \brief Apply the action float.
1535
void ptb::plee::apply_float()
1537
m_right_move_force = 150000;
1538
set_state(float_state);
1539
m_progress = &plee::progress_float;
1540
} // plee::apply_float()
1542
/*----------------------------------------------------------------------------*/
1544
* \brief Apply the action dive.
1547
void ptb::plee::apply_dive()
1549
add_internal_force( bear::universe::force_type(0, -200000));
1550
} // plee::apply_float()
1552
/*----------------------------------------------------------------------------*/
1554
* \brief Apply the action injured.
1556
void ptb::plee::apply_injured()
1558
m_right_move_force = 0;
1559
m_nb_bottom_contact = 0;
1560
set_state(plee::injured_state);
1561
m_progress = &plee::progress_injured;
1562
} // plee::apply_injured()
1564
/*----------------------------------------------------------------------------*/
1566
* \brief Call a function.
1567
* \param name The function to call.
1569
void ptb::plee::execute_function( const std::string& name )
1571
if ( name == "start_roar" )
1573
if ( name == "start_game_over" )
1575
if ( name == "start_captive" )
1577
else if ( name == "start_crouch" )
1579
else if ( name == "start_fall" )
1581
else if ( name == "start_float" )
1583
else if ( name == "start_idle" )
1585
else if ( name == "start_jump" )
1587
else if ( name == "start_look_upward" )
1588
apply_look_upward();
1589
else if ( name == "start_run" )
1591
else if ( name == "start_sink" )
1593
else if ( name == "start_slap" )
1595
else if ( name == "start_attack" )
1597
else if ( name == "start_start_cling" )
1598
apply_start_cling();
1599
else if ( name == "start_start_hang" )
1601
else if ( name == "start_cling" )
1603
else if ( name == "start_hang" )
1605
else if ( name == "start_clung_jump" )
1607
else if ( name == "start_throw" )
1609
else if ( name == "start_maintain" )
1611
else if ( name == "start_start_jump" )
1613
else if ( name == "start_swimming" )
1615
else if ( name == "start_vertical_jump" )
1616
apply_vertical_jump();
1617
else if ( name == "wait" )
1619
else if ( name == "start_walk" )
1621
else if ( name == "throw" )
1622
apply_throw_object();
1623
else if ( name == "start_injured" )
1626
super::execute_function(name);
1627
} // plee::execute_function()
1629
/*----------------------------------------------------------------------------*/
1631
* \brief Inform the item that he have no energy now.
1632
* \param attacker The attacker monster.
1634
void ptb::plee::inform_no_energy(const monster& attacker)
1637
} // plee::inform_no_energy()
1639
/*----------------------------------------------------------------------------*/
1641
* \brief The monster is injured.
1642
* \param attacker The monster attacking me.
1644
void ptb::plee::injure
1645
(const monster& attacker, const bear::universe::collision_info& info)
1647
double orientation = -1;
1649
if ( ( info.get_collision_side() ==
1650
bear::universe::zone::middle_right_zone ) ||
1651
( info.get_collision_side() ==
1652
bear::universe::zone::top_right_zone ) ||
1653
( info.get_collision_side() ==
1654
bear::universe::zone::bottom_right_zone ) )
1657
set_speed(bear::universe::speed_type(0,0));
1659
( bear::universe::force_type(orientation * 4000000, 5500000) );
1661
super::injure(attacker,info);
1663
m_states[m_current_state]->do_injured();
1664
} // ptb::plee::injure()
1666
/*----------------------------------------------------------------------------*/
1668
* \brief The monster isn't injure any more.
1670
void ptb::plee::finish_injure()
1672
super::finish_injure();
1674
m_states[m_current_state]->do_finish_injured();
1675
} // ptb::monster_item::finish_injure()
1677
/*----------------------------------------------------------------------------*/
1679
* \brief Get a given offensive coefficient.
1680
* param index The index of the attack.
1681
* param other The other monster.
1682
* param info Information on collision.
1684
unsigned int ptb::plee::get_offensive_coefficient
1685
( unsigned int index,
1686
const monster& other,
1687
const bear::universe::collision_info& info ) const
1689
unsigned int result = super::get_offensive_coefficient(index,other,info);
1691
const base_item* item = dynamic_cast<const base_item*>(&other);
1693
if ( ( item != NULL ) && ( result != 0 ) )
1695
if ( get_rendering_attributes().is_mirrored() )
1697
if ( item->get_left() >= get_left() )
1700
else if ( item->get_right() <= get_right() )
1705
} // plee::get_offensive_coefficient()
1707
/*----------------------------------------------------------------------------*/
1709
* \brief Give a string representation of the item.
1710
* \param str (out) The result of the convertion.
1712
void ptb::plee::to_string( std::string& str ) const
1714
std::ostringstream oss;
1716
super::to_string(str);
1718
oss << "oxygen_gauge: ";
1719
if ( m_gauges[oxygen_gauge]->is_activated() )
1722
oss << "not active : ";
1723
oss << m_gauges[oxygen_gauge]->get_value() << "/"
1724
<< m_gauges[oxygen_gauge]->get_max_value() << "\n";
1726
oss << "fire_gauge: ";
1727
if ( m_gauges[fire_gauge]->is_activated() )
1730
oss << "not active : ";
1731
oss << m_gauges[fire_gauge]->get_value() << "/"
1732
<< m_gauges[fire_gauge]->get_max_value() << "\n";
1734
oss << "ice_gauge: ";
1735
if ( m_gauges[ice_gauge]->is_activated() )
1738
oss << "not active : ";
1739
oss << m_gauges[ice_gauge]->get_value() << "/"
1740
<< m_gauges[ice_gauge]->get_max_value() << "\n";
1743
oss << m_states[m_current_state]->get_name();
1746
oss << get_current_action_name();
1748
oss << "can_cling: " << m_can_cling << "\n";
1749
oss << "status_look_upward: " << m_status_look_upward << "\n";
1750
oss << "status_crouch: " << m_status_crouch << "\n";
1751
oss << "powers: " << " : ";
1752
if ( game_variables::get_air_power(m_index) )
1754
if ( game_variables::get_fire_power(m_index) )
1756
if ( game_variables::get_water_power(m_index) )
1759
oss << "air_float: ";
1764
oss << " : " << m_air_float_time;
1768
} // plee::to_string()
1770
/*---------------------------------------------------------------------------*/
1772
* \brief Do one iteration in the state .
1773
* \param elapsed_time Elapsed time since the last call.
1775
void ptb::plee::progress_walk( bear::universe::time_type elapsed_time )
1779
if ( has_bottom_contact() )
1781
if ( m_last_bottom_left == get_bottom_left() )
1782
start_action_model("idle");
1785
bear::universe::speed_type speed( get_speed() );
1786
// calculate the speed in the intern axis
1787
bear::universe::coordinate_type speed_x =
1788
speed.dot_product(get_x_axis());
1790
if( std::abs(speed_x) >= s_speed_to_run )
1792
if ( m_run_time >= s_time_to_run )
1793
start_action_model("run");
1795
else if ( speed_x == 0 )
1796
start_action_model("idle");
1798
m_right_move_force =
1799
50000 + std::min(m_run_time,s_time_to_run)*(300000-50000)
1804
test_in_sky_or_swimm();
1805
} // plee::progress_walk()
1807
/*---------------------------------------------------------------------------*/
1809
* \brief Do one iteration in the state .
1810
* \param elapsed_time Elapsed time since the last call.
1812
void ptb::plee::progress_idle( bear::universe::time_type elapsed_time )
1816
if ( has_bottom_contact() )
1820
if ( m_state_time >= s_time_to_wait )
1822
std::ostringstream s;
1823
s << "wait" << (rand() % 3 + 1);
1824
start_action_model(s.str());
1828
test_in_sky_or_swimm();
1829
} // plee::progress_idle()
1831
/*---------------------------------------------------------------------------*/
1833
* \brief Do one iteration in the state .
1834
* \param elapsed_time Elapsed time since the last call.
1836
void ptb::plee::progress_jump( bear::universe::time_type elapsed_time )
1838
if ( !test_bottom_contact() )
1840
if ( is_only_in_environment(bear::universe::water_environment) )
1842
if( get_speed().y <= 0 )
1843
start_action_model("sink");
1845
start_action_model("swimming");
1847
else if ( is_in_floating() )
1848
start_action_model("float");
1849
else if( get_speed().y <= 0 )
1850
start_action_model("fall");
1852
} // plee::progress_jump()
1854
/*---------------------------------------------------------------------------*/
1856
* \brief Do one iteration in the state .
1857
* \param elapsed_time Elapsed time since the last call.
1859
void ptb::plee::progress_fall( bear::universe::time_type elapsed_time )
1861
if ( !test_bottom_contact() )
1863
if ( is_only_in_environment(bear::universe::water_environment) )
1864
if( get_speed().y <= 0 )
1865
start_action_model("sink");
1867
start_action_model("swimming");
1868
else if ( is_in_floating() )
1869
start_action_model("float");
1870
if( get_speed().y > 0 )
1871
start_action_model("jump");
1873
} // plee::progress_fall()
1875
/*---------------------------------------------------------------------------*/
1877
* \brief Do one iteration in the state .
1878
* \param elapsed_time Elapsed time since the last call.
1880
void ptb::plee::progress_dead( bear::universe::time_type elapsed_time )
1884
start_action_model("roar");
1885
} // plee::progress_dead()
1888
/*---------------------------------------------------------------------------*/
1890
* \brief Do one iteration in the state .
1891
* \param elapsed_time Elapsed time since the last call.
1893
void ptb::plee::progress_game_over( bear::universe::time_type elapsed_time )
1895
set_status_look_upward(false);
1896
set_status_crouch(false);
1897
} // plee::progress_game_over()
1899
/*---------------------------------------------------------------------------*/
1901
* \brief Do one iteration in the state .
1902
* \param elapsed_time Elapsed time since the last call.
1904
void ptb::plee::progress_roar( bear::universe::time_type elapsed_time )
1907
} // plee::progress_roar()
1909
/*---------------------------------------------------------------------------*/
1911
* \brief Do one iteration in the state .
1912
* \param elapsed_time Elapsed time since the last call.
1914
void ptb::plee::progress_run( bear::universe::time_type elapsed_time )
1916
if ( has_bottom_contact() )
1918
bear::universe::speed_type speed;
1919
speed = get_speed();
1921
// calculate the speed in the intern axis
1922
bear::universe::coordinate_type speed_x =
1923
speed.dot_product(get_x_axis());
1925
if( std::abs(speed_x) < s_speed_to_run )
1928
start_action_model("idle");
1930
start_action_model("walk");
1934
test_in_sky_or_swimm();
1935
} // plee::progress_run()
1937
/*---------------------------------------------------------------------------*/
1939
* \brief Do one iteration in the state .
1940
* \param elapsed_time Elapsed time since the last call.
1942
void ptb::plee::progress_slap( bear::universe::time_type elapsed_time )
1946
bear::universe::speed_type speed(get_speed());
1947
bear::universe::coordinate_type speed_x = speed.dot_product(get_x_axis());
1949
if ( get_current_action_name() == "slap" )
1951
if ( std::abs(speed_x) != 0 )
1952
switch_to_model_action("slap_and_walk");
1954
else if ( get_current_action_name() == "slap_and_walk")
1956
if( std::abs(speed_x) == 0 )
1957
switch_to_model_action("slap");
1960
if ( has_right_contact() )
1962
else if ( has_left_contact() )
1964
} // plee::progress_slap()
1966
/*---------------------------------------------------------------------------*/
1968
* \brief Do one iteration in the state .
1969
* \param elapsed_time Elapsed time since the last call.
1971
void ptb::plee::progress_start_jump( bear::universe::time_type elapsed_time )
1973
m_halo_animation->next(elapsed_time);
1977
if ( ! has_bottom_contact() )
1978
test_in_sky_or_swimm();
1979
} // plee::progress_start_jump()
1981
/*---------------------------------------------------------------------------*/
1983
* \brief Do one iteration in the state .
1984
* \param elapsed_time Elapsed time since the last call.
1986
void ptb::plee::progress_vertical_jump
1987
( bear::universe::time_type elapsed_time )
1989
if ( !test_bottom_contact() )
1990
if( get_speed().y <= 0 )
1991
start_action_model("fall");
1992
} // plee::progress_vertical_jump()
1994
/*---------------------------------------------------------------------------*/
1996
* \brief Do one iteration in the state .
1997
* \param elapsed_time Elapsed time since the last call.
1999
void ptb::plee::progress_crouch( bear::universe::time_type elapsed_time )
2003
if ( ! has_bottom_contact() )
2004
test_in_sky_or_swimm();
2005
} // plee::progress_crouch()
2007
/*---------------------------------------------------------------------------*/
2009
* \brief Do one iteration in the state .
2010
* \param elapsed_time Elapsed time since the last call.
2012
void ptb::plee::progress_look_upward( bear::universe::time_type elapsed_time )
2016
if ( ! has_bottom_contact() )
2017
test_in_sky_or_swimm();
2018
} // plee::progress_look_upward()
2020
/*---------------------------------------------------------------------------*/
2022
* \brief Do one iteration in the state .
2023
* \param elapsed_time Elapsed time since the last call.
2025
void ptb::plee::progress_captive( bear::universe::time_type elapsed_time )
2028
} // plee::progress_captive()
2030
/*---------------------------------------------------------------------------*/
2032
* \brief Do one iteration in the state .
2033
* \param elapsed_time Elapsed time since the last call.
2035
void ptb::plee::progress_throw( bear::universe::time_type elapsed_time )
2039
bear::universe::speed_type speed(get_speed());
2040
bear::universe::coordinate_type speed_x = speed.dot_product(get_x_axis());
2042
if ( get_current_action_name() == "throw" )
2044
if ( ! has_bottom_contact() )
2045
switch_to_model_action("throw_and_fall");
2046
else if( std::abs(speed_x) != 0 )
2047
switch_to_model_action("throw_and_walk");
2049
else if ( get_current_action_name() == "throw_and_walk")
2051
if ( ! has_bottom_contact() )
2052
switch_to_model_action("throw_and_fall");
2053
else if( std::abs(speed_x) == 0 )
2054
switch_to_model_action("throw");
2056
else if ( get_current_action_name() == "throw_and_fall")
2058
if ( has_bottom_contact() )
2060
if( std::abs(speed_x) == 0 )
2061
switch_to_model_action("throw");
2063
switch_to_model_action("throw_and_walk");
2067
if ( ( m_current_object == air_honeypot_object ) &&
2068
! m_can_throw_power[monster::air_attack] )
2070
game_variables::set_air_power(m_index, true);
2071
start_action_model("idle");
2073
if ( ( m_current_object == fire_honeypot_object ) &&
2074
! m_can_throw_power[monster::fire_attack] )
2076
game_variables::set_fire_power(m_index, true);
2077
start_action_model("idle");
2079
if ( ( m_current_object == water_honeypot_object ) &&
2080
! m_can_throw_power[monster::water_attack] )
2082
game_variables::set_water_power(m_index, true);
2083
start_action_model("idle");
2085
} // plee::progress_throw()
2087
/*---------------------------------------------------------------------------*/
2089
* \brief Do one iteration in the state .
2090
* \param elapsed_time Elapsed time since the last call.
2092
void ptb::plee::progress_maintain( bear::universe::time_type elapsed_time )
2096
bear::universe::speed_type speed(get_speed());
2097
bear::universe::coordinate_type speed_x = speed.dot_product(get_x_axis());
2099
if ( get_current_action_name() == "maintain" )
2101
if ( ! has_bottom_contact() )
2102
switch_to_model_action("maintain_and_fall");
2103
else if( std::abs(speed_x) != 0 )
2104
switch_to_model_action("maintain_and_walk");
2106
else if ( get_current_action_name() == "maintain_and_walk")
2108
if ( ! has_bottom_contact() )
2109
switch_to_model_action("maintain_and_fall");
2110
else if( std::abs(speed_x) == 0 )
2111
switch_to_model_action("maintain");
2113
else if ( get_current_action_name() == "maintain_and_fall")
2115
if ( has_bottom_contact() )
2117
if( std::abs(speed_x) == 0 )
2118
switch_to_model_action("maintain");
2120
switch_to_model_action("maintain_and_walk");
2123
} // plee::progress_maintain()
2125
/*---------------------------------------------------------------------------*/
2127
* \brief Do one iteration in the state .
2128
* \param elapsed_time Elapsed time since the last call.
2130
void ptb::plee::progress_wait( bear::universe::time_type elapsed_time )
2134
if ( ! has_bottom_contact() )
2135
test_in_sky_or_swimm();
2136
} // plee::progress_wait()
2138
/*---------------------------------------------------------------------------*/
2140
* \brief Do one iteration in the state .
2141
* \param elapsed_time Elapsed time since the last call.
2143
void ptb::plee::progress_start_cling
2144
( bear::universe::time_type elapsed_time )
2146
if ( !test_bottom_contact() )
2148
if ( ( !get_rendering_attributes().is_mirrored()
2149
&& has_right_contact() ) ||
2150
( get_rendering_attributes().is_mirrored() && has_left_contact() ) )
2152
// test if the wall can be clung
2154
start_action_model("cling");
2156
start_action_model("idle");
2159
} // plee::progress_start_cling()
2161
/*---------------------------------------------------------------------------*/
2163
* \brief Do one iteration in the state .
2164
* \param elapsed_time Elapsed time since the last call.
2166
void ptb::plee::progress_cling( bear::universe::time_type elapsed_time )
2168
if ( ! test_bottom_contact() )
2170
if ( has_top_contact() || ( ! m_can_cling ) )
2171
start_action_model("fall");
2174
bear::universe::speed_type speed = get_speed();
2184
bear::universe::force_type force
2185
( - get_mass() * get_owner().get_gravity() );
2187
if ( (get_density() != 0) &&
2188
( get_mass() != std::numeric_limits<double>::infinity() ) )
2189
force += get_owner().get_gravity() * get_mass() *
2190
get_owner().get_average_density(get_bounding_box()) /
2193
add_external_force(force);
2196
} // plee::progress_cling()
2198
/*---------------------------------------------------------------------------*/
2200
* \brief Do one iteration in the state .
2201
* \param elapsed_time Elapsed time since the last call.
2203
void ptb::plee::progress_clung_jump
2204
( bear::universe::time_type elapsed_time )
2206
if ( !test_bottom_contact() )
2207
if( get_speed().y <= 0 )
2208
start_action_model("fall");
2209
} // plee::progress_clung_jump()
2211
/*---------------------------------------------------------------------------*/
2213
* \brief Do one iteration in the state .
2214
* \param elapsed_time Elapsed time since the last call.
2216
void ptb::plee::progress_start_hang
2217
( bear::universe::time_type elapsed_time )
2219
if ( !test_bottom_contact() )
2221
if ( ( !get_rendering_attributes().is_mirrored() &&
2222
has_right_contact() ) ||
2223
( get_rendering_attributes().is_mirrored() && has_left_contact() ) )
2224
start_action_model("hang");
2226
if ( m_state_time >= s_max_time_to_hang )
2227
start_action_model("idle");
2229
} // plee::progress_start_hang()
2231
/*---------------------------------------------------------------------------*/
2233
* \brief Do one iteration in the state .
2234
* \param elapsed_time Elapsed time since the last call.
2236
void ptb::plee::progress_hang( bear::universe::time_type elapsed_time )
2238
if ( ! test_bottom_contact() )
2240
if ( has_top_contact() )
2241
start_action_model("fall");
2243
add_external_force(- get_mass() * get_owner().get_gravity());
2245
} // plee::progress_hang()
2247
/*---------------------------------------------------------------------------*/
2249
* \brief Do one iteration in the state .
2250
* \param elapsed_time Elapsed time since the last call.
2252
void ptb::plee::progress_swimming( bear::universe::time_type elapsed_time )
2254
if ( !test_bottom_contact() )
2256
if ( is_only_in_environment(bear::universe::water_environment) )
2258
if( get_speed().y <= 0 )
2259
start_action_model("sink");
2261
else if ( is_in_floating() )
2262
start_action_model("float");
2263
else if( get_speed().y <= 0 )
2264
start_action_model("fall");
2266
start_action_model("jump");
2268
} // plee::progress_swimming()
2270
/*---------------------------------------------------------------------------*/
2272
* \brief Do one iteration in the state .
2273
* \param elapsed_time Elapsed time since the last call.
2275
void ptb::plee::progress_sink( bear::universe::time_type elapsed_time )
2277
if ( !test_bottom_contact() )
2279
if ( is_only_in_environment(bear::universe::water_environment) )
2281
if( get_speed().y > 0 )
2282
start_action_model("swimming");
2284
else if ( is_in_floating() )
2285
start_action_model("float");
2286
else if( get_speed().y > 0 )
2287
start_action_model("jump");
2289
start_action_model("fall");
2291
} // plee::progress_sink()
2293
/*---------------------------------------------------------------------------*/
2295
* \brief Do one iteration in the state .
2296
* \param elapsed_time Elapsed time since the last call.
2298
void ptb::plee::progress_float( bear::universe::time_type elapsed_time )
2300
if ( !test_bottom_contact() )
2302
if ( is_only_in_environment(bear::universe::water_environment) )
2304
if( get_speed().y > 0 )
2305
start_action_model("swimming");
2307
start_action_model("sink");
2309
else if ( ! is_in_floating() )
2311
if( get_speed().y > 0 )
2312
start_action_model("jump");
2314
start_action_model("fall");
2317
} // plee::progress_float()
2319
/*---------------------------------------------------------------------------*/
2321
* \brief Do one iteration in the state .
2322
* \param elapsed_time Elapsed time since the last call.
2324
void ptb::plee::progress_injured( bear::universe::time_type elapsed_time )
2328
if ( has_bottom_contact() )
2330
m_nb_bottom_contact++;
2332
if ( m_nb_bottom_contact > 2 )
2334
if ( m_last_bottom_left == get_bottom_left() )
2335
start_action_model("idle");
2338
bear::universe::speed_type speed( get_speed() );
2339
// calculate the speed in the intern axis
2340
bear::universe::coordinate_type speed_x =
2341
speed.dot_product(get_x_axis());
2343
if( std::abs(speed_x) >= s_speed_to_run )
2344
start_action_model("run");
2345
else if ( speed_x == 0 )
2346
start_action_model("idle");
2348
start_action_model("walk");
2352
} // plee::progress_injured()
2354
/*----------------------------------------------------------------------------*/
2356
* \brief Set the state of Plee.
2358
void ptb::plee::set_state(plee_state_name state)
2360
if ( state != m_current_state )
2362
m_states[m_current_state]->stop();
2363
m_current_state = state;
2364
m_states[m_current_state]->start();
2367
} // plee::set_state()
2369
/*----------------------------------------------------------------------------*/
2371
* \brief Test if Plee is crushed.
2373
bool ptb::plee::is_crushed() const
2375
return ( ( has_bottom_contact() && has_top_contact() ) ||
2376
( has_right_contact() && has_left_contact() ) );
2377
// && has_contact_after_collision() );
2378
} // plee::is_crushed()
2380
/*----------------------------------------------------------------------------*/
2382
* \brief Spawn the plee after his death.
2383
* \todo Game over if the plee has no more lifes.
2384
* \todo Update lifes and any other counters.
2386
void ptb::plee::regenerate()
2388
set_center_of_mass( m_saved_position );
2389
set_speed( bear::universe::speed_type(0, 0) );
2390
set_internal_force(bear::universe::force_type(0, 0));
2391
set_external_force(bear::universe::force_type(0, 0));
2392
m_energy = game_variables::get_max_energy(m_index);
2393
m_invincible_time = 0;
2394
set_invincible(false);
2395
m_last_visual_time = 0;
2396
m_last_visuals.clear();
2398
m_can_cling = false;
2399
m_air_float = false;
2401
game_variables::set_air_power(m_index,false);
2402
game_variables::set_fire_power(m_index,false);
2403
game_variables::set_water_power(m_index,false);
2405
m_gauges[oxygen_gauge]->set_value(s_max_oxygen);
2406
m_gauges[fire_gauge]->set_value(s_max_fire_gauge);
2407
m_gauges[ice_gauge]->set_value(s_max_ice_gauge);
2408
m_air_stones.clear();
2409
m_move_right = false;
2410
m_move_left = false;
2411
m_last_bottom_left = bear::universe::position_type(0,0);
2412
get_rendering_attributes().mirror(false);
2414
if ( m_animation_to_throw )
2416
delete m_animation_to_throw;
2417
m_animation_to_throw = NULL;
2420
} // plee::regenerate()
2422
/*----------------------------------------------------------------------------*/
2424
* \brief Indicates if Plee has a power.
2426
bool ptb::plee::has_a_power() const
2428
return game_variables::get_air_power(m_index) ||
2429
game_variables::get_fire_power(m_index) ||
2430
game_variables::get_water_power(m_index);
2431
} // plee::has_power()
2433
/*----------------------------------------------------------------------------*/
2435
* \brief Indicates if Plee is in the water and in the air.
2438
bool ptb::plee::is_in_floating() const
2440
bool result = false;
2444
std::set<bear::universe::environment_type> environments;
2445
get_owner().get_environments(get_bounding_box(), environments);
2447
(environments.find(bear::universe::water_environment) !=
2448
environments.end()) &&
2449
( environments.size() >= 1 );
2453
} // plee::is_only_in_floatting()
2455
/*----------------------------------------------------------------------------*/
2457
* \brief Update the orientation.
2459
void ptb::plee::update_orientation()
2461
if ( get_speed().x < 0 )
2463
if ( get_current_action_name()!= "injured" )
2464
get_rendering_attributes().mirror(true);
2466
get_rendering_attributes().mirror(false);
2468
else if ( get_speed().x > 0 )
2470
if ( get_current_action_name()!= "injured" )
2471
get_rendering_attributes().mirror(false);
2473
get_rendering_attributes().mirror(true);
2475
} // plee::update_orientation()
2477
/*----------------------------------------------------------------------------*/
2479
* \brief Update the offensive and defensive parameters according to
2481
* \param p The power status.
2482
* \param a The corresponding attack
2484
void ptb::plee::update_power( bool b, monster::attack_type a)
2488
m_defensive_powers[a] = true;
2489
m_offensive_coefficients[a] = 1;
2493
m_defensive_powers[a] = false;
2494
m_offensive_coefficients[a] = 0;
2496
} // plee::update_power()
2498
/*----------------------------------------------------------------------------*/
2500
* \brief Update the offensive and defensive parameters according to
2503
void ptb::plee::update_powers()
2505
update_power(game_variables::get_air_power(m_index),monster::air_attack);
2506
update_power(game_variables::get_fire_power(m_index),monster::fire_attack);
2507
update_power(game_variables::get_water_power(m_index),monster::water_attack);
2509
if ( has_a_power() && ( m_halo_hand_animation != NULL ) )
2511
if ( game_variables::get_air_power(m_index) )
2512
if ( game_variables::get_fire_power(m_index) )
2513
if ( game_variables::get_water_power(m_index) )
2514
m_halo_hand_animation->set_intensity(0.5, 0.5, 0.5);
2516
m_halo_hand_animation->set_intensity(1, 0, 0);
2518
if ( game_variables::get_water_power(m_index) )
2519
m_halo_hand_animation->set_intensity(0.19, 0.78, 0.94);
2521
m_halo_hand_animation->set_intensity(1, 1, 1);
2523
if ( game_variables::get_fire_power(m_index) )
2524
if ( game_variables::get_water_power(m_index) )
2525
m_halo_hand_animation->set_intensity(1, 0.5, 0);
2527
m_halo_hand_animation->set_intensity(0.66, 0.13, 0);
2529
if ( game_variables::get_water_power(m_index) )
2530
m_halo_hand_animation->set_intensity(0, 0, 1);
2532
} // plee::update_powers()
2534
/*----------------------------------------------------------------------------*/
2536
* \brief Set the camera on the current plee.
2538
void ptb::plee::do_get_camera()
2540
shared_camera::placement_mode mode;
2542
if ( get_name() == player_name(1) )
2543
mode = shared_camera::lock_first_player;
2545
mode = shared_camera::lock_second_player;
2547
shared_camera::set_placement_message msg(mode);
2548
bear::engine::level_globals& glob = get_level_globals();
2550
glob.send_message( "camera", msg );
2551
} // plee::do_get_camera()
2553
/*----------------------------------------------------------------------------*/
2555
* \brief Stop to look up.
2557
void ptb::plee::do_stop_look_upward()
2559
m_status_look_upward = false;
2560
m_states[m_current_state]->do_stop_look_upward();
2561
} // state_plee::do_stop_look_upward()
2563
/*----------------------------------------------------------------------------*/
2565
* \brief Stop to crouch.
2567
void ptb::plee::do_stop_crouch()
2569
m_status_crouch = false;
2570
m_states[m_current_state]->do_stop_crouch();
2571
} // state_plee::do_stop_crouch()
2573
/*----------------------------------------------------------------------------*/
2575
* \brief Progress the gauges.
2576
* \param elapsed_time Elapsed time since the last call.
2578
void ptb::plee::progress_gauges( bear::universe::time_type elapsed_time )
2580
progress_oxygen_gauge(elapsed_time);
2581
progress_fire_gauge(elapsed_time);
2582
progress_ice_gauge(elapsed_time);
2583
} // plee::progress_gauges()
2585
/*----------------------------------------------------------------------------*/
2587
* \brief Progress the oxygen_gauge.
2588
* \param elapsed_time Elapsed time since the last call.
2590
void ptb::plee::progress_oxygen_gauge( bear::universe::time_type elapsed_time )
2592
m_gauges[oxygen_gauge]->set_activated
2593
(is_in_environment(bear::universe::water_environment));
2595
bear::engine::model_mark_placement m;
2597
if ( is_in_environment(bear::universe::water_environment) )
2598
if ( get_mark_placement("mouth",m) )
2600
if ( get_owner().is_in_environment
2601
(m.get_position(), bear::universe::water_environment) )
2602
m_gauges[oxygen_gauge]->remove_value
2603
(s_oxygen_loss_speed*elapsed_time);
2605
m_gauges[oxygen_gauge]->add_value
2606
(s_oxygen_inspiration_speed*elapsed_time);
2609
m_gauges[oxygen_gauge]->remove_value(s_oxygen_loss_speed*elapsed_time);
2611
m_gauges[oxygen_gauge]->fill();
2613
if ( m_gauges[oxygen_gauge]->get_value() == 0 )
2614
remove_energy(*this,0.1);
2615
} // plee::progress_oxygen_gauge()
2617
/*----------------------------------------------------------------------------*/
2619
* \brief Progress the fire_gauge.
2620
* \param elapsed_time Elapsed time since the last call.
2622
void ptb::plee::progress_fire_gauge( bear::universe::time_type elapsed_time )
2624
m_gauges[fire_gauge]->set_activated
2625
(is_in_environment(bear::universe::fire_environment));
2627
if ( is_only_in_environment(bear::universe::fire_environment) )
2628
m_gauges[fire_gauge]->remove_value(s_fire_loss_speed*elapsed_time);
2630
m_gauges[fire_gauge]->add_value(s_fire_increase_speed*elapsed_time);
2632
if ( m_gauges[fire_gauge]->get_value() == 0 )
2633
remove_energy(*this,0.1);
2634
} // plee::progress_fire_gauge()
2636
/*----------------------------------------------------------------------------*/
2638
* \brief Progress the ice_gauge.
2639
* \param elapsed_time Elapsed time since the last call.
2641
void ptb::plee::progress_ice_gauge( bear::universe::time_type elapsed_time )
2643
m_gauges[ice_gauge]->set_activated
2644
(is_in_environment(bear::universe::ice_environment));
2646
if ( is_only_in_environment(bear::universe::ice_environment) )
2647
m_gauges[ice_gauge]->remove_value(s_ice_loss_speed*elapsed_time);
2649
m_gauges[ice_gauge]->add_value(s_ice_increase_speed*elapsed_time);
2651
if ( m_gauges[ice_gauge]->get_value() == 0 )
2652
remove_energy(*this,0.1);
2653
} // plee::progress_ice_gauge()
2655
/*----------------------------------------------------------------------------*/
2657
* \brief Progress the spot.
2658
* \param elapsed_time Elapsed time since the last call.
2660
void ptb::plee::progress_spot( bear::universe::time_type elapsed_time )
2662
bool balance_x(true);
2663
bool balance_y(true);
2665
if ( m_status_look_upward )
2667
m_look_upward_time += elapsed_time;
2669
if ( m_look_upward_time >= s_time_to_look_upward )
2672
add_spot_gap( bear::universe::position_type(0, 5) );
2676
if ( m_status_crouch )
2678
m_crouch_time += elapsed_time;
2680
if ( m_crouch_time >= s_time_to_crouch )
2683
add_spot_gap( bear::universe::position_type(0, -5) );
2687
if ( get_speed().x > s_speed_to_run )
2690
add_spot_gap( bear::universe::position_type(3, 0) );
2692
else if ( get_speed().x < -s_speed_to_run )
2695
add_spot_gap( bear::universe::position_type(-3, 0) );
2698
balance_spot(balance_x, balance_y);
2699
} // plee::progress_spot()
2702
/*---------------------------------------------------------------------------*/
2704
* \brief Teste if Plee walk and change state thereof.
2705
* Return true if Plee walk.
2707
bool ptb::plee::test_walk()
2709
bool result = false;
2711
if ( has_bottom_contact() )
2713
bear::universe::speed_type speed;
2714
speed = get_speed();
2715
// calculate the speed in the intern axis
2716
bear::universe::coordinate_type speed_x =
2717
speed.dot_product(get_x_axis());
2719
if( std::abs(speed_x) >= s_speed_to_run )
2722
start_action_model("run");
2724
else if ( ( speed_x != 0 ) &&
2725
( get_bottom_left() != m_last_bottom_left ) )
2728
start_action_model("walk");
2733
} // plee::test_walk()
2735
/*---------------------------------------------------------------------------*/
2737
* \brief Teste if Plee walk, run or is idle and change state thereof.
2738
* Return true if Plee has a bottom contact.
2740
bool ptb::plee::test_bottom_contact()
2742
bool result = false;
2744
if ( has_bottom_contact() )
2746
bear::universe::speed_type speed;
2747
speed = get_speed();
2749
// calculate the speed in the intern axis
2750
bear::universe::coordinate_type speed_x =
2751
speed.dot_product(get_x_axis());
2753
if( std::abs(speed_x) >= s_speed_to_run )
2754
start_action_model("run");
2755
else if( speed_x != 0 )
2756
start_action_model("walk");
2758
start_action_model("idle");
2764
} // plee::test_bottom_contact()
2766
/*---------------------------------------------------------------------------*/
2768
* \brief Teste if Plee is in the sky or swimm and change state thereof.
2769
* Return true if Plee is in the sky.
2771
bool ptb::plee::test_in_sky_or_swimm()
2773
bool result = false;
2775
if ( !has_bottom_contact() )
2779
if ( is_only_in_environment(bear::universe::water_environment) )
2780
if( get_speed().y <= 0 )
2781
start_action_model("sink");
2783
start_action_model("swimming");
2784
else if ( is_in_floating() )
2785
start_action_model("float");
2786
else if( get_speed().y <= 0 )
2787
start_action_model("fall");
2789
start_action_model("jump");
2793
} // plee::test_in_sky_or_swimm()
2795
/*---------------------------------------------------------------------------*/
2797
* \brief Brake on x axis if Player has no direction.
2799
void ptb::plee::brake()
2801
if ( ( ! m_move_right ) && ( ! m_move_left ) )
2803
bear::universe::speed_type speed = get_speed();
2807
m_move_right = false;
2808
m_move_left = false;
2811
/*----------------------------------------------------------------------------*/
2813
* \brief Compute the ejection force of stone.
2815
bear::universe::force_type ptb::plee::get_stone_force() const
2818
bear::universe::force_type result;
2820
if ( m_throw_up && ! m_throw_down)
2822
force = 4 + 4 * m_throw_time_ratio;
2826
else if ( ! m_throw_up && m_throw_down)
2828
force = 1 + 6 * m_throw_time_ratio;
2834
force = 3 + 5 * m_throw_time_ratio;
2841
if ( get_rendering_attributes().is_mirrored() )
2842
result.x = -result.x;
2844
result.x = result.x * force + 100*get_speed().x;
2845
result.y = result.y * force + get_speed().y;
2848
} // plee::get_stone_force()
2850
/*----------------------------------------------------------------------------*/
2852
* \brief Create a stone.
2854
* \param a The force applied to thes stone.
2856
void ptb::plee::create_stone( const bear::universe::force_type& a )
2858
if ( ! m_air_stones.empty() )
2860
std::set<ptb::stone*> save_stones(m_air_stones);
2861
std::set<ptb::stone*>::iterator it;
2862
for ( it = save_stones.begin(); it != save_stones.end(); ++it )
2864
// the call can change the set m_air_stones
2865
(*it)->inform_new_stone();
2868
else if ( game_variables::get_stones_count(m_index) > 0 )
2870
game_variables::set_stones_count
2871
( m_index, game_variables::get_stones_count(m_index) - 1);
2874
if ( game_variables::get_air_power(m_index) )
2875
if ( game_variables::get_fire_power(m_index) )
2876
if ( game_variables::get_water_power(m_index) )
2877
new_stone= new air_fire_water_stone(get_id());
2879
new_stone= new air_fire_stone(get_id());
2881
if ( game_variables::get_water_power(m_index) )
2882
new_stone= new air_water_stone(get_id());
2884
new_stone= new air_stone(get_id());
2886
if ( game_variables::get_fire_power(m_index) )
2887
if ( game_variables::get_water_power(m_index) )
2888
new_stone= new water_fire_stone(get_id());
2890
new_stone= new fire_stone(get_id());
2892
if ( game_variables::get_water_power(m_index) )
2893
new_stone= new water_stone(get_id());
2895
new_stone= new stone(get_id());
2898
bear::engine::model_mark_placement m;
2899
if ( get_mark_placement("hand",m) )
2900
new_stone->set_center_of_mass(m.get_position());
2902
new_stone->set_center_of_mass(get_center_of_mass());
2904
new_stone->set_z_position(get_z_position() + 2);
2906
new_stone->set_monster_type(monster::stone_1_monster);
2908
new_stone->set_monster_type(monster::stone_2_monster);
2909
new_item( *new_stone );
2911
new_stone->add_external_force(a);
2913
} // ptb::plee::create_stone()
2915
/*----------------------------------------------------------------------------*/
2917
* \brief Create a honeypot.
2919
* \param a The force to give at the honeypot.
2921
void ptb::plee::create_small_honeypot( const bear::universe::force_type& a)
2923
small_honeypot* new_small_honeypot = new small_honeypot();
2925
bear::engine::model_mark_placement m;
2926
if ( get_mark_placement("hand",m) )
2928
new_small_honeypot->set_z_position(m.get_depth_position());
2929
new_small_honeypot->set_center_of_mass(m.get_position());
2933
new_small_honeypot->set_z_position(get_z_position() + 1);
2934
new_small_honeypot->set_center_of_mass(get_center_of_mass());
2937
if ( m_current_object == air_honeypot_object )
2938
new_small_honeypot->set_type(base_bonus::air_power);
2939
else if ( m_current_object == fire_honeypot_object )
2940
new_small_honeypot->set_type(base_bonus::fire_power);
2942
new_small_honeypot->set_type(base_bonus::water_power);
2944
new_item( *new_small_honeypot );
2946
new_small_honeypot->add_external_force(a);
2947
} // ptb::plee::create_honeypot()
2950
/*----------------------------------------------------------------------------*/
2952
* \brief Create an azelnut.
2954
void ptb::plee::create_azelnut()
2956
azelnut* new_azelnut = new azelnut();
2958
bear::engine::model_mark_placement m;
2959
if ( get_mark_placement("hand",m) )
2961
new_azelnut->set_z_position(m.get_depth_position());
2962
new_azelnut->set_center_of_mass(m.get_position());
2966
new_azelnut->set_z_position(get_z_position() + 1);
2967
new_azelnut->set_center_of_mass(get_center_of_mass());
2970
new_item( *new_azelnut );
2972
bear::universe::force_type force(600000,600000);
2974
if ( get_rendering_attributes().is_mirrored() )
2977
force.x = force.x + 2000*get_speed().x;
2978
force.y = force.y + 20*get_speed().y;
2980
new_azelnut->add_external_force(force);
2981
} // ptb::plee::create_azelnut()
2983
/*----------------------------------------------------------------------------*/
2985
* \brief Render halos.
2986
* \param visuals (out) The sprites of the item, and their positions.
2988
void ptb::plee::render_halos
2989
( std::list<bear::engine::scene_visual>& visuals ) const
2991
render_jump_halo(visuals);
2992
render_hand_halo(visuals);
2993
} // plee::render_halos()
2995
/*----------------------------------------------------------------------------*/
2997
* \brief Render jump halo.
2998
* \param visuals (out) The sprites of the item, and their positions.
3000
void ptb::plee::render_jump_halo
3001
( std::list<bear::engine::scene_visual>& visuals ) const
3003
if ( m_current_state == plee::start_jump_state )
3005
bear::universe::size_type height
3006
( s_max_halo_height * (m_state_time / s_time_to_jump) );
3008
bear::visual::sprite current_sprite(m_halo_animation->get_sprite());
3009
current_sprite.set_height((unsigned int)height);
3010
current_sprite.set_angle
3011
( current_sprite.get_angle() + get_visual_angle() );
3014
( bear::engine::scene_visual
3015
( get_bottom_middle().x - current_sprite.width() / 2,
3016
get_bottom() + current_sprite.height() - 2,
3017
current_sprite, get_z_position()+1 ) );
3019
} // plee::render_jump_halo()
3021
/*----------------------------------------------------------------------------*/
3023
* \brief Render halos.
3024
* \param visuals (out) The sprites of the item, and their positions.
3027
ptb::plee::render_hand_halo
3028
( std::list<bear::engine::scene_visual>& visuals ) const
3030
if ( has_a_power() &&
3031
( ( m_current_state == plee::maintain_state ) ||
3032
( m_current_state == plee::throw_state ) ) )
3034
bear::visual::sprite current_sprite(m_halo_hand_animation->get_sprite());
3035
double angle(current_sprite.get_angle() + get_visual_angle() );
3036
bear::universe::position_type pos(get_center_of_mass());
3037
bear::engine::model_mark_placement m;
3039
if ( get_mark_placement("hand_over",m) )
3040
if ( m.is_visible() )
3042
angle += m.get_angle();
3043
pos = m.get_position();
3045
current_sprite.set_angle(angle);
3047
( bear::engine::scene_visual
3048
( pos.x - current_sprite.width() / 2,
3049
pos.y + current_sprite.height() / 2,
3050
current_sprite, get_z_position()+1 ) );
3053
} // plee::render_hand_halo()
3055
/*----------------------------------------------------------------------------*/
3057
* \brief Render the throw state.
3058
* \param visuals (out) The sprites of the item, and their positions.
3061
ptb::plee::render_throw
3062
( std::list<bear::engine::scene_visual>& visuals ) const
3064
if ( m_current_state == plee::throw_state )
3065
if ( m_animation_to_throw != NULL )
3067
bear::engine::model_mark_placement m;
3069
if ( get_mark_placement("hand",m) )
3070
if ( m.is_visible() )
3072
bear::visual::sprite current_sprite
3073
(m_animation_to_throw->get_sprite());
3075
double angle(current_sprite.get_angle() +
3076
get_visual_angle() + m.get_angle() );
3077
bear::universe::position_type pos = m.get_position();
3078
current_sprite.set_angle(angle);
3081
( bear::engine::scene_visual
3082
( pos.x - current_sprite.width() / 2,
3083
pos.y + current_sprite.height() / 2,
3084
current_sprite, m.get_depth_position() ) );
3087
} // plee::render_throw()
3089
/*----------------------------------------------------------------------------*/
3091
* \brief Get the sprite representing the item without invincible visuals.
3092
* \param visuals (out) The sprites of the item, and their positions.
3095
ptb::plee::get_visuals_without_invincibility
3096
( std::list<bear::engine::scene_visual>& visuals ) const
3098
super::get_visual(visuals);
3100
render_halos(visuals);
3101
render_throw(visuals);
3102
} // plee::get_visuals_without_invincibility()
3104
/*---------------------------------------------------------------------------*/
3106
* \brief Progress the invincibility statut.
3107
* \param elapsed_time Elapsed time since the last call.
3109
void ptb::plee::progress_invincibility
3110
( bear::universe::time_type elapsed_time )
3112
m_last_visual_time += elapsed_time;
3114
if ( is_invincible() )
3116
m_invincible_time += elapsed_time;
3117
if ( m_invincible_time >= invincibility_effect::get_total_duration() )
3118
set_invincible(false);
3121
if ( m_last_visual_time > 0.03 )
3123
m_last_visual_time = 0;
3125
if ( is_invincible() )
3127
if ( m_last_visuals.size() > 6 )
3128
m_last_visuals.pop_front();
3130
std::list<bear::engine::scene_visual> visuals;
3131
get_visuals_without_invincibility(visuals);
3133
std::list<bear::engine::scene_visual>::iterator it;
3134
for ( it = visuals.begin(); it != visuals.end(); ++it )
3135
it->scene_element.get_rendering_attributes().set_intensity
3138
m_last_visuals.push_back(visuals);
3140
else if ( ! m_last_visuals.empty() )
3141
m_last_visuals.pop_front();
3143
std::list< std::list<bear::engine::scene_visual> >::iterator it;
3145
for ( it = m_last_visuals.begin(); it != m_last_visuals.end(); ++it )
3147
std::list<bear::engine::scene_visual>::iterator it2;
3149
for (it2 = it->begin(); it2 != it->end(); ++it2 )
3150
it2->scene_element.get_rendering_attributes().set_opacity
3152
it2->scene_element.get_rendering_attributes().get_opacity());
3155
} // plee::progress_invincibilty()
3157
/*---------------------------------------------------------------------------*/
3159
* \brief Progress the air_float movement.
3160
* \param elapsed_time Elapsed time since the last call.
3162
void ptb::plee::progress_air_float
3163
( bear::universe::time_type elapsed_time )
3165
m_air_float_time += elapsed_time;
3167
if ( m_air_float_time >= s_max_time_air_float )
3168
m_air_float = false;
3171
if ( get_speed().y < 0 )
3173
double r=(double)rand()/(double)RAND_MAX;
3175
bear::universe::force_type force
3176
( -(0.5+r/2)*get_mass() * get_owner().get_gravity() );
3178
if ( (get_density() != 0) &&
3179
( get_mass() != std::numeric_limits<double>::infinity() ) )
3180
force += get_owner().get_gravity() * get_mass() *
3181
get_owner().get_average_density(get_bounding_box()) /
3184
add_external_force(force);
3187
} // progress_air_float()