Fixed rotation when moving
This commit is contained in:
parent
843719b433
commit
1886bd7f16
@ -564,18 +564,29 @@ int getRelativeDirection(SDL_Rect pos1, SDL_Rect pos2) {
|
|||||||
_y = pos2.y - pos1.y;
|
_y = pos2.y - pos1.y;
|
||||||
|
|
||||||
if (_x>0) {
|
if (_x>0) {
|
||||||
return DOWN;
|
|
||||||
} else if (_x<0) {
|
|
||||||
return UP;
|
|
||||||
} else if (_y>0) {
|
|
||||||
return RIGHT;
|
|
||||||
} else if (_y<0) {
|
|
||||||
return LEFT;
|
return LEFT;
|
||||||
|
} else if (_x<0) {
|
||||||
|
return RIGHT;
|
||||||
|
} else if (_y>0) {
|
||||||
|
return DOWN;
|
||||||
|
} else if (_y<0) {
|
||||||
|
return UP;
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return DOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int canAttackPlayer(PLAYER *p1, PLAYER *p2) {
|
||||||
|
int allow = 0,_x,_y;
|
||||||
|
|
||||||
|
_x = p2->PositionX - p1->PositionX;
|
||||||
|
_y = p2->PositionY - p1->PositionY;
|
||||||
|
|
||||||
|
if (_x <= 1 && _x >= -1 && _y <= 1 && _y >= -1) allow = 1;
|
||||||
|
|
||||||
|
return allow;
|
||||||
|
}
|
||||||
|
|
||||||
void AttackPlayer(PLAYER *player1, PLAYER *player2)
|
void AttackPlayer(PLAYER *player1, PLAYER *player2)
|
||||||
{
|
{
|
||||||
printf("Fonction Attaque\n");
|
printf("Fonction Attaque\n");
|
||||||
|
@ -70,6 +70,7 @@ int isMoveCorrect(ARENA_H_TILE* arena, TILE *t_list, int coord_x, int coord_y, i
|
|||||||
int getRelativeDirection(SDL_Rect pos1, SDL_Rect pos2);
|
int getRelativeDirection(SDL_Rect pos1, SDL_Rect pos2);
|
||||||
|
|
||||||
int NumberPlayerAlive(PLAYER *Head);
|
int NumberPlayerAlive(PLAYER *Head);
|
||||||
|
int canAttackPlayer(PLAYER *p1, PLAYER *p2);
|
||||||
void AttackPlayer(PLAYER *player1, PLAYER *player2);
|
void AttackPlayer(PLAYER *player1, PLAYER *player2);
|
||||||
void ActionPlayer(ARENA_H_TILE* arena,TILE *t_list,PLAYER * player, int action);
|
void ActionPlayer(ARENA_H_TILE* arena,TILE *t_list,PLAYER * player, int action);
|
||||||
|
|
||||||
|
@ -68,16 +68,18 @@ int updateArena(SDL_Window* window, ARENA_H_TILE* arena, TILE *tiles, PLAYER *pl
|
|||||||
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
|
||||||
|
if (canAttackPlayer(p1,p2)==1) {
|
||||||
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
|
// 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(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(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(p1->texture[getRelativeDirection(oldposition, position)], NULL, SDL_GetWindowSurface(window), &position);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -96,9 +98,9 @@ int updateArena(SDL_Window* window, ARENA_H_TILE* arena, TILE *tiles, PLAYER *pl
|
|||||||
IAposition.x = p2->PositionX * TILE_SIZE;
|
IAposition.x = p2->PositionX * TILE_SIZE;
|
||||||
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(getTileSurfaceFromID(tiles,getTileTypeID(arena,(oldIAposition.x)/TILE_SIZE,(oldIAposition.y)/TILE_SIZE)), NULL, SDL_GetWindowSurface(window), &oldIAposition);
|
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(p2->texture[getRelativeDirection(oldIAposition, IAposition)], NULL, SDL_GetWindowSurface(window), &IAposition);
|
||||||
|
|
||||||
SDL_UpdateWindowSurface(window);
|
SDL_UpdateWindowSurface(window);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user