From 4f226a9705d4410fe11d90a89b6cb3b06c8eadc3 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sun, 11 Sep 2011 16:50:44 -0400 Subject: Jump: Disallowed going offscreen after going below ledge level and then riding back up on the wave Fixes #228 --- Classes/JumpGameMode.m | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Classes/JumpGameMode.m') diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m index 15b0e16..1e55b48 100644 --- a/Classes/JumpGameMode.m +++ b/Classes/JumpGameMode.m @@ -182,6 +182,9 @@ if ((cart.sprite.position.y < 86) && (cart.boundedByScreen)) { cart.boundedByScreen = NO; + } else if ((cart.sprite.position.y >= 86) && (!cart.boundedByScreen)) + { + cart.boundedByScreen = YES; } if (cart.sprite.position.y == (0-cart.sprite.boundingBox.size.height/2)) -- cgit 1.4.1 From f3ea6312f1e0d6a0069c41f71f6f40fdfbd8030a Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sun, 11 Sep 2011 19:55:27 -0400 Subject: Made falling objects on the wave destroy at the ledges Previously, falling objects on the wave floated through the ledges--now they destroy when they touch the ledges just like objects not on the wave. Falling objects also now only fall straight downward if they were dropped while the wave was active. Closes #221 --- Classes/FallingObject.h | 2 -- Classes/FallingObject.m | 10 ---------- Classes/JumpGameMode.m | 29 ++++++++++++++++++++--------- 3 files changed, 20 insertions(+), 21 deletions(-) (limited to 'Classes/JumpGameMode.m') diff --git a/Classes/FallingObject.h b/Classes/FallingObject.h index d3ac638..6cb0c14 100755 --- a/Classes/FallingObject.h +++ b/Classes/FallingObject.h @@ -24,7 +24,5 @@ - (BOOL)tick; - (void)collideWithCart; - (void)collideWithFloor; -- (BOOL)flag:(int)flag; -- (void)setFlag:(int)flag withValue:(BOOL)value; @end diff --git a/Classes/FallingObject.m b/Classes/FallingObject.m index 86edd15..85ea902 100755 --- a/Classes/FallingObject.m +++ b/Classes/FallingObject.m @@ -93,16 +93,6 @@ } -- (BOOL)flag:(int)flag -{ - return flags[flag]; -} - -- (void)setFlag:(int)flag withValue:(BOOL)value -{ - flags[flag] = value; -} - - (void)dealloc { [sprite.parent removeChild:sprite cleanup:YES]; diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m index 1e55b48..b192058 100644 --- a/Classes/JumpGameMode.m +++ b/Classes/JumpGameMode.m @@ -30,7 +30,19 @@ @end -// FallingObject flag 0 is whether the object is floating in water +@implementation FallingObject (Flags) + +- (BOOL)fellDuringWave +{ + return flags[0]; +} + +- (void)setFellDuringWave:(BOOL)value +{ + flags[0] = value; +} + +@end @implementation JumpGameMode @@ -118,10 +130,12 @@ } } + [ledges minusSet:discardedSet]; + NSMutableSet* discardedObjects = [NSMutableSet set]; for (FallingObject* object in objects) { - if ((object.sprite.position.y < 86) && (![object flag:0])) + if (object.sprite.position.y < (64+object.sprite.boundingBox.size.height/2)) { for (CCSprite* ledge in ledges) { @@ -144,20 +158,14 @@ } } - if ((waterTick >= 180) || ((waterTick > 0) && ([object flag:0]))) + if (object.fellDuringWave) { object.sprite.position = ccp(object.sprite.position.x, MAX(object.sprite.position.y, water.position.y+80+11)); } else { object.sprite.position = ccp(object.sprite.position.x-ledgeScrollSpeed, object.sprite.position.y); } - - if ((waterTick > 0) && (object.sprite.position.y <= (water.position.y+80+11))) - { - [object setFlag:0 withValue:YES]; - } } - [ledges minusSet:discardedSet]; [objects minusSet:discardedObjects]; if (rightmost <= 480) @@ -396,6 +404,7 @@ object.sprite.position = ccp(objectX, 360); object.sprite.scale = 1; + object.fellDuringWave = waterTick > 0; [self addChild:object.sprite]; [objects addObject:object]; @@ -429,6 +438,7 @@ object.sprite.position = ccp(objectX, 360); object.sprite.scale = 1; + object.fellDuringWave = waterTick > 0; [self addChild:object.sprite]; [objects addObject:object]; @@ -464,6 +474,7 @@ object.sprite.position = ccp(objectX, 360); object.sprite.scale = 1; + object.fellDuringWave = waterTick > 0; [self addChild:object.sprite]; [objects addObject:object]; -- 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/JumpGameMode.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