I use Numpy and Python in a project where a 2D map is represented by ndarray:
map = [[1,2,3,4,5], [2,3,4,2,3], [2,2,2,1,2], [3,2,1,2,3], [4,6,5,7,4]] MAP_WIDTH = 5, MAP_HEIGHT = 5
The object has a tuple:
actor.location = (3,3)
and viewing range:
actor.range = 2
How to write the actor.view_map(map) function, so that the map returns the area surrounding the actorβs location to a range. For example (using the map above),
range = 1 location = (3, 2) => [[2,3,4], [3,4,2], [2,2,1]]
but if the range of actors extends too far, I want the map to fill -1:
range = 1 location = (1,1) [[-1,-1,-1], [-1, 1, 2], [-1, 2, 3]]
The simplest case is a range of 0, which returns the current square:
range = 0 location = (1, 2) [[2]]
How to cut the map to a certain border?