/bike.h |
---|
38,10 → 38,11 |
QColor colour; |
bool collided; |
float abpool; |
float velocity; |
float speed; |
private: |
QTcpSocket *socket; |
float velocity; |
private slots: |
void readyRead(); |
/mainwindow.h |
---|
27,11 → 27,14 |
QList<Bike *> bikes; |
QTimer *timer; |
int id; |
QTimer *suddenDeathTimer; |
bool suddenDeath; |
private slots: |
void newConnection(); |
void checkClients(); |
void chat(QString name, QString message); |
void activateSuddenDeath(); |
}; |
#endif // MAINWINDOW_H |
/bike.cpp |
---|
23,6 → 23,7 |
hadGo = false; |
dead = false; |
collided = false; |
speed = 5; |
colour.setBlue(0); |
colour.setRed(0); |
270,6 → 271,7 |
hadGo = false; |
dead = false; |
collided = false; |
speed = 5; |
socket->write("RESET\n"); |
} |
293,12 → 295,12 |
{ |
angle += 360; |
} |
if(velocity < 5) |
if(velocity < speed) |
velocity += 0.3; |
else if(velocity > 5) |
else if(velocity > speed) |
velocity -= 0.3; |
if(abs(5-velocity)<0.3) |
velocity = 5; |
if(abs(speed-velocity)<0.3) |
velocity = speed; |
if(abpool<10) |
abpool += 0.2; |
hadGo = true; |
315,12 → 317,12 |
{ |
angle += 360; |
} |
if(velocity < 5) |
if(velocity < speed) |
velocity += 0.3; |
else if(velocity > 5) |
else if(velocity > speed) |
velocity -= 0.3; |
if(abs(5-velocity)<0.3) |
velocity = 5; |
if(abs(speed-velocity)<0.3) |
velocity = speed; |
if(abpool<10) |
abpool += 0.2; |
hadGo = true; |
331,12 → 333,12 |
velocity += 0.1; |
abpool -= 0.5; |
} else { |
if(velocity < 5) |
if(velocity < speed) |
velocity += 0.3; |
else if(velocity > 5) |
else if(velocity > speed) |
velocity -= 0.3; |
if(abs(5-velocity)<0.3) |
velocity = 5; |
if(abs(speed-velocity)<0.3) |
velocity = speed; |
} |
hadGo = true; |
} |
347,12 → 349,12 |
abpool -= 0.5; |
} |
else { |
if(velocity < 5) |
if(velocity < speed) |
velocity += 0.3; |
else if(velocity > 5) |
else if(velocity > speed) |
velocity -= 0.3; |
if(abs(5-velocity)<0.3) |
velocity = 5; |
if(abs(speed-velocity)<0.3) |
velocity = speed; |
} |
hadGo = true; |
} |
359,12 → 361,12 |
else if (line == "N") |
{ |
if(velocity < 5) |
if(velocity < speed) |
velocity += 0.3; |
else if(velocity > 5) |
else if(velocity > speed) |
velocity -= 0.3; |
if(abs(5-velocity)<0.3) |
velocity = 5; |
if(abs(speed-velocity)<0.3) |
velocity = speed; |
if(abpool<10) |
abpool += 0.2; |
hadGo = true; |
/mainwindow.cpp |
---|
12,6 → 12,11 |
connect(timer, SIGNAL(timeout()), this, SLOT(update())); |
timer->start(50); |
suddenDeath = false; |
suddenDeathTimer = new QTimer(this); |
connect(suddenDeathTimer, SIGNAL(timeout()), this, SLOT(activateSuddenDeath())); |
suddenDeathTimer->start(300000); |
id = 0; |
} |
22,6 → 27,10 |
void MainWindow::reset() |
{ |
suddenDeathTimer->stop(); |
suddenDeathTimer->start(300000); |
suddenDeath = false; |
for (int i = 0; i < bikes.count(); i++) |
{ |
bikes[i]->reset(); |
30,6 → 39,14 |
void MainWindow::paintEvent(QPaintEvent *e) |
{ |
if (suddenDeath) |
{ |
for (int i = 0; i < bikes.count(); i++) |
{ |
bikes[i]->speed += 0.02; |
} |
} |
e->accept(); |
QPainter painter(this); |
138,3 → 155,12 |
bikes[i]->setText(packet); |
} |
} |
void MainWindow::activateSuddenDeath() |
{ |
if (!suddenDeath) |
{ |
suddenDeath = true; |
chat("Server", "SUDDEN DEATH ACTIVATED!"); |
} |
} |