Skip to content

Instantly share code, notes, and snippets.

@wjdp
Created April 8, 2014 12:45
Show Gist options
  • Save wjdp/10118593 to your computer and use it in GitHub Desktop.
Save wjdp/10118593 to your computer and use it in GitHub Desktop.
int MoveableObject::CollisionY
int MoveableObject::CollisionY(bool bToJump)
{
int iDesired;
if (bToJump)
{
int iDirection = 1;
int iDesired = m_iCurrentScreenY + m_iCollisionY + m_iCollisionHeight + 1;
printf("%d %d\n", iDesired, m_iCurrentScreenY + m_iCollisionY + m_iCollisionHeight);
}
else
{
int iDirection = (int)m_fSub_Pixel_Y - m_iCurrentScreenY;
if (iDirection>0) iDesired = (int)m_fSub_Pixel_Y + m_iCollisionY + m_iCollisionHeight;
else if (iDirection<0) iDesired = (int)m_fSub_Pixel_Y + m_iCollisionY;
else return 0;
}
int iLeft = (int)m_fSub_Pixel_X + m_iCollisionX;
int iRight = (int)m_fSub_Pixel_X + m_iCollisionX + m_iCollisionWidth;
int pos = 1;
bool bCollide = false;
ObjectData* sObjectDataArray = GetMyEngine()->GetCombinedObjectArray();
int iObjectDataArraySize = GetMyEngine()->GetCombinedObjectArraySize();
ObjectData sForeignObject = sObjectDataArray[pos];
while (pos <= iObjectDataArraySize) {
//printf("%d %d %d %d\n",sForeignObject.x_left,sForeignObject.x_right,sForeignObject.y_top, sForeignObject.y_bottom);
/*if (sForeignObject.y_top <= iDesiredBottom) {
if (sForeignObject.x_left <= iMyMidPoint && sForeignObject.x_right >= iMyMidPoint)
{
bCollide = true;
}*/
if ( (sForeignObject.x_left < iLeft && sForeignObject.x_right > iLeft) ||
(sForeignObject.x_left < iRight && sForeignObject.x_right > iRight))
{
if (sForeignObject.y_top <= iDesired && sForeignObject.y_bottom >= iDesired)
{
bCollide = true;
}
}
pos++;
sForeignObject = sObjectDataArray[pos];
}
if (bCollide == true) {
return 1; // We're only using 1px for correction factors at the moment
}
else
{
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment