const std::string ROCK_SOUND = "sounds/brick.wav"; //TODO use own sound.
}
+Rock::Rock(const Vector& pos, std::string spritename)
+ : MovingSprite(pos, spritename)
+{
+ sound_manager->preload(ROCK_SOUND);
+ on_ground = false;
+ grabbed = false;
+ set_group(COLGROUP_MOVING_STATIC);
+}
+
Rock::Rock(const lisp::Lisp& reader)
: MovingSprite(reader, "images/objects/rock/rock.sprite")
{
if( grabbed )
return;
+ if (on_ground) physic.set_velocity_x(0);
+
movement = physic.get_movement(elapsed_time);
}
void
Rock::collision_solid(const CollisionHit& hit)
{
+ if(grabbed) {
+ return;
+ }
if(hit.top || hit.bottom)
physic.set_velocity_y(0);
if(hit.left || hit.right)
if(hit.crush)
physic.set_velocity(0, 0);
- if(hit.bottom && !on_ground) {
+ if(hit.bottom && !on_ground && !grabbed) {
sound_manager->play(ROCK_SOUND, get_pos());
on_ground = true;
}
HitResponse
Rock::collision(GameObject& other, const CollisionHit& hit)
{
+ if(grabbed) {
+ return PASSTHROUGH;
+ }
if(!on_ground) {
if(hit.bottom && physic.get_velocity_y() > 200) {
MovingObject* moving_object = dynamic_cast<MovingObject*> (&other);
Rock::grab(MovingObject& , const Vector& pos, Direction)
{
movement = pos - get_pos();
- set_group(COLGROUP_DISABLED);
- on_ground = true;
+ last_movement = movement;
+ set_group(COLGROUP_TOUCHABLE);
+ on_ground = false;
grabbed = true;
}
void
-Rock::ungrab(MovingObject& , Direction )
+Rock::ungrab(MovingObject& , Direction dir)
{
set_group(COLGROUP_MOVING_STATIC);
on_ground = false;
- physic.set_velocity(0, 0);
+ if(dir == UP) {
+ physic.set_velocity(0, -500);
+ } else if (last_movement.norm() > 1) {
+ physic.set_velocity((dir == RIGHT) ? 200 : -200, -200);
+ } else {
+ physic.set_velocity(0, 0);
+ }
grabbed = false;
}