-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathEnemy.pde
59 lines (47 loc) · 1.1 KB
/
Enemy.pde
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
abstract class Enemy extends GameObject {
Enemy() {
x_pos = 1350;
}
void update(int speed) {
x_pos -= speed;
}
boolean is_offscreen() {
return x_pos + obj_width < 0;
}
}
class Cactus extends Enemy {
int type;
int[] cactus_widths = {30, 64, 98, 46, 96, 146};
int[] cactus_heights = {66, 66, 66, 96, 96, 96};
int[] cactus_y_pos = {470, 470, 470, 444, 444, 444};
Cactus() {
type = (int)random(6);
obj_width = cactus_widths[type];
obj_height = cactus_heights[type];
y_pos = cactus_y_pos[type];
sprite = "cactus_type_" + (type + 1);
sprite_offset[0] = -2;
sprite_offset[1] = -2;
}
}
class Bird extends Enemy {
int type;
int[] birds_y_pos = {435, 480, 370};
Bird() {
x_pos = 1350;
obj_width = 84;
obj_height = 40;
type = (int)random(3);
y_pos = birds_y_pos[type];
sprite = "bird_flying_1";
sprite_offset[0] = -4;
sprite_offset[1] = -16;
}
void toggle_sprite() {
if (sprite.equals("bird_flying_1")) {
sprite = "bird_flying_2";
} else {
sprite = "bird_flying_1";
}
}
}