From edcbec30ccfa7de4741e8d15ea5e1b9314ac4842 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=A9na=C3=AFg=20Le=20Moigne?=
 <lenaig.le-moigne@insa-rennes.fr>
Date: Fri, 13 May 2016 22:51:23 +0200
Subject: [PATCH] =?UTF-8?q?D=C3=A9but=20de=20la=20gestion=20changement=20d?=
 =?UTF-8?q?e=20joueur=20avec=20un=20bouton?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ElderInternalIgnition/SDL_lena_pour_henry.c | 383 --------------------
 src/affichage.c                             |  49 ++-
 2 files changed, 48 insertions(+), 384 deletions(-)
 delete mode 100644 ElderInternalIgnition/SDL_lena_pour_henry.c

diff --git a/ElderInternalIgnition/SDL_lena_pour_henry.c b/ElderInternalIgnition/SDL_lena_pour_henry.c
deleted file mode 100644
index 1245aff..0000000
--- a/ElderInternalIgnition/SDL_lena_pour_henry.c
+++ /dev/null
@@ -1,383 +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_entrer_royaume=NULL;
-    SDL_Surface* logo=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_logo;
-    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 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_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*10;
-    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;
-    pos_logo.x=(LARGEUR_CARTE*LARGEUR_CASE-LARGEUR_BOUTON)/14;
-    pos_logo.y=(HAUTEUR_CARTE*HAUTEUR_CASE-HAUTEUR_BOUTON)/10+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;
-    }
-
-    logo = SDL_LoadBMP("../resources/Skins/logo.bmp");
-    if (!logo)
-    {
-        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'événement */
-            {
-                case SDL_QUIT: /* Si c'est un événement 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 = Jeu;
-                    }
-                    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;
-            }
-        SDL_BlitSurface(logo,NULL,ecran,&pos_logo);
-        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'é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(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;
-}
diff --git a/src/affichage.c b/src/affichage.c
index c6f0a22..beddcb4 100644
--- a/src/affichage.c
+++ b/src/affichage.c
@@ -646,7 +646,7 @@ int affichage_carte()
     int x=0;
     int nombre_classes=nbClasses();
     SDL_Event event;
-    SDL_Surface* ecran=SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE+1), HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF);;
+    SDL_Surface* ecran=SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE+20), HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF);;
     SDL_Surface* classes[nombre_classes];
     SDL_Surface* cases[HAUTEUR_CARTE][LARGEUR_CARTE];
     SDL_Surface* persos[NB_PERSO*NB_JOUEURS];
@@ -657,6 +657,46 @@ int affichage_carte()
     SDL_Rect Position_Case_brillante;
     SDL_Rect Position_Guerrier_select;
 
+    SDL_Surface* texte = NULL;
+    SDL_Surface* texte2 = NULL;
+    SDL_Surface* texte3 = NULL;
+    SDL_Surface* texte4 = NULL;
+    SDL_Surface* previsualisation[5]= {NULL};
+    SDL_Surface* textes[NB_JOUEURS*NB_PERSO]= {NULL};
+    SDL_Rect pos_bouton;
+    SDL_Rect pos_texte;
+    SDL_Rect pos_texte2;
+    SDL_Rect pos_texte3;
+    SDL_Rect pos_texte4;
+    TTF_Font *police = NULL;
+    TTF_Font *petite_police = NULL;
+    TTF_Font *mini_police = NULL;
+    SDL_Color couleurNoire = {0, 0, 0};
+    SDL_Color couleurBlanche = {255, 255, 255};
+    SDL_Color couleurBleue = {10, 30, 80};
+    SDL_Color couleurDoree = {190, 190, 120};
+
+    police=TTF_OpenFont("../resources/fonts/OLDENGL.ttf",46);
+    petite_police=TTF_OpenFont("../resources/fonts/arial.ttf",32);
+    mini_police=TTF_OpenFont("../resources/fonts/arial.ttf",25);
+
+    texte= TTF_RenderText_Shaded(police, "Joueur actuel", couleurBlanche,couleurNoire);
+    texte2= TTF_RenderText_Shaded(petite_police, nom_1, couleurBlanche, couleurNoire);
+    texte3= TTF_RenderText_Shaded(petite_police, nom_2, couleurBlanche, couleurNoire);
+    texte4= TTF_RenderText_Shaded(mini_police, "Joueur suivant", couleurBlanche, couleurNoire);
+
+
+    pos_texte.x=ecran->w/1.15-texte->w/2;
+    pos_texte.y=10;
+    pos_texte2.x=pos_texte.x-(texte2->w-texte->w)/2;
+    pos_texte2.y=pos_texte.y+(3*texte2->h)/2;
+    pos_texte3.x=pos_texte.x-(texte3->w-texte->w)/2;
+    pos_texte3.y=pos_texte.y+(3*texte3->h)/2;
+    pos_texte4.x=pos_texte.x-(texte4->w-texte->w)/2;
+    pos_texte4.y=pos_texte.y+(3*texte4->h)/0.8;
+
+
+
     for(i=0; i<LARGEUR_CARTE; i++)
     {
         for(j=0; j<HAUTEUR_CARTE; j++)
@@ -731,6 +771,8 @@ int affichage_carte()
             break;
         case SDL_MOUSEBUTTONDOWN:
             //deplacement_personnage(event.button.x,event.button.y);
+            //nextJoueur();
+
             break;
         case SDL_MOUSEMOTION:
             if(event.motion.x<LARGEUR_CARTE*LARGEUR_CASE&&event.motion.y<HAUTEUR_CARTE*HAUTEUR_CASE)
@@ -775,6 +817,11 @@ int affichage_carte()
         }
         /*SDL_BlitSurface(Guerrier_select,NULL,ecran,&Position_Guerrier_select);*/
         SDL_BlitSurface(Case_brillante,NULL,ecran,&Position_Case_brillante);
+
+        SDL_BlitSurface(texte,NULL,ecran,&pos_texte);
+        SDL_BlitSurface(texte2,NULL,ecran,&pos_texte2);
+        SDL_BlitSurface(texte4,NULL,ecran,&pos_texte4);
+
         SDL_Flip(ecran);
     }
 
-- 
GitLab