package MapBounds import NoWurst import Vectors import Wurstunit import Region import Rect import MagicFunctions import Annotations public rect playableMapRect public region playableMapRegion public rect boundRect public region boundRegion public vec2 playableMin public vec2 playableMax public vec2 boundMin public vec2 boundMax public vec2 playableCenter public vec2 boundCenter // playable map area function inPlayableXY(real x, real y) returns boolean return x > playableMin.x and x < playableMax.x and y > playableMin.y and y < playableMax.y public function vec2.inPlayable() returns boolean return inPlayableXY(this.x, this.y) public function vec3.inPlayable() returns boolean return inPlayableXY(this.x, this.y) // map boundaries function inBoundsXY(real x, real y) returns boolean return x > boundMin.x and x < boundMax.x and y > boundMin.y and y < boundMax.y public function vec2.inBounds() returns boolean return inBoundsXY(this.x, this.y) public function vec3.inBounds() returns boolean return inBoundsXY(this.x, this.y) public function randomPointOnMap() returns vec2 return vec2(GetRandomReal(playableMin.x, playableMax.x), GetRandomReal(playableMin.y, playableMax.y)) /** Must be at init because globals get initialized before map bounds */ @compiletime function initMapBounds() playableMapRect = compiletime ? Rect(-1024, -1024, 1024, 1024) : GetPlayableMapRect() playableMapRegion = CreateRegion()..addRect(playableMapRect) boundRect = compiletime ? Rect(-1536, -1536, 1536, 1536) : GetWorldBounds() boundRegion = CreateRegion()..addRect(boundRect) playableMin = vec2(playableMapRect.getMinX(), playableMapRect.getMinY()) playableMax = vec2(playableMapRect.getMaxX(), playableMapRect.getMaxY()) boundMin = vec2(boundRect.getMinX(), boundRect.getMinY()) boundMax = vec2(boundRect.getMaxX(), boundRect.getMaxY()) playableCenter = (playableMin + playableMax) * .5 boundCenter = (boundMin + boundMax) * .5 init initMapBounds() @Test function testMapBounds() playableMapRect.getMinX().assertEquals(-1024) playableMapRect.getMaxX().assertEquals(1024) playableMapRect.getMinY().assertEquals(-1024) playableMapRect.getMaxY().assertEquals(1024) (playableMin + playableMax).toString().assertEquals(playableCenter.toString())