//	Survival.h - Survival 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 SURVIVAL_H_
#define SURVIVAL_H_

#include "GameState.h"
#include "Player.h"

#include <vector>
#include <stdint.h>

class Dot;
class Crash;

///	Survival game mode.
class Survival : public GameState
{
  public:
	///	Constructor.
	Survival(Application *app);
	///	Destructor.
	~Survival();

	///	Draws the state.
	void draw(Drawer *d);

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

	///	Called when a mouse down event is received.
	void mouseDown(int button, int posX, int posY);
	///	Called when a mouse up event is received.
	void mouseUp(int button, int posX, int posY);
	///	Called when a mouse move event is received.
	void mouseMove(int posX, int posY);

	///	Returns the name of this state.
	const std::string getName() const {return "Survival";};
  private:
	///	Helper method. Deflects any nearby dots.
	void deflectDots();
	///	Helper method. Attracts any nearby dots.
	void attractDots();
	///	Helper method. Checks whether any dots have collided.
	void collisionDetection();
	///	Helper method. Calculates how many dots are near each other.
	void calcNearby();
	///	Helper method. Returns which rails have slow dots near the spawn point.
	void calcSlowDotsNearSpawn();
	///	Helper method. Returns which rails have med dots near the spawn point.
	void calcMedDotsNearSpawn();

	///	The crash image.
	static uint32_t crashImage;
	///	The game over image.
	static uint32_t gameOverImage;
	///	The font we use.
	static uint32_t font;

	///	How many rails there are.
	int numRails;

	///	The player deflector.
	Player player;

	///	The currently-active dots.
	std::vector<Dot *> dots;
	///	Used to generate new dots.
	int dotCount;
	///	Used to determine when to generate new dots.
	float dotCountLength;

	///	Any crashes currently active.
	std::vector<Crash *> crashes;
	///	The player's remaining lives.
	int numLives;
	///	Used to ensure the player doesn't quit to the title screen too early.
	int gameOverCount;

	///	Used to determine when we need to spawn a slow dot to avoid premature crashing.
	std::vector<int> slowDotsNearSpawn;
	///	Used to determine when we need to spawn a slow or med dot to avoid premature crashing.
	std::vector<int> medDotsNearSpawn;
	///	A combined version of the above 2 vectors.
	std::vector<int> slowMedDotsNearSpawn;

	///	Used when the player is swiping a dot.
	Dot *swipingDot;
};

#endif
