public void RegisterBlockedCircle(FCircle circle) { for (int ox = (int)((circle.X - circle.Radius) / GDConstants.TILE_WIDTH); ox <= (int)((circle.X + circle.Radius) / GDConstants.TILE_WIDTH); ox++) { for (int oy = (int)((circle.Y - circle.Radius) / GDConstants.TILE_WIDTH); oy <= (int)((circle.Y + circle.Radius) / GDConstants.TILE_WIDTH); oy++) { int x = ox + MAX_EXTENSION_X; // real coords -> array coords int y = oy + MAX_EXTENSION_Y; if (x < 0) { continue; } if (y < 0) { continue; } if (x >= tileCountX) { continue; } if (y >= tileCountY) { continue; } var rect = new FRectangle(ox * TILE_WIDTH, oy * TILE_WIDTH, TILE_WIDTH, TILE_WIDTH); if (circle.Contains(rect.TopLeft, 0.5f) && circle.Contains(rect.TopRight, 0.5f)) { _grid[x, y].BlockNorth = true; } if (circle.Contains(rect.TopRight, 0.5f) && circle.Contains(rect.BottomRight, 0.5f)) { _grid[x, y].BlockEast = true; } if (circle.Contains(rect.BottomRight, 0.5f) && circle.Contains(rect.BottomLeft, 0.5f)) { _grid[x, y].BlockSouth = true; } if (circle.Contains(rect.BottomLeft, 0.5f) && circle.Contains(rect.TopLeft, 0.5f)) { _grid[x, y].BlockWest = true; } } } }
protected AbstractFractionController(float interval, GDGameScreen owner, Cannon cannon, Fraction fraction, bool singleUpdatePerCycle) { updateInterval = interval; onlySingleUpdate = singleUpdatePerCycle; Cannon = cannon; Fraction = fraction; Owner = owner; if (fraction.IsPlayer) { timeSinceLastUpdate = 0f; } innerBoundings = new FCircle(Cannon.Position, Cannon.Scale * Cannon.CANNON_OUTER_DIAMETER / 2); }
// http://stackoverflow.com/a/1879223/1761622 public static bool Intersects(this FRectangle rectangle, FCircle circle) { // clamp(value, min, max) - limits value to the range min..max // Find the closest point to the circle within the rectangle float closestX = FloatMath.Clamp(circle.X, rectangle.Left, rectangle.Right); float closestY = FloatMath.Clamp(circle.Y, rectangle.Top, rectangle.Bottom); // Calculate the distance between the circle's center and this closest point float distanceX = circle.X - closestX; float distanceY = circle.Y - closestY; // If the distance is less than the circle's radius, an intersection occurs float distanceSquared = (distanceX * distanceX) + (distanceY * distanceY); return(distanceSquared < (circle.Radius * circle.Radius)); }
public void RegisterSpawn(Cannon cannon, FCircle circle) { for (int ox = (int)((circle.X - circle.Radius) / GDConstants.TILE_WIDTH); ox <= (int)((circle.X + circle.Radius) / GDConstants.TILE_WIDTH); ox++) { for (int oy = (int)((circle.Y - circle.Radius) / GDConstants.TILE_WIDTH); oy <= (int)((circle.Y + circle.Radius) / GDConstants.TILE_WIDTH); oy++) { int x = ox + MAX_EXTENSION_X; // real coords -> array coords int y = oy + MAX_EXTENSION_Y; if (x < 0) { continue; } if (y < 0) { continue; } if (x >= tileCountX) { continue; } if (y >= tileCountY) { continue; } var rect = new FRectangle(ox * TILE_WIDTH, oy * TILE_WIDTH, TILE_WIDTH, TILE_WIDTH); if (!rect.Intersects(circle)) { continue; } _grid[x, y].SpawnSource = cannon; _grid[x, y].PowerCurr = 1f; } } }
public void RegisterBlockedCircle(FCircle c) { // NOTHING }
public void RegisterSpawn(Cannon cannon, FCircle circle) { // NOTHING }
public void DrawCircle(FCircle circle, int sides, Color color, float thickness = 1f) { DrawCircle(circle.Center, circle.Radius, sides, color, thickness); }