10,11 → 10,11 |
|
isDisconnected = false; |
|
x = rand() % 80000; |
y = rand() % 60000; |
x = rand() % 800; |
y = rand() % 600; |
linePoints.append(QPoint(x, y)); |
|
velocity = 100; |
velocity = 1; |
angle = (rand() % 4) * 90; |
abpool = 0; |
name = ""; |
23,14 → 23,12 |
hadGo = false; |
dead = false; |
collided = false; |
speed = 500; |
speed = 5; |
|
colour.setBlue(0); |
colour.setRed(0); |
colour.setGreen(0); |
|
greet(); |
|
if (!socket->waitForReadyRead(2000)) |
{ |
socket->disconnectFromHost(); |
62,7 → 60,7 |
|
point2 = linePoints[i]; |
|
painter->drawLine(point1/100., point2/100.); |
painter->drawLine(point1, point2); |
} |
|
if (!collided) |
86,13 → 84,13 |
} |
if (angle == 0 || angle == 180) |
{ |
painter->fillRect(x/100. - 5, y/100. - 15, 10, 30, colour); |
painter->fillRect(x - 5, y - 15, 10, 30, colour); |
} |
else |
{ |
painter->fillRect(x/100. - 15, y/100. - 5, 30, 10, colour); |
painter->fillRect(x - 15, y - 5, 30, 10, colour); |
} |
painter->drawText(x/100., y/100. - 20, name); |
painter->drawText(x, y - 20, name); |
} |
else |
{ |
160,7 → 158,6 |
} |
|
hadGo = false; |
couldReadLine = false; |
if (!socket->waitForReadyRead(1)) |
{ |
// socket->disconnectFromHost(); |
168,9 → 165,8 |
haveSentAlready = true; |
return; |
} |
if (!hadGo && couldReadLine) |
if (!hadGo) |
{ |
cout << "KILLING BECAUSE HE DIDN'T HAVE A GO\n"; |
socket->disconnectFromHost(); |
dead = true; |
} |
196,9 → 192,9 |
// Do collision detection here |
// use linePoints |
int i = linePoints.count() - 1; |
if(linePoints[i-1].x() < 0 || linePoints[i-1].x() >= 80000 || linePoints[i-1].y() < 0 || linePoints[i-1].y() >= 60000) |
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() >= 80000 || linePoints[i].y() < 0 || linePoints[i].y() >= 60000) |
if(linePoints[i].x() < 0 || linePoints[i].x() > 800 || linePoints[i].y() < 0 || linePoints[i].y() > 600) |
return true; |
int j, r; |
Bike *bike; |
244,7 → 240,7 |
{ |
// x equal |
|
if((ix > jx && i1x < jx) || (ix < jx && i1x > jx)) |
if(ix > jx && i1x < jx || ix < jx && i1x > jx) |
{ |
if((sign(iy - jy) != sign(iy - j1y))) |
return true; |
253,7 → 249,7 |
if(jy == j1y) |
{ |
|
if((iy > jy && i1y < jy) || (iy < jy && i1y > jy)) |
if(iy > jy && i1y < jy || iy < jy && i1y > jy) |
{ |
if((sign(ix - jx) != sign(ix - j1x))) |
return true; |
274,13 → 270,13 |
void Bike::reset() |
{ |
cout << "Reset was called\n"; |
x = rand() % 80000; |
y = rand() % 60000; |
x = rand() % 800; |
y = rand() % 600; |
linePoints.clear(); |
|
linePoints.append(QPoint(x, y)); |
|
velocity = 100; |
velocity = 1; |
angle = 0; |
abpool = 0; |
show = true; |
288,17 → 284,11 |
hadGo = false; |
dead = false; |
collided = false; |
speed = 500; |
speed = 5; |
|
socket->write("RESET\n"); |
} |
|
void Bike::greet() |
{ |
cout << "Greeting\n"; |
socket->write("ARENA 80000 60000\n"); |
} |
|
void Bike::readyRead() |
{ |
while (socket->canReadLine()) |
305,7 → 295,6 |
{ |
QByteArray data = socket->readLine(); |
QString line = data.trimmed(); |
couldReadLine = true; |
|
if (line == "L") |
{ |
320,10 → 309,10 |
angle += 360; |
} |
if(velocity < speed) |
velocity += 30; |
velocity += 0.3; |
else if(velocity > speed) |
velocity -= 30; |
if(abs(speed-velocity)<30) |
velocity -= 0.3; |
if(abs(speed-velocity)<0.3) |
velocity = speed; |
if(abpool<10) |
abpool += 0.2; |
342,10 → 331,10 |
angle += 360; |
} |
if(velocity < speed) |
velocity += 30; |
velocity += 0.3; |
else if(velocity > speed) |
velocity -= 30; |
if(abs(speed-velocity)<30) |
velocity -= 0.3; |
if(abs(speed-velocity)<0.3) |
velocity = speed; |
if(abpool<10) |
abpool += 0.2; |
354,14 → 343,14 |
else if (line == "A") |
{ |
if(abpool > 0){ |
velocity += 20; |
velocity += 0.1; |
abpool -= 0.5; |
} else { |
if(velocity < speed) |
velocity += 30; |
velocity += 0.3; |
else if(velocity > speed) |
velocity -= 30; |
if(abs(speed-velocity)<30) |
velocity -= 0.3; |
if(abs(speed-velocity)<0.3) |
velocity = speed; |
} |
hadGo = true; |
369,15 → 358,15 |
else if (line == "D") |
{ |
if(abpool > 0){ |
velocity -= 20; |
velocity -= 0.2; |
abpool -= 0.5; |
} |
else { |
if(velocity < speed) |
velocity += 30; |
velocity += 0.3; |
else if(velocity > speed) |
velocity -= 30; |
if(abs(speed-velocity)<30) |
velocity -= 0.3; |
if(abs(speed-velocity)<0.3) |
velocity = speed; |
} |
hadGo = true; |
386,10 → 375,10 |
{ |
|
if(velocity < speed) |
velocity += 30; |
velocity += 0.3; |
else if(velocity > speed) |
velocity -= 30; |
if(abs(speed-velocity)<30) |
velocity -= 0.3; |
if(abs(speed-velocity)<0.3) |
velocity = speed; |
if(abpool<10) |
abpool += 0.2; |
426,15 → 415,6 |
emit chat(name, message); |
} |
|
if(velocity < speed) |
velocity += 30; |
else if(velocity > speed) |
velocity -= 30; |
if(abs(speed-velocity)<30) |
velocity = speed; |
if(abpool<10) |
abpool += 0.2; |
|
hadGo = true; |
} |
} |