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 --- Classes/JumpGameMode.m | 54 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) (limited to 'Classes/JumpGameMode.m') 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 -- cgit 1.4.1