-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorld.java
More file actions
152 lines (130 loc) · 2.99 KB
/
World.java
File metadata and controls
152 lines (130 loc) · 2.99 KB
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
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.List;
public class World {
private final Assign9 main;
private final Player player;
private static final List<Entity> entities = new ArrayList<Entity>();
public static int enemyCount = 0;
private boolean newWave = false;
private int wave = 0;
public World(Assign9 main) {
this.main = main;
this.player = new Player(main);
this.newWave = true;
}
public void tick(final Graphics2D g) {
if (main.isGameOver()) {
return;
}
if (newWave) {
enemyCount = 0;
entities.clear();
if (wave < 5) {
wave ++;
}
createInitSpawn(g, true);
newWave = false;
}
player.draw(g);
player.update(g);
for (Entity e : entities) {
if (e != null) {
if (e instanceof DefaultNPC) {
final DefaultNPC npc = (DefaultNPC) e;
npc.draw(g);
npc.update(g);
}
if (e instanceof BossNPC) {
final BossNPC npc = (BossNPC) e;
npc.draw(g);
npc.update(g);
}
if (player.collidesWithSprite(e)) {
player.onCollision(e);
if (e instanceof Collidable) {
((Collidable) e).onCollision(player);
}
}
}
}
if (enemyCount <= 0) {
newWave = true;
}
}
private void createInitSpawn(Graphics2D g, boolean update) {
if (wave == 1) {
for (int y = 64; y < 385; y += 64) {
createNPC(720, y, g, update);
enemyCount ++;
}
} else if (wave == 2) {
for (int y = 64; y < 385; y += 64) {
createNPC(620, y, g, update);
enemyCount ++;
}
for (int y = 64; y < 385; y += 64) {
createNPC(720, y, g, update);
enemyCount ++;
}
} else if (wave == 3) {
for (int y = 64; y < 385; y += 64) {
createNPC(520, y, g, update);
enemyCount ++;
}
for (int y = 64; y < 385; y += 64) {
createNPC(620, y, g, update);
enemyCount ++;
}
for (int y = 64; y < 385; y += 64) {
createNPC(720, y, g, update);
enemyCount ++;
}
} else if (wave == 4) {
for (int y = 64; y < 385; y += 64) {
createNPC(520, y, g, update);
enemyCount ++;
}
for (int y = 64; y < 385; y += 64) {
createNPC(620, y, g, update);
enemyCount ++;
}
for (int y = 64; y < 385; y += 64) {
createNPC(720, y, g, update);
enemyCount ++;
}
createBoss(740, 100, g, update);
enemyCount ++;
createBoss(740, 200, g, update);
enemyCount ++;
createBoss(740, 300, g, update);
enemyCount ++;
}
}
public void createNPC(int x, int y, Graphics2D g, boolean update) {
DefaultNPC npc = new DefaultNPC(main, new Position(x, y));
npc.draw(g);
if (update) {
entities.add(npc);
}
}
public void createBoss(int x, int y, Graphics2D g, boolean update) {
BossNPC npc = new BossNPC(main, new Position(x, y));
npc.draw(g);
if (update) {
entities.add(npc);
}
}
public static List<Entity> getEntities() {
return entities;
}
public Player getPlayer() {
return player;
}
public int getWave() {
return wave;
}
public void setWave(int wave) {
this.wave = wave;
}
}