Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //elements.cpp
- #include "elements.h"
- #define TL_RADIUS 14;
- Car::Car(int nx, int ny, int ndirection)
- {
- x = nx;
- y = ny;
- direction = ndirection;
- srand (time (NULL));
- Turn = rand()%3;
- }
- //==================================================
- void Car::show(QPainter *painter)
- {
- if (direction == 1)
- {
- QImage car1("://images/car1.jpg");
- painter->drawImage(x, y, car1);
- }
- if (direction == 2)
- {
- QImage car2("://images/car2.jpg");
- painter->drawImage(x, y, car2);
- }
- if (direction == 3)
- {
- QImage car3("://images/car3.jpg");
- painter->drawImage(x, y, car3);
- }
- if (direction == 4)
- {
- QImage car4("://images/car4.jpg");
- painter->drawImage(x, y, car4);
- }
- }
- //==================================================
- void Car::moving()
- {
- // остановка на 320 или 10
- if (tc==1)
- {
- return;
- }
- if (direction==1)
- {
- y++;
- }
- if (direction==2)
- {
- x--;
- }
- if (direction==3)
- {
- y--;
- }
- if (direction==4)
- {
- x++;
- }
- }
- void Car::slotTC(int tc_color)
- {
- tc = tc_color;
- }
- void Car::turn()
- {
- if (Turn == 0)
- {
- return;
- }
- if ((direction == 1 && Turn == 1) || (direction == 3 && Turn == 2))
- {
- direction = 4;
- }
- if ((direction == 1 && Turn == 2) || (direction == 3 && Turn == 1))
- {
- direction = 2;
- }
- if ((direction == 2 && Turn == 1) || (direction == 4 && Turn == 2))
- {
- direction = 1;
- }
- if ((direction == 2 && Turn == 2) || (direction == 3 && Turn == 1))
- {
- direction = 3;
- }
- }
- //==================================================
- //==================================================
- TrafficLight::TrafficLight (int npos, int ncolor)
- {
- position = npos;
- radius = TL_RADIUS;
- Traffic_Color = ncolor;
- if (position == 1)
- {
- x1 = 65;
- y1 = 42;
- x2 = 356;
- y2 = 335;
- a = 0;
- }
- if (position == 2)
- {
- x1 = 336;
- y1 = 62;
- x2 = 46;
- y2 = 355;
- a = 90;
- }
- if (position == 3)
- {
- x1 = 356;
- y1 = 376;
- x2 = 65;
- y2 = 83;
- a = 180;
- }
- if (position == 4)
- {
- x1 = 87;
- y1 = 355;
- x2 = 376;
- y2 = 62;
- a = 270;
- }
- }
- //==================================================
- void TrafficLight::light (int nt_red, int nt_yellow, int nt_green, int nc)
- {
- Traffic_Color = nc;
- SendTCS();
- }
- void TrafficLight::SendTCS()
- {
- emit signalTC(Traffic_Color);
- }
- void TrafficLight::show(QPainter *painter)
- {
- //устанавливаем цвет и толщину
- //карандаша
- if (Traffic_Color == 1)
- {
- painter->setPen(QPen(Qt::red,1));
- painter->setBrush(QBrush(Qt::red));
- }
- if (Traffic_Color == 2)
- {
- painter->setPen(QPen(Qt::yellow,1));
- painter->setBrush(QBrush(Qt::yellow));
- }
- if (Traffic_Color == 3 )
- {
- painter->setPen(QPen(Qt::green,1));
- painter->setBrush(QBrush(Qt::green));
- }
- painter->drawChord(x1, y1, 2*radius, 2*radius, 16*a, 16*180);
- painter->drawChord(x2, y2, 2*radius, 2*radius, 16*a, 16*180);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement