1 // SuperTux - Weak Block
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "object/weak_block.hpp"
20 #include "object/bullet.hpp"
21 #include "supertux/object_factory.hpp"
22 #include "supertux/sector.hpp"
26 WeakBlock::WeakBlock(const Reader& lisp)
27 : MovingSprite(lisp, "images/objects/strawbox/strawbox.sprite", LAYER_TILES, COLGROUP_STATIC), state(STATE_NORMAL)
29 sprite->set_action("normal");
33 WeakBlock::collision(GameObject& other, const CollisionHit& )
38 if (dynamic_cast<Bullet*>(&other)) {
49 case STATE_DISINTEGRATING:
55 log_debug << "unhandled state" << std::endl;
60 WeakBlock::update(float )
68 if (sprite->animation_done()) {
69 state = STATE_DISINTEGRATING;
70 sprite->set_action("disintegrating", 1);
72 set_group(COLGROUP_DISABLED);
76 case STATE_DISINTEGRATING:
77 if (sprite->animation_done()) {
87 WeakBlock::startBurning()
89 if (state != STATE_NORMAL) return;
90 state = STATE_BURNING;
91 sprite->set_action("burning", 1);
95 WeakBlock::spreadHit()
97 Sector* sector = Sector::current();
99 log_debug << "no current sector" << std::endl;
102 for(Sector::GameObjects::iterator i = sector->gameobjects.begin(); i != sector->gameobjects.end(); ++i) {
103 WeakBlock* wb = dynamic_cast<WeakBlock*>(*i);
105 if (wb == this) continue;
106 if (wb->state != STATE_NORMAL) continue;
107 float dx = fabsf(wb->get_pos().x - this->get_pos().x);
108 float dy = fabsf(wb->get_pos().y - this->get_pos().y);
109 if ((dx <= 32.5) && (dy <= 32.5)) wb->startBurning();