Merge branch 'arena'

This commit is contained in:
JackCarterSmith 2018-06-23 11:45:32 +02:00
commit 8faa5edc7b
19 changed files with 2204 additions and 1882 deletions

3
.gitignore vendored
View File

@ -41,6 +41,9 @@
*.su *.su
*.idb *.idb
*.pdb *.pdb
docs\
latex\
html\
# Kernel Module Compile Results # Kernel Module Compile Results
*.mod* *.mod*

File diff suppressed because it is too large Load Diff

View File

@ -1,30 +1,23 @@
/* #ifndef IAENGINE_H_
* IAEngine.h #define IAENGINE_H_
*
* Created on: 17 juin 2018 typedef struct noeud
* Author: isen {
*/ int compteur, min, cout_f; //
#ifndef IAENGINE_H_ int ParentX;
#define IAENGINE_H_ int ParentY;
// 'adresse' du parent (qui sera toujours dans la map fermée)
typedef struct noeud }NOEUD;
{
int compteur, min, cout_f; //
int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2PositionX, int Player2PositionY);
int ParentX; //int IAEngine(PLAYER * player1, PLAYER * player2);
int ParentY; int IAEngine(ARENA_H_TILE* arena,PLAYER * player1, PLAYER * player2);
// 'adresse' du parent (qui sera toujours dans la map fermée) int distance(int x1, int y1, int x2, int y2);
}NOEUD; //int CalculatePath(ARENA_H_TILE* arena,int PositionX, int PositionY,PLAYER * player1, int compteur, int distance,int min);
//int CalculatePath(ARENA_H_TILE* arena,int posX, int posY,NOEUD * n1,PLAYER * player1, int compteur, int dist,int min);
int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2PositionX, int Player2PositionY); NOEUD * CalculatePath(ARENA_H_TILE* arena,int posX, int posY,NOEUD * n1,PLAYER * player1,PLAYER * player2, int compteur, int dist,int min);
//int IAEngine(PLAYER * player1, PLAYER * player2); //NOEUD * CalculatePath(ARENA_H_TILE* arena,int posX, int posY,NOEUD * n1,PLAYER * player1, int compteur, int dist,int min);
int IAEngine(ARENA_H_TILE* arena,PLAYER * player1, PLAYER * player2); #endif /* IAENGINE_H_ */
int distance(int x1, int y1, int x2, int y2);
//int CalculatePath(ARENA_H_TILE* arena,int PositionX, int PositionY,PLAYER * player1, int compteur, int distance,int min);
//int CalculatePath(ARENA_H_TILE* arena,int posX, int posY,NOEUD * n1,PLAYER * player1, int compteur, int dist,int min);
NOEUD * CalculatePath(ARENA_H_TILE* arena,int posX, int posY,NOEUD * n1,PLAYER * player1,PLAYER * player2, int compteur, int dist,int min);
//NOEUD * CalculatePath(ARENA_H_TILE* arena,int posX, int posY,NOEUD * n1,PLAYER * player1, int compteur, int dist,int min);
#endif /* IAENGINE_H_ */

View File

@ -1,105 +1,168 @@
#include "arenaEngine.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "fileHandler.h" #include "fileHandler.h"
//#include "logHelper.h" #include "logHelper.h"
#include "arenaEngine.h"
/* /*
* Arena generate functions * Arena generate functions
*/ */
TILE *createTileList(void) {
TILE *tile_0 = NULL, *tile_1 = NULL, *tile_2 = NULL, *tile_3 = NULL, *tile_4 = NULL, *tile_5 = NULL;
#define BLOC_SIZE 32 // Taille d'un bloc (carré) en pixels tile_0 = calloc(1,sizeof(TILE));
#define NB_BLOCS_LARGEUR 20 tile_1 = calloc(1,sizeof(TILE));
#define NB_BLOCS_HAUTEUR 20 tile_2 = calloc(1,sizeof(TILE));
#define LARGEUR_FENETRE BLOC_SIZE * NB_BLOCS_LARGEUR tile_3 = calloc(1,sizeof(TILE));
#define HAUTEUR_FENETRE BLOC_SIZE * NB_BLOCS_HAUTEUR tile_4 = calloc(1,sizeof(TILE));
tile_5 = calloc(1,sizeof(TILE));
tile_0->type_id = 0;
tile_0->texture = IMG_Load("data/tile_grass.png");
tile_0->canBeMined = 0;
tile_0->isGround = 1;
tile_0->nextTile = tile_1;
tile_1->type_id = 1;
tile_1->texture = IMG_Load("data/tile_rock.png");
tile_1->canBeMined = 0;
tile_1->isGround = 1;
tile_1->nextTile = tile_2;
ARENA_H_TILE* genNewArena(int size_h, int size_w) tile_2->type_id = 2;
{ tile_2->texture = IMG_Load("data/tile_tree.png");
ARENA_H_TILE* arenaOrigin = NULL; tile_2->canBeMined = 0;
ARENA_H_TILE* TmpCursor_h = NULL; tile_2->isGround = 0;
ARENA_W_TILE* TmpCursor_w = NULL; tile_2->nextTile = tile_3;
int i,j;
FILE* fichier = NULL; tile_3->type_id = 3;
char ligneFichier[NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1] = {0}; tile_3->texture = IMG_Load("data/tile_water.png");
//int i = 0, j = 0; tile_3->canBeMined = 0;
tile_3->isGround = 0;
tile_3->nextTile = tile_4;
printf("Chargement du fichier\n"); tile_4->type_id = 4;
fichier = fopen("level2-20x20.lvl", "r"); tile_4->texture = IMG_Load("data/tile_gold.png");
tile_4->canBeMined = 1;
tile_4->isGround = 1;
tile_4->nextTile = tile_5;
if (fichier == NULL) tile_5->type_id = 5;
return 0; tile_5->texture = IMG_Load("data/tile_spawn.png");
tile_5->canBeMined = 0;
tile_5->isGround = 1;
tile_5->nextTile = NULL;
fgets(ligneFichier, size_w * size_h + 1, fichier); return tile_0;
for(i=0;i<size_h;i++)
{
if (i==0)
{
arenaOrigin = createHTile(NULL);
TmpCursor_h = arenaOrigin;
}
else
{
TmpCursor_h = createHTile(TmpCursor_h);
}
for(j=0;j<size_w;j++)
{
if (j==0)
{
TmpCursor_w = createWTile(TmpCursor_h, NULL);
}
else
{
createWTile(NULL, TmpCursor_w);
}
switch (ligneFichier[(i * size_w) + j])
{
case '0': TmpCursor_w->type_id = 0;
//printf("herbe\n");
break;
case '1':
TmpCursor_w->type_id = 1;
// printf("caillou\n");
break;
case '2':
TmpCursor_w->type_id = 2;
//printf("arbre\n");
break;
}
if (j!=0) TmpCursor_w = TmpCursor_w->nextColumn;
}
}
return arenaOrigin;
} }
PLAYER *createPlayerList(void) {
PLAYER *p0 = NULL, *p1 = NULL, *p2 = NULL, *p3 = NULL;
p0 = calloc(1,sizeof(PLAYER));
p1 = calloc(1,sizeof(PLAYER));
p2 = calloc(1,sizeof(PLAYER));
p3 = calloc(1,sizeof(PLAYER));
p0->Id = 0;
p0->PositionX = 0;
p0->PositionY = 0;
p0->texture[DOWN] = IMG_Load("data/sprite_player_0.png");
p0->texture[UP] = IMG_Load("data/sprite_player_1.png");
p0->texture[LEFT] = IMG_Load("data/sprite_player_2.png");
p0->texture[RIGHT] = IMG_Load("data/sprite_player_3.png");
p0->suiv = p1;
ARENA_H_TILE* createHTile(ARENA_H_TILE* prevHTile) p1->Id = 1;
{ p1->PositionX = A_WIDTH;
p1->PositionY = A_HEIGHT;
p1->texture[DOWN] = IMG_Load("data/sprite_ia_0.png");
p1->texture[UP] = IMG_Load("data/sprite_ia_1.png");
p1->texture[LEFT] = IMG_Load("data/sprite_ia_2.png");
p1->texture[RIGHT] = IMG_Load("data/sprite_ia_3.png");
p1->suiv = p2;
p2->Id = 0;
p2->PositionX = 0;
p2->PositionY = A_HEIGHT;
//p2->texture[DOWN] = IMG_Load("data/sprite_player_0.png");
//p2->texture[UP] = IMG_Load("data/sprite_player_1.png");
//p2->texture[LEFT] = IMG_Load("data/sprite_player_2.png");
//p2->texture[RIGHT] = IMG_Load("data/sprite_player_3.png");
p2->suiv = p3;
p3->Id = 0;
p3->PositionX = A_WIDTH;
p3->PositionY = 0;
//p3->texture[DOWN] = IMG_Load("data/sprite_player_0.png");
//p3->texture[UP] = IMG_Load("data/sprite_player_1.png");
//p3->texture[LEFT] = IMG_Load("data/sprite_player_2.png");
//p3->texture[RIGHT] = IMG_Load("data/sprite_player_3.png");
p3->suiv = NULL;
return p1;
}
void clearRessourcesCache(TILE *t, PLAYER *p) {
PLAYER *p0 = NULL, *p1 = NULL, *p2 = NULL, *p3 = NULL;
TILE *tile_0 = NULL, *tile_1 = NULL, *tile_2 = NULL, *tile_3 = NULL, *tile_4 = NULL, *tile_5 = NULL;
int i;
p0 = p;
p1 = p0->suiv;
p2 = p1->suiv;
p3 = p2->suiv;
tile_0 = t;
tile_1 = tile_0->nextTile;
tile_2 = tile_1->nextTile;
tile_3 = tile_2->nextTile;
tile_4 = tile_3->nextTile;
tile_5 = tile_4->nextTile;
for (i=0;i<=3;i++) {
SDL_FreeSurface(p0->texture[i]);
}
for (i=0;i<=3;i++) {
SDL_FreeSurface(p1->texture[i]);
}
/*
for (i=0;i<=3;i++) {
SDL_FreeSurface(p2->texture[i]);
}
for (i=0;i<=3;i++) {
SDL_FreeSurface(p3->texture[i]);
}
*/
free(p3);free(p2);free(p1);free(p0);
SDL_FreeSurface(tile_0->texture);
SDL_FreeSurface(tile_1->texture);
SDL_FreeSurface(tile_2->texture);
SDL_FreeSurface(tile_3->texture);
SDL_FreeSurface(tile_4->texture);
SDL_FreeSurface(tile_5->texture);
free(tile_0);free(tile_1);free(tile_2);free(tile_3);free(tile_4);free(tile_5);
}
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->type_id = random_lim(5);
//tile_h->playerOnTile = NULL; //tile_h->playerOnTile = NULL;
tile_h->nextRow = NULL; tile_h->nextRow = NULL;
tile_h->nextColumn = NULL; tile_h->nextColumn = NULL;
} } 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->type_id = random_lim(5);
//tile_h->playerOnTile = NULL; //tile_h->playerOnTile = NULL;
tile_h->nextRow = NULL; tile_h->nextRow = NULL;
tile_h->nextColumn = NULL; tile_h->nextColumn = NULL;
@ -108,59 +171,96 @@ ARENA_H_TILE* createHTile(ARENA_H_TILE* prevHTile)
return tile_h; 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) {
{
ARENA_W_TILE* tile_w = NULL; ARENA_W_TILE* tile_w = NULL;
if (prevHTile != NULL && prevWTile == NULL) if (prevHTile != NULL && prevWTile == NULL) {
{
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->type_id = random_lim(5);
//tile_w->playerOnTile = NULL; //tile_w->playerOnTile = NULL;
tile_w->nextColumn = NULL; tile_w->nextColumn = NULL;
return tile_w; return tile_w;
} } else if (prevHTile == NULL && prevWTile != NULL) {
else if (prevHTile == NULL && prevWTile != NULL)
{
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->type_id = random_lim(5);
//tile_w->playerOnTile = NULL; //tile_w->playerOnTile = NULL;
tile_w->nextColumn = NULL; tile_w->nextColumn = NULL;
} }
return NULL; return NULL;
} }
/*
ARENA_H_TILE* genNewArena(int size_h, int size_w) int setTileTypeID(ARENA_H_TILE* arena, int x, int y, int new_id) {
{ int i;
//x=coord_x-1;
//y=coord_y-1;
if (x > A_WIDTH || y > A_HEIGHT || x < 0 || y < 0) return -1;
if (y == 0) {
ARENA_H_TILE* tile_h = NULL;
tile_h = arena;
if (x != 0) {
for (i=0;i<x;i++) {
tile_h = tile_h->nextRow;
}
}
tile_h->type_id = new_id;
if (tile_h->type_id == new_id) return 0;
} else {
ARENA_W_TILE* tile_w = NULL;
ARENA_H_TILE* tile_h = NULL;
tile_h = arena;
if (x != 0) {
for (i=0;i<x;i++) {
tile_h = tile_h->nextRow;
}
}
tile_w = tile_h->nextColumn;
if (y != 0) {
for (i=0;i<y;i++) {
tile_w = tile_w->nextColumn;
}
}
tile_w->type_id = new_id;
if (tile_w->type_id == new_id) return 0;
}
return -1;
}
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 z,i,j,rand_x,rand_y;
for(i=0;i<size_h;i++) /*
{ * Generate new flatgrass arena
if (i==0) */
{ for(i=0;i<=size_h;i++){
if (i==0) {
arenaOrigin = createHTile(NULL); arenaOrigin = createHTile(NULL);
TmpCursor_h = arenaOrigin; TmpCursor_h = arenaOrigin;
} } else {
else
{
TmpCursor_h = createHTile(TmpCursor_h); TmpCursor_h = createHTile(TmpCursor_h);
} }
for(j=0;j<size_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
{
createWTile(NULL, TmpCursor_w); createWTile(NULL, TmpCursor_w);
} }
@ -168,16 +268,103 @@ ARENA_H_TILE* genNewArena(int size_h, int size_w)
} }
} }
/*
* Generate some rock area
*/
for (z=1; z <= A_WIDTH * A_HEIGHT * ROCK_GEN_RATE/100; z++) {
rand_x = random_lim(A_WIDTH)-1;
rand_y = random_lim(A_HEIGHT)-1;
for (i=-2;i<=1;i++) {
for (j=-1;j<=3;j++) {
if (random_lim(101) < 65) {
if (((rand_x + i) >= 0 && (rand_x + i) < A_WIDTH) && ((rand_y + j) >= 0 && (rand_y + j) < A_HEIGHT)) {
if(setTileTypeID(arenaOrigin, rand_x+i, rand_y+j, ROCK)!=0) addLogWarn("Failed to add rock on arena."); else z++;
}
}
}
}
}
/*
* Generate some tree area on grass
*/
for (z=1; z <= A_WIDTH * A_HEIGHT * TREE_GEN_RATE/100; z++) {
rand_x = random_lim(A_WIDTH)-1;
rand_y = random_lim(A_HEIGHT)-1;
for (i=-2;i<=2;i++) {
for (j=-2;j<=2;j++) {
if (random_lim(101) < 65) {
if (((rand_x + i >= 0 && rand_x + i < A_WIDTH) && (rand_y + j >= 0 && rand_y + j < A_HEIGHT)) && getTileTypeID(arenaOrigin, rand_x+i, rand_y+j) == GRASS) {
if(setTileTypeID(arenaOrigin, rand_x+i, rand_y+j, TREE)!=0) addLogWarn("Failed to tree add on arena."); else z++;
}
}
}
}
}
/*
* Generate some gold area on rock
*/
for (z=1; z <= A_WIDTH * A_HEIGHT * GOLD_GEN_RATE/100; z++) {
rand_x = random_lim(A_WIDTH)-1;
rand_y = random_lim(A_HEIGHT)-1;
if (((rand_x + i >= 0 && rand_x + i <= A_WIDTH) && (rand_y + j >= 0 && rand_y + j <= A_HEIGHT)) && getTileTypeID(arenaOrigin, rand_x+i, rand_y+j) == ROCK) {
if(setTileTypeID(arenaOrigin, rand_x+i, rand_y+j, GOLD)!=0) addLogWarn("Failed to add gold on arena."); else z++;
}
}
/*
* Generate some water area on grass
*/
for (z=1; z <= A_WIDTH * A_HEIGHT * WATER_GEN_RATE/100; z++) {
rand_x = random_lim(A_WIDTH)-1;
rand_y = random_lim(A_HEIGHT)-1;
for (i=-2;i<=2;i++) {
for (j=-3;j<=3;j++) {
if (i >= -1 && j >= -1 && i <= 1 && j <= 1) {
if (((rand_x + i) >= 0 && (rand_x + i) < A_WIDTH) && ((rand_y + j) >= 0 && (rand_y + j) < A_HEIGHT)) {
if(setTileTypeID(arenaOrigin, rand_x+i, rand_y+j, WATER)!=0) {
addLogWarn("Failed to add water on arena.");
}else z++;
}
} /*else {
if (random_lim(101) < 60) {
if ((rand_x + i >= 0 && rand_x + i <= A_WIDTH) && (rand_y + i >= 0 && rand_y + i <= A_HEIGHT)) {
if(setTileTypeID(arenaOrigin, rand_x+i, rand_y+j, WATER)!=0) addLogWarn("Tree failed to add on arena."); else z++;
}
}
}*/
}
}
}
/*
* Generate spawn
*/
for (z=0; z <= 1; z++) {
if(setTileTypeID(arenaOrigin, 0+z, 0, SPAWN)!=0) addLogWarn("Failed to add spawn area up left corner");
if(setTileTypeID(arenaOrigin, 0, 0+z, SPAWN)!=0) addLogWarn("Failed to add spawn area up left corner");
if(setTileTypeID(arenaOrigin, 0+z, 0+z, SPAWN)!=0) addLogWarn("Failed to add spawn area up left corner");
}
for (z=0; z <= 1; z++) {
if(setTileTypeID(arenaOrigin, A_WIDTH-1-z, A_HEIGHT-1, SPAWN)!=0) addLogWarn("Failed to add spawn area botton right corner");
if(setTileTypeID(arenaOrigin, A_WIDTH-1, A_HEIGHT-1-z, SPAWN)!=0) addLogWarn("Failed to add spawn area botton right corner");
if(setTileTypeID(arenaOrigin, A_WIDTH-1-z, A_HEIGHT-1-z, SPAWN)!=0) addLogWarn("Failed to add spawn area botton right corner");
}
return arenaOrigin; return arenaOrigin;
} }
*/
/* /*
* Arena delete functions * Arena delete functions
*/ */
void deleteWTile(ARENA_W_TILE* WTile) void deleteWTile(ARENA_W_TILE* WTile) {
{
if (WTile->nextColumn != NULL) { if (WTile->nextColumn != NULL) {
deleteWTile(WTile->nextColumn); deleteWTile(WTile->nextColumn);
} }
@ -185,10 +372,8 @@ void deleteWTile(ARENA_W_TILE* WTile)
free(WTile); free(WTile);
} }
void deleteHTile(ARENA_H_TILE* HTile) void deleteHTile(ARENA_H_TILE* HTile) {
{ if (HTile->nextRow != NULL) {
if (HTile->nextRow != NULL)
{
deleteHTile(HTile->nextRow); deleteHTile(HTile->nextRow);
} }
@ -196,8 +381,7 @@ void deleteHTile(ARENA_H_TILE* HTile)
free(HTile); free(HTile);
} }
void deleteArena(ARENA_H_TILE* arena) void deleteArena(ARENA_H_TILE* arena) {
{
deleteHTile(arena); deleteHTile(arena);
} }
@ -206,45 +390,39 @@ void deleteArena(ARENA_H_TILE* arena)
/* /*
* Arena status functions * Arena status functions
*/ */
int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y) int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y) {
{
int type_id = -1; int type_id = -1;
int i; int i;
//coord_x=x-1;
//coord_y=y-1;
if (coord_y == 0) if (coord_x > A_WIDTH || coord_y > A_HEIGHT || coord_x < 0 || coord_y < 0) return -1;
{
if (coord_y == 0) {
ARENA_H_TILE* tile_h = NULL; ARENA_H_TILE* tile_h = NULL;
tile_h = arena; tile_h = arena;
if (coord_x != 0) if (coord_x != 0) {
{ for (i=0;i<coord_x;i++) {
for (i=0;i<coord_x;i++) tile_h = tile_h->nextRow;
{
tile_h = arena->nextRow;
} }
} }
type_id = tile_h->type_id; type_id = tile_h->type_id;
} } else {
else
{
ARENA_W_TILE* tile_w = NULL; ARENA_W_TILE* tile_w = NULL;
ARENA_H_TILE* tile_h = NULL; ARENA_H_TILE* tile_h = NULL;
tile_h = arena; tile_h = arena;
if (coord_x != 0) if (coord_x != 0) {
{ for (i=0;i<coord_x;i++) {
for (i=0;i<coord_x;i++)
{
tile_h = tile_h->nextRow; tile_h = tile_h->nextRow;
} }
} }
tile_w = tile_h->nextColumn; tile_w = tile_h->nextColumn;
if (coord_y != 0) if (coord_y != 0) {
{ for (i=0;i<coord_y;i++) {
for (i=0;i<coord_y;i++)
{
tile_w = tile_w->nextColumn; tile_w = tile_w->nextColumn;
} }
} }
@ -254,3 +432,66 @@ int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y)
return type_id; return type_id;
} }
int isGroundTile(TILE *t_list, int id) {
TILE *tmp_tile = NULL;
int i=0;
tmp_tile = t_list;
while (i<id) {
tmp_tile = tmp_tile->nextTile;
i++;
}
return tmp_tile->isGround;
}
SDL_Surface *getTileSurfaceFromID(TILE *t_list, int id) {
TILE *tmp_tile = NULL;
int i=0;
tmp_tile = t_list;
while (i<id) {
tmp_tile = tmp_tile->nextTile;
i++;
}
return tmp_tile->texture;
}
int isPlayerAdjacent(PLAYER* p1, PLAYER* p2) {
int adjPlayer = -1;
if ((p1->PositionX-1 || p1->PositionX+1) == p2->PositionX && (p1->PositionY-1 || p1->PositionY+1) == p2->PositionY) adjPlayer = 1;
return adjPlayer;
}
int isMoveCorrect(ARENA_H_TILE* arena, TILE *t_list, int coord_x, int coord_y, int direction) {
if (!((coord_x <= 0 && direction == LEFT) || (coord_y <= 0 && direction == UP) || (coord_x >= A_HEIGHT && direction == RIGHT) || (coord_y >= A_WIDTH && direction == DOWN))) {
if (isGroundTile(t_list,getTileTypeID(arena,coord_x,coord_y))) {
return 1;
}
}
return 0;
}
int getRelativeDirection(SDL_Rect pos1, SDL_Rect pos2) {
int _x,_y;
_x = pos2.x - pos1.x;
_y = pos2.y - pos1.y;
if (_x>1) {
return DOWN;
} else if (_x<1) {
return UP;
} else if (_y>1) {
return RIGHT;
} else if (_y<1) {
return LEFT;
} else {
return -1;
}
}

View File

@ -1,52 +1,70 @@
//#include "playerInterface.h" #include "main.h"
#include <SDL2/SDL.h>
#ifndef ARENAENGINE_H_ #include <SDL2/SDL_image.h>
#define ARENAENGINE_H_
#ifndef ARENAENGINE_H_
#define ARENAENGINE_H_
/*
typedef struct items{
int type_id; typedef struct tileType{
//texture? int type_id;
int isFlat; SDL_Surface *texture;
int minedId; int isGround;
struct items *nextItem; int canBeMined;
}ITEMS; struct tileType *nextTile;
*/ }TILE;
typedef struct tileType typedef struct Player
{ {
int type_id; int Id;
//texture? char Name[35];
int isGround; //char Race[20];
int canBeMined;
}TILE; SDL_Surface *texture[4];
typedef struct arena_h_tile int HealthPoints;
{ //Rows chained list int AttacksPoints;
int type_id; int DefensePoints;
//PLAYER* playerOnTile;
struct arena_h_tile *nextRow; int PositionX;
struct arena_w_tile *nextColumn; int PositionY;
}ARENA_H_TILE; //char Weapons[Max_Weapons];
typedef struct arena_w_tile //int Coins;
{ //Columns chained list
int type_id; struct Player * suiv;
//PLAYER* playerOnTile;
struct arena_w_tile *nextColumn; }PLAYER;
}ARENA_W_TILE;
typedef struct arena_h_tile{ //Rows chained list
int type_id;
//Generation functions //PLAYER* playerOnTile;
ARENA_H_TILE* genNewArena(int size_h, int size_w); struct arena_h_tile *nextRow;
void deleteArena(ARENA_H_TILE* arena); struct arena_w_tile *nextColumn;
}ARENA_H_TILE;
ARENA_H_TILE* createHTile(ARENA_H_TILE* prevHTile);
ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile); typedef struct arena_w_tile{ //Columns chained list
int type_id;
//Status functions //PLAYER* playerOnTile;
int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y); struct arena_w_tile *nextColumn;
}ARENA_W_TILE;
#endif
//Generation functions
TILE* createTileList(void);
PLAYER *createPlayerList(void);
void clearRessourcesCache(TILE *t, PLAYER *p);
int setTileTypeID(ARENA_H_TILE* arena, int x, int y, int new_id);
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);
int isGroundTile(TILE *t_list, int id);
SDL_Surface *getTileSurfaceFromID(TILE *t_list, int id);
int isPlayerAdjacent(PLAYER* p1, PLAYER* p2);
int isMoveCorrect(ARENA_H_TILE* arena, TILE *t_list, int coord_x, int coord_y, int direction);
int getRelativeDirection(SDL_Rect pos1, SDL_Rect pos2);
#endif

View File

@ -1,3 +1,34 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "SDL2/SDL.h" #include "logHelper.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include "arenaGUI.h"
void displayArena(ARENA_H_TILE* arena, SDL_Window* window, TILE *tiles, int size_h, int size_w, int tile_size) {
SDL_Rect tmp_tile_coord;
int i,j;
for (i=0; i<size_h; i++) {
for (j=0; j<size_w; j++) {
tmp_tile_coord.x = i * tile_size;
tmp_tile_coord.y = j * tile_size;
SDL_BlitSurface(getTileSurfaceFromID(tiles,getTileTypeID(arena,i,j)), NULL, SDL_GetWindowSurface(window), &tmp_tile_coord);
SDL_UpdateWindowSurface(window);
}
}
}
void updatePlayerPos(ARENA_H_TILE* arena, SDL_Window* window, PLAYER *player, TILE *tiles, SDL_Rect new_coord) {
SDL_Rect old_coord;
old_coord.x = player->PositionX;
old_coord.y = player->PositionY;
SDL_BlitSurface(getTileSurfaceFromID(tiles,getTileTypeID(arena,player->PositionX,player->PositionY)), NULL, SDL_GetWindowSurface(window), &old_coord);
SDL_BlitSurface(player->texture[getRelativeDirection(old_coord, new_coord)], NULL, SDL_GetWindowSurface(window), &new_coord);
SDL_UpdateWindowSurface(window);
}

View File

@ -1,6 +1,10 @@
#ifndef ARENAGUI_H_ #include "main.h"
#define ARENAGUI_H_ #include "arenaEngine.h"
#ifndef ARENAGUI_H_
#define ARENAGUI_H_
#endif
void displayArena(ARENA_H_TILE* arena, SDL_Window* windows, TILE *tiles, int size_h, int size_w, int tile_size);
void updatePlayerPos(ARENA_H_TILE* arena, SDL_Window* window, PLAYER *player, TILE *tiles, SDL_Rect new_coord);
#endif

View File

@ -1,118 +1,102 @@
/* #include <stdlib.h>
* fileHandler.c #include <stdio.h>
* #include "SDL2/SDL.h"
* Created on: 20 juin 2018 #include "SDL2/SDL_image.h"
* Author: isen
* #include "fileHandler.h"
* Contient la gestion des fichier et notament la récupération d'un niveau
*/ /*
#include <stdlib.h> PLAYER * LoadLevel(ARENA_H_TILE *Head)
#include <stdio.h> {
#include "SDL2/SDL.h" printf("Fonction Chargement d'un niveau\n");
#include "SDL2/SDL_image.h"
if(Head == NULL)
#include "fileHandler.h" {
//#include "main.c" printf("La liste est vide\n");
}
#define BLOC_SIZE 32 // Taille d'un bloc (carré) en pixels else
#define NB_BLOCS_LARGEUR 20 {
#define NB_BLOCS_HAUTEUR 20 FILE* fichier = NULL;
#define LARGEUR_FENETRE BLOC_SIZE * NB_BLOCS_LARGEUR char ligneFichier[NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1] = {0};
#define HAUTEUR_FENETRE BLOC_SIZE * NB_BLOCS_HAUTEUR int i = 0, j = 0;
/*
//Ouverture du fichier
PLAYER * LoadLevel(ARENA_H_TILE *Head) fichier = fopen("level1.lvl", "r");
{ if (fichier == NULL)
printf("Fonction Chargement d'un niveau\n"); return 0;
//Lecture du fichier
if(Head == NULL) fgets(ligneFichier, NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1, fichier);
{
printf("La liste est vide\n"); for (i = 0 ; i < NB_BLOCS_LARGEUR ; i++)
} {
else for (j = 0 ; j < NB_BLOCS_HAUTEUR ; j++)
{ {
FILE* fichier = NULL; switch (ligneFichier[(i * NB_BLOCS_LARGEUR) + j])
char ligneFichier[NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1] = {0}; {
int i = 0, j = 0; case '0':
//Herbe
//Ouverture du fichier ARENA_H_TILE->Type = 0;
fichier = fopen("level1.lvl", "r"); break;
if (fichier == NULL) case '1':
return 0; //Pierre
//Lecture du fichier ARENA_H_TILE->Type = 1;
fgets(ligneFichier, NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1, fichier); break;
case '2':
for (i = 0 ; i < NB_BLOCS_LARGEUR ; i++) //Arbre
{ ARENA_H_TILE->Type = 2;
for (j = 0 ; j < NB_BLOCS_HAUTEUR ; j++) break;
{ case '3':
switch (ligneFichier[(i * NB_BLOCS_LARGEUR) + j]) //Rivière
{ ARENA_H_TILE->Type = 3;
case '0': break;
//Herbe }
ARENA_H_TILE->Type = 0; Head = Head->suiv;
break; }
case '1': }
//Pierre }
ARENA_H_TILE->Type = 1; }
break;
case '2': */
//Arbre //Fonction a réadapter avec la liste chainée Arene
ARENA_H_TILE->Type = 2;
break; int chargerNiveau(int niveau[][NB_BLOCS_HAUTEUR])
case '3': {
//Rivière FILE* fichier = NULL;
ARENA_H_TILE->Type = 3; char ligneFichier[NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1] = {0};
break; int i = 0, j = 0;
}
Head = Head->suiv; printf("Chargement du fichier\n");
} fichier = fopen("level1.lvl", "r");
} if (fichier == NULL)
} return 0;
}
fgets(ligneFichier, NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1, fichier);
*/
//Fonction a réadapter avec la liste chainée Arene for (i = 0 ; i < NB_BLOCS_LARGEUR ; i++)
{
int chargerNiveau(int niveau[][NB_BLOCS_HAUTEUR]) for (j = 0 ; j < NB_BLOCS_HAUTEUR ; j++)
{ {
FILE* fichier = NULL; //printf("j= %i \n",j);
char ligneFichier[NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1] = {0}; switch (ligneFichier[(i * NB_BLOCS_LARGEUR) + j])
int i = 0, j = 0; {
case '0':
printf("Chargement du fichier\n"); niveau[j][i] = 0;
fichier = fopen("level1.lvl", "r"); //printf("herbe\n");
if (fichier == NULL) break;
return 0; case '1':
niveau[j][i] = 1;
fgets(ligneFichier, NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1, fichier); // printf("caillou\n");
break;
for (i = 0 ; i < NB_BLOCS_LARGEUR ; i++) case '2':
{ niveau[j][i] = 2;
for (j = 0 ; j < NB_BLOCS_HAUTEUR ; j++) //printf("arbre\n");
{ break;
//printf("j= %i \n",j); }
switch (ligneFichier[(i * NB_BLOCS_LARGEUR) + j]) }
{ //printf("Ligne\n");
case '0': }
niveau[j][i] = 0;
//printf("herbe\n"); fclose(fichier);
break; return 1;
case '1': }
niveau[j][i] = 1;
// printf("caillou\n");
break;
case '2':
niveau[j][i] = 2;
//printf("arbre\n");
break;
}
}
//printf("Ligne\n");
}
fclose(fichier);
return 1;
}

View File

@ -1,19 +1,6 @@
/* #ifndef FILEHANDLER_H_
* fileHandler.h #define FILEHANDLER_H_
*
* Created on: 20 juin 2018 int chargerNiveau(int niveau[][NB_BLOCS_HAUTEUR]);
* Author: isen
*/ #endif /* FILEHANDLER_H_ */
#ifndef FILEHANDLER_H_
#define FILEHANDLER_H_
#define BLOC_SIZE 32 // Taille d'un bloc (carré) en pixels
#define NB_BLOCS_LARGEUR 20
#define NB_BLOCS_HAUTEUR 20
#define LARGEUR_FENETRE BLOC_SIZE * NB_BLOCS_LARGEUR
#define HAUTEUR_FENETRE BLOC_SIZE * NB_BLOCS_HAUTEUR
int chargerNiveau(int niveau[][NB_BLOCS_HAUTEUR]);
#endif /* FILEHANDLER_H_ */

View File

@ -1,76 +1,76 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include "logHelper.h" #include "logHelper.h"
FILE *log_file=NULL; FILE *log_file=NULL;
int initialise_logger(){ int initialise_logger(){
time_t raw_time; time_t raw_time;
struct tm *pdh; struct tm *pdh;
time(&raw_time); time(&raw_time);
pdh = localtime(&raw_time); pdh = localtime(&raw_time);
char name[32]; char name[32];
sprintf(name, "%04d-%02d-%02d.log", pdh->tm_year+1900, pdh->tm_mon+1, pdh->tm_mday); sprintf(name, "logs/%04d-%02d-%02d.log", pdh->tm_year+1900, pdh->tm_mon+1, pdh->tm_mday);
log_file=fopen(name, "a"); log_file=fopen(name, "a");
if(log_file==NULL) //fichier innexistant if(log_file==NULL) //fichier innexistant
{ {
log_file=fopen(name,"w+"); log_file=fopen(name,"w+");
if(log_file==NULL) { //Le prog n'a pas les droits en écriture if(log_file==NULL) { //Le prog n'a pas les droits en écriture
printf("\n****************************************************************\nATTENTION ! Le fichier de log ne peut être écris, aucune info ne sera enregistré !\n****************************************************************\n"); printf("\n****************************************************************\nATTENTION ! Le fichier de log ne peut être écris, aucune info ne sera enregistré !\n****************************************************************\n");
return -1; return -1;
} }
} }
return 0; return 0;
} }
void stop_logger() {fclose(log_file);} void stop_logger() {fclose(log_file);}
void addLogInfo(char *mess){ void addLogInfo(char *mess){
time_t now; time_t now;
struct tm* tm_info; struct tm* tm_info;
char buffer[12]; char buffer[12];
initialise_logger(); initialise_logger();
time(&now); time(&now);
tm_info = localtime(&now); tm_info = localtime(&now);
strftime(buffer, 12, "%H:%M:%S", tm_info); strftime(buffer, 12, "%H:%M:%S", tm_info);
fprintf(log_file,"[INFO][%s] %s\n", buffer, mess); fprintf(log_file,"[INFO][%s] %s\n", buffer, mess);
stop_logger(); stop_logger();
} }
void addLogWarn(char *mess){ void addLogWarn(char *mess){
time_t now; time_t now;
struct tm* tm_info; struct tm* tm_info;
char buffer[12]; char buffer[12];
initialise_logger(); initialise_logger();
time(&now); time(&now);
tm_info = localtime(&now); tm_info = localtime(&now);
strftime(buffer, 12, "%H:%M:%S", tm_info); strftime(buffer, 12, "%H:%M:%S", tm_info);
fprintf(log_file,"[WARN][%s] %s\n", buffer, mess); fprintf(log_file,"[WARN][%s] %s\n", buffer, mess);
stop_logger(); stop_logger();
} }
void addLogCritical(char *mess){ void addLogCritical(char *mess){
time_t now; time_t now;
struct tm* tm_info; struct tm* tm_info;
char buffer[12]; char buffer[12];
initialise_logger(); initialise_logger();
time(&now); time(&now);
tm_info = localtime(&now); tm_info = localtime(&now);
strftime(buffer, 12, "%H:%M:%S", tm_info); strftime(buffer, 12, "%H:%M:%S", tm_info);
fprintf(log_file,"[CRITICAL][%s] %s\n", buffer, mess); fprintf(log_file,"[CRITICAL][%s] %s\n", buffer, mess);
stop_logger(); stop_logger();
} }

View File

@ -1,11 +1,11 @@
#ifndef LOGGER_H_ #ifndef LOGGER_H_
#define LOGGER_H_ #define LOGGER_H_
int initialise_logger(); //Prépare le logger à écrire dans les fichiers de logs int initialise_logger(); //Prépare le logger à écrire dans les fichiers de logs
void stop_logger(); void stop_logger();
void addLogInfo(char *mess); //Ajoute une entrée dans le fichier de log de type INFO void addLogInfo(char *mess); //Ajoute une entrée dans le fichier de log de type INFO
void addLogWarn(char *mess); void addLogWarn(char *mess);
void addLogCritical(char *mess); //Ajoute une entrée dans le fichier de log de type CRITICAL void addLogCritical(char *mess); //Ajoute une entrée dans le fichier de log de type CRITICAL
#endif #endif

View File

@ -1,220 +1,293 @@
/* #include "main.h"
* main.c #include <stdio.h>
* #include <stdlib.h>
* Created on: 17 juin 2018 #include <time.h>
* Author: isen #include "logHelper.h"
*/ #include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
//#include "IAEngine.h" //#include <SDL2/SDL_ttf.h>
#include "playerInterface.h" //#include <SDL2/SDL_thread.h>
#include "fileHandler.h" //#include <SDL2/SDL_mutex.h>
#include "arenaEngine.h" #include "arenaEngine.h"
#include "arenaGUI.h"
#include "SDL2/SDL.h" #include "IAEngine.h"
#include "SDL2/SDL_image.h" #include "playerInterface.h"
#include <stdio.h>
#include <stdlib.h>
void initDisplayLib() {
#define BLOC_SIZE 32 // Taille d'un bloc (carré) en pixels if (SDL_Init(SDL_INIT_VIDEO) != 0) {
#define NB_BLOCS_LARGEUR 20 addLogCritical("Init SDL libs failed !");
#define NB_BLOCS_HAUTEUR 20
#define LARGEUR_FENETRE BLOC_SIZE * NB_BLOCS_LARGEUR exit(EXIT_FAILURE);
#define HAUTEUR_FENETRE BLOC_SIZE * NB_BLOCS_HAUTEUR }
}
enum {HAUT, BAS, GAUCHE, DROITE};
enum {GRASS, ROCK, TREE,FIRSTPLAYER, IA1}; //Définit quel type de case il s'agit int random_lim(int max) {
int r, d = RAND_MAX / max;
int main(void) max *= d;
{ do { r = rand(); } while (r >= max);
return r / d;
SDL_Init(SDL_INIT_VIDEO); }
if (SDL_Init(SDL_INIT_VIDEO) != 0 )
{ int main(int argc, char *argv[]) {
fprintf(stdout,"Échec de l'initialisation de la SDL (%s)\n",SDL_GetError()); addLogInfo("Starting game...");
return -1; srand(time(NULL));
} addLogInfo("Try init SDL libs...");
else initDisplayLib();
{
int continuer = 1; addLogInfo("Load ressources in memory...");
int action; TILE *tile_ressources = createTileList();
PLAYER *player_ressources = createPlayerList();
ARENA_H_TILE* arena = NULL; //Déclaration de l'arène
addLogInfo("Create SDL windows instance...");
SDL_Surface *player[4] = {NULL}; // 4 surfaces pour 4 directions de mario SDL_Window* gameWindows = SDL_CreateWindow("Arena Survival Tournament - alpha 0.3", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOWS_WIDTH, WINDOWS_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS);
SDL_Surface *IA1[4] = {NULL}; // 4 surfaces pour 4 directions de mario
SDL_Surface *grass = NULL; addLogInfo("Creating new arena...");
SDL_Surface *rock = NULL, *tree = NULL, *river = NULL,*actualPlayer = NULL, *actualIA1 = NULL; ARENA_H_TILE* arena = NULL;
SDL_Rect position, positionJoueur; arena = genNewArena(A_HEIGHT, A_WIDTH);
if (arena == NULL) {
addLogCritical("Error with arena generator !");
exit(EXIT_FAILURE);
}
int i = 0, j = 0; addLogInfo("Successfully created arena.");
int carte[NB_BLOCS_LARGEUR][NB_BLOCS_HAUTEUR] = {0};
addLogInfo("Display arena GUI...");
//SDL_WM_SetIcon(IMG_Load("adventurer_resize.png"),NULL); //Définit l'icone de la fenêtre displayArena(arena, gameWindows, tile_ressources, A_HEIGHT, A_WIDTH, TILE_SIZE);
// Création de la fenêtre
SDL_Window* pWindow = NULL; SDL_Delay(3000);
pWindow = SDL_CreateWindow("Arena Survival Tournament",SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,LARGEUR_FENETRE,HAUTEUR_FENETRE,SDL_WINDOW_SHOWN);
deleteArena(arena);
//Génération de la nouvelle arène à partir du fichier addLogInfo("Cleared arena.");
arena = genNewArena(NB_BLOCS_HAUTEUR, NB_BLOCS_LARGEUR);
clearRessourcesCache(tile_ressources, player_ressources);
if (arena == NULL) addLogInfo("Free ressources.");
{
printf("Erreur de la génération de l'arène\n");
} addLogInfo("Unload SDL libs...");
// Chargement des sprites (décors, personnage...) SDL_Quit();
grass = IMG_Load("Landscape/grass_green_32x32.png"); return EXIT_SUCCESS;
rock = IMG_Load("Landscape/stone_green_32x32.png"); }
tree = IMG_Load("Landscape/tree_green_32x32.png");
river = IMG_Load("Landscape/river_green_32x32.png");
/*
player[BAS] = IMG_Load("Adventurer/adventurer1_32x32.png"); * main.c
player[HAUT] = IMG_Load("Adventurer/adventurer_back_32x32.png"); *
player[DROITE] = IMG_Load("Adventurer/adventurer1_right_32x32.png"); * Created on: 17 juin 2018
player[GAUCHE] = IMG_Load("Adventurer/adventurer1_left_32x32.png"); * Author: isen
*/
IA1[BAS] = IMG_Load("IA1/adventurer2_32x32.png");
IA1[HAUT] = IMG_Load("IA1/adventurer2_back_32x32.png"); //#include "IAEngine.h"
IA1[DROITE] = IMG_Load("IA1/adventurer2_right_32x32.png"); #include "playerInterface.h"
IA1[GAUCHE] = IMG_Load("IA1/adventurer2_left_32x32.png"); #include "fileHandler.h"
#include "arenaEngine.h"
actualPlayer = player[BAS];
actualIA1 = IA1[BAS]; #include "SDL2/SDL.h"
#include "SDL2/SDL_image.h"
SDL_Surface* Sprites[5]= {grass,rock,tree,actualPlayer,actualIA1}; #include <stdio.h>
#include <stdlib.h>
// Chargement du niveau pour le tableau (Phase de test)
/*if (!chargerNiveau(carte)) #define BLOC_SIZE 32 // Taille d'un bloc (carré) en pixels
{ #define NB_BLOCS_LARGEUR 20
printf("Niveau non chargé\n");// On arrête le jeu si on n'a pas pu charger le niveau #define NB_BLOCS_HAUTEUR 20
}*/ #define LARGEUR_FENETRE BLOC_SIZE * NB_BLOCS_LARGEUR
#define HAUTEUR_FENETRE BLOC_SIZE * NB_BLOCS_HAUTEUR
/*
//Cette fonction peut être utile pour rechercher un joueur ( Pour la detection) enum {HAUT, BAS, GAUCHE, DROITE};
// Recherche de la position de Mario au départ enum {GRASS, ROCK, TREE,FIRSTPLAYER, IA1}; //Définit quel type de case il s'agit
for (i = 0 ; i < NB_BLOCS_LARGEUR ; i++)
{ int main(void)
for (j = 0 ; j < NB_BLOCS_HAUTEUR ; j++) {
{
if (carte[i][j] == MARIO) // Si Mario se trouve à cette position SDL_Init(SDL_INIT_VIDEO);
{
positionJoueur.x = i; if (SDL_Init(SDL_INIT_VIDEO) != 0 )
positionJoueur.y = j; {
carte[i][j] = VIDE; fprintf(stdout,"Échec de l'initialisation de la SDL (%s)\n",SDL_GetError());
} return -1;
} }
} else
*/ {
int continuer = 1;
// Placement des objets à l'écran à la création de l'arène int action;
drawArena(pWindow,arena,Sprites);
ARENA_H_TILE* arena = NULL; //Déclaration de l'arène
SDL_Event event; // Cette variable servira plus tard à gérer les événements SDL_Surface *player[4] = {NULL}; // 4 surfaces pour 4 directions de mario
SDL_Surface *IA1[4] = {NULL}; // 4 surfaces pour 4 directions de mario
if( pWindow ) SDL_Surface *grass = NULL;
{ SDL_Surface *rock = NULL, *tree = NULL, *river = NULL,*actualPlayer = NULL, *actualIA1 = NULL;
SDL_UpdateWindowSurface(pWindow); //Rafaichis la fenetre SDL_Rect position, positionJoueur;
//SDL_Delay(3000); /* Attendre trois secondes, que l'utilisateur voie la fenêtre */
while (continuer)
{
int i = 0, j = 0;
int carte[NB_BLOCS_LARGEUR][NB_BLOCS_HAUTEUR] = {0};
action = PlayerInterface(pWindow,arena,Sprites);
//SDL_WM_SetIcon(IMG_Load("adventurer_resize.png"),NULL); //Définit l'icone de la fenêtre
if (action == -1)
{ // Création de la fenêtre
continuer = 0; SDL_Window* pWindow = NULL;
} pWindow = SDL_CreateWindow("Arena Survival Tournament",SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,LARGEUR_FENETRE,HAUTEUR_FENETRE,SDL_WINDOW_SHOWN);
else
{ //Génération de la nouvelle arène à partir du fichier
arena = genNewArena(NB_BLOCS_HAUTEUR, NB_BLOCS_LARGEUR);
}
if (arena == NULL)
{
} printf("Erreur de la génération de l'arène\n");
//SDL_DestroyWindow(pWindow); }
} // Chargement des sprites (décors, personnage...)
else grass = IMG_Load("Landscape/grass_green_32x32.png");
{ rock = IMG_Load("Landscape/stone_green_32x32.png");
fprintf(stderr,"Erreur de création de la fenêtre: %s\n",SDL_GetError()); tree = IMG_Load("Landscape/tree_green_32x32.png");
} river = IMG_Load("Landscape/river_green_32x32.png");
}
player[BAS] = IMG_Load("Adventurer/adventurer1_32x32.png");
//IAEngine(); player[HAUT] = IMG_Load("Adventurer/adventurer_back_32x32.png");
player[DROITE] = IMG_Load("Adventurer/adventurer1_right_32x32.png");
SDL_Quit(); player[GAUCHE] = IMG_Load("Adventurer/adventurer1_left_32x32.png");
//PlayerInterface();
IA1[BAS] = IMG_Load("IA1/adventurer2_32x32.png");
return 0; IA1[HAUT] = IMG_Load("IA1/adventurer2_back_32x32.png");
} IA1[DROITE] = IMG_Load("IA1/adventurer2_right_32x32.png");
IA1[GAUCHE] = IMG_Load("IA1/adventurer2_left_32x32.png");
int drawArena(SDL_Window* pWindow,ARENA_H_TILE* arena,SDL_Surface **Sprites) actualPlayer = player[BAS];
{ actualIA1 = IA1[BAS];
SDL_Rect position;
int ID; SDL_Surface* Sprites[5]= {grass,rock,tree,actualPlayer,actualIA1};
for (int i = 0 ; i < NB_BLOCS_LARGEUR ; i++)
{ // Chargement du niveau pour le tableau (Phase de test)
for (int j = 0 ; j < NB_BLOCS_HAUTEUR ; j++) /*if (!chargerNiveau(carte))
{ {
position.x = i * BLOC_SIZE; printf("Niveau non chargé\n");// On arrête le jeu si on n'a pas pu charger le niveau
position.y = j * BLOC_SIZE; }*/
ID = getTileTypeID( arena, i, j); /*
switch(ID) //Cette fonction peut être utile pour rechercher un joueur ( Pour la detection)
{ // Recherche de la position de Mario au départ
case GRASS: for (i = 0 ; i < NB_BLOCS_LARGEUR ; i++)
SDL_BlitSurface(Sprites[GRASS], NULL, SDL_GetWindowSurface(pWindow), &position); {
for (j = 0 ; j < NB_BLOCS_HAUTEUR ; j++)
break; {
case ROCK: if (carte[i][j] == MARIO) // Si Mario se trouve à cette position
SDL_BlitSurface(Sprites[ROCK], NULL, SDL_GetWindowSurface(pWindow), &position); {
break; positionJoueur.x = i;
case TREE: positionJoueur.y = j;
SDL_BlitSurface(Sprites[TREE], NULL, SDL_GetWindowSurface(pWindow), &position); carte[i][j] = VIDE;
break; }
}
} }
} */
}
} // Placement des objets à l'écran à la création de l'arène
drawArena(pWindow,arena,Sprites);
/*//Fonction draw avec un tableau. A servi de test pour le graphique
int drawArena(SDL_Window* pWindow,int carte[NB_BLOCS_LARGEUR][NB_BLOCS_HAUTEUR],SDL_Surface **Sprites) SDL_Event event; // Cette variable servira plus tard à gérer les événements
{
SDL_Rect position; if( pWindow )
for (int i = 0 ; i < NB_BLOCS_LARGEUR ; i++) {
{ SDL_UpdateWindowSurface(pWindow); //Rafaichis la fenetre
for (int j = 0 ; j < NB_BLOCS_HAUTEUR ; j++)
{ //SDL_Delay(3000); /* Attendre trois secondes, que l'utilisateur voie la fenêtre */
position.x = i * BLOC_SIZE; while (continuer)
position.y = j * BLOC_SIZE; {
switch(carte[i][j]) action = PlayerInterface(pWindow,arena,Sprites);
{
case GRASS: if (action == -1)
SDL_BlitSurface(Sprites[GRASS], NULL, SDL_GetWindowSurface(pWindow), &position); {
continuer = 0;
break; }
case ROCK: else
SDL_BlitSurface(Sprites[ROCK], NULL, SDL_GetWindowSurface(pWindow), &position); {
break;
case TREE: }
SDL_BlitSurface(Sprites[TREE], NULL, SDL_GetWindowSurface(pWindow), &position);
break;
}
} //SDL_DestroyWindow(pWindow);
} }
} else
} {
*/ fprintf(stderr,"Erreur de création de la fenêtre: %s\n",SDL_GetError());
}
}
//IAEngine();
SDL_Quit();
//PlayerInterface();
return 0;
}
int drawArena(SDL_Window* pWindow,ARENA_H_TILE* arena,SDL_Surface **Sprites)
{
SDL_Rect position;
int ID;
for (int i = 0 ; i < NB_BLOCS_LARGEUR ; i++)
{
for (int j = 0 ; j < NB_BLOCS_HAUTEUR ; j++)
{
position.x = i * BLOC_SIZE;
position.y = j * BLOC_SIZE;
ID = getTileTypeID( arena, i, j);
switch(ID)
{
case GRASS:
SDL_BlitSurface(Sprites[GRASS], NULL, SDL_GetWindowSurface(pWindow), &position);
break;
case ROCK:
SDL_BlitSurface(Sprites[ROCK], NULL, SDL_GetWindowSurface(pWindow), &position);
break;
case TREE:
SDL_BlitSurface(Sprites[TREE], NULL, SDL_GetWindowSurface(pWindow), &position);
break;
}
}
}
}
/*//Fonction draw avec un tableau. A servi de test pour le graphique
int drawArena(SDL_Window* pWindow,int carte[NB_BLOCS_LARGEUR][NB_BLOCS_HAUTEUR],SDL_Surface **Sprites)
{
SDL_Rect position;
for (int i = 0 ; i < NB_BLOCS_LARGEUR ; i++)
{
for (int j = 0 ; j < NB_BLOCS_HAUTEUR ; j++)
{
position.x = i * BLOC_SIZE;
position.y = j * BLOC_SIZE;
switch(carte[i][j])
{
case GRASS:
SDL_BlitSurface(Sprites[GRASS], NULL, SDL_GetWindowSurface(pWindow), &position);
break;
case ROCK:
SDL_BlitSurface(Sprites[ROCK], NULL, SDL_GetWindowSurface(pWindow), &position);
break;
case TREE:
SDL_BlitSurface(Sprites[TREE], NULL, SDL_GetWindowSurface(pWindow), &position);
break;
}
}
}
}
*/

View File

@ -1,19 +1,19 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
int createGameMenuWindows() { int createGameMenuWindows() {
if (SDL_Init(SDL_INIT_VIDEO) != 0) { if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Erreur chargement librairie SDL ! %s\n",SDL_GetError()); printf("Erreur chargement librairie SDL ! %s\n",SDL_GetError());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
SDL_Window *main_test; SDL_Window *main_test;
main_test = SDL_CreateWindow("My test windows", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 140, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS); main_test = SDL_CreateWindow("My test windows", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 140, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS);
SDL_Delay(5000); SDL_Delay(5000);
SDL_DestroyWindow(main_test); SDL_DestroyWindow(main_test);
SDL_Quit(); SDL_Quit();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -1,6 +1,6 @@
#ifndef MENUGUI_H_ #ifndef MENUGUI_H_
#define MENUGUI_H_ #define MENUGUI_H_
#endif #endif

6
src/menuGUI.h~HEAD Normal file
View File

@ -0,0 +1,6 @@
#ifndef MENUGUI_H_
#define MENUGUI_H_
#endif

6
src/menuGUI.h~arena Normal file
View File

@ -0,0 +1,6 @@
#ifndef MENUGUI_H_
#define MENUGUI_H_
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,57 +1,49 @@
/* #include <SDL2/SDL.h>
* playerInterface.h #include "arenaEngine.h"
* #include "IAEngine.h"
* Created on: 17 juin 2018
* Author: isen #ifndef PLAYERINTERFACE_H_
*/ #define PLAYERINTERFACE_H_
#include "arenaEngine.h"
/** Structure d'un joueur (IA ou utilisateur)
#ifndef PLAYERINTERFACE_H_ *
#define PLAYERINTERFACE_H_ * */
typedef struct Player
/** Structure d'un joueur (IA ou utilisateur) {
* int Id;
* */ char Name[35];
typedef struct Player //char Race[20];
{ int Race;
int Id;
char Name[35]; int HealthPoints;
//char Race[20]; int AttacksPoints;
int Race; int DefensePoints;
int HealthPoints; int PositionX;
int AttacksPoints; int PositionY;
int DefensePoints;
//char Weapons[Max_Weapons];
int PositionX;
int PositionY; //int Coins;
//char Weapons[Max_Weapons]; struct Player * suiv;
//int Coins; }PLAYER;
struct Player * suiv; //Prototypes
}PLAYER; PLAYER* createPlayer(int Id);
PLAYER* insertRightPlaceRecursive(PLAYER* Head, PLAYER* Element);
//Prototypes void displayList(PLAYER * Head);
PLAYER * freeElement(PLAYER *Head, int Id);
PLAYER* createPlayer(int Id); PLAYER * freeList(PLAYER *Head);
PLAYER* insertRightPlaceRecursive(PLAYER* Head, PLAYER* Element);
void displayList(PLAYER * Head); PLAYER * SearchPlayer(PLAYER *Head, int idPlayer);
PLAYER * freeElement(PLAYER *Head, int Id); void AttackPlayer( PLAYER *player1, PLAYER *player2);
PLAYER * freeList(PLAYER *Head); //void ActionPlayer(PLAYER * player, int action);
void ActionPlayer(ARENA_H_TILE* arena,PLAYER * player, int action);
PLAYER * SearchPlayer(PLAYER *Head, int idPlayer);
void AttackPlayer( PLAYER *player1, PLAYER *player2); int NumberPlayerAlive(PLAYER *Head);
//void ActionPlayer(PLAYER * player, int action); int getEvent(void);
void ActionPlayer(ARENA_H_TILE* arena,PLAYER * player, int action);
#endif /* PLAYERINTERFACE_H_ */
int NumberPlayerAlive(PLAYER *Head);
int getEvent(void);
#define ARENAMAX 20
#endif /* PLAYERINTERFACE_H_ */