From: LMH Date: Wed, 28 Nov 2012 22:29:21 +0000 (-1000) Subject: New bonus_block content: light X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=f0fb4b738b14cb49314ea6792edbd4849d496f04;p=supertux.git New bonus_block content: light --- diff --git a/data/images/objects/bonus_block/bonusblock.sprite b/data/images/objects/bonus_block/bonusblock.sprite index 3f5924c29..9ce96d155 100644 --- a/data/images/objects/bonus_block/bonusblock.sprite +++ b/data/images/objects/bonus_block/bonusblock.sprite @@ -16,4 +16,10 @@ (action (name "empty") (images "empty.png")) + (action + (name "on") + (images "on.png")) + (action + (name "off") + (images "off.png")) ) diff --git a/data/images/objects/bonus_block/light.xcf b/data/images/objects/bonus_block/light.xcf new file mode 100644 index 000000000..91e54400c Binary files /dev/null and b/data/images/objects/bonus_block/light.xcf differ diff --git a/data/images/objects/bonus_block/off.png b/data/images/objects/bonus_block/off.png new file mode 100644 index 000000000..37db176ad Binary files /dev/null and b/data/images/objects/bonus_block/off.png differ diff --git a/data/images/objects/bonus_block/on.png b/data/images/objects/bonus_block/on.png new file mode 100644 index 000000000..f66ae7713 Binary files /dev/null and b/data/images/objects/bonus_block/on.png differ diff --git a/data/images/objects/lightmap_light/bonusblock_light.png b/data/images/objects/lightmap_light/bonusblock_light.png new file mode 100644 index 000000000..e498abd7f Binary files /dev/null and b/data/images/objects/lightmap_light/bonusblock_light.png differ diff --git a/data/images/tiles.strf b/data/images/tiles.strf index c35cf706c..afc788f33 100644 --- a/data/images/tiles.strf +++ b/data/images/tiles.strf @@ -14,6 +14,29 @@ ;; - the meaning of the values in (attributes ...) can be seen in ;; src/tile.cpp, unisolid is 3 not 2 (supertux-tiles + (tile + (id 2943) + (images + "objects/bonus_block/full-0.png" + "objects/bonus_block/full-1.png" + "objects/bonus_block/full-2.png" + "objects/bonus_block/full-3.png" + "objects/bonus_block/full-4.png" + "objects/bonus_block/full-3.png" + "objects/bonus_block/full-2.png" + "objects/bonus_block/full-1.png" + "objects/bonus_block/full-0.png" + "objects/bonus_block/full-0.png" + "objects/bonus_block/full-0.png" + ) + (solid #t) + (fullbox #t) + (next-tile 84) + (editor-images "objects/bonus_block/off.png") + (data 6) + (fps 15) + ) + (tilegroup (name "Pipe: Green") (tiles @@ -523,7 +546,7 @@ ) (tilegroup (name "Block") - (tiles 27 28 29 47 48 50 49 211 77 51 52 212 78 62 61 213 44 83 84 102 140 103 104 105 112 128 1311 2153) + (tiles 27 28 29 47 48 50 49 211 77 51 52 212 78 62 61 213 44 83 84 102 140 103 104 105 112 128 1311 2153 2943) ) (tilegroup (name "Background") @@ -3823,5 +3846,5 @@ (image "tiles/snow/slope-upper.png" ) ) -;; next-id: 2943 +;; next-id: 2944 ) diff --git a/data/levels/test/bonusblock.stl b/data/levels/test/bonusblock.stl index 44cf5f07d..4f953a0dd 100755 --- a/data/levels/test/bonusblock.stl +++ b/data/levels/test/bonusblock.stl @@ -35,7 +35,7 @@ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 2943 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 132 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 48 8 ; 736 diff --git a/src/object/bonus_block.cpp b/src/object/bonus_block.cpp index 3a2596f14..37ad89583 100644 --- a/src/object/bonus_block.cpp +++ b/src/object/bonus_block.cpp @@ -40,7 +40,8 @@ BonusBlock::BonusBlock(const Vector& pos, int data) : Block(sprite_manager->create("images/objects/bonus_block/bonusblock.sprite")), contents(), object(0), - hit_counter(1) + hit_counter(1), + lightsprite(Surface::create("/images/objects/lightmap_light/bonusblock_light.png")) { bbox.set_pos(pos); sprite->set_action("normal"); @@ -50,6 +51,7 @@ BonusBlock::BonusBlock(const Vector& pos, int data) : case 3: contents = CONTENT_STAR; break; case 4: contents = CONTENT_1UP; break; case 5: contents = CONTENT_ICEGROW; break; + case 6: contents = CONTENT_LIGHT; sound_manager->preload("sounds/switch.ogg"); break; default: log_warning << "Invalid box contents" << std::endl; contents = CONTENT_COIN; @@ -61,7 +63,8 @@ BonusBlock::BonusBlock(const Reader& lisp) : Block(sprite_manager->create("images/objects/bonus_block/bonusblock.sprite")), contents(), object(0), - hit_counter(1) + hit_counter(1), + lightsprite(Surface::create("/images/objects/lightmap_light/bonusblock_light.png")) { Vector pos; @@ -97,6 +100,9 @@ BonusBlock::BonusBlock(const Reader& lisp) : contents = CONTENT_CUSTOM; } else if(contentstring == "script") { contents = CONTENT_SCRIPT; + } else if(contentstring == "light") { + contents = CONTENT_LIGHT; + sound_manager->preload("sounds/switch.ogg"); } else { log_warning << "Invalid box contents '" << contentstring << "'" << std::endl; } @@ -244,10 +250,18 @@ BonusBlock::try_open(Player *player) } break; } + case CONTENT_LIGHT: + { + if(sprite->get_action() == "on") + sprite->set_action("off"); + else + sprite->set_action("on"); + sound_manager->play("sounds/switch.ogg"); + } } start_bounce(player); - if(hit_counter <= 0){ //use 0 to allow infinite hits + if(hit_counter <= 0 || contents == CONTENT_LIGHT){ //use 0 to allow infinite hits }else if(hit_counter == 1){ sprite->set_action("empty"); }else{ @@ -273,4 +287,17 @@ Block::break_me() remove_me(); } +void +BonusBlock::draw(DrawingContext& context){ + // draw regular sprite + sprite->draw(context, get_pos(), 10); + //Draw light if on. + if(sprite->get_action() == "on") { + Vector pos = get_pos() + (bbox.get_size() - lightsprite->get_size()) / 2; + context.push_target(); + context.set_target(DrawingContext::LIGHTMAP); + context.draw_surface(lightsprite, pos, 10); + context.pop_target(); + } +} /* EOF */ diff --git a/src/object/bonus_block.hpp b/src/object/bonus_block.hpp index d8798b381..f99378593 100644 --- a/src/object/bonus_block.hpp +++ b/src/object/bonus_block.hpp @@ -18,6 +18,7 @@ #define HEADER_SUPERTUX_OBJECT_BONUS_BLOCK_HPP #include "object/block.hpp" +#include "object/moving_sprite.hpp" class BonusBlock : public Block { @@ -36,7 +37,8 @@ public: CONTENT_STAR, CONTENT_1UP, CONTENT_CUSTOM, - CONTENT_SCRIPT + CONTENT_SCRIPT, + CONTENT_LIGHT }; protected: @@ -46,12 +48,14 @@ public: Contents contents; MovingObject* object; int hit_counter; + void draw(DrawingContext& context); private: BonusBlock(const BonusBlock&); BonusBlock& operator=(const BonusBlock&); std::string sprite_name; std::string script; + SurfacePtr lightsprite; }; #endif