2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "trigger/trigger_base.hpp"
19 #include "object/player.hpp"
20 #include "sprite/sprite.hpp"
22 TriggerBase::TriggerBase() :
28 set_group(COLGROUP_TOUCHABLE);
31 TriggerBase::~TriggerBase()
33 // unregister remove_listener hooks, so nobody will try to call us after we've been destroyed
34 for (std::list<Player*>::iterator i = losetouch_listeners.begin(); i != losetouch_listeners.end(); i++) {
36 p->del_remove_listener(this);
38 losetouch_listeners.clear();
42 TriggerBase::update(float )
44 if (lasthit && !hit) {
45 for (std::list<Player*>::iterator i = losetouch_listeners.begin(); i != losetouch_listeners.end(); i++) {
47 event(*p, EVENT_LOSETOUCH);
48 p->del_remove_listener(this);
50 losetouch_listeners.clear();
57 TriggerBase::draw(DrawingContext& context)
62 sprite->draw(context, get_pos(), LAYER_TILES+1);
66 TriggerBase::collision(GameObject& other, const CollisionHit& )
68 Player* player = dynamic_cast<Player*> (&other);
72 losetouch_listeners.push_back(player);
73 player->add_remove_listener(this);
74 event(*player, EVENT_TOUCH);
82 TriggerBase::object_removed(GameObject* object)
84 for (std::list<Player*>::iterator i = losetouch_listeners.begin(); i != losetouch_listeners.end(); i++) {
87 losetouch_listeners.erase(i);