← Pixel Dreamer Studio

A sprinkler that waters a round patch

Keep the tiles whose distance from the centre is at most the radius plus half a tile.

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.

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

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