Time for action – allowing the ship to shoot cannonballs
Let's allow the pirate ship to shoot cannonballs by following these steps:
Open the
Ship.h
file.Add a read-only property called
isShooting
, which has an instance variable counterpart called_isShooting
, as shown in the following code:@property (readonly) BOOL isShooting;
Add a cannonball for the left-hand side and the right-hand side of the ship. Both of them are pointers to
SPImage
, as shown in the following code:@property SPImage *cannonBallLeft; @property SPImage *cannonBallRight;
Switch to the
Ship.m
file.Inside the
initWithType
method, set the_isShooting
instance variable toNO
at the top of the method.Inside the
initWithType
method, create both cannonballs with thecannonball.png
image, set theirvisible
property toNO
, and add them to the display tree.Inside the
shoot
method, abort if_isShooting
is set toYES
, else set_isShooting
toYES
, as shown:if (_isShooting) { return; } _isShooting = YES;
Set some default values for the...