blob: 3046be3730ec5c1350fe448c751794aec95aa98e (
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
|
//
// Cart.m
// Cart Collect
//
// Created by Starla Insigna on 8/9/11.
// Copyright 2011 Four Island. All rights reserved.
//
#import "Cart.h"
@implementation Cart
@synthesize sprite;
- (id)initWithSprite:(CCSprite*)m_sprite
{
self = [super init];
if (nil != self)
{
sprite = m_sprite;
}
return self;
}
- (void)tick
{
// Move the cart based on acceleration gathered from accelerometer
sprite.position = ccp(MIN(MAX(sprite.position.x+accelX, 16),464), sprite.position.y);
}
- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration
{
static float prevY=0;
#define kFilterFactor 0.05f
float accelY = -((float) acceleration.y * kFilterFactor + (1- kFilterFactor)*prevY);
prevY = accelY;
accelX = accelY * 750;
}
@end
|