#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "c2d2/chien2d2.h"
#include "c2d2/chien2d2primitivas.h"
#include "c2d2/chienaudio2.h"

extern char mednum[50], mednum1[50], mednum2[50], mednum3[50], mednum4[50], mednum5[50];
extern int medcount, medcount1, medcount2, medcount3, medcount4, medcount5;
extern int f2medcount, f2medcount1, f2medcount2, f2medcount3, f2medcount4, f2medcount5;
extern int f3medcount, f3medcount1, f3medcount2, f3medcount3, f3medcount4, f3medcount5;
extern int fase;
extern unsigned int som_tocando1; 
extern unsigned int som_tocando2;
extern unsigned int som_tocando3;
extern unsigned int som_tocando4;
extern unsigned int som_tocando5;
extern unsigned int som_tocando6;
extern unsigned int som_tocando7;
extern unsigned int som_tocando8;
extern bool encerra;
extern unsigned int botao_jogar;
extern unsigned int botao_ajuda;
extern unsigned int botao_creditos;
extern unsigned int botao_menu;
extern unsigned int botao_voltar;
extern unsigned int botao_sair;
extern unsigned int botao_proximo;
extern int estadoatual;
extern unsigned int spmira;
extern unsigned int titulo;

extern unsigned int musicas[2];//musicas do jogo...


void TelaPrincipal()//TELA INICIAL
{
	CA2_TocaMusica(musicas[0],-1);
	fase = 1;
	C2D2_Botao *teclas = C2D2_PegaTeclas();
    C2D2_Mouse *mouse = C2D2_PegaMouse();
	int opt[4], op = -1;
	C2D2_Sincroniza(C2D2_FPS_PADRAO);
	do
	{
        if(teclas[C2D2_ESC].pressionado)
            encerra=true;
        if(C2D2_ColidiuSprites(spmira, 0, mouse->x, mouse->y, botao_jogar, 0, 305, 250)) //mouse colidiu com botão jogar
			opt[0] = 1;
		else
			opt[0] = 0;

		if(C2D2_ColidiuSprites(spmira, 0, mouse->x, mouse->y, botao_ajuda, 0, 305, 310)) //mouse colidiu com botão ajuda
			opt[1] = 1;
		else
			opt[1] = 0;

        if(C2D2_ColidiuSprites(spmira, 0, mouse->x, mouse->y, botao_creditos, 0, 305, 370)) //mouse colidiu com botão créditos
			opt[2] = 1;
		else
			opt[2] = 0;

        if(C2D2_ColidiuSprites(spmira, 0, mouse->x, mouse->y, botao_sair, 0, 305, 430)) //mouse colidiu com botão sair
			opt[3] = 1;
		else
			opt[3] = 0;

        if(mouse->botoes[C2D2_MESQUERDO].pressionado)
        {
			for(int I = 0; I<4; I++){
				if(opt[I] == 1){
					op = I;
					break;
				}
			}

			switch(op){
				case 0:
					estadoatual = 2;
					break;
				case 1:
					estadoatual = 8;
					break;
				case 2:
					estadoatual = 3;
					break;
				case 3:
					encerra = true;
					break;
				default:
					op = -1;
			}

        }
		C2D2_LimpaTela();
        C2D2_DesenhaSprite(titulo, 0, 0, 0);
        C2D2_DesenhaSprite(botao_jogar, opt[0], 305, 250);
		C2D2_DesenhaSprite(botao_ajuda, opt[1], 305, 310);
        C2D2_DesenhaSprite(botao_creditos, opt[2], 305, 370);
        C2D2_DesenhaSprite(botao_sair, opt[3], 305, 430);
        C2D2_DesenhaSprite(spmira, 0, mouse->x, mouse->y);
		C2D2_Sincroniza(C2D2_FPS_PADRAO);
	}
	while(!encerra && estadoatual==1);
}