From 4d09a715397de91a66f3fbea0fe2b629f64b6e9a Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Mon, 12 Sep 2011 21:45:12 -0400 Subject: Made the cart in Jump mode fall more quickly Closes #229 --- Classes/Cart.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Classes/Cart.m') diff --git a/Classes/Cart.m b/Classes/Cart.m index 0344bdf..979226b 100644 --- a/Classes/Cart.m +++ b/Classes/Cart.m @@ -54,7 +54,7 @@ if ((delegate != nil) && ([delegate respondsToSelector:@selector(cartShouldFall:)])) { int bottom = [delegate cartShouldFall:self]; - sprite.position = ccp(sprite.position.x, MAX(bottom, sprite.position.y-6)); + sprite.position = ccp(sprite.position.x, MAX(bottom, sprite.position.y-8)); } else { NSLog(@"Falling is set on a cart without a compatible game mode."); } -- cgit 1.4.1 From 08cb72a92328cb0f38947fe5e8c5f23bab8cd0cc Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Mon, 17 Oct 2011 20:57:46 -0400 Subject: Added support for gyroscope-based movement Closes #230 --- Cartographic.xcodeproj/project.pbxproj | 10 ++++++ Classes/Cart.h | 2 +- Classes/Cart.m | 13 ++++--- Classes/GameMode.h | 6 ++++ Classes/GameMode.m | 63 +++++++++++++++++++++++++++++++--- Classes/JumpGameMode.m | 14 ++++---- 6 files changed, 89 insertions(+), 19 deletions(-) (limited to 'Classes/Cart.m') diff --git a/Cartographic.xcodeproj/project.pbxproj b/Cartographic.xcodeproj/project.pbxproj index 75343b3..cd76e10 100755 --- a/Cartographic.xcodeproj/project.pbxproj +++ b/Cartographic.xcodeproj/project.pbxproj @@ -109,6 +109,7 @@ 6C19F1651401917900F9CCD3 /* feedback2.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C19F1641401917900F9CCD3 /* feedback2.png */; }; 6C29041013EAEB590032DA0F /* TutorialBubble.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C29040F13EAEB590032DA0F /* TutorialBubble.m */; }; 6C29041213EAEC8A0032DA0F /* framestuff.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C29041113EAEC8A0032DA0F /* framestuff.png */; }; + 6C2A07781436100C007AB76C /* CoreMotion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6C2A07771436100C007AB76C /* CoreMotion.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 6C39CFE013FC2708002B21AF /* tutorial.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C39CFDF13FC2708002B21AF /* tutorial.png */; }; 6C39CFE213FC2713002B21AF /* tutorial2.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C39CFE113FC2713002B21AF /* tutorial2.png */; }; 6C39CFE513FC4635002B21AF /* JumpGameMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C39CFE413FC4635002B21AF /* JumpGameMode.m */; }; @@ -444,6 +445,7 @@ 6C29040E13EAEB590032DA0F /* TutorialBubble.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TutorialBubble.h; sourceTree = ""; }; 6C29040F13EAEB590032DA0F /* TutorialBubble.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TutorialBubble.m; sourceTree = ""; }; 6C29041113EAEC8A0032DA0F /* framestuff.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = framestuff.png; sourceTree = ""; }; + 6C2A07771436100C007AB76C /* CoreMotion.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMotion.framework; path = System/Library/Frameworks/CoreMotion.framework; sourceTree = SDKROOT; }; 6C39CFDF13FC2708002B21AF /* tutorial.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = tutorial.png; sourceTree = ""; }; 6C39CFE113FC2713002B21AF /* tutorial2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = tutorial2.png; sourceTree = ""; }; 6C39CFE313FC4635002B21AF /* JumpGameMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JumpGameMode.h; sourceTree = ""; }; @@ -673,6 +675,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 6C2A07781436100C007AB76C /* CoreMotion.framework in Frameworks */, DCCBF1B70F6022AE0040855A /* CoreGraphics.framework in Frameworks */, DCCBF1B90F6022AE0040855A /* Foundation.framework in Frameworks */, DCCBF1BB0F6022AE0040855A /* OpenGLES.framework in Frameworks */, @@ -743,6 +746,7 @@ children = ( 6C88B69314119B5A0049E402 /* libTestFlight.a */, 3F8395D013D746200059AEE8 /* libsqlite3.0.dylib */, + 6C2A07771436100C007AB76C /* CoreMotion.framework */, DCCBF1B60F6022AE0040855A /* CoreGraphics.framework */, DCCBF1B80F6022AE0040855A /* Foundation.framework */, DCCBF1BA0F6022AE0040855A /* OpenGLES.framework */, @@ -1686,6 +1690,7 @@ INFOPLIST_FILE = Resources/Info.plist; INFOPLIST_PREFIX_HEADER = Versioning.h; INFOPLIST_PREPROCESS = YES; + IPHONEOS_DEPLOYMENT_TARGET = 3.0; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)\"", @@ -1695,6 +1700,7 @@ "-ObjC", ); PRODUCT_NAME = Cartographic; + SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = 1; WARNING_CFLAGS = "-Wall"; }; @@ -1718,6 +1724,7 @@ INFOPLIST_FILE = Resources/Info.plist; INFOPLIST_PREFIX_HEADER = Versioning.h; INFOPLIST_PREPROCESS = YES; + IPHONEOS_DEPLOYMENT_TARGET = 3.0; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)\"", @@ -1727,6 +1734,7 @@ "-ObjC", ); PRODUCT_NAME = Cartographic; + SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = 1; WARNING_CFLAGS = "-Wall"; }; @@ -1821,6 +1829,7 @@ INFOPLIST_FILE = Resources/Info.plist; INFOPLIST_PREFIX_HEADER = Versioning.h; INFOPLIST_PREPROCESS = YES; + IPHONEOS_DEPLOYMENT_TARGET = 3.0; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)\"", @@ -1830,6 +1839,7 @@ "-ObjC", ); PRODUCT_NAME = Cartographic; + SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = 1; WARNING_CFLAGS = "-Wall"; }; diff --git a/Classes/Cart.h b/Classes/Cart.h index 1058025..af463f2 100644 --- a/Classes/Cart.h +++ b/Classes/Cart.h @@ -26,6 +26,6 @@ @property (assign) BOOL boundedByScreen; - (id)initWithSprite:(CCSprite*)sprite; - (void)tick; -- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration; +- (void)deviceDidRotate:(double)pitch; @end diff --git a/Classes/Cart.m b/Classes/Cart.m index 979226b..f9da181 100644 --- a/Classes/Cart.m +++ b/Classes/Cart.m @@ -62,15 +62,14 @@ } } -- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration +#define kFilterFactor 0.05f + +- (void)deviceDidRotate:(double)pitch { static float prevY=0; - -#define kFilterFactor 0.05f - - float accelY = -((float) acceleration.y * kFilterFactor + (1- kFilterFactor)*prevY); - - prevY = accelY; + float accelY = -((float) pitch * kFilterFactor + (1- kFilterFactor)*prevY); + + prevY = accelY; accelX = accelY * 750; } diff --git a/Classes/GameMode.h b/Classes/GameMode.h index e82ad10..2fcf275 100644 --- a/Classes/GameMode.h +++ b/Classes/GameMode.h @@ -8,6 +8,7 @@ #import "CCLayer.h" #import "Cart.h" +#import #define GAME_SCENE 436 #define GAME_LAYER 437 @@ -28,6 +29,10 @@ void (^delayedAction)(void); BOOL isPaused; + + BOOL hasGyroscope; + double pitch; + CMMotionManager* motionManager; } @property (readonly) Cart* cart; @@ -43,5 +48,6 @@ - (void)mainmenu; - (void)scheduleDelayedAction:(void(^)(void))delayedAction delay:(float)delay; - (void)runDelayedAction; +- (void)setPitch:(double)m_pitch; @end diff --git a/Classes/GameMode.m b/Classes/GameMode.m index 1e80237..e45ddfe 100644 --- a/Classes/GameMode.m +++ b/Classes/GameMode.m @@ -33,8 +33,6 @@ if (nil != self) { - isAccelerometerEnabled_ = YES; - objects = [[NSMutableSet alloc] init]; cart = [[Cart alloc] initWithSprite:[CCSprite spriteWithFile:@"cart.png"]]; @@ -64,6 +62,26 @@ } isPaused = NO; + + Class cmClass = (NSClassFromString(@"CMMotionManager")); + if (cmClass) + { + motionManager = [[CMMotionManager alloc] init]; + + if (motionManager.gyroAvailable) + { + [motionManager setDeviceMotionUpdateInterval:1.0f/60.0f]; + isAccelerometerEnabled_ = NO; + hasGyroscope = YES; + } else { + isAccelerometerEnabled_ = YES; + motionManager = nil; + hasGyroscope = NO; + } + } else { + isAccelerometerEnabled_ = YES; + hasGyroscope = NO; + } } return self; @@ -71,19 +89,39 @@ - (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration { - [cart accelerometer:accelerometer didAccelerate:acceleration]; + self.pitch = acceleration.y; } - (void)onEnterTransitionDidFinish { [super onEnterTransitionDidFinish]; - [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 60)]; + if (hasGyroscope) + { + [motionManager startDeviceMotionUpdates]; + } else { + [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 60)]; + } + [self schedule:@selector(tick:) interval:1.0f/60.0f]; } +- (void)onExit +{ + if (hasGyroscope) + { + [motionManager stopDeviceMotionUpdates]; + } +} + - (void)tick:(ccTime)dt { + if (hasGyroscope) + { + CMDeviceMotion* motion = [motionManager deviceMotion]; + self.pitch = -motion.attitude.pitch; + } + [cart tick]; NSMutableSet* discardedObjects = [NSMutableSet set]; @@ -111,6 +149,11 @@ [self pauseSchedulerAndActions]; + if (hasGyroscope) + { + [motionManager stopDeviceMotionUpdates]; + } + shadedLayer = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 127)]; [[[CCDirector sharedDirector] runningScene] addChild:shadedLayer]; @@ -143,6 +186,11 @@ shadedLayer = nil; pauseLayer = nil; + if (hasGyroscope) + { + [motionManager startDeviceMotionUpdates]; + } + [self resumeSchedulerAndActions]; isPaused = NO; @@ -211,6 +259,13 @@ } } +- (void)setPitch:(double)m_pitch +{ + pitch = m_pitch; + + [cart deviceDidRotate:pitch]; +} + - (void)dealloc { [objects release]; diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m index b192058..eb552a2 100644 --- a/Classes/JumpGameMode.m +++ b/Classes/JumpGameMode.m @@ -288,13 +288,6 @@ isGesturing = NO; } -- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration -{ - [super accelerometer:accelerometer didAccelerate:acceleration]; - - expectedAngle = acceleration.y*M_PI_2; -} - - (int)cartShouldFall:(Cart *)m_cart { int bottom = 0-m_cart.sprite.boundingBox.size.height/2; @@ -500,6 +493,13 @@ } } +- (void)setPitch:(double)m_pitch +{ + [super setPitch:m_pitch]; + + expectedAngle = pitch*M_PI_2; +} + @end @implementation LedgeFactory -- cgit 1.4.1