-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththings.cpp
361 lines (317 loc) · 5.18 KB
/
things.cpp
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#include "things.h"
using namespace std;
/**
Constructor for the thing class
@param Pixmap pointer that will be used on the item to show the image. Nx is the x position. Ny is the y position
*/
Thing::Thing( QPixmap* p, int nx, int ny )
{
pixMap = p;
x = nx;
y = ny;
setPos( x, y );
}
/**
get the y position of the thing
@return the y position of the current thing
*/
int Thing::getY()
{
return y;
}
/**
get the x position of the thing
@return the x position of the current thing
*/
int Thing::getX()
{
return x;
}
/**
Constructor for the player class
@param Pixmap pointer that will be used on the item to show the image. Nx is the x position. Ny is the y position
@post: give the player 3hp
*/
Player::Player(QPixmap *pm, int nx, int ny): Thing(pm, nx, ny)
{
setPixmap(*pm);
hp_= 3;
}
/**
* removes one hp whenever the item is hit
*/
void Thing::isHit()
{
hp_--;
}
/**
* @return bool that tells the caller if the item is for or against the player
*/
bool Thing::isBad()
{
if(bad == 1)
{
return true;
}else{
return false;
}
}
/**
Constructor for the player class
@param Pixmap pointer that will be used on the item to show the image. Nx is the x position. Ny is the y position. Left tells the squid what side of the screen is should spawn
@post: give the squid 1hp, it is bad, not a power up
*/
Squid::Squid(QPixmap *pm, int nx, int ny, int left): Thing (pm, nx, ny)
{
setPixmap(*pm);
left_ = left;
hp_ = 1;
bad = 1;
powerUpNumberz = 0;
}
/**
* removes one HP off the squid
*/
void Squid::hit()
{
hp_ --;
}
/**
* moves the squid based on the side it is on
* */
void Squid::move()
{
if(left_ == 1)
{
moveBy(-1,1);
x--;
}else{
moveBy(1,1);
x++;
}
y++;
}
/**
* just moves the bomb directly down by two pixels per call
* */
void PlusBomb::move()
{
moveBy(0,2);
y = y + 2;
}
/**
* just moves the manta directly down by one pixel per call
* */
void Manta::move()
{
moveBy(0,1);
y = y + 1;
}
/**
* just moves the shark in a zig zag movement
* */
void Shark::move()
{
if(goingLeft < 30)
{
moveBy(2,2);
goingLeft ++;
}
if(goingLeft >= 30)
{
moveBy(-2,2);
goingLeft ++;
}
if (goingLeft == 60)
{
goingLeft = 0;
}
}
/**
* moves the player up by ten pixels if it is in the bounds
* */
void Player::moveUp()
{
if(y > -WINDOW_MAX_Y)
{
moveBy(0,-10);
y = y - 10;
}
}
/**
* moves the player down by ten pixels if it is in the bounds
* */
void Player::moveDown()
{
if(y < WINDOW_MAX_Y-65)
{
moveBy(0,10);
y = y + 10;
}
}
/**
* moves the player left by ten pixels if it is in the bounds
* */
void Player::moveLeft()
{
if(x > -WINDOW_MAX_X)
{
moveBy(-10,0);
x = x - 10;
}
}
/**
* moves the player right by ten pixels if it is in the bounds
* */
void Player::moveRight()
{
if(x < WINDOW_MAX_X - 100)
{
moveBy(10,0);
x = x + 10;
}
}
/**
* does nothing. I just had to satisfy the pure virtual function
* */
void Player::move()
{
}
/**
* @return the current HP of the thing
* */
int Thing::getHP()
{
return hp_;
}
/**
* @return the x position of the current item
* */
int Player::getX()
{
return x;
}
/**
* @return the Y position of the current item
* */
int Player::getY()
{
return y;
}
/**
* Constructor to make a bullet
* @post it is not bad, hp = 1, not a power up
* */
Lazer::Lazer (QPixmap *pm, int nx, int ny): Thing(pm,nx,ny)
{
setPixmap(*pm);
bad = 0;
hp_ = 1;
powerUpNumberz = 0;
}
/**
* Constructor to make a manta
* @post it is bad, hp = 10, not a power up
* */
Manta::Manta (QPixmap *pm, int nx, int ny): Thing(pm,nx,ny)
{
setPixmap(*pm);
bad = 1;
hp_ = 10;
powerUpNumberz = 0;
}
/**
* Constructor to make a manta
* @post it is bad, hp = 5, not a power up, not going left
* */
Shark::Shark (QPixmap *pm, int nx, int ny): Thing(pm,nx,ny)
{
setPixmap(*pm);
bad = 1;
hp_ = 5;
goingLeft = 0;
powerUpNumberz = 0;
}
/**
* @return the number of the power up
* */
int Thing::powerUpNumber()
{
return powerUpNumberz;
}
/**
* Constructor to make a plusbomb
* @post it is not bad, a power up, infinite HP
* */
PlusBomb::PlusBomb (QPixmap *pm, int nx, int ny): Thing(pm,nx,ny)
{
setPixmap(*pm);
bad = 0;
powerUpNumberz = 1;
hp_ = 10000;
}
/**
* Constructor to make a pluspoints
* @post it is not bad, hp = 10000, a power up
* */
PlusPoints::PlusPoints(QPixmap *pm, int nx, int ny): Thing(pm,nx,ny)
{
setPixmap(*pm);
bad = 0;
powerUpNumberz = 2;
hp_ = 10000;
}
/**
* Constructor to make a shield
* @post it is not bad, hp = 10000, a power up
* */
Shield::Shield(QPixmap *pm, int nx, int ny): Thing(pm,nx,ny)
{
setPixmap(*pm);
bad = 0;
powerUpNumberz = 3;
hp_ = 10000;
}
/**
* Moves the shield down by 5 pixels
* */
void Shield::move()
{
moveBy(0,5);
y = y + 5;
}
/**
* Constructor to make a better gun power up
* @post not bad, power up, hp = 10000
* */
BetterGun::BetterGun(QPixmap *pm, int nx, int ny): Thing(pm,nx,ny)
{
setPixmap(*pm);
bad = 0;
powerUpNumberz = 4;
hp_ = 10000;
}
/**
* move the better gun power up by 5 pixels
* */
void BetterGun::move()
{
moveBy(0,5);
y = y + 5;
}
/**
* move the plus points power up by pixels
* */
void PlusPoints::move()
{
moveBy(0,5);
y = y + 5;
}
/**
* move the lazer by 5 pixels
* */
void Lazer::move()
{
moveBy(0,-5);
y = y - 5;
}