This commit is contained in:
ramapcsx2 2014-12-09 11:16:34 +01:00
commit be8f7a231f

View File

@ -84,37 +84,40 @@ public final class Level {
public void handleUpdateTick() { public void handleUpdateTick() {
//Check whether the current interval is configured //Check whether the current interval is configured
int currentIntervalIndex = this.config.getIntervalIndexByCurrentTime(this.levelClock); int currentIntervalIndex = this.config.getIntervalIndexByCurrentTime(this.levelClock);
if(currentIntervalIndex == -1) return; //Nothing to do
//Fetch the current interval //If there are still configured intervals, take care of the rules
int[] currentInterval = this.config.intervalList.get(currentIntervalIndex); if(currentIntervalIndex != -1) {
int relativeTimeWithinCurrentInterval = this.levelClock - currentInterval[0]; //Fetch the current interval
int intervalLength = currentInterval[1] - currentInterval[0]; int[] currentInterval = this.config.intervalList.get(currentIntervalIndex);
/* int relativeTimeWithinCurrentInterval = this.levelClock - currentInterval[0];
* @see <LevelConfig> int intervalLength = currentInterval[1] - currentInterval[0];
* Get all the spawnrules for the current interval. /*
* - 0: Interval this rule belongs to * @see <LevelConfig>
* - 1: EntityNumber - This helps to find out what Entity to actually spawn. * Get all the spawnrules for the current interval.
* - 2: Amount - The amount of Entities to spawn at a time. * - 0: Interval this rule belongs to
* - 3: SpawnRate - The rate at which the Entities are supposed to be spawned. * - 1: EntityNumber - This helps to find out what Entity to actually spawn.
* - 4: SpawnPosition - percentage of GameConfig.windowHeight - Where the Enemy shall spawn. * - 2: Amount - The amount of Entities to spawn at a time.
*/ * - 3: SpawnRate - The rate at which the Entities are supposed to be spawned.
for(int[] spawnRule : this.config.spawnRuleList) { * - 4: SpawnPosition - percentage of GameConfig.windowHeight - Where the Enemy shall spawn.
//Skip spawn rules that are not in the current spawn interval. */
if(spawnRule[0] != currentIntervalIndex) continue; for(int[] spawnRule : this.config.spawnRuleList) {
//Divide the current interval by spawnrate //Skip spawn rules that are not in the current spawn interval.
int intervalModulus = intervalLength / spawnRule[3]; if(spawnRule[0] != currentIntervalIndex) continue;
//Check whether the spawn rate strikes right now. //Divide the current interval by spawnrate
if(relativeTimeWithinCurrentInterval % Math.max(1,intervalModulus) == 0) { int intervalModulus = intervalLength / spawnRule[3];
//If the rule matches the current time, spawn the configured Entity in the configured amount: //Check whether the spawn rate strikes right now.
for(int i=0; i<spawnRule[2]; i++) { if(relativeTimeWithinCurrentInterval % Math.max(1,intervalModulus) == 0) {
//Minus one because the upper border is _excluded_ from the range! //If the rule matches the current time, spawn the configured Entity in the configured amount:
int x = GameConfig.gameScreenWidth + GameConfig.gameScreenXOffset - 1; for(int i=0; i<spawnRule[2]; i++) {
//Minus one because the upper border is _excluded_ from the range! //Minus one because the upper border is _excluded_ from the range!
int y = Math.round((GameConfig.gameScreenHeight * spawnRule[4]) / 100) + GameConfig.gameScreenYOffset - 1; int x = GameConfig.gameScreenWidth + GameConfig.gameScreenXOffset - 1;
this.spawnEntityByAvailableName(Entity.availableNames.values()[spawnRule[1]], x, y); //Minus one because the upper border is _excluded_ from the range!
int y = Math.round((GameConfig.gameScreenHeight * spawnRule[4]) / 100) + GameConfig.gameScreenYOffset - 1;
this.spawnEntityByAvailableName(Entity.availableNames.values()[spawnRule[1]], x, y);
}
} }
} }
} } //end if still intervals configured
//Check for GameOver things. //Check for GameOver things.
this.checkGameOverCondition(); this.checkGameOverCondition();