summary refs log tree commit diff stats
path: root/Classes/JumpGameMode.m
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-08-17 19:54:25 -0400
committerStarla Insigna <starla4444@gmail.com>2011-08-17 19:54:25 -0400
commit4d94802036a53e6ec246ab0abac17fd76d17c885 (patch)
tree7e19df50363755707b7e7907117888146abc2377 /Classes/JumpGameMode.m
parentfee8d3506b4c2f6d5933a85181de9bb8e6f5fcc4 (diff)
downloadcartcollect-4d94802036a53e6ec246ab0abac17fd76d17c885.tar.gz
cartcollect-4d94802036a53e6ec246ab0abac17fd76d17c885.tar.bz2
cartcollect-4d94802036a53e6ec246ab0abac17fd76d17c885.zip
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
Diffstat (limited to 'Classes/JumpGameMode.m')
-rw-r--r--Classes/JumpGameMode.m110
1 files changed, 110 insertions, 0 deletions
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 @@
1//
2// JumpGameMode.m
3// Cart Collect
4//
5// Created by Starla Insigna on 8/17/11.
6// Copyright 2011 Four Island. All rights reserved.
7//
8
9#import "JumpGameMode.h"
10
11#define kMinimumGestureLength 25
12#define kMaximumVariance 5
13
14@implementation JumpGameMode
15
16- (id)init
17{
18 self = [super init];
19
20 if (nil != self)
21 {
22 water = [CCSprite spriteWithFile:@"water.png"];
23 water.position = ccp(240, -80);
24 [self addChild:water];
25
26 self.isTouchEnabled = YES;
27
28 waterTick = 0;
29 wave = NO;
30 }
31
32 return self;
33}
34
35- (void)onEnterTransitionDidFinish
36{
37 [super onEnterTransitionDidFinish];
38
39 [self scheduleDelayedAction:^{
40 wave = YES;
41 } delay:3.0f];
42}
43
44- (void)tick:(ccTime)dt
45{
46 [super tick:dt];
47
48 if (wave)
49 {
50 waterTick++;
51
52 water.position = ccp(240, 160 * sin(waterTick / (36 * M_PI)) - 80);
53
54 if (waterTick == 180)
55 {
56 wave = NO;
57
58 [self scheduleDelayedAction:^{
59 wave = YES;
60 } delay:10.0f];
61 } else if (waterTick == 360)
62 {
63 wave = NO;
64 waterTick = 0;
65 }
66 }
67
68 if (jump)
69 {
70 jumpTick++;
71
72 cart.sprite.position = ccp(cart.sprite.position.x, MAX(100 * sin(jumpTick / (2 * M_PI)) + 22, water.position.y+80+11));
73
74 if (jumpTick == 20)
75 {
76 jump = NO;
77 jumpTick = 0;
78 }
79 } else {
80 cart.sprite.position = ccp(cart.sprite.position.x, MAX(22, water.position.y+80+11));
81 }
82}
83
84- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
85{
86 UITouch* touch = [touches anyObject];
87 gestureStartPoint = [touch locationInView:nil];
88}
89
90- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
91{
92 UITouch* touch = [touches anyObject];
93 CGPoint gestureCurrentPosition = [touch locationInView:nil];
94 CGFloat deltaX = fabsf(gestureStartPoint.x - gestureCurrentPosition.x);
95 CGFloat deltaY = fabsf(gestureStartPoint.y - gestureCurrentPosition.y);
96
97 if ((deltaX >= kMinimumGestureLength) && (deltaY <= kMaximumVariance*swipeVarianceModifer) && (cart.sprite.position.y == 22))
98 {
99 jump = YES;
100 }
101}
102
103- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
104{
105 [super accelerometer:accelerometer didAccelerate:acceleration];
106
107 swipeVarianceModifer = MAX(1,(fabsf(acceleration.y) * 480)/kMaximumVariance);
108}
109
110@end