6.12 Cannonball
Subclass of GameElement
The Cannonball
subclass of GameElement
(Sections 6.12.1–6.12.4) represents a cannonball fired from the cannon.
6.12.1 Instance Variables and Constructor
The Cannonball
constructor (Fig. 6.15) receives the cannonball’s radius
rather than width
and height
in the GameElement
constructor. Lines 15–16 call super
with width
and height
values calculated from the radius
. The constructor also receives the horizontal velocity of the Cannonball
, velocityX
, in addition to its vertical velocity, velocityY
. Line 18 initializes onScreen
to true
because the Cannonball
is initially on the screen.
6.12.2 Methods getRadius
, collidesWith ...
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.