-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vehicle.cpp
52 lines (47 loc) · 1.56 KB
/
Vehicle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "Vehicle.h"
#include<iostream>
#include<stdlib.h>
Vehicle::Vehicle(GameWindow::laneDirection dir, int position, int sp): speed(sp), direction(dir)
{
auto vehicleType=rand() % 20;
if(vehicleType < 7)
setPixmap(QPixmap(":/resources/images/hotrod.png"));
else if(vehicleType < 11)
setPixmap(QPixmap(":/resources/images/taxi.png"));
else if(vehicleType < 13)
setPixmap(QPixmap(":/resources/images/police1.png"));
else if(vehicleType < 15)
setPixmap(QPixmap(":/resources/images/police.png"));
else if(vehicleType < 17)
setPixmap(QPixmap(":/resources/images/truck.png"));
else if(vehicleType < 20)
setPixmap(QPixmap(":/resources/images/bike.png"));
this->setData(0,GameWindow::itemType::vehicle);
switch(direction)
{
case GameWindow::laneDirection::left:
setPos(800, position - pixmap().height() / 2);
break;
case GameWindow::laneDirection::right:
setPos(- pixmap().width(), position - pixmap().height() / 2);
setTransformOriginPoint(pixmap().width()/2,pixmap().height()/2);
setRotation(180);
break;
}
connect(GameWindow::timer.get(),SIGNAL(timeout()),this,SLOT(move()));
}
void Vehicle::move()
{
if(!GameWindow::isItemVisible(GameWindow::itemType::menuPause))
{
switch(direction)
{
case GameWindow::laneDirection::left:
setPos(x() - speed, y());
break;
case GameWindow::laneDirection::right:
setPos(x() + speed, y());
break;
}
}
}