| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- //
- // 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(SDL_Window *ecran, SDL_Surface *screen)
- {
- int running = 1, choice = 0, current = 1;
- SDL_Rect select, position, element1 = {4,7}, element2={5,9};
- SDL_Surface *menu = NULL, *arrow = NULL, *wall = NULL;
- menu = IMG_Load("sprites/menu.png");
- arrow = IMG_Load("sprites/arrow.png");
- wall = IMG_Load("sprites/wall.png");
- while (running) {
- position.x = position.y = 0;
- SDL_BlitSurface(wall, NULL, screen, &position);
- SDL_BlitSurface(menu, NULL, screen, &position); // Affiche le menu
- (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(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;
- }
- }
|