summary refs log tree commit diff stats
path: root/Classes
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
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')
-rwxr-xr-xClasses/Bottle.h3
-rw-r--r--Classes/Cart.h22
-rw-r--r--Classes/Cart.m45
-rwxr-xr-xClasses/Cherry.h3
-rwxr-xr-xClasses/FallingObject.h3
-rwxr-xr-xClasses/FallingObject.m50
-rwxr-xr-xClasses/GameLayer.h23
-rwxr-xr-xClasses/GameLayer.m149
-rw-r--r--Classes/GameMode.h27
-rw-r--r--Classes/GameMode.m78
-rwxr-xr-xClasses/GameOverLayer.h5
-rwxr-xr-xClasses/GameOverLayer.m5
-rwxr-xr-xClasses/Highscore.h3
-rwxr-xr-xClasses/Highscore.m1
-rwxr-xr-xClasses/HighscoreListController.h3
-rwxr-xr-xClasses/HighscoreListController.m13
-rwxr-xr-xClasses/MainMenuLayer.h3
-rwxr-xr-xClasses/MainMenuLayer.m7
-rwxr-xr-xClasses/OneUp.m11
-rwxr-xr-xClasses/Rock.m12
-rw-r--r--[-rwxr-xr-x]Classes/ValuableObject.h8
-rw-r--r--Classes/ValuableObject.m46
22 files changed, 346 insertions, 174 deletions
diff --git a/Classes/Bottle.h b/Classes/Bottle.h index 37c41d5..71e94e9 100755 --- a/Classes/Bottle.h +++ b/Classes/Bottle.h
@@ -7,10 +7,9 @@
7// 7//
8 8
9#import <Foundation/Foundation.h> 9#import <Foundation/Foundation.h>
10#import "FallingObject.h"
11#import "ValuableObject.h" 10#import "ValuableObject.h"
12 11
13@interface Bottle : FallingObject <ValuableObject> { 12@interface Bottle : ValuableObject {
14 13
15} 14}
16 15
diff --git a/Classes/Cart.h b/Classes/Cart.h new file mode 100644 index 0000000..d708d73 --- /dev/null +++ b/Classes/Cart.h
@@ -0,0 +1,22 @@
1//
2// Cart.h
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 <Foundation/Foundation.h>
10#import "cocos2d.h"
11
12@interface Cart : NSObject {
13 CCSprite* sprite;
14 float accelX;
15}
16
17@property (readonly) CCSprite* sprite;
18- (id)initWithSprite:(CCSprite*)sprite;
19- (void)tick;
20- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration;
21
22@end
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
diff --git a/Classes/Cherry.h b/Classes/Cherry.h index 65437f5..0a7e450 100755 --- a/Classes/Cherry.h +++ b/Classes/Cherry.h
@@ -7,10 +7,9 @@
7// 7//
8 8
9#import <Foundation/Foundation.h> 9#import <Foundation/Foundation.h>
10#import "FallingObject.h"
11#import "ValuableObject.h" 10#import "ValuableObject.h"
12 11
13@interface Cherry : FallingObject <ValuableObject> { 12@interface Cherry : ValuableObject {
14 13
15} 14}
16 15
diff --git a/Classes/FallingObject.h b/Classes/FallingObject.h index a1ac56e..0bda787 100755 --- a/Classes/FallingObject.h +++ b/Classes/FallingObject.h
@@ -17,5 +17,8 @@
17@property (readonly) CCSprite* sprite; 17@property (readonly) CCSprite* sprite;
18@property (readonly) int weight; 18@property (readonly) int weight;
19- (id)init; 19- (id)init;
20- (BOOL)tick;
21- (void)collideWithCart;
22- (void)collideWithFloor;
20 23
21@end 24@end
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];
diff --git a/Classes/GameLayer.h b/Classes/GameLayer.h index e72b551..128cbf2 100755 --- a/Classes/GameLayer.h +++ b/Classes/GameLayer.h
@@ -8,30 +8,13 @@
8 8
9#import <Foundation/Foundation.h> 9#import <Foundation/Foundation.h>
10#import "cocos2d.h" 10#import "cocos2d.h"
11#import "FallingObject.h"
12#import "Cherry.h"
13#import "Bottle.h"
14#import "OneUp.h"
15#import "Rock.h"
16#import "GameOverLayer.h"
17#import "ValuableObject.h"
18#import "CocosDenshion.h"
19#import "SimpleAudioEngine.h"
20#import "TutorialBubble.h" 11#import "TutorialBubble.h"
21#import "MainMenuLayer.h" 12#import "GameMode.h"
22 13
23#define GAME_SCENE 436 14@interface GameLayer : GameMode {
24#define GAME_LAYER 437
25
26@interface GameLayer : CCLayer {
27 NSMutableSet* objects;
28 float accelX;
29 CCLabelBMFont* scoreLabel; 15 CCLabelBMFont* scoreLabel;
30 CCLabelBMFont* livesLabel; 16 CCLabelBMFont* livesLabel;
31 int score;
32 int lives;
33 float addSpeed; 17 float addSpeed;
34 CCSprite* cartSprite;
35 TutorialBubble* currentTutorial; 18 TutorialBubble* currentTutorial;
36 19
37 CCLayerColor* shadedLayer; 20 CCLayerColor* shadedLayer;
@@ -39,9 +22,7 @@
39} 22}
40 23
41@property (nonatomic,retain) TutorialBubble* currentTutorial; 24@property (nonatomic,retain) TutorialBubble* currentTutorial;
42+ (CCScene*)scene;
43- (id)init; 25- (id)init;
44- (void)updateLabels;
45- (void)pause; 26- (void)pause;
46- (void)unpause; 27- (void)unpause;
47- (void)mainmenu; 28- (void)mainmenu;
diff --git a/Classes/GameLayer.m b/Classes/GameLayer.m index 2ec8ef5..95bc83b 100755 --- a/Classes/GameLayer.m +++ b/Classes/GameLayer.m
@@ -7,109 +7,29 @@
7// 7//
8 8
9#import "GameLayer.h" 9#import "GameLayer.h"
10 10#import "FallingObject.h"
11#import "Cherry.h"
12#import "Bottle.h"
13#import "OneUp.h"
14#import "Rock.h"
15#import "GameOverLayer.h"
16#import "SimpleAudioEngine.h"
17#import "MainMenuLayer.h"
11 18
12@implementation GameLayer 19@implementation GameLayer
13 20
14@synthesize currentTutorial; 21@synthesize currentTutorial;
15 22
16+ (CCScene*)scene
17{
18 CCScene* scene = [CCScene node];
19
20 CCLayerColor* backgroundLayer = [CCLayerColor layerWithColor:ccc4(255, 255, 255, 255)];
21 [scene addChild:backgroundLayer];
22
23 GameLayer* layer = [GameLayer node];
24 layer.tag = GAME_LAYER;
25 [scene addChild:layer];
26
27 scene.tag = GAME_SCENE;
28
29 return scene;
30}
31
32- (void)tick:(ccTime)dt 23- (void)tick:(ccTime)dt
33{ 24{
34 // Move the cart based on acceleration gathered from accelerometer
35 cartSprite.position = ccp(MIN(MAX(cartSprite.position.x+accelX, 16),464), cartSprite.position.y);
36
37 int lastScore = score; 25 int lastScore = score;
38 26
39 for (FallingObject* object in objects) 27 [super tick:dt];
40 {
41 // Move objects down
42 object.sprite.position = ccp(object.sprite.position.x, object.sprite.position.y-object.weight);
43
44 // Cart collision detection
45 CGSize first = [cartSprite boundingBox].size;
46 CGSize second = [object.sprite boundingBox].size;
47
48 if (cartSprite.position.x > (object.sprite.position.x - second.width/2 - first.width/2))
49 {
50 if (cartSprite.position.x < (object.sprite.position.x + second.width/2 + first.width/2))
51 {
52 if (cartSprite.position.y > (object.sprite.position.y - second.height/2 - first.height/2))
53 {
54 if (cartSprite.position.y < (object.sprite.position.y + second.height/2 + first.height/2))
55 {
56 [object retain];
57 [objects removeObject:object];
58
59 // If a cart collides with an object, it's going to vanish no matter what
60 [object.sprite.parent removeChild:object.sprite cleanup:YES];
61
62 NSString* audioFile = nil;
63 if ([object isKindOfClass:[OneUp class]])
64 {
65 audioFile = [[NSBundle mainBundle] pathForResource:@"1up" ofType:@"wav"];
66 lives++;
67 } else if ([object isKindOfClass:[Rock class]])
68 {
69 audioFile = [[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"];
70 lives--;
71 } else if ([object conformsToProtocol:@protocol(ValuableObject)]) {
72 audioFile = [[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"];
73 score += [((FallingObject<ValuableObject>*)object) pointValue];
74 }
75
76 if (audioFile != nil)
77 {
78 [[SimpleAudioEngine sharedEngine] playEffect:audioFile];
79 }
80
81 [self updateLabels];
82
83 continue; // Don't check for collision with floor
84 }
85 }
86 }
87 }
88
89 // Collision detection with floor
90 if (object.sprite.position.y - (object.sprite.contentSize.height/2) < 0)
91 {
92 [object retain];
93 [objects removeObject:object];
94
95 [object.sprite.parent removeChild:object.sprite cleanup:YES];
96
97 if ([object conformsToProtocol:@protocol(ValuableObject)])
98 {
99 NSString* audioFile = [[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"];
100 [[SimpleAudioEngine sharedEngine] playEffect:audioFile];
101
102 lives--;
103
104 [self updateLabels];
105 }
106 }
107 }
108 28
109 if (lives == 0) 29 if (lives == 0)
110 { 30 {
111 [self unschedule:@selector(randomlyAddObject:)]; 31 [self unscheduleAllSelectors];
112 [self unschedule:@selector(tick:)]; 32
113 [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverLayer sceneWithScore:score]]]; 33 [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverLayer sceneWithScore:score]]];
114 } else if (score > lastScore) 34 } else if (score > lastScore)
115 { 35 {
@@ -237,20 +157,12 @@
237 backgroundImage.position = ccp(240, 160); 157 backgroundImage.position = ccp(240, 160);
238 [self addChild:backgroundImage z:0]; 158 [self addChild:backgroundImage z:0];
239 159
240 isAccelerometerEnabled_ = YES; 160 cart = [[Cart alloc] initWithSprite:[CCSprite spriteWithFile:@"cart.png"]];
241 161 cart.sprite.position = ccp(winWidth/2, 22);
242 //cart = [[Cart alloc] init]; 162 cart.sprite.scale = cartScale;
243 cartSprite = [CCSprite spriteWithFile:@"cart.png"]; 163 [self addChild:cart.sprite];
244 cartSprite.position = ccp(winWidth/2, 22); 164
245 cartSprite.scale = cartScale; 165 scoreLabel = [CCLabelBMFont labelWithString:@"Score: 0" fntFile:@"helvetica2.fnt"];
246 [self addChild:cartSprite];
247
248 objects = [[NSMutableSet alloc] init];
249
250 score = 0;
251 lives = 3;
252
253 scoreLabel = [CCLabelBMFont labelWithString:@"Score: 0" fntFile:@"helvetica2.fnt"];
254 scoreLabel.position = ccp(50, 300); 166 scoreLabel.position = ccp(50, 300);
255 [self addChild:scoreLabel]; 167 [self addChild:scoreLabel];
256 168
@@ -258,6 +170,9 @@
258 livesLabel.position = ccp(50, 280); 170 livesLabel.position = ccp(50, 280);
259 [self addChild:livesLabel]; 171 [self addChild:livesLabel];
260 172
173 score = 0;
174 lives = 3;
175
261 CCMenuItemImage* pauseButton = [CCMenuItemImage itemFromNormalImage:@"pause2.png" selectedImage:@"pause.png" target:self selector:@selector(pause)]; 176 CCMenuItemImage* pauseButton = [CCMenuItemImage itemFromNormalImage:@"pause2.png" selectedImage:@"pause.png" target:self selector:@selector(pause)];
262 CCMenu* pauseMenu = [CCMenu menuWithItems:pauseButton, nil]; 177 CCMenu* pauseMenu = [CCMenu menuWithItems:pauseButton, nil];
263 [pauseMenu setPosition:ccp(480-8-16, 320-8-16)]; 178 [pauseMenu setPosition:ccp(480-8-16, 320-8-16)];
@@ -273,27 +188,21 @@
273{ 188{
274 [super onEnter]; 189 [super onEnter];
275 190
276 [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 60)];
277 [self schedule:@selector(tick:) interval:1.0f/60.0f];
278 [self schedule:@selector(randomlyAddObject:) interval:addSpeed]; 191 [self schedule:@selector(randomlyAddObject:) interval:addSpeed];
279} 192}
280 193
281- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration 194- (void)setScore:(int)m_score
282{ 195{
283 static float prevY=0; 196 score = m_score;
284 197
285#define kFilterFactor 0.05f 198 [scoreLabel setString:[NSString stringWithFormat:@"Score: %d", score]];
286
287 float accelY = -((float) acceleration.y * kFilterFactor + (1- kFilterFactor)*prevY);
288
289 prevY = accelY;
290 accelX = accelY * 750;
291} 199}
292 200
293- (void)updateLabels 201- (void)setLives:(int)m_lives
294{ 202{
295 [scoreLabel setString:[NSString stringWithFormat:@"Score: %d", score]]; 203 lives = m_lives;
296 [livesLabel setString:[NSString stringWithFormat:@"Lives: %d", lives]]; 204
205 [livesLabel setString:[NSString stringWithFormat:@"Lives: %d", lives]];
297} 206}
298 207
299- (void)pause 208- (void)pause
diff --git a/Classes/GameMode.h b/Classes/GameMode.h new file mode 100644 index 0000000..bd47c90 --- /dev/null +++ b/Classes/GameMode.h
@@ -0,0 +1,27 @@
1//
2// GameMode.h
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 "CCLayer.h"
10#import "Cart.h"
11
12#define GAME_SCENE 436
13#define GAME_LAYER 437
14
15@interface GameMode : CCLayer {
16 NSMutableSet* objects;
17 int score;
18 int lives;
19 Cart* cart;
20}
21
22@property (readonly) Cart* cart;
23@property (assign) int score;
24@property (assign) int lives;
25- (void)tick:(ccTime)dt;
26
27@end
diff --git a/Classes/GameMode.m b/Classes/GameMode.m new file mode 100644 index 0000000..6fa31e5 --- /dev/null +++ b/Classes/GameMode.m
@@ -0,0 +1,78 @@
1//
2// GameMode.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 "GameMode.h"
10#import "FallingObject.h"
11
12@implementation GameMode
13
14@synthesize cart, score, lives;
15
16+ (CCScene*)scene
17{
18 CCScene* scene = [CCScene node];
19
20 GameMode* layer = [self node];
21 layer.tag = GAME_LAYER;
22 [scene addChild:layer];
23
24 scene.tag = GAME_SCENE;
25
26 return scene;
27}
28
29- (id)init
30{
31 self = [super init];
32
33 if (nil != self)
34 {
35 isAccelerometerEnabled_ = YES;
36
37 objects = [[NSMutableSet alloc] init];
38 }
39
40 return self;
41}
42
43- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration
44{
45 [cart accelerometer:accelerometer didAccelerate:acceleration];
46}
47
48- (void)onEnter
49{
50 [super onEnter];
51
52 [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 60)];
53 [self schedule:@selector(tick:) interval:1.0f/60.0f];
54}
55
56- (void)tick:(ccTime)dt
57{
58 [cart tick];
59
60 for (FallingObject* object in objects)
61 {
62 if ([object tick])
63 {
64 [object retain];
65 [self removeChild:object.sprite cleanup:YES];
66 [objects removeObject:object];
67 }
68 }
69}
70
71- (void)dealloc
72{
73 [objects release];
74 [cart release];
75 [super dealloc];
76}
77
78@end
diff --git a/Classes/GameOverLayer.h b/Classes/GameOverLayer.h index ea533ac..c800e82 100755 --- a/Classes/GameOverLayer.h +++ b/Classes/GameOverLayer.h
@@ -8,11 +8,6 @@
8 8
9#import <Foundation/Foundation.h> 9#import <Foundation/Foundation.h>
10#import "cocos2d.h" 10#import "cocos2d.h"
11#import "Cart_CollectAppDelegate.h"
12#import <sqlite3.h>
13#import "cocoslive.h"
14
15@class MainMenuLayer;
16 11
17@interface GameOverLayer : CCLayer <UITextFieldDelegate, UIAlertViewDelegate> { 12@interface GameOverLayer : CCLayer <UITextFieldDelegate, UIAlertViewDelegate> {
18 UILabel* scoreField; 13 UILabel* scoreField;
diff --git a/Classes/GameOverLayer.m b/Classes/GameOverLayer.m index 65b11e1..9f58f01 100755 --- a/Classes/GameOverLayer.m +++ b/Classes/GameOverLayer.m
@@ -7,7 +7,10 @@
7// 7//
8 8
9#import "GameOverLayer.h" 9#import "GameOverLayer.h"
10 10#import "Cart_CollectAppDelegate.h"
11#import <sqlite3.h>
12#import "cocoslive.h"
13#import "MainMenuLayer.h"
11 14
12@implementation GameOverLayer 15@implementation GameOverLayer
13 16
diff --git a/Classes/Highscore.h b/Classes/Highscore.h index 4cab75f..bc6a8fb 100755 --- a/Classes/Highscore.h +++ b/Classes/Highscore.h
@@ -7,9 +7,6 @@
7// 7//
8 8
9#import <Foundation/Foundation.h> 9#import <Foundation/Foundation.h>
10#import <sqlite3.h>
11#import "Cart_CollectAppDelegate.h"
12#import "cocoslive.h"
13 10
14@interface Highscore : NSObject { 11@interface Highscore : NSObject {
15 NSString* name; 12 NSString* name;
diff --git a/Classes/Highscore.m b/Classes/Highscore.m index 7239cca..20ce56f 100755 --- a/Classes/Highscore.m +++ b/Classes/Highscore.m
@@ -8,7 +8,6 @@
8 8
9#import "Highscore.h" 9#import "Highscore.h"
10 10
11
12@implementation Highscore 11@implementation Highscore
13 12
14@synthesize name, score, date; 13@synthesize name, score, date;
diff --git a/Classes/HighscoreListController.h b/Classes/HighscoreListController.h index f673609..7b0069d 100755 --- a/Classes/HighscoreListController.h +++ b/Classes/HighscoreListController.h
@@ -7,9 +7,6 @@
7// 7//
8 8
9#import <UIKit/UIKit.h> 9#import <UIKit/UIKit.h>
10#import "Highscore.h"
11#import "cocoslive.h"
12#import "RootViewController.h"
13 10
14@interface HighscoreListController : UITableViewController { 11@interface HighscoreListController : UITableViewController {
15 UINavigationBar* navigationBar; 12 UINavigationBar* navigationBar;
diff --git a/Classes/HighscoreListController.m b/Classes/HighscoreListController.m index 4d108e4..932b147 100755 --- a/Classes/HighscoreListController.m +++ b/Classes/HighscoreListController.m
@@ -7,7 +7,11 @@
7// 7//
8 8
9#import "HighscoreListController.h" 9#import "HighscoreListController.h"
10 10#import "Highscore.h"
11#import "RootViewController.h"
12#import "cocoslive.h"
13#import <sqlite3.h>
14#import "Cart_CollectAppDelegate.h"
11 15
12@implementation HighscoreListController 16@implementation HighscoreListController
13 17
@@ -290,9 +294,10 @@
290 294
291- (void)back 295- (void)back
292{ 296{
293 RootViewController* viewController = [[[UIApplication sharedApplication] delegate] viewController]; 297 Cart_CollectAppDelegate* appDelegate = ((Cart_CollectAppDelegate*) [[UIApplication sharedApplication] delegate]);
294 [[[[UIApplication sharedApplication] delegate] window] setRootViewController:nil]; 298 RootViewController* viewController = [appDelegate viewController];
295 [[[[UIApplication sharedApplication] delegate] window] addSubview:viewController.view]; 299 [[appDelegate window] setRootViewController:nil];
300 [[appDelegate window] addSubview:viewController.view];
296} 301}
297 302
298- (void)switchLists:(id)sender 303- (void)switchLists:(id)sender
diff --git a/Classes/MainMenuLayer.h b/Classes/MainMenuLayer.h index fc4f82f..d8483b3 100755 --- a/Classes/MainMenuLayer.h +++ b/Classes/MainMenuLayer.h
@@ -8,9 +8,6 @@
8 8
9#import <Foundation/Foundation.h> 9#import <Foundation/Foundation.h>
10#import "cocos2d.h" 10#import "cocos2d.h"
11#import "HighscoreListController.h"
12
13@class GameLayer;
14 11
15@interface MainMenuLayer : CCLayer { 12@interface MainMenuLayer : CCLayer {
16 13
diff --git a/Classes/MainMenuLayer.m b/Classes/MainMenuLayer.m index ac7f4a7..11cffd7 100755 --- a/Classes/MainMenuLayer.m +++ b/Classes/MainMenuLayer.m
@@ -7,7 +7,9 @@
7// 7//
8 8
9#import "MainMenuLayer.h" 9#import "MainMenuLayer.h"
10 10#import "HighscoreListController.h"
11#import "GameLayer.h"
12#import "Cart_CollectAppDelegate.h"
11 13
12@implementation MainMenuLayer 14@implementation MainMenuLayer
13 15
@@ -61,7 +63,8 @@
61- (void)highscores 63- (void)highscores
62{ 64{
63 HighscoreListController* listController = [[HighscoreListController alloc] initWithStyle:UITableViewStylePlain]; 65 HighscoreListController* listController = [[HighscoreListController alloc] initWithStyle:UITableViewStylePlain];
64 [[[[UIApplication sharedApplication] delegate] window] setRootViewController:listController]; 66 Cart_CollectAppDelegate* appDelegate = ((Cart_CollectAppDelegate*) [[UIApplication sharedApplication] delegate]);
67 [[appDelegate window] setRootViewController:listController];
65 [listController release]; 68 [listController release];
66} 69}
67 70
diff --git a/Classes/OneUp.m b/Classes/OneUp.m index e09935c..9e0d4f0 100755 --- a/Classes/OneUp.m +++ b/Classes/OneUp.m
@@ -7,7 +7,8 @@
7// 7//
8 8
9#import "OneUp.h" 9#import "OneUp.h"
10 10#import "GameMode.h"
11#import "SimpleAudioEngine.h"
11 12
12@implementation OneUp 13@implementation OneUp
13 14
@@ -24,4 +25,12 @@
24 return self; 25 return self;
25} 26}
26 27
28- (void)collideWithCart
29{
30 GameMode* gameLayer = ((GameMode*) sprite.parent);
31 [gameLayer setLives:gameLayer.lives+1];
32
33 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"1up" ofType:@"wav"]];
34}
35
27@end 36@end
diff --git a/Classes/Rock.m b/Classes/Rock.m index a3b3b9e..aac1aaf 100755 --- a/Classes/Rock.m +++ b/Classes/Rock.m
@@ -7,7 +7,8 @@
7// 7//
8 8
9#import "Rock.h" 9#import "Rock.h"
10 10#import "GameMode.h"
11#import "SimpleAudioEngine.h"
11 12
12@implementation Rock 13@implementation Rock
13 14
@@ -24,4 +25,13 @@
24 return self; 25 return self;
25} 26}
26 27
28- (void)collideWithCart
29{
30 GameMode* gameLayer = ((GameMode*) sprite.parent);
31 [gameLayer setLives:gameLayer.lives-1];
32
33 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]];
34}
35
36
27@end 37@end
diff --git a/Classes/ValuableObject.h b/Classes/ValuableObject.h index ccefbbd..7b484d9 100755..100644 --- a/Classes/ValuableObject.h +++ b/Classes/ValuableObject.h
@@ -2,13 +2,13 @@
2// ValuableObject.h 2// ValuableObject.h
3// Cart Collect 3// Cart Collect
4// 4//
5// Created by iD Student Account on 7/20/11. 5// Created by Starla Insigna on 8/9/11.
6// Copyright 2011 __MyCompanyName__. All rights reserved. 6// Copyright 2011 Four Island. All rights reserved.
7// 7//
8 8
9#import <Foundation/Foundation.h> 9#import "FallingObject.h"
10 10
11@protocol ValuableObject 11@interface ValuableObject : FallingObject
12 12
13- (int)pointValue; 13- (int)pointValue;
14 14
diff --git a/Classes/ValuableObject.m b/Classes/ValuableObject.m new file mode 100644 index 0000000..f1a036f --- /dev/null +++ b/Classes/ValuableObject.m
@@ -0,0 +1,46 @@
1//
2// ValuableObject.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 "ValuableObject.h"
10#import "GameMode.h"
11#import "SimpleAudioEngine.h"
12
13@implementation ValuableObject
14
15- (id)init
16{
17 self = [super init];
18 if (self) {
19 // Initialization code here.
20 }
21
22 return self;
23}
24
25- (void)collideWithCart
26{
27 GameMode* gameLayer = ((GameMode*) sprite.parent);
28 [gameLayer setScore:gameLayer.score+self.pointValue];
29
30 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]];
31}
32
33- (void)collideWithFloor
34{
35 GameMode* gameLayer = ((GameMode*) sprite.parent);
36 [gameLayer setLives:gameLayer.lives-1];
37
38 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]];
39}
40
41- (int)pointValue
42{
43 @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)] userInfo:nil];
44}
45
46@end