Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Car::moving()
- {
- // движение при подъезде к перекрёстку, если светофор не зелёный, то стоп
- if (tc !=3 && f==false)
- {
- if (direction==1 && y>=10)
- {
- emit siganlXY(direction, x, y);
- return;
- }
- if (direction==2 && x<=320)
- {
- int nx = x + CLENGTH;
- emit siganlXY(direction, nx, y);
- return;
- }
- if (direction==3 && y<=320)
- {
- int ny = y + CLENGTH;
- emit siganlXY(direction, x, ny);
- return;
- }
- if (direction==4 && x>=10)
- {
- emit siganlXY(direction, x, y);
- return;
- }
- }
- if (tc == 3 && f==false)
- {
- if (direction==1 && y>=20)
- {
- turn();
- return;
- }
- if (direction==2 && x<=310)
- {
- turn();
- return;
- }
- if (direction==3 && y<=310)
- {
- turn();
- return;
- }
- if (direction==4 && x>=20)
- {
- turn();
- return;
- }
- }
- // если машинка после повторота исчезла за краем экрана, то
- if (f==true)
- {
- if (direction==1 && y>=450)
- {
- x = 150;
- y = -138;
- srand (time(NULL));
- Turn = rand()%3;
- f = false;
- return;
- }
- if (direction==2 && x<=0)
- {
- x = 460;
- y = 150;
- srand (time(NULL));
- Turn = rand()%3;
- f = false;
- return;
- }
- if (direction==3 && y<=0)
- {
- x = 250;
- y = 460;
- srand (time(NULL));
- Turn = rand()%3;
- f = false;
- return;
- }
- if (direction==4 && x>=450)
- {
- x = -138;
- y = 250;
- srand (time(NULL));
- Turn = rand()%3;
- f = false;
- return;
- }
- }
- // движение в зависимости от направления
- if (direction==1)
- {
- y++;
- emit siganlXY(direction, x, y);
- return;
- }
- if (direction==2)
- {
- x--;
- int nx = x + CLENGTH;
- emit siganlXY(direction, nx, y);
- return;
- }
- if (direction==3)
- {
- y--;
- int ny = y + CLENGTH;
- emit siganlXY(direction, x, ny);
- return;
- }
- if (direction==4)
- {
- x++;
- emit siganlXY(direction, x, y);
- return;
- }
- }
- //==================================================
- void Car::turn()
- {
- if (Turn == 0)
- {
- f = true;
- return;
- }
- if ((direction == 1 && Turn == 1) || (direction == 3 && Turn == 2))
- {
- direction = 4;
- x++;
- y = 250;
- }
- if ((direction == 1 && Turn == 2) || (direction == 3 && Turn == 1))
- {
- direction = 2;
- x--;
- y = 150;
- }
- if ((direction == 2 && Turn == 1) || (direction == 4 && Turn == 2))
- {
- direction = 1;
- y++;
- x = 150;
- }
- if ((direction == 2 && Turn == 2) || (direction == 4 && Turn == 1))
- {
- direction = 3;
- y--;
- x = 250;
- }
- f = true;
- }
- //==================================================
- //==================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement