From 44ef9ca509db10b0c7ff6b086e74ee737cb838c9 Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Wed, 26 May 2004 22:46:59 +0000 Subject: [PATCH] A couple of improvements for the flying platform. SVN-Revision: 1333 --- src/gameobjs.cpp | 19 ++++++++++++------- src/gameobjs.h | 5 +++++ src/player.cpp | 4 ++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/gameobjs.cpp b/src/gameobjs.cpp index 743d9cb9b..76722c708 100644 --- a/src/gameobjs.cpp +++ b/src/gameobjs.cpp @@ -302,6 +302,11 @@ FlyingPlatform::FlyingPlatform(DisplayManager& displaymanager, LispReader& reade point = 0; move = false; + float x = pos_x[point+1] - pos_x[point]; + float y = pos_y[point+1] - pos_y[point]; + vel_x = x*velocity / sqrt(x*x + y*y); + vel_y = -(velocity - vel_x); + frame = 0; } @@ -341,6 +346,11 @@ if((unsigned)point+1 != pos_x.size()) pos_y[point] == pos_y[point+1])) { point++; + + float x = pos_x[point+1] - pos_x[point]; + float y = pos_y[point+1] - pos_y[point]; + vel_x = x*velocity / sqrt(x*x + y*y); + vel_y = -(velocity - vel_x); } } else // last point @@ -349,7 +359,7 @@ else // last point // reverse vector return; } - +/* if(pos_x[point+1] > base.x) base.x += velocity * frame_ratio; else if(pos_x[point+1] < base.x) @@ -359,15 +369,10 @@ if(pos_y[point+1] > base.y) base.y += velocity * frame_ratio; else if(pos_y[point+1] < base.y) base.y -= velocity * frame_ratio; -/* -float x = pos_x[point+1] - pos_x[point]; -float y = pos_y[point+1] - pos_y[point]; -float vel_x = x*velocity / sqrt(x*x + y*y); -float vel_y = velocity - vel_x; +*/ base.x += vel_x * frame_ratio; base.y += vel_y * frame_ratio; -*/ } void diff --git a/src/gameobjs.h b/src/gameobjs.h index ff2e31e19..49515a345 100644 --- a/src/gameobjs.h +++ b/src/gameobjs.h @@ -132,6 +132,9 @@ public: virtual void collision(const MovingObject& other, int); void collision(void *p_c_object, int c_object, CollisionType type); + float get_vel_x() { return vel_x; } + float get_vel_y() { return vel_y; } + Physic physic; enum { M_NORMAL, M_HELD } mode; @@ -140,6 +143,8 @@ public: std::vector pos_y; float velocity; + float vel_x, vel_y; // calculated based in the velocity + int point; bool move; unsigned int frame; diff --git a/src/player.cpp b/src/player.cpp index 1c3493956..04af10f05 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -822,7 +822,11 @@ Player::collision(void* p_c_object, int c_object) pplatform_c = (FlyingPlatform*) p_c_object; base.y = pplatform_c->base.y - base.height; + physic.set_velocity_x(pplatform_c->get_vel_x()); + physic.enable_gravity(false); + can_jump = true; + fall_mode = ON_GROUND; break; default: -- 2.11.0