summaryrefslogtreecommitdiff
path: root/menuprincipal.c
blob: 51d47322d2e9798faa9fa4007f4f1000a527cb9a (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
#include <stdlib.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include "structures.h"
#include "prototypes.h"
#include "constantes.h"

void Fmenuprincipal (SURFACES *surfaces, POSITIONS *positions)
{
    int continuer = 1;
    SDL_Event event;
    int Vmode = 0;
    SDL_BlitSurface (surfaces->Pmenujouer,NULL,surfaces->Pecran,&positions->Vpositionmenu);
    SDL_Flip (surfaces->Pecran);
    while (continuer)
    {
        SDL_WaitEvent (&event);
        switch (event.type)
        {
            case SDL_KEYDOWN:
            switch (event.key.keysym.sym)
            {
                case SDLK_DOWN:
                case SDLK_j:

                if (Vmode < 2)
                {
                    Vmode++;
                    Fchangersurlignage (Vmode,surfaces,positions);
                }
                else
                {
                    Vmode = 0;
                    Fchangersurlignage (Vmode,surfaces,positions);
                }
                break;
                case SDLK_UP:
                case SDLK_k:
                if (Vmode > 0)
                {
                    Vmode--;
                    Fchangersurlignage (Vmode,surfaces,positions);
                }
                else
                {
                    Vmode = 2;
                    Fchangersurlignage (Vmode,surfaces,positions);
                }
                break;
                case SDLK_RETURN:
                case SDLK_f:
                continuer = Fentrermode (Vmode,surfaces,positions);
                Vmode = 0;
                if (continuer)
                {
                    SDL_BlitSurface (surfaces->Pmenujouer,NULL,surfaces->Pecran,&positions->Vpositionmenu);
                    SDL_Flip (surfaces->Pecran);
                }
                break;
                default:
                break;
            }
            break;
        }
    }
}

void Fchangersurlignage (int Vmode, SURFACES *surfaces, POSITIONS *positions)
{
    if (Vmode == 0)
        SDL_BlitSurface (surfaces->Pmenujouer,NULL,surfaces->Pecran,&positions->Vpositionmenu);
    else if (Vmode == 1)
        SDL_BlitSurface (surfaces->Pmenuoptions,NULL,surfaces->Pecran,&positions->Vpositionmenu);
    else if (Vmode == 2)
        SDL_BlitSurface (surfaces->Pmenuquitter,NULL,surfaces->Pecran,&positions->Vpositionmenu);
    SDL_Flip (surfaces->Pecran);
}

int Fentrermode (int Vmode, SURFACES *surfaces, POSITIONS *positions)
{
    int continuer = 1;

    if (Vmode == 0)
        Fmenuchoixpersos (surfaces,positions);
    else if (Vmode == 1)
        Foptions (surfaces,positions);
    else if (Vmode == 2)
        continuer = 0;
    return continuer;
}