I lost the source code of that build, but I hope this helps. The collision that I'm using is custom code writen by me, so it might be really irrelevant to you. The collision class below has been writen with my current game in mind, unlike the one used in the demo you saw.
Collision:
struct CollisionBox
{
int Width;
int Height;
};
template< class Map > class WorldCollision // Map is a 2D array of ints
{
public:
// Set
void SetBoundingBox(const int xMiddleOfSprite, const int Height)
{
m_CollisionBox.Height = Height;
m_CollisionBox.Width = xMiddleOfSprite;
}
void SetCollisionMap(const Map* const pMap , const int Tile_Size)
{
m_pMap = const_cast<Map*>(pMap);
m_TileSize = Tile_Size;
}
// Collision.
// 0 - nothing
// 1 - solid
// 2 - jump pad
bool PlayerWorldCollisionCheck(const int YOffSet = 0 , const int CollisionValue = 1)
{
for(int h = 1; h <= m_CollisionBox.Height; ++h)
{
if((*m_pMap)
//Y Axis
[((dbSpriteOffsetY(2) - YOffSet + ( dbScreenHeight() / 2 ) + 16 + h)/ m_TileSize)]
//X Axis
[((dbSpriteOffsetX(2) + ( dbScreenWidth() / 2 ) + m_CollisionBox.Width)/ m_TileSize)]
== CollisionValue)
{
// Character collided with world
return true;
}
}
return false;
}
bool EnemyWorldCollisionCheck(const int CharacterSprite, const int YOffSet = 0, const int CollisionValue = 1)
{
for(int h = 1; h <= m_CollisionBox.Height; ++h)
{
if((*m_pMap)
//Y Axis
[((dbSpriteOffsetY(2) - dbSpriteOffsetY(CharacterSprite) - YOffSet + (dbSpriteY(CharacterSprite)) + 16 + h)/ m_TileSize)]
//X Axis
[((dbSpriteOffsetX(2) - dbSpriteOffsetX(CharacterSprite) + (dbSpriteX(CharacterSprite)) + m_CollisionBox.Width)/ m_TileSize)]
== CollisionValue)
{
return true;
}
}
return false;
}
private:
Map* m_pMap;
CollisionBox m_CollisionBox;
int m_TileSize;
};
Gravity:
const float foot = 0.30480f;
class Gravity
{
public:
Gravity(const float Velocity = 35.05f, const float Gravity = 12.0f ) : T(0), G(Gravity), V(Velocity) {}
// Set
inline void SetTime(const float Time) { T = Time; }
inline void SetVelocity(const float Velocity) { V = Velocity; }
inline void IncrementTime(void) { T += 0.1; }
inline void ResetTime(void) { T = 0; }
//Get
inline float GetTime() const { return T; }
// Gravity Equations for Upward Motion
inline float UpVelocity(void) const { return (V - (G * (T))); }
inline float UpTimeToReachPeak(void) const { return (V / G); }
inline bool IsCharacterJumping(void)
{
if( T <= UpTimeToReachPeak() ) return true;
else return false;
}
// Gravity Equations for Falling Objects
inline float DownVelocity(void) const { return (G * (T)); }
private:
float V, T, A, G;
};
bool Rise()
{
if( pGravity->IsCharacterJumping() )
{
pGravity->IncrementTime();
Move Character at this speed (-pGravity->UpVelocity() *foot)
// More here...
return true;
}
return false;
}
void Fall()
{
pGravity->ResetTime();
while(!pCollision->PlayerWorldCollisionCheck()) // <----- Get rid of the while loop so that this function loops once per frame
{
pGravity->IncrementTime();
Move Character at this speed (pGravity->DownVelocity() *foot)
//More Here...
dbSync();
}
}
Main Loop:
bool Jump = false;
while(LoopGDK())
{
if((USER_IMPUT_JUMP)
{
if(!Jump) Jump = true;
}
if(Jump)
{
if(!Rise()) Jump = false;
}
//more here..
Fall();
dbSync();
}