Game Development Reference
In-Depth Information
class TankGraphics < Component
# ...
DEBUG_COLORS = [
Gosu :: Color :: RED ,
Gosu :: Color :: BLUE ,
Gosu :: Color :: YELLOW ,
Gosu :: Color :: WHITE
]
# ...
def draw_bounding_box
i = 0
object . box . each_slice( 2 ) do | x, y |
color = DEBUG_COLORS [ i ]
$window . draw_triangle(
x - 3 , y - 3 , color,
x, y, color,
x + 3 , y - 3 , color,
100 )
i = (i + 1 ) % 4
end
end
# ...
Now we can visually test bounding box edges and see that they actually are where they
belong.
High precision bounding boxes
Time to pimp our TankPhysics to detect those collisions. While our algorithm is pretty
fast, it doesn't make sense to check collisions for objects that are pretty far apart. This is
why we need our ObjectPool to know how to query objects in close proximity.
class ObjectPool
# ...
def nearby (object, max_distance)
@objects . select do | obj |
Search WWH ::




Custom Search