3ff9b218
mahmoudrabia
rapport finale
|
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
156
157
158
159
160
|
#include <stdio.h>
#include "Graphique/libgraph.h"
#include <stdlib.h>
#include "liste.h"
#define TAILLE_X 700
#define TAILLE_DESC 40
#define LARGEUR_MONS 30
#define HAUTEUR_MONS 30
#define LARGEUR_VAIS 35
#define SPEED 1
#define MISS_SPEED 5
#define LARGEUR_MISS 5
#define HAUTEUR_MISS 10
l_entite* create_l_entite(int x,int y,int speed,int image)
{
l_entite* monster_1 =(l_entite*)malloc(sizeof(l_entite));
(monster_1->ent).image=image;
(monster_1->ent).x =x;
(monster_1->ent).y =y;
(monster_1->ent).speed=speed;
monster_1->next = NULL;
return monster_1;
}
entite create_entite(entite ent,int x,int y, int speed, int image)
{
(ent).image=image;
(ent).x =x;
(ent).y =y;
(ent).speed=speed;
return ent;
}
void add_entite (l_entite** head,int x,int y,int speed,int image)
{
l_entite* new_monster = create_l_entite( x, y,speed,image);
if (head==NULL)
{
*head=new_monster;
}
else
{
l_entite* current =*head;
while (current->next != NULL)
{ current=current->next;
}
current->next=new_monster;
}
}
void display_l_entite(l_entite* mons)
{
l_entite* ptr= mons;
while(ptr != NULL)
{
afficherLutin((ptr->ent).image,(ptr->ent).x,(ptr->ent).y);
ptr=ptr->next;
}
}
void display_entite(entite ent)
{
afficherLutin((ent).image,(ent).x,(ent).y);
}
void moveMonster(l_entite* monstre)
{
int max = TAILLE_X - LARGEUR_MONS;
l_entite* currentMonster = monstre;
while (currentMonster != NULL)
{
(currentMonster->ent).x += (currentMonster->ent).speed;
if ( (currentMonster->ent).x < 0 || (currentMonster->ent).x > max)
{
(currentMonster->ent).speed = -(currentMonster->ent).speed;
(currentMonster->ent).y += TAILLE_DESC ;
}
currentMonster = currentMonster->next;
}
}
void addMissile(l_entite** head, entite vaisseau,int image)
{
// int MI =chargerLutin("graphique/invader_missile.bmp", COULEUR_NOIR);
l_entite* newMissile = malloc(sizeof(l_entite));
(newMissile->ent).x = vaisseau.x + (LARGEUR_VAIS/2);
(newMissile->ent).y = (vaisseau).y - 5;
(newMissile->ent).speed = SPEED;
(newMissile->ent).image = image;
newMissile->next = *head;
*head = newMissile;
}
void moveMissile (l_entite* msl)
{
l_entite* currentMissile = msl;
while(currentMissile != NULL)
{
(currentMissile->ent).y = (currentMissile->ent).y - MISS_SPEED ;
currentMissile = currentMissile->next;
}
}
void remove_entite (l_entite** head, l_entite* to_delete)
{
l_entite* courant = *head;
while (courant != NULL)
{
if ((courant->ent).x == (to_delete->ent).x && (courant->ent).y == (to_delete->ent).y)
{
free(to_delete);
}
courant = courant->next;
}
}
void detecterCollisions(l_entite* l_missile, l_entite* l_monstre)
{
l_entite* missile_courant = l_missile;
l_entite* monstre_courant = l_monstre;
while (missile_courant != NULL)
{
while (monstre_courant != NULL)
{
if ( (monstre_courant->ent).x <= (missile_courant->ent).x && (missile_courant->ent).x <= (monstre_courant->ent).x + LARGEUR_MONS && (missile_courant->ent).y + HAUTEUR_MISS <= (monstre_courant->ent).y + HAUTEUR_MONS )
{
int B=lutinTexte("boom", COULEUR_BLEU);
afficherLutin(B,300,400);
remove_entite(&l_missile,missile_courant);
remove_entite(&l_monstre,monstre_courant);
(missile_courant->ent).image = 0;
(monstre_courant->ent).image = 0;
}
monstre_courant = monstre_courant->next;
}
missile_courant = missile_courant->next;
}
}
|