player animation
This commit is contained in:
BIN
image/playerDown.png
LFS
Normal file
BIN
image/playerDown.png
LFS
Normal file
Binary file not shown.
BIN
image/playerFall.png
LFS
Normal file
BIN
image/playerFall.png
LFS
Normal file
Binary file not shown.
BIN
image/playerLeft.png
LFS
Normal file
BIN
image/playerLeft.png
LFS
Normal file
Binary file not shown.
BIN
image/playerUp.png
LFS
Normal file
BIN
image/playerUp.png
LFS
Normal file
Binary file not shown.
BIN
image/win.png
LFS
BIN
image/win.png
LFS
Binary file not shown.
@@ -14,7 +14,7 @@ void displayImage (SDL_Renderer *renderer, SDL_Texture *texture, vect pos,
|
|||||||
int size);
|
int size);
|
||||||
void initSDL (dis *display_user);
|
void initSDL (dis *display_user);
|
||||||
void displayTextSDL(dis *display_user,char *text, vect coor, vect size, int font_size);
|
void displayTextSDL(dis *display_user,char *text, vect coor, vect size, int font_size);
|
||||||
void screenDisplayGameSDL (char **tab,vect dim_tab, dis *display_user, vect *player_pos, int fov);
|
void screenDisplayGameSDL (char **tab,vect dim_tab, dis *display_user, vect *player_pos, int fov, vect direction);
|
||||||
void backgroundDisplay(dis *display_user,int bg);
|
void backgroundDisplay(dis *display_user,int bg);
|
||||||
|
|
||||||
#endif // !DISPLAY_H
|
#endif // !DISPLAY_H
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ char *timeToText(time_t time);
|
|||||||
void nullScore(score *player_score);
|
void nullScore(score *player_score);
|
||||||
void winOrLoseLoop(dis *display_user,score *score_user, bool win);
|
void winOrLoseLoop(dis *display_user,score *score_user, bool win);
|
||||||
unsigned int scoreCalculator(score *score_user, bool win);
|
unsigned int scoreCalculator(score *score_user, bool win);
|
||||||
|
unsigned int scoreCalculatorCyp(score *score_user, bool win);
|
||||||
int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
||||||
int nbr_targets, dis *display_user,score *score_user, int num_fichier);
|
int nbr_targets, dis *display_user,score *score_user, int num_fichier);
|
||||||
int titleScreen (dis *display_user);
|
int titleScreen (dis *display_user);
|
||||||
|
|||||||
@@ -43,9 +43,10 @@ void screenDisplay (char **tab, int x ,int y )
|
|||||||
* l'affichage SDL
|
* l'affichage SDL
|
||||||
* \param player_pos la position du joueur
|
* \param player_pos la position du joueur
|
||||||
* \param fov Le fov de la vision du joueur, -1 si desactiver.
|
* \param fov Le fov de la vision du joueur, -1 si desactiver.
|
||||||
|
* \param direction La direction du personnage.
|
||||||
* \return Void
|
* \return Void
|
||||||
*/
|
*/
|
||||||
void screenDisplayGameSDL (char **tab,vect dim_tab, dis *display_user, vect *player_pos, int fov)
|
void screenDisplayGameSDL (char **tab,vect dim_tab, dis *display_user, vect *player_pos, int fov, vect direction)
|
||||||
{
|
{
|
||||||
unsigned int display_game
|
unsigned int display_game
|
||||||
= display_user->size_window - display_user->size_menu;
|
= display_user->size_window - display_user->size_menu;
|
||||||
@@ -102,7 +103,11 @@ void screenDisplayGameSDL (char **tab,vect dim_tab, dis *display_user, vect *pla
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case PLAYER:
|
case PLAYER:
|
||||||
img = IMG_Load ("image/player.png");
|
if(direction.y == 1){ img = IMG_Load ("image/player.png");}
|
||||||
|
else if(direction.y == -1){ img = IMG_Load ("image/playerLeft.png");}
|
||||||
|
else if(direction.x == -1){ img = IMG_Load ("image/playerUp.png");}
|
||||||
|
else if(direction.x == 1){ img = IMG_Load ("image/playerDown.png");}
|
||||||
|
else if(direction.y == 0 && direction.x == 0){ img = IMG_Load ("image/playerFall.png");}
|
||||||
break;
|
break;
|
||||||
case TARGET:
|
case TARGET:
|
||||||
img = IMG_Load ("image/target.png");
|
img = IMG_Load ("image/target.png");
|
||||||
|
|||||||
@@ -147,10 +147,10 @@ char canIGoDirection (char valueOfNCase, char valueOfNPlusOneCase)
|
|||||||
* \param direction La direction que le joueur veut effectuer.
|
* \param direction La direction que le joueur veut effectuer.
|
||||||
* \param score_user Toutes les données nécessaire pour calculer le score fini
|
* \param score_user Toutes les données nécessaire pour calculer le score fini
|
||||||
* du joueur.
|
* du joueur.
|
||||||
* \return Void
|
* \return int return 1 si le joueur n'a pas bouger.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void move (char **tab, vect *playerPos, vect direction, score *score_user)
|
int move (char **tab, vect *playerPos, vect direction, score *score_user)
|
||||||
{
|
{
|
||||||
short int valueOfNCase
|
short int valueOfNCase
|
||||||
= tab[playerPos->x + direction.x][playerPos->y + direction.y];
|
= tab[playerPos->x + direction.x][playerPos->y + direction.y];
|
||||||
@@ -179,6 +179,7 @@ void move (char **tab, vect *playerPos, vect direction, score *score_user)
|
|||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
playAudio(2);
|
playAudio(2);
|
||||||
|
return 1;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
//move player
|
//move player
|
||||||
@@ -251,6 +252,7 @@ void move (char **tab, vect *playerPos, vect direction, score *score_user)
|
|||||||
playerPos->x = playerPos->x + direction.x;
|
playerPos->x = playerPos->x + direction.x;
|
||||||
playerPos->y = playerPos->y + direction.y;
|
playerPos->y = playerPos->y + direction.y;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -303,7 +305,7 @@ int inGameLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
|||||||
char input;
|
char input;
|
||||||
bool finish = false;
|
bool finish = false;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos, fov);
|
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos, fov,direction);
|
||||||
while (!finish)
|
while (!finish)
|
||||||
{
|
{
|
||||||
while (SDL_PollEvent (&event))
|
while (SDL_PollEvent (&event))
|
||||||
@@ -346,9 +348,10 @@ int inGameLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
|||||||
direction.x = 0;
|
direction.x = 0;
|
||||||
direction.y = 0;
|
direction.y = 0;
|
||||||
}
|
}
|
||||||
move (tab2d, playerPos, direction, score_user);
|
int tmp = move (tab2d, playerPos, direction, score_user);
|
||||||
|
if(tmp == 1){direction.x = 0; direction.y = 0;}
|
||||||
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos,
|
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos,
|
||||||
fov);
|
fov,direction);
|
||||||
if (!menu)
|
if (!menu)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -503,7 +506,7 @@ int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
|||||||
char input;
|
char input;
|
||||||
bool finish = false;
|
bool finish = false;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos, fov);
|
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos, fov,direction);
|
||||||
|
|
||||||
|
|
||||||
int GRID_SIZE = 20;
|
int GRID_SIZE = 20;
|
||||||
@@ -544,7 +547,7 @@ int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
|||||||
tab2d[row][col] += 1;
|
tab2d[row][col] += 1;
|
||||||
}
|
}
|
||||||
// Met à jour l'affichage
|
// Met à jour l'affichage
|
||||||
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos, fov);
|
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos, fov,direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.button.button == SDL_BUTTON_RIGHT) {
|
if (event.button.button == SDL_BUTTON_RIGHT) {
|
||||||
@@ -570,7 +573,7 @@ int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
|||||||
tab2d[row][col] -= 1;
|
tab2d[row][col] -= 1;
|
||||||
}
|
}
|
||||||
// Met à jour l'affichage
|
// Met à jour l'affichage
|
||||||
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos, fov);
|
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos, fov,direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -609,9 +612,10 @@ int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
|||||||
direction.x = 0;
|
direction.x = 0;
|
||||||
direction.y = 0;
|
direction.y = 0;
|
||||||
}
|
}
|
||||||
move (tab2d, playerPos, direction, score_user);
|
int tmp = move (tab2d, playerPos, direction, score_user);
|
||||||
|
if(tmp == 1){direction.x = 0; direction.y = 0;}
|
||||||
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos,
|
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos,
|
||||||
fov);
|
fov,direction);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -941,7 +945,7 @@ void winOrLoseLoop(dis *display_user,score *score_user, bool win)
|
|||||||
displayImage(display_user->renderer, texture, pos, display_user->size_window);
|
displayImage(display_user->renderer, texture, pos, display_user->size_window);
|
||||||
|
|
||||||
char text[50] = "";
|
char text[50] = "";
|
||||||
snprintf(text, 50, "Score : %u",scoreCalculator(score_user, win));
|
snprintf(text, 50, "Score : %u",scoreCalculatorCyp(score_user, win));
|
||||||
vect pos_score = {10, (display_user->size_window*3) / 4};
|
vect pos_score = {10, (display_user->size_window*3) / 4};
|
||||||
vect size_score = {display_user->size_window / 4, display_user->size_window - 10};
|
vect size_score = {display_user->size_window / 4, display_user->size_window - 10};
|
||||||
displayTextSDL(display_user, text , pos_score, size_score, 80);
|
displayTextSDL(display_user, text , pos_score, size_score, 80);
|
||||||
@@ -976,5 +980,17 @@ unsigned int scoreCalculator(score *score_user, bool win)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int scoreCalculatorCyp(score *score_user, bool win)
|
||||||
|
{
|
||||||
|
unsigned short int result = 0; //plus grand nombre
|
||||||
|
int time = score_user->after - score_user->before;
|
||||||
|
result += (score_user->move_box + score_user->move_player) * time;
|
||||||
|
if (!win)
|
||||||
|
{
|
||||||
|
result /= 50;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user