Question

New Programmer here. Trying space invaders. I have a 2 dimensional array of objects stored in a one dimensional array (using modulo to determine rows and columns). Each object will return its boundaries in graphical space. I need to determine the boundaries (top, bottom, left, right) of the whole array for collision detection.

I feel like I'm missing something super simple. All my tests seem to only get the position of the last one. Also, some of the objects disappear, possibly changing the dimensions.

Was it helpful?

Solution

The overall boundary box is

overall_top    = min(all of top)
overall_bottom = max(all of bottom)
overall_left   = min(all of left)
overall_right  = max(all of right)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top