January 2014
Intermediate to advanced
736 pages
70h 43m
English
When the user touches the screen, method onTouchEvent (Section 6.8.13) calls fireCannonball (Fig. 6.13). If there’s already a cannonball on the screen, the method returns immediately. Line 313 calls alignCannon to aim the cannon at the touch point and get the cannon’s angle. Lines 316–317 “load the cannon” (that is, position the cannonball inside the cannon). Then, lines 320 and 323 calculate the horizontal and vertical components of the cannonball’s velocity. Next, we set cannonballOnScreen to true so that the cannonball will be drawn by method drawGameElements (Fig. 6.15) and increment shotsFired. Finally, we play the cannon’s firing sound (represented by the CANNON_SOUND_ID).
307 ...
Read now
Unlock full access