#include <cmath>
#include <GL/glut.h>
#include <list>
#include <string>
#include <strstream>
#include <vector>

#include "globale.h"
#include "Temps.h"
#include "CVector3.h"
#include "CCamera.h"
#include "CCube.h"
#include "CBloc.h"
#include "CJeu.h"
#include "CWinStream.h"
#include "AnimDebut.h"




// Fonction qui attend que l'on appuie sur ENTER pour recommencer le jeu

void keyboardGameOver(unsigned char key, int x, int y)
{
	// On appuie sur ENTER
	if (key == 13)
	{
		glViewport(0,0, SCREEN_WIDTH - LARGEURTEXTE, SCREEN_HEIGHT);

		for (int i = 0; i < MAX_X; i++)
			for (int j = 0; j < MAX_Y; j++)
				for (int k = 0; k < MAX_Z; k++)
					gJeu.CubeMatrice[i][j][k].x = -1;

		gJeu.CubeADessiner.clear();
		gJeu.Bloc.LesCubes.clear();
		gJeu.BlocGuide.LesCubes.clear();
		gJeu.BlocPreview.LesCubes.clear();
		gJeu.Niveau = 0;
		gJeu.NombreDePlans = 0;

		SetIntroFunc();
	}
}




// Fonction qui arrange tout pour que ça soit en mode gameover

void GameOver(void)
{
	gCamera.DisplayFunc = NoDisplay;

	glutIdleFunc(0);
	glutDisplayFunc(NoDisplay);
	glutKeyboardFunc(keyboardGameOver);
	glutMouseFunc(0);
	glutMotionFunc(0);
	glutPassiveMotionFunc(0);


	gJeu.GameDraw();

	glViewport(0,0, SCREEN_WIDTH, SCREEN_HEIGHT);

	unsigned char Message0[] = "GAME OVER";
	unsigned char Message1[] = "Appuyez sur ENTER pour recommencer";
	
	wout.Begin();

		glColor4f(0, 0, 0, ASSOMBPAUSE);
		glBegin(GL_QUADS);
			glVertex2i(0, 0);
			glVertex2i(0, SCREEN_HEIGHT);
			glVertex2i(SCREEN_WIDTH, SCREEN_HEIGHT);
			glVertex2i(SCREEN_WIDTH, 0);
		glEnd();
		
		wout.SetCouleur(1,1,1,1);
		
		wout.SetPos(CENTRE_X - (wout.Length(Message0) >> 1), 3 * (CENTRE_Y >> 1));
		wout << Message0;
		wout.flush();

		wout.SetPos(CENTRE_X - (wout.Length(Message1) >> 1), CENTRE_Y);
		wout << Message1;
		wout.flush();

	wout.End();

	glutSwapBuffers();
}
