-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgem.cpp
More file actions
42 lines (31 loc) · 639 Bytes
/
Copy pathgem.cpp
File metadata and controls
42 lines (31 loc) · 639 Bytes
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
#include "gem.h"
GEM::GEM() {
active = false;
}
void GEM::draw() {
if (active)
draw_sprite(buffer, (BITMAP*)gem_data[type].dat, (int)x, (int)y);
}
void GEM::launch(float X, float Y) {
type = rand() % 3;
x = X + rand() % CHICKEN_WIDTH;
y = Y + rand() % CHICKEN_HEIGHT/2;
x_vel = rand() % 6 - rand() % 6;
y_vel = -(rand() % 5) - 12;
active = true;
}
int GEM::run() {
if (active) {
y_vel += GRAVITY/2;
x += x_vel;
y += y_vel;
if (mouse_x > x - 10 && mouse_x < x + 20)
if (mouse_y > y - 10 && mouse_y < y + 18) {
active = false;
return 1;
}
if (y > SCREEN_H)
active = false;
}
return 0;
}