summary refs log tree commit diff stats
path: root/Classes/GameMode.m
blob: 6fa31e5b97e01fa3e6a6f6af7008104fba5cb37f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
//  GameMode.m
//  Cart Collect
//
//  Created by Starla Insigna on 8/9/11.
//  Copyright 2011 Four Island. All rights reserved.
//

#import "GameMode.h"
#import "FallingObject.h"

@implementation GameMode

@synthesize cart, score, lives;

+ (CCScene*)scene
{
	CCScene* scene = [CCScene node];
		
	GameMode* layer = [self node];
    layer.tag = GAME_LAYER;
	[scene addChild:layer];
	
	scene.tag = GAME_SCENE;
	
	return scene;
}

- (id)init
{
    self = [super init];
    
    if (nil != self)
    {
        isAccelerometerEnabled_ = YES;
        
        objects = [[NSMutableSet alloc] init];
    }
    
    return self;
}

- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration
{	
	[cart accelerometer:accelerometer didAccelerate:acceleration];
}

- (void)onEnter
{
    [super onEnter];
    
    [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 60)];
    [self schedule:@selector(tick:) interval:1.0f/60.0f];
}

- (void)tick:(ccTime)dt
{
    [cart tick];
    
    for (FallingObject* object in objects)
	{
        if ([object tick])
        {
            [object retain];
            [self removeChild:object.sprite cleanup:YES];
            [objects removeObject:object];
        }
    }
}

- (void)dealloc
{
    [objects release];
    [cart release];
    [super dealloc];
}

@end