projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
SDL: Implement lightmaps smaller than the screen size. LIGHTMAP_DIV is calculated...
[supertux.git]
/
src
/
object
/
rock.cpp
diff --git
a/src/object/rock.cpp
b/src/object/rock.cpp
index
e5f10b3
..
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")
{
@@
-72,6
+81,9
@@
Rock::update(float elapsed_time)
void
Rock::collision_solid(const CollisionHit& hit)
{
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)
@@
-79,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;
}
@@
-88,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);
@@
-107,8
+122,8
@@
Rock::grab(MovingObject& , const Vector& pos, Direction)
{
movement = pos - get_pos();
last_movement = movement;
{
movement = pos - get_pos();
last_movement = movement;
- set_group(COLGROUP_
DISABLED
);
- on_ground =
tru
e;
+ set_group(COLGROUP_
TOUCHABLE
);
+ on_ground =
fals
e;
grabbed = true;
}
grabbed = true;
}
@@
-117,7
+132,9
@@
Rock::ungrab(MovingObject& , Direction dir)
{
set_group(COLGROUP_MOVING_STATIC);
on_ground = false;
{
set_group(COLGROUP_MOVING_STATIC);
on_ground = false;
- if (last_movement.norm() > 1) {
+ 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);
physic.set_velocity((dir == RIGHT) ? 200 : -200, -200);
} else {
physic.set_velocity(0, 0);