From: LMH Date: Mon, 16 Jan 2012 22:16:31 +0000 (-1000) Subject: Bonusblock enhancements: sprite changable, multi-hit, can contain scripts, added... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=f7f40c193277389e73e565a92cd2bec807be3463;p=supertux.git Bonusblock enhancements: sprite changable, multi-hit, can contain scripts, added sprites and test level (bug 838) --- diff --git a/data/images/objects/bonus_block/hiddenbonus.sprite b/data/images/objects/bonus_block/hiddenbonus.sprite new file mode 100644 index 000000000..21f3cdaa5 --- /dev/null +++ b/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")) +) diff --git a/data/images/objects/bonus_block/invisible.png b/data/images/objects/bonus_block/invisible.png new file mode 100644 index 000000000..31e35b246 Binary files /dev/null and b/data/images/objects/bonus_block/invisible.png differ diff --git a/data/images/objects/bonus_block/purple_0.png b/data/images/objects/bonus_block/purple_0.png new file mode 100644 index 000000000..8dd735426 Binary files /dev/null and b/data/images/objects/bonus_block/purple_0.png differ diff --git a/data/images/objects/bonus_block/purple_1.png b/data/images/objects/bonus_block/purple_1.png new file mode 100644 index 000000000..b1060ac22 Binary files /dev/null and b/data/images/objects/bonus_block/purple_1.png differ diff --git a/data/images/objects/bonus_block/purple_2.png b/data/images/objects/bonus_block/purple_2.png new file mode 100644 index 000000000..03054053a Binary files /dev/null and b/data/images/objects/bonus_block/purple_2.png differ diff --git a/data/images/objects/bonus_block/purple_3.png b/data/images/objects/bonus_block/purple_3.png new file mode 100644 index 000000000..2eed8aceb Binary files /dev/null and b/data/images/objects/bonus_block/purple_3.png differ diff --git a/data/images/objects/bonus_block/purple_4.png b/data/images/objects/bonus_block/purple_4.png new file mode 100644 index 000000000..a190a0ea2 Binary files /dev/null and b/data/images/objects/bonus_block/purple_4.png differ diff --git a/data/images/objects/bonus_block/purple_empty.png b/data/images/objects/bonus_block/purple_empty.png new file mode 100644 index 000000000..30bb53707 Binary files /dev/null and b/data/images/objects/bonus_block/purple_empty.png differ diff --git a/data/images/objects/bonus_block/purpleblock.sprite b/data/images/objects/bonus_block/purpleblock.sprite new file mode 100644 index 000000000..04c2654b3 --- /dev/null +++ b/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")) +) diff --git a/data/levels/test/bonusblock.stl b/data/levels/test/bonusblock.stl new file mode 100755 index 000000000..8fe206c79 --- /dev/null +++ b/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 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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 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 )) +)) diff --git a/src/object/bonus_block.cpp b/src/object/bonus_block.cpp index 084253e08..93e944c88 100644 --- a/src/object/bonus_block.cpp +++ b/src/object/bonus_block.cpp @@ -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"); @@ -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; @@ -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); @@ -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; } @@ -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 diff --git a/src/object/bonus_block.hpp b/src/object/bonus_block.hpp index 35c845e01..fd248f165 100644 --- a/src/object/bonus_block.hpp +++ b/src/object/bonus_block.hpp @@ -35,7 +35,8 @@ public: CONTENT_ICEGROW, CONTENT_STAR, CONTENT_1UP, - CONTENT_CUSTOM + CONTENT_CUSTOM, + CONTENT_SCRIPT }; protected: @@ -48,6 +49,9 @@ public: private: BonusBlock(const BonusBlock&); BonusBlock& operator=(const BonusBlock&); + int hit_counter; + std::string sprite_name; + std::string script; }; #endif