Subversion Repositories QTron

Compare Revisions

Ignore whitespace Rev 39 → Rev 40

/bike.h
25,12 → 25,13
bool hasCollided(QList<Bike *> bikes);
void setText(QString text);
void reset();
void greet();
bool isReady;
bool dead;
bool show;
bool hadGo;
float x;
float y;
int x;
int y;
QString name;
int angle;
QList<QPoint> linePoints;
45,6 → 46,7
float speed;
QTcpSocket *socket;
bool haveSentAlready;
bool couldReadLine;
 
private slots:
void disconnected();
/mainwindow.h
2,6 → 2,7
#define MAINWINDOW_H
 
#include <QMainWindow>
#include <QApplication>
#include <QPaintEvent>
#include <QTcpServer>
#include <QList>
/bike.cpp
10,11 → 10,11
 
isDisconnected = false;
 
x = rand() % 800;
y = rand() % 600;
x = rand() % 80000;
y = rand() % 60000;
linePoints.append(QPoint(x, y));
 
velocity = 1;
velocity = 100;
angle = (rand() % 4) * 90;
abpool = 0;
name = "";
23,12 → 23,14
hadGo = false;
dead = false;
collided = false;
speed = 5;
speed = 500;
 
colour.setBlue(0);
colour.setRed(0);
colour.setGreen(0);
 
greet();
 
if (!socket->waitForReadyRead(2000))
{
socket->disconnectFromHost();
60,7 → 62,7
 
point2 = linePoints[i];
 
painter->drawLine(point1, point2);
painter->drawLine(point1/100., point2/100.);
}
 
if (!collided)
84,13 → 86,13
}
if (angle == 0 || angle == 180)
{
painter->fillRect(x - 5, y - 15, 10, 30, colour);
painter->fillRect(x/100. - 5, y/100. - 15, 10, 30, colour);
}
else
{
painter->fillRect(x - 15, y - 5, 30, 10, colour);
painter->fillRect(x/100. - 15, y/100. - 5, 30, 10, colour);
}
painter->drawText(x, y - 20, name);
painter->drawText(x/100., y/100. - 20, name);
}
else
{
158,6 → 160,7
}
 
hadGo = false;
couldReadLine = false;
if (!socket->waitForReadyRead(1))
{
// socket->disconnectFromHost();
165,8 → 168,9
haveSentAlready = true;
return;
}
if (!hadGo)
if (!hadGo && couldReadLine)
{
cout << "KILLING BECAUSE HE DIDN'T HAVE A GO\n";
socket->disconnectFromHost();
dead = true;
}
192,9 → 196,9
// 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)
if(linePoints[i-1].x() < 0 || linePoints[i-1].x() >= 80000 || linePoints[i-1].y() < 0 || linePoints[i-1].y() >= 60000)
return true;
if(linePoints[i].x() < 0 || linePoints[i].x() > 800 || linePoints[i].y() < 0 || linePoints[i].y() > 600)
if(linePoints[i].x() < 0 || linePoints[i].x() >= 80000 || linePoints[i].y() < 0 || linePoints[i].y() >= 60000)
return true;
int j, r;
Bike *bike;
240,7 → 244,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;
249,7 → 253,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;
270,13 → 274,13
void Bike::reset()
{
cout << "Reset was called\n";
x = rand() % 800;
y = rand() % 600;
x = rand() % 80000;
y = rand() % 60000;
linePoints.clear();
 
linePoints.append(QPoint(x, y));
 
velocity = 1;
velocity = 100;
angle = 0;
abpool = 0;
show = true;
284,11 → 288,17
hadGo = false;
dead = false;
collided = false;
speed = 5;
speed = 500;
 
socket->write("RESET\n");
}
 
void Bike::greet()
{
cout << "Greeting\n";
socket->write("ARENA 80000 60000\n");
}
 
void Bike::readyRead()
{
while (socket->canReadLine())
295,6 → 305,7
{
QByteArray data = socket->readLine();
QString line = data.trimmed();
couldReadLine = true;
 
if (line == "L")
{
309,10 → 320,10
angle += 360;
}
if(velocity < speed)
velocity += 0.3;
velocity += 30;
else if(velocity > speed)
velocity -= 0.3;
if(abs(speed-velocity)<0.3)
velocity -= 30;
if(abs(speed-velocity)<30)
velocity = speed;
if(abpool<10)
abpool += 0.2;
331,10 → 342,10
angle += 360;
}
if(velocity < speed)
velocity += 0.3;
velocity += 30;
else if(velocity > speed)
velocity -= 0.3;
if(abs(speed-velocity)<0.3)
velocity -= 30;
if(abs(speed-velocity)<30)
velocity = speed;
if(abpool<10)
abpool += 0.2;
343,14 → 354,14
else if (line == "A")
{
if(abpool > 0){
velocity += 0.1;
velocity += 20;
abpool -= 0.5;
} else {
if(velocity < speed)
velocity += 0.3;
velocity += 30;
else if(velocity > speed)
velocity -= 0.3;
if(abs(speed-velocity)<0.3)
velocity -= 30;
if(abs(speed-velocity)<30)
velocity = speed;
}
hadGo = true;
358,15 → 369,15
else if (line == "D")
{
if(abpool > 0){
velocity -= 0.2;
velocity -= 20;
abpool -= 0.5;
}
else {
if(velocity < speed)
velocity += 0.3;
velocity += 30;
else if(velocity > speed)
velocity -= 0.3;
if(abs(speed-velocity)<0.3)
velocity -= 30;
if(abs(speed-velocity)<30)
velocity = speed;
}
hadGo = true;
375,10 → 386,10
{
 
if(velocity < speed)
velocity += 0.3;
velocity += 30;
else if(velocity > speed)
velocity -= 0.3;
if(abs(speed-velocity)<0.3)
velocity -= 30;
if(abs(speed-velocity)<30)
velocity = speed;
if(abpool<10)
abpool += 0.2;
415,6 → 426,15
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;
}
}
/mainwindow.cpp
89,7 → 89,7
{
// cout << ":: Sent move request..." << endl;
bool alldone = false;
timer2->start(10000);
time_t start = time(NULL);
while(!alldone){
for (int i = 0; i < bikes.count(); i++)
{
105,8 → 105,9
alldone = false;
}
}
if(time(NULL) - 10 > start)
clientTimeOut();
}
timer2->stop();
}
 
for (int i = 0; i < bikes.count(); i++)
192,6 → 193,7
if (!suddenDeath)
{
suddenDeath = true;
cout << "SUDDEN DEATH ACTIVATED!" << endl;
chat("Server", "SUDDEN DEATH ACTIVATED!");
}
}