forked from kevin890703/assign6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enemy.pde
105 lines (95 loc) · 1.85 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
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
class Enemy{
int x = 0;
int y = 0;
int type;
int speed = 5;
PImage enemyImg;
Enemy(int x, int y, int type) {
this.x = x;
this.y = y;
this.type = type;
enemyImg = loadImage("img/enemy.png");
}
void move() {
this.x+= 5;
}
void draw()
{
image(enemyImg, x, y);
}
boolean isCollideWithFighter()
{
return false;
}
boolean isOutOfBorder()
{
return false;
}
}
void addEnemy(int type)
{
for (int i = 0; i < enemyCount; ++i) {
enemys[i] = null;
}
switch (type) {
case EnemysShowingType.STRAIGHT:
addStraightEnemy();
break;
case EnemysShowingType.SLOPE:
addSlopeEnemy();
break;
case EnemysShowingType.DIAMOND:
addDiamondEnemy();
break;
case EnemysShowingType.STRONGLINE:
addEnemyStrong();
break;
}
time = millis();
}
void addStraightEnemy()
{
float t = random(height - 60);
int h = int(t);
for (int i = 0; i < 5; ++i) {
enemys[i] = new Enemy( (i+1)*-80, h , FlightType.ENEMY);
}
}
void addSlopeEnemy()
{
float t = random(height - 60 * 5);
int h = int(t);
for (int i = 0; i < 5; ++i) {
enemys[i] = new Enemy((i+1)*-80, h + i * 50 , FlightType.ENEMY);
}
}
void addDiamondEnemy()
{
float t = random( 60 * 3 ,height - 60 * 3);
int h = int(t);
int x_axis = 1;
for (int i = 0; i < 8; ++i) {
if (i == 0 || i == 7) {
enemys[i] = new Enemy((x_axis+1)*-80, h, FlightType.ENEMY);
x_axis++;
}
else if (i == 1 || i == 5){
enemys[i] = new Enemy((x_axis+1)*-80, h + 1 * 40, FlightType.ENEMY);
enemys[i+1] = new Enemy((x_axis+1)*-80, h - 1 * 40, FlightType.ENEMY);
i++;
x_axis++;
}
else {
enemys[i] = new Enemy((x_axis+1)*-80, h + 2 * 40, FlightType.ENEMY);
enemys[i+1] = new Enemy((x_axis+1)*-80, h - 2 * 40, FlightType.ENEMY);
i++;
x_axis++;
}
}
}
void addEnemyStrong()
{
for (int i = 0; i < 5; ++i) {
enemys[i] = new Enemy(0, 40+ i * 85, FlightType.ENEMYSTRONG);
}
}