/
Wave.java
90 lines (72 loc) · 2.23 KB
/
Wave.java
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
package org.gdc.gdcalaga;
import java.util.*;
import org.newdawn.slick.Graphics;
public class Wave extends Entity {
private EnemyGroup group;
private String type;
private int xCols, yRows, curX, curY, totalEnemies, spawnedEnemies;
private float delay;
private Path path;
private float lastSpawn;
private ArrayList<Enemy> enemies;
public Wave(EntityManager manager, String waveType, int rows, int cols, int numEnemies, float spawnDelay, Path wavePath)
{
super(manager);
x = 800;
y = 50;
type = waveType;
yRows = rows;
xCols = cols;
delay = spawnDelay;
group = new EnemyGroup(manager, 100, x, y);
path = wavePath;
lastSpawn = 0;
enemies = new ArrayList<Enemy>();
if(type == "block"){
totalEnemies = xCols * yRows;
} else {
totalEnemies = numEnemies;
}
}
public void update(float delta)
{
lastSpawn += delta;
if(lastSpawn >= delay && spawnedEnemies < totalEnemies){
lastSpawn -= delay;
spawnEnemy();
}
for(int i = enemies.size() - 1; i >= 0; i--){
if(enemies.get(i).IsDying()) enemies.remove(i);
}
if(enemies.size() == 0 && spawnedEnemies >= totalEnemies){
group.Destroy();
Destroy();
}
}
public void draw(Graphics g)
{
}
public void Collide(Entity other)
{
}
private void spawnEnemy(){
if(type == "block"){
float newX = curX * 400 / xCols;
float newY = curY * 620 / yRows;
Enemy newEnemy = new Enemy(entities, newX, newY);
newEnemy.setGroup(group, newX, newY);
newEnemy.setPath(path.copy(x + newX, y + newY));
curY++;
if(curY >= yRows){
curY = 0;
curX++;
}
enemies.add(newEnemy);
} else if(type == "stream"){
Enemy newEnemy = new Enemy(entities, x, y);
newEnemy.setPath(path.copy(x, y));
enemies.add(newEnemy);
}
spawnedEnemies++;
}
}