6.9 Blocker
Subclass of GameElement
Class Blocker
(Fig. 6.8)—a subclass of GameElement
—represents the blocker, which makes it more difficult for the player to destroy targets. Class Blocker
’s missPenalty
is subtracted from the remaining game time if the Cannonball
collides with the Blocker
. The getMissPenalty
method (lines 17–19) returns the missPenalty
—this method is called from CannonView
’s testForCollisions
method when subtracting the missPenalty
from the remaining time (Section 6.13.11). The Blocker
constructor (lines 9–14) passes its arguments and the ID for the blocker-hit sound (CannonView.BLOCKER_SOUND_ID
) to the superclass constructor (line 11), then initializes missPenalty
.
Get Android How to Program, 3/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.