From 7eb543b37f42f708611f969de2d813a5457c54d8 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Fri, 4 Jan 2013 16:26:04 -0500 Subject: Created score bar Closes #190 --- Cartographic.xcodeproj/project.pbxproj | 6 ++++ Classes/ClassicGameMode.h | 7 +++++ Classes/ClassicGameMode.m | 36 ++++++++++++++++++++++- Classes/GameMode.h | 12 +------- Classes/GameMode.m | 45 +--------------------------- Classes/JumpGameMode.h | 10 +++++++ Classes/JumpGameMode.m | 54 ++++++++++++++++++++++++++++++---- Classes/ScoreBarLayer.h | 19 ++++++++++++ Classes/ScoreBarLayer.m | 41 ++++++++++++++++++++++++++ Classes/TutorialMode.h | 7 +++++ Classes/TutorialMode.m | 36 ++++++++++++++++++++++- 11 files changed, 211 insertions(+), 62 deletions(-) create mode 100644 Classes/ScoreBarLayer.h create mode 100644 Classes/ScoreBarLayer.m diff --git a/Cartographic.xcodeproj/project.pbxproj b/Cartographic.xcodeproj/project.pbxproj index 32912ef..1513954 100755 --- a/Cartographic.xcodeproj/project.pbxproj +++ b/Cartographic.xcodeproj/project.pbxproj @@ -122,6 +122,7 @@ 6C85834014055A44009EF100 /* CCNotifications.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C85833F14055A44009EF100 /* CCNotifications.m */; }; 6C85834414055B2E009EF100 /* notificationDesign.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C85834314055B2E009EF100 /* notificationDesign.m */; }; 6C85834614056E57009EF100 /* venice.png in Resources */ = {isa = PBXBuildFile; fileRef = 6C85834514056E57009EF100 /* venice.png */; }; + 6C91A8781697745A00939EA1 /* ScoreBarLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C91A8771697745A00939EA1 /* ScoreBarLayer.m */; }; 6CC89DD913F2F4E6003704F7 /* Entitlements.plist in Resources */ = {isa = PBXBuildFile; fileRef = 6CC89DD813F2F4E6003704F7 /* Entitlements.plist */; }; 6CC89DDF13F31413003704F7 /* TutorialMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 6CC89DDE13F31413003704F7 /* TutorialMode.m */; }; 6CDBE80C14092DB00072F287 /* ledge.png in Resources */ = {isa = PBXBuildFile; fileRef = 6CDBE80B14092DB00072F287 /* ledge.png */; }; @@ -459,6 +460,8 @@ 6C85834314055B2E009EF100 /* notificationDesign.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = notificationDesign.m; sourceTree = ""; }; 6C85834514056E57009EF100 /* venice.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = venice.png; sourceTree = ""; }; 6C88B69314119B5A0049E402 /* libTestFlight.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libTestFlight.a; sourceTree = ""; }; + 6C91A8761697745A00939EA1 /* ScoreBarLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScoreBarLayer.h; sourceTree = ""; }; + 6C91A8771697745A00939EA1 /* ScoreBarLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ScoreBarLayer.m; sourceTree = ""; }; 6CB532581403BA4F00780A5E /* GameModeSelectionDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameModeSelectionDelegate.h; sourceTree = ""; }; 6CC89DD813F2F4E6003704F7 /* Entitlements.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Entitlements.plist; sourceTree = ""; }; 6CC89DDD13F31413003704F7 /* TutorialMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TutorialMode.h; sourceTree = ""; }; @@ -778,6 +781,8 @@ 3F03221813D7904E00E6A708 /* Highscore.m */, 6C29040E13EAEB590032DA0F /* TutorialBubble.h */, 6C29040F13EAEB590032DA0F /* TutorialBubble.m */, + 6C91A8761697745A00939EA1 /* ScoreBarLayer.h */, + 6C91A8771697745A00939EA1 /* ScoreBarLayer.m */, ); path = Classes; sourceTree = ""; @@ -1545,6 +1550,7 @@ 6CF64C1D141BFA9600F3B702 /* FallingObjectFactory.m in Sources */, 6CE5F7EA1483FAC8008E9ADA /* GameModeInfo.m in Sources */, 6CE5F7EE14855331008E9ADA /* GameModeManager.m in Sources */, + 6C91A8781697745A00939EA1 /* ScoreBarLayer.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Classes/ClassicGameMode.h b/Classes/ClassicGameMode.h index 898a5e7..018588d 100755 --- a/Classes/ClassicGameMode.h +++ b/Classes/ClassicGameMode.h @@ -12,9 +12,16 @@ #import "FallingObjectDelegate.h" @interface ClassicGameMode : GameMode { + int score; + int lives; + CCLabelBMFont* scoreLabel; + CCLabelBMFont* livesLabel; + float addSpeed; } +@property (nonatomic) int score; +@property (nonatomic) int lives; - (id)init; - (void)randomlyAddObject:(ccTime)dt; diff --git a/Classes/ClassicGameMode.m b/Classes/ClassicGameMode.m index e9085f2..0dabbdc 100755 --- a/Classes/ClassicGameMode.m +++ b/Classes/ClassicGameMode.m @@ -10,9 +10,12 @@ #import "FallingObject.h" #import "GameOverScene.h" #import "SimpleAudioEngine.h" +#import "ScoreBarLayer.h" @implementation ClassicGameMode +@synthesize score, lives; + typedef enum { kCherryObject = 0, kEnergyDrinkObject, @@ -181,9 +184,26 @@ static GameModeInfo* info; CCSprite* backgroundImage = [CCSprite spriteWithFile:@"SeaBeach.png"]; backgroundImage.position = ccp(240, 160); [self addChild:backgroundImage z:-1]; - + + score = 0; + lives = 3; addSpeed = 2.5f; + ScoreBarLayer* scoreBar = [ScoreBarLayer scoreBar]; + [self addChild:scoreBar]; + + scoreLabel = [CCLabelBMFont labelWithString:@"0" fntFile:@"helvetica2.fnt"]; + scoreLabel.position = ccp(30,20); + [scoreBar addChild:scoreLabel]; + + CCSprite* livesImage = [CCSprite spriteWithFile:@"oneup.png"]; + livesImage.position = ccp(110, 20); + [scoreBar addChild:livesImage]; + + livesLabel = [CCLabelBMFont labelWithString:@"x3" fntFile:@"helvetica2.fnt"]; + livesLabel.position = ccp(142,20); + [scoreBar addChild:livesLabel]; + [objectFactory createRecipeWithIdentifier:kCherryObject spriteFilename:@"cherry.png" weight:5]; [objectFactory createRecipeWithIdentifier:kEnergyDrinkObject spriteFilename:@"bottle.png" weight:6]; [objectFactory createRecipeWithIdentifier:kOneUpObject spriteFilename:@"oneup.png" weight:10]; @@ -230,4 +250,18 @@ static GameModeInfo* info; } } +- (void)setScore:(int)m_score +{ + score = m_score; + + [scoreLabel setString:[NSString stringWithFormat:@"%d", score]]; +} + +- (void)setLives:(int)m_lives +{ + lives = m_lives; + + [livesLabel setString:[NSString stringWithFormat:@"x%d", lives]]; +} + @end diff --git a/Classes/GameMode.h b/Classes/GameMode.h index ae3fbe5..6421099 100644 --- a/Classes/GameMode.h +++ b/Classes/GameMode.h @@ -17,10 +17,7 @@ @interface GameMode : CCLayer { NSMutableSet* objects; - int score; - int lives; - int pointMultiplier; - Cart* cart; + Cart* cart; FallingObjectFactory* objectFactory; CCLayerColor* willPauseLayer; @@ -29,9 +26,6 @@ BOOL isPaused; BOOL isPausing; - CCLabelBMFont* scoreLabel; - CCLabelBMFont* livesLabel; - void (^delayedAction)(void); BOOL hasGyroscope; @@ -43,10 +37,6 @@ } @property (readonly) Cart* cart; -@property (nonatomic,assign) int score; -@property (nonatomic,assign) int lives; -@property (nonatomic,assign) int pointMultiplier; -@property (readonly) BOOL isPaused; - (void)tick:(ccTime)dt; - (BOOL)canPause; - (void)pause; diff --git a/Classes/GameMode.m b/Classes/GameMode.m index ca269cd..956e512 100644 --- a/Classes/GameMode.m +++ b/Classes/GameMode.m @@ -12,7 +12,7 @@ @implementation GameMode -@synthesize cart, score, lives, isPaused, pointMultiplier; +@synthesize cart; - (id)init { @@ -28,18 +28,6 @@ cart.delegate = self; [self addChild:cart.sprite]; - scoreLabel = [CCLabelBMFont labelWithString:@"Score: 0" fntFile:@"helvetica2.fnt"]; - scoreLabel.position = ccp(50, 300); - [self addChild:scoreLabel]; - - livesLabel = [CCLabelBMFont labelWithString:@"Lives: 3" fntFile:@"helvetica2.fnt"]; - livesLabel.position = ccp(50, 280); - [self addChild:livesLabel]; - - score = 0; - lives = 3; - pointMultiplier = 1; - objectFactory = [[FallingObjectFactory alloc] init]; isPaused = NO; @@ -187,37 +175,6 @@ [alert release]; } -- (void)setScore:(int)m_score -{ - score = m_score; - - if (pointMultiplier > 1) - { - [scoreLabel setString:[NSString stringWithFormat:@"Score: %d x%d", score, pointMultiplier]]; - } else { - [scoreLabel setString:[NSString stringWithFormat:@"Score: %d", score]]; - } -} - -- (void)setLives:(int)m_lives -{ - lives = m_lives; - - [livesLabel setString:[NSString stringWithFormat:@"Lives: %d", lives]]; -} - -- (void)setPointMultiplier:(int)m_pointMultiplier -{ - pointMultiplier = m_pointMultiplier; - - if (pointMultiplier > 1) - { - [scoreLabel setString:[NSString stringWithFormat:@"Score: %d x%d", score, pointMultiplier]]; - } else { - [scoreLabel setString:[NSString stringWithFormat:@"Score: %d", score]]; - } -} - - (void)scheduleDelayedAction:(void(^)(void))m_delayedAction delay:(float)delay { delayedAction = Block_copy([m_delayedAction retain]); diff --git a/Classes/JumpGameMode.h b/Classes/JumpGameMode.h index a09bbea..7502a28 100644 --- a/Classes/JumpGameMode.h +++ b/Classes/JumpGameMode.h @@ -23,8 +23,18 @@ int ledgeScrollSpeed; float ledgeAccelerationRate; float addSpeed; + + int score; + int lives; + int pointMultiplier; + CCLabelBMFont* scoreLabel; + CCLabelBMFont* livesLabel; + CCLabelBMFont* pointMultiplierLabel; } +@property (nonatomic) int score; +@property (nonatomic) int lives; +@property (nonatomic) int pointMultiplier; - (void)accelerateGame; - (void)randomlyAddObject:(ccTime)dt; - (void)incrementScore; diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m index f0cb469..af51a70 100644 --- a/Classes/JumpGameMode.m +++ b/Classes/JumpGameMode.m @@ -10,6 +10,7 @@ #import "SimpleAudioEngine.h" #import "FallingObject.h" #import "GameOverScene.h" +#import "ScoreBarLayer.h" #define kMinimumGestureLength 25 @@ -41,6 +42,8 @@ @implementation JumpGameMode +@synthesize score, lives, pointMultiplier; + typedef enum { kRockObject = 0, kOneUpObject, @@ -75,6 +78,33 @@ static GameModeInfo* info; backgroundImage.position = ccp(240, 160); [self addChild:backgroundImage z:-1]; + score = 0; + lives = 3; + pointMultiplier = 1; + + ScoreBarLayer* scoreBar = [ScoreBarLayer scoreBar]; + [self addChild:scoreBar]; + + scoreLabel = [CCLabelBMFont labelWithString:@"0" fntFile:@"helvetica2.fnt"]; + scoreLabel.position = ccp(30,20); + [scoreBar addChild:scoreLabel]; + + CCSprite* livesImage = [CCSprite spriteWithFile:@"oneup.png"]; + livesImage.position = ccp(110, 20); + [scoreBar addChild:livesImage]; + + livesLabel = [CCLabelBMFont labelWithString:@"x3" fntFile:@"helvetica2.fnt"]; + livesLabel.position = ccp(142,20); + [scoreBar addChild:livesLabel]; + + CCSprite* pointMultiplierImage = [CCSprite spriteWithFile:@"multiplier.png"]; + pointMultiplierImage.position = ccp(190, 20); + [scoreBar addChild:pointMultiplierImage]; + + pointMultiplierLabel = [CCLabelBMFont labelWithString:@"x1" fntFile:@"helvetica2.fnt"]; + pointMultiplierLabel.position = ccp(222,20); + [scoreBar addChild:pointMultiplierLabel]; + water = [CCSprite spriteWithFile:@"water.png"]; water.position = ccp(240, -60); [self addChild:water]; @@ -491,16 +521,30 @@ static GameModeInfo* info; [self setScore:self.score+pointMultiplier]; } -- (void)setLives:(int)m_lives +- (void)setScore:(int)m_score { - int oldLives = lives; - - [super setLives:m_lives]; + score = m_score; - if (oldLives > lives) + [scoreLabel setString:[NSString stringWithFormat:@"%d", score]]; +} + +- (void)setLives:(int)m_lives +{ + if (m_lives < lives) { [self setPointMultiplier:1]; } + + lives = m_lives; + + [livesLabel setString:[NSString stringWithFormat:@"x%d", lives]]; +} + +- (void)setPointMultiplier:(int)m_pointMultiplier +{ + pointMultiplier = m_pointMultiplier; + + [pointMultiplierLabel setString:[NSString stringWithFormat:@"x%d", pointMultiplier]]; } - (void)didCatchItem:(FallingObject *)item diff --git a/Classes/ScoreBarLayer.h b/Classes/ScoreBarLayer.h new file mode 100644 index 0000000..4102f73 --- /dev/null +++ b/Classes/ScoreBarLayer.h @@ -0,0 +1,19 @@ +// +// ScoreBarLayer.h +// Cartographic +// +// Created by Starla Insigna on 1/4/13. +// Copyright 2013 __MyCompanyName__. All rights reserved. +// + +#import +#import "cocos2d.h" + +@interface ScoreBarLayer : CCLayerGradient { + +} + ++ (ScoreBarLayer*)scoreBar; +- (id)init; + +@end diff --git a/Classes/ScoreBarLayer.m b/Classes/ScoreBarLayer.m new file mode 100644 index 0000000..b838ac9 --- /dev/null +++ b/Classes/ScoreBarLayer.m @@ -0,0 +1,41 @@ +// +// ScoreBarLayer.m +// Cartographic +// +// Created by Starla Insigna on 1/4/13. +// Copyright 2013 __MyCompanyName__. All rights reserved. +// + +#import "ScoreBarLayer.h" + + +@implementation ScoreBarLayer + ++ (ScoreBarLayer*)scoreBar +{ + return [[[ScoreBarLayer alloc] init] autorelease]; +} + +- (id)init +{ + self = [super initWithColor:ccc4(101, 214, 253, 255) fadingTo:ccc4(0, 104, 248, 255)]; + + if (nil != self) + { + [self changeWidth:480 height:40]; + self.position = ccp(0, 280); + } + + return self; +} + +- (void)draw +{ + [super draw]; + + glEnable(GL_LINE_SMOOTH); + glColor4ub(0, 0, 0, 255); + ccDrawLine(ccp(0,0), ccp(480,0)); +} + +@end diff --git a/Classes/TutorialMode.h b/Classes/TutorialMode.h index 697c688..160e6bc 100644 --- a/Classes/TutorialMode.h +++ b/Classes/TutorialMode.h @@ -14,9 +14,16 @@ TutorialBubble* currentTutorial; BOOL showedDeathBubble; int randomItemsDropped; + + int score; + int lives; + CCLabelBMFont* scoreLabel; + CCLabelBMFont* livesLabel; } @property (nonatomic,retain) TutorialBubble* currentTutorial; +@property (nonatomic) int score; +@property (nonatomic) int lives; - (void)endTutorial; - (FallingObject*)dropSpecificItem:(int)objectType; - (FallingObject*)dropRandomItem; diff --git a/Classes/TutorialMode.m b/Classes/TutorialMode.m index 3f37505..17d9412 100644 --- a/Classes/TutorialMode.m +++ b/Classes/TutorialMode.m @@ -12,6 +12,7 @@ #import "SimpleAudioEngine.h" #import "ClassicGameMode.h" #import "JumpGameMode.h" +#import "ScoreBarLayer.h" // Item tags: // 2000 - first dropped item @@ -30,7 +31,7 @@ typedef enum { @implementation TutorialMode -@synthesize currentTutorial; +@synthesize currentTutorial, lives, score; static GameModeInfo* info; @@ -60,9 +61,27 @@ static GameModeInfo* info; backgroundImage.position = ccp(240, 160); [self addChild:backgroundImage z:-1]; + score = 0; + lives = 3; + showedDeathBubble = NO; randomItemsDropped = 0; + ScoreBarLayer* scoreBar = [ScoreBarLayer scoreBar]; + [self addChild:scoreBar]; + + scoreLabel = [CCLabelBMFont labelWithString:@"0" fntFile:@"helvetica2.fnt"]; + scoreLabel.position = ccp(30,20); + [scoreBar addChild:scoreLabel]; + + CCSprite* livesImage = [CCSprite spriteWithFile:@"oneup.png"]; + livesImage.position = ccp(110, 20); + [scoreBar addChild:livesImage]; + + livesLabel = [CCLabelBMFont labelWithString:@"x3" fntFile:@"helvetica2.fnt"]; + livesLabel.position = ccp(142,20); + [scoreBar addChild:livesLabel]; + [objectFactory createRecipeWithIdentifier:kCherryObject spriteFilename:@"cherry.png" weight:5]; [objectFactory createRecipeWithIdentifier:kEnergyDrinkObject spriteFilename:@"bottle.png" weight:6]; [objectFactory createRecipeWithIdentifier:kOneUpObject spriteFilename:@"oneup.png" weight:10]; @@ -397,4 +416,19 @@ static GameModeInfo* info; randomItemsDropped++; } + +- (void)setScore:(int)m_score +{ + score = m_score; + + [scoreLabel setString:[NSString stringWithFormat:@"%d", score]]; +} + +- (void)setLives:(int)m_lives +{ + lives = m_lives; + + [livesLabel setString:[NSString stringWithFormat:@"x%d", lives]]; +} + @end -- cgit 1.4.1