Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bonusblock enhancements: sprite changable, multi-hit, can contain scr…
…ipts, added sprites and test level (bug 838)
  • Loading branch information
LMH0013 authored and sommer committed Jan 21, 2012
1 parent 7f27664 commit f7f40c1
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 8 deletions.
8 changes: 8 additions & 0 deletions data/images/objects/bonus_block/hiddenbonus.sprite
@@ -0,0 +1,8 @@
(supertux-sprite
(action
(name "empty")
(images "empty.png"))
(action
(name "normal")
(images "invisible.png"))
)
Binary file added data/images/objects/bonus_block/invisible.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/bonus_block/purple_0.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/bonus_block/purple_1.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/bonus_block/purple_2.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/bonus_block/purple_3.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/bonus_block/purple_4.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/bonus_block/purple_empty.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions data/images/objects/bonus_block/purpleblock.sprite
@@ -0,0 +1,19 @@
(supertux-sprite
(action
(fps 15)
(name "normal")
(images "purple_0.png"
"purple_1.png"
"purple_2.png"
"purple_3.png"
"purple_4.png"
"purple_2.png"
"purple_1.png"
"purple_0.png"
"purple_0.png"
"purple_0.png"
))
(action
(name "empty")
(images "purple_empty.png"))
)
222 changes: 222 additions & 0 deletions data/levels/test/bonusblock.stl
@@ -0,0 +1,222 @@
(supertux-level
(version 2)
(name (_ "Bonusblock Test"))
(author "LMH")
(license "GPL 2 / CC-by-sa 3.0" )
(sector (name "main" )
(ambient-light 1 1 1 )
(camera (mode "normal" ))
(init-script " lightson <- true; ")

(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 44 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 0 ; 608
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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
))

(bonusblock
(x 256 )
(y 640 )
(contents "coin" )
(count 3 )
)

(bonusblock
(x 384 )
(y 640 )
(contents "firegrow" )
(sprite "images/objects/bonus_block/brick.sprite" )
)

(bonusblock
(x 512 )
(y 640 )
(contents "1up" )
(sprite "images/objects/bonus_block/hiddenbonus.sprite" )
)

(bonusblock
(x 640 )
(y 640 )
(contents "script" )
(script "
vineA.goto_node(8);
vineB.goto_node(8);
vineC.goto_node(8);
vineD.goto_node(8);
vineE.goto_node(8);
vineF.goto_node(8);
vineG.goto_node(8);
vineH.goto_node(8);
")
)

(bonusblock
(x 768 )
(y 640 )
(contents "script" )
(sprite "images/objects/bonus_block/hiddenbonus.sprite" )
(count 0 )
(script "
if(lightson){
lightson <- false;
settings.set_ambient_light(0, 0, 0);
cover.fade(0,0);
} else {
lightson <- true;
settings.set_ambient_light(1, 1, 1);
cover.fade(1,0);
}
")
)
(candle (x 768 )(y 640 ))

(tilemap (name "cover" )(alpha 1 )
(z-pos -100 )(solid #f )
(path (node (x 767 )(y 640 )) )
(width 1 )(height 1 )
(tiles 131 ))
(tilemap
(z-pos -200 )(solid #f )
(path (node (x 767 )(y 640 )) )
(width 1 )(height 1 )
(tiles 61 ))

(tilemap (name "vineA" )
(z-pos -50 )(solid #t )
(path (node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 608 )(time 0.25 ))
(node (x 640 )(y 576 )(time 0.25 ))
(node (x 640 )(y 544 )(time 0.25 ))
(node (x 640 )(y 512 )(time 0.25 ))
(node (x 640 )(y 480 )(time 0.25 ))
(node (x 640 )(y 448 )(time 0.25 ))
(node (x 640 )(y 416 )(time 0.25 ))
(node (x 640 )(y 384 )(time 0.25 )) )
(width 1 )(height 1 )
(tiles 2163 ))
(tilemap (name "vineB" )
(z-pos -50 )(solid #t )
(path (node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 608 )(time 0.25 ))
(node (x 640 )(y 576 )(time 0.25 ))
(node (x 640 )(y 544 )(time 0.25 ))
(node (x 640 )(y 512 )(time 0.25 ))
(node (x 640 )(y 480 )(time 0.25 ))
(node (x 640 )(y 448 )(time 0.25 ))
(node (x 640 )(y 416 )(time 0.25 )) )
(width 1 )(height 1 )
(tiles 2162 ))
(tilemap (name "vineC" )
(z-pos -50 )(solid #t )
(path (node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 608 )(time 0.25 ))
(node (x 640 )(y 576 )(time 0.25 ))
(node (x 640 )(y 544 )(time 0.25 ))
(node (x 640 )(y 512 )(time 0.25 ))
(node (x 640 )(y 480 )(time 0.25 ))
(node (x 640 )(y 448 )(time 0.25 )) )
(width 1 )(height 1 )
(tiles 2162 ))
(tilemap (name "vineD" )
(z-pos -50 )(solid #t )
(path (node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 608 )(time 0.25 ))
(node (x 640 )(y 576 )(time 0.25 ))
(node (x 640 )(y 544 )(time 0.25 ))
(node (x 640 )(y 512 )(time 0.25 ))
(node (x 640 )(y 480 )(time 0.25 )) )
(width 1 )(height 1 )
(tiles 2162 ))
(tilemap (name "vineE" )
(z-pos -50 )(solid #t )
(path (node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 608 )(time 0.25 ))
(node (x 640 )(y 576 )(time 0.25 ))
(node (x 640 )(y 544 )(time 0.25 ))
(node (x 640 )(y 512 )(time 0.25 )) )
(width 1 )(height 1 )
(tiles 2163 ))
(tilemap (name "vineF" )
(z-pos -50 )(solid #t )
(path (node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 608 )(time 0.25 ))
(node (x 640 )(y 576 )(time 0.25 ))
(node (x 640 )(y 544 )(time 0.25 )) )
(width 1 )(height 1 )
(tiles 2162 ))
(tilemap (name "vineG" )
(z-pos -50 )(solid #t )
(path (node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 608 )(time 0.25 ))
(node (x 640 )(y 576 )(time 0.25 )) )
(width 1 )(height 1 )
(tiles 2162 ))
(tilemap (name "vineH" )
(z-pos -50 )(solid #t )
(path (node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 640 )(time 0.25 ))
(node (x 640 )(y 608 )(time 0.25 )) )
(width 1 )(height 1 )
(tiles 2162 ))
))
39 changes: 32 additions & 7 deletions src/object/bonus_block.cpp
Expand Up @@ -39,7 +39,8 @@
BonusBlock::BonusBlock(const Vector& pos, int data) :
Block(sprite_manager->create("images/objects/bonus_block/bonusblock.sprite")),
contents(),
object(0)
object(0),
hit_counter(1)
{
bbox.set_pos(pos);
sprite->set_action("normal");
Expand All @@ -59,7 +60,8 @@ BonusBlock::BonusBlock(const Vector& pos, int data) :
BonusBlock::BonusBlock(const Reader& lisp) :
Block(sprite_manager->create("images/objects/bonus_block/bonusblock.sprite")),
contents(),
object(0)
object(0),
hit_counter(1)
{
Vector pos;

Expand All @@ -71,6 +73,13 @@ BonusBlock::BonusBlock(const Reader& lisp) :
iter.value()->get(pos.x);
} else if(token == "y") {
iter.value()->get(pos.y);
} else if(token == "sprite") {
iter.value()->get(sprite_name);
sprite = sprite_manager->create(sprite_name);
} else if(token == "count") {
iter.value()->get(hit_counter);
} else if(token == "script") {
iter.value()->get(script);
} else if(token == "contents") {
std::string contentstring;
iter.value()->get(contentstring);
Expand All @@ -86,6 +95,8 @@ BonusBlock::BonusBlock(const Reader& lisp) :
contents = CONTENT_1UP;
} else if(contentstring == "custom") {
contents = CONTENT_CUSTOM;
} else if(contentstring == "script") {
contents = CONTENT_SCRIPT;
} else {
log_warning << "Invalid box contents '" << contentstring << "'" << std::endl;
}
Expand Down Expand Up @@ -206,15 +217,29 @@ BonusBlock::try_open(Player *player)
break;

case CONTENT_CUSTOM:
SpecialRiser* riser = new SpecialRiser(get_pos(), object);
object = 0;
sector->add_object(riser);
sound_manager->play("sounds/upgrade.wav");
{
SpecialRiser* riser = new SpecialRiser(get_pos(), object);
object = 0;
sector->add_object(riser);
sound_manager->play("sounds/upgrade.wav");
break;
}

case CONTENT_SCRIPT:
if(script != "") {
std::istringstream stream(script);
Sector::current()->run_script(stream, "powerup-script");
}
break;
}

start_bounce(player);
sprite->set_action("empty");
if(hit_counter <= 0){ //use 0 to allow infinite hits
}else if(hit_counter == 1){
sprite->set_action("empty");
}else{
hit_counter--;
}
}

void
Expand Down
6 changes: 5 additions & 1 deletion src/object/bonus_block.hpp
Expand Up @@ -35,7 +35,8 @@ class BonusBlock : public Block
CONTENT_ICEGROW,
CONTENT_STAR,
CONTENT_1UP,
CONTENT_CUSTOM
CONTENT_CUSTOM,
CONTENT_SCRIPT
};

protected:
Expand All @@ -48,6 +49,9 @@ class BonusBlock : public Block
private:
BonusBlock(const BonusBlock&);
BonusBlock& operator=(const BonusBlock&);
int hit_counter;
std::string sprite_name;
std::string script;
};

#endif
Expand Down

0 comments on commit f7f40c1

Please sign in to comment.