Guest User

Untitled

a guest
Apr 25th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. public static bool FitInCircle(int y, int x, int oY, int oX, int radius2)
  2. {
  3.             bool ret = false;
  4.  
  5.                 int dX = (oX > x) ? (oX - x) : (x - oX);    
  6.                 int dY = (oY > y) ? (oY - y) : (y - oY);
  7.              
  8.                 if (dX * dX + dY * dY <= radius2)
  9.                                    ret = true;
  10.              
  11.             return ret;
  12. }
  13.  
  14. Doesn't seem to select the same tiles as:
  15.  
  16. private void AddPresence(Location point)
  17. {
  18.            int radius = (int)Math.Round(Math.Sqrt(CollationRadius2), 0, MidpointRounding.AwayFromZero);
  19.            int dY, dX;
  20.                for (int y = -radius - 2; y <= radius + 2; y++)
  21.                    for (int x = -radius - 2; x <= radius + 2; x++)
  22.                        if (x * x + y * y <= CollationRadius2)
  23.                        {
  24.                            dY = (point.Y + y) % Smurfer.Height;
  25.                            if (dY < 0) dY += Smurfer.Height;
  26.  
  27.                            dX = (point.X + x) % Smurfer.Width;
  28.                            if (dX < 0) dX += Smurfer.Width;
  29.  
  30.                            World.Presence[dY, dX]++;
  31.                            Presence[dY, dX]++;
  32.                        }
  33.        }
Add Comment
Please, Sign In to add comment