-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation.c
47 lines (35 loc) · 990 Bytes
/
animation.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "animation.h"
/* fonction qui permet d'animer l'hero ou l'ennemi */
void dessinerAnimatedEntity(ObjetJeux *entity)
{
if (entity->frameTimer <= 0)
{
entity->frameTimer = TEMPS_ENTRE_2_FRAMES;
entity->frameNumber++;
if(entity->frameNumber >= entity->sprite->w / entity->w)
entity->frameNumber = 0;
}
else
entity->frameTimer--;
SDL_Rect dest;
dest.x = entity->x - map.startX;
dest.y = entity->y - map.startY;
dest.w = entity->w;
dest.h = entity->h;
SDL_Rect src;
src.x = entity->frameNumber * entity->w;
src.y = 0;
src.w = entity->w;
src.h = entity->h;
SDL_BlitSurface(entity->sprite, &src, jeu.screen, &dest);
}
void changerAnimation(ObjetJeux *entity, char *name)
{
if (entity->sprite != NULL)
{
SDL_FreeSurface(entity->sprite);
}
entity->sprite = loadImage(name);
entity->frameNumber = 0;
entity->frameTimer = TEMPS_ENTRE_2_FRAMES;
}