I am just placing items at random coordinates on the map, that seemed easiest, but it won't prevent them from being spawned inside the walls. The items can tell me if they are spawned inside a wall though so I thought I could just move them in that event.
The location my items spawn is basically just this:
new_item.set_pos(Vector2(iposx,iposy))
this then tells me if they are in an inaccessible place:
new_item.connect("body_enter", self, "_on_Area2D_body_enter")
iterate += 1
func _on_Area2D_body_enter( body ):
if(body.get_name() == "Player"):
print("Player")
elif(body.get_name() == "Walls"):
var iposx= randi()%int(xwg)-100
var iposy= randi()%int(ywg)-100
#new_item.set_pos(Vector2(iposx,iposy))
The way I have it now all I'd need is a way to change the items position inside the function _on_Area2D_body_enter( body ):
But of course the new_item does not point to the right item at that point.
Is there a way to place items on tiles instead of coordinates and preclude any tiles covered by wall tiles?
Thanks for the tip with CollisionShape2D though!