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 "object/explosion.hpp"
22 #include "supertux/object_factory.hpp"
23 #include "supertux/sector.hpp"
24 #include "sprite/sprite.hpp"
25 #include "sprite/sprite_manager.hpp"
26 #include "util/reader.hpp"
30 WeakBlock::WeakBlock(const Reader& lisp)
31 : MovingSprite(lisp, "images/objects/weak_block/strawbox.sprite", LAYER_TILES, COLGROUP_STATIC), state(STATE_NORMAL),
34 sprite->set_action("normal");
35 //Check if this weakblock destroys adjacent weakblocks
36 if(lisp.get("linked", linked)){
38 sprite_name = "images/objects/weak_block/meltbox.sprite";
39 sprite = sprite_manager->create(sprite_name);
40 sprite->set_action("normal");
46 WeakBlock::collision_bullet(Bullet& bullet, const CollisionHit& hit)
51 //Ensure only fire destroys weakblock
52 if(bullet.get_type() == FIRE_BONUS) {
56 //Other bullets ricochet
58 bullet.ricochet(*this, hit);
63 case STATE_DISINTEGRATING:
67 log_debug << "unhandled state" << std::endl;
75 WeakBlock::collision(GameObject& other, const CollisionHit& hit)
80 if (Bullet* bullet = dynamic_cast<Bullet*> (&other)) {
81 return collision_bullet(*bullet, hit);
83 //Explosions destroy weakblocks as well
84 if (dynamic_cast<Explosion*> (&other)) {
90 case STATE_DISINTEGRATING:
94 log_debug << "unhandled state" << std::endl;
102 WeakBlock::update(float )
110 if (sprite->animation_done()) {
111 state = STATE_DISINTEGRATING;
112 sprite->set_action("disintegrating", 1);
114 set_group(COLGROUP_DISABLED);
118 case STATE_DISINTEGRATING:
119 if (sprite->animation_done()) {
129 WeakBlock::startBurning()
131 if (state != STATE_NORMAL) return;
132 state = STATE_BURNING;
133 sprite->set_action("burning", 1);
137 WeakBlock::spreadHit()
139 //Destroy adjacent weakblocks if applicable
141 Sector* sector = Sector::current();
143 log_debug << "no current sector" << std::endl;
146 for(Sector::GameObjects::iterator i = sector->gameobjects.begin(); i != sector->gameobjects.end(); ++i) {
147 WeakBlock* wb = dynamic_cast<WeakBlock*>(*i);
149 if (wb == this) continue;
150 if (wb->state != STATE_NORMAL) continue;
151 float dx = fabsf(wb->get_pos().x - this->get_pos().x);
152 float dy = fabsf(wb->get_pos().y - this->get_pos().y);
153 if ((dx <= 32.5) && (dy <= 32.5)) wb->startBurning();