102 lines
3.0 KiB
C
102 lines
3.0 KiB
C
/**
|
|
* \file main.c
|
|
*
|
|
* Le main permet de stocker et de lancer les fonctions permetant de lancer le jeu.
|
|
*/
|
|
#include "../include/display.h"
|
|
#include "../include/function.h"
|
|
#include "../include/read.h"
|
|
#include <SDL2/SDL.h>
|
|
#include <SDL2/SDL_image.h>
|
|
#include <SDL2/SDL_render.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#define SIZE_PLAY 20
|
|
#define SIZE_MENU 200
|
|
|
|
int main ()
|
|
{
|
|
dis display_user;
|
|
display_user.size_menu = SIZE_MENU;
|
|
display_user.size_box = SIZE_PLAY;
|
|
display_user.size_window = getMaxSize (display_user);
|
|
initSDL (&display_user);
|
|
|
|
vect *playerPos = (vect *)malloc (sizeof (vect));
|
|
vect *targets = {0};
|
|
int nbr_targets;
|
|
score playerScore = {0};
|
|
char **tab2d = creatArea2D (SIZE_PLAY, SIZE_PLAY);
|
|
|
|
score score_user = {0, 0, 0,0};
|
|
vect dim = {SIZE_PLAY, SIZE_PLAY};
|
|
int output = -1;
|
|
|
|
vect dim_menu = {0, 0};
|
|
vect pos = {4, 1};
|
|
char**menu = generatorMenu("maps", &dim_menu, &pos);
|
|
|
|
backgroundDisplay(&display_user);
|
|
vect null = {0, 0};
|
|
output = inGameLoop (menu, &dim_menu, &pos, &null , 1,
|
|
&display_user, &score_user, true);
|
|
nullScore(&score_user);
|
|
SDL_RenderClear(display_user.renderer);
|
|
SDL_Event event;
|
|
|
|
// Loop pour le jeu entier menu et les jeux.
|
|
while(output != 0)
|
|
{
|
|
|
|
SDL_RenderClear(display_user.renderer);
|
|
backgroundDisplay(&display_user);
|
|
if(output == -1)
|
|
{
|
|
menu = generatorMenu("maps", &dim_menu, &pos);
|
|
pos.x = 4; pos.y = 1;
|
|
output = inGameLoop(menu, &dim_menu, &pos, &null, 1, &display_user, &score_user, true);
|
|
nullScore(&score_user);
|
|
}
|
|
else if(output == -2)
|
|
{
|
|
output = inEditorLoop(menu, &dim_menu, &pos, &null, 1, &display_user, &score_user);
|
|
}
|
|
else
|
|
{
|
|
score_user.before = time(NULL);
|
|
char txt[30] = "";
|
|
if(output <= 3)
|
|
{
|
|
snprintf(txt, 30, "maps/original_%d.txt", output);
|
|
}
|
|
else
|
|
{
|
|
snprintf(txt, 30, "maps/custom_%d.txt", output - 4);
|
|
}
|
|
if (targets != NULL) free(targets);
|
|
if (tab2d != NULL) free2D(tab2d, SIZE_PLAY);
|
|
tab2d = creatArea2D(SIZE_PLAY, SIZE_PLAY);
|
|
targets = fileToTab2D(txt, tab2d, SIZE_PLAY, playerPos, &nbr_targets);
|
|
output = inGameLoop(tab2d, &dim, playerPos, targets, nbr_targets, &display_user, &score_user, false);
|
|
SDL_RenderClear(display_user.renderer);
|
|
score_user.after = time(NULL);
|
|
if(output != -1000) winOrLoseLoop(&display_user, &score_user, output==1);
|
|
output = -1;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//screenDisplay(tab2d, SIZE_PLAY, SIZE_PLAY);
|
|
SDL_DestroyWindow (display_user.window);
|
|
SDL_DestroyRenderer (display_user.renderer);
|
|
if (tab2d != NULL)free2D (tab2d, SIZE_PLAY);
|
|
if (playerPos != NULL)free (playerPos);
|
|
if (targets != NULL)free (targets);
|
|
SDL_Quit ();
|
|
|
|
return 0;
|
|
}
|