Skip to content

Commit

Permalink
Cleaned up some junk in bonus_block.
Browse files Browse the repository at this point in the history
Removed some unnecessary switches to reduce the amount of code.  Star and Tux dolls now make a noise when leaving the bonus block.  Removed unused variable from coin_explode.  Heavy coins now bounce once when hitting the ground at high velocity and reflect their y velocity when hitting the bottome of something.  Made it easy for the editor to place bonus blocks with the flip level potions.
  • Loading branch information
LMH0013 committed Aug 26, 2013
1 parent 8fe3731 commit a381575
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 54 deletions.
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 3037)
(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/bonus-levelflip.png")
(data 12)
(fps 15)
)

(tile
(id 2948)
(images
Expand Down Expand Up @@ -601,7 +624,7 @@
)
(tilegroup
(name "Block")
(tiles 27 28 29 47 48 50 49 211 77 51 52 212 78 62 61 213 44 83 2947 2948 84 102 140 103 104 105 112 128 2943 2944 2945 2946 1311 2153)
(tiles 27 28 29 47 48 50 49 211 77 51 52 212 78 62 61 213 44 83 2947 2948 84 102 140 103 104 105 112 128 3037 2943 2944 2945 2946 1311 2153)
)
(tilegroup
(name "Background")
Expand Down Expand Up @@ -3993,5 +4016,5 @@
(image "tiles/pole/diagonals.png")
)

;; next-id: 3037
;; next-id: 3038
)
2 changes: 1 addition & 1 deletion src/badguy/goldbomb.cpp
Expand Up @@ -160,7 +160,7 @@ GoldBomb::kill_fall()
if(is_valid()) {
remove_me();
Sector::current()->add_object(new Explosion(get_bbox().get_middle()));
Sector::current()->add_object(new CoinExplode(get_pos() + Vector (0, -40), 1));
Sector::current()->add_object(new CoinExplode(get_pos() + Vector (0, -40)));
}

run_dead_script();
Expand Down
62 changes: 21 additions & 41 deletions src/object/bonus_block.cpp
Expand Up @@ -59,11 +59,20 @@ BonusBlock::BonusBlock(const Vector& pos, int data) :
sound_manager->preload("sounds/switch.ogg");
lightsprite=Surface::create("/images/objects/lightmap_light/bonusblock_light.png");
break;
case 7: contents = CONTENT_TRAMPOLINE; break;
case 8: contents = CONTENT_PORTTRAMPOLINE; break;
case 9: contents = CONTENT_ROCK; break;
case 7: contents = CONTENT_TRAMPOLINE;
//object = new Trampoline(get_pos(), false); //needed if this is to be moved to custom
break;
case 8: contents = CONTENT_CUSTOM;
object = new Trampoline(get_pos(), true);
break;
case 9: contents = CONTENT_CUSTOM;
object = new Rock(get_pos(), "images/objects/rock/rock.sprite");
break;
case 10: contents = CONTENT_RAIN; break;
case 11: contents = CONTENT_EXPLODE; break;
case 12: contents = CONTENT_CUSTOM;
object = new PowerUp(get_pos(), "images/powerups/potions/red-potion.sprite");
break;
default:
log_warning << "Invalid box contents" << std::endl;
contents = CONTENT_COIN;
Expand Down Expand Up @@ -93,7 +102,7 @@ BonusBlock::BonusBlock(const Reader& lisp) :
sprite = sprite_manager->create(sprite_name);
} else if(token == "count") {
iter.value()->get(hit_counter);
} else if(token == "script") { // use when bonusblock is to contain ONLY a script
} else if(token == "script") {
iter.value()->get(script);
} else if(token == "contents") {
std::string contentstring;
Expand All @@ -110,17 +119,13 @@ BonusBlock::BonusBlock(const Reader& lisp) :
contents = CONTENT_1UP;
} else if(contentstring == "custom") {
contents = CONTENT_CUSTOM;
} else if(contentstring == "script") {
} else if(contentstring == "script") { // use when bonusblock is to contain ONLY a script
contents = CONTENT_SCRIPT;
} else if(contentstring == "light") {
contents = CONTENT_LIGHT;
sound_manager->preload("sounds/switch.ogg");
} else if(contentstring == "trampoline") {
contents = CONTENT_TRAMPOLINE;
} else if(contentstring == "porttrampoline") {
contents = CONTENT_PORTTRAMPOLINE;
} else if(contentstring == "rock") {
contents = CONTENT_ROCK;
} else if(contentstring == "rain") {
contents = CONTENT_RAIN;
} else if(contentstring == "explode") {
Expand Down Expand Up @@ -248,12 +253,14 @@ BonusBlock::try_open(Player *player)
case CONTENT_STAR:
{
sector->add_object(new Star(get_pos() + Vector(0, -32), direction));
sound_manager->play("sounds/upgrade.wav");
break;
}

case CONTENT_1UP:
{
sector->add_object(new OneUp(get_pos(), direction));
sound_manager->play("sounds/upgrade.wav");
break;
}

Expand Down Expand Up @@ -285,22 +292,6 @@ BonusBlock::try_open(Player *player)
sound_manager->play("sounds/upgrade.wav");
break;
}
case CONTENT_PORTTRAMPOLINE:
{
SpecialRiser* riser = new SpecialRiser(get_pos(), new Trampoline(get_pos(), true));
sector->add_object(riser);
sound_manager->play("sounds/upgrade.wav");
break;
}
case CONTENT_ROCK:
{
SpecialRiser* riser = new SpecialRiser(get_pos(),
new Rock(get_pos(), "images/objects/rock/rock.sprite"));
sector->add_object(riser);
sound_manager->play("sounds/upgrade.wav");
break;
}

case CONTENT_RAIN:
{
hit_counter = 1; // multiple hits of coin rain is not allowed
Expand All @@ -311,7 +302,7 @@ BonusBlock::try_open(Player *player)
case CONTENT_EXPLODE:
{
hit_counter = 1; // multiple hits of coin explode is not allowed
Sector::current()->add_object(new CoinExplode(get_pos() + Vector (0, -40), 1));
Sector::current()->add_object(new CoinExplode(get_pos() + Vector (0, -40)));
sound_manager->play("sounds/upgrade.wav");
break;
}
Expand Down Expand Up @@ -385,18 +376,20 @@ BonusBlock::try_drop(Player *player)
case CONTENT_STAR:
{
sector->add_object(new Star(get_pos() + Vector(0, 32), direction));
sound_manager->play("sounds/upgrade.wav");
break;
}

case CONTENT_1UP:
{
sector->add_object(new OneUp(get_pos(), DOWN));
sound_manager->play("sounds/upgrade.wav");
break;
}

case CONTENT_CUSTOM:
{
//TODO: confirm this works
//TODO: non-portable trampolines could be moved to CONTENT_CUSTOM, but they should not drop
object->set_pos(get_pos() + Vector(0, 32));
sector->add_object(object);
object = 0;
Expand All @@ -417,19 +410,6 @@ BonusBlock::try_drop(Player *player)
try_open(player);
break;
}
case CONTENT_PORTTRAMPOLINE:
{
Sector::current()->add_object(new Trampoline(get_pos() + Vector (0, 32), true));
sound_manager->play("sounds/upgrade.wav");
break;
}
case CONTENT_ROCK:
{
Sector::current()->add_object(new Rock(get_pos() + Vector (0, 32), "images/objects/rock/rock.sprite"));
sound_manager->play("sounds/upgrade.wav");
break;
}

case CONTENT_RAIN:
{
try_open(player);
Expand All @@ -438,7 +418,7 @@ BonusBlock::try_drop(Player *player)
case CONTENT_EXPLODE:
{
hit_counter = 1; // multiple hits of coin explode is not allowed
Sector::current()->add_object(new CoinExplode(get_pos() + Vector (0, 40), -1));
Sector::current()->add_object(new CoinExplode(get_pos() + Vector (0, 40)));
sound_manager->play("sounds/upgrade.wav");
break;
}
Expand Down
2 changes: 0 additions & 2 deletions src/object/bonus_block.hpp
Expand Up @@ -41,8 +41,6 @@ class BonusBlock : public Block
CONTENT_SCRIPT,
CONTENT_LIGHT,
CONTENT_TRAMPOLINE,
CONTENT_PORTTRAMPOLINE,
CONTENT_ROCK,
CONTENT_RAIN,
CONTENT_EXPLODE
};
Expand Down
10 changes: 7 additions & 3 deletions src/object/coin.cpp
Expand Up @@ -208,8 +208,12 @@ HeavyCoin::collision_solid(const CollisionHit& hit)
if(hit.bottom) {
if(physic.get_velocity_y() > clink_threshold)
sound_manager->play("sounds/coin.wav");
physic.set_velocity_y(0);
physic.set_velocity_x(0);
if(physic.get_velocity_y() > 200) {// lets some coins bounce
physic.set_velocity_y(-99);
}else{
physic.set_velocity_y(0);
physic.set_velocity_x(0);
}
}
if(hit.right || hit.left) {
if(physic.get_velocity_x() > clink_threshold || physic.get_velocity_x() < clink_threshold)
Expand All @@ -219,7 +223,7 @@ HeavyCoin::collision_solid(const CollisionHit& hit)
if(hit.top) {
if(physic.get_velocity_y() < clink_threshold)
sound_manager->play("sounds/coin.wav");
physic.set_velocity_y(0);
physic.set_velocity_y(-physic.get_velocity_y());
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/object/coin_explode.cpp
Expand Up @@ -20,9 +20,8 @@
#include "object/coin.hpp"
#include "supertux/sector.hpp"

CoinExplode::CoinExplode(const Vector& pos, const int vert) :
position(pos),
y_velocity_weight(vert) // should generally be +/- 1 to send coins up or down respectively
CoinExplode::CoinExplode(const Vector& pos) :
position(pos)
{
}

Expand Down
3 changes: 1 addition & 2 deletions src/object/coin_explode.hpp
Expand Up @@ -25,13 +25,12 @@
class CoinExplode : public GameObject
{
public:
CoinExplode(const Vector& pos, const int vert);
CoinExplode(const Vector& pos);
virtual void update(float elapsed_time);
virtual void draw(DrawingContext& context);

private:
Vector position;
int y_velocity_weight;
};

#endif
Expand Down

0 comments on commit a381575

Please sign in to comment.