Skip to content

Commit

Permalink
weakblock: ice-themed sprite/behavior added, fire bullets absorbed, i…
Browse files Browse the repository at this point in the history
…ceflower no longer destroys, test level added (bug 819)
  • Loading branch information
LMH0013 committed Jan 24, 2012
1 parent 48e41b1 commit 0e7aa8c
Show file tree
Hide file tree
Showing 31 changed files with 265 additions and 44 deletions.
Binary file added data/images/objects/weak_block/melt_01.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/objects/weak_block/melt_02.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/objects/weak_block/melt_03.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/objects/weak_block/melt_04.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/objects/weak_block/melt_05.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/objects/weak_block/melt_06.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/objects/weak_block/melt_07.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/objects/weak_block/melt_08.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/objects/weak_block/melt_09.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/objects/weak_block/melt_10.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/objects/weak_block/melt_11.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/objects/weak_block/meltbox.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions data/images/objects/weak_block/meltbox.sprite
@@ -0,0 +1,29 @@
(supertux-sprite
(action
(name "normal")
(images
"meltbox.png"
)
)
(action
(name "burning")
(images
"melt_01.png"
"melt_02.png"
"melt_03.png"
"melt_04.png"
"melt_05.png"
)
)
(action
(name "disintegrating")
(images
"melt_06.png"
"melt_07.png"
"melt_08.png"
"melt_09.png"
"melt_10.png"
"melt_11.png"
)
)
)
Binary file added data/images/objects/weak_block/meltbox.xcf
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
141 changes: 141 additions & 0 deletions data/levels/test/weakblock.stl
@@ -0,0 +1,141 @@
(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 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 0 0 0 0 0 0 ; 448
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 ; 480
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 ; 512
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 ; 544
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 ; 576
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 ; 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 ))
))
131 changes: 88 additions & 43 deletions src/object/weak_block.cpp
Expand Up @@ -21,65 +21,107 @@
#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;
}

void
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;
}
}

Expand All @@ -94,19 +136,22 @@ WeakBlock::startBurning()
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();
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/object/weak_block.hpp
Expand Up @@ -20,6 +20,8 @@

#include "object/moving_sprite.hpp"
#include "supertux/physic.hpp"
#include "object/bullet.hpp"


/**
* A block that can be destroyed by Bullet hits
Expand All @@ -31,7 +33,7 @@ class WeakBlock : public MovingSprite

HitResponse collision(GameObject& other, const CollisionHit& hit);
void update(float elapsed_time);

protected:
/**
* called by self when hit by a bullet
Expand All @@ -50,6 +52,10 @@ class WeakBlock : public MovingSprite
STATE_DISINTEGRATING /**< crumbling to dust, no longer solid */
};
State state;

bool linked;
virtual HitResponse collision_bullet(Bullet& bullet, const CollisionHit& hit);

};

#endif
Expand Down

0 comments on commit 0e7aa8c

Please sign in to comment.