//
//  TitleScreen.cpp
//  GlobalGameJam15
//
//  Created by Cesar Parent on 24/01/2015.
//  Copyright (c) 2015 Cesar Parent. All rights reserved.
//

#include "TitleScreen.h"
#include "Defines.h"
#include "MainMenu.h"

TitleScreen::TitleScreen(Game& game) : Scene(game, kGameWidth/2, kGameHeight/2)
{
	setAnchorPoint(0, 0);
	setPosition(0, 0);
	setXScale(2);
	setYScale(2);
	background = new SpriteNode("assets/uis/titlescreen.png");
	background->setPosition(kGameWidth/4, kGameHeight/4);
	addChild(background);
	
	Sound::playMusic("assets/sounds/music.wav");
	
	Resources::preloadSoundEffects({"assets/sounds/caught.wav", "assets/sounds/jump.wav"});
}

TitleScreen::~TitleScreen()
{
	delete background;
}

#pragma mark delegates

void TitleScreen::didEnterStack()
{
	Controls::setDelegate(this);
}

void TitleScreen::didLeaveStack()
{
	Controls::setDelegate(nullptr);
}

void TitleScreen::controllerButtonPressBegan(int controller, SDL_GameControllerButton button)
{
	if(button == SDL_CONTROLLER_BUTTON_START)
	{
		_game.pushScene(new MainMenu(_game));
	}
}

void TitleScreen::keyboardPressBegan(SDL_Scancode key)
{
	if(key == SDL_SCANCODE_RETURN)
	{
		_game.pushScene(new MainMenu(_game));
	}
	else if(key == SDL_SCANCODE_F)
	{
		_game.toggleFullScreen();
	}
}