93 lines
2.8 KiB
C
93 lines
2.8 KiB
C
#include "main.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
#include "logHelper.h"
|
|
#include <SDL2/SDL.h>
|
|
#include <SDL2/SDL_image.h>
|
|
#include <SDL2/SDL_ttf.h>
|
|
//#include <SDL2/SDL_thread.h>
|
|
//#include <SDL2/SDL_mutex.h>
|
|
#include "arenaEngine.h"
|
|
#include "arenaGUI.h"
|
|
//#include "IAEngine.h"
|
|
#include "playerInterface.h"
|
|
|
|
|
|
void initDisplayLib() {
|
|
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
|
addLogCritical("Init SDL libs failed !");
|
|
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
int random_lim(int max) {
|
|
int r, d = RAND_MAX / max;
|
|
max *= d;
|
|
do { r = rand(); } while (r >= max);
|
|
return r / d;
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
addLogInfo("Starting game...");
|
|
srand(time(NULL));
|
|
addLogInfo("Try init SDL libs...");
|
|
initDisplayLib();
|
|
|
|
addLogInfo("Load ressources in memory...");
|
|
TILE *tile_ressources = createTileList();
|
|
PLAYER *player_ressources = createPlayerList();
|
|
/*
|
|
SDL_Surface *tile_grass = NULL, *tile_rock = NULL, *tile_tree = NULL, *tile_water = NULL, *sprite_player_act = NULL, *sprite_ia_act = NULL;
|
|
SDL_Surface *ressource[6] = {tile_grass, tile_rock, tile_tree, tile_water, sprite_player_act, sprite_ia_act};
|
|
SDL_Surface *sprite_player[4] = {NULL}, *sprite_ia[4] = {NULL};
|
|
tile_grass = IMG_Load("data/tile_grass.png");
|
|
tile_rock = IMG_Load("data/tile_rock.png");
|
|
tile_tree = IMG_Load("data/tile_tree.png");
|
|
tile_water = IMG_Load("data/tile_water.png");
|
|
|
|
sprite_player[DOWN] = IMG_Load("data/sprite_player_1.png");
|
|
//sprite_player[UP] = IMG_Load("data/sprite_player_2.png");
|
|
//sprite_player[LEFT] = IMG_Load("data/sprite_player_3.png");
|
|
//sprite_player[RIGHT] = IMG_Load("data/sprite_player_4.png");
|
|
|
|
sprite_ia[DOWN] = IMG_Load("data/sprite_ia_1.png");
|
|
//sprite_ia[UP] = IMG_Load("data/sprite_ia_2.png");
|
|
//sprite_ia[LEFT] = IMG_Load("data/sprite_ia_3.png");
|
|
//sprite_ia[RIGHT] = IMG_Load("data/sprite_ia_4.png");
|
|
*/
|
|
|
|
addLogInfo("Create SDL windows instance...");
|
|
SDL_Window* gameWindows = SDL_CreateWindow("Arena Survival Tournament - alpha 0.2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOWS_WIDTH, WINDOWS_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
|
|
|
|
addLogInfo("Creating new arena...");
|
|
ARENA_H_TILE* arena = NULL;
|
|
arena = genNewArena(A_HEIGHT, A_WIDTH);
|
|
if (arena == NULL) {
|
|
addLogCritical("Error with arena generator !");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
addLogInfo("Successfully created arena.");
|
|
|
|
addLogInfo("Display arena GUI...");
|
|
//sprite_player_act = sprite_player[DOWN];
|
|
//sprite_ia_act = sprite_ia[DOWN];
|
|
displayArena(arena, gameWindows, tile_ressources, A_HEIGHT, A_WIDTH, TILE_SIZE);
|
|
|
|
|
|
SDL_Delay(5000);
|
|
|
|
deleteArena(arena);
|
|
addLogInfo("Cleared arena.");
|
|
|
|
clearRessourcesCache(tile_ressources, player_ressources);
|
|
addLogInfo("Free ressources.");
|
|
|
|
|
|
addLogInfo("Unload SDL libs...");
|
|
SDL_Quit();
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|