summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-10-17 20:57:46 -0400
committerStarla Insigna <starla4444@gmail.com>2011-10-17 20:57:46 -0400
commit08cb72a92328cb0f38947fe5e8c5f23bab8cd0cc (patch)
tree7f08db53abebda90785398911a6ed2f08c972051
parent4d09a715397de91a66f3fbea0fe2b629f64b6e9a (diff)
downloadcartcollect-9092687f7e8b6675e31995535ee181cdad20109e.tar.gz
cartcollect-9092687f7e8b6675e31995535ee181cdad20109e.tar.bz2
cartcollect-9092687f7e8b6675e31995535ee181cdad20109e.zip
Added support for gyroscope-based movement v0.4.8
Closes #230
-rwxr-xr-xCartographic.xcodeproj/project.pbxproj10
-rw-r--r--Classes/Cart.h2
-rw-r--r--Classes/Cart.m13
-rw-r--r--Classes/GameMode.h6
-rw-r--r--Classes/GameMode.m63
-rw-r--r--Classes/JumpGameMode.m14
6 files changed, 89 insertions, 19 deletions
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 @@
109 6C19F1651401917900F9CCD3 /* feedback2.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C19F1641401917900F9CCD3 /* feedback2.png */; }; 109 6C19F1651401917900F9CCD3 /* feedback2.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C19F1641401917900F9CCD3 /* feedback2.png */; };
110 6C29041013EAEB590032DA0F /* TutorialBubble.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C29040F13EAEB590032DA0F /* TutorialBubble.m */; }; 110 6C29041013EAEB590032DA0F /* TutorialBubble.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C29040F13EAEB590032DA0F /* TutorialBubble.m */; };
111 6C29041213EAEC8A0032DA0F /* framestuff.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C29041113EAEC8A0032DA0F /* framestuff.png */; }; 111 6C29041213EAEC8A0032DA0F /* framestuff.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C29041113EAEC8A0032DA0F /* framestuff.png */; };
112 6C2A07781436100C007AB76C /* CoreMotion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6C2A07771436100C007AB76C /* CoreMotion.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
112 6C39CFE013FC2708002B21AF /* tutorial.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C39CFDF13FC2708002B21AF /* tutorial.png */; }; 113 6C39CFE013FC2708002B21AF /* tutorial.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C39CFDF13FC2708002B21AF /* tutorial.png */; };
113 6C39CFE213FC2713002B21AF /* tutorial2.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C39CFE113FC2713002B21AF /* tutorial2.png */; }; 114 6C39CFE213FC2713002B21AF /* tutorial2.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C39CFE113FC2713002B21AF /* tutorial2.png */; };
114 6C39CFE513FC4635002B21AF /* JumpGameMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C39CFE413FC4635002B21AF /* JumpGameMode.m */; }; 115 6C39CFE513FC4635002B21AF /* JumpGameMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C39CFE413FC4635002B21AF /* JumpGameMode.m */; };
@@ -444,6 +445,7 @@
444 6C29040E13EAEB590032DA0F /* TutorialBubble.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TutorialBubble.h; sourceTree = "<group>"; }; 445 6C29040E13EAEB590032DA0F /* TutorialBubble.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TutorialBubble.h; sourceTree = "<group>"; };
445 6C29040F13EAEB590032DA0F /* TutorialBubble.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TutorialBubble.m; sourceTree = "<group>"; }; 446 6C29040F13EAEB590032DA0F /* TutorialBubble.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TutorialBubble.m; sourceTree = "<group>"; };
446 6C29041113EAEC8A0032DA0F /* framestuff.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = framestuff.png; sourceTree = "<group>"; }; 447 6C29041113EAEC8A0032DA0F /* framestuff.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = framestuff.png; sourceTree = "<group>"; };
448 6C2A07771436100C007AB76C /* CoreMotion.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMotion.framework; path = System/Library/Frameworks/CoreMotion.framework; sourceTree = SDKROOT; };
447 6C39CFDF13FC2708002B21AF /* tutorial.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = tutorial.png; sourceTree = "<group>"; }; 449 6C39CFDF13FC2708002B21AF /* tutorial.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = tutorial.png; sourceTree = "<group>"; };
448 6C39CFE113FC2713002B21AF /* tutorial2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = tutorial2.png; sourceTree = "<group>"; }; 450 6C39CFE113FC2713002B21AF /* tutorial2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = tutorial2.png; sourceTree = "<group>"; };
449 6C39CFE313FC4635002B21AF /* JumpGameMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JumpGameMode.h; sourceTree = "<group>"; }; 451 6C39CFE313FC4635002B21AF /* JumpGameMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JumpGameMode.h; sourceTree = "<group>"; };
@@ -673,6 +675,7 @@
673 isa = PBXFrameworksBuildPhase; 675 isa = PBXFrameworksBuildPhase;
674 buildActionMask = 2147483647; 676 buildActionMask = 2147483647;
675 files = ( 677 files = (
678 6C2A07781436100C007AB76C /* CoreMotion.framework in Frameworks */,
676 DCCBF1B70F6022AE0040855A /* CoreGraphics.framework in Frameworks */, 679 DCCBF1B70F6022AE0040855A /* CoreGraphics.framework in Frameworks */,
677 DCCBF1B90F6022AE0040855A /* Foundation.framework in Frameworks */, 680 DCCBF1B90F6022AE0040855A /* Foundation.framework in Frameworks */,
678 DCCBF1BB0F6022AE0040855A /* OpenGLES.framework in Frameworks */, 681 DCCBF1BB0F6022AE0040855A /* OpenGLES.framework in Frameworks */,
@@ -743,6 +746,7 @@
743 children = ( 746 children = (
744 6C88B69314119B5A0049E402 /* libTestFlight.a */, 747 6C88B69314119B5A0049E402 /* libTestFlight.a */,
745 3F8395D013D746200059AEE8 /* libsqlite3.0.dylib */, 748 3F8395D013D746200059AEE8 /* libsqlite3.0.dylib */,
749 6C2A07771436100C007AB76C /* CoreMotion.framework */,
746 DCCBF1B60F6022AE0040855A /* CoreGraphics.framework */, 750 DCCBF1B60F6022AE0040855A /* CoreGraphics.framework */,
747 DCCBF1B80F6022AE0040855A /* Foundation.framework */, 751 DCCBF1B80F6022AE0040855A /* Foundation.framework */,
748 DCCBF1BA0F6022AE0040855A /* OpenGLES.framework */, 752 DCCBF1BA0F6022AE0040855A /* OpenGLES.framework */,
@@ -1686,6 +1690,7 @@
1686 INFOPLIST_FILE = Resources/Info.plist; 1690 INFOPLIST_FILE = Resources/Info.plist;
1687 INFOPLIST_PREFIX_HEADER = Versioning.h; 1691 INFOPLIST_PREFIX_HEADER = Versioning.h;
1688 INFOPLIST_PREPROCESS = YES; 1692 INFOPLIST_PREPROCESS = YES;
1693 IPHONEOS_DEPLOYMENT_TARGET = 3.0;
1689 LIBRARY_SEARCH_PATHS = ( 1694 LIBRARY_SEARCH_PATHS = (
1690 "$(inherited)", 1695 "$(inherited)",
1691 "\"$(SRCROOT)\"", 1696 "\"$(SRCROOT)\"",
@@ -1695,6 +1700,7 @@
1695 "-ObjC", 1700 "-ObjC",
1696 ); 1701 );
1697 PRODUCT_NAME = Cartographic; 1702 PRODUCT_NAME = Cartographic;
1703 SDKROOT = iphoneos;
1698 TARGETED_DEVICE_FAMILY = 1; 1704 TARGETED_DEVICE_FAMILY = 1;
1699 WARNING_CFLAGS = "-Wall"; 1705 WARNING_CFLAGS = "-Wall";
1700 }; 1706 };
@@ -1718,6 +1724,7 @@
1718 INFOPLIST_FILE = Resources/Info.plist; 1724 INFOPLIST_FILE = Resources/Info.plist;
1719 INFOPLIST_PREFIX_HEADER = Versioning.h; 1725 INFOPLIST_PREFIX_HEADER = Versioning.h;
1720 INFOPLIST_PREPROCESS = YES; 1726 INFOPLIST_PREPROCESS = YES;
1727 IPHONEOS_DEPLOYMENT_TARGET = 3.0;
1721 LIBRARY_SEARCH_PATHS = ( 1728 LIBRARY_SEARCH_PATHS = (
1722 "$(inherited)", 1729 "$(inherited)",
1723 "\"$(SRCROOT)\"", 1730 "\"$(SRCROOT)\"",
@@ -1727,6 +1734,7 @@
1727 "-ObjC", 1734 "-ObjC",
1728 ); 1735 );
1729 PRODUCT_NAME = Cartographic; 1736 PRODUCT_NAME = Cartographic;
1737 SDKROOT = iphoneos;
1730 TARGETED_DEVICE_FAMILY = 1; 1738 TARGETED_DEVICE_FAMILY = 1;
1731 WARNING_CFLAGS = "-Wall"; 1739 WARNING_CFLAGS = "-Wall";
1732 }; 1740 };
@@ -1821,6 +1829,7 @@
1821 INFOPLIST_FILE = Resources/Info.plist; 1829 INFOPLIST_FILE = Resources/Info.plist;
1822 INFOPLIST_PREFIX_HEADER = Versioning.h; 1830 INFOPLIST_PREFIX_HEADER = Versioning.h;
1823 INFOPLIST_PREPROCESS = YES; 1831 INFOPLIST_PREPROCESS = YES;
1832 IPHONEOS_DEPLOYMENT_TARGET = 3.0;
1824 LIBRARY_SEARCH_PATHS = ( 1833 LIBRARY_SEARCH_PATHS = (
1825 "$(inherited)", 1834 "$(inherited)",
1826 "\"$(SRCROOT)\"", 1835 "\"$(SRCROOT)\"",
@@ -1830,6 +1839,7 @@
1830 "-ObjC", 1839 "-ObjC",
1831 ); 1840 );
1832 PRODUCT_NAME = Cartographic; 1841 PRODUCT_NAME = Cartographic;
1842 SDKROOT = iphoneos;
1833 TARGETED_DEVICE_FAMILY = 1; 1843 TARGETED_DEVICE_FAMILY = 1;
1834 WARNING_CFLAGS = "-Wall"; 1844 WARNING_CFLAGS = "-Wall";
1835 }; 1845 };
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 @@
26@property (assign) BOOL boundedByScreen; 26@property (assign) BOOL boundedByScreen;
27- (id)initWithSprite:(CCSprite*)sprite; 27- (id)initWithSprite:(CCSprite*)sprite;
28- (void)tick; 28- (void)tick;
29- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration; 29- (void)deviceDidRotate:(double)pitch;
30 30
31@end 31@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 @@
62 } 62 }
63} 63}
64 64
65- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration 65#define kFilterFactor 0.05f
66
67- (void)deviceDidRotate:(double)pitch
66{ 68{
67 static float prevY=0; 69 static float prevY=0;
68 70 float accelY = -((float) pitch * kFilterFactor + (1- kFilterFactor)*prevY);
69#define kFilterFactor 0.05f 71
70 72 prevY = accelY;
71 float accelY = -((float) acceleration.y * kFilterFactor + (1- kFilterFactor)*prevY);
72
73 prevY = accelY;
74 accelX = accelY * 750; 73 accelX = accelY * 750;
75} 74}
76 75
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 @@
8 8
9#import "CCLayer.h" 9#import "CCLayer.h"
10#import "Cart.h" 10#import "Cart.h"
11#import <CoreMotion/CoreMotion.h>
11 12
12#define GAME_SCENE 436 13#define GAME_SCENE 436
13#define GAME_LAYER 437 14#define GAME_LAYER 437
@@ -28,6 +29,10 @@
28 void (^delayedAction)(void); 29 void (^delayedAction)(void);
29 30
30 BOOL isPaused; 31 BOOL isPaused;
32
33 BOOL hasGyroscope;
34 double pitch;
35 CMMotionManager* motionManager;
31} 36}
32 37
33@property (readonly) Cart* cart; 38@property (readonly) Cart* cart;
@@ -43,5 +48,6 @@
43- (void)mainmenu; 48- (void)mainmenu;
44- (void)scheduleDelayedAction:(void(^)(void))delayedAction delay:(float)delay; 49- (void)scheduleDelayedAction:(void(^)(void))delayedAction delay:(float)delay;
45- (void)runDelayedAction; 50- (void)runDelayedAction;
51- (void)setPitch:(double)m_pitch;
46 52
47@end 53@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 @@
33 33
34 if (nil != self) 34 if (nil != self)
35 { 35 {
36 isAccelerometerEnabled_ = YES;
37
38 objects = [[NSMutableSet alloc] init]; 36 objects = [[NSMutableSet alloc] init];
39 37
40 cart = [[Cart alloc] initWithSprite:[CCSprite spriteWithFile:@"cart.png"]]; 38 cart = [[Cart alloc] initWithSprite:[CCSprite spriteWithFile:@"cart.png"]];
@@ -64,6 +62,26 @@
64 } 62 }
65 63
66 isPaused = NO; 64 isPaused = NO;
65
66 Class cmClass = (NSClassFromString(@"CMMotionManager"));
67 if (cmClass)
68 {
69 motionManager = [[CMMotionManager alloc] init];
70
71 if (motionManager.gyroAvailable)
72 {
73 [motionManager setDeviceMotionUpdateInterval:1.0f/60.0f];
74 isAccelerometerEnabled_ = NO;
75 hasGyroscope = YES;
76 } else {
77 isAccelerometerEnabled_ = YES;
78 motionManager = nil;
79 hasGyroscope = NO;
80 }
81 } else {
82 isAccelerometerEnabled_ = YES;
83 hasGyroscope = NO;
84 }
67 } 85 }
68 86
69 return self; 87 return self;
@@ -71,19 +89,39 @@
71 89
72- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration 90- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration
73{ 91{
74 [cart accelerometer:accelerometer didAccelerate:acceleration]; 92 self.pitch = acceleration.y;
75} 93}
76 94
77- (void)onEnterTransitionDidFinish 95- (void)onEnterTransitionDidFinish
78{ 96{
79 [super onEnterTransitionDidFinish]; 97 [super onEnterTransitionDidFinish];
80 98
81 [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 60)]; 99 if (hasGyroscope)
100 {
101 [motionManager startDeviceMotionUpdates];
102 } else {
103 [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 60)];
104 }
105
82 [self schedule:@selector(tick:) interval:1.0f/60.0f]; 106 [self schedule:@selector(tick:) interval:1.0f/60.0f];
83} 107}
84 108
109- (void)onExit
110{
111 if (hasGyroscope)
112 {
113 [motionManager stopDeviceMotionUpdates];
114 }
115}
116
85- (void)tick:(ccTime)dt 117- (void)tick:(ccTime)dt
86{ 118{
119 if (hasGyroscope)
120 {
121 CMDeviceMotion* motion = [motionManager deviceMotion];
122 self.pitch = -motion.attitude.pitch;
123 }
124
87 [cart tick]; 125 [cart tick];
88 126
89 NSMutableSet* discardedObjects = [NSMutableSet set]; 127 NSMutableSet* discardedObjects = [NSMutableSet set];
@@ -111,6 +149,11 @@
111 149
112 [self pauseSchedulerAndActions]; 150 [self pauseSchedulerAndActions];
113 151
152 if (hasGyroscope)
153 {
154 [motionManager stopDeviceMotionUpdates];
155 }
156
114 shadedLayer = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 127)]; 157 shadedLayer = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 127)];
115 [[[CCDirector sharedDirector] runningScene] addChild:shadedLayer]; 158 [[[CCDirector sharedDirector] runningScene] addChild:shadedLayer];
116 159
@@ -143,6 +186,11 @@
143 shadedLayer = nil; 186 shadedLayer = nil;
144 pauseLayer = nil; 187 pauseLayer = nil;
145 188
189 if (hasGyroscope)
190 {
191 [motionManager startDeviceMotionUpdates];
192 }
193
146 [self resumeSchedulerAndActions]; 194 [self resumeSchedulerAndActions];
147 195
148 isPaused = NO; 196 isPaused = NO;
@@ -211,6 +259,13 @@
211 } 259 }
212} 260}
213 261
262- (void)setPitch:(double)m_pitch
263{
264 pitch = m_pitch;
265
266 [cart deviceDidRotate:pitch];
267}
268
214- (void)dealloc 269- (void)dealloc
215{ 270{
216 [objects release]; 271 [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 @@
288 isGesturing = NO; 288 isGesturing = NO;
289} 289}
290 290
291- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
292{
293 [super accelerometer:accelerometer didAccelerate:acceleration];
294
295 expectedAngle = acceleration.y*M_PI_2;
296}
297
298- (int)cartShouldFall:(Cart *)m_cart 291- (int)cartShouldFall:(Cart *)m_cart
299{ 292{
300 int bottom = 0-m_cart.sprite.boundingBox.size.height/2; 293 int bottom = 0-m_cart.sprite.boundingBox.size.height/2;
@@ -500,6 +493,13 @@
500 } 493 }
501} 494}
502 495
496- (void)setPitch:(double)m_pitch
497{
498 [super setPitch:m_pitch];
499
500 expectedAngle = pitch*M_PI_2;
501}
502
503@end 503@end
504 504
505@implementation LedgeFactory 505@implementation LedgeFactory