Advertisement
Guest User

Untitled

a guest
Jul 1st, 2022
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. void nextPosition () {
  2.     int cx = humans[targetId]->x - x;
  3.     int cy = humans[targetId]->y - y;
  4.     int dist2 = distance2(*humans[targetId]);
  5.     // If the distance is less or equal to zombie speed then nextX takes the value of human X and nextY takes the value of human Y
  6.     if (dist2 < ZOMBIE_SPEED_SQUARED) {
  7.         x = humans[targetId]->x;
  8.         y = humans[targetId]->y;
  9.     }
  10.     else {
  11.         float distanceCoeff = ZOMBIE_SPEED / distance(dist2);
  12.         x += cx * distanceCoeff;
  13.         y += cy * distanceCoeff;
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement