Fixed grass move bug and cleaned code
This commit is contained in:
parent
907a33d715
commit
843719b433
@ -557,11 +557,11 @@ int NumberPlayerAlive(PLAYER *Head)
|
|||||||
return numberAlive;
|
return numberAlive;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getRelativeDirection(int pos1_x, int pos1_y, int pos2_x, int pos2_y) {
|
int getRelativeDirection(SDL_Rect pos1, SDL_Rect pos2) {
|
||||||
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>0) {
|
if (_x>0) {
|
||||||
return DOWN;
|
return DOWN;
|
||||||
|
@ -67,7 +67,7 @@ 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(int pos1_x, int pos1_y, int pos2_x, int pos2_y);
|
int getRelativeDirection(SDL_Rect pos1, SDL_Rect pos2);
|
||||||
|
|
||||||
int NumberPlayerAlive(PLAYER *Head);
|
int NumberPlayerAlive(PLAYER *Head);
|
||||||
void AttackPlayer(PLAYER *player1, PLAYER *player2);
|
void AttackPlayer(PLAYER *player1, PLAYER *player2);
|
||||||
|
@ -26,8 +26,7 @@ int updateArena(SDL_Window* window, ARENA_H_TILE* arena, TILE *tiles, PLAYER *pl
|
|||||||
|
|
||||||
PLAYER *p1=NULL,*p2=NULL;
|
PLAYER *p1=NULL,*p2=NULL;
|
||||||
|
|
||||||
p1=player;
|
p1=player;p2=player->suiv;
|
||||||
p2=player->suiv;
|
|
||||||
|
|
||||||
printf("Nom player 1 : %s\n",p1->Name);
|
printf("Nom player 1 : %s\n",p1->Name);
|
||||||
printf("Nom player 2 : %s\n",p2->Name);
|
printf("Nom player 2 : %s\n",p2->Name);
|
||||||
@ -36,64 +35,49 @@ int updateArena(SDL_Window* window, ARENA_H_TILE* arena, TILE *tiles, PLAYER *pl
|
|||||||
|
|
||||||
int action=0,actionIA=0;
|
int action=0,actionIA=0;
|
||||||
|
|
||||||
|
//Affichage des joueurs au début de la partie
|
||||||
|
position.x = p1->PositionX * TILE_SIZE;
|
||||||
|
position.y = p1->PositionY * TILE_SIZE;
|
||||||
|
SDL_BlitSurface(p1->texture[DOWN], NULL, SDL_GetWindowSurface(window), &position);
|
||||||
|
|
||||||
|
IAposition.x = p2->PositionX * TILE_SIZE;
|
||||||
|
IAposition.y = p2->PositionY * TILE_SIZE;
|
||||||
|
SDL_BlitSurface(p2->texture[DOWN], NULL, SDL_GetWindowSurface(window), &IAposition);
|
||||||
|
|
||||||
|
SDL_UpdateWindowSurface(window);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
oldposition.x = p1->PositionX * TILE_SIZE;
|
oldposition.x = p1->PositionX * TILE_SIZE;
|
||||||
oldposition.y = p1->PositionY * TILE_SIZE;
|
oldposition.y = p1->PositionY * TILE_SIZE;
|
||||||
oldIAposition.x = p2->PositionX * TILE_SIZE;
|
oldIAposition.x = p2->PositionX * TILE_SIZE;
|
||||||
oldIAposition.y = p2->PositionY * TILE_SIZE;
|
oldIAposition.y = p2->PositionY * TILE_SIZE;
|
||||||
|
|
||||||
|
|
||||||
//Affichage des joueurs au début de la partie
|
while(action == 0) {
|
||||||
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();
|
action=getKeyEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(action == -1)
|
if(action == -1){
|
||||||
{
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else if(action == 1) {
|
||||||
else if(action == 1)
|
|
||||||
{
|
|
||||||
ActionPlayer(arena,tiles,p1,1); //Déplacement vers le haut
|
ActionPlayer(arena,tiles,p1,1); //Déplacement vers le haut
|
||||||
}
|
} else if(action == 2) {
|
||||||
else if(action == 2)
|
|
||||||
{
|
|
||||||
ActionPlayer(arena,tiles,p1,2); //Déplacement vers la droite
|
ActionPlayer(arena,tiles,p1,2); //Déplacement vers la droite
|
||||||
}
|
} else if(action == 3) {
|
||||||
else if(action == 3)
|
|
||||||
{
|
|
||||||
ActionPlayer(arena,tiles,p1,3); //Déplacement vers le bas
|
ActionPlayer(arena,tiles,p1,3); //Déplacement vers le bas
|
||||||
}
|
} else if(action == 4) {
|
||||||
else if(action == 4)
|
|
||||||
{
|
|
||||||
ActionPlayer(arena,tiles,p1,4); //Déplacement vers la gauche
|
ActionPlayer(arena,tiles,p1,4); //Déplacement vers la gauche
|
||||||
}
|
} else if(action == 5) {
|
||||||
else if(action == 5)
|
|
||||||
{
|
|
||||||
//Regarder le perso en face, le plus près
|
//Regarder le perso en face, le plus près
|
||||||
AttackPlayer(p1,p2); //Voir quel player on choisit d'attaquer
|
AttackPlayer(p1,p2); //Voir quel player on choisit d'attaquer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// On place le joueur à la bonne position
|
||||||
//Partie ajoutée
|
|
||||||
// On place le joueur à la bonne position
|
|
||||||
position.x = p1->PositionX * TILE_SIZE;
|
position.x = p1->PositionX * TILE_SIZE;
|
||||||
position.y = p1->PositionY * 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[getRelativeDirection(oldposition, position)], NULL, SDL_GetWindowSurface(window), &position);
|
||||||
|
SDL_BlitSurface(getTileSurfaceFromID(tiles,getTileTypeID(arena,(oldposition.x)/TILE_SIZE,(oldposition.y)/TILE_SIZE)), NULL, SDL_GetWindowSurface(window), &oldposition);
|
||||||
SDL_BlitSurface(p1->texture[DOWN], 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);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -113,28 +97,25 @@ int updateArena(SDL_Window* window, ARENA_H_TILE* arena, TILE *tiles, PLAYER *pl
|
|||||||
IAposition.y = p2->PositionY * TILE_SIZE;
|
IAposition.y = p2->PositionY * TILE_SIZE;
|
||||||
|
|
||||||
//SDL_BlitSurface(p2->texture[getRelativeDirection(oldIAposition, IAposition)], NULL, SDL_GetWindowSurface(window), &IAposition);
|
//SDL_BlitSurface(p2->texture[getRelativeDirection(oldIAposition, IAposition)], NULL, SDL_GetWindowSurface(window), &IAposition);
|
||||||
|
SDL_BlitSurface(getTileSurfaceFromID(tiles,getTileTypeID(arena,(oldIAposition.x)/TILE_SIZE,(oldIAposition.y)/TILE_SIZE)), NULL, SDL_GetWindowSurface(window), &oldIAposition);
|
||||||
SDL_BlitSurface(p2->texture[DOWN], 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);
|
SDL_UpdateWindowSurface(window);
|
||||||
|
|
||||||
action=0;actionIA=0;
|
action=0;actionIA=0;
|
||||||
|
|
||||||
} while((p1->HealthPoints >0) && (NumberPlayerAlive(player) > 1));
|
} while((p1->HealthPoints > 0) && (NumberPlayerAlive(player) > 1));
|
||||||
|
|
||||||
printf("La partie est terminée\n");
|
printf("La partie est terminée\n");
|
||||||
|
|
||||||
if(p1->HealthPoints > 0)
|
if(p1->HealthPoints > 0){
|
||||||
{
|
|
||||||
printf("Vous avez gagné\n");
|
printf("Vous avez gagné\n");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Vous avez perdu\n");
|
printf("Vous avez perdu\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Si une des IA meurt, voir comment on le gère
|
//Si une des IA meurt, voir comment on le gère
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getKeyEvent()
|
int getKeyEvent()
|
||||||
@ -142,15 +123,13 @@ int getKeyEvent()
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
SDL_WaitEvent(&event); /* Récupération de l'événement dans event */
|
SDL_WaitEvent(&event); /* Récupération de l'événement dans event */
|
||||||
|
|
||||||
switch(event.type) /* Test du type d'événement */
|
switch(event.type) { /* Test du type d'événement */
|
||||||
{
|
|
||||||
/* Si c'est un événement de type "Quitter" */
|
/* Si c'est un événement de type "Quitter" */
|
||||||
case SDL_QUIT :
|
case SDL_QUIT :
|
||||||
printf("QUITTER\n");
|
printf("QUITTER\n");
|
||||||
return -1;
|
return -1;
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
switch(event.key.keysym.sym) //La valeur de touche
|
switch(event.key.keysym.sym) { //La valeur de touche
|
||||||
{
|
|
||||||
case SDLK_UP:
|
case SDLK_UP:
|
||||||
printf("FLECHE DU HAUT\n");
|
printf("FLECHE DU HAUT\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -54,14 +54,7 @@ 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;
|
while (updateArena(gameWindows,arena,tile_ressources,player_ressources)!=0) {}
|
||||||
int action;
|
|
||||||
|
|
||||||
while (continuer) {
|
|
||||||
action = updateArena(gameWindows,arena,tile_ressources,player_ressources);
|
|
||||||
|
|
||||||
if (action == -1) continuer = 0;
|
|
||||||
}
|
|
||||||
SDL_DestroyWindow(gameWindows);
|
SDL_DestroyWindow(gameWindows);
|
||||||
|
|
||||||
deleteArena(arena);
|
deleteArena(arena);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user