#import "GameplayLayer.h"
@implementation GameplayLayer
-(id)init {
[self scheduleUpdate];
self = [super init];
CGSize size =[[CCDirector sharedDirector] winSize];
if (self != nil) {
screenHeight = size.height;
srceenWidth = size.width;
// enable touches
duckSprite = [CCSprite spriteWithFile:@"duck1.png"
rect:CGRectMake(0, 0, 20, 20)];
duckSprite.position = ccp(100, screenHeight/2);
[self addChild:duckSprite];
CCAnimation *duckAnim = [CCAnimation animation];
[duckAnim addFrameWithFilename:@"duck1.png"];
[duckAnim addFrameWithFilename:@"duck2.png"];
id duckAnimationAction =
[CCAnimate actionWithDuration:0.5f
animation:duckAnim
restoreOriginalFrame:YES];
id repeatduckAnimation =
[CCRepeatForever actionWithAction:duckAnimationAction];
[duckSprite runAction:repeatduckAnimation];
crosshair = [CCSprite spriteWithFile:@"crosshair.png"
rect:CGRectMake(0, 0, 125, 125)];
[self addChild:crosshair];
crosshair.position = CGPointMake( size.width / 2, size.height / 2);
self.isAccelerometerEnabled = YES;
CCMenuItem *shoot = [CCMenuItemImage itemFromNormalImage:@"Shootbutton.png" selectedImage:@"Shootbuttons.png" target:self selector:@selector(shootbuttonin:)];
shoot.position = ccp(450,30);
[self addChild:shoot];
}
return self;
}
- (void)shootbuttonin:(id)sender {
[[CCDirector sharedDirector] winSize];
CGRect duckRect = CGRectMake(
duckSprite.position.x - (duckSprite.contentSize.width/2),
duckSprite.position.y - (duckSprite.contentSize.height/2),
duckSprite.contentSize.width,
duckSprite.contentSize.height);
CGRect crosshairRect = CGRectMake(
crosshair.position.x - (crosshair.contentSize.width/2),
crosshair.position.y - (crosshair.contentSize.height/2),
crosshair.contentSize.width,
crosshair.contentSize.height);
if (CGRectIntersectsRect(duckRect, crosshairRect)) {
CCLOG(@"Collision!");
}
}
-(void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
CCLOG(@"Acceleration Values are x:%f y:%f z:%f", acceleration.x , acceleration.y, acceleration.z );
tiltHorizontal = acceleration.y * 20;
tiltVertically = (acceleration.x + .4) *20;
CCLOG(@"tiltHorizontal is %i", tiltHorizontal );
}
- (void) dealloc
{
// in case you have something to dealloc, do it in this method
// in this particular example nothing needs to be released.
// cocos2d will automatically release all the children (Label)
// don't forget to call "super dealloc"
[super dealloc];
}
@end
2012-02-04 00:31:37.263 DuckHunting[718:707] cocos2d: cocos2d v1.0.1
2012-02-04 00:31:37.268 DuckHunting[718:707] cocos2d: Using Director Type:CCDirectorDisplayLink
2012-02-04 00:31:37.808 DuckHunting[718:707] cocos2d: OS version: 5.0.1 (0x05000100)
2012-02-04 00:31:37.810 DuckHunting[718:707] cocos2d: GL_VENDOR: Imagination Technologies
2012-02-04 00:31:37.811 DuckHunting[718:707] cocos2d: GL_RENDERER: PowerVR SGX 543
2012-02-04 00:31:37.813 DuckHunting[718:707] cocos2d: GL_VERSION: OpenGL ES-CM 1.1 IMGSGX543-63.14.2
2012-02-04 00:31:37.815 DuckHunting[718:707] cocos2d: GL_MAX_TEXTURE_SIZE: 4096
2012-02-04 00:31:37.816 DuckHunting[718:707] cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH: 16
2012-02-04 00:31:37.818 DuckHunting[718:707] cocos2d: GL_MAX_SAMPLES: 4
2012-02-04 00:31:37.819 DuckHunting[718:707] cocos2d: GL supports PVRTC: YES
2012-02-04 00:31:37.821 DuckHunting[718:707] cocos2d: GL supports BGRA8888 textures: YES
2012-02-04 00:31:37.822 DuckHunting[718:707] cocos2d: GL supports NPOT textures: YES
2012-02-04 00:31:37.823 DuckHunting[718:707] cocos2d: GL supports discard_framebuffer: YES
2012-02-04 00:31:37.825 DuckHunting[718:707] cocos2d: compiled with NPOT support: NO
2012-02-04 00:31:37.826 DuckHunting[718:707] cocos2d: compiled with VBO support in TextureAtlas : YES
2012-02-04 00:31:37.828 DuckHunting[718:707] cocos2d: compiled with Affine Matrix transformation in CCNode : YES
2012-02-04 00:31:37.829 DuckHunting[718:707] cocos2d: compiled with Profiling Support: NO
2012-02-04 00:31:37.947 DuckHunting[718:707] cocos2d: surface size: 480x320
2012-02-04 00:31:38.197 DuckHunting[718:707] cocos2d: Frame interval: 1
2012-02-04 00:31:38.241 DuckHunting[718:707] -[GameplayLayer update:]: unrecognized selector sent to instance 0x318740
2012-02-04 00:31:38.244 DuckHunting[718:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GameplayLayer update:]: unrecognized selector sent to instance 0x318740'
*** First throw call stack:
(0x36ff88bf 0x316c61e5 0x36ffbacb 0x36ffa945 0x36f55680 0x4fba9 0x6ddb5 0x6fb05 0x33552423 0x33552379 0x3067af93 0x360b0891 0x36fc1f43 0x36fcc553 0x36fcc4f5 0x36fcb343 0x36f4e4dd 0x36f4e3a5 0x31104fcd 0x325c0743 0x91ccb 0x2d04)
terminate called throwing an exception(gdb)