--- /dev/null
+(supertux-level
+ (version 2)
+ (name (_ "Weakblock Test"))
+ (author "LMH")
+ (license "GPL 2 / CC-by-sa 3.0" )
+ (sector (name "main" )
+ (ambient-light 1 1 1 )
+ (camera (mode "normal" ))
+
+ (spawnpoint (name "main" )
+ (x 80 )(y 704 ))
+
+ (tilemap (name "Interactive" )
+ (z-pos 0 )(solid #t )
+ (width 42 )(height 30 )
+ (tiles ; 160 192 224 256 288 320 352 384 416 448 480 512 544 576 608 640 672 704 736 768 800 832 864 896 928 960 992 1024 1056 1088 1120 1152 1184 1216 1248 1280 1312
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 32
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 64
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 96
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 128
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 160
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 192
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 224
+0 0 0 0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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 608
+0 0 0 0 140 0 140 0 0 102 0 102 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 640
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 672
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; 704
+8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 ; 736
+14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 ; 768
+11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 ; 800
+11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 ; 832
+11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 ; 864
+11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 ; 896
+11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 ; 928
+ ))
+ (weak_block
+ (linked #f )
+ (x 480 )(y 736 ))
+ (weak_block
+ (linked #f )
+ (x 512 )(y 736 ))
+ (weak_block
+ (linked #f )
+ (x 544 )(y 736 ))
+ (weak_block
+ (linked #f )
+ (x 576 )(y 736 ))
+ (weak_block
+ (linked #f )
+ (x 608 )(y 736 ))
+ (weak_block
+ (linked #f )
+ (x 640 )(y 736 ))
+ (weak_block
+ (linked #f )
+ (x 672 )(y 736 ))
+ (weak_block
+ (x 480 )(y 672 ))
+ (weak_block
+ (x 512 )(y 672 ))
+ (weak_block
+ (x 544 )(y 672 ))
+ (weak_block
+ (x 576 )(y 672 ))
+ (weak_block
+ (x 608 )(y 672 ))
+ (weak_block
+ (x 640 )(y 672 ))
+ (weak_block
+ (x 672 )(y 672 ))
+
+ (weak_block
+ (linked #f )
+ (x 736 )(y 704 ))
+ (weak_block
+ (linked #f )
+ (x 768 )(y 704 ))
+ (weak_block
+ (linked #f )
+ (x 800 )(y 704 ))
+ (weak_block
+ (linked #f )
+ (x 832 )(y 704 ))
+ (weak_block
+ (linked #f )
+ (x 864 )(y 704 ))
+ (weak_block
+ (linked #f )
+ (x 896 )(y 704 ))
+ (weak_block
+ (linked #f )
+ (x 928 )(y 704 ))
+ (weak_block
+ (x 736 )(y 672 ))
+ (weak_block
+ (x 768 )(y 672 ))
+ (weak_block
+ (x 800 )(y 672 ))
+ (weak_block
+ (x 832 )(y 672 ))
+ (weak_block
+ (x 864 )(y 672 ))
+ (weak_block
+ (x 896 )(y 672 ))
+ (weak_block
+ (x 928 )(y 672 ))
+
+ (weak_block
+ (linked #t )(sprite "images/objects/weak_block/meltbox.sprite" )
+ (x 992 )(y 704 ))
+ (weak_block
+ (linked #t )(sprite "images/objects/weak_block/meltbox.sprite" )
+ (x 1024 )(y 704 ))
+ (weak_block
+ (linked #t )(sprite "images/objects/weak_block/meltbox.sprite" )
+ (x 1056 )(y 704 ))
+ (weak_block
+ (linked #t )(sprite "images/objects/weak_block/meltbox.sprite" )
+ (x 1088 )(y 704 ))
+ (weak_block
+ (linked #t )(sprite "images/objects/weak_block/meltbox.sprite" )
+ (x 1120 )(y 704 ))
+ (weak_block
+ (linked #t )(sprite "images/objects/weak_block/meltbox.sprite" )
+ (x 1152 )(y 704 ))
+ (weak_block
+ (linked #t )(sprite "images/objects/weak_block/meltbox.sprite" )
+ (x 1184 )(y 704 ))
+))
#include "object/explosion.hpp"
#include "supertux/object_factory.hpp"
#include "supertux/sector.hpp"
+#include "sprite/sprite.hpp"
+#include "sprite/sprite_manager.hpp"
+#include "util/reader.hpp"
#include <math.h>
WeakBlock::WeakBlock(const Reader& lisp)
- : MovingSprite(lisp, "images/objects/strawbox/strawbox.sprite", LAYER_TILES, COLGROUP_STATIC), state(STATE_NORMAL)
+: MovingSprite(lisp, "images/objects/weak_block/strawbox.sprite", LAYER_TILES, COLGROUP_STATIC), state(STATE_NORMAL),
+linked(true)
{
sprite->set_action("normal");
+ //Check if this weakblock destroys adjacent weakblocks
+ if(lisp.get("linked", linked)){
+ if(! linked){
+ sprite_name = "images/objects/weak_block/meltbox.sprite";
+ sprite = sprite_manager->create(sprite_name);
+ sprite->set_action("normal");
+ }
+ }
}
HitResponse
-WeakBlock::collision(GameObject& other, const CollisionHit& )
+WeakBlock::collision_bullet(Bullet& bullet, const CollisionHit& hit)
{
switch (state) {
-
+
case STATE_NORMAL:
- if (dynamic_cast<Bullet*>(&other)) {
+ //Ensure only fire destroys weakblock
+ if(bullet.get_type() == FIRE_BONUS) {
startBurning();
+ bullet.remove_me();
}
- if (dynamic_cast<Explosion*> (&other)) {
- startBurning();
+ //Other bullets ricochet
+ else {
+ bullet.ricochet(*this, hit);
}
- break;
-
+ break;
+
case STATE_BURNING:
case STATE_DISINTEGRATING:
break;
-
+
default:
log_debug << "unhandled state" << std::endl;
break;
- }
+ }
+
+ return FORCE_MOVE;
+}
+HitResponse
+WeakBlock::collision(GameObject& other, const CollisionHit& hit)
+{
+ switch (state) {
+
+ case STATE_NORMAL:
+ if (Bullet* bullet = dynamic_cast<Bullet*> (&other)) {
+ return collision_bullet(*bullet, hit);
+ }
+ //Explosions destroy weakblocks as well
+ if (dynamic_cast<Explosion*> (&other)) {
+ startBurning();
+ }
+ break;
+
+ case STATE_BURNING:
+ case STATE_DISINTEGRATING:
+ break;
+
+ default:
+ log_debug << "unhandled state" << std::endl;
+ break;
+ }
+
return FORCE_MOVE;
}
WeakBlock::update(float )
{
switch (state) {
-
- case STATE_NORMAL:
- break;
-
- case STATE_BURNING:
- if (sprite->animation_done()) {
- state = STATE_DISINTEGRATING;
- sprite->set_action("disintegrating", 1);
- spreadHit();
- set_group(COLGROUP_DISABLED);
- }
- break;
-
- case STATE_DISINTEGRATING:
- if (sprite->animation_done()) {
- remove_me();
- return;
- }
- break;
-
+
+ case STATE_NORMAL:
+ break;
+
+ case STATE_BURNING:
+ if (sprite->animation_done()) {
+ state = STATE_DISINTEGRATING;
+ sprite->set_action("disintegrating", 1);
+ spreadHit();
+ set_group(COLGROUP_DISABLED);
+ }
+ break;
+
+ case STATE_DISINTEGRATING:
+ if (sprite->animation_done()) {
+ remove_me();
+ return;
+ }
+ break;
+
}
}
void
WeakBlock::spreadHit()
{
- Sector* sector = Sector::current();
- if (!sector) {
- log_debug << "no current sector" << std::endl;
- return;
- }
- for(Sector::GameObjects::iterator i = sector->gameobjects.begin(); i != sector->gameobjects.end(); ++i) {
- WeakBlock* wb = dynamic_cast<WeakBlock*>(*i);
- if (!wb) continue;
- if (wb == this) continue;
- if (wb->state != STATE_NORMAL) continue;
- float dx = fabsf(wb->get_pos().x - this->get_pos().x);
- float dy = fabsf(wb->get_pos().y - this->get_pos().y);
- if ((dx <= 32.5) && (dy <= 32.5)) wb->startBurning();
+ //Destroy adjacent weakblocks if applicable
+ if(linked) {
+ Sector* sector = Sector::current();
+ if (!sector) {
+ log_debug << "no current sector" << std::endl;
+ return;
+ }
+ for(Sector::GameObjects::iterator i = sector->gameobjects.begin(); i != sector->gameobjects.end(); ++i) {
+ WeakBlock* wb = dynamic_cast<WeakBlock*>(*i);
+ if (!wb) continue;
+ if (wb == this) continue;
+ if (wb->state != STATE_NORMAL) continue;
+ float dx = fabsf(wb->get_pos().x - this->get_pos().x);
+ float dy = fabsf(wb->get_pos().y - this->get_pos().y);
+ if ((dx <= 32.5) && (dy <= 32.5)) wb->startBurning();
+ }
}
}