1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include "structures.h"
#include "constantes.h"
#include "prototypes.h"
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions)
{
TTF_Font *police = NULL;
int Vchoix = PALADIN;
SDL_Color vert;
bool continuer = true;
PERSONNAGES persos[3];
ENNEMIS ennemis[5];
SDL_Event event;
int Vnbperso = 0;
vert.r = 39;
vert.g = 189;
vert.b = 31;
police = TTF_OpenFont ("TIMESI.TTF",36);
/* loop until we have actually chosen our three characters */
while (Vnbperso < 3) {
static const char *strings[] = {
"Please choose the class of your first character",
"Please choose the class of your second character",
"Please choose the class of your third character",
};
/* display the background with the selected text */
if (Vchoix == PALADIN) {
SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu);
} else if (Vchoix == PRETRE) {
SDL_BlitSurface (surfaces->Pchoixpretre,NULL,surfaces->Pecran,&positions->Vpositionmenu);
} else if (Vchoix == VOLEUR) {
SDL_BlitSurface (surfaces->Pchoixvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenu);
} else {
abort();
}
/* display the string associated with the current character number (aka Please choose ...) */
surfaces->Ptextechoixmenu = TTF_RenderText_Blended (police, strings[Vnbperso], vert);
positions->Vpositiontextemenu.x=XWIN/2-surfaces->Ptextechoixmenu->w/2;
SDL_BlitSurface (surfaces->Ptextechoixmenu,NULL,surfaces->Pecran,&positions->Vpositiontextemenu);
SDL_BlitSurface (surfaces->Ppretre,NULL,surfaces->Pecran,&positions->Vpositionmenupretre);
SDL_BlitSurface (surfaces->Ppaladin,NULL,surfaces->Pecran,&positions->Vpositionmenupaladin);
SDL_BlitSurface (surfaces->Pvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenuvoleur);
SDL_Flip (surfaces->Pecran);
continuer = true;
while (continuer)
{
SDL_WaitEvent (&event);
switch (event.type)
{
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_LEFT:
case SDLK_h:
if (Vchoix > PALADIN) {
Vchoix--;
} else {
Vchoix=VOLEUR;
}
Fchangersurlignage2 (Vchoix,surfaces,positions);
break;
case SDLK_RIGHT:
case SDLK_l:
if (Vchoix < VOLEUR) {
Vchoix++;
} else {
Vchoix = PALADIN;
}
Fchangersurlignage2 (Vchoix,surfaces,positions);
break;
case SDLK_RETURN:
case SDLK_f:
persos[Vnbperso++].classe = Vchoix;
continuer = false;
break;
default:
break;
}
break;
}
}
}
TTF_CloseFont (police);
SDL_Flip(surfaces->Pecran);
Fremplirpersos2 (surfaces,persos);
Fmap(surfaces,positions,persos,ennemis);
}
void Fchangersurlignage2 (int Vchoix, SURFACES *surfaces, POSITIONS *positions)
{
if (Vchoix==PALADIN)
SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu);
else if (Vchoix==PRETRE)
SDL_BlitSurface (surfaces->Pchoixpretre,NULL,surfaces->Pecran,&positions->Vpositionmenu);
else if (Vchoix==VOLEUR)
SDL_BlitSurface (surfaces->Pchoixvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenu);
SDL_BlitSurface (surfaces->Ppretre,NULL,surfaces->Pecran,&positions->Vpositionmenupretre);
SDL_BlitSurface (surfaces->Ppaladin,NULL,surfaces->Pecran,&positions->Vpositionmenupaladin);
SDL_BlitSurface (surfaces->Pvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenuvoleur);
SDL_BlitSurface (surfaces->Ptextechoixmenu,NULL,surfaces->Pecran,&positions->Vpositiontextemenu);
SDL_Flip (surfaces->Pecran);
}
void Fremplirpersos2 (SURFACES *surfaces, PERSONNAGES persos[])
{
int i;
for (i=0;i<3;i++)
{
if (persos[i].classe==PALADIN)
surfaces->Tperso[i]=IMG_Load("images/paladin.bmp");
else if (persos[i].classe==PRETRE)
surfaces->Tperso[i]=IMG_Load("images/prĂȘtre.bmp");
else if (persos[i].classe==VOLEUR)
surfaces->Tperso[i]=IMG_Load("images/voleur.bmp");
}
}
void Fremplirennemis (SURFACES *surfaces,int Vnbennemis,ENNEMIS ennemis[])
{
int i;
for (i=0;i<=Vnbennemis;i++)
{
if (ennemis[i].classe==GUERRIER_GOBELIN)
surfaces->Tennemi[i]=surfaces->Pgobelin;
}
}
int Fcalculernbennemis ()
{
int nb;
nb=(rand()%(4-0+1))+0;
return nb;
}
|