blob: 45c370c581120107342db79b493c981c61f246bc (
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
|
//
// 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, immobile;
- (id)initWithSprite:(CCSprite*)m_sprite
{
self = [super init];
if (nil != self)
{
sprite = m_sprite;
immobile = NO;
}
return self;
}
- (void)tick
{
if (!immobile)
{
// 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
|