15,7 → 15,7 |
linePoints.append(QPoint(x, y)); |
|
velocity = 1; |
angle = 0; |
angle = (rand() % 4) * 90; |
abpool = 0; |
name = ""; |
show = false; |
81,6 → 81,15 |
{ |
x -= velocity; |
} |
if (angle == 0 || angle == 180) |
{ |
painter->fillRect(x - 5, y - 15, 10, 30, colour); |
} |
else |
{ |
painter->fillRect(x - 15, y - 5, 30, 10, colour); |
} |
painter->drawText(x, y - 20, name); |
} |
else |
{ |
87,16 → 96,9 |
linePoints.clear(); |
} |
|
if (angle == 0 || angle == 180) |
{ |
painter->fillRect(x - 5, y - 15, 10, 30, colour); |
} |
else |
{ |
painter->fillRect(x - 15, y - 5, 30, 10, colour); |
} |
|
painter->drawText(x, y - 20, name); |
|
|
} |
} |
|
107,12 → 109,18 |
Bike *bike = bikes[i]; |
if (bike->isReady && bike->show) |
{ |
if (bike->dead || bike->collided) |
if (bike->collided) |
{ |
socket->write("DEAD "); |
socket->write(bike->name.toAscii()); |
socket->write("\n"); |
} |
else if (bike->dead) |
{ |
socket->write("DISCO "); |
socket->write(bike->name.toAscii()); |
socket->write("\n"); |
} |
else |
{ |
socket->write("BIKE "); |
186,28 → 194,57 |
for(r = 0; r < bikes.count(); r++) |
{ |
bike = bikes[r]; |
for(j = 0; j < bike->linePoints.count() - 1; j++) |
int forsubtract = 1; |
if(bike->name == name){ |
forsubtract = 3; |
} |
for(j = 0; j < bike->linePoints.count() - forsubtract; j++) |
{ |
if(!(bike->linePoints[j].x() == bike->linePoints[j+1].x() && linePoints[i].x() == linePoints[i-1].x()) && !(bike->linePoints[j].y() == bike->linePoints[j+1].y() && linePoints[i].y() == linePoints[i-1].y())) |
int jx = bike->linePoints[j].x(); |
int j1x = bike->linePoints[j+1].x(); |
int jy = bike->linePoints[j].y(); |
int j1y = bike->linePoints[j+1].y(); |
int ix = linePoints[i-1].x(); |
int i1x = linePoints[i].x(); |
int iy = linePoints[i-1].y(); |
int i1y = linePoints[i].y(); |
|
if(angle == 0){ |
iy += 1; |
i1y -= 1; |
} |
if(angle == 90){ |
ix -= 1; |
i1x += 1; |
} |
if(angle == 180){ |
iy -= 1; |
i1y += 1; |
} |
if(angle == 270){ |
ix += 1; |
i1x -= 1; |
} |
if(!(jx == j1x && i1x == ix) && !(jy == j1y && i1y == iy)) |
{ |
|
// If not parallel |
if(bike->linePoints[j].x() == bike->linePoints[j+1].x()) |
if(jx == j1x) |
{ |
// x equal |
|
if(linePoints[i-1].x() > bike->linePoints[j].x() && linePoints[i].x() < bike->linePoints[j].x() || linePoints[i-1].x() < bike->linePoints[j].x() && linePoints[i].x() > bike->linePoints[j].x()) |
if(ix > jx && i1x < jx || ix < jx && i1x > jx) |
{ |
if((sign(linePoints[i-1].y() - bike->linePoints[j].y()) != sign(linePoints[i-1].y() - bike->linePoints[j+1].y()))) |
if((sign(iy - jy) != sign(iy - j1y))) |
return true; |
} |
} |
if(bike->linePoints[j].y() == bike->linePoints[j+1].y()) |
if(jy == j1y) |
{ |
|
if(linePoints[i-1].y() > bike->linePoints[j].y() && linePoints[i].y() < bike->linePoints[j].y() || linePoints[i-1].y() < bike->linePoints[j].y() && linePoints[i].y() > bike->linePoints[j].y()) |
if(iy > jy && i1y < jy || iy < jy && i1y > jy) |
{ |
if((sign(linePoints[i-1].x() - bike->linePoints[j].x()) != sign(linePoints[i-1].x() - bike->linePoints[j+1].x()))) |
if((sign(ix - jx) != sign(ix - j1x))) |
return true; |
} |
} |
257,9 → 294,11 |
angle += 360; |
} |
if(velocity < 5) |
velocity += 0.5; |
velocity += 0.3; |
else if(velocity > 5) |
velocity -= 0.5; |
velocity -= 0.3; |
if(abs(5-velocity)<0.3) |
velocity = 5; |
if(abpool<10) |
abpool += 0.2; |
hadGo = true; |
277,9 → 316,11 |
angle += 360; |
} |
if(velocity < 5) |
velocity += 0.5; |
velocity += 0.3; |
else if(velocity > 5) |
velocity -= 0.5; |
velocity -= 0.3; |
if(abs(5-velocity)<0.3) |
velocity = 5; |
if(abpool<10) |
abpool += 0.2; |
hadGo = true; |
289,6 → 330,13 |
if(abpool > 0){ |
velocity += 0.1; |
abpool -= 0.5; |
} else { |
if(velocity < 5) |
velocity += 0.3; |
else if(velocity > 5) |
velocity -= 0.3; |
if(abs(5-velocity)<0.3) |
velocity = 5; |
} |
hadGo = true; |
} |
298,14 → 346,25 |
velocity -= 0.2; |
abpool -= 0.5; |
} |
else { |
if(velocity < 5) |
velocity += 0.3; |
else if(velocity > 5) |
velocity -= 0.3; |
if(abs(5-velocity)<0.3) |
velocity = 5; |
} |
hadGo = true; |
} |
else if (line == "N") |
{ |
|
if(velocity < 5) |
velocity += 0.5; |
velocity += 0.3; |
else if(velocity > 5) |
velocity -= 0.5; |
velocity -= 0.3; |
if(abs(5-velocity)<0.3) |
velocity = 5; |
if(abpool<10) |
abpool += 0.2; |
hadGo = true; |