First of all, I am not sure if this question should be asked here, since it might be more of a general question about algorithms. Let me know if I am out of line.
In my game I use a grid of integer coordinates ( (0,0), (0,1), ...
) to hold info the map/level
I am trying to get an array of coordinates (Vector2(x,y))
that "resembles" a "circle" around a given starting start_pos
and 2 int
, min_range
and max_range
. The purpose is to have a list of valid tiles for attacking at a distance in a tactical RPG grid based game.
I have found a way of implementing it, but seems quite bloated, and was wandering if there is a simplier way of doing it.
func get_tiles_in_ranges(start_pos: Vector2, min_range: int, max_range: int) -> Array:
var out = []
for R in range(min_range, max_range + 1, 1):
out.append_array([
start_pos + Vector2(R,0),
start_pos + Vector2(-R,0),
start_pos + Vector2(0,R),
start_pos + Vector2(0,-R),
])
for x in range (1, R, 1):
var y = R - x
out.append_array([
start_pos + Vector2(x,y),
start_pos + Vector2(-x,y),
start_pos + Vector2(x,-y),
start_pos + Vector2(-x,-y),
])
return out
Also, is there a good source/book of usefull algorithms for these type of grid/tactical games? Thanks in advance!
edit: to clarify it should look like
( in the case of min_range =1, max range=3) (the blue tiles)