We all like the bases that can be destroyed by chunks being split out,
I originally implemented it by making a rectangle filled with individual squares (2x2 pixel size CANVAS rects) that would collision detect with any bullets (On^2 very inefficient). I am now trying to make the base into a shape instead of a boring rectangle. I also want to perform collections of nearby squares when one is hit so that chunks can be taken of the base, instead of just the part that was hit. (easy to do with a rectangular array)
Is a 2 dimensianal arry still the best way to acheive this? Is there a way to create this array by somehow performing image analysis of a PNG to populate this array? Transparent parts would hold no base item at that [i][j].
O(n^2)
if every pixel of your base needs to collide with every other pixel. Usually though, what you want is for each bullet to ask "do I hit anything where I am currently?" which can be looked up inO(bullet count)
(and you can skip bullets above/below the base area), or "did I pass through anything on my way here?" which isO(bullet count * bullet speed)
. Once you've detected a hit at a particular location, you can splash out to neighbouring pixels inO(hits this frame * neighbourhood radius^2)
which should still be quite a bit less thanO(total pixel count^2)
. \$\endgroup\$