Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
basic score display
Browse files Browse the repository at this point in the history
  • Loading branch information
biou committed Feb 12, 2014
1 parent 59a4e82 commit 4dae230
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 72 deletions.
2 changes: 2 additions & 0 deletions GGJ13/GGJ13/WHBasicLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define whCredits 1
#define whWin 2
#define whNewLevel 2
#define whDisconnect 3
//#define whHelp 3

@interface WHBasicLayer : CCLayer {
Expand All @@ -28,5 +29,6 @@

// returns a CCScene that contains the WHBasicLayer layer as the only child
+(CCScene *) scene:(int)m;
+(CCScene *) scene:(int) m withScore:(int) s andTime:(int)t;

@end
100 changes: 35 additions & 65 deletions GGJ13/GGJ13/WHBasicLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@


static int mode;
static int score;
static int timeBonus;

@implementation WHBasicLayer

Expand All @@ -28,6 +30,23 @@ +(CCScene *) scene:(int) m
return scene;
}

+(CCScene *) scene:(int) m withScore:(int) s andTime:(int)t
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];

// 'layer' is an autorelease object.
mode = m;
score = s;
timeBonus = t;
WHBasicLayer * baseLayer = [[WHBasicLayer alloc] init];

[scene addChild: baseLayer];

// return the scene
return scene;
}


- (id)init {
self = [super init];
Expand Down Expand Up @@ -69,65 +88,24 @@ - (id)init {

bgpic.position = ccp(winsize.width/2 , winsize.height/2 );
[self addChild:bgpic];

/*
if (mode == whGameover) {
//WHScore * s = [WHScore sharedInstance];
//int t = [s getScore];
//s.vomis = [NSMutableArray array];
//[[GCHelper sharedInstance] reportScore:t forCategory:@"WHScore1"];
int total = score + timeBonus * 10;
CGSize winsize = [CCDirector sharedDirector].winSize;
int fontSize = 16;
CCLabelTTF *sLabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"Points: %d", score] fontName:@"DBLCDTempBlack" fontSize:fontSize];
[sLabel setColor:ccc3(181, 216, 19)];
[sLabel setPosition: ccp(winsize.width/2, 60)];
[self addChild: sLabel];
CCLabelTTF *tLabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"Time: %ds x 10", timeBonus] fontName:@"DBLCDTempBlack" fontSize:fontSize];
[tLabel setColor:ccc3(181, 216, 19)];
[tLabel setPosition: ccp(winsize.width/2, 40)];
[self addChild: tLabel];
CCLabelTTF *fLabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"Total: %d", total] fontName:@"DBLCDTempBlack" fontSize:fontSize];
[fLabel setColor:ccc3(181, 216, 19)];
[fLabel setPosition: ccp(winsize.width/2, 20)];
[self addChild: fLabel];
}
if (mode != whCredits && mode != whHelp)
{
WHScore * s = [WHScore sharedInstance];
int newScore = [s getScore] + [s getTime]*100;
NSString * str = nil;
int fontSize = 0;
CGPoint labelPos;
if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ) {
fontSize = 21;
labelPos = ccp(winsize.width/2, winsize.height-20);
} else {
fontSize = 42;
labelPos = ccp(winsize.width/2, winsize.height-50);
}
if (mode == whGameover) {
str = [NSString stringWithFormat:@"Score: %d", [s getScore]];
} else {
str = [NSString stringWithFormat:@"Score: %d + %d x 100 = %d", [s getScore], [s getTime], newScore];
[s setScore:newScore];
}
CCLabelTTF *label = [CCLabelTTF labelWithString:str fontName:@"Chalkduster" fontSize:fontSize];
[label setPosition: labelPos];
[self addChild: label];
}
if (mode == whNewLevel)
{
WHScore * s = [WHScore sharedInstance];
[s incrementLevel];
int t = [s getLevel];
[s setTime:90];
int fontSize = 0;
CGPoint labelPos;
if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ) {
fontSize = 32;
labelPos = ccp(winsize.width/2, 20);
} else {
fontSize = 64;
labelPos = ccp(winsize.width/2, 50);
}
NSString * str = [NSString stringWithFormat:@"Level %d", t];
CCLabelTTF *label = [CCLabelTTF labelWithString:str fontName:@"Chalkduster" fontSize:fontSize];
[label setPosition: labelPos];
[self addChild: label];
}
*/



BBAudioManager *audioManager = [BBAudioManager sharedAM];
[audioManager stopBGM];
Expand Down Expand Up @@ -174,14 +152,6 @@ - (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
case whWin:
[[CCDirector sharedDirector] replaceScene: [CCTransitionFade transitionWithDuration:0.5f scene:[WHMenuLayer scene]]];
break;
/*
case whHelp:
[[CCDirector sharedDirector] replaceScene: [CCTransitionFade transitionWithDuration:0.5f scene:[WHGameScene node]]];
break;
case whNewLevel:
[[CCDirector sharedDirector] replaceScene: [CCTransitionFade transitionWithDuration:0.5f scene:[WHGameScene node]]];
break;
*/
default:
break;
}
Expand Down
4 changes: 4 additions & 0 deletions GGJ13/GGJ13/WHGameLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ -(void)touchBoutonX: (float)bx withNumber: (int)n
} else {
[[self.boutons objectAtIndex:n] setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"bouton-on-no.png"]];
BBAudioManager * am = [BBAudioManager sharedAM];

[self.gameScene incrementScore:-5];
[am playSFX:@"buzz.caf"];
[self itemMissed:YES];
Expand Down Expand Up @@ -394,6 +395,9 @@ -(void)itemMissed:(BOOL)bigMiss {
[self.gameScene updateJaugeWith:0];

int penalty = bigMiss?2:1;
int time = [self.gameScene getTime];

penalty = ((time/60)+1) * penalty;
if ([self.gameScene getGameBPM] < BPM_MEDIAN) {
penalty = -penalty;
}
Expand Down
1 change: 1 addition & 0 deletions GGJ13/GGJ13/WHGameScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ typedef enum {
-(void) displayMessage:(int)m;
-(void) executeNewZique;
-(void) incrementScore:(int)i;
-(int) getTime;

+(WHGameScene *) scene:(int)m;

Expand Down
19 changes: 12 additions & 7 deletions GGJ13/GGJ13/WHGameScene.mm
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ - (void)socket:(GCDAsyncSocket *)sender didReadData:(NSData *)data withTag:(long
-(void)mange:(int)m {
switch (m) {
case ItemTypeGHB:
[self displayMessage:2];
NSLog(@"TODO Score à zéro pour cause de GHB");
[self displayMessage:3];
break;

case ItemTypeLSD:
Expand Down Expand Up @@ -466,6 +465,7 @@ -(void) setScore:(int)s {
}

-(void) incrementScore:(int)i {

i *= scoreFactor;
if (score+i < 0) {
[self setScore:0];
Expand All @@ -474,6 +474,11 @@ -(void) incrementScore:(int)i {
}
}

-(int) getTime
{
return secondsSinceStart;
}

-(void) updateHeaderScore {
[headerLayer removeChildByTag:12 cleanup:true];
CGSize winsize = [CCDirector sharedDirector].winSize;
Expand All @@ -485,13 +490,13 @@ -(void) updateHeaderScore {
}

-(void) updateHeaderTime {
[headerLayer removeChildByTag:13 cleanup:true];
[headerLayer removeChildByTag:16 cleanup:true];
CGSize winsize = [CCDirector sharedDirector].winSize;
int fontSize = 16;
CCLabelTTF *label = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"%02d:%02d", secondsSinceStart/60, secondsSinceStart % 60] fontName:@"DBLCDTempBlack" fontSize:fontSize];
[label setColor:ccc3(181, 216, 19)];
[label setPosition: ccp(winsize.width-60, winsize.height-34)];
[headerLayer addChild: label z:1 tag:13];
[headerLayer addChild: label z:1 tag:16];
}

-(void) updateJaugeWith:(int)statut {
Expand Down Expand Up @@ -821,14 +826,14 @@ - (void)endScene:(EndReason)endReason {
}
if (endReason == kEndReasonWin) {
NSLog(@"win");
[[CCDirector sharedDirector] replaceScene: [CCTransitionFade transitionWithDuration:0.5f scene: [WHBasicLayer scene:whWin]]];
[[CCDirector sharedDirector] replaceScene: [CCTransitionFade transitionWithDuration:0.5f scene: [WHBasicLayer scene:whWin withScore:score andTime:secondsSinceStart]]];
} else if (endReason == kEndReasonLose) {
NSLog(@"lose");
[[CCDirector sharedDirector] replaceScene: [CCTransitionFade transitionWithDuration:0.5f scene: [WHBasicLayer scene:whGameover]]];
[[CCDirector sharedDirector] replaceScene: [CCTransitionFade transitionWithDuration:0.5f scene: [WHBasicLayer scene:whGameover withScore:score andTime:secondsSinceStart]]];
} else if (endReason == kEndReasonDisconnect) {
NSLog(@"disconnect");
// FIXME disconnect screen
[[CCDirector sharedDirector] replaceScene: [CCTransitionFade transitionWithDuration:0.5f scene: [WHBasicLayer scene:whGameover]]];
[[CCDirector sharedDirector] replaceScene: [CCTransitionFade transitionWithDuration:0.5f scene: [WHBasicLayer scene:whDisconnect]]];
}

}
Expand Down

0 comments on commit 4dae230

Please sign in to comment.