summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xCartographic.xcodeproj/project.pbxproj23
-rw-r--r--Classes/Cart.h5
-rw-r--r--Classes/Cart.m23
-rw-r--r--Classes/CartDelegate.h19
-rwxr-xr-xClasses/ClassicGameMode.m2
-rw-r--r--Classes/GameMode.h2
-rw-r--r--Classes/GameMode.m1
-rwxr-xr-xClasses/GameOverScene.h5
-rwxr-xr-xClasses/GameOverScene.m9
-rw-r--r--Classes/JumpGameMode.h11
-rw-r--r--Classes/JumpGameMode.m344
-rw-r--r--Resources/ledge.pngbin0 -> 1012 bytes
12 files changed, 423 insertions, 21 deletions
diff --git a/Cartographic.xcodeproj/project.pbxproj b/Cartographic.xcodeproj/project.pbxproj index 61b9f11..95e1f93 100755 --- a/Cartographic.xcodeproj/project.pbxproj +++ b/Cartographic.xcodeproj/project.pbxproj
@@ -127,6 +127,7 @@
127 6C85834614056E57009EF100 /* venice.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C85834514056E57009EF100 /* venice.png */; }; 127 6C85834614056E57009EF100 /* venice.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C85834514056E57009EF100 /* venice.png */; };
128 6CC89DD913F2F4E6003704F7 /* Entitlements.plist in Resources */ = {isa = PBXBuildFile; fileRef = 6CC89DD813F2F4E6003704F7 /* Entitlements.plist */; }; 128 6CC89DD913F2F4E6003704F7 /* Entitlements.plist in Resources */ = {isa = PBXBuildFile; fileRef = 6CC89DD813F2F4E6003704F7 /* Entitlements.plist */; };
129 6CC89DDF13F31413003704F7 /* TutorialMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 6CC89DDE13F31413003704F7 /* TutorialMode.m */; }; 129 6CC89DDF13F31413003704F7 /* TutorialMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 6CC89DDE13F31413003704F7 /* TutorialMode.m */; };
130 6CDBE80C14092DB00072F287 /* ledge.png in Resources */ = {isa = PBXBuildFile; fileRef = 6CDBE80B14092DB00072F287 /* ledge.png */; };
130 DC6640030F83B3EA000B3E49 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC6640020F83B3EA000B3E49 /* AudioToolbox.framework */; }; 131 DC6640030F83B3EA000B3E49 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC6640020F83B3EA000B3E49 /* AudioToolbox.framework */; };
131 DC6640050F83B3EA000B3E49 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC6640040F83B3EA000B3E49 /* OpenAL.framework */; }; 132 DC6640050F83B3EA000B3E49 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC6640040F83B3EA000B3E49 /* OpenAL.framework */; };
132 DCCBF1B70F6022AE0040855A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DCCBF1B60F6022AE0040855A /* CoreGraphics.framework */; }; 133 DCCBF1B70F6022AE0040855A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DCCBF1B60F6022AE0040855A /* CoreGraphics.framework */; };
@@ -465,6 +466,8 @@
465 6CC89DDD13F31413003704F7 /* TutorialMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TutorialMode.h; sourceTree = "<group>"; }; 466 6CC89DDD13F31413003704F7 /* TutorialMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TutorialMode.h; sourceTree = "<group>"; };
466 6CC89DDE13F31413003704F7 /* TutorialMode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TutorialMode.m; sourceTree = "<group>"; }; 467 6CC89DDE13F31413003704F7 /* TutorialMode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TutorialMode.m; sourceTree = "<group>"; };
467 6CC89DE013F3197F003704F7 /* FallingObjectDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FallingObjectDelegate.h; sourceTree = "<group>"; }; 468 6CC89DE013F3197F003704F7 /* FallingObjectDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FallingObjectDelegate.h; sourceTree = "<group>"; };
469 6CDBE80B14092DB00072F287 /* ledge.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ledge.png; sourceTree = "<group>"; };
470 6CDBE80E140936CF0072F287 /* CartDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CartDelegate.h; sourceTree = "<group>"; };
468 DC6640020F83B3EA000B3E49 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; 471 DC6640020F83B3EA000B3E49 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
469 DC6640040F83B3EA000B3E49 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; }; 472 DC6640040F83B3EA000B3E49 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; };
470 DCCBF1B60F6022AE0040855A /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 473 DCCBF1B60F6022AE0040855A /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
@@ -782,6 +785,7 @@
782 3F6C7F4D13D647B600C038FE /* Sprites */ = { 785 3F6C7F4D13D647B600C038FE /* Sprites */ = {
783 isa = PBXGroup; 786 isa = PBXGroup;
784 children = ( 787 children = (
788 6CDBE80B14092DB00072F287 /* ledge.png */,
785 6C39CFE613FC46CD002B21AF /* water.png */, 789 6C39CFE613FC46CD002B21AF /* water.png */,
786 6C29041113EAEC8A0032DA0F /* framestuff.png */, 790 6C29041113EAEC8A0032DA0F /* framestuff.png */,
787 3F6C7EE013D636BE00C038FE /* rock.png */, 791 3F6C7EE013D636BE00C038FE /* rock.png */,
@@ -965,6 +969,7 @@
965 6C0C140F13F2099B003A31B2 /* Cart.h */, 969 6C0C140F13F2099B003A31B2 /* Cart.h */,
966 6C0C141013F2099B003A31B2 /* Cart.m */, 970 6C0C141013F2099B003A31B2 /* Cart.m */,
967 6CC89DE013F3197F003704F7 /* FallingObjectDelegate.h */, 971 6CC89DE013F3197F003704F7 /* FallingObjectDelegate.h */,
972 6CDBE80E140936CF0072F287 /* CartDelegate.h */,
968 ); 973 );
969 name = Items; 974 name = Items;
970 sourceTree = "<group>"; 975 sourceTree = "<group>";
@@ -1395,7 +1400,7 @@
1395 29B97313FDCFA39411CA2CEA /* Project object */ = { 1400 29B97313FDCFA39411CA2CEA /* Project object */ = {
1396 isa = PBXProject; 1401 isa = PBXProject;
1397 attributes = { 1402 attributes = {
1398 LastUpgradeCheck = 0410; 1403 LastUpgradeCheck = 0420;
1399 }; 1404 };
1400 buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "Cartographic" */; 1405 buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "Cartographic" */;
1401 compatibilityVersion = "Xcode 3.2"; 1406 compatibilityVersion = "Xcode 3.2";
@@ -1468,6 +1473,7 @@
1468 6C39CFE913FC8AC4002B21AF /* jump2.png in Resources */, 1473 6C39CFE913FC8AC4002B21AF /* jump2.png in Resources */,
1469 6C39CFEB13FC8ACA002B21AF /* jump.png in Resources */, 1474 6C39CFEB13FC8ACA002B21AF /* jump.png in Resources */,
1470 6C85834614056E57009EF100 /* venice.png in Resources */, 1475 6C85834614056E57009EF100 /* venice.png in Resources */,
1476 6CDBE80C14092DB00072F287 /* ledge.png in Resources */,
1471 ); 1477 );
1472 runOnlyForDeploymentPostprocessing = 0; 1478 runOnlyForDeploymentPostprocessing = 0;
1473 }; 1479 };
@@ -1655,6 +1661,7 @@
1655 GCC_PRECOMPILE_PREFIX_HEADER = YES; 1661 GCC_PRECOMPILE_PREFIX_HEADER = YES;
1656 GCC_PREFIX_HEADER = Cart_Collect_Prefix.pch; 1662 GCC_PREFIX_HEADER = Cart_Collect_Prefix.pch;
1657 GCC_TREAT_WARNINGS_AS_ERRORS = NO; 1663 GCC_TREAT_WARNINGS_AS_ERRORS = NO;
1664 GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
1658 HEADER_SEARCH_PATHS = libs; 1665 HEADER_SEARCH_PATHS = libs;
1659 INFOPLIST_FILE = Resources/Info.plist; 1666 INFOPLIST_FILE = Resources/Info.plist;
1660 INFOPLIST_PREFIX_HEADER = Versioning.h; 1667 INFOPLIST_PREFIX_HEADER = Versioning.h;
@@ -1686,6 +1693,7 @@
1686 GCC_PRECOMPILE_PREFIX_HEADER = YES; 1693 GCC_PRECOMPILE_PREFIX_HEADER = YES;
1687 GCC_PREFIX_HEADER = Cart_Collect_Prefix.pch; 1694 GCC_PREFIX_HEADER = Cart_Collect_Prefix.pch;
1688 GCC_TREAT_WARNINGS_AS_ERRORS = NO; 1695 GCC_TREAT_WARNINGS_AS_ERRORS = NO;
1696 GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
1689 HEADER_SEARCH_PATHS = libs; 1697 HEADER_SEARCH_PATHS = libs;
1690 INFOPLIST_FILE = Resources/Info.plist; 1698 INFOPLIST_FILE = Resources/Info.plist;
1691 INFOPLIST_PREFIX_HEADER = Versioning.h; 1699 INFOPLIST_PREFIX_HEADER = Versioning.h;
@@ -1713,6 +1721,7 @@
1713 GCC_DYNAMIC_NO_PIC = NO; 1721 GCC_DYNAMIC_NO_PIC = NO;
1714 GCC_OPTIMIZATION_LEVEL = 0; 1722 GCC_OPTIMIZATION_LEVEL = 0;
1715 GCC_TREAT_WARNINGS_AS_ERRORS = NO; 1723 GCC_TREAT_WARNINGS_AS_ERRORS = NO;
1724 GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
1716 HEADER_SEARCH_PATHS = ( 1725 HEADER_SEARCH_PATHS = (
1717 libs/Chipmunk/include/chipmunk, 1726 libs/Chipmunk/include/chipmunk,
1718 libs, 1727 libs,
@@ -1731,6 +1740,7 @@
1731 DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 1740 DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
1732 GCC_PREPROCESSOR_DEFINITIONS = ""; 1741 GCC_PREPROCESSOR_DEFINITIONS = "";
1733 GCC_TREAT_WARNINGS_AS_ERRORS = NO; 1742 GCC_TREAT_WARNINGS_AS_ERRORS = NO;
1743 GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
1734 HEADER_SEARCH_PATHS = ( 1744 HEADER_SEARCH_PATHS = (
1735 libs/Chipmunk/include/chipmunk, 1745 libs/Chipmunk/include/chipmunk,
1736 libs, 1746 libs,
@@ -1756,7 +1766,7 @@
1756 "GCC_THUMB_SUPPORT[arch=armv6]" = NO; 1766 "GCC_THUMB_SUPPORT[arch=armv6]" = NO;
1757 "GCC_THUMB_SUPPORT[arch=armv7]" = YES; 1767 "GCC_THUMB_SUPPORT[arch=armv7]" = YES;
1758 GCC_UNROLL_LOOPS = YES; 1768 GCC_UNROLL_LOOPS = YES;
1759 GCC_VERSION = com.apple.compilers.llvmgcc42; 1769 GCC_VERSION = "";
1760 GCC_WARN_ABOUT_RETURN_TYPE = YES; 1770 GCC_WARN_ABOUT_RETURN_TYPE = YES;
1761 GCC_WARN_UNUSED_VARIABLE = YES; 1771 GCC_WARN_UNUSED_VARIABLE = YES;
1762 IPHONEOS_DEPLOYMENT_TARGET = 3.0; 1772 IPHONEOS_DEPLOYMENT_TARGET = 3.0;
@@ -1783,6 +1793,7 @@
1783 NDEBUG, 1793 NDEBUG,
1784 ); 1794 );
1785 GCC_TREAT_WARNINGS_AS_ERRORS = NO; 1795 GCC_TREAT_WARNINGS_AS_ERRORS = NO;
1796 GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
1786 HEADER_SEARCH_PATHS = libs; 1797 HEADER_SEARCH_PATHS = libs;
1787 INFOPLIST_FILE = Resources/Info.plist; 1798 INFOPLIST_FILE = Resources/Info.plist;
1788 INFOPLIST_PREFIX_HEADER = Versioning.h; 1799 INFOPLIST_PREFIX_HEADER = Versioning.h;
@@ -1810,6 +1821,7 @@
1810 DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 1821 DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
1811 GCC_PREPROCESSOR_DEFINITIONS = ""; 1822 GCC_PREPROCESSOR_DEFINITIONS = "";
1812 GCC_TREAT_WARNINGS_AS_ERRORS = NO; 1823 GCC_TREAT_WARNINGS_AS_ERRORS = NO;
1824 GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
1813 HEADER_SEARCH_PATHS = ( 1825 HEADER_SEARCH_PATHS = (
1814 libs/Chipmunk/include/chipmunk, 1826 libs/Chipmunk/include/chipmunk,
1815 libs, 1827 libs,
@@ -1823,6 +1835,7 @@
1823 6C19F16F1401944500F9CCD3 /* Ad-Hoc */ = { 1835 6C19F16F1401944500F9CCD3 /* Ad-Hoc */ = {
1824 isa = XCBuildConfiguration; 1836 isa = XCBuildConfiguration;
1825 buildSettings = { 1837 buildSettings = {
1838 GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
1826 PRODUCT_NAME = "$(TARGET_NAME)"; 1839 PRODUCT_NAME = "$(TARGET_NAME)";
1827 }; 1840 };
1828 name = "Ad-Hoc"; 1841 name = "Ad-Hoc";
@@ -1830,6 +1843,7 @@
1830 6C263DDD13F6F4A000116746 /* Debug */ = { 1843 6C263DDD13F6F4A000116746 /* Debug */ = {
1831 isa = XCBuildConfiguration; 1844 isa = XCBuildConfiguration;
1832 buildSettings = { 1845 buildSettings = {
1846 GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
1833 PRODUCT_NAME = "$(TARGET_NAME)"; 1847 PRODUCT_NAME = "$(TARGET_NAME)";
1834 }; 1848 };
1835 name = Debug; 1849 name = Debug;
@@ -1837,6 +1851,7 @@
1837 6C263DDE13F6F4A000116746 /* Release */ = { 1851 6C263DDE13F6F4A000116746 /* Release */ = {
1838 isa = XCBuildConfiguration; 1852 isa = XCBuildConfiguration;
1839 buildSettings = { 1853 buildSettings = {
1854 GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
1840 PRODUCT_NAME = "$(TARGET_NAME)"; 1855 PRODUCT_NAME = "$(TARGET_NAME)";
1841 }; 1856 };
1842 name = Release; 1857 name = Release;
@@ -1856,7 +1871,7 @@
1856 ); 1871 );
1857 "GCC_THUMB_SUPPORT[arch=armv6]" = NO; 1872 "GCC_THUMB_SUPPORT[arch=armv6]" = NO;
1858 "GCC_THUMB_SUPPORT[arch=armv7]" = YES; 1873 "GCC_THUMB_SUPPORT[arch=armv7]" = YES;
1859 GCC_VERSION = com.apple.compilers.llvmgcc42; 1874 GCC_VERSION = "";
1860 GCC_WARN_ABOUT_RETURN_TYPE = YES; 1875 GCC_WARN_ABOUT_RETURN_TYPE = YES;
1861 GCC_WARN_UNUSED_VARIABLE = YES; 1876 GCC_WARN_UNUSED_VARIABLE = YES;
1862 IPHONEOS_DEPLOYMENT_TARGET = 3.0; 1877 IPHONEOS_DEPLOYMENT_TARGET = 3.0;
@@ -1881,7 +1896,7 @@
1881 "GCC_THUMB_SUPPORT[arch=armv6]" = NO; 1896 "GCC_THUMB_SUPPORT[arch=armv6]" = NO;
1882 "GCC_THUMB_SUPPORT[arch=armv7]" = YES; 1897 "GCC_THUMB_SUPPORT[arch=armv7]" = YES;
1883 GCC_UNROLL_LOOPS = YES; 1898 GCC_UNROLL_LOOPS = YES;
1884 GCC_VERSION = com.apple.compilers.llvmgcc42; 1899 GCC_VERSION = "";
1885 GCC_WARN_ABOUT_RETURN_TYPE = YES; 1900 GCC_WARN_ABOUT_RETURN_TYPE = YES;
1886 GCC_WARN_UNUSED_VARIABLE = YES; 1901 GCC_WARN_UNUSED_VARIABLE = YES;
1887 IPHONEOS_DEPLOYMENT_TARGET = 3.0; 1902 IPHONEOS_DEPLOYMENT_TARGET = 3.0;
diff --git a/Classes/Cart.h b/Classes/Cart.h index 0ef1abf..302e5ec 100644 --- a/Classes/Cart.h +++ b/Classes/Cart.h
@@ -8,15 +8,20 @@
8 8
9#import <Foundation/Foundation.h> 9#import <Foundation/Foundation.h>
10#import "cocos2d.h" 10#import "cocos2d.h"
11#import "CartDelegate.h"
11 12
12@interface Cart : NSObject { 13@interface Cart : NSObject {
13 CCSprite* sprite; 14 CCSprite* sprite;
14 float accelX; 15 float accelX;
15 BOOL immobile; 16 BOOL immobile;
17 id<CartDelegate> delegate;
18 BOOL falling;
16} 19}
17 20
18@property (readonly) CCSprite* sprite; 21@property (readonly) CCSprite* sprite;
19@property (assign) BOOL immobile; 22@property (assign) BOOL immobile;
23@property (nonatomic,retain) id<CartDelegate> delegate;
24@property (assign) BOOL falling;
20- (id)initWithSprite:(CCSprite*)sprite; 25- (id)initWithSprite:(CCSprite*)sprite;
21- (void)tick; 26- (void)tick;
22- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration; 27- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration;
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
diff --git a/Classes/CartDelegate.h b/Classes/CartDelegate.h new file mode 100644 index 0000000..8c37019 --- /dev/null +++ b/Classes/CartDelegate.h
@@ -0,0 +1,19 @@
1//
2// CartDelegate.h
3// Cartographic
4//
5// Created by Starla Insigna on 8/27/11.
6// Copyright 2011 Four Island. All rights reserved.
7//
8
9#import <Foundation/Foundation.h>
10
11@class Cart;
12
13@protocol CartDelegate <NSObject>
14
15@optional
16- (int)cartShouldFall:(Cart*)cart;
17- (BOOL)cartIsObstructed:(Cart*)cart;
18
19@end
diff --git a/Classes/ClassicGameMode.m b/Classes/ClassicGameMode.m index c1d3be7..b8fe636 100755 --- a/Classes/ClassicGameMode.m +++ b/Classes/ClassicGameMode.m
@@ -28,7 +28,7 @@
28 { 28 {
29 [self unscheduleAllSelectors]; 29 [self unscheduleAllSelectors];
30 30
31 [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverScene sceneWithScore:score]]]; 31 [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverScene sceneWithScore:score gameMode:@"Collect"]]];
32 } else if (score > lastScore) 32 } else if (score > lastScore)
33 { 33 {
34 if ((lastScore < 6500) && (score >= 6500)) 34 if ((lastScore < 6500) && (score >= 6500))
diff --git a/Classes/GameMode.h b/Classes/GameMode.h index 53ed9fc..0659a57 100644 --- a/Classes/GameMode.h +++ b/Classes/GameMode.h
@@ -12,7 +12,7 @@
12#define GAME_SCENE 436 12#define GAME_SCENE 436
13#define GAME_LAYER 437 13#define GAME_LAYER 437
14 14
15@interface GameMode : CCLayer <UIAlertViewDelegate> { 15@interface GameMode : CCLayer <UIAlertViewDelegate, CartDelegate> {
16 NSMutableSet* objects; 16 NSMutableSet* objects;
17 int score; 17 int score;
18 int lives; 18 int lives;
diff --git a/Classes/GameMode.m b/Classes/GameMode.m index af9b3bd..f0eb02f 100644 --- a/Classes/GameMode.m +++ b/Classes/GameMode.m
@@ -40,6 +40,7 @@
40 cart = [[Cart alloc] initWithSprite:[CCSprite spriteWithFile:@"cart.png"]]; 40 cart = [[Cart alloc] initWithSprite:[CCSprite spriteWithFile:@"cart.png"]];
41 cart.sprite.position = ccp(240, 22); 41 cart.sprite.position = ccp(240, 22);
42 cart.sprite.scale = 2; 42 cart.sprite.scale = 2;
43 cart.delegate = self;
43 [self addChild:cart.sprite]; 44 [self addChild:cart.sprite];
44 45
45 scoreLabel = [CCLabelBMFont labelWithString:@"Score: 0" fntFile:@"helvetica2.fnt"]; 46 scoreLabel = [CCLabelBMFont labelWithString:@"Score: 0" fntFile:@"helvetica2.fnt"];
diff --git a/Classes/GameOverScene.h b/Classes/GameOverScene.h index ef63aa7..a91286e 100755 --- a/Classes/GameOverScene.h +++ b/Classes/GameOverScene.h
@@ -18,10 +18,11 @@
18 UIActivityIndicatorView* activityIndicator; 18 UIActivityIndicatorView* activityIndicator;
19 UIButton* backButton; 19 UIButton* backButton;
20 int score; 20 int score;
21 NSString* gameMode;
21} 22}
22 23
23+ (GameOverScene*)sceneWithScore:(int)score; 24+ (GameOverScene*)sceneWithScore:(int)score gameMode:(NSString*)gameMode;
24- (id)initWithScore:(int)score; 25- (id)initWithScore:(int)score gameMode:(NSString*)gameMode;
25- (void)newgame; 26- (void)newgame;
26- (void)submitScore; 27- (void)submitScore;
27- (void)exit; 28- (void)exit;
diff --git a/Classes/GameOverScene.m b/Classes/GameOverScene.m index 94236ff..f2dca0b 100755 --- a/Classes/GameOverScene.m +++ b/Classes/GameOverScene.m
@@ -14,12 +14,12 @@
14 14
15@implementation GameOverScene 15@implementation GameOverScene
16 16
17+ (GameOverScene*)sceneWithScore:(int)score 17+ (GameOverScene*)sceneWithScore:(int)score gameMode:(NSString*)gameMode
18{ 18{
19 return [[[GameOverScene alloc] initWithScore:score] autorelease]; 19 return [[[GameOverScene alloc] initWithScore:score gameMode:gameMode] autorelease];
20} 20}
21 21
22- (id)initWithScore:(int)score2 22- (id)initWithScore:(int)score2 gameMode:(NSString*)gameMode2
23{ 23{
24 self = [super init]; 24 self = [super init];
25 25
@@ -36,6 +36,7 @@
36 [theLayer addChild:backgroundImage z:0]; 36 [theLayer addChild:backgroundImage z:0];
37 37
38 score = score2; 38 score = score2;
39 gameMode = gameMode2;
39 40
40 movingLayer = [[UIView alloc] initWithFrame:CGRectMake(0, -320, 480, 320)]; 41 movingLayer = [[UIView alloc] initWithFrame:CGRectMake(0, -320, 480, 320)];
41 movingLayer.backgroundColor = [UIColor clearColor]; 42 movingLayer.backgroundColor = [UIColor clearColor];
@@ -88,7 +89,7 @@
88 textField.enabled = NO; 89 textField.enabled = NO;
89 submitSwitch.enabled = NO; 90 submitSwitch.enabled = NO;
90 91
91 const char* sqlQuery = [[NSString stringWithFormat:@"INSERT INTO highscores (name, score, gameMode) VALUES (\"%@\",%d,\"Collect\")", [textField text], score] UTF8String]; 92 const char* sqlQuery = [[NSString stringWithFormat:@"INSERT INTO highscores (name, score, gameMode) VALUES (\"%@\",%d,\"%@\")", [textField text], score, gameMode] UTF8String];
92 sqlite3_stmt* compiled_statement; 93 sqlite3_stmt* compiled_statement;
93 94
94 if (sqlite3_prepare_v2([Cart_CollectAppDelegate database], sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK) 95 if (sqlite3_prepare_v2([Cart_CollectAppDelegate database], sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK)
diff --git a/Classes/JumpGameMode.h b/Classes/JumpGameMode.h index 9753720..f6a31f8 100644 --- a/Classes/JumpGameMode.h +++ b/Classes/JumpGameMode.h
@@ -8,6 +8,8 @@
8 8
9#import "GameMode.h" 9#import "GameMode.h"
10 10
11@class LedgeFactory;
12
11@interface JumpGameMode : GameMode <CCStandardTouchDelegate> { 13@interface JumpGameMode : GameMode <CCStandardTouchDelegate> {
12 CCSprite* water; 14 CCSprite* water;
13 int waterTick; 15 int waterTick;
@@ -16,6 +18,15 @@
16 int jumpTick; 18 int jumpTick;
17 BOOL jump; 19 BOOL jump;
18 float expectedAngle; 20 float expectedAngle;
21 NSMutableSet* ledges;
22 LedgeFactory* factory;
23 int ledgeScrollSpeed;
24 float ledgeAccelerationRate;
25 float addSpeed;
19} 26}
20 27
28- (void)accelerateLedgeScrolling;
29- (void)randomlyAddObject:(ccTime)dt;
30- (void)incrementScore;
31
21@end 32@end
diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m index e30be6a..bac3fa5 100644 --- a/Classes/JumpGameMode.m +++ b/Classes/JumpGameMode.m
@@ -7,8 +7,27 @@
7// 7//
8 8
9#import "JumpGameMode.h" 9#import "JumpGameMode.h"
10#import "SimpleAudioEngine.h"
11#import "FallingObject.h"
12#import "Cherry.h"
13#import "Bottle.h"
14#import "OneUp.h"
15#import "Rock.h"
16#import "GameOverScene.h"
10 17
11#define kMinimumGestureLength 50 18#define kMinimumGestureLength 25
19
20@interface LedgeFactory : NSObject {
21 UIImage* leftSprite;
22 UIImage* midSprite;
23 UIImage* rightSprite;
24 UIImage* singleSprite;
25}
26
27- (id)init;
28- (UIImage*)createLedgeWithWidth:(int)width height:(int)height;
29
30@end
12 31
13@implementation JumpGameMode 32@implementation JumpGameMode
14 33
@@ -18,14 +37,33 @@
18 37
19 if (nil != self) 38 if (nil != self)
20 { 39 {
40 CCSprite* backgroundImage = [CCSprite spriteWithFile:@"SeaBeach.png"];
41 backgroundImage.position = ccp(240, 160);
42 [self addChild:backgroundImage z:-1];
43
21 water = [CCSprite spriteWithFile:@"water.png"]; 44 water = [CCSprite spriteWithFile:@"water.png"];
22 water.position = ccp(240, -80); 45 water.position = ccp(240, -60);
23 [self addChild:water]; 46 [self addChild:water];
24 47
48 cart.sprite.position = ccp(120, 22+64); //86
49 cart.falling = YES;
50 cart.delegate = self;
51
25 self.isTouchEnabled = YES; 52 self.isTouchEnabled = YES;
26 53
27 waterTick = 0; 54 waterTick = 0;
28 wave = NO; 55 wave = NO;
56
57 factory = [[LedgeFactory alloc] init];
58 ledges = [[NSMutableSet alloc] init];
59 CCSprite* ledge = [CCSprite spriteWithTexture:[[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:6 height:2]]];
60 ledge.position = ccp(80, 32);
61 [self addChild:ledge];
62 [ledges addObject:ledge];
63
64 ledgeScrollSpeed = 0;
65 ledgeAccelerationRate = 20.0f;
66 addSpeed = 2.5f;
29 } 67 }
30 68
31 return self; 69 return self;
@@ -34,21 +72,122 @@
34- (void)onEnterTransitionDidFinish 72- (void)onEnterTransitionDidFinish
35{ 73{
36 [super onEnterTransitionDidFinish]; 74 [super onEnterTransitionDidFinish];
75
76 [self schedule:@selector(accelerateLedgeScrolling) interval:ledgeAccelerationRate];
77 [self schedule:@selector(randomlyAddObject:) interval:addSpeed];
78 [self schedule:@selector(incrementScore) interval:1.0f];
37 79
38 [self scheduleDelayedAction:^{ 80 [self scheduleDelayedAction:^{
39 wave = YES; 81 wave = YES;
40 } delay:3.0f]; 82 } delay:60.0f];
41} 83}
42 84
43- (void)tick:(ccTime)dt 85- (void)tick:(ccTime)dt
44{ 86{
87 NSMutableSet* discardedSet = [NSMutableSet set];
88 int rightmost = 0;
89 int rightwidth = 0;
90
91 for (CCSprite* sprite in ledges)
92 {
93 sprite.position = ccp(sprite.position.x - ledgeScrollSpeed, sprite.position.y);
94
95 if ((sprite.position.x + sprite.boundingBox.size.width/2) < 0)
96 {
97 [discardedSet addObject:sprite];
98 [self removeChild:sprite cleanup:YES];
99 }
100
101 if (sprite.position.x > rightmost)
102 {
103 rightmost = sprite.position.x;
104 rightwidth = sprite.boundingBox.size.width/2;
105 }
106 }
107
108 for (FallingObject* object in objects)
109 {
110 if (waterTick > 0)
111 {
112 object.sprite.position = ccp(object.sprite.position.x, MAX(object.sprite.position.y, water.position.y+80+11));
113 } else {
114 object.sprite.position = ccp(object.sprite.position.x-ledgeScrollSpeed, object.sprite.position.y);
115 }
116 }
117
118 [ledges minusSet:discardedSet];
119
120 if (rightmost <= 480)
121 {
122 CCSprite* ledge = [CCSprite spriteWithTexture:[[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:(arc4random() % 10) height:2]]];
123 ledge.position = ccp(rightmost + rightwidth + ledge.boundingBox.size.width/2+64, 32);
124 [self addChild:ledge];
125 [ledges addObject:ledge];
126 }
127
128 if ([self cartIsObstructed:cart])
129 {
130 cart.sprite.position = ccp(cart.sprite.position.x-ledgeScrollSpeed, cart.sprite.position.y);
131 }
132
133 int lastScore = score;
134
45 [super tick:dt]; 135 [super tick:dt];
46 136
137 if (cart.sprite.position.y == (0-cart.sprite.boundingBox.size.height/2))
138 {
139 [self setLives:self.lives-1];
140
141 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]];
142
143 cart.sprite.position = ccp(cart.sprite.position.x, 320 + cart.sprite.boundingBox.size.height/2);
144 }
145
146 if (lives == 0)
147 {
148 [self unscheduleAllSelectors];
149
150 [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverScene sceneWithScore:score gameMode:@"Jump"]]];
151 } else if (score > lastScore)
152 {
153 if ((lastScore < 240) && (score >= 240))
154 {
155 [self unschedule:@selector(randomlyAddObject:)];
156 [self schedule:@selector(randomlyAddObject:) interval:0.6f];
157 addSpeed = 0.6f;
158 } else if ((lastScore < 180) && (score >= 180))
159 {
160 [self unschedule:@selector(randomlyAddObject:)];
161 [self schedule:@selector(randomlyAddObject:) interval:0.7f];
162 addSpeed = 0.7f;
163 } else if ((lastScore < 120) && (score >= 120))
164 {
165 [self unschedule:@selector(randomlyAddObject:)];
166 [self schedule:@selector(randomlyAddObject:) interval:0.8f];
167 addSpeed = 0.8f;
168 } else if ((lastScore < 90) && (score >= 90))
169 {
170 [self unschedule:@selector(randomlyAddObject:)];
171 [self schedule:@selector(randomlyAddObject:) interval:0.9f];
172 addSpeed = 0.9f;
173 } else if ((lastScore < 60) && (score >= 60))
174 {
175 [self unschedule:@selector(randomlyAddObject:)];
176 [self schedule:@selector(randomlyAddObject:) interval:1.0f];
177 addSpeed = 1.0f;
178 } else if ((lastScore < 30) && (score >= 30))
179 {
180 [self unschedule:@selector(randomlyAddObject:)];
181 [self schedule:@selector(randomlyAddObject:) interval:2.0f];
182 addSpeed = 2.0f;
183 }
184 }
185
47 if (wave) 186 if (wave)
48 { 187 {
49 waterTick++; 188 waterTick++;
50 189
51 water.position = ccp(240, 160 * sin(waterTick / (36 * M_PI)) - 80); 190 water.position = ccp(240, 140 * sin(waterTick / (36 * M_PI)) - 60);
52 191
53 if (waterTick == 180) 192 if (waterTick == 180)
54 { 193 {
@@ -61,6 +200,10 @@
61 { 200 {
62 wave = NO; 201 wave = NO;
63 waterTick = 0; 202 waterTick = 0;
203
204 [self scheduleDelayedAction:^{
205 wave = YES;
206 } delay:60.0f];
64 } 207 }
65 } 208 }
66 209
@@ -68,15 +211,14 @@
68 { 211 {
69 jumpTick++; 212 jumpTick++;
70 213
71 cart.sprite.position = ccp(cart.sprite.position.x, MAX(100 * sin(jumpTick / (2 * M_PI)) + 22, water.position.y+80+11)); 214 cart.sprite.position = ccp(cart.sprite.position.x, MAX(100 * sin(jumpTick / (2 * M_PI)) + 86, water.position.y+80+11));
72 215
73 if (jumpTick == 20) 216 if (jumpTick == 20)
74 { 217 {
75 jump = NO; 218 jump = NO;
76 jumpTick = 0; 219 jumpTick = 0;
220 cart.falling = YES;
77 } 221 }
78 } else {
79 cart.sprite.position = ccp(cart.sprite.position.x, MAX(22, water.position.y+80+11));
80 } 222 }
81} 223}
82 224
@@ -93,9 +235,10 @@
93 CGFloat angle = atan2f(gestureCurrentPosition.y - gestureStartPoint.y, gestureCurrentPosition.x - gestureStartPoint.x); 235 CGFloat angle = atan2f(gestureCurrentPosition.y - gestureStartPoint.y, gestureCurrentPosition.x - gestureStartPoint.x);
94 CGFloat distance = sqrt(powf((gestureCurrentPosition.x - gestureStartPoint.x),2) + powf((gestureCurrentPosition.y - gestureStartPoint.y),2)); 236 CGFloat distance = sqrt(powf((gestureCurrentPosition.x - gestureStartPoint.x),2) + powf((gestureCurrentPosition.y - gestureStartPoint.y),2));
95 237
96 if ((distance >= kMinimumGestureLength) && (angle >= expectedAngle - M_PI_4) && (angle <= expectedAngle + M_PI_4) && (cart.sprite.position.y == 22)) 238 if ((distance >= kMinimumGestureLength) && (angle >= expectedAngle - M_PI_4) && (angle <= expectedAngle + M_PI_4) && ((cart.sprite.position.y >= 80) && (cart.sprite.position.y <= 90)))
97 { 239 {
98 jump = YES; 240 jump = YES;
241 cart.falling = NO;
99 } 242 }
100} 243}
101 244
@@ -106,4 +249,189 @@
106 expectedAngle = acceleration.y*M_PI_2; 249 expectedAngle = acceleration.y*M_PI_2;
107} 250}
108 251
252- (int)cartShouldFall:(Cart *)m_cart
253{
254 int bottom = 0-m_cart.sprite.boundingBox.size.height/2;
255
256 for (CCSprite* sprite in ledges)
257 {
258 CGSize first = [m_cart.sprite boundingBox].size;
259 CGSize second = [sprite boundingBox].size;
260
261 if (m_cart.sprite.position.x > (sprite.position.x - second.width/2 - first.width/2))
262 {
263 if (m_cart.sprite.position.x < (sprite.position.x + second.width/2 + first.width/2))
264 {
265 bottom = sprite.position.y + second.height/2 + first.height/2;
266 break;
267 }
268 }
269 }
270
271 if (waterTick > 0)
272 {
273 bottom = MAX(water.position.y+80+11, bottom);
274 }
275
276 return bottom;
277}
278
279- (BOOL)cartIsObstructed:(Cart *)m_cart
280{
281 for (CCSprite* sprite in ledges)
282 {
283 CGSize first = [m_cart.sprite boundingBox].size;
284 CGSize second = [sprite boundingBox].size;
285
286 if (m_cart.sprite.position.x > (sprite.position.x - second.width/2 - first.width/2))
287 {
288 if (m_cart.sprite.position.x < (sprite.position.x + second.width/2 + first.width/2))
289 {
290 if (m_cart.sprite.position.y > (sprite.position.y - second.height/2 - first.height/2))
291 {
292 if (m_cart.sprite.position.y < (sprite.position.y + second.height/2 + first.height/2))
293 {
294 return YES;
295 }
296 }
297 }
298 }
299 }
300
301 return NO;
302}
303
304- (void)accelerateLedgeScrolling
305{
306 [self unschedule:@selector(accelerateLedgeScrolling)];
307
308 ledgeScrollSpeed += 2;
309 ledgeAccelerationRate *= 2;
310
311 [self schedule:@selector(accelerateLedgeScrolling) interval:ledgeAccelerationRate];
312}
313
314- (void)randomlyAddObject:(ccTime)dt
315{
316 FallingObject* object;
317
318 if (score < 120)
319 {
320 int randomval = arc4random()%100;
321
322 if (randomval < 80)
323 {
324 object = [[Rock alloc] init];
325 } else {
326 object = [[OneUp alloc] init];
327 }
328 } else {
329 int randomval = arc4random()%100;
330
331 if (randomval < 70)
332 {
333 object = [[Rock alloc] init];
334 } else {
335 object = [[OneUp alloc] init];
336 }
337 }
338
339 int objectX = arc4random()%448+16;
340 object.sprite.position = ccp(objectX, 360);
341 object.sprite.scale = 1;
342 [self addChild:object.sprite];
343
344 [objects addObject:object];
345 [object release];
346
347 if (score >= 120)
348 {
349 if (arc4random() % 100 > 80)
350 {
351 object = [[Rock alloc] init];
352
353 objectX = arc4random()%448+16;
354 object.sprite.position = ccp(objectX, 360);
355 object.sprite.scale = 1;
356 [self addChild:object.sprite];
357
358 [objects addObject:object];
359 [object release];
360 }
361 }
362
363 if (score >= 240)
364 {
365 if (arc4random() % 100 > 80)
366 {
367 object = [[Rock alloc] init];
368
369 objectX = arc4random()%448+16;
370 object.sprite.position = ccp(objectX, 360);
371 object.sprite.scale = 1;
372 [self addChild:object.sprite];
373
374 [objects addObject:object];
375 [object release];
376 }
377 }
378}
379
380- (void)incrementScore
381{
382 [self setScore:self.score+1];
383}
384
109@end 385@end
386
387@implementation LedgeFactory
388
389- (id)init
390{
391 self = [super init];
392
393 CGImageRef framestuff = [[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ledge" ofType:@"png"]] CGImage];
394 CGImageRef leftRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(0, 0, 32, 32));
395 CGImageRef midRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(32, 0, 32, 32));
396 CGImageRef rightRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(64, 0, 32, 32));
397 CGImageRef singleRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(96, 0, 32, 32));
398 leftSprite = [[UIImage alloc] initWithCGImage:leftRef];
399 midSprite = [[UIImage alloc] initWithCGImage:midRef];
400 rightSprite = [[UIImage alloc] initWithCGImage:rightRef];
401 singleSprite = [[UIImage alloc] initWithCGImage:singleRef];
402 CGImageRelease(leftRef);
403 CGImageRelease(midRef);
404 CGImageRelease(rightRef);
405 CGImageRelease(singleRef);
406
407 return self;
408}
409
410- (UIImage*)createLedgeWithWidth:(int)width height:(int)height
411{
412 UIGraphicsBeginImageContext(CGSizeMake(width*32, height*32));
413
414 for (int y=0; y<height; y++)
415 {
416 if (width == 1)
417 {
418 [singleSprite drawInRect:CGRectMake(0, y*32, 32, 32)];
419 } else {
420 [leftSprite drawInRect:CGRectMake(0, y*32, 32, 32)];
421
422 for (int x=1; x<(width-1); x++)
423 {
424 [midSprite drawInRect:CGRectMake(x*32, y*32, 32, 32)];
425 }
426
427 [rightSprite drawInRect:CGRectMake((width-1)*32, y*32, 32, 32)];
428 }
429 }
430
431 UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
432 UIGraphicsEndImageContext();
433
434 return result;
435}
436
437@end \ No newline at end of file
diff --git a/Resources/ledge.png b/Resources/ledge.png new file mode 100644 index 0000000..0729a69 --- /dev/null +++ b/Resources/ledge.png
Binary files differ