summaryrefslogtreecommitdiff
path: root/menuchoixpersos.c
blob: 05e1a0a6761ca35cd4958a006b3c392134c4423b (plain)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#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>
#include "players.h"

static
struct team_t *new_ally_team(SURFACES *surfaces,
        const enum character_class_t *classes, int cnt)
{
    struct team_t *team = malloc(sizeof(struct team_t));

    team->name = "Team Player";
    team->cpu = false;
    team->chr_cnt = cnt;
    team->chrs = malloc(sizeof(struct character_t) * team->chr_cnt);

    for (int i = 0; i < team->chr_cnt; i++) {
        struct character_t *chr = &team->chrs[i];

        chr->name = "Player";
        chr->cpu = false;
        chr->team = team;
        chr->class_ = classes[i];
        chr->alive = true;

        switch (chr->class_) {
            case CLASS_PALADIN:
                chr->def_surf = surfaces->Ppaladin;
                chr->red_surf = surfaces->red_paladin;
                break;
            case CLASS_PRIEST:
                chr->def_surf = surfaces->Ppretre;
                chr->red_surf = surfaces->red_priest;
                break;
            case CLASS_THIEF:
                chr->def_surf = surfaces->Pvoleur;
                chr->red_surf = surfaces->red_thief;
                break;
            default:
                abort();
        }

        chr->surf = chr->def_surf;

        chr->hp = base_stats_g[chr->class_].hp;
        chr->max_hp = base_stats_g[chr->class_].hp;
        chr->mp = base_stats_g[chr->class_].mp;
        chr->max_mp = base_stats_g[chr->class_].mp;
        chr->magic = base_stats_g[chr->class_].magic;
        chr->strength = base_stats_g[chr->class_].strength;
        chr->defense = base_stats_g[chr->class_].defense;
        chr->spirit = base_stats_g[chr->class_].spirit;

        /* set its position */
        chr->pos.x = 20;
        chr->pos.y = (YWIN / (cnt + 1)) * (i + 1) - chr->def_surf->h / 2;
    }

    return team;
}

void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions)
{
    TTF_Font *police = NULL;
    int Vchoix = PALADIN;
    SDL_Color vert;
    bool continuer = true;
    struct team_t *ally_team;
    enum character_class_t chr_classes[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:
                    chr_classes[Vnbperso++] = Vchoix;
                    continuer = false;
                    break;
                    default:
                    break;
                }
                break;
            }
        }
    }
    TTF_CloseFont (police);
    SDL_Flip(surfaces->Pecran);
    ally_team = new_ally_team(surfaces, chr_classes, 3);
    Fmap(surfaces,positions, ally_team,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 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;
}