From 4d94802036a53e6ec246ab0abac17fd76d17c885 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Wed, 17 Aug 2011 19:54:25 -0400 Subject: Started Jump game mode So far, Jump exists as a blank world where the player can control the cart (including the ability to jump by swiping upwards) and where the water level rises for a bit and then falls, taking the cart with it. Refs #204 --- Cart Collect.xcodeproj/project.pbxproj | 18 ++++++ Classes/JumpGameMode.h | 21 +++++++ Classes/JumpGameMode.m | 110 +++++++++++++++++++++++++++++++++ Classes/MainMenuLayer.h | 1 + Classes/MainMenuLayer.m | 9 ++- Resources/jump.png | Bin 0 -> 2071 bytes Resources/jump2.png | Bin 0 -> 2079 bytes Resources/water.png | Bin 0 -> 981 bytes 8 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 Classes/JumpGameMode.h create mode 100644 Classes/JumpGameMode.m create mode 100644 Resources/jump.png create mode 100644 Resources/jump2.png create mode 100644 Resources/water.png diff --git a/Cart Collect.xcodeproj/project.pbxproj b/Cart Collect.xcodeproj/project.pbxproj index 1c07ef3..5ecda95 100755 --- a/Cart Collect.xcodeproj/project.pbxproj +++ b/Cart Collect.xcodeproj/project.pbxproj @@ -105,6 +105,10 @@ 6C29041213EAEC8A0032DA0F /* framestuff.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C29041113EAEC8A0032DA0F /* framestuff.png */; }; 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 */; }; + 6C39CFE713FC46CD002B21AF /* water.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C39CFE613FC46CD002B21AF /* water.png */; }; + 6C39CFE913FC8AC4002B21AF /* jump2.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C39CFE813FC8AC4002B21AF /* jump2.png */; }; + 6C39CFEB13FC8ACA002B21AF /* jump.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C39CFEA13FC8ACA002B21AF /* jump.png */; }; 6C5179C613DF3839006F1F38 /* Morning1.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C5179C513DF3839006F1F38 /* Morning1.png */; }; 6CC89DD913F2F4E6003704F7 /* Entitlements.plist in Resources */ = {isa = PBXBuildFile; fileRef = 6CC89DD813F2F4E6003704F7 /* Entitlements.plist */; }; 6CC89DDF13F31413003704F7 /* TutorialMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 6CC89DDE13F31413003704F7 /* TutorialMode.m */; }; @@ -411,6 +415,11 @@ 6C29041113EAEC8A0032DA0F /* framestuff.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = framestuff.png; sourceTree = ""; }; 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 = ""; }; + 6C39CFE413FC4635002B21AF /* JumpGameMode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JumpGameMode.m; sourceTree = ""; }; + 6C39CFE613FC46CD002B21AF /* water.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = water.png; sourceTree = ""; }; + 6C39CFE813FC8AC4002B21AF /* jump2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = jump2.png; sourceTree = ""; }; + 6C39CFEA13FC8ACA002B21AF /* jump.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = jump.png; sourceTree = ""; }; 6C5179C513DF3839006F1F38 /* Morning1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Morning1.png; sourceTree = ""; }; 6CC89DD813F2F4E6003704F7 /* Entitlements.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Entitlements.plist; sourceTree = ""; }; 6CC89DDD13F31413003704F7 /* TutorialMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TutorialMode.h; sourceTree = ""; }; @@ -729,6 +738,7 @@ 3F6C7F4D13D647B600C038FE /* Sprites */ = { isa = PBXGroup; children = ( + 6C39CFE613FC46CD002B21AF /* water.png */, 6C29041113EAEC8A0032DA0F /* framestuff.png */, 3F6C7EE013D636BE00C038FE /* rock.png */, 3F63FA3E13D4EE53003B3D14 /* oneup.png */, @@ -765,6 +775,8 @@ 3F7D0EC713D8E6B000B6CE14 /* Buttons */ = { isa = PBXGroup; children = ( + 6C39CFEA13FC8ACA002B21AF /* jump.png */, + 6C39CFE813FC8AC4002B21AF /* jump2.png */, 6C39CFE113FC2713002B21AF /* tutorial2.png */, 6C39CFDF13FC2708002B21AF /* tutorial.png */, 3F7D0F4813D8F17C00B6CE14 /* highscores.png */, @@ -871,6 +883,8 @@ 3FE79CD313D4DE37001A6B93 /* ClassicGameMode.m */, 6CC89DDD13F31413003704F7 /* TutorialMode.h */, 6CC89DDE13F31413003704F7 /* TutorialMode.m */, + 6C39CFE313FC4635002B21AF /* JumpGameMode.h */, + 6C39CFE413FC4635002B21AF /* JumpGameMode.m */, ); name = "Game Modes"; sourceTree = ""; @@ -1363,6 +1377,9 @@ 6CC89DD913F2F4E6003704F7 /* Entitlements.plist in Resources */, 6C39CFE013FC2708002B21AF /* tutorial.png in Resources */, 6C39CFE213FC2713002B21AF /* tutorial2.png in Resources */, + 6C39CFE713FC46CD002B21AF /* water.png in Resources */, + 6C39CFE913FC8AC4002B21AF /* jump2.png in Resources */, + 6C39CFEB13FC8ACA002B21AF /* jump.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1407,6 +1424,7 @@ 6C0C141113F2099B003A31B2 /* Cart.m in Sources */, 6C0C141413F20E98003A31B2 /* GameMode.m in Sources */, 6CC89DDF13F31413003704F7 /* TutorialMode.m in Sources */, + 6C39CFE513FC4635002B21AF /* JumpGameMode.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Classes/JumpGameMode.h b/Classes/JumpGameMode.h new file mode 100644 index 0000000..7b7dff4 --- /dev/null +++ b/Classes/JumpGameMode.h @@ -0,0 +1,21 @@ +// +// JumpGameMode.h +// Cart Collect +// +// Created by Starla Insigna on 8/17/11. +// Copyright 2011 Four Island. All rights reserved. +// + +#import "GameMode.h" + +@interface JumpGameMode : GameMode { + CCSprite* water; + int waterTick; + BOOL wave; + CGPoint gestureStartPoint; + int jumpTick; + BOOL jump; + float swipeVarianceModifer; +} + +@end diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m new file mode 100644 index 0000000..e8c8c7e --- /dev/null +++ b/Classes/JumpGameMode.m @@ -0,0 +1,110 @@ +// +// JumpGameMode.m +// Cart Collect +// +// Created by Starla Insigna on 8/17/11. +// Copyright 2011 Four Island. All rights reserved. +// + +#import "JumpGameMode.h" + +#define kMinimumGestureLength 25 +#define kMaximumVariance 5 + +@implementation JumpGameMode + +- (id)init +{ + self = [super init]; + + if (nil != self) + { + water = [CCSprite spriteWithFile:@"water.png"]; + water.position = ccp(240, -80); + [self addChild:water]; + + self.isTouchEnabled = YES; + + waterTick = 0; + wave = NO; + } + + return self; +} + +- (void)onEnterTransitionDidFinish +{ + [super onEnterTransitionDidFinish]; + + [self scheduleDelayedAction:^{ + wave = YES; + } delay:3.0f]; +} + +- (void)tick:(ccTime)dt +{ + [super tick:dt]; + + if (wave) + { + waterTick++; + + water.position = ccp(240, 160 * sin(waterTick / (36 * M_PI)) - 80); + + if (waterTick == 180) + { + wave = NO; + + [self scheduleDelayedAction:^{ + wave = YES; + } delay:10.0f]; + } else if (waterTick == 360) + { + wave = NO; + waterTick = 0; + } + } + + if (jump) + { + jumpTick++; + + cart.sprite.position = ccp(cart.sprite.position.x, MAX(100 * sin(jumpTick / (2 * M_PI)) + 22, water.position.y+80+11)); + + if (jumpTick == 20) + { + jump = NO; + jumpTick = 0; + } + } else { + cart.sprite.position = ccp(cart.sprite.position.x, MAX(22, water.position.y+80+11)); + } +} + +- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event +{ + UITouch* touch = [touches anyObject]; + gestureStartPoint = [touch locationInView:nil]; +} + +- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event +{ + UITouch* touch = [touches anyObject]; + CGPoint gestureCurrentPosition = [touch locationInView:nil]; + CGFloat deltaX = fabsf(gestureStartPoint.x - gestureCurrentPosition.x); + CGFloat deltaY = fabsf(gestureStartPoint.y - gestureCurrentPosition.y); + + if ((deltaX >= kMinimumGestureLength) && (deltaY <= kMaximumVariance*swipeVarianceModifer) && (cart.sprite.position.y == 22)) + { + jump = YES; + } +} + +- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration +{ + [super accelerometer:accelerometer didAccelerate:acceleration]; + + swipeVarianceModifer = MAX(1,(fabsf(acceleration.y) * 480)/kMaximumVariance); +} + +@end diff --git a/Classes/MainMenuLayer.h b/Classes/MainMenuLayer.h index e43c5e1..c7e3348 100755 --- a/Classes/MainMenuLayer.h +++ b/Classes/MainMenuLayer.h @@ -17,6 +17,7 @@ - (id)init; - (void)newgame; - (void)tutorial; +- (void)jump; - (void)highscores; @end diff --git a/Classes/MainMenuLayer.m b/Classes/MainMenuLayer.m index 537c5c1..cf4b8cf 100755 --- a/Classes/MainMenuLayer.m +++ b/Classes/MainMenuLayer.m @@ -11,6 +11,7 @@ #import "ClassicGameMode.h" #import "TutorialMode.h" #import "Cart_CollectAppDelegate.h" +#import "JumpGameMode.h" @implementation MainMenuLayer @@ -46,9 +47,10 @@ CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"newgame.png" selectedImage:@"newgame2.png" target:self selector:@selector(newgame)]; CCMenuItemImage* tutorialMenuItem = [CCMenuItemImage itemFromNormalImage:@"tutorial.png" selectedImage:@"tutorial2.png" target:self selector:@selector(tutorial)]; + CCMenuItemImage* jumpMenuItem = [CCMenuItemImage itemFromNormalImage:@"jump.png" selectedImage:@"jump2.png" target:self selector:@selector(jump)]; CCMenuItemImage* highscoresMenuItem = [CCMenuItemImage itemFromNormalImage:@"highscores.png" selectedImage:@"highscores2.png" target:self selector:@selector(highscores)]; - CCMenu* menu = [CCMenu menuWithItems:newgameMenuItem, tutorialMenuItem, highscoresMenuItem, nil]; + CCMenu* menu = [CCMenu menuWithItems:newgameMenuItem, tutorialMenuItem, jumpMenuItem, highscoresMenuItem, nil]; [menu alignItemsVertically]; menu.position = ccp(240, 100); [self addChild:menu]; @@ -67,6 +69,11 @@ [[CCDirector sharedDirector] replaceScene:[TutorialMode scene]]; } +- (void)jump +{ + [[CCDirector sharedDirector] replaceScene:[JumpGameMode scene]]; +} + - (void)highscores { HighscoreListController* listController = [[HighscoreListController alloc] initWithStyle:UITableViewStylePlain]; diff --git a/Resources/jump.png b/Resources/jump.png new file mode 100644 index 0000000..4546088 Binary files /dev/null and b/Resources/jump.png differ diff --git a/Resources/jump2.png b/Resources/jump2.png new file mode 100644 index 0000000..3e83046 Binary files /dev/null and b/Resources/jump2.png differ diff --git a/Resources/water.png b/Resources/water.png new file mode 100644 index 0000000..bf4ff13 Binary files /dev/null and b/Resources/water.png differ -- cgit 1.4.1 From 6b9c8afd0e4a49efffd504378f1db34264928250 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Wed, 17 Aug 2011 20:29:16 -0400 Subject: Improved jumping gesture detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, when determining if the player had swiped upward for a jump in the Jump game mode, the game checked that the player had touched and moved upward a certain amount, with less than a certain amount of variance in horizontal position. However, this did not work well with the deeply-ingrained rotation aspect of the game, so the game was programmed to widen this allowed horizontal variance when the device was rotated. This really did not work too well, so now the game calculates an "expected" angle from the bottom of the screen based on rotation that it determines to point upward and also the angle of the player's swipe from the bottom of the screen. If the swipe angle falls within 45 degrees (π/4 radians) of the expected angle, the cart jumps. Really quite awesome if you ask me. :P Refs #204 --- Classes/JumpGameMode.h | 2 +- Classes/JumpGameMode.m | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Classes/JumpGameMode.h b/Classes/JumpGameMode.h index 7b7dff4..9753720 100644 --- a/Classes/JumpGameMode.h +++ b/Classes/JumpGameMode.h @@ -15,7 +15,7 @@ CGPoint gestureStartPoint; int jumpTick; BOOL jump; - float swipeVarianceModifer; + float expectedAngle; } @end diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m index e8c8c7e..e30be6a 100644 --- a/Classes/JumpGameMode.m +++ b/Classes/JumpGameMode.m @@ -8,8 +8,7 @@ #import "JumpGameMode.h" -#define kMinimumGestureLength 25 -#define kMaximumVariance 5 +#define kMinimumGestureLength 50 @implementation JumpGameMode @@ -91,10 +90,10 @@ { UITouch* touch = [touches anyObject]; CGPoint gestureCurrentPosition = [touch locationInView:nil]; - CGFloat deltaX = fabsf(gestureStartPoint.x - gestureCurrentPosition.x); - CGFloat deltaY = fabsf(gestureStartPoint.y - gestureCurrentPosition.y); + CGFloat angle = atan2f(gestureCurrentPosition.y - gestureStartPoint.y, gestureCurrentPosition.x - gestureStartPoint.x); + CGFloat distance = sqrt(powf((gestureCurrentPosition.x - gestureStartPoint.x),2) + powf((gestureCurrentPosition.y - gestureStartPoint.y),2)); - if ((deltaX >= kMinimumGestureLength) && (deltaY <= kMaximumVariance*swipeVarianceModifer) && (cart.sprite.position.y == 22)) + if ((distance >= kMinimumGestureLength) && (angle >= expectedAngle - M_PI_4) && (angle <= expectedAngle + M_PI_4) && (cart.sprite.position.y == 22)) { jump = YES; } @@ -104,7 +103,7 @@ { [super accelerometer:accelerometer didAccelerate:acceleration]; - swipeVarianceModifer = MAX(1,(fabsf(acceleration.y) * 480)/kMaximumVariance); + expectedAngle = acceleration.y*M_PI_2; } @end -- cgit 1.4.1