I have been trying to port over a bullet engine which features a Bullet and BulletCache class into another project. My main difficulty is that the Bullet/BulletCache methods are defined with the assumption of a GameScene singleton. This is a bad practice and the code I am trying to port it to does not have a singleton GameScene class.
In fact, the only singelton this code has is for the Sound engine!
Game classes:
the code calls the GameScene because in the original code, that is where the BulletCache is, but in my code, BulletCache is a subclass of LevelObject (which is a subclass of CCNode) and so my accessors are in the Level Object.
However, LevelObject is not a singelton; I need some tips on how to cleanly port this code over. Thanks!
In fact, the only singelton this code has is for the Sound engine!
Code:
-(void) checkForBulletCollisions
{
EnemyEntity* enemy;
CCARRAY_FOREACH([batch children], enemy)
{
if (enemy.visible)
{
BulletCache* bulletCache = [[GameScene sharedGameScene] bulletCache];
CGRect bbox = [enemy boundingBox];
if ([bulletCache isPlayerBulletCollidingWithRect:bbox])
{
// This enemy got hit ...
[enemy gotHit];
}
}
}
}
Game classes:
Code:
@interface GameScene : CCScene
+(void) newGame:(NSString*)levelFile;
-(void) reloadGame:(NSString*)levelFile;
@end
@interface GameLayer : CCLayer
{
CGPoint cameraOffset,cameraMin,cameraMax;
}
-(void) moveCamera:(CGPoint)pos;
-(CGPoint) getCameraPosition;
@end
the code calls the GameScene because in the original code, that is where the BulletCache is, but in my code, BulletCache is a subclass of LevelObject (which is a subclass of CCNode) and so my accessors are in the Level Object.
However, LevelObject is not a singelton; I need some tips on how to cleanly port this code over. Thanks!