

#import "GameOver.h"
#import "Menu.h"
#import "GameScene.h"

@implementation GameOver
{
    int score;
    int BestScore;
    int gameMode;
    
    SKLabelNode * playAgain;
    SKLabelNode * backToMenu;
    
    SKLabelNode * BestScoreLabel;
    SKLabelNode * ScoreLabel;
    
    
    
}

-(void) didMoveToView:(SKView *)view
{
    [self removeAllActions];
    
    SKAction * gameOverSound         = [SKAction playSoundFileNamed:@"gameOverSound.wav" waitForCompletion:YES];
    [self runAction:gameOverSound];
    
    SKSpriteNode * BackGround        = [SKSpriteNode spriteNodeWithImageNamed:@"bg.png"];
    BackGround.position              = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
    [BackGround setScale:1];
    BackGround.zPosition             = 0;
    
    SKLabelNode * gameOverLabel      = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
    gameOverLabel.fontSize           = 80;
    gameOverLabel.position           = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)+170);
    gameOverLabel.text = @"Game Over";
    
    
    
    BestScoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
    NSString *bstsco    = [NSString stringWithFormat:@"Best: %d", BestScore];
    BestScoreLabel.text          = bstsco;
    BestScoreLabel.position = CGPointMake(CGRectGetMidX(self.frame)-200, CGRectGetMidY(self.frame));
    BestScoreLabel.fontSize = 50;
    
    
    ScoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
    NSString *sco    = [NSString stringWithFormat:@"Score: %d", score];
    ScoreLabel.text          = sco;
    ScoreLabel.position = CGPointMake(CGRectGetMidX(self.frame)+200, CGRectGetMidY(self.frame));
    ScoreLabel.fontSize = 50;
    
   
    
    playAgain                        = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
    playAgain.fontSize               = 60;
    playAgain .position              = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)-150);
    playAgain.text                   = @"Play Again";
    
    backToMenu                       = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
    backToMenu.fontSize              = 60;
    backToMenu.position              = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)-250);
    backToMenu.text                  = @"Back To Menu";
    
    [self addChild:BackGround];
    [self addChild:playAgain];
    [self addChild:backToMenu];
    [self addChild:gameOverLabel];
    [self addChild:BestScoreLabel];
    [self addChild:ScoreLabel];
    
    //Criação de botões e Labels
    
    if(score==BestScore)
    {
        
        
    }
    
    
}

-(void)getScore:(int)SC getBestScore:(int)BS getMode:(int)GM//Função que recebe Score atual, Best Score e o Modo de Jogo
{
    score     = SC;
    BestScore = BS;
    gameMode  = GM;
    
    
}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    
    
    for (UITouch *touch in touches)
    {
        CGPoint location = [touch locationInNode:self];
        
        if([playAgain containsPoint:location])
        {
            
            GameScene        * inu = [[GameScene alloc]initWithSize:self.size];
            inu.scaleMode = SKSceneScaleModeAspectFill;
            SKTransition *transition = [SKTransition fadeWithDuration:1];
            [self.view presentScene: inu transition:transition];
            
            
        }
        
        else if([backToMenu containsPoint:location])
        {
            
            Menu * m = [[Menu alloc]initWithSize:self.size];
            SKTransition * trans = [SKTransition fadeWithDuration:1];
            m.scaleMode = SKSceneScaleModeAspectFill;
            [self.view presentScene:m transition:trans];
            
        }
        
        
    }
    
    
    
    
}



@end
