Skip to content
Snippets Groups Projects
Commit 0dbff622 authored by Lénaïg Le Moigne's avatar Lénaïg Le Moigne
Browse files

Première ébauche de la mise au point de l'écran d'accueil. A regarder par Henry

parent ec0940dd
No related branches found
No related tags found
No related merge requests found
#include <stdlib.h>
#include <SDL/SDL.h>
#include "structures.h"
#include "partie.h"
#include "joueur.h"
#include "joueurList.h"
#include "personnage.h"
#include "case.h"
#include "deplacements.h"
#include "SDL.h"
#include "controleurSDL.h"
/*!
* \file SDL.c
* \brief Fichier contenant le code des fonctions liees l'affichage par la SDL.
*/
/*!
* \fn int main_SDL(char* Map)
* \brief fonction qui gre l'affichage
*
* \param la carte au format texte (une lettre = une case)
*/
int main_SDL(char* Map)
{
int i,j,affichermenu;
SDL_Surface* ecran=NULL;
SDL_Event event;
SDL_Surface* guerrier=NULL;
SDL_Surface* mage=NULL;
SDL_Surface* voleur=NULL;
SDL_Surface* archer=NULL;
SDL_Surface* guerisseur=NULL;
SDL_Surface* plaine=NULL;
SDL_Surface* eau=NULL;
SDL_Surface* montagne=NULL;
SDL_Surface* foret=NULL;
SDL_Surface* bouton_entrer_royaume=NULL;
SDL_Surface* bouton_continuer=NULL;
SDL_Surface* bouton_quitter=NULL;
SDL_Surface* Case_brillante=NULL;
SDL_Surface* Guerrier_select=NULL;
SDL_Rect Position_Case[LARGEUR_CARTE*HAUTEUR_CARTE];
SDL_Rect Position_Perso[NB_PERSO];
SDL_Rect Position_Case_brillante;
SDL_Rect Position_Guerrier_select;
SDL_Rect pos_bouton_entrer_royaume;
SDL_Rect pos_bouton_continuer;
SDL_Rect pos_bouton_quitter;
int x_case_brillante;
int y_case_brillante;
int x_guerrier_select;
int y_guerrier_select;
int quitter=0;
affichermenu=0;
typedef enum{Accueil,Jeu}etat;
int Etat = Accueil;
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "Unable to init SDL: %s\n", SDL_GetError() );
return 1;
}
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);
pos_bouton_entrer_royaume.x=(LARGEUR_CARTE*LARGEUR_CASE-LARGEUR_BOUTON)/2;
pos_bouton_quitter.x=(LARGEUR_CARTE*LARGEUR_CASE-LARGEUR_BOUTON)/2;
pos_bouton_continuer.x=(LARGEUR_CARTE*LARGEUR_CASE-LARGEUR_BOUTON)/2;
pos_bouton_entrer_royaume.y=(HAUTEUR_CARTE*HAUTEUR_CASE-HAUTEUR_BOUTON)/2+HAUTEUR_BOUTON;
pos_bouton_quitter.y=(HAUTEUR_CARTE*HAUTEUR_CASE-HAUTEUR_BOUTON)/2+HAUTEUR_BOUTON;
pos_bouton_continuer.y=(HAUTEUR_CARTE*HAUTEUR_CASE-HAUTEUR_BOUTON)/2-HAUTEUR_BOUTON;
guerrier = SDL_LoadBMP("../resources/Skins/guerrier.bmp");
if (!guerrier)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(guerrier, SDL_SRCCOLORKEY, SDL_MapRGB(guerrier->format, 0, 0, 255));
bouton_entrer_royaume = SDL_LoadBMP("../resources/Skins/Entrer_Royaume.bmp");
if (!bouton_entrer_royaume)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
bouton_continuer = SDL_LoadBMP("../resources/Skins/continuer.bmp");
if (!bouton_continuer)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
bouton_quitter = SDL_LoadBMP("../resources/Skins/quitter.bmp");
if (!bouton_continuer)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
mage = SDL_LoadBMP("../resources/Skins/mage.bmp");
if (!mage)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(mage, SDL_SRCCOLORKEY, SDL_MapRGB(mage->format, 0, 0, 255));
voleur = SDL_LoadBMP("../resources/Skins/voleur.bmp");
if (!voleur)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(voleur, SDL_SRCCOLORKEY, SDL_MapRGB(voleur->format, 0, 0, 255));
archer = SDL_LoadBMP("../resources/Skins/archer.bmp");
if (!archer)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(archer, SDL_SRCCOLORKEY, SDL_MapRGB(archer->format, 0, 0, 255));
guerisseur = SDL_LoadBMP("../resources/Skins/guerisseur.bmp");
if (!guerisseur)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(guerisseur, SDL_SRCCOLORKEY, SDL_MapRGB(guerisseur->format, 0, 0, 255));
plaine = SDL_LoadBMP("../resources/Skins/plaine.bmp");
if (!plaine)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(plaine, SDL_SRCCOLORKEY, SDL_MapRGB(plaine->format, 0, 0, 255));
eau = SDL_LoadBMP("../resources/Skins/eau.bmp");
if (!eau)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(eau, SDL_SRCCOLORKEY, SDL_MapRGB(eau->format, 0, 0, 255));
montagne = SDL_LoadBMP("../resources/Skins/montagne.bmp");
if (!montagne)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(montagne, SDL_SRCCOLORKEY, SDL_MapRGB(montagne->format, 0, 0, 255));
foret = SDL_LoadBMP("../resources/Skins/foret.bmp");
if (!foret)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(foret, SDL_SRCCOLORKEY, SDL_MapRGB(foret->format, 0, 0, 255));
Case_brillante = SDL_LoadBMP("../resources/Skins/case_brillante.bmp");
if (!Case_brillante)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(Case_brillante, SDL_SRCCOLORKEY, SDL_MapRGB(Case_brillante->format, 0, 0, 255));
Guerrier_select = SDL_LoadBMP("../resources/Skins/guerrier_select.bmp");
if (!Guerrier_select)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(Guerrier_select, SDL_SRCCOLORKEY, SDL_MapRGB(Guerrier_select->format, 0, 0, 255));
for(i=0;i<LARGEUR_CARTE;i+=2)
{
for(j=0;j<HAUTEUR_CARTE;j++)
{
Position_Case[j*LARGEUR_CARTE+i].x=LARGEUR_CASE*i;
Position_Case[j*LARGEUR_CARTE+i].y=HAUTEUR_CASE*j;
}
}
for(i=1;i<LARGEUR_CARTE;i+=2)
{
for(j=0;j<HAUTEUR_CARTE;j++)
{
Position_Case[j*LARGEUR_CARTE+i].x=LARGEUR_CASE*i;
Position_Case[j*LARGEUR_CARTE+i].y=HAUTEUR_CASE*j+(HAUTEUR_CASE/2);
}
}
init_controleur(Position_Case);
while(quitter==0)
{
switch(Etat){
case Accueil:
SDL_WaitEvent(&event);
switch(event.type) /* Test du type d'vnement */
{
case SDL_QUIT: /* Si c'est un vnement de type "Quitter" */
quitter=1;
break;
case SDL_MOUSEBUTTONDOWN:
if(pos_bouton_entrer_royaume.y<event.button.y&&event.button.y<pos_bouton_entrer_royaume.y+LARGEUR_BOUTON){
Etat = 1;;
}
break;
case SDL_KEYDOWN:/* Si c'est un vnement de type "touche presse" */
switch(event.key.keysym.sym){
case SDLK_ESCAPE:
affichermenu=0;
break;
default:
quitter=0;
}
break;
}
SDL_BlitSurface(bouton_entrer_royaume,NULL,ecran,&pos_bouton_entrer_royaume);
SDL_Flip(ecran);
break;
case Jeu:
SDL_WaitEvent(&event);
if(affichermenu==1){
switch(event.type) /* Test du type d'vnement */
{
case SDL_QUIT: /* Si c'est un vnement de type "Quitter" */
quitter=1;
break;
case SDL_MOUSEBUTTONDOWN:
if(pos_bouton_continuer.x<event.button.x&&event.button.x<pos_bouton_continuer.x+LARGEUR_BOUTON){
if(pos_bouton_continuer.y<event.button.y&&event.button.y<pos_bouton_continuer.x+HAUTEUR_BOUTON){
affichermenu=0;
}
if(pos_bouton_quitter.y<event.button.y&&event.button.y<pos_bouton_quitter.x+HAUTEUR_BOUTON){
quitter=1;
}
}
break;
case SDL_KEYDOWN:/* Si c'est un vnement de type "touche presse" */
switch(event.key.keysym.sym){
case SDLK_ESCAPE:
affichermenu=0;
break;
default:
quitter=0;
}
break;
}
}
else{
switch(event.type) /* Test du type d'vnement */
{
case SDL_QUIT: /* Si c'est un vnement de type "Quitter" */
quitter=1;
break;
case SDL_MOUSEBUTTONDOWN:
deplacement_personnage(event.button.x,event.button.y);
break;
case SDL_MOUSEMOTION:
if(event.motion.x<LARGEUR_CARTE*LARGEUR_CASE&&event.motion.y<HAUTEUR_CARTE*HAUTEUR_CASE)
{
x_case_brillante = get_position_case_x(deplacement_brillance(event.motion.x,event.motion.y));
y_case_brillante = get_position_case_y(deplacement_brillance(event.motion.x,event.motion.y));
}
break;
case SDL_KEYDOWN:/* Si c'est un vnement de type "touche presse" */
switch(event.key.keysym.sym){
case SDLK_n:
persosuivant();
break;
case SDLK_ESCAPE:
affichermenu=1;
break;
default:
quitter=0;
}
break;
}
}
for(i=0;i<NB_PERSO;i++){
Position_Perso[i].x=get_position_perso_x(i);
Position_Perso[i].y=get_position_perso_y(i);
}
Position_Case_brillante.x=x_case_brillante;
Position_Case_brillante.y=y_case_brillante;
x_guerrier_select = get_position_case_x(&Position_Perso[persoactuel()]);
y_guerrier_select = get_position_case_y(&Position_Perso[persoactuel()]);
Position_Guerrier_select.x=x_guerrier_select;
Position_Guerrier_select.y=y_guerrier_select;
SDL_FillRect(ecran,NULL,SDL_MapRGB(ecran->format,0,0,0));
if(affichermenu==0)
{
for(i=0;i<LARGEUR_CARTE*HAUTEUR_CARTE;i++)
{
switch(Map[i])
{
case 80: //"P" en ASCII
SDL_BlitSurface(plaine,NULL,ecran,&Position_Case[i]);
break;
case 70: //"F" en ASCII
SDL_BlitSurface(foret,NULL,ecran,&Position_Case[i]);
break;
case 69: //"E" en ASCII
SDL_BlitSurface(eau,NULL,ecran,&Position_Case[i]);
break;
case 77: //"M" en ASCII
SDL_BlitSurface(montagne,NULL,ecran,&Position_Case[i]);
break;
default:
quitter=0;
}
}
for(i=0;i<NB_PERSO;i++)
{
SDL_BlitSurface(guerrier,NULL,ecran,&Position_Perso[0]);
SDL_BlitSurface(mage,NULL,ecran,&Position_Perso[1]);
SDL_BlitSurface(archer,NULL,ecran,&Position_Perso[2]);
}
SDL_BlitSurface(Guerrier_select,NULL,ecran,&Position_Guerrier_select);
SDL_BlitSurface(Case_brillante,NULL,ecran,&Position_Case_brillante);
}else{
SDL_BlitSurface(bouton_continuer,NULL,ecran,&pos_bouton_continuer);
SDL_BlitSurface(bouton_quitter,NULL,ecran,&pos_bouton_quitter);
}
SDL_Flip(ecran);
break;
default:
break;
}
}
quitter=0;
SDL_FreeSurface(guerrier);
SDL_FreeSurface(Case_brillante);
SDL_FreeSurface(Guerrier_select);
SDL_FreeSurface(plaine);
SDL_FreeSurface(mage);
SDL_FreeSurface(voleur);
SDL_FreeSurface(archer);
SDL_FreeSurface(guerisseur);
SDL_FreeSurface(eau);
SDL_FreeSurface(montagne);
SDL_FreeSurface(foret);
SDL_Quit();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment