Subversion Repositories QTron

Compare Revisions

Regard whitespace Rev 8 → Rev 9

/bike.cpp
162,11 → 162,48
hasHadGo = true;
}
 
int sign(float x){
if(x > 0){
return 1;
}
if(x < 0){
return -1;
}
return 0;
}
 
bool Bike::hasCollided()
{
// Do collision detection here
// use linePoints
 
int i = linePoints.count() - 1;
if(linePoints[i-1].x() < 0 || linePoints[i-1].x() > 800 || linePoints[i-1].y() < 0 || linePoints[i-1].y() > 600)
return true;
if(linePoints[i].x() < 0 || linePoints[i].x() > 800 || linePoints[i].y() < 0 || linePoints[i].y() > 600)
return true;
for(int j = 0; j < linePoints.count() - 2; j++)
{
if(!(linePoints[j].x == linePoints[j+1].x() && linePoints[i].x() == linePoints[i-1].x()) && !(linePoints[j].y() == linePoints[j+1].y() && linePoints[i].y == linePoints[i-1].y()))
{
// If not parallel
if(linePoints[j].x() == linePoints[j+1].x())
{
// x equal
if(linePoints[i-1].x() > linePoints[j].x() && linePoints[i].x() < linePoints[j].x() || linePoints[i-1].x() < linePoints[j].x() && linePoints[i].x() > linePoints[j].x()){
if((sign(linePoints[i-1].y() - linePoints[j].y()) != sign(linePoints[i-1].y() - linePoints[j+1].y())))
return true;
}
}
else if(linePoints[j].y() == linePoints[j+1].y())
{
if(linePoints[i-1].y() > linePoints[j].y() && linePoints[i].y() < linePoints[j].y() || linePoints[i-1].y() < linePoints[j].y() && linePoints[i].y() > linePoints[j].y())
{
if((sign(linePoints[i-1].x() - linePoints[j].x()) != sign(linePoints[i-1].x() - linePoints[j+1].x())))
return true;
}
}
}
}
return false;
}