Advertisement
Guest User

Untitled

a guest
Mar 5th, 2014
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #import "GameOverScene.h"
  3. #import "NHRScore.h"
  4. #import "MyScene.h"
  5. #import "MainMenuScene.h"
  6. #import "NHRShop.h"
  7.  
  8. @interface GameOverScene()
  9. @property CGRect playButtonRect;
  10. @property CGRect menuButtonRect;
  11. /*{
  12.     CGRect playButtonRect;
  13.     CGRect menuButtonRect;
  14. } */
  15. @end
  16.  
  17. @implementation GameOverScene
  18.  
  19. @synthesize playButtonRect;
  20. @synthesize menuButtonRect;
  21.  
  22.     -(id)initWithSize:(CGSize)size {
  23.         if (self = [super initWithSize:size]) {
  24.             /* Setup your scene here */
  25.            
  26.             //This label shows the score number
  27.             SKLabelNode *scoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Helvetica"];
  28.             //Get an instance of my custom scoring storage class -- this has the data for the score from the previous game
  29.             NHRScore *scoreController = [[NHRScore alloc]init];
  30.             //The simple int-to-NSString converter.
  31.             int scoreForLabel = [scoreController getUserScore];
  32.             NSString *scoreStringForLabel = [NSString stringWithFormat:@"%d",scoreForLabel];
  33.             scoreLabel.text = scoreStringForLabel;
  34.             scoreLabel.fontColor = [UIColor colorWithRed:0.25 green:0.25 blue:0.85 alpha:0.75];
  35.             //The order the labels are in here DOES NOT match the order they are laid out in the scene.
  36.             //Use the label text for guidance.
  37.            
  38.             //set the position of the label
  39.             scoreLabel.position = CGPointMake(self.frame.size.width/2,self.frame.size.height-125);
  40.             //and render it
  41.             [self addChild:scoreLabel];
  42.            
  43.             //This label shows "Score:"
  44.             SKLabelNode *prettyScoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Helvetica"];
  45.             prettyScoreLabel.text = @"Score:";
  46.             prettyScoreLabel.position = CGPointMake(self.frame.size.width/2, self.frame.size.height-95);
  47.             prettyScoreLabel.fontColor = [UIColor colorWithRed:0.25 green:0.25 blue:0.85 alpha:0.75];
  48.             [self addChild:prettyScoreLabel];
  49.            
  50.             //idk why the background color is all the way down here...
  51.             //This makes a purdy purple color similar to Xcodes purple code highlighting
  52.             //self.backgroundColor = [SKColor colorWithRed:0.5 green:0.0 blue:0.7 alpha:1.0];
  53.             //We actually want the BG white:
  54.             self.backgroundColor = [SKColor colorWithWhite:1.0 alpha:1.0];
  55.             //The game over label
  56.             //we need to find a new place for this, the iAd covers it
  57.             SKLabelNode *gameOverLabel = [SKLabelNode labelNodeWithFontNamed:@"Helvetica"];
  58.             gameOverLabel.text = @"Game over!";
  59.             gameOverLabel.position = CGPointMake(self.frame.size.width/2, prettyScoreLabel.position.y + 45);
  60.             gameOverLabel.fontColor = [UIColor colorWithRed:0.25 green:0.25 blue:0.85 alpha:0.75];
  61.             [self addChild:gameOverLabel];
  62.            
  63.             //High score label, look at the normal score labels comments for more info
  64.             SKLabelNode *highScoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Helvetica"];
  65.             int highScore = [scoreController getHighScore];
  66.             NSString *highScoreForLabel = [NSString stringWithFormat:@"%d", highScore];
  67.             highScoreLabel.text = highScoreForLabel;
  68.             highScoreLabel.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2 + 15);
  69.             highScoreLabel.fontColor = [UIColor colorWithRed:0.25 green:0.25 blue:0.85 alpha:0.75];
  70.             [self addChild:highScoreLabel];
  71.            
  72.             //shows "high score:"
  73.             SKLabelNode *prettyHighScoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Helvetica"];
  74.             prettyHighScoreLabel.text = @"High score:";
  75.             prettyHighScoreLabel.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2 + 45);
  76.             prettyHighScoreLabel.fontColor = [UIColor colorWithRed:0.25 green:0.25 blue:0.85 alpha:0.75];
  77.             [self addChild:prettyHighScoreLabel];
  78.            
  79.             SKSpriteNode *playButton = [SKSpriteNode spriteNodeWithImageNamed:@"newPlayButton"];
  80.             playButton.position = CGPointMake(self.frame.size.width/3,self.frame.size.height/6);
  81.             playButtonRect = playButton.frame;
  82.             [self addChild:playButton];
  83.            
  84.             SKSpriteNode *menuButton = [SKSpriteNode spriteNodeWithImageNamed:@"menuButton"];
  85.             menuButton.position = CGPointMake(self.frame.size.width/3 + self.frame.size.width/3, self.frame.size.height/6);
  86.             menuButtonRect = menuButton.frame;
  87.             [self addChild:menuButton];
  88.            
  89.             //Shows the amount of money you have
  90.             NSInteger totalCurrency = [scoreController getTotalCurrency];
  91.             NSString *toDisplayForCurrency = [NSString stringWithFormat:@"%ld",(long)totalCurrency];
  92.             SKLabelNode *totalCurrencyLabel = [SKLabelNode labelNodeWithFontNamed:@"Helvetica"];
  93.             totalCurrencyLabel.text = toDisplayForCurrency;
  94.             totalCurrencyLabel.fontColor = [SKColor colorWithRed:0.25 green:0.25 blue:0.85 alpha:0.75];
  95.             totalCurrencyLabel.position = CGPointMake(self.frame.size.width/2, playButton.position.y + 100);
  96.             [self addChild:totalCurrencyLabel];
  97.            
  98.             //Shows "Money:"
  99.             SKLabelNode *moneyLabel = [SKLabelNode labelNodeWithFontNamed:@"Helvetica"];
  100.             moneyLabel.text = @"Money:";
  101.             moneyLabel.fontColor = [SKColor colorWithRed:0.25 green:0.25 blue:0.85 alpha:0.75];
  102.             moneyLabel.position = CGPointMake(self.frame.size.width/2, totalCurrencyLabel.position.y + 35);
  103.             [self addChild:moneyLabel];
  104.         }
  105.         return self;
  106.     }
  107.  
  108. -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  109.     /* Called when a touch begins */
  110.    
  111.     for (UITouch *touch in touches) {
  112.         CGPoint location = [touch locationInNode:self];
  113.         @autoreleasepool {
  114.            
  115.        
  116.         if(CGRectContainsPoint(playButtonRect, location)) {
  117.             //Go back to gameplay scene
  118.             SKTransition *reveal = [SKTransition revealWithDirection:SKTransitionDirectionUp duration:1.5];
  119.             MyScene *newScene = [[MyScene alloc] initWithSize: CGSizeMake(self.frame.size.width,self.frame.size.height)];
  120.             [self.scene.view presentScene: newScene transition:reveal];
  121.            
  122.         } else if(CGRectContainsPoint(menuButtonRect, location)) {
  123.             SKTransition *reveal = [SKTransition revealWithDirection:SKTransitionDirectionUp duration:1.5];
  124.             MainMenuScene *newScene = [[MainMenuScene alloc] initWithSize:CGSizeMake(self.frame.size.width, self.frame.size.height)];
  125.             [self.scene.view presentScene:newScene transition:reveal];
  126.         } }
  127.                
  128.     }
  129. }
  130.  
  131. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement