diff options
Diffstat (limited to 'Classes/Cart.m')
-rw-r--r-- | Classes/Cart.m | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Classes/Cart.m b/Classes/Cart.m new file mode 100644 index 0000000..3046be3 --- /dev/null +++ b/Classes/Cart.m | |||
@@ -0,0 +1,45 @@ | |||
1 | // | ||
2 | // Cart.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 "Cart.h" | ||
10 | |||
11 | @implementation Cart | ||
12 | |||
13 | @synthesize sprite; | ||
14 | |||
15 | - (id)initWithSprite:(CCSprite*)m_sprite | ||
16 | { | ||
17 | self = [super init]; | ||
18 | |||
19 | if (nil != self) | ||
20 | { | ||
21 | sprite = m_sprite; | ||
22 | } | ||
23 | |||
24 | return self; | ||
25 | } | ||
26 | |||
27 | - (void)tick | ||
28 | { | ||
29 | // Move the cart based on acceleration gathered from accelerometer | ||
30 | sprite.position = ccp(MIN(MAX(sprite.position.x+accelX, 16),464), sprite.position.y); | ||
31 | } | ||
32 | |||
33 | - (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration | ||
34 | { | ||
35 | static float prevY=0; | ||
36 | |||
37 | #define kFilterFactor 0.05f | ||
38 | |||
39 | float accelY = -((float) acceleration.y * kFilterFactor + (1- kFilterFactor)*prevY); | ||
40 | |||
41 | prevY = accelY; | ||
42 | accelX = accelY * 750; | ||
43 | } | ||
44 | |||
45 | @end | ||