[Super-tux-commit] supertux/src collision.h,1.11,1.12 gameobjs.cpp,1.19,1.20 gameobjs.h,1.12,1.13 pl
Brought to you by:
wkendrick
From: Ryan F. <sik...@us...> - 2004-05-16 05:48:37
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5449 Modified Files: collision.h gameobjs.cpp gameobjs.h player.cpp world.cpp Log Message: - trampoline stuff Index: collision.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/collision.h,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- collision.h 26 Apr 2004 19:11:53 -0000 1.11 +++ collision.h 16 May 2004 05:48:28 -0000 1.12 @@ -31,7 +31,8 @@ { CO_BULLET, CO_BADGUY, - CO_PLAYER + CO_PLAYER, + CO_TRAMPOLINE }; enum CollisionType { Index: player.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/player.cpp,v retrieving revision 1.94 retrieving revision 1.95 diff -u -d -r1.94 -r1.95 --- player.cpp 13 May 2004 12:44:36 -0000 1.94 +++ player.cpp 16 May 2004 05:48:28 -0000 1.95 @@ -18,6 +18,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <math.h> +#include <cassert> #include "gameloop.h" #include "globals.h" #include "player.h" @@ -643,6 +644,7 @@ Player::collision(void* p_c_object, int c_object) { BadGuy* pbad_c = NULL; + Trampoline* ptramp_c = NULL; switch (c_object) { @@ -693,6 +695,25 @@ player_status.score_multiplier++; } break; + + case CO_TRAMPOLINE: + ptramp_c = (Trampoline*) p_c_object; + + 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; + } + else + { + } + break; + default: break; } Index: gameobjs.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameobjs.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- gameobjs.cpp 16 May 2004 04:04:03 -0000 1.19 +++ gameobjs.cpp 16 May 2004 05:48:28 -0000 1.20 @@ -223,7 +223,7 @@ { char sprite_name[16]; sprintf(sprite_name, "trampoline-%i", i+1); - img_trampoline[0] = sprite_manager->load(sprite_name); + img_trampoline[i] = sprite_manager->load(sprite_name); } } @@ -238,6 +238,15 @@ } void +Trampoline::draw() +{ + img_trampoline[0]->draw((int)base.x, (int)base.y); + + if (debug_mode) + fillrect(base.x - scroll_x, base.y - scroll_y, base.width, base.height, 75, 75, 0, 150); +} + +void Trampoline::action(double frame_ratio) { physic.apply(frame_ratio, base.x, base.y); @@ -253,19 +262,50 @@ else physic.enable_gravity(true); - // TODO: - // If HELD - // - move with tux - // If jumped on - // - compress springs (reduce height) } +// TODO: +// If HELD +// - move with tux +// If jumped on +// - compress springs (reduce height) + void -Trampoline::draw() +Trampoline::collision(void *p_c_object, int c_object, CollisionType type) { - img_trampoline[0]->draw((int)base.x, (int)base.y); -} + Player* pplayer_c = NULL; + switch (c_object) + { + case CO_PLAYER: + pplayer_c = (Player*) p_c_object; + + if (type == COLLISION_NORMAL) + { + // TODO: Pick up if HELD + } + else if (type == COLLISION_SQUISH) + { + // TODO: compress springs + // TODO: launch tux, if necessary + + base.y = pplayer_c->base.y + pplayer_c->base.height; + base.height = (32 - (int)pplayer_c->base.y % 32); + if (base.height < 16) + { + base.height = 32; + + pplayer_c->physic.set_velocity_y(8); + } + } + + break; + + default: + break; + + } +} /* EOF */ Index: world.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/world.cpp,v retrieving revision 1.94 retrieving revision 1.95 diff -u -d -r1.94 -r1.95 --- world.cpp 16 May 2004 03:28:22 -0000 1.94 +++ world.cpp 16 May 2004 05:48:28 -0000 1.95 @@ -499,6 +499,25 @@ upgrades[i].collision(&tux, CO_PLAYER, COLLISION_NORMAL); } } + + // CO_TRAMPOLINE & (CO_PLAYER or CO_BADGUY) + for (Trampolines::iterator i = trampolines.begin(); i != trampolines.end(); ++i) + { + if (rectcollision((*i)->base, tux.base)) + { + if (tux.previous_base.y < tux.base.y && + tux.previous_base.y + tux.previous_base.height + < (*i)->base.y + (*i)->base.height/2) + { + (*i)->collision(&tux, CO_PLAYER, COLLISION_SQUISH); + } + else + { + tux.collision(*i, CO_TRAMPOLINE); + (*i)->collision(&tux, CO_PLAYER, COLLISION_NORMAL); + } + } + } } void Index: gameobjs.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameobjs.h,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- gameobjs.h 16 May 2004 03:28:22 -0000 1.12 +++ gameobjs.h 16 May 2004 05:48:28 -0000 1.13 @@ -27,6 +27,7 @@ #include "timer.h" #include "scene.h" #include "physic.h" +#include "collision.h" enum ObjectType { OBJ_NONE, OBJ_BADGUY, OBJ_TRAMPOLINE }; @@ -127,6 +128,8 @@ init(data.x, data.y); }; + void collision(void *p_c_object, int c_object, CollisionType type); + Physic physic; private: |