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 --- Classes/JumpGameMode.m | 110 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 Classes/JumpGameMode.m (limited to 'Classes/JumpGameMode.m') 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 -- cgit 1.4.1