Picking tiles with abs(x) + abs(y) makes a diamond, picking them with the larger of abs(x) and abs(y) makes a square, and keeping tiles up to exactly the radius leaves a single tile sticking out on each side. In our Godot 4.7 test with a radius of 3 tiles, the diamond watered 25 tiles and left one 2.83 tiles away dry while watering one 3.00 away, the square watered 49, and the plain distance check left 4 lone tips. Keeping tiles up to 3.5 tiles from the centre watered a round patch of 37 tiles, with every watered tile closer than every dry one and no lone tips.
The code
Save it as tile_circle.gd, load it with const Round := preload("res://tile_circle.gd"), and loop over Round.cells(sprinkler_cell, 2) to water, till or light up the tiles. The cells are TileMapLayer coordinates: get the sprinkler's cell with local_to_map(). It is for square grids, not isometric or hexagon layouts.
extends RefCounted
## Picks the cells of a square grid that are inside a round area, for a
## sprinkler, a watering can or an area spell, so the shape looks round instead
## of a diamond, a square or a circle with spikes.
## const Round := preload("res://tile_circle.gd")
## for cell in Round.cells(sprinkler_cell, 2): water(cell)
## Cells are TileMapLayer coordinates, from local_to_map().
static func cells(center: Vector2i, radius: int) -> Array[Vector2i]:
var out: Array[Vector2i] = []
var limit := (radius + 0.5) * (radius + 0.5)
for y in range(-radius, radius + 1):
for x in range(-radius, radius + 1):
if x * x + y * y <= limit:
out.append(center + Vector2i(x, y))
return out
What we measured
Radii of 1 to 4 tiles around the centre tile, four ways of picking the tiles. For each we counted the tiles, the farthest watered tile and the nearest dry tile, measured from tile centre to tile centre, and the lone tips: a watered tile on the middle row or column with both neighbours beside it dry. Two runs gave the same result.
- abs(x) + abs(y) <= r: a diamond of 5, 13, 25 and 41 tiles. From radius 3 a closer tile stays dry than the farthest one watered: 2.83 against 3.00, and 3.61 against 4.00 at radius 4. Lone tips 4.
- max(abs(x), abs(y)) <= r: a full square of 9, 25, 49 and 81 tiles. Corners 4.24 tiles away get water at radius 3 while a tile 4.00 away does not.
- Distance <= r: 5, 13, 29 and 49 tiles. Round, but with 4 lone tips at every radius, one at the end of each axis. At radius 1 and 2 it is the same shape as the diamond.
- The script, distance <= r + 0.5: 9, 21, 37 and 69 tiles, no lone tips, and the farthest watered tile always closer than the nearest dry one: 2.24 against 2.83 at radius 2, 3.16 against 3.61 at radius 3, 4.47 against 5.00 at radius 4. Radius 1 is the full 3 by 3 block.
Why it happens
abs(x) + abs(y) counts steps along the grid, so going diagonally costs two steps and the diagonals end early. The larger of abs(x) and abs(y) lets a diagonal step cost one, so the corners reach as far as the sides. Real distance is round, but only one tile on each axis sits at exactly the radius, so it is kept while its neighbours at 3.16 are dropped. Adding half a tile makes the circle reach the outer edge of the end tiles instead of their centres, so the tiles beside them come in too and the edge steps evenly.
What to change
- Fire or water that should spread one ring of tiles per step: read the old grid, write a new one.
- Crops that should only be picked when ready: growth stages that match the harvest check.
- The cell under the mouse on a grid that goes into negative numbers: floor, not int().
What the farm looks like: Farming & Harvest VFX for Godot 4 has 23 ready-made farm effects in Stylized and Retro PSX looks, including harvest bursts for carrots, berries and wheat, a Ready to Harvest sparkle and a Giant Crop reward.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Farming & Harvest VFX for Godot 4 has 23 ready-made farm effects in Stylized and Retro PSX looks, including harvest bursts for carrots, berries and wheat, a Ready to Harvest sparkle and a Giant Crop reward.
More how-tos for Farming & Harvest VFX for Godot 4: Make a harvested crop pop out in an arc
More how-tos: Game systems
- Hover a 3D object inside a SubViewport
- A turned building that covers the cells it stands on
- An inventory that never loses an item and never overfills a stack
- A JSON save that loads back exactly what you saved
- Fire that spreads one cell per step, in every direction
- A pooled enemy that comes back as fresh as a new one
- An enemy that stops at the dead player and finds the respawned one
- Poison, burn and bleed that keep ticking when applied again
- XP, qi and gold that keep growing without going negative
- Count slot line wins with wilds in front
- Random directions spread evenly over a sphere or a cone
- Count a lap only when the car really went round
- Make a seed repeat: daily runs, replays and roguelike seeds
- Offline progress that counts the time the game was closed
- A chance roll without the long bad-luck streaks
- Check crafting recipes in any order, with the right counts
- Make HP and mana regen the same at any frame rate
- Damage over time with the right number of ticks
- Spawn enemies where the camera cannot see them
- Keep a chasing horde from stacking into one enemy
- Make the fish bite after the same wait at any frame rate
- Snap buildings to the right grid cell on both sides of the origin
- Make a cooking timer fire once, on time
- Pick from a weighted loot table with the right chances
- Level up as many times as the XP covers
- Walk a patrol guard to each point without overshooting
- Remove items from an Array while checking them, without skipping any
- Scatter spikes, roots or trees in a circle without overlaps
- Count and take crafting items from every stack
- Play random sounds and events without obvious repeats
- Pick the growth image so the ripe one shows exactly when the crop can be picked
- Turn a day counter into season, day and year without a day 0
- An enemy that dies once, however many hits land
- A fair shuffle you can replay
- A ghost that drives the lap at real speed
- A vision cone that does not flicker at the edge
- Move a group of units without a pile-up
- A slot reel that always lands forward on the result
- A crowd of NPCs that never emote or bob in step
- A song position that moves on every frame
- Nodes your editor tool adds that stay in the scene