-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spawner.java
165 lines (146 loc) · 3.78 KB
/
Spawner.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
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
import java.util.ArrayList;
/**
Handles all spawning
@author Kush Banker and Jack Basinet
@version 11.18.19
*/
class Spawner
{
public static final int WINDOW_WIDTH = 800;
public static final int WINDOW_HEIGHT = 600;
public static final int MINI_SPAWN_RATE_WAVE_MS = 300;
private int alien_spawn_rate_ms;
private int twin_spawn_rate_ms;
private int cannon_spawn_rate_ms;
private int mini_spawn_rate_ms;
private int hearty_spawn_rate_ms;
private int spike_spawn_rate_ms;
private int tank_spawn_rate_ms;
private int minisPerWave;
private int alienTimer;
private int twinTimer;
private int cannonTimer;
private int miniTimer;
private int heartyTimer;
private int spikeTimer;
private int tankTimer;
private boolean miniWave;
private int miniWaveCt;
private int miniWaveX;
private int timer;
private ArrayList<Enemy> enemiesToSpawn;
public Spawner()
{
alien_spawn_rate_ms = 2000;
twin_spawn_rate_ms = 3000;
cannon_spawn_rate_ms = 7000;
mini_spawn_rate_ms = 9500;
hearty_spawn_rate_ms = 10000;
spike_spawn_rate_ms = 10000;
tank_spawn_rate_ms = 11000;
timer = 0;
alienTimer = 0;
twinTimer = 0;
cannonTimer = 0;
miniTimer = 0;
heartyTimer = 0;
spikeTimer = 0;
enemiesToSpawn = new ArrayList<Enemy>();
}
/**
THE MOST IMPORTANT METHOD OF THEM ALL
@param ms Milliseconds
*/
public void tick(int ms)
{
timer += ms;
alienTimer += ms;
if(timer >= 25000) { twinTimer += ms; }
if(timer >= 55000) { cannonTimer += ms; }
if(timer >= 60000)
{
int ifHeart = (int)(Math.random()*3);
if(ifHeart == 2) { heartyTimer += ms; }
}
if(timer >= 90000)
{
miniTimer += ms;
alien_spawn_rate_ms = 2800;
twin_spawn_rate_ms = 3200;
}
if(timer >= 130000) { spikeTimer += ms; }
if(timer >= 150000) { tankTimer += ms; }
if(timer == 180000) { this.harder(); }
if(timer == 220000) { this.harder(); }
if(timer == 240000) { this.harder(); }
//System.out.println(timer);
}
public void harder()
{
alien_spawn_rate_ms -= 200;
twin_spawn_rate_ms -= 200;
cannon_spawn_rate_ms -= 200;
mini_spawn_rate_ms -= 200;
hearty_spawn_rate_ms -= 200;
spike_spawn_rate_ms -= 200;
tank_spawn_rate_ms -= 200;
}
public ArrayList<Enemy> spawn()
{
enemiesToSpawn = new ArrayList<Enemy>();
//Alien
if(alienTimer >= alien_spawn_rate_ms)
{
enemiesToSpawn.add(new Alien((int) (Math.random()*(WINDOW_WIDTH-120) + 60), 0));
alienTimer = 0;
}
// Twin
if(twinTimer >= twin_spawn_rate_ms)
{
enemiesToSpawn.add(new Twin((int) (Math.random()*(WINDOW_WIDTH-120) + 60), 0));
twinTimer = 0;
}
// Cannon
if(cannonTimer >= cannon_spawn_rate_ms)
{
enemiesToSpawn.add(new Cannon((int) (Math.random()*(WINDOW_WIDTH-120) + 60), 0));
cannonTimer = 0;
}
// Mini
if(miniWave)
{
if(miniWaveCt >= minisPerWave)
{
miniWave = false;
}
else if(miniTimer >= MINI_SPAWN_RATE_WAVE_MS)
{
enemiesToSpawn.add(new Mini(miniWaveX, 0));
miniTimer = 0;
miniWave = true;
miniWaveCt++;
}
}
else if(miniTimer >= mini_spawn_rate_ms)
{
miniTimer = 0;
miniWave = true;
miniWaveCt = 0;
minisPerWave = (int) (Math.random() * 4 + 2);
miniWaveX = (int) (Math.random()*(WINDOW_WIDTH-120) + 60);
}
//HEARTY
if(heartyTimer >= hearty_spawn_rate_ms)
{
enemiesToSpawn.add(new Hearty((int) (Math.random()*(WINDOW_WIDTH-120) + 60), 0));
heartyTimer = 0;
}
//Spike
if(spikeTimer >= spike_spawn_rate_ms)
{
enemiesToSpawn.add(new Spike((int) (Math.random()*(WINDOW_WIDTH-120) + 60), 0));
spikeTimer = 0;
}
return enemiesToSpawn;
}
}