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() :
27 set_group(COLGROUP_TOUCHABLE);
30 TriggerBase::~TriggerBase()
32 // unregister remove_listener hooks, so nobody will try to call us after we've been destroyed
33 for (std::list<Player*>::iterator i = losetouch_listeners.begin(); i != losetouch_listeners.end(); i++) {
35 p->del_remove_listener(this);
37 losetouch_listeners.clear();
41 TriggerBase::update(float )
43 if (lasthit && !hit) {
44 for (std::list<Player*>::iterator i = losetouch_listeners.begin(); i != losetouch_listeners.end(); i++) {
46 event(*p, EVENT_LOSETOUCH);
47 p->del_remove_listener(this);
49 losetouch_listeners.clear();
56 TriggerBase::draw(DrawingContext& context)
61 sprite->draw(context, get_pos(), LAYER_TILES+1);
65 TriggerBase::collision(GameObject& other, const CollisionHit& )
67 Player* player = dynamic_cast<Player*> (&other);
71 losetouch_listeners.push_back(player);
72 player->add_remove_listener(this);
73 event(*player, EVENT_TOUCH);
81 TriggerBase::object_removed(GameObject* object)
83 for (std::list<Player*>::iterator i = losetouch_listeners.begin(); i != losetouch_listeners.end(); i++) {
86 losetouch_listeners.erase(i);