-
Montjoie Henri authoredMontjoie Henri authored
SDL_bis.c 4.15 KiB
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include "SDL.h"
#include "structures.h"
int SDL_bis()
{ int quitter=0;
EtatsJeu etat=SAISIE_JOUEURS;
SDL_Surface* ecran=NULL;
SDL_Event event;
SDL_Surface* logo = NULL;
SDL_Surface* rectangle = NULL;
SDL_Surface* texte = NULL;
SDL_Rect pos_logo;
SDL_Rect pos_texte;
TTF_Font *police = NULL;
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "Unable to init SDL: %s\n", SDL_GetError() );
return 1;
}
if(TTF_Init() == -1)
{
fprintf(stderr, "Erreur d'initialisation de TTF_Init : %s\n", TTF_GetError());
exit(EXIT_FAILURE);
}
police=TTF_OpenFont("../resources/fonts/arial.ttf",26);
SDL_Color couleurNoire = {0, 0, 0};
SDL_Color couleurBlanche = {255, 255, 255};
SDL_Color couleurBleue = {10, 30, 80};
SDL_Color couleurDoree = {190, 190, 120};
ecran = SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE+1), HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
if (ecran == NULL) // Si l'ouverture a chou, on le note et on arrte
{
fprintf(stderr, "Impossible de charger le mode vido : %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
SDL_WM_SetCaption("Elder Internal Ignition",NULL);
texte = TTF_RenderText_Shaded(police, "Entrez le nom du joueur 1", couleurBlanche,couleurNoire);
SDL_FillRect(ecran,NULL,SDL_MapRGB(ecran->format,0,0,0));
logo = SDL_LoadBMP("../resources/Skins/logo.bmp");
if (!logo)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
pos_logo.x=0;
pos_logo.y=0;
pos_texte.x=(ecran->w-texte->w)/2;
pos_texte.y=ecran->h-200;
char nom_joueur1[TAILLE_NOMS] = "";
while(etat==SAISIE_JOUEURS)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
etat=FERMER;
break;
}
SDL_BlitSurface(texte,NULL,ecran,&pos_texte);
SDL_BlitSurface(logo,NULL,ecran,&pos_logo);
SDL_Flip(ecran);
fgets(nom_joueur1, sizeof(nom_joueur1), stdin);
}
texte = TTF_RenderText_Shaded(police, "Entrez le nom du joueur 2", couleurBlanche,couleurNoire);
SDL_BlitSurface(texte,NULL,ecran,&pos_texte);
SDL_Flip(ecran);
char nom_joueur2[TAILLE_NOMS] = "";
fgets(nom_joueur2, sizeof(nom_joueur2), stdin);
ajouterUnJoueur(nom_joueur1,&etat);
ajouterUnJoueur(nom_joueur2,&etat);
police=TTF_OpenFont("../resources/fonts/OLDENGL.ttf",40);
texte = TTF_RenderText_Shaded(police, "Entrez dans le Royaume !", couleurDoree,couleurBleue);
pos_texte.x=(ecran->w-texte->w)/2;
pos_texte.y=ecran->h-200;
rectangle=SDL_CreateRGBSurface(SDL_HWSURFACE,texte->w,texte->h,NULL,0,0,255,NULL);
SDL_FillRect(ecran,NULL,SDL_MapRGB(ecran->format,0,0,0));
SDL_BlitSurface(logo,NULL,ecran,&pos_logo);
SDL_BlitSurface(texte,NULL,ecran,&pos_texte);
SDL_BlitSurface(rectangle,NULL,ecran,&pos_texte);
SDL_Flip(ecran);
while(etat==LANCEMENT)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
etat=FERMER;
break;
case SDL_MOUSEBUTTONDOWN:
if (event.button.x<pos_texte.x+texte->w&&event.button.x>pos_texte.x&&event.button.y<pos_texte.y+texte->h&&event.button.y>pos_texte.y)
{etat=CONFIGURATION;}
break;
default:
break;
}
SDL_BlitSurface(logo,NULL,ecran,&pos_logo);
SDL_BlitSurface(texte,NULL,ecran,&pos_texte);
SDL_BlitSurface(rectangle,NULL,ecran,&pos_texte);
SDL_Flip(ecran);
}
while(etat==CONFIGURATION)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
etat=FERMER;
break;
case SDL_MOUSEBUTTONDOWN:
if (event.button.x<pos_texte.x+texte->w&&event.button.x>pos_texte.x&&event.button.y<pos_texte.y+texte->h&&event.button.y>pos_texte.y)
etat=CONFIGURATION;
break;
}
}
return 0;
}