One flaw with the getOneObjectAtOffets()
and getObjectsAtOffset()
methods is that they only check the granularity of a single pixel. If an object of interest is one pixel above or below the offset provided to these methods, then no collision will be detected. In fact, in this implementation, if you allow the simulation to run until the zombies reach the houses, you'll notice that some zombies can move past the houses. This is because the pixel-only check fails between houses. One way to handle this deficiency is to use hidden-sprite collision detection. Figure 7 illustrates this method.
In the hidden-sprite method, you use another Actor
class to test for collisions. Figure 7 shows a Zombie
object using a smaller, auxiliary Actor
class to determine if a collision occurred with the flower. While the hidden sprite is shown as a translucent red rectangle, in practice, we would set...