diff options
author | Starla Insigna <starla4444@gmail.com> | 2011-08-17 19:54:25 -0400 |
---|---|---|
committer | Starla Insigna <starla4444@gmail.com> | 2011-08-17 19:54:25 -0400 |
commit | 4d94802036a53e6ec246ab0abac17fd76d17c885 (patch) | |
tree | 7e19df50363755707b7e7907117888146abc2377 /Classes | |
parent | fee8d3506b4c2f6d5933a85181de9bb8e6f5fcc4 (diff) | |
download | cartcollect-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')
-rw-r--r-- | Classes/JumpGameMode.h | 21 | ||||
-rw-r--r-- | Classes/JumpGameMode.m | 110 | ||||
-rwxr-xr-x | Classes/MainMenuLayer.h | 1 | ||||
-rwxr-xr-x | Classes/MainMenuLayer.m | 9 |
4 files changed, 140 insertions, 1 deletions
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 @@ | |||
1 | // | ||
2 | // JumpGameMode.h | ||
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 "GameMode.h" | ||
10 | |||
11 | @interface JumpGameMode : GameMode <CCStandardTouchDelegate> { | ||
12 | CCSprite* water; | ||
13 | int waterTick; | ||
14 | BOOL wave; | ||
15 | CGPoint gestureStartPoint; | ||
16 | int jumpTick; | ||
17 | BOOL jump; | ||
18 | float swipeVarianceModifer; | ||
19 | } | ||
20 | |||
21 | @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 @@ | |||
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 | ||
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 @@ | |||
17 | - (id)init; | 17 | - (id)init; |
18 | - (void)newgame; | 18 | - (void)newgame; |
19 | - (void)tutorial; | 19 | - (void)tutorial; |
20 | - (void)jump; | ||
20 | - (void)highscores; | 21 | - (void)highscores; |
21 | 22 | ||
22 | @end | 23 | @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 @@ | |||
11 | #import "ClassicGameMode.h" | 11 | #import "ClassicGameMode.h" |
12 | #import "TutorialMode.h" | 12 | #import "TutorialMode.h" |
13 | #import "Cart_CollectAppDelegate.h" | 13 | #import "Cart_CollectAppDelegate.h" |
14 | #import "JumpGameMode.h" | ||
14 | 15 | ||
15 | @implementation MainMenuLayer | 16 | @implementation MainMenuLayer |
16 | 17 | ||
@@ -46,9 +47,10 @@ | |||
46 | 47 | ||
47 | CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"newgame.png" selectedImage:@"newgame2.png" target:self selector:@selector(newgame)]; | 48 | CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"newgame.png" selectedImage:@"newgame2.png" target:self selector:@selector(newgame)]; |
48 | CCMenuItemImage* tutorialMenuItem = [CCMenuItemImage itemFromNormalImage:@"tutorial.png" selectedImage:@"tutorial2.png" target:self selector:@selector(tutorial)]; | 49 | CCMenuItemImage* tutorialMenuItem = [CCMenuItemImage itemFromNormalImage:@"tutorial.png" selectedImage:@"tutorial2.png" target:self selector:@selector(tutorial)]; |
50 | CCMenuItemImage* jumpMenuItem = [CCMenuItemImage itemFromNormalImage:@"jump.png" selectedImage:@"jump2.png" target:self selector:@selector(jump)]; | ||
49 | CCMenuItemImage* highscoresMenuItem = [CCMenuItemImage itemFromNormalImage:@"highscores.png" selectedImage:@"highscores2.png" target:self selector:@selector(highscores)]; | 51 | CCMenuItemImage* highscoresMenuItem = [CCMenuItemImage itemFromNormalImage:@"highscores.png" selectedImage:@"highscores2.png" target:self selector:@selector(highscores)]; |
50 | 52 | ||
51 | CCMenu* menu = [CCMenu menuWithItems:newgameMenuItem, tutorialMenuItem, highscoresMenuItem, nil]; | 53 | CCMenu* menu = [CCMenu menuWithItems:newgameMenuItem, tutorialMenuItem, jumpMenuItem, highscoresMenuItem, nil]; |
52 | [menu alignItemsVertically]; | 54 | [menu alignItemsVertically]; |
53 | menu.position = ccp(240, 100); | 55 | menu.position = ccp(240, 100); |
54 | [self addChild:menu]; | 56 | [self addChild:menu]; |
@@ -67,6 +69,11 @@ | |||
67 | [[CCDirector sharedDirector] replaceScene:[TutorialMode scene]]; | 69 | [[CCDirector sharedDirector] replaceScene:[TutorialMode scene]]; |
68 | } | 70 | } |
69 | 71 | ||
72 | - (void)jump | ||
73 | { | ||
74 | [[CCDirector sharedDirector] replaceScene:[JumpGameMode scene]]; | ||
75 | } | ||
76 | |||
70 | - (void)highscores | 77 | - (void)highscores |
71 | { | 78 | { |
72 | HighscoreListController* listController = [[HighscoreListController alloc] initWithStyle:UITableViewStylePlain]; | 79 | HighscoreListController* listController = [[HighscoreListController alloc] initWithStyle:UITableViewStylePlain]; |