From ab9f7381455b334fa0df563e21775410be74ea45 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sat, 10 Sep 2011 10:04:18 -0400 Subject: Added point multipliers There is support for point multipliers for any game mode, but only Jump currently utilizes it. Closes #222 --- Classes/GameMode.h | 2 ++ Classes/GameMode.m | 22 ++++++++++++++++++++-- Classes/JumpGameMode.m | 46 +++++++++++++++++++++++++--------------------- Classes/PointMultiplier.h | 15 +++++++++++++++ Classes/PointMultiplier.m | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+), 23 deletions(-) create mode 100644 Classes/PointMultiplier.h create mode 100644 Classes/PointMultiplier.m (limited to 'Classes') diff --git a/Classes/GameMode.h b/Classes/GameMode.h index 0659a57..e82ad10 100644 --- a/Classes/GameMode.h +++ b/Classes/GameMode.h @@ -16,6 +16,7 @@ NSMutableSet* objects; int score; int lives; + int pointMultiplier; Cart* cart; CCLayerColor* shadedLayer; @@ -32,6 +33,7 @@ @property (readonly) Cart* cart; @property (nonatomic,assign) int score; @property (nonatomic,assign) int lives; +@property (nonatomic,assign) int pointMultiplier; @property (readonly) BOOL isPaused; + (CCScene*)scene; - (void)tick:(ccTime)dt; diff --git a/Classes/GameMode.m b/Classes/GameMode.m index f0eb02f..1e80237 100644 --- a/Classes/GameMode.m +++ b/Classes/GameMode.m @@ -12,7 +12,7 @@ @implementation GameMode -@synthesize cart, score, lives, isPaused; +@synthesize cart, score, lives, isPaused, pointMultiplier; + (CCScene*)scene { @@ -53,6 +53,7 @@ score = 0; lives = 3; + pointMultiplier = 1; if ([self canPause]) { @@ -159,7 +160,12 @@ { score = m_score; - [scoreLabel setString:[NSString stringWithFormat:@"Score: %d", 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 @@ -169,6 +175,18 @@ [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.m b/Classes/JumpGameMode.m index 0cf916a..9076426 100644 --- a/Classes/JumpGameMode.m +++ b/Classes/JumpGameMode.m @@ -14,6 +14,7 @@ #import "OneUp.h" #import "Rock.h" #import "GameOverScene.h" +#import "PointMultiplier.h" #define kMinimumGestureLength 25 @@ -308,26 +309,17 @@ { FallingObject* object; - if (score < 120) - { - int randomval = arc4random()%100; - - if (randomval < 80) - { - object = [[Rock alloc] init]; - } else { - object = [[OneUp alloc] init]; - } - } else { - int randomval = arc4random()%100; - - if (randomval < 70) - { - object = [[Rock alloc] init]; - } else { - object = [[OneUp alloc] init]; - } - } + int randomval = arc4random()%100; + + if (randomval < 50) + { + object = [[Rock alloc] init]; + } else if (randomval < 75) + { + object = [[PointMultiplier alloc] init]; + } else { + object = [[OneUp alloc] init]; + } int objectX; @@ -434,7 +426,19 @@ - (void)incrementScore { - [self setScore:self.score+1]; + [self setScore:self.score+pointMultiplier]; +} + +- (void)setLives:(int)m_lives +{ + int oldLives = lives; + + [super setLives:m_lives]; + + if (oldLives > lives) + { + [self setPointMultiplier:1]; + } } @end diff --git a/Classes/PointMultiplier.h b/Classes/PointMultiplier.h new file mode 100644 index 0000000..9d009cb --- /dev/null +++ b/Classes/PointMultiplier.h @@ -0,0 +1,15 @@ +// +// PointMultiplier.h +// Cartographic +// +// Created by Starla Insigna on 9/10/11. +// Copyright (c) 2011 Four Island. All rights reserved. +// + +#import "FallingObject.h" + +@interface PointMultiplier : FallingObject + +- (id)init; + +@end diff --git a/Classes/PointMultiplier.m b/Classes/PointMultiplier.m new file mode 100644 index 0000000..a14bf68 --- /dev/null +++ b/Classes/PointMultiplier.m @@ -0,0 +1,36 @@ +// +// PointMultiplier.m +// Cartographic +// +// Created by Starla Insigna on 9/10/11. +// Copyright (c) 2011 Four Island. All rights reserved. +// + +#import "PointMultiplier.h" +#import "GameMode.h" +#import "SimpleAudioEngine.h" + +@implementation PointMultiplier + +- (id)init +{ + self = [super init]; + + if (nil != self) + { + sprite = [CCSprite spriteWithFile:@"multiplier.png"]; + weight = 8; + } + + return self; +} + +- (void)collideWithCart +{ + GameMode* gameLayer = ((GameMode*) sprite.parent); + [gameLayer setPointMultiplier:gameLayer.pointMultiplier+1]; + + [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]]; +} + +@end -- cgit 1.4.1