#import "GameOverScene.h"
#import "NHRScore.h"
#import "MyScene.h"
#import "MainMenuScene.h"
#import "NHRShop.h"
@interface GameOverScene()
@property CGRect playButtonRect;
@property CGRect menuButtonRect;
/*{
CGRect playButtonRect;
CGRect menuButtonRect;
} */
@end
@implementation GameOverScene
@synthesize playButtonRect;
@synthesize menuButtonRect;
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
/* Setup your scene here */
//This label shows the score number
SKLabelNode *scoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Helvetica"];
//Get an instance of my custom scoring storage class -- this has the data for the score from the previous game
NHRScore *scoreController = [[NHRScore alloc]init];
//The simple int-to-NSString converter.
int scoreForLabel = [scoreController getUserScore];
NSString *scoreStringForLabel = [NSString stringWithFormat:@"%d",scoreForLabel];
scoreLabel.text = scoreStringForLabel;
scoreLabel.fontColor = [UIColor colorWithRed:0.25 green:0.25 blue:0.85 alpha:0.75];
//The order the labels are in here DOES NOT match the order they are laid out in the scene.
//Use the label text for guidance.
//set the position of the label
scoreLabel.position = CGPointMake(self.frame.size.width/2,self.frame.size.height-125);
//and render it
[self addChild:scoreLabel];
//This label shows "Score:"
SKLabelNode *prettyScoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Helvetica"];
prettyScoreLabel.text = @"Score:";
prettyScoreLabel.position = CGPointMake(self.frame.size.width/2, self.frame.size.height-95);
prettyScoreLabel.fontColor = [UIColor colorWithRed:0.25 green:0.25 blue:0.85 alpha:0.75];
[self addChild:prettyScoreLabel];
//idk why the background color is all the way down here...
//This makes a purdy purple color similar to Xcodes purple code highlighting
//self.backgroundColor = [SKColor colorWithRed:0.5 green:0.0 blue:0.7 alpha:1.0];
//We actually want the BG white:
self.backgroundColor = [SKColor colorWithWhite:1.0 alpha:1.0];
//The game over label
//we need to find a new place for this, the iAd covers it
SKLabelNode *gameOverLabel = [SKLabelNode labelNodeWithFontNamed:@"Helvetica"];
gameOverLabel.text = @"Game over!";
gameOverLabel.position = CGPointMake(self.frame.size.width/2, prettyScoreLabel.position.y + 45);
gameOverLabel.fontColor = [UIColor colorWithRed:0.25 green:0.25 blue:0.85 alpha:0.75];
[self addChild:gameOverLabel];
//High score label, look at the normal score labels comments for more info
SKLabelNode *highScoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Helvetica"];
int highScore = [scoreController getHighScore];
NSString *highScoreForLabel = [NSString stringWithFormat:@"%d", highScore];
highScoreLabel.text = highScoreForLabel;
highScoreLabel.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2 + 15);
highScoreLabel.fontColor = [UIColor colorWithRed:0.25 green:0.25 blue:0.85 alpha:0.75];
[self addChild:highScoreLabel];
//shows "high score:"
SKLabelNode *prettyHighScoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Helvetica"];
prettyHighScoreLabel.text = @"High score:";
prettyHighScoreLabel.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2 + 45);
prettyHighScoreLabel.fontColor = [UIColor colorWithRed:0.25 green:0.25 blue:0.85 alpha:0.75];
[self addChild:prettyHighScoreLabel];
SKSpriteNode *playButton = [SKSpriteNode spriteNodeWithImageNamed:@"newPlayButton"];
playButton.position = CGPointMake(self.frame.size.width/3,self.frame.size.height/6);
playButtonRect = playButton.frame;
[self addChild:playButton];
SKSpriteNode *menuButton = [SKSpriteNode spriteNodeWithImageNamed:@"menuButton"];
menuButton.position = CGPointMake(self.frame.size.width/3 + self.frame.size.width/3, self.frame.size.height/6);
menuButtonRect = menuButton.frame;
[self addChild:menuButton];
//Shows the amount of money you have
NSInteger totalCurrency = [scoreController getTotalCurrency];
NSString *toDisplayForCurrency = [NSString stringWithFormat:@"%ld",(long)totalCurrency];
SKLabelNode *totalCurrencyLabel = [SKLabelNode labelNodeWithFontNamed:@"Helvetica"];
totalCurrencyLabel.text = toDisplayForCurrency;
totalCurrencyLabel.fontColor = [SKColor colorWithRed:0.25 green:0.25 blue:0.85 alpha:0.75];
totalCurrencyLabel.position = CGPointMake(self.frame.size.width/2, playButton.position.y + 100);
[self addChild:totalCurrencyLabel];
//Shows "Money:"
SKLabelNode *moneyLabel = [SKLabelNode labelNodeWithFontNamed:@"Helvetica"];
moneyLabel.text = @"Money:";
moneyLabel.fontColor = [SKColor colorWithRed:0.25 green:0.25 blue:0.85 alpha:0.75];
moneyLabel.position = CGPointMake(self.frame.size.width/2, totalCurrencyLabel.position.y + 35);
[self addChild:moneyLabel];
}
return self;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];
@autoreleasepool {
if(CGRectContainsPoint(playButtonRect, location)) {
//Go back to gameplay scene
SKTransition *reveal = [SKTransition revealWithDirection:SKTransitionDirectionUp duration:1.5];
MyScene *newScene = [[MyScene alloc] initWithSize: CGSizeMake(self.frame.size.width,self.frame.size.height)];
[self.scene.view presentScene: newScene transition:reveal];
} else if(CGRectContainsPoint(menuButtonRect, location)) {
SKTransition *reveal = [SKTransition revealWithDirection:SKTransitionDirectionUp duration:1.5];
MainMenuScene *newScene = [[MainMenuScene alloc] initWithSize:CGSizeMake(self.frame.size.width, self.frame.size.height)];
[self.scene.view presentScene:newScene transition:reveal];
} }
}
}
@end