-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds LevelWaves class, which can store and spawn waves
- Loading branch information
Showing
6 changed files
with
87 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"1": [ | ||
{"Xeno": 5} | ||
], | ||
"2": [ | ||
{"Xeno": 7} | ||
], | ||
"3" : [ | ||
{"Xeno": 4} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
source/core/src/main/com/csse3200/game/components/tasks/waves/LevelWaves.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.csse3200.game.components.tasks.waves; | ||
|
||
import com.badlogic.gdx.math.GridPoint2; | ||
import com.csse3200.game.entities.Entity; | ||
import com.csse3200.game.services.GameTime; | ||
import com.csse3200.game.services.ServiceLocator; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class LevelWaves extends Entity { | ||
List<WaveClass> waves = new ArrayList<>(); | ||
private float spawnDelay; | ||
private GameTime gameTime; | ||
private long startTime; | ||
private Random rand = new Random(); | ||
private int currentRandom = 0; | ||
private int previousRandom = 0; | ||
private int mobIndex; | ||
private int waveIndex; | ||
|
||
public LevelWaves(int spawnDelay) { | ||
this.spawnDelay = spawnDelay; | ||
this.gameTime = ServiceLocator.getTimeSource(); | ||
this.startTime = this.gameTime.getTime(); | ||
this.mobIndex = 0; | ||
this.waveIndex = 0; | ||
} | ||
|
||
public void addWave(WaveClass wave) { | ||
this.waves.add(wave); | ||
} | ||
|
||
public WaveClass getWave(int index) { | ||
return this.waves.get(index); | ||
} | ||
|
||
public void spawnWave() { | ||
if (gameTime.getTime() >= startTime + spawnDelay * 1000) { | ||
do { | ||
currentRandom = rand.nextInt(1, 7); | ||
} while (currentRandom == previousRandom); | ||
previousRandom = currentRandom; | ||
GridPoint2 randomPos = new GridPoint2(19, currentRandom); | ||
this.getEvents().trigger("spawnWave", waves.get(waveIndex) | ||
.getMobs().get(mobIndex), randomPos); | ||
startTime = gameTime.getTime(); | ||
mobIndex++; | ||
previousRandom = currentRandom; | ||
} else if (mobIndex == waves.get(waveIndex).getSize()) { | ||
this.getEvents().trigger("waveFinishedSpawning"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters