Subversion Repositories QTron

Compare Revisions

Ignore whitespace Rev 6 → Rev 8

/bike.h
18,7 → 18,8
public:
Bike(QTcpSocket *sock, int i);
void draw(QPainter *painter);
void run(QList<Bike *> bikes);
void run(QList<Bike *> bikes);
bool hasCollided();
void reset();
bool isReady;
bool dead;
31,8 → 32,9
QList<QPoint> linePoints;
int id;
bool isDisconnected;
bool hasHadGo;
QColor colour;
bool hasHadGo;
QColor colour;
bool collided;
 
private:
QTcpSocket *socket;
/bike.cpp
21,6 → 21,7
isReady = false;
hadGo = false;
dead = false;
collided = false;
 
colour.setBlue(0);
colour.setRed(0);
60,22 → 61,31
painter->drawLine(point1, point2);
}
 
if (angle == 0)
if (!collided)
{
y -= velocity;
collided = hasCollided();
 
if (angle == 0)
{
y -= velocity;
}
else if (angle == 90)
{
x += velocity;
}
else if (angle == 180)
{
y += velocity;
}
else if (angle == 270)
{
x -= velocity;
}
}
else if (angle == 90)
else
{
x += velocity;
linePoints.clear();
}
else if (angle == 180)
{
y += velocity;
}
else if (angle == 270)
{
x -= velocity;
}
 
if (angle == 0 || angle == 180)
{
111,12 → 121,12
socket->write(QString::number(bike->x).toAscii());
socket->write(" ");
socket->write(QString::number(bike->y).toAscii());
socket->write(" ");
socket->write(QString::number(bike->colour.red()).toAscii());
socket->write(" ");
socket->write(QString::number(bike->colour.green()).toAscii());
socket->write(" ");
socket->write(QString::number(bike->colour.blue()).toAscii());
socket->write(" ");
socket->write(QString::number(bike->colour.red()).toAscii());
socket->write(" ");
socket->write(QString::number(bike->colour.green()).toAscii());
socket->write(" ");
socket->write(QString::number(bike->colour.blue()).toAscii());
socket->write("\n");
}
}
138,7 → 148,7
socket->flush();
 
hadGo = false;
if (!socket->waitForReadyRead(2000))
if (!socket->waitForReadyRead(2000))
{
socket->disconnectFromHost();
dead = true;
152,6 → 162,14
hasHadGo = true;
}
 
bool Bike::hasCollided()
{
// Do collision detection here
// use linePoints
 
return false;
}
 
void Bike::reset()
{
x = rand() % 800;
166,6 → 184,7
isReady = true;
hadGo = false;
dead = false;
collided = false;
 
socket->write("RESET\n");
}
232,11 → 251,11
{
colour.setRed(list[1].toInt());
}
else if (list.count() >= 3)
if (list.count() >= 3)
{
colour.setGreen(list[2].toInt());
}
else if (list.count() >= 4)
if (list.count() >= 4)
{
colour.setBlue(list[3].toInt());
}