From 0df4eeffa8ddfdeea15c690c3a0cea31890374c3 Mon Sep 17 00:00:00 2001 From: Henri Montjoie <henri.montjoie@insa-rennes.fr> Date: Tue, 10 May 2016 15:21:21 +0200 Subject: [PATCH] nettoyage --- src/ClassesXML.c | 2 +- src/SDL.c | 324 ---------------- src/SDL_bis.c | 394 ------------------- src/TerrainsXML.c | 1 + src/affichage.c | 761 +++++++++++++++++++++++++++++++++++++ src/{SDL.h => affichage.h} | 13 +- src/controleur.c | 3 +- src/controleurSDL.c | 2 +- src/main.c | 11 +- 9 files changed, 780 insertions(+), 731 deletions(-) delete mode 100644 src/SDL.c delete mode 100644 src/SDL_bis.c create mode 100644 src/affichage.c rename src/{SDL.h => affichage.h} (67%) diff --git a/src/ClassesXML.c b/src/ClassesXML.c index 32b7488..d05da8e 100644 --- a/src/ClassesXML.c +++ b/src/ClassesXML.c @@ -83,7 +83,7 @@ Classe* Remplir_Classes(FILE* Classes_log, char *filename) /* Remplit le tableau strcpy(Classe_en_cours.nom, name_text); /*----------------------------------------------------------------------------------------------*/ - /*Chargement des skins de la classe en cours + /*Chargement des skins de la classe en cours*/ /*----------------------------------------------------------------------------------------------*/ fprintf(Classes_log,"\nChargement des skins de la classe numero %d\n", i+1); diff --git a/src/SDL.c b/src/SDL.c deleted file mode 100644 index 1da0e65..0000000 --- a/src/SDL.c +++ /dev/null @@ -1,324 +0,0 @@ -#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 gère 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_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_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; - - 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 arrête - { - fprintf(stderr, "Impossible de charger le mode vidéo : %s\n", SDL_GetError()); - exit(EXIT_FAILURE); - } - - SDL_WM_SetCaption("Elder Internal Ignition",NULL); - - pos_bouton_quitter.x=(LARGEUR_CARTE*LARGEUR_CASE-LARGEUR_BOUTON)/2; - pos_bouton_continuer.x=(LARGEUR_CARTE*LARGEUR_CASE-LARGEUR_BOUTON)/2; - 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_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) - { - SDL_WaitEvent(&event); - if(affichermenu==1){ - switch(event.type) /* Test du type d'événement */ - { - case SDL_QUIT: /* Si c'est un événement 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 événement de type "touche pressée" */ - switch(event.key.keysym.sym){ - case SDLK_ESCAPE: - affichermenu=0; - break; - default: - quitter=0; - } - break; - } - } - else{ - switch(event.type) /* Test du type d'événement */ - { - case SDL_QUIT: /* Si c'est un événement 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 événement de type "touche pressée" */ - 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(guerisseur,NULL,ecran,&Position_Perso[0]); - SDL_BlitSurface(mage,NULL,ecran,&Position_Perso[1]); - SDL_BlitSurface(guerrier,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); - } - 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; -} - - diff --git a/src/SDL_bis.c b/src/SDL_bis.c deleted file mode 100644 index 7b7405f..0000000 --- a/src/SDL_bis.c +++ /dev/null @@ -1,394 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <SDL/SDL.h> -#include <SDL/SDL_ttf.h> -#include "SDL.h" -#include "structures.h" -#include "controleur.h" - - -char* castIntToChar(int n) -{ - switch(n) - { - case 0: - return "0"; - break; - case 1: - return "1"; - break; - case 2: - return "2"; - break; - case 3: - return "3"; - break; - case 4: - return "4"; - break; - case 5: - return "5"; - break; - case 6: - return "6"; - break; - default: - return "-1"; - break; - } -} - - -char* afficherListe(char** nomsClasses, char** skinsClasses, int nbChoix, TTF_Font* police,SDL_Color couleurTexte) -{ - int i, quitter; - char* classeChoisie; - SDL_Surface* fenetre=NULL; - SDL_Event event; - SDL_Surface* tabTextes[nbChoix]; - SDL_Surface* tabSkins[nbChoix]; - SDL_Rect positionsTextes[nbChoix]; - SDL_Rect positionsSkins[nbChoix]; - SDL_Color couleurNoire = {0, 0, 0}; - - for(i=0;i<nbChoix;i++){ - tabSkins[i]=SDL_LoadBMP(skinsClasses[i]); - if (!tabSkins[i]) - { - printf("Unable to load bitmap: %s\n", skinsClasses[i]); - return 1; - } - SDL_SetColorKey(tabSkins[i], SDL_SRCCOLORKEY, SDL_MapRGB(tabSkins[i]->format, 0, 0, 255)); - } - - fenetre = SDL_SetVideoMode(260, nbChoix*tabSkins[0]->h, 32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RESIZABLE); - SDL_FillRect(fenetre,NULL,SDL_MapRGB(fenetre->format,0,0,0)); - - quitter=0; - while(quitter==0) - { - SDL_WaitEvent(&event); - switch(event.type) - { - case SDL_QUIT: - SDL_FreeSurface(fenetre); - return "fermer"; - break; - case SDL_MOUSEBUTTONDOWN: - for(i=0;i<nbChoix;i++) - { - if(event.button.y/positionsSkins[0].h==i) - { - classeChoisie=nomsClasses[i]; - quitter=1; - } - } - break; - default: - break; - } - for(i=0;i<nbChoix;i++) - { - tabTextes[i]=TTF_RenderText_Shaded(police, nomsClasses[i], couleurTexte,couleurNoire); - positionsSkins[i].y=i*tabSkins[0]->h; - positionsSkins[i].x=0; - positionsTextes[i].x=tabSkins[i]->w+4; - positionsTextes[i].y=positionsSkins[i].y+(tabSkins[i]->h/3); - SDL_BlitSurface(tabTextes[i],NULL,fenetre,&positionsTextes[i]); - SDL_BlitSurface(tabSkins[i],NULL,fenetre,&positionsSkins[i]); - } - SDL_Flip(fenetre); - } - SDL_FreeSurface(fenetre); - return classeChoisie; -} - - -int SDL_bis() -{ - int i; - EtatsJeu etat=SAISIE_JOUEURS; - SDL_Surface* ecran=NULL; - SDL_Event event; - SDL_Surface* logo = NULL; - SDL_Surface* rectangle = NULL; - SDL_Surface* texte = NULL; - SDL_Surface* texte2 = NULL; - SDL_Surface* texte3 = NULL; - SDL_Rect pos_logo; - SDL_Rect pos_texte; - SDL_Rect pos_texte2; - SDL_Rect pos_texte3; - SDL_Rect pos_texte3_bis; - TTF_Font *police = NULL; - TTF_Font *petite_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 arrête - { - fprintf(stderr, "Impossible de charger le mode vidéo : %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=(ecran->w-logo->w)/2; - pos_logo.y=0; - pos_texte.x=(ecran->w-texte->w)/2; - pos_texte.y=ecran->h-200; - SDL_BlitSurface(texte,NULL,ecran,&pos_texte); - SDL_BlitSurface(logo,NULL,ecran,&pos_logo); - SDL_Flip(ecran); - - char nom_joueur1[TAILLE_NOMS] = ""; - fgets(nom_joueur1, sizeof(nom_joueur1), stdin); - if(strlen(nom_joueur1)>TAILLE_NOMS-2){ - printf("erreur : nom trop long"); - return -1; - } - if(strlen(nom_joueur1)>1){ nom_joueur1[strlen(nom_joueur1)-1]=NULL;} - - char nom_joueur2[TAILLE_NOMS] = ""; - - texte = TTF_RenderText_Shaded(police, "Entrez le nom du joueur 2", couleurBlanche,couleurNoire); - SDL_BlitSurface(texte,NULL,ecran,&pos_texte); - SDL_Flip(ecran); - - fgets(nom_joueur2, sizeof(nom_joueur2), stdin); - if(strlen(nom_joueur1)>TAILLE_NOMS-2){ - printf("erreur : nom trop long"); - return -1; - } - if(strlen(nom_joueur2)>1) {nom_joueur2[strlen(nom_joueur2)-1]=NULL;} - - 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); - } - - SDL_FillRect(ecran,NULL,SDL_MapRGB(ecran->format,0,0,0)); - SDL_Flip(ecran); - - police=TTF_OpenFont("../resources/fonts/OLDENGL.ttf",44); - petite_police=TTF_OpenFont("../resources/fonts/OLDENGL.ttf",32); - - texte= TTF_RenderText_Shaded(police, nom_joueur1, couleurBlanche,couleurNoire); - texte2= TTF_RenderText_Shaded(police, nom_joueur2, couleurBlanche, couleurNoire); - texte3= TTF_RenderText_Shaded(petite_police, "choisissez vos personnages", couleurBlanche, couleurNoire); - pos_texte.x=ecran->w/4-texte->w/2; - pos_texte.y=10; - pos_texte2.x=(3*ecran->w)/4-texte2->w/2; - pos_texte2.y=10; - pos_texte3.x=pos_texte.x-(texte3->w-texte->w)/2; - pos_texte3.y=pos_texte.y+(3*texte3->h)/2; - pos_texte3_bis.x=pos_texte2.x-(texte3->w-texte2->w)/2; - pos_texte3_bis.y=pos_texte2.y+(3*texte3->h)/2; - - SDL_BlitSurface(texte,NULL,ecran,&pos_texte); - SDL_BlitSurface(texte2,NULL,ecran,&pos_texte2); - SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3); - SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3_bis); - SDL_Flip(ecran); - - SDL_Surface textes[6]; - SDL_Rect posTextes[6]; - police=TTF_OpenFont("../resources/fonts/arial.ttf",26); - - char src[50], dest[50]; - - for(i=0;i<3;i++) - { - strcpy(dest, "personnage "); - strcpy(src, castIntToChar(i+1)); - textes[i]= *TTF_RenderText_Shaded(police, strcat(dest, src), couleurBlanche,couleurNoire); - } - - for(i=3;i<6;i++) - { - strcpy(dest, "personnage "); - strcpy(src, castIntToChar(i-2)); - textes[i]= *TTF_RenderText_Shaded(police, strcat(dest, src), couleurBlanche,couleurNoire); - } - - for(i=0;i<3;i++) - { - posTextes[i].x=ecran->w/4-textes[i].w/2; - posTextes[i].y=(i+1)*ecran->h/6; - SDL_BlitSurface(&textes[i],NULL,ecran,&(posTextes[i])); - } - - for(i=3;i<6;i++) - { - posTextes[i].x=(3*ecran->w)/4-textes[i].w/2; - posTextes[i].y=posTextes[i-3].y; - SDL_BlitSurface(&textes[i],NULL,ecran,&posTextes[i]); - } - SDL_Flip(ecran); - - char** path_images=obtenirSkinsClasses(); - SDL_Surface* images_classes[nbClasses()]; - SDL_Surface* images_persos[3][2]={{NULL}}; - SDL_Rect positions_images[3][2]; - int numClassePerso[3][2]={{-1,-1},{-1,-1},{-1,-1}}; - int j,p,k; - j=0; - p=0; - char *classeChoisie; - for(i=0;i<nbClasses();i++) - { - images_classes[i]=SDL_LoadBMP(path_images[i]); - if (!images_classes[i]) - { - printf("Unable to load bitmap: %s\n", SDL_GetError()); - return 1; - } - SDL_SetColorKey(images_classes[i], SDL_SRCCOLORKEY, SDL_MapRGB(images_classes[i]->format, 0, 0, 255)); - } - - SDL_Surface* map_choisie=SDL_LoadBMP("../resources/Skins/Map_select.bmp"); - if (!map_choisie) - { - printf("Unable to load bitmap: %s\n", SDL_GetError()); - return 1; - } - SDL_Surface* previsualisation[5]={NULL}; - SDL_Rect position_carte[5]; - char* path[5]; - path[0]="../resources/Skins/Map_1.bmp"; - path[1]="../resources/Skins/Map_2.bmp"; - path[2]="../resources/Skins/Map_3.bmp"; - path[3]="../resources/Skins/Map_4.bmp"; - path[4]="../resources/Skins/autre_map.bmp"; - - for(i=0;i<5;i++) - { - previsualisation[i]=SDL_LoadBMP(path[i]); - if (!previsualisation[i]) - { - printf("Unable to load bitmap: %s\n", SDL_GetError()); - return 1; - } - position_carte[i].y=(ecran->h)-(previsualisation[i]->h+100); - position_carte[i].x=(ecran->w-previsualisation[i]->w)/2+(10+previsualisation[i]->w)*(i-2); - } - - while(etat==CONFIGURATION) - { - SDL_WaitEvent(&event); - switch(event.type) - { - case SDL_QUIT: - etat=FERMER; - break; - case SDL_MOUSEBUTTONDOWN: - if(event.button.x>posTextes[0].x&&event.button.x<posTextes[0].x+textes[0].w) - j=1; - if(event.button.x>posTextes[3].x&&event.button.x<posTextes[3].x+textes[3].w) - j=2; - for(i=0;i<3;i++){ - if(event.button.y>posTextes[i].y&&event.button.y<posTextes[i].y+textes[i].h) - p=i+1; - } - if(j!=0&&p!=0){ - classeChoisie=afficherListe(obtenirNomsClasses(), obtenirSkinsClasses(), nbClasses(), police, couleurBlanche); - if(classeChoisie!="fermer") - { - numClassePerso[p-1][j-1]=ajouterPersonnage(classeChoisie, p-1, j); - } - ecran = SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE+1), HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF); - - } - break; - default: - break; - } - - for(i=0;i<6;i++){ - SDL_BlitSurface(&textes[i],NULL,ecran,&(posTextes[i])); - } - for(i=0;i<3;i++){ - for(k=0;k<2;k++){ - positions_images[i][k].y=posTextes[i].y+textes[i].h; - positions_images[i][k].x=posTextes[3*k].x+(textes[3*k].w-images_classes[0]->w)/2; - images_persos[i][k]=images_classes[numClassePerso[i][k]]; - if(numClassePerso[i][k]!=-1) - { - SDL_BlitSurface(images_persos[i][k],NULL,ecran,&positions_images[i][k]); - } - } - } - SDL_BlitSurface(texte,NULL,ecran,&pos_texte); - SDL_BlitSurface(texte2,NULL,ecran,&pos_texte2); - SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3); - SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3_bis); - for(i=0;i<5;i++) - { - SDL_BlitSurface(previsualisation[i],NULL,ecran,&position_carte[i]); - } - SDL_Flip(ecran); - p=0; - j=0; - } - SDL_Quit(); - return 0; -} diff --git a/src/TerrainsXML.c b/src/TerrainsXML.c index c1d29b4..f93affd 100644 --- a/src/TerrainsXML.c +++ b/src/TerrainsXML.c @@ -185,6 +185,7 @@ Skins_Terrain * Load_Skins_Terrain(char *filename) else { fprintf(stderr,"Impossible d'ouvrir le fichier Skins_XML_log"); + return NULL; } } diff --git a/src/affichage.c b/src/affichage.c new file mode 100644 index 0000000..04583e7 --- /dev/null +++ b/src/affichage.c @@ -0,0 +1,761 @@ +#include <stdio.h> +#include <stdlib.h> +#include <SDL/SDL.h> +#include <SDL/SDL_ttf.h> + +#include "affichage.h" +#include "controleur.h" +#include "controleurSDL.h" + +/*! +* \file affichage.c +* \brief Fichier contenant le code des fonctions liees à l'affichage par la SDL. +*/ + +EtatsJeu etat; +char* nom_1; +char* nom_2; + +/*! + * \fn char* afficherListeClasses(char** nomsClasses, char** skinsClasses, int nbChoix, TTF_Font* police,SDL_Color couleurTexte) + * \brief Fonction permettant le choix de la classe d'un personnage par le joueur + * + * \param le tableau contenant les noms des classes, le tableau contenant les adresse de leurs images, le nombre de classes, et la police et la couleur dans lesquelles écrire les noms + * \return le nom de la classe choisie + */ +char* afficherListeClasses(char** nomsClasses, char** skinsClasses, int nbChoix, TTF_Font* police,SDL_Color couleurTexte) +{ + int i, quitter; + char* classeChoisie; + SDL_Surface* fenetre=NULL; + SDL_Event event; + SDL_Surface* tabTextes[nbChoix]; + SDL_Surface* tabSkins[nbChoix]; + SDL_Rect positionsTextes[nbChoix]; + SDL_Rect positionsSkins[nbChoix]; + SDL_Color couleurNoire = {0, 0, 0}; + + for(i=0;i<nbChoix;i++){ + tabSkins[i]=SDL_LoadBMP(skinsClasses[i]); + if (!tabSkins[i]) + { + printf("Unable to load bitmap: %s\n", skinsClasses[i]); + return NULL; + } + SDL_SetColorKey(tabSkins[i], SDL_SRCCOLORKEY, SDL_MapRGB(tabSkins[i]->format, 0, 0, 255)); + } + + fenetre = SDL_SetVideoMode(260, nbChoix*tabSkins[0]->h, 32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RESIZABLE); + SDL_FillRect(fenetre,NULL,SDL_MapRGB(fenetre->format,0,0,0)); + + quitter=0; + while(quitter==0) + { + SDL_WaitEvent(&event); + switch(event.type) + { + case SDL_QUIT: + SDL_FreeSurface(fenetre); + return "fermer"; + break; + case SDL_MOUSEBUTTONDOWN: + for(i=0;i<nbChoix;i++) + { + if(event.button.y/positionsSkins[0].h==i) + { + classeChoisie=nomsClasses[i]; + quitter=1; + } + } + break; + default: + break; + } + for(i=0;i<nbChoix;i++) + { + tabTextes[i]=TTF_RenderText_Shaded(police, nomsClasses[i], couleurTexte,couleurNoire); + positionsSkins[i].y=i*tabSkins[0]->h; + positionsSkins[i].x=0; + positionsTextes[i].x=tabSkins[i]->w+4; + positionsTextes[i].y=positionsSkins[i].y+(tabSkins[i]->h/3); + SDL_BlitSurface(tabTextes[i],NULL,fenetre,&positionsTextes[i]); + SDL_BlitSurface(tabSkins[i],NULL,fenetre,&positionsSkins[i]); + } + SDL_Flip(fenetre); + } + SDL_FreeSurface(fenetre); + return classeChoisie; +} + + +/*! + * \fn int saisie_noms_joueurs() + * \brief fonction qui gère l'affichage de l'ecran de saisie des noms des joueurs + */ +int saisie_noms_joueurs() +{ + SDL_Surface* ecran=NULL; + SDL_Surface* logo = 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); + } + + SDL_Color couleurNoire = {0, 0, 0}; + SDL_Color couleurBlanche = {255, 255, 255}; + + etat=SAISIE_JOUEURS; + police=TTF_OpenFont("../resources/fonts/arial.ttf",26); + + 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 arrête + { + fprintf(stderr, "Impossible de charger le mode vidéo : %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=(ecran->w-logo->w)/2; + pos_logo.y=0; + pos_texte.x=(ecran->w-texte->w)/2; + pos_texte.y=ecran->h-200; + SDL_BlitSurface(texte,NULL,ecran,&pos_texte); + SDL_BlitSurface(logo,NULL,ecran,&pos_logo); + SDL_Flip(ecran); + + char nom_joueur1[TAILLE_NOMS] = ""; + fgets(nom_joueur1, sizeof(nom_joueur1), stdin); + if(strlen(nom_joueur1)>TAILLE_NOMS-2){ + printf("erreur : nom trop long"); + return -1; + } + if(strlen(nom_joueur1)>1){ nom_joueur1[strlen(nom_joueur1)-1]=NULL;} + + char nom_joueur2[TAILLE_NOMS] = ""; + + texte = TTF_RenderText_Shaded(police, "Entrez le nom du joueur 2", couleurBlanche,couleurNoire); + SDL_BlitSurface(texte,NULL,ecran,&pos_texte); + SDL_Flip(ecran); + + fgets(nom_joueur2, sizeof(nom_joueur2), stdin); + if(strlen(nom_joueur1)>TAILLE_NOMS-2){ + printf("erreur : nom trop long"); + return -1; + } + if(strlen(nom_joueur2)>1) {nom_joueur2[strlen(nom_joueur2)-1]=NULL;} + + ajouterUnJoueur(nom_joueur1,&etat); + ajouterUnJoueur(nom_joueur2,&etat); + + nom_1=nom_joueur1; + nom_2=nom_joueur2; + + if(etat==LANCEMENT) affichage_ecran_accueil(); + return 0; +} + + +/*! + * \fn int affichage_menu_configuration() + * \brief fonction qui gère l'affichage de l'ecran d'accueil (logo + bouton de lancement) + */ +int affichage_ecran_accueil() +{ + if(etat!=LANCEMENT) + { + etat=LANCEMENT; + nom_1="Joueur 1"; + nom_2="Joueur 2"; + ajouterUnJoueur(nom_1,&etat); + ajouterUnJoueur(nom_2,&etat); + } + + 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); + } + + SDL_Surface* ecran = SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE+1), HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF); + SDL_WM_SetCaption("Elder Internal Ignition",NULL); + SDL_Event event; + SDL_Surface* rectangle = NULL; + SDL_Surface* logo = NULL; + SDL_Surface* texte = NULL; + TTF_Font *police = NULL; + SDL_Rect pos_logo; + SDL_Rect pos_texte; + SDL_Color couleurBleue = {10, 30, 80}; + SDL_Color couleurDoree = {190, 190, 120}; + + 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,0,0,0,255,0); + + logo = SDL_LoadBMP("../resources/Skins/logo.bmp"); + if (!logo) + { + printf("Unable to load bitmap: %s\n", SDL_GetError()); + return 1; + } + pos_logo.x=(ecran->w-logo->w)/2; + pos_logo.y=0; + 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); + } + if(etat==CONFIGURATION) affichage_menu_configuration(); + return 0; +} + + +/*! + * \fn int affichage_menu_configuration() + * \brief fonction qui gère l'affichage de l'ecran de configuration de la partie (choix de la carte et des personnages) + */ +int affichage_menu_configuration() +{ + if(etat!=CONFIGURATION) + { + etat=CONFIGURATION; + } + SDL_Surface* ecran = SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE+1), HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF); + SDL_WM_SetCaption("Elder Internal Ignition",NULL); + SDL_Event event; + SDL_Surface* texte = NULL; + SDL_Surface* texte2 = NULL; + SDL_Surface* texte3 = NULL; + TTF_Font *police = NULL; + TTF_Font *petite_police = NULL; + SDL_Rect pos_texte; + SDL_Rect pos_texte2; + SDL_Rect pos_texte3; + SDL_Rect pos_texte3_bis; + SDL_Color couleurNoire = {0, 0, 0}; + SDL_Color couleurBlanche = {255, 255, 255}; + int i; + + SDL_FillRect(ecran,NULL,SDL_MapRGB(ecran->format,0,0,0)); + + police=TTF_OpenFont("../resources/fonts/OLDENGL.ttf",44); + petite_police=TTF_OpenFont("../resources/fonts/OLDENGL.ttf",32); + + texte= TTF_RenderText_Shaded(police, nom_1, couleurBlanche,couleurNoire); + texte2= TTF_RenderText_Shaded(police, nom_2, couleurBlanche, couleurNoire); + texte3= TTF_RenderText_Shaded(petite_police, "choisissez vos personnages", couleurBlanche, couleurNoire); + pos_texte.x=ecran->w/4-texte->w/2; + pos_texte.y=10; + pos_texte2.x=(3*ecran->w)/4-texte2->w/2; + pos_texte2.y=10; + pos_texte3.x=pos_texte.x-(texte3->w-texte->w)/2; + pos_texte3.y=pos_texte.y+(3*texte3->h)/2; + pos_texte3_bis.x=pos_texte2.x-(texte3->w-texte2->w)/2; + pos_texte3_bis.y=pos_texte2.y+(3*texte3->h)/2; + + SDL_BlitSurface(texte,NULL,ecran,&pos_texte); + SDL_BlitSurface(texte2,NULL,ecran,&pos_texte2); + SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3); + SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3_bis); + + SDL_Surface textes[6]; + SDL_Rect posTextes[6]; + police=TTF_OpenFont("../resources/fonts/arial.ttf",26); + + char src[50], dest[50]; + + char buffer[3]; + for(i=0;i<3;i++) + { + strcpy(dest, "personnage "); + strcpy(src, itoa(i+1,buffer,10)); + textes[i]= *TTF_RenderText_Shaded(police, strcat(dest, src), couleurBlanche,couleurNoire); + } + + for(i=3;i<6;i++) + { + strcpy(dest, "personnage "); + strcpy(src, itoa(i-2,buffer,10)); + textes[i]= *TTF_RenderText_Shaded(police, strcat(dest, src), couleurBlanche,couleurNoire); + } + + for(i=0;i<3;i++) + { + posTextes[i].x=ecran->w/4-textes[i].w/2; + posTextes[i].y=(i+1)*ecran->h/6; + SDL_BlitSurface(&textes[i],NULL,ecran,&(posTextes[i])); + } + + for(i=3;i<6;i++) + { + posTextes[i].x=(3*ecran->w)/4-textes[i].w/2; + posTextes[i].y=posTextes[i-3].y; + SDL_BlitSurface(&textes[i],NULL,ecran,&posTextes[i]); + } + SDL_Flip(ecran); + + char** path_images=obtenirSkinsClasses(); + SDL_Surface* images_classes[nbClasses()]; + SDL_Surface* images_persos[3][2]={{NULL}}; + SDL_Rect positions_images[3][2]; + int numClassePerso[3][2]={{-1,-1},{-1,-1},{-1,-1}}; + int j,p,k; + j=0; + p=0; + char *classeChoisie; + for(i=0;i<nbClasses();i++) + { + images_classes[i]=SDL_LoadBMP(path_images[i]); + if (!images_classes[i]) + { + printf("Unable to load bitmap: %s\n", SDL_GetError()); + return 1; + } + SDL_SetColorKey(images_classes[i], SDL_SRCCOLORKEY, SDL_MapRGB(images_classes[i]->format, 0, 0, 255)); + } + + SDL_Surface* map_choisie=SDL_LoadBMP("../resources/Skins/Map_select.bmp"); + if (!map_choisie) + { + printf("Unable to load bitmap: %s\n", SDL_GetError()); + return 1; + } + SDL_Surface* previsualisation[5]={NULL}; + SDL_Rect position_carte[5]; + char* path[5]; + path[0]="../resources/Skins/Map_1.bmp"; + path[1]="../resources/Skins/Map_2.bmp"; + path[2]="../resources/Skins/Map_3.bmp"; + path[3]="../resources/Skins/Map_4.bmp"; + path[4]="../resources/Skins/autre_map.bmp"; + + for(i=0;i<5;i++) + { + previsualisation[i]=SDL_LoadBMP(path[i]); + if (!previsualisation[i]) + { + printf("Unable to load bitmap: %s\n", SDL_GetError()); + return 1; + } + position_carte[i].y=(ecran->h)-(previsualisation[i]->h+100); + position_carte[i].x=(ecran->w-previsualisation[i]->w)/2+(10+previsualisation[i]->w)*(i-2); + } + + while(etat==CONFIGURATION) + { + SDL_WaitEvent(&event); + switch(event.type) + { + case SDL_QUIT: + etat=FERMER; + break; + case SDL_MOUSEBUTTONDOWN: + if(event.button.x>posTextes[0].x&&event.button.x<posTextes[0].x+textes[0].w) + j=1; + if(event.button.x>posTextes[3].x&&event.button.x<posTextes[3].x+textes[3].w) + j=2; + for(i=0;i<3;i++){ + if(event.button.y>posTextes[i].y&&event.button.y<posTextes[i].y+textes[i].h) + p=i+1; + } + if(j!=0&&p!=0){ + classeChoisie=afficherListeClasses(obtenirNomsClasses(), obtenirSkinsClasses(), nbClasses(), police, couleurBlanche); + if(classeChoisie!="fermer") + { + numClassePerso[p-1][j-1]=ajouterPersonnage(classeChoisie, p-1, j); + } + ecran = SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE+1), HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF); + + } + break; + default: + break; + } + + for(i=0;i<6;i++){ + SDL_BlitSurface(&textes[i],NULL,ecran,&(posTextes[i])); + } + for(i=0;i<3;i++){ + for(k=0;k<2;k++){ + positions_images[i][k].y=posTextes[i].y+textes[i].h; + positions_images[i][k].x=posTextes[3*k].x+(textes[3*k].w-images_classes[0]->w)/2; + images_persos[i][k]=images_classes[numClassePerso[i][k]]; + if(numClassePerso[i][k]!=-1) + { + SDL_BlitSurface(images_persos[i][k],NULL,ecran,&positions_images[i][k]); + } + } + } + SDL_BlitSurface(texte,NULL,ecran,&pos_texte); + SDL_BlitSurface(texte2,NULL,ecran,&pos_texte2); + SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3); + SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3_bis); + for(i=0;i<5;i++) + { + SDL_BlitSurface(previsualisation[i],NULL,ecran,&position_carte[i]); + } + SDL_Flip(ecran); + p=0; + j=0; + } + SDL_Quit(); + return 0; +} + + +/*! + * \fn int affichage_carte(char* Map) + * \brief fonction qui gère l'affichage pendant la partie + * + * \param la carte au format texte (une lettre = une case) + */ + +int affichage_carte(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_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_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; + + 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 arrête + { + fprintf(stderr, "Impossible de charger le mode vidéo : %s\n", SDL_GetError()); + exit(EXIT_FAILURE); + } + + SDL_WM_SetCaption("Elder Internal Ignition",NULL); + + pos_bouton_quitter.x=(LARGEUR_CARTE*LARGEUR_CASE-LARGEUR_BOUTON)/2; + pos_bouton_continuer.x=(LARGEUR_CARTE*LARGEUR_CASE-LARGEUR_BOUTON)/2; + 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_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) + { + SDL_WaitEvent(&event); + if(affichermenu==1){ + switch(event.type) /* Test du type d'événement */ + { + case SDL_QUIT: /* Si c'est un événement 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 événement de type "touche pressée" */ + switch(event.key.keysym.sym){ + case SDLK_ESCAPE: + affichermenu=0; + break; + default: + quitter=0; + } + break; + } + } + else{ + switch(event.type) /* Test du type d'événement */ + { + case SDL_QUIT: /* Si c'est un événement 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 événement de type "touche pressée" */ + 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(guerisseur,NULL,ecran,&Position_Perso[0]); + SDL_BlitSurface(mage,NULL,ecran,&Position_Perso[1]); + SDL_BlitSurface(guerrier,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); + } + 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; +} + + diff --git a/src/SDL.h b/src/affichage.h similarity index 67% rename from src/SDL.h rename to src/affichage.h index 7110046..637135e 100644 --- a/src/SDL.h +++ b/src/affichage.h @@ -1,5 +1,5 @@ /*! -* \file SDL.h +* \file affichage.h * \brief Fichier contenant les signatures des fonctions liees a l'affichage par SDL. */ @@ -15,7 +15,14 @@ #define HAUTEUR_BOUTON 20 #define LARGEUR_BOUTON 115 -int main_SDL(char* Map); -int SDL_bis(); + +int saisie_noms_joueurs(); + +int affichage_menu_configuration(); + +int affichage_ecran_accueil(); + +int affichage_carte(char* Map); + #endif diff --git a/src/controleur.c b/src/controleur.c index 4e5ffff..812189b 100644 --- a/src/controleur.c +++ b/src/controleur.c @@ -7,6 +7,7 @@ #include <stdlib.h> #include <string.h> +#include "controleur.h" #include "partie.h" #include "joueur.h" #include "joueurList.h" @@ -15,7 +16,7 @@ #include "classe.h" #include "gamePackage.h" #include "roxml.h" -#include "SDL.h" +#include "affichage.h" #include "structures.h" Partie * partieGlobale; diff --git a/src/controleurSDL.c b/src/controleurSDL.c index bd3cd92..f6b5e37 100644 --- a/src/controleurSDL.c +++ b/src/controleurSDL.c @@ -7,7 +7,7 @@ #include "personnage.h" #include "case.h" #include "deplacements.h" -#include "SDL.h" +#include "affichage.h" #include "controleurSDL.h" #include "controleur.h" diff --git a/src/main.c b/src/main.c index 32ab623..df8557a 100644 --- a/src/main.c +++ b/src/main.c @@ -5,7 +5,7 @@ #include "case.h" #include "terrain.h" #include "controleur.h" -#include "SDL.h" +#include "affichage.h" #include "roxml.h" #include "carte.h" #include "Interface.h" @@ -83,18 +83,15 @@ int init_jeu(char *filename) return 0; } -int main() +int main(void) { //init_jeu("../resources/Init_jeu.xml"); initJeu(); - SDL_bis(); - - - - + //saisie_noms_joueurs(); /*lance le jeu à l'ecran "entrer nom joueur 1"*/ + affichage_ecran_accueil(); /*lance le jeu direct à l'ecran de lancement, sans rentrer les noms des joueurs*/ return 0; -- GitLab