summary refs log tree commit diff stats
path: root/Classes/JumpGameMode.m
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-08-24 12:09:32 -0400
committerStarla Insigna <starla4444@gmail.com>2011-08-24 12:09:32 -0400
commit55c94570ae9b7a31167705350dde0a4162058f9b (patch)
tree185b9608bbdc157990aa570e449324ffb33be59d /Classes/JumpGameMode.m
parentd8f00310e486aed1ab289a0f816acec571193c32 (diff)
parent6b9c8afd0e4a49efffd504378f1db34264928250 (diff)
downloadcartcollect-55c94570ae9b7a31167705350dde0a4162058f9b.tar.gz
cartcollect-55c94570ae9b7a31167705350dde0a4162058f9b.tar.bz2
cartcollect-55c94570ae9b7a31167705350dde0a4162058f9b.zip
Merged in changes from default branch
Diffstat (limited to 'Classes/JumpGameMode.m')
-rw-r--r--Classes/JumpGameMode.m109
1 files changed, 109 insertions, 0 deletions
diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m new file mode 100644 index 0000000..e30be6a --- /dev/null +++ b/Classes/JumpGameMode.m
@@ -0,0 +1,109 @@
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 50
12
13@implementation JumpGameMode
14
15- (id)init
16{
17 self = [super init];
18
19 if (nil != self)
20 {
21 water = [CCSprite spriteWithFile:@"water.png"];
22 water.position = ccp(240, -80);
23 [self addChild:water];
24
25 self.isTouchEnabled = YES;
26
27 waterTick = 0;
28 wave = NO;
29 }
30
31 return self;
32}
33
34- (void)onEnterTransitionDidFinish
35{
36 [super onEnterTransitionDidFinish];
37
38 [self scheduleDelayedAction:^{
39 wave = YES;
40 } delay:3.0f];
41}
42
43- (void)tick:(ccTime)dt
44{
45 [super tick:dt];
46
47 if (wave)
48 {
49 waterTick++;
50
51 water.position = ccp(240, 160 * sin(waterTick / (36 * M_PI)) - 80);
52
53 if (waterTick == 180)
54 {
55 wave = NO;
56
57 [self scheduleDelayedAction:^{
58 wave = YES;
59 } delay:10.0f];
60 } else if (waterTick == 360)
61 {
62 wave = NO;
63 waterTick = 0;
64 }
65 }
66
67 if (jump)
68 {
69 jumpTick++;
70
71 cart.sprite.position = ccp(cart.sprite.position.x, MAX(100 * sin(jumpTick / (2 * M_PI)) + 22, water.position.y+80+11));
72
73 if (jumpTick == 20)
74 {
75 jump = NO;
76 jumpTick = 0;
77 }
78 } else {
79 cart.sprite.position = ccp(cart.sprite.position.x, MAX(22, water.position.y+80+11));
80 }
81}
82
83- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
84{
85 UITouch* touch = [touches anyObject];
86 gestureStartPoint = [touch locationInView:nil];
87}
88
89- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
90{
91 UITouch* touch = [touches anyObject];
92 CGPoint gestureCurrentPosition = [touch locationInView:nil];
93 CGFloat angle = atan2f(gestureCurrentPosition.y - gestureStartPoint.y, gestureCurrentPosition.x - gestureStartPoint.x);
94 CGFloat distance = sqrt(powf((gestureCurrentPosition.x - gestureStartPoint.x),2) + powf((gestureCurrentPosition.y - gestureStartPoint.y),2));
95
96 if ((distance >= kMinimumGestureLength) && (angle >= expectedAngle - M_PI_4) && (angle <= expectedAngle + M_PI_4) && (cart.sprite.position.y == 22))
97 {
98 jump = YES;
99 }
100}
101
102- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
103{
104 [super accelerometer:accelerometer didAccelerate:acceleration];
105
106 expectedAngle = acceleration.y*M_PI_2;
107}
108
109@end