Skip to content

Commit

Permalink
New bonus_block content: light
Browse files Browse the repository at this point in the history
  • Loading branch information
LMH0013 committed Nov 28, 2012
1 parent ae73da5 commit f0fb4b7
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 7 deletions.
6 changes: 6 additions & 0 deletions data/images/objects/bonus_block/bonusblock.sprite
Expand Up @@ -16,4 +16,10 @@
(action
(name "empty")
(images "empty.png"))
(action
(name "on")
(images "on.png"))
(action
(name "off")
(images "off.png"))
)
Binary file added data/images/objects/bonus_block/light.xcf
Binary file not shown.
Binary file added data/images/objects/bonus_block/off.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/on.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 25 additions & 2 deletions data/images/tiles.strf
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -3823,5 +3846,5 @@
(image "tiles/snow/slope-upper.png" )
)

;; next-id: 2943
;; next-id: 2944
)
2 changes: 1 addition & 1 deletion data/levels/test/bonusblock.stl
Expand Up @@ -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
Expand Down
33 changes: 30 additions & 3 deletions src/object/bonus_block.cpp
Expand Up @@ -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");
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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{
Expand All @@ -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 */
6 changes: 5 additions & 1 deletion src/object/bonus_block.hpp
Expand Up @@ -18,6 +18,7 @@
#define HEADER_SUPERTUX_OBJECT_BONUS_BLOCK_HPP

#include "object/block.hpp"
#include "object/moving_sprite.hpp"

class BonusBlock : public Block
{
Expand All @@ -36,7 +37,8 @@ class BonusBlock : public Block
CONTENT_STAR,
CONTENT_1UP,
CONTENT_CUSTOM,
CONTENT_SCRIPT
CONTENT_SCRIPT,
CONTENT_LIGHT
};

protected:
Expand All @@ -46,12 +48,14 @@ class BonusBlock : public Block
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
Expand Down

0 comments on commit f0fb4b7

Please sign in to comment.