Release alpha1
This commit is contained in:
parent
14850bd05f
commit
907a33d715
9
makefile
9
makefile
@ -21,8 +21,7 @@ src/arenaGUI.c \
|
|||||||
src/fileHandler.c \
|
src/fileHandler.c \
|
||||||
src/logHelper.c \
|
src/logHelper.c \
|
||||||
src/main.c \
|
src/main.c \
|
||||||
src/menuGUI.c \
|
src/menuGUI.c
|
||||||
src/playerInterface.c
|
|
||||||
|
|
||||||
OBJS += \
|
OBJS += \
|
||||||
build/IAEngine.o \
|
build/IAEngine.o \
|
||||||
@ -31,8 +30,7 @@ build/arenaGUI.o \
|
|||||||
build/fileHandler.o \
|
build/fileHandler.o \
|
||||||
build/logHelper.o \
|
build/logHelper.o \
|
||||||
build/main.o \
|
build/main.o \
|
||||||
build/menuGUI.o \
|
build/menuGUI.o
|
||||||
build/playerInterface.o
|
|
||||||
|
|
||||||
C_DEPS += \
|
C_DEPS += \
|
||||||
build/IAEngine.d \
|
build/IAEngine.d \
|
||||||
@ -41,8 +39,7 @@ build/arenaGUI.d \
|
|||||||
build/fileHandler.d \
|
build/fileHandler.d \
|
||||||
build/logHelper.d \
|
build/logHelper.d \
|
||||||
build/main.d \
|
build/main.d \
|
||||||
build/menuGUI.d \
|
build/menuGUI.d
|
||||||
build/playerInterface.d
|
|
||||||
|
|
||||||
|
|
||||||
build/%.o: src/%.c
|
build/%.o: src/%.c
|
||||||
|
1046
src/IAEngine.c
1046
src/IAEngine.c
File diff suppressed because it is too large
Load Diff
@ -1,35 +1,27 @@
|
|||||||
/*
|
#include "main.h"
|
||||||
* IAEngine.h
|
#include "arenaEngine.h"
|
||||||
*
|
#include <SDL2/SDL.h>
|
||||||
* Created on: 17 juin 2018
|
|
||||||
* Author: isen
|
#ifndef IAENGINE_H_
|
||||||
*/
|
#define IAENGINE_H_
|
||||||
|
|
||||||
#ifndef IAENGINE_H_
|
typedef struct noeud
|
||||||
#define IAENGINE_H_
|
{
|
||||||
|
int compteur, min, cout_f; //
|
||||||
typedef struct noeud
|
|
||||||
{
|
int ParentX;
|
||||||
int compteur, min, cout_f; //
|
int ParentY;
|
||||||
|
// 'adresse' du parent (qui sera toujours dans la map fermée)
|
||||||
int ParentX;
|
}NOEUD;
|
||||||
int ParentY;
|
|
||||||
|
|
||||||
int actualX;
|
int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2PositionX, int Player2PositionY);
|
||||||
int actualY;
|
//int IAEngine(PLAYER * player1, PLAYER * player2);
|
||||||
// 'adresse' du parent (qui sera toujours dans la map fermée)
|
int IAEngine(ARENA_H_TILE *arena,TILE *t_list,PLAYER *player1, PLAYER *player2);
|
||||||
}NOEUD;
|
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);
|
||||||
int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2PositionX, int Player2PositionY);
|
|
||||||
//int IAEngine(PLAYER * player1, PLAYER * player2);
|
NOEUD *CalculatePath(ARENA_H_TILE *arena,int posX, int posY,NOEUD *n1,PLAYER *player1,PLAYER *player2, int compteur, int dist,int min);
|
||||||
int IAEngine(ARENA_H_TILE* arena,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 distance(int x1, int y1, int x2, int y2);
|
#endif /* IAENGINE_H_ */
|
||||||
//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,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,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_ */
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "fileHandler.h"
|
|
||||||
#include "logHelper.h"
|
|
||||||
#include "arenaEngine.h"
|
#include "arenaEngine.h"
|
||||||
|
|
||||||
|
|
||||||
@ -59,6 +57,7 @@ TILE *createTileList(void) {
|
|||||||
|
|
||||||
PLAYER *createPlayerList(void) {
|
PLAYER *createPlayerList(void) {
|
||||||
PLAYER *p0 = NULL, *p1 = NULL, *p2 = NULL, *p3 = NULL;
|
PLAYER *p0 = NULL, *p1 = NULL, *p2 = NULL, *p3 = NULL;
|
||||||
|
int race;
|
||||||
|
|
||||||
p0 = calloc(1,sizeof(PLAYER));
|
p0 = calloc(1,sizeof(PLAYER));
|
||||||
p1 = calloc(1,sizeof(PLAYER));
|
p1 = calloc(1,sizeof(PLAYER));
|
||||||
@ -73,15 +72,71 @@ PLAYER *createPlayerList(void) {
|
|||||||
p0->texture[LEFT] = IMG_Load("data/sprite_player_2.png");
|
p0->texture[LEFT] = IMG_Load("data/sprite_player_2.png");
|
||||||
p0->texture[RIGHT] = IMG_Load("data/sprite_player_3.png");
|
p0->texture[RIGHT] = IMG_Load("data/sprite_player_3.png");
|
||||||
p0->suiv = p1;
|
p0->suiv = p1;
|
||||||
|
printf("Entrer le nom du joueur\n");
|
||||||
|
scanf("%s",p0->Name);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
printf("Race? 1:Orc 2: Elf 3:Humain \n");
|
||||||
|
scanf("%d",&race);
|
||||||
|
} while((race < 1) || (race > 3));
|
||||||
|
|
||||||
|
p0->Race = race;
|
||||||
|
|
||||||
|
switch(race)
|
||||||
|
{
|
||||||
|
//Race ORC
|
||||||
|
case 1: p0->HealthPoints = 100;
|
||||||
|
p0->AttacksPoints = 10;
|
||||||
|
break;
|
||||||
|
|
||||||
|
//Race Elfe
|
||||||
|
case 2: p0->HealthPoints = 80;
|
||||||
|
p0->AttacksPoints = 9;
|
||||||
|
break;
|
||||||
|
|
||||||
|
//Race Humaine
|
||||||
|
case 3: p0->HealthPoints = 90;
|
||||||
|
p0->AttacksPoints = 9;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
p1->Id = 1;
|
p1->Id = 1;
|
||||||
p1->PositionX = A_WIDTH;
|
p1->PositionX = A_WIDTH-1;
|
||||||
p1->PositionY = A_HEIGHT;
|
p1->PositionY = A_HEIGHT-1;
|
||||||
p1->texture[DOWN] = IMG_Load("data/sprite_ia_0.png");
|
p1->texture[DOWN] = IMG_Load("data/sprite_ia_0.png");
|
||||||
p1->texture[UP] = IMG_Load("data/sprite_ia_1.png");
|
p1->texture[UP] = IMG_Load("data/sprite_ia_1.png");
|
||||||
p1->texture[LEFT] = IMG_Load("data/sprite_ia_2.png");
|
p1->texture[LEFT] = IMG_Load("data/sprite_ia_2.png");
|
||||||
p1->texture[RIGHT] = IMG_Load("data/sprite_ia_3.png");
|
p1->texture[RIGHT] = IMG_Load("data/sprite_ia_3.png");
|
||||||
p1->suiv = p2;
|
p1->suiv = p2;
|
||||||
|
printf("Entrer le nom du joueur\n");
|
||||||
|
scanf("%s",p1->Name);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
printf("Race? 1:Orc 2: Elf 3:Humain \n");
|
||||||
|
scanf("%d",&race);
|
||||||
|
} while((race < 1) || (race > 3));
|
||||||
|
|
||||||
|
p1->Race = race;
|
||||||
|
|
||||||
|
switch(race)
|
||||||
|
{
|
||||||
|
//Race ORC
|
||||||
|
case 1: p1->HealthPoints = 100;
|
||||||
|
p1->AttacksPoints = 10;
|
||||||
|
break;
|
||||||
|
|
||||||
|
//Race Elfe
|
||||||
|
case 2: p1->HealthPoints = 80;
|
||||||
|
p1->AttacksPoints = 9;
|
||||||
|
break;
|
||||||
|
|
||||||
|
//Race Humaine
|
||||||
|
case 3: p1->HealthPoints = 90;
|
||||||
|
p1->AttacksPoints = 9;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
p2->Id = 0;
|
p2->Id = 0;
|
||||||
p2->PositionX = 0;
|
p2->PositionX = 0;
|
||||||
@ -101,7 +156,7 @@ PLAYER *createPlayerList(void) {
|
|||||||
//p3->texture[RIGHT] = IMG_Load("data/sprite_player_3.png");
|
//p3->texture[RIGHT] = IMG_Load("data/sprite_player_3.png");
|
||||||
p3->suiv = NULL;
|
p3->suiv = NULL;
|
||||||
|
|
||||||
return p1;
|
return p0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearRessourcesCache(TILE *t, PLAYER *p) {
|
void clearRessourcesCache(TILE *t, PLAYER *p) {
|
||||||
@ -468,8 +523,14 @@ int isPlayerAdjacent(PLAYER* p1, PLAYER* p2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int isMoveCorrect(ARENA_H_TILE* arena, TILE *t_list, int coord_x, int coord_y, int direction) {
|
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 (!((coord_x <= 0 && direction == LEFT) || (coord_y <= 0 && direction == UP) || (coord_x >= A_HEIGHT-1 && direction == RIGHT) || (coord_y >= A_WIDTH-1 && direction == DOWN))) {
|
||||||
if (isGroundTile(t_list,getTileTypeID(arena,coord_x,coord_y))) {
|
if (direction==UP && isGroundTile(t_list,getTileTypeID(arena,coord_x,coord_y-1))) {
|
||||||
|
return 1;
|
||||||
|
} else if (direction==DOWN && isGroundTile(t_list,getTileTypeID(arena,coord_x,coord_y+1))) {
|
||||||
|
return 1;
|
||||||
|
} else if (direction==LEFT && isGroundTile(t_list,getTileTypeID(arena,coord_x-1,coord_y))) {
|
||||||
|
return 1;
|
||||||
|
} else if (direction==RIGHT && isGroundTile(t_list,getTileTypeID(arena,coord_x+1,coord_y))) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -477,21 +538,176 @@ int isMoveCorrect(ARENA_H_TILE* arena, TILE *t_list, int coord_x, int coord_y, i
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getRelativeDirection(SDL_Rect pos1, SDL_Rect pos2) {
|
int NumberPlayerAlive(PLAYER *Head)
|
||||||
|
{
|
||||||
|
int numberAlive=0;
|
||||||
|
|
||||||
|
if(Head == NULL){
|
||||||
|
printf("La liste est vide\n");
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
do {
|
||||||
|
if(Head->HealthPoints > 0) {
|
||||||
|
numberAlive++;
|
||||||
|
}
|
||||||
|
Head=Head->suiv;
|
||||||
|
} while(Head != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return numberAlive;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getRelativeDirection(int pos1_x, int pos1_y, int pos2_x, int pos2_y) {
|
||||||
int _x,_y;
|
int _x,_y;
|
||||||
|
|
||||||
_x = pos2.x - pos1.x;
|
_x = pos2_x - pos1_x;
|
||||||
_y = pos2.y - pos1.y;
|
_y = pos2_y - pos1_y;
|
||||||
|
|
||||||
if (_x>1) {
|
if (_x>0) {
|
||||||
return DOWN;
|
return DOWN;
|
||||||
} else if (_x<1) {
|
} else if (_x<0) {
|
||||||
return UP;
|
return UP;
|
||||||
} else if (_y>1) {
|
} else if (_y>0) {
|
||||||
return RIGHT;
|
return RIGHT;
|
||||||
} else if (_y<1) {
|
} else if (_y<0) {
|
||||||
return LEFT;
|
return LEFT;
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AttackPlayer(PLAYER *player1, PLAYER *player2)
|
||||||
|
{
|
||||||
|
printf("Fonction Attaque\n");
|
||||||
|
|
||||||
|
|
||||||
|
if((player1 != NULL) && (player2 != NULL))
|
||||||
|
{
|
||||||
|
|
||||||
|
if((player1->HealthPoints > 0) && (player2->HealthPoints > 0))
|
||||||
|
{
|
||||||
|
|
||||||
|
printf("\n\n** Tour **\n");
|
||||||
|
|
||||||
|
printf("Attaque Joueur %d sur joueur %d \n",player1->Id,player2->Id);
|
||||||
|
|
||||||
|
player2->HealthPoints = player2->HealthPoints - player1->AttacksPoints;
|
||||||
|
|
||||||
|
printf("Joueur %d : %s PV = %d\n ",player1->Id,player1->Name,player1->HealthPoints);
|
||||||
|
printf("Joueur %d : %s PV = %d\n ",player2->Id,player2->Name,player2->HealthPoints);
|
||||||
|
|
||||||
|
/*if((player1->HealthPoints > 0) && (player2->HealthPoints > 0))
|
||||||
|
{
|
||||||
|
printf("\nAttaque Joueur %d sur joueur %d\n ",player2->Id,player1->Id);
|
||||||
|
player1->HealthPoints = player1->HealthPoints - player2->AttacksPoints;
|
||||||
|
|
||||||
|
printf("Joueur %d : %s PV = %d\n ",player1->Id,player1->Name,player1->HealthPoints);
|
||||||
|
printf("Joueur %d : %s PV = %d \n",player2->Id,player2->Name,player2->HealthPoints);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ActionPlayer(ARENA_H_TILE* arena,TILE *t_list,PLAYER *player,int action)
|
||||||
|
{
|
||||||
|
/* action = 1 --> Déplacement d'1 carreau vers le haut
|
||||||
|
* action = 2 --> Déplacement d'1 carreau vers la droite
|
||||||
|
* action = 3 --> Déplacement d'1 carreau vers le bas
|
||||||
|
* action = 4 --> Déplacement d'1 carreau vers la gauche
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
SDL_Point current_pos;
|
||||||
|
|
||||||
|
|
||||||
|
if(player != NULL)
|
||||||
|
{
|
||||||
|
// récupère la position du personnage. La position de l'instance sur l'arène est récupérer par une fonction
|
||||||
|
current_pos.x = player->PositionX;
|
||||||
|
current_pos.y = player->PositionY;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
printf("\n**** Player %s ****\n",player->Name);
|
||||||
|
|
||||||
|
if(action == 1)
|
||||||
|
{
|
||||||
|
printf("On veut aller vers le haut\n");
|
||||||
|
printf("ID case[%i][%i] : %i \n",current_pos.x,current_pos.y-1,getTileTypeID(arena, current_pos.x, current_pos.y-1));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(isMoveCorrect(arena,t_list,current_pos.x,current_pos.y,UP))
|
||||||
|
{
|
||||||
|
player->PositionY = (current_pos.y)-1;
|
||||||
|
printf("Déplacement de 1 vers le haut\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Impossible d'aller vers le haut\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(action == 2)
|
||||||
|
{
|
||||||
|
printf("On veut aller vers la droite\n");
|
||||||
|
printf("ID case[%i][%i] : %i \n",current_pos.x+1,current_pos.y,getTileTypeID(arena, current_pos.x+1, current_pos.y));
|
||||||
|
|
||||||
|
if(isMoveCorrect(arena,t_list,current_pos.x,current_pos.y,RIGHT))
|
||||||
|
{
|
||||||
|
player->PositionX = (current_pos.x)+1;
|
||||||
|
printf("Déplacement de 1 vers la droite\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Impossible d'aller vers la droite\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(action == 3)
|
||||||
|
{
|
||||||
|
printf("On veut aller vers le bas\n");
|
||||||
|
printf("ID case[%i][%i] : %i \n",current_pos.x,current_pos.y+1,getTileTypeID(arena, current_pos.x, current_pos.y+1));
|
||||||
|
|
||||||
|
if(isMoveCorrect(arena,t_list,current_pos.x,current_pos.y,DOWN))
|
||||||
|
{
|
||||||
|
player->PositionY = (current_pos.y)+1;
|
||||||
|
printf("Déplacement de 1 vers le bas\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Impossible d'aller vers le bas\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(action == 4)
|
||||||
|
{
|
||||||
|
printf("On veut aller vers la gauche\n");
|
||||||
|
printf("ID case[%i][%i] : %i \n",current_pos.x-1,current_pos.y,getTileTypeID(arena, current_pos.x-1, current_pos.y));
|
||||||
|
|
||||||
|
if(isMoveCorrect(arena,t_list,current_pos.x,current_pos.y,LEFT))
|
||||||
|
{
|
||||||
|
player->PositionX = (current_pos.x)-1;
|
||||||
|
printf("Déplacement de 1 vers la gauche\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Impossible d'aller vers la gauche\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Autre action\n");
|
||||||
|
printf("ID case[%i][%i] : %i \n",current_pos.x,current_pos.y-1,getTileTypeID(arena, current_pos.x, current_pos.y-1));
|
||||||
|
|
||||||
|
printf("ID case[%i][%i] : %i \n",current_pos.x+1,current_pos.y,getTileTypeID(arena, current_pos.x+1, current_pos.y));
|
||||||
|
|
||||||
|
printf("ID case[%i][%i] : %i \n",current_pos.x,current_pos.y+1,getTileTypeID(arena, current_pos.x, current_pos.y+1));
|
||||||
|
|
||||||
|
printf("ID case[%i][%i] : %i \n",current_pos.x-1,current_pos.y,getTileTypeID(arena, current_pos.x-1, current_pos.y));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Echec, le joueur est NULL\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
|
#include "fileHandler.h"
|
||||||
|
#include "logHelper.h"
|
||||||
|
|
||||||
#ifndef ARENAENGINE_H_
|
#ifndef ARENAENGINE_H_
|
||||||
#define ARENAENGINE_H_
|
#define ARENAENGINE_H_
|
||||||
@ -19,7 +21,7 @@ typedef struct Player
|
|||||||
{
|
{
|
||||||
int Id;
|
int Id;
|
||||||
char Name[35];
|
char Name[35];
|
||||||
//char Race[20];
|
int Race;
|
||||||
|
|
||||||
SDL_Surface *texture[4];
|
SDL_Surface *texture[4];
|
||||||
|
|
||||||
@ -65,6 +67,10 @@ int isGroundTile(TILE *t_list, int id);
|
|||||||
SDL_Surface *getTileSurfaceFromID(TILE *t_list, int id);
|
SDL_Surface *getTileSurfaceFromID(TILE *t_list, int id);
|
||||||
int isPlayerAdjacent(PLAYER* p1, PLAYER* p2);
|
int isPlayerAdjacent(PLAYER* p1, PLAYER* p2);
|
||||||
int isMoveCorrect(ARENA_H_TILE* arena, TILE *t_list, int coord_x, int coord_y, int direction);
|
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);
|
int getRelativeDirection(int pos1_x, int pos1_y, int pos2_x, int pos2_y);
|
||||||
|
|
||||||
|
int NumberPlayerAlive(PLAYER *Head);
|
||||||
|
void AttackPlayer(PLAYER *player1, PLAYER *player2);
|
||||||
|
void ActionPlayer(ARENA_H_TILE* arena,TILE *t_list,PLAYER * player, int action);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
161
src/arenaGUI.c
161
src/arenaGUI.c
@ -1,9 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "logHelper.h"
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <SDL2/SDL_image.h>
|
|
||||||
#include <SDL2/SDL_ttf.h>
|
|
||||||
#include "arenaGUI.h"
|
#include "arenaGUI.h"
|
||||||
|
|
||||||
void displayArena(ARENA_H_TILE* arena, SDL_Window* window, TILE *tiles, int size_h, int size_w, int tile_size) {
|
void displayArena(ARENA_H_TILE* arena, SDL_Window* window, TILE *tiles, int size_h, int size_w, int tile_size) {
|
||||||
@ -21,6 +17,162 @@ void displayArena(ARENA_H_TILE* arena, SDL_Window* window, TILE *tiles, int size
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int updateArena(SDL_Window* window, ARENA_H_TILE* arena, TILE *tiles, PLAYER *player) {
|
||||||
|
//Ajouté
|
||||||
|
SDL_Rect position;
|
||||||
|
SDL_Rect oldposition;
|
||||||
|
SDL_Rect IAposition;
|
||||||
|
SDL_Rect oldIAposition;
|
||||||
|
|
||||||
|
PLAYER *p1=NULL,*p2=NULL;
|
||||||
|
|
||||||
|
p1=player;
|
||||||
|
p2=player->suiv;
|
||||||
|
|
||||||
|
printf("Nom player 1 : %s\n",p1->Name);
|
||||||
|
printf("Nom player 2 : %s\n",p2->Name);
|
||||||
|
|
||||||
|
printf("Nombre de joueur en vie : %i\n",NumberPlayerAlive(player));
|
||||||
|
|
||||||
|
int action=0,actionIA=0;
|
||||||
|
|
||||||
|
|
||||||
|
do {
|
||||||
|
oldposition.x = p1->PositionX * TILE_SIZE;
|
||||||
|
oldposition.y = p1->PositionY * TILE_SIZE;
|
||||||
|
oldIAposition.x = p2->PositionX * TILE_SIZE;
|
||||||
|
oldIAposition.y = p2->PositionY * TILE_SIZE;
|
||||||
|
|
||||||
|
|
||||||
|
//Affichage des joueurs au début de la partie
|
||||||
|
SDL_BlitSurface(p1->texture[DOWN], NULL, SDL_GetWindowSurface(window), &position);
|
||||||
|
SDL_BlitSurface(p2->texture[DOWN], NULL, SDL_GetWindowSurface(window), &IAposition);
|
||||||
|
|
||||||
|
SDL_UpdateWindowSurface(window);
|
||||||
|
|
||||||
|
while(action == 0)
|
||||||
|
{
|
||||||
|
action=getKeyEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(action == -1)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if(action == 1)
|
||||||
|
{
|
||||||
|
ActionPlayer(arena,tiles,p1,1); //Déplacement vers le haut
|
||||||
|
}
|
||||||
|
else if(action == 2)
|
||||||
|
{
|
||||||
|
ActionPlayer(arena,tiles,p1,2); //Déplacement vers la droite
|
||||||
|
}
|
||||||
|
else if(action == 3)
|
||||||
|
{
|
||||||
|
ActionPlayer(arena,tiles,p1,3); //Déplacement vers le bas
|
||||||
|
}
|
||||||
|
else if(action == 4)
|
||||||
|
{
|
||||||
|
ActionPlayer(arena,tiles,p1,4); //Déplacement vers la gauche
|
||||||
|
}
|
||||||
|
else if(action == 5)
|
||||||
|
{
|
||||||
|
//Regarder le perso en face, le plus près
|
||||||
|
AttackPlayer(p1,p2); //Voir quel player on choisit d'attaquer
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Partie ajoutée
|
||||||
|
// On place le joueur à la bonne position
|
||||||
|
position.x = p1->PositionX * TILE_SIZE;
|
||||||
|
position.y = p1->PositionY * TILE_SIZE;
|
||||||
|
//SDL_BlitSurface(actualPlayer, NULL, SDL_GetWindowSurface(window), &position);
|
||||||
|
|
||||||
|
// Effacement de l'écran
|
||||||
|
//SDL_FillRect(SDL_GetWindowSurface(window), NULL, SDL_MapRGB(SDL_GetWindowSurface(window)->format, 255, 255, 255));
|
||||||
|
|
||||||
|
//SDL_BlitSurface(p1->texture[getRelativeDirection(oldposition, position)], NULL, SDL_GetWindowSurface(window), &position);
|
||||||
|
SDL_BlitSurface(p1->texture[DOWN], NULL, SDL_GetWindowSurface(window), &position);
|
||||||
|
SDL_BlitSurface(getTileSurfaceFromID(tiles,getTileTypeID(arena,oldposition.x,oldposition.y)), NULL, SDL_GetWindowSurface(window), &oldposition);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Tour de l'IA
|
||||||
|
actionIA = IAEngine(arena,tiles,p1,p2);
|
||||||
|
printf("Tour de l'IA\n");
|
||||||
|
if(actionIA == 5)
|
||||||
|
{
|
||||||
|
AttackPlayer(p1,p2);
|
||||||
|
}
|
||||||
|
else if ((actionIA >= 1) && (actionIA <= 4))
|
||||||
|
{
|
||||||
|
ActionPlayer(arena,tiles,p2,actionIA);
|
||||||
|
}
|
||||||
|
|
||||||
|
IAposition.x = p2->PositionX * TILE_SIZE;
|
||||||
|
IAposition.y = p2->PositionY * TILE_SIZE;
|
||||||
|
|
||||||
|
//SDL_BlitSurface(p2->texture[getRelativeDirection(oldIAposition, IAposition)], NULL, SDL_GetWindowSurface(window), &IAposition);
|
||||||
|
SDL_BlitSurface(p2->texture[DOWN], NULL, SDL_GetWindowSurface(window), &IAposition);
|
||||||
|
SDL_BlitSurface(getTileSurfaceFromID(tiles,getTileTypeID(arena,oldIAposition.x,oldIAposition.y)), NULL, SDL_GetWindowSurface(window), &oldIAposition);
|
||||||
|
|
||||||
|
SDL_UpdateWindowSurface(window);
|
||||||
|
|
||||||
|
action=0;actionIA=0;
|
||||||
|
|
||||||
|
} while((p1->HealthPoints >0) && (NumberPlayerAlive(player) > 1));
|
||||||
|
|
||||||
|
printf("La partie est terminée\n");
|
||||||
|
|
||||||
|
if(p1->HealthPoints > 0)
|
||||||
|
{
|
||||||
|
printf("Vous avez gagné\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Vous avez perdu\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Si une des IA meurt, voir comment on le gère
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getKeyEvent()
|
||||||
|
{
|
||||||
|
SDL_Event event;
|
||||||
|
SDL_WaitEvent(&event); /* Récupération de l'événement dans event */
|
||||||
|
|
||||||
|
switch(event.type) /* Test du type d'événement */
|
||||||
|
{
|
||||||
|
/* Si c'est un événement de type "Quitter" */
|
||||||
|
case SDL_QUIT :
|
||||||
|
printf("QUITTER\n");
|
||||||
|
return -1;
|
||||||
|
case SDL_KEYUP:
|
||||||
|
switch(event.key.keysym.sym) //La valeur de touche
|
||||||
|
{
|
||||||
|
case SDLK_UP:
|
||||||
|
printf("FLECHE DU HAUT\n");
|
||||||
|
return 1;
|
||||||
|
case SDLK_DOWN:
|
||||||
|
printf("FLECHE DU BAS\n");
|
||||||
|
return 3;
|
||||||
|
case SDLK_RIGHT:
|
||||||
|
printf("FLECHE DE DROITE\n");
|
||||||
|
return 2;
|
||||||
|
case SDLK_LEFT:
|
||||||
|
printf("FLECHE DE GAUCHE\n");
|
||||||
|
return 4;
|
||||||
|
case SDLK_SPACE:
|
||||||
|
printf("BARRE D'ESPACE\n");
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
void updatePlayerPos(ARENA_H_TILE* arena, SDL_Window* window, PLAYER *player, TILE *tiles, SDL_Rect new_coord) {
|
void updatePlayerPos(ARENA_H_TILE* arena, SDL_Window* window, PLAYER *player, TILE *tiles, SDL_Rect new_coord) {
|
||||||
SDL_Rect old_coord;
|
SDL_Rect old_coord;
|
||||||
|
|
||||||
@ -32,3 +184,4 @@ void updatePlayerPos(ARENA_H_TILE* arena, SDL_Window* window, PLAYER *player, TI
|
|||||||
|
|
||||||
SDL_UpdateWindowSurface(window);
|
SDL_UpdateWindowSurface(window);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
@ -1,10 +1,18 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "arenaEngine.h"
|
#include "arenaEngine.h"
|
||||||
|
#include "logHelper.h"
|
||||||
|
#include "IAEngine.h"
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <SDL2/SDL_image.h>
|
||||||
|
//#include <SDL2/SDL_ttf.h>
|
||||||
|
|
||||||
#ifndef ARENAGUI_H_
|
#ifndef ARENAGUI_H_
|
||||||
#define ARENAGUI_H_
|
#define ARENAGUI_H_
|
||||||
|
|
||||||
void displayArena(ARENA_H_TILE* arena, SDL_Window* windows, TILE *tiles, int size_h, int size_w, int tile_size);
|
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);
|
int updateArena(SDL_Window* window, ARENA_H_TILE* arena, TILE *tiles, PLAYER *player);
|
||||||
|
int getKeyEvent();
|
||||||
|
|
||||||
|
//void updatePlayerPos(ARENA_H_TILE* arena, SDL_Window* window, PLAYER *player, TILE *tiles, SDL_Rect new_coord);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,7 +18,7 @@ PLAYER * LoadLevel(ARENA_H_TILE *Head)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
FILE* fichier = NULL;
|
FILE* fichier = NULL;
|
||||||
char ligneFichier[NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1] = {0};
|
char ligneFichier[A_WIDTH * A_HEIGHT + 1] = {0};
|
||||||
int i = 0, j = 0;
|
int i = 0, j = 0;
|
||||||
|
|
||||||
//Ouverture du fichier
|
//Ouverture du fichier
|
||||||
@ -26,13 +26,13 @@ PLAYER * LoadLevel(ARENA_H_TILE *Head)
|
|||||||
if (fichier == NULL)
|
if (fichier == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
//Lecture du fichier
|
//Lecture du fichier
|
||||||
fgets(ligneFichier, NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1, fichier);
|
fgets(ligneFichier, A_WIDTH * A_HEIGHT + 1, fichier);
|
||||||
|
|
||||||
for (i = 0 ; i < NB_BLOCS_LARGEUR ; i++)
|
for (i = 0 ; i < A_WIDTH ; i++)
|
||||||
{
|
{
|
||||||
for (j = 0 ; j < NB_BLOCS_HAUTEUR ; j++)
|
for (j = 0 ; j < A_HEIGHT ; j++)
|
||||||
{
|
{
|
||||||
switch (ligneFichier[(i * NB_BLOCS_LARGEUR) + j])
|
switch (ligneFichier[(i * A_WIDTH) + j])
|
||||||
{
|
{
|
||||||
case '0':
|
case '0':
|
||||||
//Herbe
|
//Herbe
|
||||||
@ -60,10 +60,11 @@ PLAYER * LoadLevel(ARENA_H_TILE *Head)
|
|||||||
*/
|
*/
|
||||||
//Fonction a réadapter avec la liste chainée Arene
|
//Fonction a réadapter avec la liste chainée Arene
|
||||||
|
|
||||||
int chargerNiveau(int niveau[][NB_BLOCS_HAUTEUR])
|
/*
|
||||||
|
int chargerNiveau(int niveau[][])
|
||||||
{
|
{
|
||||||
FILE* fichier = NULL;
|
FILE* fichier = NULL;
|
||||||
char ligneFichier[NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1] = {0};
|
char ligneFichier[A_WIDTH * A_HEIGHT + 1] = {0};
|
||||||
int i = 0, j = 0;
|
int i = 0, j = 0;
|
||||||
|
|
||||||
printf("Chargement du fichier\n");
|
printf("Chargement du fichier\n");
|
||||||
@ -71,14 +72,14 @@ int chargerNiveau(int niveau[][NB_BLOCS_HAUTEUR])
|
|||||||
if (fichier == NULL)
|
if (fichier == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fgets(ligneFichier, NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1, fichier);
|
fgets(ligneFichier, A_WIDTH * A_HEIGHT + 1, fichier);
|
||||||
|
|
||||||
for (i = 0 ; i < NB_BLOCS_LARGEUR ; i++)
|
for (i = 0 ; i < A_WIDTH ; i++)
|
||||||
{
|
{
|
||||||
for (j = 0 ; j < NB_BLOCS_HAUTEUR ; j++)
|
for (j = 0 ; j < A_HEIGHT ; j++)
|
||||||
{
|
{
|
||||||
//printf("j= %i \n",j);
|
//printf("j= %i \n",j);
|
||||||
switch (ligneFichier[(i * NB_BLOCS_LARGEUR) + j])
|
switch (ligneFichier[(i * A_WIDTH) + j])
|
||||||
{
|
{
|
||||||
case '0':
|
case '0':
|
||||||
niveau[j][i] = 0;
|
niveau[j][i] = 0;
|
||||||
@ -99,4 +100,5 @@ int chargerNiveau(int niveau[][NB_BLOCS_HAUTEUR])
|
|||||||
|
|
||||||
fclose(fichier);
|
fclose(fichier);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
/*
|
#include "main.h"
|
||||||
* fileHandler.h
|
|
||||||
*
|
|
||||||
* Created on: 20 juin 2018
|
|
||||||
* Author: isen
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FILEHANDLER_H_
|
#ifndef FILEHANDLER_H_
|
||||||
#define FILEHANDLER_H_
|
#define FILEHANDLER_H_
|
||||||
|
|
||||||
int chargerNiveau(int niveau[][NB_BLOCS_HAUTEUR]);
|
//int chargerNiveau(int niveau[][]);
|
||||||
|
|
||||||
#endif /* FILEHANDLER_H_ */
|
#endif /* FILEHANDLER_H_ */
|
||||||
|
232
src/main.c
232
src/main.c
@ -11,7 +11,6 @@
|
|||||||
#include "arenaEngine.h"
|
#include "arenaEngine.h"
|
||||||
#include "arenaGUI.h"
|
#include "arenaGUI.h"
|
||||||
#include "IAEngine.h"
|
#include "IAEngine.h"
|
||||||
#include "playerInterface.h"
|
|
||||||
|
|
||||||
|
|
||||||
void initDisplayLib() {
|
void initDisplayLib() {
|
||||||
@ -55,8 +54,15 @@ int main(int argc, char *argv[]) {
|
|||||||
addLogInfo("Display arena GUI...");
|
addLogInfo("Display arena GUI...");
|
||||||
displayArena(arena, gameWindows, tile_ressources, A_HEIGHT, A_WIDTH, TILE_SIZE);
|
displayArena(arena, gameWindows, tile_ressources, A_HEIGHT, A_WIDTH, TILE_SIZE);
|
||||||
|
|
||||||
|
int continuer = 1;
|
||||||
|
int action;
|
||||||
|
|
||||||
SDL_Delay(3000);
|
while (continuer) {
|
||||||
|
action = updateArena(gameWindows,arena,tile_ressources,player_ressources);
|
||||||
|
|
||||||
|
if (action == -1) continuer = 0;
|
||||||
|
}
|
||||||
|
SDL_DestroyWindow(gameWindows);
|
||||||
|
|
||||||
deleteArena(arena);
|
deleteArena(arena);
|
||||||
addLogInfo("Cleared arena.");
|
addLogInfo("Cleared arena.");
|
||||||
@ -69,225 +75,3 @@ int main(int argc, char *argv[]) {
|
|||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* main.c
|
|
||||||
*
|
|
||||||
* Created on: 17 juin 2018
|
|
||||||
* Author: isen
|
|
||||||
*/
|
|
||||||
|
|
||||||
//#include "IAEngine.h"
|
|
||||||
#include "playerInterface.h"
|
|
||||||
#include "fileHandler.h"
|
|
||||||
#include "arenaEngine.h"
|
|
||||||
|
|
||||||
#include "SDL2/SDL.h"
|
|
||||||
#include "SDL2/SDL_image.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.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
|
|
||||||
|
|
||||||
enum {HAUT, BAS, GAUCHE, DROITE};
|
|
||||||
enum {GRASS, ROCK, TREE,FIRSTPLAYER, IA1}; //Définit quel type de case il s'agit
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
|
||||||
|
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) != 0 )
|
|
||||||
{
|
|
||||||
fprintf(stdout,"Échec de l'initialisation de la SDL (%s)\n",SDL_GetError());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int continuer = 1;
|
|
||||||
int action;
|
|
||||||
|
|
||||||
ARENA_H_TILE* arena = NULL; //Déclaration de l'arène
|
|
||||||
|
|
||||||
SDL_Surface *player[4] = {NULL}; // 4 surfaces pour 4 directions de mario
|
|
||||||
SDL_Surface *IA1[4] = {NULL}; // 4 surfaces pour 4 directions de mario
|
|
||||||
SDL_Surface *grass = NULL;
|
|
||||||
SDL_Surface *rock = NULL, *tree = NULL, *river = NULL,*actualPlayer = NULL, *actualIA1 = NULL;
|
|
||||||
SDL_Rect position, positionJoueur;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int i = 0, j = 0;
|
|
||||||
int carte[NB_BLOCS_LARGEUR][NB_BLOCS_HAUTEUR] = {0};
|
|
||||||
|
|
||||||
//SDL_WM_SetIcon(IMG_Load("adventurer_resize.png"),NULL); //Définit l'icone de la fenêtre
|
|
||||||
|
|
||||||
// Création de la fenêtre
|
|
||||||
SDL_Window* pWindow = NULL;
|
|
||||||
pWindow = SDL_CreateWindow("Arena Survival Tournament",SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,LARGEUR_FENETRE,HAUTEUR_FENETRE,SDL_WINDOW_SHOWN);
|
|
||||||
|
|
||||||
//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");
|
|
||||||
}
|
|
||||||
// Chargement des sprites (décors, personnage...)
|
|
||||||
grass = IMG_Load("Landscape/grass_green_32x32.png");
|
|
||||||
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");
|
|
||||||
player[HAUT] = IMG_Load("Adventurer/adventurer_back_32x32.png");
|
|
||||||
player[DROITE] = IMG_Load("Adventurer/adventurer1_right_32x32.png");
|
|
||||||
player[GAUCHE] = IMG_Load("Adventurer/adventurer1_left_32x32.png");
|
|
||||||
|
|
||||||
IA1[BAS] = IMG_Load("IA1/adventurer2_32x32.png");
|
|
||||||
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");
|
|
||||||
|
|
||||||
actualPlayer = player[BAS];
|
|
||||||
actualIA1 = IA1[BAS];
|
|
||||||
|
|
||||||
SDL_Surface* Sprites[5]= {grass,rock,tree,actualPlayer,actualIA1};
|
|
||||||
|
|
||||||
// Chargement du niveau pour le tableau (Phase de test)
|
|
||||||
/*if (!chargerNiveau(carte))
|
|
||||||
{
|
|
||||||
printf("Niveau non chargé\n");// On arrête le jeu si on n'a pas pu charger le niveau
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
//Cette fonction peut être utile pour rechercher un joueur ( Pour la detection)
|
|
||||||
// Recherche de la position de Mario au départ
|
|
||||||
for (i = 0 ; i < NB_BLOCS_LARGEUR ; i++)
|
|
||||||
{
|
|
||||||
for (j = 0 ; j < NB_BLOCS_HAUTEUR ; j++)
|
|
||||||
{
|
|
||||||
if (carte[i][j] == MARIO) // Si Mario se trouve à cette position
|
|
||||||
{
|
|
||||||
positionJoueur.x = i;
|
|
||||||
positionJoueur.y = j;
|
|
||||||
carte[i][j] = VIDE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Placement des objets à l'écran à la création de l'arène
|
|
||||||
drawArena(pWindow,arena,Sprites);
|
|
||||||
|
|
||||||
|
|
||||||
SDL_Event event; // Cette variable servira plus tard à gérer les événements
|
|
||||||
|
|
||||||
if( pWindow )
|
|
||||||
{
|
|
||||||
SDL_UpdateWindowSurface(pWindow); //Rafaichis la fenetre
|
|
||||||
|
|
||||||
//SDL_Delay(3000); /* Attendre trois secondes, que l'utilisateur voie la fenêtre */
|
|
||||||
while (continuer)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
action = PlayerInterface(pWindow,arena,Sprites);
|
|
||||||
|
|
||||||
if (action == -1)
|
|
||||||
{
|
|
||||||
continuer = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
//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;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
#ifndef MENUGUI_H_
|
|
||||||
#define MENUGUI_H_
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,6 +0,0 @@
|
|||||||
#ifndef MENUGUI_H_
|
|
||||||
#define MENUGUI_H_
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,626 +0,0 @@
|
|||||||
#include "playerInterface.h"
|
|
||||||
//#include "arenaEngine.h"
|
|
||||||
|
|
||||||
#include "SDL2/SDL.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
|
|
||||||
enum {GRASS, ROCK, TREE,FIRSTPLAYER, IA1};
|
|
||||||
#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 PlayerInterface(SDL_Window* pWindow,ARENA_H_TILE* arena,SDL_Surface **Sprites)
|
|
||||||
{
|
|
||||||
|
|
||||||
//Ajouté
|
|
||||||
SDL_Rect position;
|
|
||||||
SDL_Rect oldposition;
|
|
||||||
SDL_Rect IAposition;
|
|
||||||
SDL_Rect oldIAposition;
|
|
||||||
|
|
||||||
|
|
||||||
PLAYER* List=NULL;
|
|
||||||
PLAYER* Element=NULL;
|
|
||||||
int id=0;
|
|
||||||
int numberAlive;
|
|
||||||
|
|
||||||
PLAYER* player1=NULL;
|
|
||||||
PLAYER* player2=NULL;
|
|
||||||
|
|
||||||
while(id<2)
|
|
||||||
{
|
|
||||||
id = id + 1;
|
|
||||||
Element = createPlayer(id);
|
|
||||||
List = insertRightPlaceRecursive(List,Element);
|
|
||||||
}
|
|
||||||
|
|
||||||
displayList(List);
|
|
||||||
|
|
||||||
player1 = SearchPlayer(List, 1);
|
|
||||||
player2 = SearchPlayer(List, 2);
|
|
||||||
|
|
||||||
printf("Nom player 1 : %s\n",player1->Name);
|
|
||||||
printf("Nom player 2 : %s\n",player2->Name);
|
|
||||||
|
|
||||||
numberAlive = NumberPlayerAlive(List);
|
|
||||||
printf("Nombre de joueur en vie : %i\n",numberAlive);
|
|
||||||
|
|
||||||
int action=0;
|
|
||||||
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
|
|
||||||
oldposition.x = player1->PositionX * BLOC_SIZE;
|
|
||||||
oldposition.y = player1->PositionY * BLOC_SIZE;
|
|
||||||
oldIAposition.x = player2->PositionX * BLOC_SIZE;
|
|
||||||
oldIAposition.y = player2->PositionY * BLOC_SIZE;
|
|
||||||
|
|
||||||
//Affichage des joueurs au début de la partie
|
|
||||||
SDL_BlitSurface(Sprites[FIRSTPLAYER], NULL, SDL_GetWindowSurface(pWindow), &oldposition);
|
|
||||||
SDL_BlitSurface(Sprites[IA1], NULL, SDL_GetWindowSurface(pWindow), &oldIAposition);
|
|
||||||
|
|
||||||
SDL_UpdateWindowSurface(pWindow);
|
|
||||||
|
|
||||||
while(action == 0)
|
|
||||||
{
|
|
||||||
action=getEvent();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(action == -1)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else if(action == 1)
|
|
||||||
{
|
|
||||||
ActionPlayer(arena,player1,1); //Déplacement vers le haut
|
|
||||||
}
|
|
||||||
else if(action == 2)
|
|
||||||
{
|
|
||||||
ActionPlayer(arena,player1,2); //Déplacement vers la droite
|
|
||||||
}
|
|
||||||
else if(action == 3)
|
|
||||||
{
|
|
||||||
ActionPlayer(arena,player1,3); //Déplacement vers le bas
|
|
||||||
}
|
|
||||||
else if(action == 4)
|
|
||||||
{
|
|
||||||
ActionPlayer(arena,player1,4); //Déplacement vers la gauche
|
|
||||||
}
|
|
||||||
else if(action == 5)
|
|
||||||
{
|
|
||||||
//Regarder le perso en face, le plus près
|
|
||||||
AttackPlayer(player1,player2); //Voir quel player on choisit d'attaquer
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Partie ajoutée
|
|
||||||
// On place le joueur à la bonne position
|
|
||||||
position.x = player1->PositionX * BLOC_SIZE;
|
|
||||||
position.y = player1->PositionY * BLOC_SIZE;
|
|
||||||
//SDL_BlitSurface(actualPlayer, NULL, SDL_GetWindowSurface(pWindow), &position);
|
|
||||||
|
|
||||||
// Effacement de l'écran
|
|
||||||
//SDL_FillRect(SDL_GetWindowSurface(pWindow), NULL, SDL_MapRGB(SDL_GetWindowSurface(pWindow)->format, 255, 255, 255));
|
|
||||||
|
|
||||||
SDL_BlitSurface(Sprites[FIRSTPLAYER], NULL, SDL_GetWindowSurface(pWindow), &position);
|
|
||||||
SDL_BlitSurface(Sprites[GRASS], NULL, SDL_GetWindowSurface(pWindow), &oldposition);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Tour de l'IA
|
|
||||||
IAEngine(arena,player1,player2);
|
|
||||||
|
|
||||||
IAposition.x = player2->PositionX * BLOC_SIZE;
|
|
||||||
IAposition.y = player2->PositionY * BLOC_SIZE;
|
|
||||||
|
|
||||||
SDL_BlitSurface(Sprites[IA1], NULL, SDL_GetWindowSurface(pWindow), &IAposition);
|
|
||||||
SDL_BlitSurface(Sprites[GRASS], NULL, SDL_GetWindowSurface(pWindow), &oldIAposition);
|
|
||||||
|
|
||||||
SDL_UpdateWindowSurface(pWindow);
|
|
||||||
|
|
||||||
action=0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
while((player1->HealthPoints >0) && (NumberPlayerAlive(List) > 1));
|
|
||||||
|
|
||||||
printf("La partie est terminée\n");
|
|
||||||
|
|
||||||
if(player1->HealthPoints > 0)
|
|
||||||
{
|
|
||||||
printf("Vous avez gagné\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Vous avez perdu\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
//Si une des IA meurt, voir comment on le gère
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int getEvent()
|
|
||||||
{
|
|
||||||
int action;
|
|
||||||
SDL_Event event;
|
|
||||||
SDL_WaitEvent(&event); /* Récupération de l'événement dans event */
|
|
||||||
|
|
||||||
switch(event.type) /* Test du type d'événement */
|
|
||||||
{
|
|
||||||
/* Si c'est un événement de type "Quitter" */
|
|
||||||
case SDL_QUIT : printf("QUITTER\n");
|
|
||||||
//action = -1;
|
|
||||||
//break;
|
|
||||||
return -1;
|
|
||||||
case SDL_KEYUP:
|
|
||||||
switch(event.key.keysym.sym) //La valeur de touche
|
|
||||||
{
|
|
||||||
case SDLK_UP: printf("FLECHE DU HAUT\n");
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
case SDLK_DOWN: printf("FLECHE DU BAS\n");
|
|
||||||
return 3;
|
|
||||||
|
|
||||||
case SDLK_RIGHT:printf("FLECHE DE DROITE\n");
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
case SDLK_LEFT: printf("FLECHE DE GAUCHE\n");
|
|
||||||
return 4;
|
|
||||||
|
|
||||||
case SDLK_SPACE:printf("BARRE D'ESPACE\n");
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**Fonction qui crée un joueur
|
|
||||||
*
|
|
||||||
* */
|
|
||||||
PLAYER* createPlayer(int Id)
|
|
||||||
{
|
|
||||||
PLAYER* player=NULL;
|
|
||||||
//Utilisé la fonction de récupération de la taille de l'arène
|
|
||||||
|
|
||||||
int race;
|
|
||||||
player=(PLAYER*)malloc(sizeof(PLAYER));
|
|
||||||
if(player==NULL)
|
|
||||||
{
|
|
||||||
printf("ERREUR Allocation joueur ");
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Entrer le nom du joueur\n");
|
|
||||||
scanf("%s",player->Name);
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
printf("Race? 1:Orc 2: Elf 3:Humain \n");
|
|
||||||
scanf("%d",&race);
|
|
||||||
}
|
|
||||||
while((race < 1) || (race > 3));
|
|
||||||
|
|
||||||
player->Race = race;
|
|
||||||
|
|
||||||
switch(race)
|
|
||||||
{
|
|
||||||
//Race ORC
|
|
||||||
case 1: player->HealthPoints = 100;
|
|
||||||
player->AttacksPoints = 10;
|
|
||||||
break;
|
|
||||||
|
|
||||||
//Race Elfe
|
|
||||||
case 2: player->HealthPoints = 80;
|
|
||||||
player->AttacksPoints = 9;
|
|
||||||
break;
|
|
||||||
|
|
||||||
//Race Humaine
|
|
||||||
case 3: player->HealthPoints = 90;
|
|
||||||
player->AttacksPoints = 9;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
player->Id = Id;
|
|
||||||
//player->AttacksPoints = 10;
|
|
||||||
|
|
||||||
if(Id == 1)
|
|
||||||
{
|
|
||||||
player->PositionX=0;
|
|
||||||
player->PositionY=0;
|
|
||||||
}
|
|
||||||
else if(Id ==2)
|
|
||||||
{
|
|
||||||
player->PositionX=ARENAMAX - 1;
|
|
||||||
//player->PositionX=5;
|
|
||||||
player->PositionY=0;
|
|
||||||
}
|
|
||||||
else if(Id ==3)
|
|
||||||
{
|
|
||||||
player->PositionX=0;
|
|
||||||
player->PositionY=ARENAMAX - 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
player->PositionX=ARENAMAX - 1;
|
|
||||||
player->PositionY=ARENAMAX - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
player->suiv=NULL;
|
|
||||||
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**Fonction qui ajoute un joueur à la liste
|
|
||||||
*
|
|
||||||
* */
|
|
||||||
|
|
||||||
PLAYER* insertRightPlaceRecursive(PLAYER* Head, PLAYER* Element)
|
|
||||||
{
|
|
||||||
if(Head == NULL)
|
|
||||||
{
|
|
||||||
return Element;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Element->Id < Head->Id)
|
|
||||||
{
|
|
||||||
Element->suiv = Head;
|
|
||||||
return Element;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(Element->Id == Head->Id)
|
|
||||||
{
|
|
||||||
printf("Le joueur à l'id %d exite déja dans la liste\n",Element->Id);
|
|
||||||
free(Element);
|
|
||||||
return Head;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Head->suiv = insertRightPlaceRecursive(Head->suiv,Element);
|
|
||||||
return Head;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void displayList(PLAYER * Head)
|
|
||||||
{
|
|
||||||
if(Head == NULL)
|
|
||||||
{
|
|
||||||
printf("La liste est vide\n");
|
|
||||||
}
|
|
||||||
while(Head != NULL)
|
|
||||||
{
|
|
||||||
printf("****Player %d****\n",Head->Id);
|
|
||||||
printf("Nom : %s\n",Head->Name);
|
|
||||||
Head = Head->suiv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PLAYER * freeElement(PLAYER *Head, int Id)
|
|
||||||
{
|
|
||||||
PLAYER * Element;
|
|
||||||
|
|
||||||
if(Head == NULL)
|
|
||||||
{
|
|
||||||
printf("La liste est vide\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Id == Head->Id)
|
|
||||||
{
|
|
||||||
Element = Head;
|
|
||||||
Head = Head->suiv;
|
|
||||||
printf("Le joueur %d a été supprimé de la liste\n",Element->Id);
|
|
||||||
free(Element);
|
|
||||||
return Head;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Head->suiv = freeElement(Head->suiv,Id);
|
|
||||||
return Head;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PLAYER * freeList(PLAYER *Head)
|
|
||||||
{
|
|
||||||
if(Head != NULL)
|
|
||||||
{
|
|
||||||
freeList(Head->suiv);
|
|
||||||
|
|
||||||
}
|
|
||||||
free(Head);
|
|
||||||
Head=NULL;
|
|
||||||
|
|
||||||
return Head;
|
|
||||||
}
|
|
||||||
|
|
||||||
int NumberPlayerAlive(PLAYER *Head)
|
|
||||||
{
|
|
||||||
int numberAlive=0;
|
|
||||||
if(Head == NULL)
|
|
||||||
{
|
|
||||||
printf("La liste est vide\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if(Head->HealthPoints > 0)
|
|
||||||
{
|
|
||||||
numberAlive = numberAlive + 1;
|
|
||||||
}
|
|
||||||
Head=Head->suiv;
|
|
||||||
}
|
|
||||||
while(Head != NULL);
|
|
||||||
return numberAlive;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PLAYER * SearchPlayer(PLAYER *Head, int idPlayer)
|
|
||||||
{
|
|
||||||
printf("Fonction Recherche\n");
|
|
||||||
|
|
||||||
if(Head == NULL)
|
|
||||||
{
|
|
||||||
printf("La liste est vide\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Head->Id == idPlayer)
|
|
||||||
{
|
|
||||||
printf("Trouvé\n");
|
|
||||||
|
|
||||||
printf(" Joueur %s\n",Head->Name);
|
|
||||||
return Head;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Head->suiv = SearchPlayer(Head->suiv,idPlayer);
|
|
||||||
|
|
||||||
return Head->suiv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AttackPlayer( PLAYER *player1, PLAYER *player2)
|
|
||||||
{
|
|
||||||
printf("Fonction Attaque\n");
|
|
||||||
|
|
||||||
|
|
||||||
if((player1 != NULL) && (player2 != NULL))
|
|
||||||
{
|
|
||||||
|
|
||||||
if((player1->HealthPoints > 0) && (player2->HealthPoints > 0))
|
|
||||||
{
|
|
||||||
|
|
||||||
printf("\n\n** Tour **\n");
|
|
||||||
|
|
||||||
printf("Attaque Joueur %d sur joueur %d \n",player1->Id,player2->Id);
|
|
||||||
|
|
||||||
player2->HealthPoints = player2->HealthPoints - player1->AttacksPoints;
|
|
||||||
|
|
||||||
printf("Joueur %d : %s PV = %d\n ",player1->Id,player1->Name,player1->HealthPoints);
|
|
||||||
printf("Joueur %d : %s PV = %d\n ",player2->Id,player2->Name,player2->HealthPoints);
|
|
||||||
|
|
||||||
/*if((player1->HealthPoints > 0) && (player2->HealthPoints > 0))
|
|
||||||
{
|
|
||||||
printf("\nAttaque Joueur %d sur joueur %d\n ",player2->Id,player1->Id);
|
|
||||||
player1->HealthPoints = player1->HealthPoints - player2->AttacksPoints;
|
|
||||||
|
|
||||||
printf("Joueur %d : %s PV = %d\n ",player1->Id,player1->Name,player1->HealthPoints);
|
|
||||||
printf("Joueur %d : %s PV = %d \n",player2->Id,player2->Name,player2->HealthPoints);
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ActionPlayer(ARENA_H_TILE* arena,PLAYER * player, int action)
|
|
||||||
{
|
|
||||||
/* action = 1 --> Déplacement d'1 carreau vers le haut
|
|
||||||
* action = 2 --> Déplacement d'1 carreau vers la droite
|
|
||||||
* action = 3 --> Déplacement d'1 carreau vers le bas
|
|
||||||
* action = 4 --> Déplacement d'1 carreau vers la gauche
|
|
||||||
*
|
|
||||||
* */
|
|
||||||
int ID;
|
|
||||||
|
|
||||||
|
|
||||||
if(player != NULL)
|
|
||||||
{
|
|
||||||
// récupère la position du personnage. La position de l'instance sur l'arène est récupérer par une fonction
|
|
||||||
int positionX = player->PositionX;
|
|
||||||
int positionY = player->PositionY;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
printf("\n**** Player %s ****\n",player->Name);
|
|
||||||
|
|
||||||
if(action == 1)
|
|
||||||
{
|
|
||||||
printf("On veut aller vers le haut\n");
|
|
||||||
ID = getTileTypeID(arena, positionX, positionY -1);
|
|
||||||
printf("ID case[%i][%i] : %i \n",positionX,positionY-1,ID);
|
|
||||||
|
|
||||||
if((positionY-1 >= 0) && (ID == 0))
|
|
||||||
{
|
|
||||||
player->PositionY = positionY-1;
|
|
||||||
printf("Déplacement de 1 vers le haut\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Impossible d'aller vers le haut\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(action == 2)
|
|
||||||
{
|
|
||||||
printf("On veut aller vers la droite\n");
|
|
||||||
ID = getTileTypeID(arena, positionX + 1, positionY);
|
|
||||||
printf("ID case[%i][%i] : %i \n",positionX+1,positionY,ID);
|
|
||||||
|
|
||||||
if((positionX + 1 < ARENAMAX) && (ID == 0))
|
|
||||||
{
|
|
||||||
player->PositionX = positionX + 1;
|
|
||||||
printf("Déplacement de 1 vers la droite\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Impossible d'aller vers la droite\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(action == 3)
|
|
||||||
{
|
|
||||||
printf("On veut aller vers le bas\n");
|
|
||||||
ID = getTileTypeID(arena, positionX, positionY + 1);
|
|
||||||
printf("ID case[%i][%i] : %i \n",positionX,positionY+1,ID);
|
|
||||||
|
|
||||||
if((positionY + 1 < ARENAMAX) && (ID == 0))
|
|
||||||
{
|
|
||||||
player->PositionY = positionY + 1;
|
|
||||||
printf("Déplacement de 1 vers le bas\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Impossible d'aller vers le bas\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(action == 4)
|
|
||||||
{
|
|
||||||
printf("On veut aller vers la gauche\n");
|
|
||||||
ID = getTileTypeID(arena, positionX - 1, positionY);
|
|
||||||
printf("ID case[%i][%i] : %i \n",positionX-1,positionY,ID);
|
|
||||||
|
|
||||||
if((positionX - 1 >= 0) && (ID == 0))
|
|
||||||
{
|
|
||||||
player->PositionX = positionX - 1;
|
|
||||||
printf("Déplacement de 1 vers la gauche\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Impossible d'aller vers la gauche\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Autre action\n");
|
|
||||||
ID = getTileTypeID(arena, positionX, positionY -1);
|
|
||||||
printf("ID case[%i][%i] : %i \n",positionX,positionY-1,ID);
|
|
||||||
|
|
||||||
ID = getTileTypeID(arena, positionX + 1, positionY);
|
|
||||||
printf("ID case[%i][%i] : %i \n",positionX+1,positionY,ID);
|
|
||||||
|
|
||||||
ID = getTileTypeID(arena, positionX, positionY + 1);
|
|
||||||
printf("ID case[%i][%i] : %i \n",positionX+1,positionY,ID);
|
|
||||||
|
|
||||||
ID = getTileTypeID(arena, positionX - 1, positionY);
|
|
||||||
printf("ID case[%i][%i] : %i \n",positionX-1,positionY,ID);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Echec, le joueur est NULL\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
void ActionPlayer(PLAYER * player, int action)
|
|
||||||
{
|
|
||||||
/* action = 1 --> Déplacement d'1 carreau vers le haut
|
|
||||||
* action = 2 --> Déplacement d'1 carreau vers la droite
|
|
||||||
* action = 3 --> Déplacement d'1 carreau vers le bas
|
|
||||||
* action = 4 --> Déplacement d'1 carreau vers la gauche
|
|
||||||
*
|
|
||||||
*
|
|
||||||
|
|
||||||
if(player != NULL)
|
|
||||||
{
|
|
||||||
// récupère la position du personnage. La position de l'instance sur l'arène est récupérer par une fonction
|
|
||||||
int positionX = player->PositionX;
|
|
||||||
int positionY = player->PositionY;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
printf("\n**** Player %s ****\n",player->Name);
|
|
||||||
|
|
||||||
if(action == 1)
|
|
||||||
{
|
|
||||||
printf("On veut aller vers le haut\n");
|
|
||||||
|
|
||||||
if(positionY-1 >= 0)
|
|
||||||
{
|
|
||||||
player->PositionY = positionY-1;
|
|
||||||
printf("Déplacement de 1 vers le haut\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Impossible d'aller vers le haut\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(action == 2)
|
|
||||||
{
|
|
||||||
printf("On veut aller vers la droite\n");
|
|
||||||
|
|
||||||
if(positionX + 1 < ARENAMAX)
|
|
||||||
{
|
|
||||||
player->PositionX = positionX + 1;
|
|
||||||
printf("Déplacement de 1 vers la droite\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Impossible d'aller vers la droite\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(action == 3)
|
|
||||||
{
|
|
||||||
printf("On veut aller vers le bas\n");
|
|
||||||
|
|
||||||
if(positionY + 1 < ARENAMAX)
|
|
||||||
{
|
|
||||||
player->PositionY = positionY + 1;
|
|
||||||
printf("Déplacement de 1 vers le bas\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Impossible d'aller vers le bas\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(action == 4)
|
|
||||||
{
|
|
||||||
printf("On veut aller vers la gauche\n");
|
|
||||||
|
|
||||||
if(positionX - 1 >= 0)
|
|
||||||
{
|
|
||||||
player->PositionX = positionX - 1;
|
|
||||||
printf("Déplacement de 1 vers la gauche\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Impossible d'aller vers la gauche\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Autre action\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Echec, le joueur est NULL\n");
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
|||||||
#include <SDL2/SDL.h>
|
|
||||||
#include "arenaEngine.h"
|
|
||||||
#include "IAEngine.h"
|
|
||||||
|
|
||||||
#ifndef PLAYERINTERFACE_H_
|
|
||||||
#define PLAYERINTERFACE_H_
|
|
||||||
|
|
||||||
/** Structure d'un joueur (IA ou utilisateur)
|
|
||||||
*
|
|
||||||
* */
|
|
||||||
typedef struct Player
|
|
||||||
{
|
|
||||||
int Id;
|
|
||||||
char Name[35];
|
|
||||||
//char Race[20];
|
|
||||||
int Race;
|
|
||||||
|
|
||||||
int HealthPoints;
|
|
||||||
int AttacksPoints;
|
|
||||||
int DefensePoints;
|
|
||||||
|
|
||||||
int PositionX;
|
|
||||||
int PositionY;
|
|
||||||
|
|
||||||
//char Weapons[Max_Weapons];
|
|
||||||
|
|
||||||
//int Coins;
|
|
||||||
|
|
||||||
struct Player * suiv;
|
|
||||||
|
|
||||||
}PLAYER;
|
|
||||||
|
|
||||||
//Prototypes
|
|
||||||
|
|
||||||
PLAYER* createPlayer(int Id);
|
|
||||||
PLAYER* insertRightPlaceRecursive(PLAYER* Head, PLAYER* Element);
|
|
||||||
void displayList(PLAYER * Head);
|
|
||||||
PLAYER * freeElement(PLAYER *Head, int Id);
|
|
||||||
PLAYER * freeList(PLAYER *Head);
|
|
||||||
|
|
||||||
PLAYER * SearchPlayer(PLAYER *Head, int idPlayer);
|
|
||||||
void AttackPlayer( PLAYER *player1, PLAYER *player2);
|
|
||||||
//void ActionPlayer(PLAYER * player, int action);
|
|
||||||
void ActionPlayer(ARENA_H_TILE* arena,PLAYER * player, int action);
|
|
||||||
|
|
||||||
int NumberPlayerAlive(PLAYER *Head);
|
|
||||||
int getEvent(void);
|
|
||||||
|
|
||||||
#endif /* PLAYERINTERFACE_H_ */
|
|
Loading…
x
Reference in New Issue
Block a user