summary refs log tree commit diff stats
path: root/Classes/FallingObject.m
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-08-09 21:36:09 -0400
committerStarla Insigna <starla4444@gmail.com>2011-08-09 21:36:09 -0400
commit002dc99a071a4a8f7d2afc15d1fdf2ae0312faed (patch)
tree82808d85a131ed0f970b374828a3e80ee1fb8d35 /Classes/FallingObject.m
parent1ed37fda409479769c8d110aa22d5dadc9d2cb85 (diff)
downloadcartcollect-002dc99a071a4a8f7d2afc15d1fdf2ae0312faed.tar.gz
cartcollect-002dc99a071a4a8f7d2afc15d1fdf2ae0312faed.tar.bz2
cartcollect-002dc99a071a4a8f7d2afc15d1fdf2ae0312faed.zip
Abstracted a lot of GameLayer's functionality out
In order to prepare for tutorial mode (and eventually, the other game modes), a lot of GameLayer's functionality (reading the accelerometer, moving the cart, moving falling objects, reacting to collisions…) has been abstracted out to FallingObject and subclasses of FallingObject, as well as a new Cart class, and GameMode, a new superclass of GameLayer. The only things that were not abstracted out that probably will be in the future are the pause functionality and the tutorial bubble functionality (which will in fact be moved to the tutorial mode class).

A lot of work was also done to cut down on compiler warnings and a lot of #imports were moved from header files to implementation files because I realized THAT'S HOW YOU'RE SUPPOSED TO DO IT.

Refs #193
Diffstat (limited to 'Classes/FallingObject.m')
-rwxr-xr-xClasses/FallingObject.m50
1 files changed, 49 insertions, 1 deletions
diff --git a/Classes/FallingObject.m b/Classes/FallingObject.m index 297b426..515948e 100755 --- a/Classes/FallingObject.m +++ b/Classes/FallingObject.m
@@ -7,7 +7,7 @@
7// 7//
8 8
9#import "FallingObject.h" 9#import "FallingObject.h"
10 10#import "GameMode.h"
11 11
12@implementation FallingObject 12@implementation FallingObject
13 13
@@ -25,6 +25,54 @@
25 return self; 25 return self;
26} 26}
27 27
28- (BOOL)tick
29{
30 GameMode* gameLayer = ((GameMode*) sprite.parent);
31
32 // Move objects down
33 sprite.position = ccp(sprite.position.x, sprite.position.y-weight);
34
35 // Cart collision detection
36 CGSize first = [gameLayer.cart.sprite boundingBox].size;
37 CGSize second = [sprite boundingBox].size;
38
39 if (gameLayer.cart.sprite.position.x > (sprite.position.x - second.width/2 - first.width/2))
40 {
41 if (gameLayer.cart.sprite.position.x < (sprite.position.x + second.width/2 + first.width/2))
42 {
43 if (gameLayer.cart.sprite.position.y > (sprite.position.y - second.height/2 - first.height/2))
44 {
45 if (gameLayer.cart.sprite.position.y < (sprite.position.y + second.height/2 + first.height/2))
46 {
47 [self collideWithCart];
48
49 return YES;
50 }
51 }
52 }
53 }
54
55 // Collision detection with floor
56 if (sprite.position.y - (sprite.contentSize.height/2) < 0)
57 {
58 [self collideWithFloor];
59
60 return YES;
61 }
62
63 return NO;
64}
65
66- (void)collideWithCart
67{
68
69}
70
71- (void)collideWithFloor
72{
73
74}
75
28- (void)dealloc 76- (void)dealloc
29{ 77{
30 [sprite release]; 78 [sprite release];