Game Development Reference
In-Depth Information
# ...
end
And unless we want all stationary tanks face same direction, we will randomize it:
class
Tank
<
GameObject
# ...
def
initialize
(object_pool, input)
# ...
@direction
=
rand
(
0.
.
7
)
* 45
@gun_angle
=
rand
(
0.
.
360
)
end
# ...
end
Fire up the game, and wander around frozen tanks. You can pass through them as if they
were ghosts, but we will fix that in a moment.
Brain dead enemies
Adding Bounding Boxes And Detecting Collisions
We want our collision detection to be pixel perfect, that means we need to have a bounding
box and check colisions against it. Get ready for some math!
First, we need to find a correct way to construct a bounding box. Tank has it's body image,
so let's see how it's boundaries look like. We will add some code to
TankGraphics
component to see it:
class
TankGraphics
<
Component
def
draw
(viewport)
# ...
draw_bounding_box
end