| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- //
- // main.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"
- #include "sim.h"
-
- static void initSprites(Sprites *Sprites);
-
- int main(int argc, const char * argv[])
- {
- if (SDL_Init(SDL_INIT_VIDEO) == -1) {
- printf("Erreur lors de l'initialisation du module SDL. Erreur : %s", SDL_GetError());
- exit(EXIT_FAILURE);
- }
- int choice = 0;
- SDL_Window *ecran;
- SDL_Surface *screen;
- Sprites Sprites;
- ecran = SDL_CreateWindow("LIFE", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, LARGEUR_ECRAN, HAUTEUR_ECRAN, SDL_WINDOW_SHOWN);
- screen = SDL_GetWindowSurface(ecran);
- initSprites(&Sprites);
- SDL_SetWindowIcon(ecran, Sprites.icon);
- while (choice == 0) {
- choice = menu(&Sprites, ecran, screen);
- switch (choice) {
- case 1:
- sim(&Sprites, ecran, screen, CYCLES);
- choice = 0;
- break;
- case 2:
- exit(EXIT_SUCCESS);
- break;
- default :
- choice = 0;
- break;
- }
- }
- SDL_Quit();
- return EXIT_SUCCESS;
- }
-
- static void initSprites(Sprites *Sprites)
- {
- Sprites->cell = IMG_Load("sprites/cell.png");
- Sprites->alivecell = IMG_Load("sprites/alivecell.png");
- Sprites->deadcell = IMG_Load("sprites/deadcell.png");
- Sprites->cellsheet = IMG_Load("sprites/cellsheet.png");
- Sprites->menu = IMG_Load("sprites/menu.png");
- Sprites->arrow = IMG_Load("sprites/arrow.png");
- Sprites->icon = IMG_Load("sprites/icon.png");
-
- for (int i = 0; i < SHEETSIZE; i++)
- {
- Sprites->clip[i].x = (i%(SHEETSIZE/4))*TAILLE_BLOC;
- Sprites->clip[i].y = (i/(SHEETSIZE/4))*TAILLE_BLOC;
- Sprites->clip[i].h = Sprites->clip[i].w = TAILLE_BLOC;
- }
-
- }
|