diff options
Diffstat (limited to 'Classes/GameMode.m')
-rw-r--r-- | Classes/GameMode.m | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/Classes/GameMode.m b/Classes/GameMode.m new file mode 100644 index 0000000..6fa31e5 --- /dev/null +++ b/Classes/GameMode.m | |||
@@ -0,0 +1,78 @@ | |||
1 | // | ||
2 | // GameMode.m | ||
3 | // Cart Collect | ||
4 | // | ||
5 | // Created by Starla Insigna on 8/9/11. | ||
6 | // Copyright 2011 Four Island. All rights reserved. | ||
7 | // | ||
8 | |||
9 | #import "GameMode.h" | ||
10 | #import "FallingObject.h" | ||
11 | |||
12 | @implementation GameMode | ||
13 | |||
14 | @synthesize cart, score, lives; | ||
15 | |||
16 | + (CCScene*)scene | ||
17 | { | ||
18 | CCScene* scene = [CCScene node]; | ||
19 | |||
20 | GameMode* layer = [self node]; | ||
21 | layer.tag = GAME_LAYER; | ||
22 | [scene addChild:layer]; | ||
23 | |||
24 | scene.tag = GAME_SCENE; | ||
25 | |||
26 | return scene; | ||
27 | } | ||
28 | |||
29 | - (id)init | ||
30 | { | ||
31 | self = [super init]; | ||
32 | |||
33 | if (nil != self) | ||
34 | { | ||
35 | isAccelerometerEnabled_ = YES; | ||
36 | |||
37 | objects = [[NSMutableSet alloc] init]; | ||
38 | } | ||
39 | |||
40 | return self; | ||
41 | } | ||
42 | |||
43 | - (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration | ||
44 | { | ||
45 | [cart accelerometer:accelerometer didAccelerate:acceleration]; | ||
46 | } | ||
47 | |||
48 | - (void)onEnter | ||
49 | { | ||
50 | [super onEnter]; | ||
51 | |||
52 | [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 60)]; | ||
53 | [self schedule:@selector(tick:) interval:1.0f/60.0f]; | ||
54 | } | ||
55 | |||
56 | - (void)tick:(ccTime)dt | ||
57 | { | ||
58 | [cart tick]; | ||
59 | |||
60 | for (FallingObject* object in objects) | ||
61 | { | ||
62 | if ([object tick]) | ||
63 | { | ||
64 | [object retain]; | ||
65 | [self removeChild:object.sprite cleanup:YES]; | ||
66 | [objects removeObject:object]; | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | |||
71 | - (void)dealloc | ||
72 | { | ||
73 | [objects release]; | ||
74 | [cart release]; | ||
75 | [super dealloc]; | ||
76 | } | ||
77 | |||
78 | @end | ||