From 361f17a609e4d3c7f688048facf171191192bba6 Mon Sep 17 00:00:00 2001 From: Ryan Flegel Date: Mon, 17 May 2004 05:24:40 +0000 Subject: [PATCH] - tux can now pick up trampoline SVN-Revision: 1226 --- src/gameobjs.cpp | 57 +++++++++++++++++++++++++++++++++++++++----------------- src/gameobjs.h | 1 + src/player.cpp | 40 ++++++++++++++++++++++++++++++++------- 3 files changed, 74 insertions(+), 24 deletions(-) diff --git a/src/gameobjs.cpp b/src/gameobjs.cpp index 3fcf0306d..f96a72cf7 100644 --- a/src/gameobjs.cpp +++ b/src/gameobjs.cpp @@ -26,6 +26,7 @@ #include "gameobjs.h" #include "sprite_manager.h" #include "resources.h" +#include "level.h" void BouncyDistro::init(float x, float y) @@ -232,11 +233,12 @@ Trampoline::init(float x, float y) { base.x = x; base.y = y; - base.width = 32; base.height = 32; frame = 0; + mode = M_NORMAL; + physic.reset(); } void @@ -256,23 +258,47 @@ Trampoline::action(double frame_ratio) physic.apply(frame_ratio, base.x, base.y); // Falling - if (issolid(base.x + base.width/2, base.y + base.height)) + if (mode != M_HELD) { - base.y = int((base.y + base.height)/32) * 32 - base.height; + if (issolid(base.x + base.width/2, base.y + base.height)) + { + base.y = int((base.y + base.height)/32) * 32 - base.height; + + physic.enable_gravity(false); + physic.set_velocity_y(0.0f); - physic.enable_gravity(false); - physic.set_velocity_y(0.0f); + physic.set_velocity_x(0); + } + else + { + physic.enable_gravity(true); + } } - else - physic.enable_gravity(true); + else // Player is carrying us around + { + /* FIXME: The trampoline object shouldn't know about pplayer objects. */ + /* If we're holding the iceblock */ + Player& tux = *World::current()->get_tux(); + Direction dir = tux.dir; -} + if(dir == RIGHT) + { + base.x = tux.base.x + 16; + base.y = tux.base.y + tux.base.height/1.5 - base.height; + } + else /* facing left */ + { + base.x = tux.base.x - 16; + base.y = tux.base.y + tux.base.height/1.5 - base.height; + } -// TODO: -// If HELD -// - move with tux -// If jumped on -// - compress springs (reduce height) + if(collision_object_map(base)) + { + base.x = tux.base.x; + base.y = tux.base.y + tux.base.height/1.5 - base.height; + } + } +} void Trampoline::collision(void *p_c_object, int c_object, CollisionType type) @@ -285,14 +311,11 @@ Trampoline::collision(void *p_c_object, int c_object, CollisionType type) if (type == COLLISION_NORMAL) { - // TODO: Pick up if HELD + // Pick up if HELD (done in Player) } else if (type == COLLISION_SQUISH) { - // TODO: compress springs - // TODO: launch tux, if necessary - int squish_amount = (32 - (int)pplayer_c->base.y % 32); if (squish_amount < 24) diff --git a/src/gameobjs.h b/src/gameobjs.h index 36c508c5a..b6470e43d 100644 --- a/src/gameobjs.h +++ b/src/gameobjs.h @@ -131,6 +131,7 @@ class Trampoline : public GameObject void collision(void *p_c_object, int c_object, CollisionType type); Physic physic; + enum { M_NORMAL, M_HELD } mode; private: float power; diff --git a/src/player.cpp b/src/player.cpp index c04bd03bb..178c75051 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -18,6 +18,8 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include +#include +#include #include #include "gameloop.h" #include "globals.h" @@ -699,19 +701,43 @@ Player::collision(void* p_c_object, int c_object) case CO_TRAMPOLINE: ptramp_c = (Trampoline*) p_c_object; - if (physic.get_velocity_x() > 0) // RIGHT + // Pick up trampoline + if (ptramp_c->mode != Trampoline::M_HELD && input.fire == DOWN && !holding_something) { - physic.set_velocity_x(0); - base.x = ptramp_c->base.x - base.width; + holding_something = true; + ptramp_c->mode = Trampoline::M_HELD; + ptramp_c->base.y -= 8; } - else if (physic.get_velocity_x() < 0) // LEFT + // Set down trampoline + else if (ptramp_c->mode == Trampoline::M_HELD && input.fire != DOWN) { - physic.set_velocity_x(0); - base.x = ptramp_c->base.x + ptramp_c->base.width; + holding_something = false; + ptramp_c->mode = Trampoline::M_NORMAL; + ptramp_c->base.y += 8; + ptramp_c->physic.set_velocity(physic.get_velocity_x(), physic.get_velocity_y()); + + //if (dir == RIGHT) + // ptramp_c->base.x = base.x + base.width+1; + //else /* LEFT */ + // ptramp_c->base.x = base.x - base.width-1; } - else +/* + // Don't let tux walk through trampoline + else if (ptramp_c->mode != Trampoline::M_HELD && on_ground()) { + if (physic.get_velocity_x() > 0) // RIGHT + { + physic.set_velocity_x(0); + base.x = ptramp_c->base.x - base.width; + } + else if (physic.get_velocity_x() < 0) // LEFT + { + physic.set_velocity_x(0); + base.x = ptramp_c->base.x + ptramp_c->base.width; + } } +*/ + break; default: -- 2.11.0