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
2d85ff2
..
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,7
+73,7
@@
Rock::update(float elapsed_time)
if( grabbed )
return;
if( grabbed )
return;
- if (on_ground) physic.
vx = 0
;
+ if (on_ground) physic.
set_velocity_x(0)
;
movement = physic.get_movement(elapsed_time);
}
movement = physic.get_movement(elapsed_time);
}
@@
-72,15
+81,17
@@
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)
if(hit.top || hit.bottom)
- physic.
vy = 0
;
+ physic.
set_velocity_y(0)
;
if(hit.left || hit.right)
if(hit.left || hit.right)
- physic.
vx = 0
;
+ physic.
set_velocity_x(0)
;
if(hit.crush)
if(hit.crush)
- physic.vx = 0;
- physic.vy = 0;
+ 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;
}
@@
-89,8
+100,11
@@
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(!on_ground) {
- if(hit.bottom && physic.
vy
> 200) {
+ if(hit.bottom && physic.
get_velocity_y()
> 200) {
MovingObject* moving_object = dynamic_cast<MovingObject*> (&other);
if(moving_object) {
//Getting a rock on the head hurts. A lot.
MovingObject* moving_object = dynamic_cast<MovingObject*> (&other);
if(moving_object) {
//Getting a rock on the head hurts. A lot.
@@
-108,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;
}
@@
-118,12
+132,12
@@
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) {
- physic.vx = ((dir == RIGHT) ? 200 : -200);
- physic.vy = -200;
+ if(dir == UP) {
+ physic.set_velocity(0, -500);
+ } else if (last_movement.norm() > 1) {
+ physic.set_velocity((dir == RIGHT) ? 200 : -200, -200);
} else {
} else {
- physic.vx = 0;
- physic.vy = 0;
+ physic.set_velocity(0, 0);
}
grabbed = false;
}
}
grabbed = false;
}