Merge branch 'arena'
This commit is contained in:
commit
fc7085d306
@ -17,9 +17,10 @@
|
|||||||
|
|
||||||
int IAEngine(PLAYER * player1, PLAYER * player2)
|
int IAEngine(PLAYER * player1, PLAYER * player2)
|
||||||
{
|
{
|
||||||
|
char Race[20];
|
||||||
|
|
||||||
//Player 1 est le joueur, player 2 le bot
|
//Player 1 est le joueur, player 2 le bot
|
||||||
if((player1 != NULL) & (player2 !=NULL))
|
if((player1 != NULL) & (player2 !=NULL))
|
||||||
char Race[20];
|
|
||||||
{
|
{
|
||||||
//On récupère les positions des 2 joueurs . L'IA sait où est le joueur
|
//On récupère les positions des 2 joueurs . L'IA sait où est le joueur
|
||||||
int Player1PositionX = player1->PositionX;
|
int Player1PositionX = player1->PositionX;
|
||||||
|
103
arenaEngine.c
103
arenaEngine.c
@ -2,36 +2,31 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "fileHandler.h"
|
#include "fileHandler.h"
|
||||||
|
#include "logHelper.h"
|
||||||
|
|
||||||
int initResources() {
|
|
||||||
//resOpen();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Arena generate functions
|
||||||
|
*/
|
||||||
ARENA_H_TILE* createHTile(ARENA_H_TILE* prevHTile) {
|
ARENA_H_TILE* createHTile(ARENA_H_TILE* prevHTile) {
|
||||||
ARENA_H_TILE* tile_h = NULL;
|
ARENA_H_TILE* tile_h = NULL;
|
||||||
|
|
||||||
if (prevHTile == NULL) {
|
if (prevHTile == NULL) {
|
||||||
tile_h = calloc(1,sizeof(ARENA_H_TILE)); //Using calloc because of resetting all memory allocated to 0
|
tile_h = calloc(1,sizeof(ARENA_H_TILE)); //Using calloc because of resetting all memory allocated to 0
|
||||||
tile_h->type_id = 0;
|
tile_h->type_id = 0;
|
||||||
tile_h->isGround = 1;
|
tile_h->playerOnTile = NULL;
|
||||||
tile_h->canBeMined = 0;
|
|
||||||
tile_h->nextRow = NULL;
|
tile_h->nextRow = NULL;
|
||||||
tile_h->nextColumn = NULL;
|
tile_h->nextColumn = NULL;
|
||||||
|
|
||||||
return tile_h;
|
|
||||||
} else if (prevHTile != NULL) {
|
} else if (prevHTile != NULL) {
|
||||||
tile_h = calloc(1,sizeof(ARENA_H_TILE));
|
tile_h = calloc(1,sizeof(ARENA_H_TILE));
|
||||||
prevHTile->nextRow = tile_h;
|
prevHTile->nextRow = tile_h;
|
||||||
tile_h->type_id = 0;
|
tile_h->type_id = 0;
|
||||||
tile_h->isGround = 1;
|
tile_h->playerOnTile = NULL;
|
||||||
tile_h->canBeMined = 0;
|
|
||||||
tile_h->nextRow = NULL;
|
tile_h->nextRow = NULL;
|
||||||
tile_h->nextColumn = NULL;
|
tile_h->nextColumn = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return tile_h;
|
||||||
}
|
}
|
||||||
|
|
||||||
ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) {
|
ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) {
|
||||||
@ -41,8 +36,7 @@ ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) {
|
|||||||
tile_w = calloc(1,sizeof(ARENA_W_TILE));
|
tile_w = calloc(1,sizeof(ARENA_W_TILE));
|
||||||
prevHTile->nextColumn = tile_w;
|
prevHTile->nextColumn = tile_w;
|
||||||
tile_w->type_id = 0;
|
tile_w->type_id = 0;
|
||||||
tile_w->isGround = 1;
|
tile_w->playerOnTile = NULL;
|
||||||
tile_w->canBeMined = 0;
|
|
||||||
tile_w->nextColumn = NULL;
|
tile_w->nextColumn = NULL;
|
||||||
|
|
||||||
return tile_w;
|
return tile_w;
|
||||||
@ -50,29 +44,28 @@ ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) {
|
|||||||
tile_w = calloc(1,sizeof(ARENA_W_TILE));
|
tile_w = calloc(1,sizeof(ARENA_W_TILE));
|
||||||
prevWTile->nextColumn = tile_w;
|
prevWTile->nextColumn = tile_w;
|
||||||
tile_w->type_id = 0;
|
tile_w->type_id = 0;
|
||||||
tile_w->isGround = 1;
|
tile_w->playerOnTile = NULL;
|
||||||
tile_w->canBeMined = 0;
|
|
||||||
tile_w->nextColumn = NULL;
|
tile_w->nextColumn = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ARENA_H_TILE* genNewArena(int w, int h) {
|
ARENA_H_TILE* genNewArena(int size_h, int size_w) {
|
||||||
ARENA_H_TILE* arenaOrigin = NULL;
|
ARENA_H_TILE* arenaOrigin = NULL;
|
||||||
ARENA_H_TILE* TmpCursor_h = NULL;
|
ARENA_H_TILE* TmpCursor_h = NULL;
|
||||||
ARENA_W_TILE* TmpCursor_w = NULL;
|
ARENA_W_TILE* TmpCursor_w = NULL;
|
||||||
int i,j;
|
int i,j;
|
||||||
|
|
||||||
for(i=0;i<h;i++){
|
for(i=0;i<size_h;i++){
|
||||||
if (i==0) {
|
if (i==0) {
|
||||||
arenaOrigin = createHTile(NULL);
|
arenaOrigin = createHTile(NULL);
|
||||||
TmpCursor_h = arenaOrigin;
|
TmpCursor_h = arenaOrigin;
|
||||||
} else {
|
} else {
|
||||||
createHTile(TmpCursor_h);
|
TmpCursor_h = createHTile(TmpCursor_h);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(j=0;j<w;j++){
|
for(j=0;j<size_w;j++){
|
||||||
if (j==0) {
|
if (j==0) {
|
||||||
TmpCursor_w = createWTile(TmpCursor_h, NULL);
|
TmpCursor_w = createWTile(TmpCursor_h, NULL);
|
||||||
} else {
|
} else {
|
||||||
@ -81,13 +74,77 @@ ARENA_H_TILE* genNewArena(int w, int h) {
|
|||||||
|
|
||||||
if (j!=0) TmpCursor_w = TmpCursor_w->nextColumn;
|
if (j!=0) TmpCursor_w = TmpCursor_w->nextColumn;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i!=0) TmpCursor_h = TmpCursor_h->nextRow;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return arenaOrigin;
|
return arenaOrigin;
|
||||||
}
|
}
|
||||||
|
|
||||||
int deleteArena(ARENA_H_TILE* genNewArena) {
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Arena delete functions
|
||||||
|
*/
|
||||||
|
void deleteWTile(ARENA_W_TILE* WTile) {
|
||||||
|
if (WTile->nextColumn != NULL) {
|
||||||
|
deleteWTile(WTile->nextColumn);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(WTile);
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteHTile(ARENA_H_TILE* HTile) {
|
||||||
|
if (HTile->nextRow != NULL) {
|
||||||
|
deleteHTile(HTile->nextRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteWTile(HTile->nextColumn);
|
||||||
|
free(HTile);
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteArena(ARENA_H_TILE* arena) {
|
||||||
|
deleteHTile(arena);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Arena status functions
|
||||||
|
*/
|
||||||
|
int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y) {
|
||||||
|
int type_id = -1;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (coord_y == 0) {
|
||||||
|
ARENA_H_TILE* tile_h = NULL;
|
||||||
|
|
||||||
|
tile_h = arena;
|
||||||
|
if (coord_x != 0) {
|
||||||
|
for (i=0;i<coord_x;i++) {
|
||||||
|
tile_h = arena->nextRow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type_id = tile_h->type_id;
|
||||||
|
} else {
|
||||||
|
ARENA_W_TILE* tile_w = NULL;
|
||||||
|
ARENA_H_TILE* tile_h = NULL;
|
||||||
|
|
||||||
|
tile_h = arena;
|
||||||
|
if (coord_x != 0) {
|
||||||
|
for (i=0;i<coord_x;i++) {
|
||||||
|
tile_h = tile_h->nextRow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tile_w = tile_h->nextColumn;
|
||||||
|
if (coord_y != 0) {
|
||||||
|
for (i=0;i<coord_y;i++) {
|
||||||
|
tile_w = tile_w->nextColumn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type_id = tile_w->type_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return type_id;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#include "playerInterface.h"
|
||||||
|
|
||||||
#ifndef ARENAENGINE_H_
|
#ifndef ARENAENGINE_H_
|
||||||
#define ARENAENGINE_H_
|
#define ARENAENGINE_H_
|
||||||
|
|
||||||
@ -13,21 +15,32 @@ typedef struct items{
|
|||||||
}ITEMS;
|
}ITEMS;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct arena_h_tile{ //Rows chained list
|
typedef struct tileType{
|
||||||
int type_id;
|
int type_id;
|
||||||
//texture?
|
//texture?
|
||||||
int isGround;
|
int isGround;
|
||||||
int canBeMined;
|
int canBeMined;
|
||||||
|
}TILE;
|
||||||
|
|
||||||
|
typedef struct arena_h_tile{ //Rows chained list
|
||||||
|
int type_id;
|
||||||
|
PLAYER* playerOnTile;
|
||||||
struct arena_h_tile *nextRow;
|
struct arena_h_tile *nextRow;
|
||||||
struct arena_w_tile *nextColumn;
|
struct arena_w_tile *nextColumn;
|
||||||
}ARENA_H_TILE;
|
}ARENA_H_TILE;
|
||||||
|
|
||||||
typedef struct arena_w_tile{ //Columns chained list
|
typedef struct arena_w_tile{ //Columns chained list
|
||||||
int type_id;
|
int type_id;
|
||||||
//texture?
|
PLAYER* playerOnTile;
|
||||||
int isGround;
|
|
||||||
int canBeMined;
|
|
||||||
struct arena_w_tile *nextColumn;
|
struct arena_w_tile *nextColumn;
|
||||||
}ARENA_W_TILE;
|
}ARENA_W_TILE;
|
||||||
|
|
||||||
|
|
||||||
|
//Generation functions
|
||||||
|
ARENA_H_TILE* genNewArena(int size_h, int size_w);
|
||||||
|
void deleteArena(ARENA_H_TILE* arena);
|
||||||
|
|
||||||
|
//Status functions
|
||||||
|
int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
77
main.c
77
main.c
@ -11,65 +11,50 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "logHelper.h"
|
#include "logHelper.h"
|
||||||
#include "SDL2/SDL.h"
|
#include <SDL2/SDL.h>
|
||||||
#include "SDL2/SDL_thread.h"
|
#include <SDL2/SDL_thread.h>
|
||||||
#include "SDL2/SDL_mutex.h"
|
#include <SDL2/SDL_mutex.h>
|
||||||
#include "arenaEngine.h"
|
#include "arenaEngine.h"
|
||||||
|
|
||||||
int main(void)
|
#define A_HEIGHT 100
|
||||||
{
|
#define A_WIDTH 100
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
|
||||||
|
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) != 0 )
|
void initDisplayLib() {
|
||||||
{
|
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||||
fprintf(stdout,"Échec de l'initialisation de la SDL (%s)\n",SDL_GetError());
|
addLogCritical("Init SDL libs failed !");
|
||||||
return -1;
|
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
|
||||||
int continuer = 1;
|
void initResources() {
|
||||||
int action;
|
//resOpen();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
ARENA_H_TILE* arena = NULL;
|
||||||
|
|
||||||
// Création de la fenêtre
|
// Création de la fenêtre
|
||||||
SDL_Window* pWindow = NULL;
|
SDL_Window* pWindow = NULL;
|
||||||
pWindow = SDL_CreateWindow("Arena Survival Tournament",SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,640,480,SDL_WINDOW_SHOWN);
|
pWindow = SDL_CreateWindow("Arena Survival Tournament",SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,640,480,SDL_WINDOW_SHOWN);
|
||||||
|
|
||||||
|
addLogInfo("Starting game...");
|
||||||
|
initDisplayLib();
|
||||||
|
initResources();
|
||||||
|
|
||||||
SDL_Event event; // Cette variable servira plus tard à gérer les événements
|
addLogInfo("Creating new arena...");
|
||||||
|
arena = genNewArena(A_HEIGHT, A_WIDTH);
|
||||||
|
if (arena == NULL) {
|
||||||
|
addLogCritical("Error with arena generator !");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
addLogInfo("Successfully created arena.");
|
||||||
|
|
||||||
if( pWindow )
|
deleteArena(arena);
|
||||||
{
|
addLogInfo("Cleared arena.");
|
||||||
SDL_Delay(3000); /* Attendre trois secondes, que l'utilisateur voie la fenêtre */
|
|
||||||
while (continuer)
|
|
||||||
{
|
|
||||||
|
|
||||||
action = PlayerInterface();
|
|
||||||
if (action == -1)
|
|
||||||
{
|
|
||||||
continuer = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
|
||||||
//SDL_DestroyWindow(pWindow);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr,"Erreur de création de la fenêtre: %s\n",SDL_GetError());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//IAEngine();
|
|
||||||
|
|
||||||
SDL_Quit();
|
|
||||||
//PlayerInterface();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "SDL2/SDL.h"
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
void initDisplayLib() {
|
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
|
||||||
printf("Erreur chargement librairie SDL ! %s\n",SDL_GetError());
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int createGameMenuWindows() {
|
int createGameMenuWindows() {
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user