-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentity.c
More file actions
155 lines (116 loc) · 2.48 KB
/
entity.c
File metadata and controls
155 lines (116 loc) · 2.48 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* @file entity.c
*/
#include "header.h"
int
nb_frame=12 ,
entity_h=100,
entity_w=100,
entity_y=100,
entity_x=100;
void init_tab_anim_entity(SDL_Rect *clip,entity *e)
{
for (int j=0;j<nb_frame; j++)
{
clip[j].h=entity_h;
clip[j].w=entity_w;
clip[j].x = j*entity_x;
clip[j].y = 0;
}
}
/**
* @brief To initialize the entity e .
* @param e the entity
* @return Nothing
*/
void initentity(entity *e)
{
e->entity = IMG_Load("es.png");
e->pos_entity.x = 3000;
e->pos_entity.y = 700;
init_tab_anim_entity(e->anim_entity,e);
e->frame_entity=0;//indice mta3 l taswera
e->direction=0;
e->col=0;
e->show=1;
}
/**
* @brief To show the entity e .
* @param screen the screen
* @param e the entity
* @return Nothing
*/
void afficherentity(entity e , SDL_Surface *screen)
{
SDL_BlitSurface(e.entity,&e.anim_entity[e.frame_entity], screen, &e.pos_entity);
}
/**
* @brief for the random movement of the secondary entity .
* @param e the entity
* @param p the personnage
* @return Nothing
*/
void deplacer(entity *e)
{
srand (time(0));// l but mel function eno l fonction rand() ma taawedesh tekhhouli nafs les valeurs f kol run ( excution)
int maxi_down=700+rand()%300;
int maxi_up=400+rand()%300;
//printf("maxup : %d\tmaxdown : %d\n",maxi_up,maxi_down );
if(e->pos_entity.y>= maxi_down)
{
e->direction =1;
}
if(e->pos_entity.y<=maxi_up)
{
e->direction =0;
}
if(e->direction==1)
{
e->pos_entity.y-=5;
}
if(e->direction==0)
{
e->pos_entity.y+=7;
}
}
/**
* @brief for the animation the secondary entity .
* @param e the entity
* @return Nothing
*/
void animerentity(entity *e)
{
if (e->frame_entity >=0 && e->frame_entity <(nb_frame-1))
e->frame_entity++;
if ( e->frame_entity ==(nb_frame-1))
e->frame_entity=0;
}
/**
* @brief for the integration of two functions (anim,mouv) .
* @param e the entity
* @param p the personnage
* @return Nothing
*/
void update_entity(entity *e)
{
deplacer(e);
animerentity(e);
}
int detect_collision(personne *p, entity* e)
{
if ((p->pos_hero.x + p->pos_hero.w< e->pos_entity. x) || (p->pos_hero.x> e->pos_entity. x + e->pos_entity. w) ||
(p->pos_hero.y + p->pos_hero.h< e->pos_entity. y) || (p->pos_hero.y> e->pos_entity. y + e->pos_entity. h ))
return 0;
else
return 1;
}
/**
* @brief if the type of the entity is good so it will disappear in case of collision .
* @param e the entity
* @return 0
*/
int gestion(entity* e)
{
e->show=0;
return 0;
}