Fixed rotation when moving

This commit is contained in:
JackCarterSmith 2018-06-26 19:34:43 +02:00
parent 843719b433
commit 1886bd7f16
5 changed files with 3248 additions and 3234 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -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);

View File

@ -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
AttackPlayer(p1,p2); //Voir quel player on choisit d'attaquer if (canAttackPlayer(p1,p2)==1) {
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);

View File

@ -1,24 +1,24 @@
#ifndef MAIN_H_ #ifndef MAIN_H_
#define MAIN_H_ #define MAIN_H_
#define A_WIDTH 30 #define A_WIDTH 30
#define A_HEIGHT 30 #define A_HEIGHT 30
#define TILE_SIZE 32 #define TILE_SIZE 32
#define WINDOWS_WIDTH TILE_SIZE * A_WIDTH #define WINDOWS_WIDTH TILE_SIZE * A_WIDTH
#define WINDOWS_HEIGHT TILE_SIZE * A_HEIGHT #define WINDOWS_HEIGHT TILE_SIZE * A_HEIGHT
/* /*
* Generator tiles spawn rate (in percent) * Generator tiles spawn rate (in percent)
*/ */
#define ROCK_GEN_RATE 30 #define ROCK_GEN_RATE 30
#define TREE_GEN_RATE 25 #define TREE_GEN_RATE 25
#define WATER_GEN_RATE 8 #define WATER_GEN_RATE 8
#define GOLD_GEN_RATE 10 #define GOLD_GEN_RATE 10
enum {DOWN, UP, LEFT, RIGHT}; enum {DOWN, UP, LEFT, RIGHT};
enum {GRASS, ROCK, TREE, WATER, GOLD, SPAWN}; enum {GRASS, ROCK, TREE, WATER, GOLD, SPAWN};
int random_lim(int max); int random_lim(int max);
#endif #endif