Version final sans pathFinding
BIN
Adventurer/adventurer1_32x32.png
Executable file
After Width: | Height: | Size: 1.9 KiB |
BIN
Adventurer/adventurer_back_32x32.png
Executable file
After Width: | Height: | Size: 1.6 KiB |
BIN
Adventurer/adventurer_left_32x32.png
Executable file
After Width: | Height: | Size: 2.1 KiB |
BIN
Adventurer/adventurer_right_32x32.png
Executable file
After Width: | Height: | Size: 2.1 KiB |
BIN
Adventurer1/adventurer1_32x32.png
Executable file
After Width: | Height: | Size: 1.9 KiB |
BIN
Adventurer1/adventurer_back_32x32.png
Executable file
After Width: | Height: | Size: 1.6 KiB |
BIN
Adventurer1/adventurer_left_32x32.png
Executable file
After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
BIN
Adventurer1/adventurer_right_32x32.png
Executable file
After Width: | Height: | Size: 2.1 KiB |
BIN
Adventurer2/adventurer2_32x32.png
Executable file
After Width: | Height: | Size: 1.9 KiB |
BIN
Adventurer2/adventurer2_back_32x32.png
Executable file
After Width: | Height: | Size: 1.7 KiB |
BIN
Adventurer2/adventurer2_left_32x32.png
Executable file
After Width: | Height: | Size: 2.1 KiB |
BIN
Adventurer2/adventurer2_right_32x32.png
Executable file
After Width: | Height: | Size: 2.1 KiB |
57
Adventurer2/playerInterface.h
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* playerInterface.h
|
||||||
|
*
|
||||||
|
* Created on: 17 juin 2018
|
||||||
|
* Author: isen
|
||||||
|
*/
|
||||||
|
#include "arenaEngine.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);
|
||||||
|
|
||||||
|
#define ARENAMAX 20
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* PLAYERINTERFACE_H_ */
|
BIN
Debug/ArenaWarSurvival
Executable file
42
Debug/makefile
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
################################################################################
|
||||||
|
# Automatically-generated file. Do not edit!
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
-include ../makefile.init
|
||||||
|
|
||||||
|
RM := rm -rf
|
||||||
|
|
||||||
|
# All of the sources participating in the build are defined here
|
||||||
|
-include sources.mk
|
||||||
|
-include subdir.mk
|
||||||
|
-include objects.mk
|
||||||
|
|
||||||
|
ifneq ($(MAKECMDGOALS),clean)
|
||||||
|
ifneq ($(strip $(C_DEPS)),)
|
||||||
|
-include $(C_DEPS)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
-include ../makefile.defs
|
||||||
|
|
||||||
|
# Add inputs and outputs from these tool invocations to the build variables
|
||||||
|
|
||||||
|
# All Target
|
||||||
|
all: ArenaWarSurvival
|
||||||
|
|
||||||
|
# Tool invocations
|
||||||
|
ArenaWarSurvival: $(OBJS) $(USER_OBJS)
|
||||||
|
@echo 'Building target: $@'
|
||||||
|
@echo 'Invoking: GCC C Linker'
|
||||||
|
gcc -o "ArenaWarSurvival" $(OBJS) $(USER_OBJS) $(LIBS)
|
||||||
|
@echo 'Finished building target: $@'
|
||||||
|
@echo ' '
|
||||||
|
|
||||||
|
# Other Targets
|
||||||
|
clean:
|
||||||
|
-$(RM) $(EXECUTABLES)$(OBJS)$(C_DEPS) ArenaWarSurvival
|
||||||
|
-@echo ' '
|
||||||
|
|
||||||
|
.PHONY: all clean dependents
|
||||||
|
|
||||||
|
-include ../makefile.targets
|
8
Debug/objects.mk
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
################################################################################
|
||||||
|
# Automatically-generated file. Do not edit!
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
USER_OBJS :=
|
||||||
|
|
||||||
|
LIBS := -lSDL2 -lSDL2_image -lSDL2main
|
||||||
|
|
17
Debug/sources.mk
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
################################################################################
|
||||||
|
# Automatically-generated file. Do not edit!
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
OBJ_SRCS :=
|
||||||
|
ASM_SRCS :=
|
||||||
|
C_SRCS :=
|
||||||
|
O_SRCS :=
|
||||||
|
S_UPPER_SRCS :=
|
||||||
|
EXECUTABLES :=
|
||||||
|
OBJS :=
|
||||||
|
C_DEPS :=
|
||||||
|
|
||||||
|
# Every subdirectory with source files must be described here
|
||||||
|
SUBDIRS := \
|
||||||
|
. \
|
||||||
|
|
36
Debug/subdir.mk
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
################################################################################
|
||||||
|
# Automatically-generated file. Do not edit!
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
# Add inputs and outputs from these tool invocations to the build variables
|
||||||
|
C_SRCS += \
|
||||||
|
../IAEngine.c \
|
||||||
|
../arenaEngine.c \
|
||||||
|
../fileHandler.c \
|
||||||
|
../main.c \
|
||||||
|
../playerInterface.c
|
||||||
|
|
||||||
|
OBJS += \
|
||||||
|
./IAEngine.o \
|
||||||
|
./arenaEngine.o \
|
||||||
|
./fileHandler.o \
|
||||||
|
./main.o \
|
||||||
|
./playerInterface.o
|
||||||
|
|
||||||
|
C_DEPS += \
|
||||||
|
./IAEngine.d \
|
||||||
|
./arenaEngine.d \
|
||||||
|
./fileHandler.d \
|
||||||
|
./main.d \
|
||||||
|
./playerInterface.d
|
||||||
|
|
||||||
|
|
||||||
|
# Each subdirectory must supply rules for building sources it contributes
|
||||||
|
%.o: ../%.c
|
||||||
|
@echo 'Building file: $<'
|
||||||
|
@echo 'Invoking: GCC C Compiler'
|
||||||
|
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
|
||||||
|
@echo 'Finished building: $<'
|
||||||
|
@echo ' '
|
||||||
|
|
||||||
|
|
BIN
IA1/adventurer2_32x32.png
Executable file
After Width: | Height: | Size: 1.9 KiB |
BIN
IA1/adventurer2_back_32x32.png
Executable file
After Width: | Height: | Size: 1.7 KiB |
BIN
IA1/adventurer2_left_32x32.png
Executable file
After Width: | Height: | Size: 2.1 KiB |
BIN
IA1/adventurer2_right_32x32.png
Executable file
After Width: | Height: | Size: 2.1 KiB |
394
IAEngine.c
@ -16,6 +16,20 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
enum {HAUT, DROITE, BAS, GAUCHE};
|
||||||
|
#define NB_BLOCS_LARGEUR 20
|
||||||
|
#define NB_BLOCS_HAUTEUR 20
|
||||||
|
|
||||||
|
|
||||||
|
struct point
|
||||||
|
{
|
||||||
|
int x,y;
|
||||||
|
}POINT;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int IAEngine(ARENA_H_TILE* arena,PLAYER * player1, PLAYER * player2)
|
int IAEngine(ARENA_H_TILE* arena,PLAYER * player1, PLAYER * player2)
|
||||||
@ -24,14 +38,16 @@ int IAEngine(ARENA_H_TILE* arena,PLAYER * player1, PLAYER * player2)
|
|||||||
//Player 1 est le joueur, player 2 le bot
|
//Player 1 est le joueur, player 2 le bot
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if((player1 != NULL) & (player2 !=NULL))
|
if((player1 != NULL) & (player2 !=NULL))
|
||||||
{
|
{
|
||||||
//On récupère les positions des 2 joueurs . L'IA sait où est le joueur
|
//On récupère les positions des 2 joueurs . L'IA sait où est le joueur
|
||||||
|
|
||||||
int action;
|
int action;
|
||||||
|
|
||||||
action = FindShortestPath(player1->PositionX,player1->PositionY,player2->PositionX,player2->PositionY);
|
|
||||||
|
|
||||||
|
//action = FindShortestPath(player1->PositionX,player1->PositionY,player2->PositionX,player2->PositionY);
|
||||||
|
action = FindPath(arena,player1,player2);
|
||||||
printf("Tour de l'IA\n");
|
printf("Tour de l'IA\n");
|
||||||
if(action == 5)
|
if(action == 5)
|
||||||
{
|
{
|
||||||
@ -43,20 +59,390 @@ int IAEngine(ARENA_H_TILE* arena,PLAYER * player1, PLAYER * player2)
|
|||||||
}
|
}
|
||||||
//On vérifie si les 2 joueurs sont à côté pour attaquer
|
//On vérifie si les 2 joueurs sont à côté pour attaquer
|
||||||
printf("Vérification position\n");
|
printf("Vérification position\n");
|
||||||
action = FindShortestPath(player1->PositionX,player1->PositionY,player2->PositionX,player2->PositionY);
|
/*action = FindShortestPath(player1->PositionX,player1->PositionY,player2->PositionX,player2->PositionY);
|
||||||
if(action == 5)
|
if(action == 5)
|
||||||
{
|
{
|
||||||
AttackPlayer(player2,player1);
|
AttackPlayer(player2,player1);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int FindPath(ARENA_H_TILE* arena,PLAYER * player1, PLAYER * player2)
|
||||||
|
{
|
||||||
|
|
||||||
|
int action;
|
||||||
|
|
||||||
|
int compteur = 0;
|
||||||
|
int minH=1000,minB=1000,minG=1000,minD=1000;
|
||||||
|
int posX=0;
|
||||||
|
int posY=0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//1 vers la gauche
|
||||||
|
NOEUD * n1 =NULL;
|
||||||
|
n1=(NOEUD*)malloc(sizeof(NOEUD));
|
||||||
|
|
||||||
|
posX = player2->PositionX -1;
|
||||||
|
posY = player2->PositionY ;
|
||||||
|
|
||||||
|
n1->min=3000;
|
||||||
|
n1->compteur=0;
|
||||||
|
n1->ParentX = player2->PositionX;
|
||||||
|
n1->ParentY = player2->PositionY;
|
||||||
|
|
||||||
|
if(((posX >= 0) && (posX < NB_BLOCS_LARGEUR ))&& ((posY >= 0) && (posY < NB_BLOCS_HAUTEUR)))
|
||||||
|
{
|
||||||
|
if(getTileTypeID(arena,posX,posY) == 0)
|
||||||
|
{
|
||||||
|
n1->compteur = n1->compteur+1;
|
||||||
|
//direction = GAUCHE;
|
||||||
|
n1=CalculatePath(arena,posX,posY,n1,player1,player2,compteur,0,minG);
|
||||||
|
minG=n1->min;
|
||||||
|
printf("minG = %i\n",minG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//1 vers le haut
|
||||||
|
posX = player2->PositionX;
|
||||||
|
posY = player2->PositionY - 1;
|
||||||
|
|
||||||
|
if(((posX >=0) && (posX <NB_BLOCS_LARGEUR ))&& ((posY >= 0) && (posY < NB_BLOCS_HAUTEUR)))
|
||||||
|
{
|
||||||
|
|
||||||
|
if(getTileTypeID(arena,posX,posY) == 0)
|
||||||
|
{
|
||||||
|
//direction = HAUT;
|
||||||
|
|
||||||
|
n1=CalculatePath(arena,posX,posY,n1,player1,player2,compteur,0,minH);
|
||||||
|
minH=n1->min;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//1 vers le bas
|
||||||
|
posX = player2->PositionX;
|
||||||
|
posY = player2->PositionY + 1;
|
||||||
|
|
||||||
|
if(((posX >= 0) && (posX < NB_BLOCS_LARGEUR ))&& ((posY >=0) && (posY < NB_BLOCS_HAUTEUR)))
|
||||||
|
{
|
||||||
|
if(getTileTypeID(arena,posX,posY) == 0)
|
||||||
|
{
|
||||||
|
//direction = BAS;
|
||||||
|
n1=CalculatePath(arena,posX,posY,n1,player1,player2,compteur,0,minB);
|
||||||
|
minB=n1->min;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//1 vers la droite
|
||||||
|
posX = player2->PositionX +1;
|
||||||
|
posY = player2->PositionY ;
|
||||||
|
|
||||||
|
if(((posX >= 0) && (posX < NB_BLOCS_LARGEUR ))&& ((posY >= 0) && (posY < NB_BLOCS_HAUTEUR)))
|
||||||
|
{
|
||||||
|
if(getTileTypeID(arena,posX,posY) == 0)
|
||||||
|
|
||||||
|
{
|
||||||
|
//direction = DROITE;
|
||||||
|
|
||||||
|
n1=CalculatePath(arena,posX,posY,n1,player1,player2,compteur,0,minD);
|
||||||
|
minD=n1->min;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("minG = %i\n",minG);
|
||||||
|
printf("minH = %i\n",minH);
|
||||||
|
printf("minB = %i\n",minB);
|
||||||
|
printf("minD = %i\n",minD);
|
||||||
|
|
||||||
|
|
||||||
|
if(minG < minD)
|
||||||
|
{
|
||||||
|
if(minG < minH)
|
||||||
|
{
|
||||||
|
if(minG <= minB)
|
||||||
|
{
|
||||||
|
printf("ACTION GAUCHE 1\n");
|
||||||
|
action = 4;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("ACTION BAS 1\n");
|
||||||
|
action = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(minH < minB)
|
||||||
|
{
|
||||||
|
printf("ACTION HAUT 1\n");
|
||||||
|
action = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("ACTION BAS 2\n");
|
||||||
|
action = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(minD < minH)
|
||||||
|
{
|
||||||
|
if(minD < minB)
|
||||||
|
{
|
||||||
|
printf("ACTION DROITE 1\n");
|
||||||
|
action = 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("ACTION BAS 3\n");
|
||||||
|
action = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(minH < minB)
|
||||||
|
{
|
||||||
|
printf("ACTION HAUT 2\n");
|
||||||
|
action = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("ACTION BAS 4\n");
|
||||||
|
action = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(n1);
|
||||||
|
return action;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int distance(int x1, int y1, int x2, int y2)
|
||||||
|
{
|
||||||
|
/* distance euclidienne */
|
||||||
|
int distX = abs(x2-x1);
|
||||||
|
int distY = abs(y2-y1);
|
||||||
|
return distX + distY;
|
||||||
|
|
||||||
|
/* carré de la distance euclidienne */
|
||||||
|
/* return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2); */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NOEUD * CalculatePath(ARENA_H_TILE* arena,int posX, int posY,NOEUD * n1,PLAYER * player1,PLAYER * player2, int compteur, int dist,int min)
|
||||||
|
{
|
||||||
|
|
||||||
|
int ID;
|
||||||
|
|
||||||
|
if(((posX - 1 >= 0) && (posX - 1 < NB_BLOCS_LARGEUR ))&& ((posY >= 0) && (posY < NB_BLOCS_HAUTEUR)))
|
||||||
|
{
|
||||||
|
if((n1->ParentX == player1->PositionX ) && ( n1->ParentY == player1->PositionY))
|
||||||
|
{
|
||||||
|
printf("n1->ParentX - 1 = %i et n1->ParentY =%i\n",n1->ParentX - 1 ,n1->ParentY);
|
||||||
|
printf("RETURN N1\n");
|
||||||
|
return n1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ID=getTileTypeID(arena,posX - 1,posY);
|
||||||
|
|
||||||
|
if(( ID== 0) && (posX-1 != n1->ParentX))
|
||||||
|
{
|
||||||
|
n1->ParentX = posX - 1;
|
||||||
|
//Vers la gauche
|
||||||
|
n1->compteur = n1->compteur + 1;
|
||||||
|
//compteur = compteur + 1;
|
||||||
|
printf("*****111*****\n");
|
||||||
|
|
||||||
|
printf("Position Player1 X: %i et Y: %i\n",player1->PositionX,player1->PositionY);
|
||||||
|
printf("Position n1 player2 X: %i et Y: %i\n",n1->ParentX,n1->ParentY);
|
||||||
|
printf("Position Player2 posX: %i et posY: %i\n",posX,posY);
|
||||||
|
printf("ID de posx - 1 et posY : %i\n",ID);
|
||||||
|
|
||||||
|
//while((posX - 1 != player1->PositionX) && (posY != player1->PositionY))
|
||||||
|
while((posX - 1 != player1->PositionX) || (posY != player1->PositionY))
|
||||||
|
{
|
||||||
|
|
||||||
|
/*printf("*****222*****\n");
|
||||||
|
printf("Position Player1 X: %i et Y: %i\n",player1->PositionX,player1->PositionY);
|
||||||
|
printf("Position n1 player2 X: %i et Y: %i\n",n1->ParentX,n1->ParentY);
|
||||||
|
printf("Position Player2 posX: %i et posY: %i\n",posX,posY);
|
||||||
|
printf("ID de posx - 1 et posY : %i\n",ID);*/
|
||||||
|
|
||||||
|
n1=CalculatePath(arena,posX - 1,posY,n1,player1,player2,compteur,dist,min);
|
||||||
|
|
||||||
|
//Post-Traitement
|
||||||
|
//Calcul du "poids" du chemin (nb de coups)
|
||||||
|
|
||||||
|
dist = distance(player1->PositionX,player1->PositionY,posX - 1,posY) + n1->compteur;
|
||||||
|
|
||||||
|
if(dist < n1->min)
|
||||||
|
{
|
||||||
|
printf("On rentre dans le min\n");
|
||||||
|
n1->min=dist;
|
||||||
|
}
|
||||||
|
return n1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("n1->compteur : %i \n",n1->compteur );
|
||||||
|
printf("abs(player2->PositionX - player1->PositionY)-1 : %i \n",abs(player2->PositionX - player1->PositionY)-1 );
|
||||||
|
if(n1->compteur == abs(player2->PositionX - player1->PositionY)-1)
|
||||||
|
{
|
||||||
|
printf("Chemin plus court trouvé\n");
|
||||||
|
n1->min=n1->compteur;
|
||||||
|
printf("n1->min : %i \n",n1->min );
|
||||||
|
return n1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(((posX +1 >= 0) && (posX + 1 < NB_BLOCS_LARGEUR ))&& ((posY >= 0) && (posY < NB_BLOCS_HAUTEUR)))
|
||||||
|
{
|
||||||
|
if((n1->ParentX == player1->PositionX ) && ( n1->ParentY == player1->PositionY))
|
||||||
|
{
|
||||||
|
printf("n1->ParentX + 1 = %i et n1->ParentY =%i\n",n1->ParentX + 1 ,n1->ParentY);
|
||||||
|
printf("RETURN N1\n");
|
||||||
|
return n1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if((getTileTypeID(arena,posX + 1 ,posY) == 0) && (posX + 1 != n1->ParentX))
|
||||||
|
{
|
||||||
|
n1->ParentX = posX + 1;
|
||||||
|
//Vers la droite
|
||||||
|
n1->compteur = n1->compteur + 1;
|
||||||
|
//compteur = compteur + 1;
|
||||||
|
|
||||||
|
//while((posX != player1->PositionX) && (posY != player1->PositionY))
|
||||||
|
while((posX != player1->PositionX) || (posY != player1->PositionY))
|
||||||
|
{
|
||||||
|
|
||||||
|
n1=CalculatePath(arena,posX + 1,posY,n1,player1,player2,compteur,dist,min);
|
||||||
|
|
||||||
|
//Post-Traitement
|
||||||
|
//Calcul du "poids" du chemin (nb de coups)
|
||||||
|
dist = distance(player1->PositionX,player1->PositionY,posX + 1,posY) + n1->compteur;
|
||||||
|
|
||||||
|
printf("DIST = %i\n",dist);
|
||||||
|
if(dist < n1->min)
|
||||||
|
{
|
||||||
|
n1->min=dist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("n1->compteur : %i \n",n1->compteur );
|
||||||
|
printf("abs(player2->PositionX - player1->PositionY)-1 : %i \n",abs(player2->PositionX - player1->PositionY)-1 );
|
||||||
|
if(n1->compteur == abs(player2->PositionX - player1->PositionY)-1)
|
||||||
|
{
|
||||||
|
printf("Chemin plus court trouvé\n");
|
||||||
|
n1->min=n1->compteur;
|
||||||
|
return n1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(((posX >= 0) && (posX < NB_BLOCS_LARGEUR ))&& ((posY + 1 >=0) && (posY + 1<NB_BLOCS_HAUTEUR)))
|
||||||
|
{
|
||||||
|
if((n1->ParentX == player1->PositionX ) && ( n1->ParentY == player1->PositionY))
|
||||||
|
{
|
||||||
|
printf("n1->ParentX = %i et n1->ParentY +1 =%i\n",n1->ParentX ,n1->ParentY+1);
|
||||||
|
printf("RETURN N1\n");
|
||||||
|
return n1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((getTileTypeID(arena,posX,posY + 1) == 0) && (posY + 1 != n1->ParentY))
|
||||||
|
{
|
||||||
|
n1->ParentY = posY + 1;
|
||||||
|
|
||||||
|
//Vers la bas
|
||||||
|
n1->compteur = n1->compteur + 1;
|
||||||
|
//compteur = compteur + 1;
|
||||||
|
|
||||||
|
//while((posX != player1->PositionX) && (posY != player1->PositionY))
|
||||||
|
while((posX != player1->PositionX) || (posY != player1->PositionY))
|
||||||
|
{
|
||||||
|
n1=CalculatePath(arena,posX,posY + 1,n1,player1,player2,compteur,dist,min);
|
||||||
|
|
||||||
|
//Post-Traitement
|
||||||
|
//Calcul du "poids" du chemin (nb de coups)
|
||||||
|
dist = distance(player1->PositionX,player1->PositionY,posX,posY + 1) + n1->compteur;
|
||||||
|
|
||||||
|
if(dist < n1->min)
|
||||||
|
{
|
||||||
|
n1->min=dist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("n1->compteur : %i \n",n1->compteur );
|
||||||
|
printf("abs(player2->PositionX - player1->PositionY)-1 : %i \n",abs(player2->PositionX - player1->PositionY)-1 );
|
||||||
|
if(n1->compteur == abs(player2->PositionX - player1->PositionY)-1)
|
||||||
|
{
|
||||||
|
printf("Chemin plus court trouvé\n");
|
||||||
|
n1->min=n1->compteur;
|
||||||
|
return n1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(((posX >= 0) && (posX < NB_BLOCS_LARGEUR ))&& ((posY - 1 >= 0) && (posY - 1 < NB_BLOCS_HAUTEUR)))
|
||||||
|
{
|
||||||
|
if((n1->ParentX == player1->PositionX ) && ( n1->ParentY == player1->PositionY))
|
||||||
|
{
|
||||||
|
printf("n1->ParentX = %i et n1->ParentY -1 =%i\n",n1->ParentX ,n1->ParentY - 1);
|
||||||
|
printf("RETURN N1\n");
|
||||||
|
return n1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((getTileTypeID(arena,posX,posY-1) == 0) && (posY - 1 != n1->ParentY))
|
||||||
|
{
|
||||||
|
n1->ParentY = posY - 1;
|
||||||
|
//Vers la haut
|
||||||
|
n1->compteur = n1->compteur + 1;
|
||||||
|
//compteur = compteur + 1;
|
||||||
|
|
||||||
|
//while((posX != player1->PositionX) && (posY != player1->PositionY))
|
||||||
|
while((posX != player1->PositionX) || (posY != player1->PositionY))
|
||||||
|
{
|
||||||
|
n1=CalculatePath(arena,posX,posY - 1,n1,player1,player2,compteur,dist,min);
|
||||||
|
|
||||||
|
//Post-Traitement
|
||||||
|
//Calcul du "poids" du chemin (nb de coups)
|
||||||
|
dist = distance(player1->PositionX,player1->PositionY,posX,posY - 1) + n1->compteur;
|
||||||
|
|
||||||
|
if(dist < n1->min)
|
||||||
|
{
|
||||||
|
n1->min=dist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("n1->compteur : %i \n",n1->compteur );
|
||||||
|
printf("abs(player2->PositionX - player1->PositionY)-1 : %i \n",abs(player2->PositionX - player1->PositionY)-1 );
|
||||||
|
|
||||||
|
if(n1->compteur == abs(player2->PositionX - player1->PositionY)-1)
|
||||||
|
{
|
||||||
|
printf("Chemin plus court trouvé\n");
|
||||||
|
n1->min=n1->compteur;
|
||||||
|
return n1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("return n1\n");
|
||||||
|
return n1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Fonction de reflexion IA fonctionne mais les pierres et arbres sont bloquants
|
//Fonction de reflexion IA fonctionne mais les pierres et arbres sont bloquants
|
||||||
@ -68,7 +454,7 @@ int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2Posi
|
|||||||
int differenceX = abs(Player1PositionX - Player2PositionX);
|
int differenceX = abs(Player1PositionX - Player2PositionX);
|
||||||
int differenceY = abs(Player1PositionY - Player2PositionY);
|
int differenceY = abs(Player1PositionY - Player2PositionY);
|
||||||
|
|
||||||
printf("DifferenceX : %i et DifferenceY : %i \n",differenceX,differenceY);
|
printf("DifferenceX : %i et DifferenceY : %i \n",differenceX,differenceY);
|
||||||
|
|
||||||
int action=0;
|
int action=0;
|
||||||
|
|
||||||
|
15
IAEngine.h
@ -8,8 +8,23 @@
|
|||||||
#ifndef IAENGINE_H_
|
#ifndef IAENGINE_H_
|
||||||
#define IAENGINE_H_
|
#define IAENGINE_H_
|
||||||
|
|
||||||
|
typedef struct noeud
|
||||||
|
{
|
||||||
|
int compteur, min, cout_f; //
|
||||||
|
|
||||||
|
int ParentX;
|
||||||
|
int ParentY;
|
||||||
|
// 'adresse' du parent (qui sera toujours dans la map fermée)
|
||||||
|
}NOEUD;
|
||||||
|
|
||||||
|
|
||||||
int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2PositionX, int Player2PositionY);
|
int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2PositionX, int Player2PositionY);
|
||||||
//int IAEngine(PLAYER * player1, PLAYER * player2);
|
//int IAEngine(PLAYER * player1, PLAYER * player2);
|
||||||
int IAEngine(ARENA_H_TILE* arena,PLAYER * player1, PLAYER * player2);
|
int IAEngine(ARENA_H_TILE* arena,PLAYER * player1, PLAYER * player2);
|
||||||
|
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_ */
|
#endif /* IAENGINE_H_ */
|
||||||
|
Before Width: | Height: | Size: 246 B After Width: | Height: | Size: 246 B |
BIN
Landscape/grass_green_32x32.png
Executable file
After Width: | Height: | Size: 2.4 KiB |
BIN
Landscape/river_green_32x32.png
Executable file
After Width: | Height: | Size: 2.2 KiB |
BIN
Landscape/stone_green_32x32.png
Executable file
After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
BIN
Landscape/tree_green_32x32.png
Executable file
After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
@ -9,7 +9,7 @@
|
|||||||
* Arena generate functions
|
* Arena generate functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define BLOC_SIZE 34 // Taille d'un bloc (carré) en pixels
|
#define BLOC_SIZE 32 // Taille d'un bloc (carré) en pixels
|
||||||
#define NB_BLOCS_LARGEUR 20
|
#define NB_BLOCS_LARGEUR 20
|
||||||
#define NB_BLOCS_HAUTEUR 20
|
#define NB_BLOCS_HAUTEUR 20
|
||||||
#define LARGEUR_FENETRE BLOC_SIZE * NB_BLOCS_LARGEUR
|
#define LARGEUR_FENETRE BLOC_SIZE * NB_BLOCS_LARGEUR
|
||||||
@ -29,7 +29,8 @@ ARENA_H_TILE* genNewArena(int size_h, int size_w)
|
|||||||
//int i = 0, j = 0;
|
//int i = 0, j = 0;
|
||||||
|
|
||||||
printf("Chargement du fichier\n");
|
printf("Chargement du fichier\n");
|
||||||
fichier = fopen("level1-20x20.lvl", "r");
|
fichier = fopen("level2-20x20.lvl", "r");
|
||||||
|
|
||||||
if (fichier == NULL)
|
if (fichier == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
#include "fileHandler.h"
|
#include "fileHandler.h"
|
||||||
//#include "main.c"
|
//#include "main.c"
|
||||||
|
|
||||||
#define BLOC_SIZE 34 // Taille d'un bloc (carré) en pixels
|
#define BLOC_SIZE 32 // Taille d'un bloc (carré) en pixels
|
||||||
#define NB_BLOCS_LARGEUR 20
|
#define NB_BLOCS_LARGEUR 20
|
||||||
#define NB_BLOCS_HAUTEUR 20
|
#define NB_BLOCS_HAUTEUR 20
|
||||||
#define LARGEUR_FENETRE BLOC_SIZE * NB_BLOCS_LARGEUR
|
#define LARGEUR_FENETRE BLOC_SIZE * NB_BLOCS_LARGEUR
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#ifndef FILEHANDLER_H_
|
#ifndef FILEHANDLER_H_
|
||||||
#define FILEHANDLER_H_
|
#define FILEHANDLER_H_
|
||||||
|
|
||||||
#define BLOC_SIZE 34 // Taille d'un bloc (carré) en pixels
|
#define BLOC_SIZE 32 // Taille d'un bloc (carré) en pixels
|
||||||
#define NB_BLOCS_LARGEUR 20
|
#define NB_BLOCS_LARGEUR 20
|
||||||
#define NB_BLOCS_HAUTEUR 20
|
#define NB_BLOCS_HAUTEUR 20
|
||||||
#define LARGEUR_FENETRE BLOC_SIZE * NB_BLOCS_LARGEUR
|
#define LARGEUR_FENETRE BLOC_SIZE * NB_BLOCS_LARGEUR
|
||||||
|
1
level2-20x20.lvl
Normal file
@ -0,0 +1 @@
|
|||||||
|
0022200002222200001000022001022200000022000200000022200000022000002200020000100222000102000000000000200000000000022200020000002220000022000000010222220000020002220000222000100000002000000000000022200000000022200000202200000200020000000220000022200000010000002200020000200000022222001000000000000022220000000220000000002222000000200000100002222201000000022200002220000220000220000200000022220000200100
|
22
main.c
@ -15,7 +15,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define BLOC_SIZE 34 // Taille d'un bloc (carré) en pixels
|
#define BLOC_SIZE 32 // Taille d'un bloc (carré) en pixels
|
||||||
#define NB_BLOCS_LARGEUR 20
|
#define NB_BLOCS_LARGEUR 20
|
||||||
#define NB_BLOCS_HAUTEUR 20
|
#define NB_BLOCS_HAUTEUR 20
|
||||||
#define LARGEUR_FENETRE BLOC_SIZE * NB_BLOCS_LARGEUR
|
#define LARGEUR_FENETRE BLOC_SIZE * NB_BLOCS_LARGEUR
|
||||||
@ -44,7 +44,7 @@ int main(void)
|
|||||||
SDL_Surface *player[4] = {NULL}; // 4 surfaces pour 4 directions de mario
|
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 *IA1[4] = {NULL}; // 4 surfaces pour 4 directions de mario
|
||||||
SDL_Surface *grass = NULL;
|
SDL_Surface *grass = NULL;
|
||||||
SDL_Surface *rock = NULL, *tree = NULL,*actualPlayer = NULL, *actualIA1 = NULL;
|
SDL_Surface *rock = NULL, *tree = NULL, *river = NULL,*actualPlayer = NULL, *actualIA1 = NULL;
|
||||||
SDL_Rect position, positionJoueur;
|
SDL_Rect position, positionJoueur;
|
||||||
|
|
||||||
|
|
||||||
@ -67,12 +67,20 @@ int main(void)
|
|||||||
printf("Erreur de la génération de l'arène\n");
|
printf("Erreur de la génération de l'arène\n");
|
||||||
}
|
}
|
||||||
// Chargement des sprites (décors, personnage...)
|
// Chargement des sprites (décors, personnage...)
|
||||||
grass = IMG_Load("/home/isen/eclipse-workspace/ArenaWarSurvival/dirt_brown.png");
|
grass = IMG_Load("Landscape/grass_green_32x32.png");
|
||||||
rock = IMG_Load("/home/isen/eclipse-workspace/ArenaWarSurvival/stone_resize.png");
|
rock = IMG_Load("Landscape/stone_green_32x32.png");
|
||||||
tree = IMG_Load("/home/isen/eclipse-workspace/ArenaWarSurvival/tree_resize.png");
|
tree = IMG_Load("Landscape/tree_green_32x32.png");
|
||||||
|
river = IMG_Load("Landscape/river_green_32x32.png");
|
||||||
|
|
||||||
player[BAS] = IMG_Load("adventurer_resize.png");
|
player[BAS] = IMG_Load("Adventurer/adventurer1_32x32.png");
|
||||||
IA1[BAS] = IMG_Load("zombie_resize.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];
|
actualPlayer = player[BAS];
|
||||||
actualIA1 = IA1[BAS];
|
actualIA1 = IA1[BAS];
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
|
|
||||||
enum {GRASS, ROCK, TREE,FIRSTPLAYER, IA1};
|
enum {GRASS, ROCK, TREE,FIRSTPLAYER, IA1};
|
||||||
#define BLOC_SIZE 34 // Taille d'un bloc (carré) en pixels
|
#define BLOC_SIZE 32 // Taille d'un bloc (carré) en pixels
|
||||||
#define NB_BLOCS_LARGEUR 20
|
#define NB_BLOCS_LARGEUR 20
|
||||||
#define NB_BLOCS_HAUTEUR 20
|
#define NB_BLOCS_HAUTEUR 20
|
||||||
#define LARGEUR_FENETRE BLOC_SIZE * NB_BLOCS_LARGEUR
|
#define LARGEUR_FENETRE BLOC_SIZE * NB_BLOCS_LARGEUR
|
||||||
|
Before Width: | Height: | Size: 2.2 KiB |