| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- //
- // menu.c
- // Life
- //
- // Created by Benoit Sida on 2014-06-13.
- // Copyright (c) 2014 Benoit Sida. All rights reserved.
- //
-
- #include <stdio.h>
- #include "constante.h"
- #include "menu.h"
-
- static void eventChoice(int* choice, int* running, int* current);
-
- int menu(Sprites *Sprites, SDL_Window *ecran, SDL_Surface *screen)
- {
- int running = 1, choice = 0, current = 1;
- SDL_Rect select, position, element1 = {4,7}, element2={5,9};
- while (running) {
- for (int i = 0 ; i < MAXMAP ; i++)
- {
- position.x = i%NB_BLOCS * TAILLE_BLOC;
- position.y = i/NB_BLOCS * TAILLE_BLOC;
- SDL_BlitSurface(Sprites->cell, NULL, screen, &position);
- }
- position.x = position.y = 0;
- SDL_BlitSurface(Sprites->menu, NULL, screen, &position);
- (current == 1) ? (select.x = element1.x * TAILLE_BLOC) : (select.x = element2.x * TAILLE_BLOC);
- (current == 1) ? (select.y = element1.y * TAILLE_BLOC) : (select.y = element2.y * TAILLE_BLOC);
- SDL_BlitSurface(Sprites->arrow, NULL, screen, &select);
- SDL_UpdateWindowSurface(ecran);
- eventChoice(&choice, &running, ¤t);
- }
- return choice;
- }
-
- static void eventChoice(int* choice, int* running, int* current)
- {
- SDL_Event event;
- SDL_WaitEvent(&event);
- switch (event.type){
- case SDL_QUIT:
- exit(EXIT_SUCCESS);
- break;
- case SDL_KEYDOWN:
- switch (event.key.keysym.sym) {
- case SDLK_ESCAPE:
- exit(EXIT_SUCCESS);
- break;
- case SDLK_1:
- *choice = 1;
- running = 0;
- break;
- case SDLK_2:
- *choice = 2;
- running = 0;
- break;
- case SDLK_UP:
- *current = 1;
- break;
- case SDLK_DOWN:
- *current = 2;
- break;
- case SDLK_RETURN:
- *running = 0;
- *choice = *current;
- break;
-
- }
- break;
- }
- }
|