HTML and CSS Reference
In-Depth Information
posite direction by reversing the y-axis direction. Replace the
Ball
object's
collide()
with the following listing.
Listing 6.10. game.jsāBall touching paddle
Step 5: Remove hit bricks
When the ball hits a brick, that brick needs to disappear. Replace
Brick.draw()
with
the code in the next listing, which tests if the ball is overlapping when a brick is drawn. If
so, it reverses the ball's y-axis and sets the brick's array data to
false
to remove it from
gameplay. Use the following listing to add a new
Bricks.collide()
method.