//	TimeAttack.h - The main TimeAttack game mode.
//  ----------------------------------------------------------------------------
//	This file is part of 'GameTemplate', template code for a game.
//	Copyright (C) 2011  Niall Moody
//	
//	This program is free software: you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation, either version 3 of the License, or
//	(at your option) any later version.
//
//	This program is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU General Public License
//	along with this program.  If not, see <http://www.gnu.org/licenses/>.
//	----------------------------------------------------------------------------

#ifndef TIMEATTACK_H_
#define TIMEATTACK_H_

#include "Crash.h"
#include "Player.h"
#include "GameCore.h"
#include "GameState.h"
#include "GameCounter.h"
#include "TonesGlobalData.h"
#include "generators/MetaGenerator.h"

///	The main TimeAttack game mode.
class TimeAttack : public GameState,
				   public GameCore::Callback
{
  public:
	///	Constructor.
	TimeAttack(Application& app, SounderPtr& sound);
	///	Destructor.
	~TimeAttack();

	///	Updates the state.
	void update();
	///	Draws the state.
	void draw(DrawerPtr& d, float timestepInterp);

	///	Called when Tones collide.
	void toneCollision();

	///	Called when a key down event is received.
	void keyDown(const std::wstring& action,
				 const std::wstring& keyPressed,
				 int keyModifier);

	///	Called when a mouse down event is received.
	void mouseDown(int button, const TwoFloats& pos);
	///	Called when a mouse up event is received.
	void mouseUp(int button, const TwoFloats& pos);
	///	Called when a mouse move event is received.
	void mouseMove(const TwoFloats& pos);

	///	Returns the name of this state.
	const std::wstring getName() const {return L"TimeAttack";};
	///	Used to construct instances of this state.
	static GameStateCreator<TimeAttack> creator;
  private:
	///	Whether we should be in pure mode or not.
	bool pure;
	///	Whether we should be in zen mode or not.
	bool zen;

	///	Handles all the game logic.
	GameCore gameCore;

	///	Used to calculate the number of seconds which have passed since the last frame.
	uint32_t lastTicks;	
	///	The remaining time before game over.
	float secondsRemaining;
	///	Used to ensure the player doesn't quit to the title screen too early.
	int gameOverCount;

	///	Whether or not we're currently paused.
	bool paused;

	///	Used to make some of the text rendering more efficient.
	TextLayout textLayouts[2];

	///	Our copy of the game's global data.
	/*!
		(this is less hassle than writing
		 dynamic_pointer_cast<TonesGlobalData>(getGlobalData()) every time)
	 */
	TonesGlobalDataPtr globalData;
	///	Our copy of the game's Sounder.
	TonesSounderPtr sounder;
};

#endif
