4
Copyright (C) 2005-2009 Julien Jorge, Sebastien Angibaud
4
Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
6
6
This program is free software; you can redistribute it and/or modify it
7
7
under the terms of the GNU General Public License as published by the
27
27
* \author Sebastien Angibaud
29
29
#include "ptb/item/clingable.hpp"
30
#include "ptb/player.hpp"
31
#include "ptb/item/plee/plee.hpp"
33
34
BASE_ITEM_EXPORT( clingable, ptb )
35
36
/*----------------------------------------------------------------------------*/
38
* \brief Do post creation actions.
40
void ptb::clingable::build()
44
m_last_position = get_top_left();
45
} // clingable::build()
47
/*----------------------------------------------------------------------------*/
49
* \brief Do one step in the progression of the item.
50
* \param elapsed_time Elasped time since the last progress.
52
void ptb::clingable::progress( bear::universe::time_type elapsed_time )
54
super::progress( elapsed_time );
56
item_list::iterator it;
57
std::list<item_list::iterator> dead;
59
for (it=m_list_items.begin(); it!=m_list_items.end(); ++it)
63
for( ; !dead.empty(); dead.pop_front() )
64
m_list_items.erase( dead.front() );
65
} // clingable::progress()
67
/*----------------------------------------------------------------------------*/
69
* \brief Apply the movement of the item.
70
* \param elapsed_time Elasped time since the last call.
72
void ptb::clingable::move( bear::universe::time_type elapsed_time )
74
super::move(elapsed_time);
76
item_list::iterator it;
77
bear::universe::position_type position = get_top_left();
79
for(it=m_list_items.begin(); it!=m_list_items.end(); ++it)
82
(*it)->set_left((*it)->get_left() + position.x - m_last_position.x);
84
((*it)->get_bottom() + position.y - m_last_position.y);
87
for(it=m_old_items.begin(); it!=m_old_items.end(); ++it)
89
if ( std::find(m_list_items.begin(), m_list_items.end(), *it)
90
== m_list_items.end() ) // item is not on me anymore
92
( (*it)->get_speed() + bear::universe::speed_type(get_speed()) );
94
m_last_position = position;
95
std::swap(m_old_items, m_list_items);
97
} // clingable::move()
99
/*----------------------------------------------------------------------------*/
37
101
* \brief Check if the collision is with a player.
38
102
* \param that The other item of the collision.
39
103
* \param info Some informations about the collision.
41
105
void ptb::clingable::collision_check_and_apply
42
106
( bear::engine::base_item& that, bear::universe::collision_info& info )
44
plee* p = dynamic_cast<plee*>(&that);
108
player* p = dynamic_cast<player*>(&that);
47
p->set_can_cling(true);
112
p->set_can_cling(true);
115
m_list_items.push_front(that);
48
117
} // clingable::collision_check_and_apply()
50
119
/*----------------------------------------------------------------------------*/
57
126
( bear::engine::base_item& that, bear::universe::collision_info& info )
59
128
collision_check_and_apply(that, info);
61
130
super::collision(that,info);
62
131
} // clingable::collision()
133
/*----------------------------------------------------------------------------*/
135
* \brief Get the items concerned by a progress/move of this one.
136
* \param d (out) A list to which are added such items.
138
void ptb::clingable::get_dependent_items( std::list<physical_item*>& d ) const
140
item_list::const_iterator it;
142
for( it=m_list_items.begin(); it!=m_list_items.end(); ++it )
144
d.push_front( it->get() );
146
for( it=m_old_items.begin(); it!=m_old_items.end(); ++it )
148
d.push_front( it->get() );
149
} // clingable::get_dependent_items()