{
CO_BULLET,
CO_BADGUY,
- CO_PLAYER
+ CO_PLAYER,
+ CO_TRAMPOLINE
};
enum CollisionType {
{
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);
}
}
}
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);
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 */
#include "timer.h"
#include "scene.h"
#include "physic.h"
+#include "collision.h"
enum ObjectType { OBJ_NONE, OBJ_BADGUY, OBJ_TRAMPOLINE };
init(data.x, data.y);
};
+ void collision(void *p_c_object, int c_object, CollisionType type);
+
Physic physic;
private:
// 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"
Player::collision(void* p_c_object, int c_object)
{
BadGuy* pbad_c = NULL;
+ Trampoline* ptramp_c = NULL;
switch (c_object)
{
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;
}
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