Game Development Reference
In-Depth Information
return isColliding;
You will also need to add the method declarations to the BulletCache interface:
-(BOOL) isPlayerBulletCollidingWithRect:(CGRect)rect;
-(BOOL) isEnemyBulletCollidingWithRect:(CGRect)rect;
The idea behind using the two wrapper methods, isPlayerBulletCollidin-
gWithRect and isEnemyBulletCollidingWithRect , is to hide the internal
detail of determining which kinds of bullets to use for collision checks. You could also
expose the usePlayerBullets parameter to other classes, but doing so would only
make it harder to eventually change the parameter from a BOOL to an enum , in case
you want to introduce a third type of bullet.
Only visible bullets can collide, of course, and by checking the bullet's new isPlay-
erBullet property, you ensure that enemies can't shoot themselves. The actual colli-
sion test is a simple CGRectIntersectsRect test, and if the bullet has actually hit
something, the bullet itself is also set to be invisible to make it disappear. The Bullet
class is extended to include the isPlayerBullet property:
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@class Ship;
@interface Bullet : CCSprite
CGPoint velocity;
float outsideScreen;
BOOL isPlayerBullet;
@property (readwrite, nonatomic) CGPoint velocity;
@property (readwrite, nonatomic) BOOL isPlayerBullet;
Search Nedrilad ::

Custom Search