[Super-tux-commit] supertux/src gameobjs.cpp,1.22,1.23 gameobjs.h,1.15,1.16 player.cpp,1.95,1.96
Brought to you by:
wkendrick
From: Ryan F. <sik...@us...> - 2004-05-17 05:24:48
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23403 Modified Files: gameobjs.cpp gameobjs.h player.cpp Log Message: - tux can now pick up trampoline Index: player.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/player.cpp,v retrieving revision 1.95 retrieving revision 1.96 diff -u -d -r1.95 -r1.96 --- player.cpp 16 May 2004 05:48:28 -0000 1.95 +++ player.cpp 17 May 2004 05:24:40 -0000 1.96 @@ -18,6 +18,8 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <math.h> +#include <iostream> +#include <iostream> #include <cassert> #include "gameloop.h" #include "globals.h" @@ -699,19 +701,43 @@ 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: Index: gameobjs.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameobjs.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- gameobjs.cpp 17 May 2004 01:24:24 -0000 1.22 +++ gameobjs.cpp 17 May 2004 05:24:40 -0000 1.23 @@ -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 @@ { base.x = x; base.y = y; - base.width = 32; base.height = 32; frame = 0; + mode = M_NORMAL; + physic.reset(); } void @@ -256,23 +258,47 @@ 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 @@ 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) Index: gameobjs.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameobjs.h,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- gameobjs.h 17 May 2004 01:24:24 -0000 1.15 +++ gameobjs.h 17 May 2004 05:24:40 -0000 1.16 @@ -131,6 +131,7 @@ void collision(void *p_c_object, int c_object, CollisionType type); Physic physic; + enum { M_NORMAL, M_HELD } mode; private: float power; |