diff --git a/Yog-Shot-Oth/GameConfig.h b/Yog-Shot-Oth/GameConfig.h index e5ec0ec..183a6de 100644 --- a/Yog-Shot-Oth/GameConfig.h +++ b/Yog-Shot-Oth/GameConfig.h @@ -42,7 +42,7 @@ #error(unknown architecture) #endif -#define GAME_AUTOROTATION kGameAutorotationNone +#define GAME_AUTOROTATION kGameAutorotationUIViewController #endif // __GAME_CONFIG_H diff --git a/Yog-Shot-Oth/MainLayer.h b/Yog-Shot-Oth/MainLayer.h index 6c66a67..e58032d 100644 --- a/Yog-Shot-Oth/MainLayer.h +++ b/Yog-Shot-Oth/MainLayer.h @@ -9,8 +9,10 @@ #import "cocos2d.h" @interface MainLayer : CCLayer { + CGSize winSize; CCSprite *starship; NSMutableArray *bullets; NSMutableArray *enemis; } + @end diff --git a/Yog-Shot-Oth/MainLayer.m b/Yog-Shot-Oth/MainLayer.m index 82f7f70..729fde6 100644 --- a/Yog-Shot-Oth/MainLayer.m +++ b/Yog-Shot-Oth/MainLayer.m @@ -8,6 +8,7 @@ #import "MainLayer.h" #import "Constants.h" +#import "CCTouchDispatcher.h" @implementation MainLayer @@ -15,7 +16,7 @@ { self = [super init]; if (self) { - CGSize winSize = [[CCDirector sharedDirector] winSize]; + winSize = [[CCDirector sharedDirector] winSize]; starship = [[CCSprite alloc] initWithFile:@"Vaisseau.png"]; starship.position = ccp(40, 40); @@ -33,12 +34,43 @@ 100 + (rand() % ((int)winSize.height - 100))); [self addChild:enemy]; } + self.isTouchEnabled = YES; + [self schedule:@selector(nextFrame:)]; } return self; } +-(void) registerWithTouchDispatcher +{ + [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES]; +} + +-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event +{ + [[CCDirector sharedDirector] resume]; + return YES; +} + + +- (void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event +{ + [[CCDirector sharedDirector] pause]; +} + +/* +- (void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event +{ + +}*/ + +- (void) nextFrame:(ccTime)dt +{ + starship.position = ccp((int)(starship.position.x + (winSize.width*dt) ) % ((int)winSize.width),40); +} + + - (void) dealloc { [starship release]; diff --git a/Yog-Shot-Oth/RootViewController.m b/Yog-Shot-Oth/RootViewController.m index 90ea8f1..8ac6431 100644 --- a/Yog-Shot-Oth/RootViewController.m +++ b/Yog-Shot-Oth/RootViewController.m @@ -67,10 +67,10 @@ // // Sample: Autorotate only in landscape mode // - if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) { - [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight]; - } else if( interfaceOrientation == UIInterfaceOrientationLandscapeRight) { - [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeLeft]; + if( interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ) { + [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationPortraitUpsideDown]; + } else if( interfaceOrientation == UIInterfaceOrientationPortrait) { + [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationPortrait]; } // Since this method should return YES in at least 1 orientation, @@ -85,7 +85,7 @@ // // return YES for the supported orientations - return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) ); + return ( UIInterfaceOrientationIsPortrait( interfaceOrientation ) ); #else #error Unknown value in GAME_AUTOROTATION @@ -93,7 +93,7 @@ #endif // GAME_AUTOROTATION - // Shold not happen + // Should not happen return NO; }