-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjets.cpp
More file actions
202 lines (175 loc) · 3.75 KB
/
objets.cpp
File metadata and controls
202 lines (175 loc) · 3.75 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "objets.h"
#include "constantes.h"
#include <math.h>
#include <random>
//---------------------PARTIE---------------------//
Partie::Partie()
{
type_scrolling = 0;
Timer = 0;
nbr_obstacle = 1;
}
int Partie::get_scrolling_type() const
{
return type_scrolling;
}
void Partie::update_scrolling(int type)
{
type_scrolling = type;
if(type == 0 or type == 1)
{
nbr_obstacle = 1;
}
if(type == 2 or type == 3)
{
nbr_obstacle = 9;
}
if(type == 4)
{
nbr_obstacle = 1;
}
}
int Partie::get_nbr_obstacle() const
{
return nbr_obstacle;
}
void Partie::init(Obstacle* obstacle) const
{
for(int i = 0; i < nbr_obstacle;i++)
{
obstacle[i].init(type_scrolling);
}
}
//---------------------OBSTACLE ET BONUS---------------------//
Obstacle::Obstacle()
{
srand((unsigned int) time(0));
size = Coord(35,40 + rand()%200);
clr = BLACK;
crds = Coord(w,floor_level - size.y());
type = 0;
is_visible = true;
}
void Obstacle::draw(const Img & shield_bonus,Img light_bonus[2],Img heart_bonus[2], int timer) const
{
if(type == 0)
{
fillRect(crds.x(),crds.y(),size.x(),size.y(),clr);
}
else if(type == 1)
{
draw_bonus(bonus_type,shield_bonus,light_bonus,heart_bonus,crds,is_visible,timer);
}
}
void Obstacle::move(int scrollingType)
{
if(scrollingType == 0 or scrollingType == 1 or scrollingType == 4)
{
crds.x() = crds.x() - speed;//Gauche ou Droite
}
if(scrollingType == 2 or scrollingType == 3)
{
crds.y() = crds.y() - speed;//Gauche ou Droite
}
}
int Obstacle::isFlying() const
{
return flying;
}
bool Obstacle::outOfBounds() const
{
if(crds.x()> w or crds.x() < -size.x() or crds.y() < -size.y() or crds.y() > h)
{
return true;
}
else
{
return false;
}
}
void Obstacle::init(int scrollingType)
{
alreadyHit = false;
flying = 0;
clr = BLACK;
setType(0);
is_visible = true;
if(scrollingType == 0)
{
//Obstacles viennent de la droite
flying = rand()%2; // Volant ou non
speed = abs(speed)*1;
size = Coord(35,40 + rand()%50);
crds = Coord(w,floor_level - size.y());
if(flying == 0)
{
size = Coord(60,20);
crds.y() = floor_level - size.y() - size_y/2-rand()%30 ;
}
}
if(scrollingType == 1)
{
//Obstacles viennent de la gauche
flying = rand()%2; // Volant ou non
speed = - abs(speed)*1;
size = Coord(35,40 + rand()%50);
crds = Coord(0,floor_level - size.y());
if(flying == 0)
{
size = Coord(60,20);
crds.y() = floor_level - size.y() - size_y/2 -rand()%30;
}
}
if(scrollingType == 2)
{
//Obstacles viennent du haut
speed = - abs(speed)*1;
size = Coord(35 + rand()%70,35);
crds = Coord(rand()%w,0);
}
if(scrollingType == 3)
{
//Obstacles viennent du bas
speed = abs(speed)*1;
size = Coord(35 + rand()%70,35);
crds = Coord(rand()%w,h);
}
if(scrollingType == 4)
{
//Bonus
speed = abs(speed)*1;
size = Coord(40,40);
crds = Coord(w,h/2);
clr = RED;
setType(1);
setBonusType(rand()%3 + 1);
}
}
int Obstacle::getBonusType() const
{
return bonus_type;
}
void Obstacle::setBonusType(int new_type)
{
bonus_type= new_type;
}
Coord Obstacle::getSize() const
{
return size;
}
Coord Obstacle::getCoord() const
{
return crds;
}
int Obstacle::getType() const
{
return type;
}
void Obstacle::setType(int new_type)
{
type = new_type;
}
void Obstacle::set_visibility(bool visible)
{
is_visible = false;
}