-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevel.java
More file actions
328 lines (224 loc) · 7.13 KB
/
Level.java
File metadata and controls
328 lines (224 loc) · 7.13 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
package com.udacity.gamedev.donkeykong;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.DelayedRemovalArray;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.udacity.gamedev.donkeykong.entities.Barrel;
import com.udacity.gamedev.donkeykong.entities.DonkeyKong;
import com.udacity.gamedev.donkeykong.entities.Door;
import com.udacity.gamedev.donkeykong.entities.Enemy;
import com.udacity.gamedev.donkeykong.entities.Fire;
import com.udacity.gamedev.donkeykong.entities.Floor;
import com.udacity.gamedev.donkeykong.entities.Ladder;
import com.udacity.gamedev.donkeykong.entities.Life;
import com.udacity.gamedev.donkeykong.entities.OilBarrel;
import com.udacity.gamedev.donkeykong.entities.Peach;
import com.udacity.gamedev.donkeykong.entities.Wall;
import com.udacity.gamedev.donkeykong.util.Constants;
import com.udacity.gamedev.donkeykong.util.Enums.Direction;
public class Level {
private Viewport viewport;
private Peach peach;
private Array<Floor> floors;
private Array<Ladder> ladders;
private DelayedRemovalArray<DonkeyKong> kong;
private DelayedRemovalArray<Barrel> barrels;
private Array<Wall> walls;
private Array<OilBarrel> oilBarrels;
private DelayedRemovalArray<Enemy> enemies;
private DelayedRemovalArray<Fire> fires;
private Array<Door> doors;
private DelayedRemovalArray<Life> lives;
private boolean gameOver;
private boolean nextLevel;
private int contNivel = 0;
public Level(Viewport viewport) {
this.viewport = viewport;
peach = new Peach(Constants.DEFAULT_SPAWN_LOCATION, this);
floors = new Array<Floor>();
ladders = new Array<Ladder>();
barrels = new DelayedRemovalArray<Barrel>();
kong = new DelayedRemovalArray<DonkeyKong>();
walls = new Array<Wall>();
oilBarrels = new Array<OilBarrel>();
enemies = new DelayedRemovalArray<Enemy>();
fires = new DelayedRemovalArray<Fire>();
doors = new Array<Door>();
lives = new DelayedRemovalArray<Life>();
gameOver = false;
nextLevel = false;
//initDebugLevel();
}
public Peach getPeach() {
return peach;
}
public void setPeach(Peach peach) {
this.peach = peach;
}
public DelayedRemovalArray<DonkeyKong> getKong() {
return kong;
}
public Viewport getViewport() {
return viewport;
}
public DelayedRemovalArray<Barrel> getBarrels() {
return barrels;
}
public Array<Ladder> getLadders() {
return ladders;
}
public Array<Floor> getFloors() {
return floors;
}
public Array<Wall> getWalls() {
return walls;
}
public Array<OilBarrel> getOilBarrels() {
return oilBarrels;
}
public DelayedRemovalArray<Enemy> getEnemies() {
return enemies;
}
public DelayedRemovalArray<Fire> getFires() {
return fires;
}
public Array<Door> getDoors() {
return doors;
}
public DelayedRemovalArray<Life> getLives() {
return lives;
}
public boolean isGameOver() {
return gameOver;
}
public boolean isNextLevel() {
return nextLevel;
}
public int getContNivel() {
return contNivel;
}
public void setContNivel(int contNivel) {
this.contNivel = contNivel;
}
public void update(float delta) {
if(peach.getLives() <= 0){
gameOver = true;
}
//peach
peach.update(delta, floors);
for(DonkeyKong donkeyKong : kong){
if(donkeyKong.getLifes() == 0){
nextLevel = true;
}
}
//kong
kong.begin();
for(int i = 0; i < kong.size; i++) {
kong.get(i).update(delta);
if(kong.get(i).getLifes() <= 0){
kong.removeIndex(i);
}
}
kong.end();
//barrels
barrels.begin();
for (Barrel barrel : barrels) {
barrel.update(delta);
if (!barrel.active) {
barrels.removeValue(barrel, false);
}
}
barrels.end();
//OilBarrels
for (OilBarrel oilBarrel : oilBarrels) {
oilBarrel.update(delta);
}
//enemies
enemies.begin();
for (Enemy enemy : enemies) {
enemy.update(delta);
if (!enemy.isActive()) {
enemies.removeValue(enemy, false);
}
}
enemies.end();
//Fire
fires.begin();
for (Fire fire : fires) {
fire.update(delta);
if (!fire.isActive()) {
fires.removeValue(fire, false);
}
}
fires.end();
//Doors
for (Door door : doors) {
door.update(delta);
}
//Lives
for (Life life : lives) {
life.update(delta);
}
}
public void render(SpriteBatch batch) {
for (Floor floor : floors) {
floor.render(batch);
}
for (DonkeyKong donkeyKong : kong) {
donkeyKong.render(batch);
}
peach.render(batch);
for (Barrel barrel : barrels) {
barrel.render(batch);
}
for(Ladder ladder : ladders){
ladder.render(batch);
}
for (Wall wall : walls) {
wall.render(batch);
}
for (OilBarrel oilBarrel : oilBarrels) {
oilBarrel.render(batch);
}
for (Enemy enemy : enemies) {
enemy.render(batch);
}
for (Fire fire : fires) {
fire.render(batch);
}
for (Door door : doors) {
door.render(batch);
}
for (Life life : lives) {
life.render(batch);
}
}
private void initDebugLevel() {
peach = new Peach(new Vector2(20, 60), this);
floors = new Array<Floor>();
ladders = new Array<Ladder>();
barrels = new DelayedRemovalArray<Barrel>();
Floor kongFloor = new Floor(121, 50, 70, 20);
kong = new DelayedRemovalArray<DonkeyKong>();
floors.add(new Floor(0, 25, 30, 20));
floors.add(new Floor(27, 25, 50, 20));
floors.add(new Floor(74, 25, 50, 20));
floors.add(new Floor(121, 25, 20, 20));
floors.add(new Floor(138, 25, 40, 20));
floors.add(new Floor(175, 25, 40, 20));
floors.add(new Floor(210, 25, 30, 20));
floors.add(kongFloor);
ladders.add(new Ladder(30, 70, new Vector2(35, 20)));
}
public void spawnBarrel(Vector2 position, Direction direction) {
barrels.add(new Barrel(this, position, direction));
}
public void spawnEnemy(Vector2 position, Direction direction){
enemies.add(new Enemy(this, direction, new Vector2(position.x, position.y+10)));
}
public void spawnFire(Vector2 position, Direction direction) {
fires.add(new Fire(position, direction, this));
}
}