projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Tux grows faster, stops growing when hit
[supertux.git]
/
src
/
object
/
rock.cpp
diff --git
a/src/object/rock.cpp
b/src/object/rock.cpp
index
472e396
..
7c56e1a
100644
(file)
--- a/
src/object/rock.cpp
+++ b/
src/object/rock.cpp
@@
-29,6
+29,15
@@
namespace {
const std::string ROCK_SOUND = "sounds/brick.wav"; //TODO use own sound.
}
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")
{
Rock::Rock(const lisp::Lisp& reader)
: MovingSprite(reader, "images/objects/rock/rock.sprite")
{
@@
-64,12
+73,17
@@
Rock::update(float elapsed_time)
if( grabbed )
return;
if( grabbed )
return;
+ if (on_ground) physic.set_velocity_x(0);
+
movement = physic.get_movement(elapsed_time);
}
void
Rock::collision_solid(const CollisionHit& hit)
{
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.top || hit.bottom)
physic.set_velocity_y(0);
if(hit.left || hit.right)
@@
-77,7
+91,7
@@
Rock::collision_solid(const CollisionHit& hit)
if(hit.crush)
physic.set_velocity(0, 0);
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;
}
sound_manager->play(ROCK_SOUND, get_pos());
on_ground = true;
}
@@
-86,6
+100,9
@@
Rock::collision_solid(const CollisionHit& hit)
HitResponse
Rock::collision(GameObject& other, const CollisionHit& hit)
{
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);
if(!on_ground) {
if(hit.bottom && physic.get_velocity_y() > 200) {
MovingObject* moving_object = dynamic_cast<MovingObject*> (&other);
@@
-104,17
+121,24
@@
void
Rock::grab(MovingObject& , const Vector& pos, Direction)
{
movement = pos - get_pos();
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
grabbed = true;
}
void
-Rock::ungrab(MovingObject& , Direction )
+Rock::ungrab(MovingObject& , Direction
dir
)
{
set_group(COLGROUP_MOVING_STATIC);
on_ground = false;
{
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;
}
grabbed = false;
}