summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xCart Collect.xcodeproj/project.pbxproj32
-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
23 files changed, 374 insertions, 178 deletions
diff --git a/Cart Collect.xcodeproj/project.pbxproj b/Cart Collect.xcodeproj/project.pbxproj index b3c5dfa..231e838 100755 --- a/Cart Collect.xcodeproj/project.pbxproj +++ b/Cart Collect.xcodeproj/project.pbxproj
@@ -84,6 +84,9 @@
84 50F4144910692EE7002A0D5E /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 50F4144410692EE7002A0D5E /* Default.png */; }; 84 50F4144910692EE7002A0D5E /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 50F4144410692EE7002A0D5E /* Default.png */; };
85 50F4144A10692EE7002A0D5E /* fps_images.png in Resources */ = {isa = PBXBuildFile; fileRef = 50F4144510692EE7002A0D5E /* fps_images.png */; }; 85 50F4144A10692EE7002A0D5E /* fps_images.png in Resources */ = {isa = PBXBuildFile; fileRef = 50F4144510692EE7002A0D5E /* fps_images.png */; };
86 50F4144B10692EE7002A0D5E /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 50F4144610692EE7002A0D5E /* Icon.png */; }; 86 50F4144B10692EE7002A0D5E /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 50F4144610692EE7002A0D5E /* Icon.png */; };
87 6C0C140E13F1C3EC003A31B2 /* ValuableObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C0C140D13F1C3EC003A31B2 /* ValuableObject.m */; };
88 6C0C141113F2099B003A31B2 /* Cart.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C0C141013F2099B003A31B2 /* Cart.m */; };
89 6C0C141413F20E98003A31B2 /* GameMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C0C141313F20E98003A31B2 /* GameMode.m */; };
87 6C29041013EAEB590032DA0F /* TutorialBubble.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C29040F13EAEB590032DA0F /* TutorialBubble.m */; }; 90 6C29041013EAEB590032DA0F /* TutorialBubble.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C29040F13EAEB590032DA0F /* TutorialBubble.m */; };
88 6C29041213EAEC8A0032DA0F /* framestuff.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C29041113EAEC8A0032DA0F /* framestuff.png */; }; 91 6C29041213EAEC8A0032DA0F /* framestuff.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C29041113EAEC8A0032DA0F /* framestuff.png */; };
89 6C5179C613DF3839006F1F38 /* Morning1.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C5179C513DF3839006F1F38 /* Morning1.png */; }; 92 6C5179C613DF3839006F1F38 /* Morning1.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C5179C513DF3839006F1F38 /* Morning1.png */; };
@@ -328,7 +331,6 @@
328 3F7D0F4913D8F17C00B6CE14 /* highscores2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = highscores2.png; sourceTree = "<group>"; }; 331 3F7D0F4913D8F17C00B6CE14 /* highscores2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = highscores2.png; sourceTree = "<group>"; };
329 3F7D0F4A13D8F17C00B6CE14 /* newgame.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = newgame.png; sourceTree = "<group>"; }; 332 3F7D0F4A13D8F17C00B6CE14 /* newgame.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = newgame.png; sourceTree = "<group>"; };
330 3F7D0F4B13D8F17C00B6CE14 /* newgame2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = newgame2.png; sourceTree = "<group>"; }; 333 3F7D0F4B13D8F17C00B6CE14 /* newgame2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = newgame2.png; sourceTree = "<group>"; };
331 3F8394AC13D72E2C0059AEE8 /* ValuableObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ValuableObject.h; sourceTree = "<group>"; };
332 3F8394F213D732330059AEE8 /* pause.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = pause.png; sourceTree = "<group>"; }; 334 3F8394F213D732330059AEE8 /* pause.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = pause.png; sourceTree = "<group>"; };
333 3F8394F413D7328E0059AEE8 /* pause2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = pause2.png; sourceTree = "<group>"; }; 335 3F8394F413D7328E0059AEE8 /* pause2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = pause2.png; sourceTree = "<group>"; };
334 3F83955113D739B10059AEE8 /* MainMenuLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainMenuLayer.h; sourceTree = "<group>"; }; 336 3F83955113D739B10059AEE8 /* MainMenuLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainMenuLayer.h; sourceTree = "<group>"; };
@@ -373,6 +375,12 @@
373 50F4144510692EE7002A0D5E /* fps_images.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = fps_images.png; sourceTree = "<group>"; }; 375 50F4144510692EE7002A0D5E /* fps_images.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = fps_images.png; sourceTree = "<group>"; };
374 50F4144610692EE7002A0D5E /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = "<group>"; }; 376 50F4144610692EE7002A0D5E /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = "<group>"; };
375 50F4144710692EE7002A0D5E /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 377 50F4144710692EE7002A0D5E /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
378 6C0C140C13F1C3EC003A31B2 /* ValuableObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ValuableObject.h; sourceTree = "<group>"; };
379 6C0C140D13F1C3EC003A31B2 /* ValuableObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ValuableObject.m; sourceTree = "<group>"; };
380 6C0C140F13F2099B003A31B2 /* Cart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Cart.h; sourceTree = "<group>"; };
381 6C0C141013F2099B003A31B2 /* Cart.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Cart.m; sourceTree = "<group>"; };
382 6C0C141213F20E98003A31B2 /* GameMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameMode.h; sourceTree = "<group>"; };
383 6C0C141313F20E98003A31B2 /* GameMode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GameMode.m; sourceTree = "<group>"; };
376 6C29040E13EAEB590032DA0F /* TutorialBubble.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TutorialBubble.h; sourceTree = "<group>"; }; 384 6C29040E13EAEB590032DA0F /* TutorialBubble.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TutorialBubble.h; sourceTree = "<group>"; };
377 6C29040F13EAEB590032DA0F /* TutorialBubble.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TutorialBubble.m; sourceTree = "<group>"; }; 385 6C29040F13EAEB590032DA0F /* TutorialBubble.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TutorialBubble.m; sourceTree = "<group>"; };
378 6C29041113EAEC8A0032DA0F /* framestuff.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = framestuff.png; sourceTree = "<group>"; }; 386 6C29041113EAEC8A0032DA0F /* framestuff.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = framestuff.png; sourceTree = "<group>"; };
@@ -656,14 +664,13 @@
656 2D500B1D0D5A766B00DBA0E3 /* Classes */ = { 664 2D500B1D0D5A766B00DBA0E3 /* Classes */ = {
657 isa = PBXGroup; 665 isa = PBXGroup;
658 children = ( 666 children = (
667 6C0C141513F211C7003A31B2 /* Game Modes */,
659 6C5887E313EE3ED900B5A80A /* Items */, 668 6C5887E313EE3ED900B5A80A /* Items */,
660 E0F81035120A173C005866B8 /* GameConfig.h */, 669 E0F81035120A173C005866B8 /* GameConfig.h */,
661 E0F81036120A173C005866B8 /* RootViewController.h */, 670 E0F81036120A173C005866B8 /* RootViewController.h */,
662 E0F81037120A173C005866B8 /* RootViewController.m */, 671 E0F81037120A173C005866B8 /* RootViewController.m */,
663 1F3B9A2C0EF2145700286867 /* Cart_CollectAppDelegate.h */, 672 1F3B9A2C0EF2145700286867 /* Cart_CollectAppDelegate.h */,
664 507022A2107672FA00393637 /* Cart_CollectAppDelegate.m */, 673 507022A2107672FA00393637 /* Cart_CollectAppDelegate.m */,
665 3FE79CD213D4DE37001A6B93 /* GameLayer.h */,
666 3FE79CD313D4DE37001A6B93 /* GameLayer.m */,
667 3F6C7EE713D6377D00C038FE /* GameOverLayer.h */, 674 3F6C7EE713D6377D00C038FE /* GameOverLayer.h */,
668 3F6C7EE813D6377D00C038FE /* GameOverLayer.m */, 675 3F6C7EE813D6377D00C038FE /* GameOverLayer.m */,
669 3F83955213D739B10059AEE8 /* MainMenuLayer.m */, 676 3F83955213D739B10059AEE8 /* MainMenuLayer.m */,
@@ -821,6 +828,17 @@
821 path = Resources; 828 path = Resources;
822 sourceTree = "<group>"; 829 sourceTree = "<group>";
823 }; 830 };
831 6C0C141513F211C7003A31B2 /* Game Modes */ = {
832 isa = PBXGroup;
833 children = (
834 6C0C141213F20E98003A31B2 /* GameMode.h */,
835 6C0C141313F20E98003A31B2 /* GameMode.m */,
836 3FE79CD213D4DE37001A6B93 /* GameLayer.h */,
837 3FE79CD313D4DE37001A6B93 /* GameLayer.m */,
838 );
839 name = "Game Modes";
840 sourceTree = "<group>";
841 };
824 6C5887E313EE3ED900B5A80A /* Items */ = { 842 6C5887E313EE3ED900B5A80A /* Items */ = {
825 isa = PBXGroup; 843 isa = PBXGroup;
826 children = ( 844 children = (
@@ -834,7 +852,10 @@
834 3F6C7C7213D5E57100C038FE /* OneUp.m */, 852 3F6C7C7213D5E57100C038FE /* OneUp.m */,
835 3F6C7EE213D636CF00C038FE /* Rock.h */, 853 3F6C7EE213D636CF00C038FE /* Rock.h */,
836 3F6C7EE313D636CF00C038FE /* Rock.m */, 854 3F6C7EE313D636CF00C038FE /* Rock.m */,
837 3F8394AC13D72E2C0059AEE8 /* ValuableObject.h */, 855 6C0C140C13F1C3EC003A31B2 /* ValuableObject.h */,
856 6C0C140D13F1C3EC003A31B2 /* ValuableObject.m */,
857 6C0C140F13F2099B003A31B2 /* Cart.h */,
858 6C0C141013F2099B003A31B2 /* Cart.m */,
838 ); 859 );
839 name = Items; 860 name = Items;
840 sourceTree = "<group>"; 861 sourceTree = "<group>";
@@ -1341,6 +1362,9 @@
1341 3F03221613D78F8C00E6A708 /* HighscoreListController.m in Sources */, 1362 3F03221613D78F8C00E6A708 /* HighscoreListController.m in Sources */,
1342 3F03221913D7904E00E6A708 /* Highscore.m in Sources */, 1363 3F03221913D7904E00E6A708 /* Highscore.m in Sources */,
1343 6C29041013EAEB590032DA0F /* TutorialBubble.m in Sources */, 1364 6C29041013EAEB590032DA0F /* TutorialBubble.m in Sources */,
1365 6C0C140E13F1C3EC003A31B2 /* ValuableObject.m in Sources */,
1366 6C0C141113F2099B003A31B2 /* Cart.m in Sources */,
1367 6C0C141413F20E98003A31B2 /* GameMode.m in Sources */,
1344 ); 1368 );
1345 runOnlyForDeploymentPostprocessing = 0; 1369 runOnlyForDeploymentPostprocessing = 0;
1346 }; 1370 };
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