- Code: Select all
Global constant number TRUE = 1
Global constant number FALSE = 0
+ Function: On function "isCovered" :
Local number result = 0
-> System: set result to TRUE
+ System: for "y" from 0 to rectangle.Width
+ System: for "x" from 0 to rectangle.Height
Local number covered = 0
Local number px = 0
Local number py = 0
-> System: set px to rectangle.X - rectangle.width/2 + loopindex("x")
-> System: set py to rectangle.Y - rectangle.height/2 + loopindex("y")
+ System: Foreach circle
+ System: distance(circle.X,circle.Y,px,py) <= circle.width/2
-> System: covered = TRUE
-> System: stop loop // stop the foreach
+ System: covered = FALSE
-> System: set result to FALSE
-> System: stop loop // stop the "x" loop
-> System: stop loop // stop the "y" loop
-> Function: set return value to result
Untested. But the idea is to sample each pixel of your rectangle and see if there's a circle for which the distance from the center of the circle to this point is lower than its radius.
I make several assumption here:
- you only have one rectangle shape in your layout
- your circle.width is exactly equal to your circle's diameter (I use width/2 for the radius)
- the origin of your rectangle and circle is in the middle
Be carefull the amount of computation will be proportionnal to rectangle.width*rectangle.height*circle.Count at worst case, which is if the rectangle is completely covered since all the loop are stopped as soon as an out of circle point is found.
If you happen to use some kind of grid snapping, you can probably lower the amount of computation since you shouldn't have to check every single point of the rectangle (but not sure)
In any case you shouldn't run this function every tick, but probably only when you drop a circle.
Also using any kind of C2's built-in overlap check isn't really reliable since a circle's collision polygon is usually an octogon and also, checking for radius is probably faster than using polygon based collision detection.
here's a working implementation:rectCoveredByCircle.capx
as you can see it can get quickly slow.Yann2013-03-26 08:36:17