Skip to content

Commit

Permalink
Snowman enhancements: dead-script is passed to snowball, fireballs on…
Browse files Browse the repository at this point in the history
…ly kill body, and jumping on produces a sound.

TODO: the sounds used here should be changed, consider them placeholders.
  • Loading branch information
LMH0013 committed Sep 15, 2013
1 parent 5d875d7 commit 42e5d5c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/badguy/snowball.cpp
Expand Up @@ -25,10 +25,11 @@ SnowBall::SnowBall(const Reader& reader)
walk_speed = 80;
}

SnowBall::SnowBall(const Vector& pos, Direction d)
SnowBall::SnowBall(const Vector& pos, Direction d, std::string script)
: WalkingBadguy(pos, d, "images/creatures/snowball/snowball.sprite", "left", "right")
{
walk_speed = 80;
dead_script = script;
}

bool
Expand Down
2 changes: 1 addition & 1 deletion src/badguy/snowball.hpp
Expand Up @@ -23,7 +23,7 @@ class SnowBall : public WalkingBadguy
{
public:
SnowBall(const Reader& reader);
SnowBall(const Vector& pos, Direction d);
SnowBall(const Vector& pos, Direction d, std::string script);

protected:
bool collision_squished(GameObject& object);
Expand Down
48 changes: 39 additions & 9 deletions src/badguy/snowman.cpp
Expand Up @@ -16,7 +16,9 @@

#include "badguy/snowman.hpp"

#include "audio/sound_manager.hpp"
#include "badguy/snowball.hpp"
#include "object/bullet.hpp"
#include "object/player.hpp"
#include "supertux/sector.hpp"

Expand All @@ -32,20 +34,15 @@ Snowman::Snowman(const Vector& pos, Direction d) :
walk_speed = 40;
}

bool
Snowman::collision_squished(GameObject& object)
void
Snowman::loose_head()
{
// replace with Snowball
Vector snowball_pos = get_pos();
// Hard-coded values from sprites
snowball_pos.x += 5;
snowball_pos.y += 1;

// bounce
Player* player = dynamic_cast<Player*>(&object);
if (player)
player->bounce(*this);

/* Create death animation for the (now headless) snowman. */
set_action (dir == LEFT ? "headless-left" : "headless-right", /* loops = */ -1);
set_pos (get_pos () + Vector (-4.0, 19.0)); /* difference in the sprite offsets */
Expand All @@ -55,9 +52,42 @@ Snowman::collision_squished(GameObject& object)
set_state (STATE_FALLING);

/* Create a new snowball where the snowman's head was */
/* TODO: Pass on our "dead_script" to the snowball. */
SnowBall* snowball = new SnowBall(snowball_pos, dir);
SnowBall* snowball = new SnowBall(snowball_pos, dir, dead_script);
Sector::current()->add_object(snowball);
}

HitResponse
Snowman::collision_bullet(Bullet& bullet, const CollisionHit& hit)
{
if(bullet.get_type() == FIRE_BONUS) {
// fire bullets destroy snowman's body
loose_head();

// FIXME: the sound used here should differ since there is still a threat
sound_manager->play("sounds/fall.wav", get_pos());
bullet.remove_me();

return ABORT_MOVE;
}
else {
// in all other cases, bullets ricochet
bullet.ricochet(*this, hit);
return FORCE_MOVE;
}
}

bool
Snowman::collision_squished(GameObject& object)
{
// bounce
Player* player = dynamic_cast<Player*>(&object);
if (player)
player->bounce(*this);

// FIXME: the squish sound isn't best here
sound_manager->play("sounds/squish.wav", get_pos());

loose_head();

return true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/badguy/snowman.hpp
Expand Up @@ -29,7 +29,10 @@ class Snowman : public WalkingBadguy
Snowman(const Vector& pos, Direction d);

protected:
void loose_head();
virtual HitResponse collision_bullet(Bullet& bullet, const CollisionHit& hit);
bool collision_squished(GameObject& object);

};

#endif
Expand Down

0 comments on commit 42e5d5c

Please sign in to comment.