summary refs log tree commit diff stats
path: root/Classes/Cart.m
diff options
context:
space:
mode:
Diffstat (limited to 'Classes/Cart.m')
-rw-r--r--Classes/Cart.m23
1 files changed, 22 insertions, 1 deletions
diff --git a/Classes/Cart.m b/Classes/Cart.m index 45c370c..cfe7ee7 100644 --- a/Classes/Cart.m +++ b/Classes/Cart.m
@@ -10,7 +10,7 @@
10 10
11@implementation Cart 11@implementation Cart
12 12
13@synthesize sprite, immobile; 13@synthesize sprite, immobile, delegate, falling;
14 14
15- (id)initWithSprite:(CCSprite*)m_sprite 15- (id)initWithSprite:(CCSprite*)m_sprite
16{ 16{
@@ -20,6 +20,7 @@
20 { 20 {
21 sprite = m_sprite; 21 sprite = m_sprite;
22 immobile = NO; 22 immobile = NO;
23 falling = NO;
23 } 24 }
24 25
25 return self; 26 return self;
@@ -30,7 +31,27 @@
30 if (!immobile) 31 if (!immobile)
31 { 32 {
32 // Move the cart based on acceleration gathered from accelerometer 33 // Move the cart based on acceleration gathered from accelerometer
34 CGPoint prevLoc = sprite.position;
33 sprite.position = ccp(MIN(MAX(sprite.position.x+accelX, 16),464), sprite.position.y); 35 sprite.position = ccp(MIN(MAX(sprite.position.x+accelX, 16),464), sprite.position.y);
36
37 if ((delegate != nil) && ([delegate respondsToSelector:@selector(cartIsObstructed:)]))
38 {
39 if ([delegate cartIsObstructed:self])
40 {
41 sprite.position = prevLoc;
42 }
43 }
44
45 if (falling)
46 {
47 if ((delegate != nil) && ([delegate respondsToSelector:@selector(cartShouldFall:)]))
48 {
49 int bottom = [delegate cartShouldFall:self];
50 sprite.position = ccp(sprite.position.x, MAX(bottom, sprite.position.y-6));
51 } else {
52 NSLog(@"Falling is set on a cart without a compatible game mode.");
53 }
54 }
34 } 55 }
35} 56}
36 57