Add positional parameter to LevelConfig.

This commit is contained in:
Jan Philipp Timme 2014-12-02 12:29:03 +01:00
parent eeb2a9c875
commit 1c80a8745a
6 changed files with 71 additions and 21 deletions

View File

@ -3,13 +3,25 @@ name:Testlevel \o/
backgroundMusic:music/ScooterFriendsTurbo8Bit.wav
background:CloudBackground
-
[0-4]
spawn:EnemyOne,1,5
spawn:StoneOne,4,5
[0-2]
spawn:StoneOne,2,1,0
spawn:StoneOne,2,1,10
spawn:StoneOne,2,1,20
spawn:StoneOne,2,1,30
spawn:StoneOne,2,1,40
spawn:EnemyOne,2,1,50
spawn:StoneOne,2,1,60
spawn:StoneOne,2,1,70
spawn:StoneOne,2,1,80
spawn:StoneOne,2,1,90
spawn:StoneOne,2,1,100
[2-4]
spawn:EnemyOne,1,5,20
spawn:StoneOne,4,5,50
[4-10]
spawn:EnemyTwo,1,10
spawn:EnemyTwo,1,10,60
[10-25]
spawn:EnemyThree,2,4
spawn:EnemyTwo,5,6
spawn:EnemyThree,2,4,33
spawn:EnemyTwo,5,6,10
[25-30]
spawn:EnemyBoss,1,1
spawn:EnemyBoss,1,1,100

View File

@ -8,7 +8,7 @@ public class GameConfig {
/**
* Whether debug output (and more) is enabled or disabled.
*/
public static boolean DEBUG = false;
public static final boolean DEBUG = false;
/**
* Width of GameWindow.

View File

@ -20,6 +20,7 @@ public class EnemyOne extends Enemy {
@Override
public void update() {
super.update();
this.transpose(-1, 0);
}
@Override

View File

@ -14,7 +14,6 @@ import de.teamteamteam.spacescooter.entity.obstacle.StoneOne;
import de.teamteamteam.spacescooter.screen.GameScreen;
import de.teamteamteam.spacescooter.sound.SoundSystem;
import de.teamteamteam.spacescooter.utility.Loader;
import de.teamteamteam.spacescooter.utility.Random;
/**
* Implementation of the actual level based gameplay logic.
@ -53,6 +52,26 @@ public final class Level {
*/
private int gameOverDelay;
/**
* Offset for game screen 0 coordinate on X axis.
*/
private int gameScreenXOffset;
/**
* Offset for game screen 0 coordinate on Y axis.
*/
private int gameScreenYOffset;
/**
* Actual width of game screen.
*/
private int gameScreenWidth;
/**
* Actual height of game screen.
*/
private int gameScreenHeight;
/**
* Constructor creating a LevelConfig based on a given config file.
*/
@ -61,6 +80,12 @@ public final class Level {
this.isGameOver = false;
this.gameOverDelay = 3;
this.config = Loader.getLevelConfigByFilename(levelConfig);
//TODO: Put this into the GameConfig!
this.gameScreenXOffset = 0;
this.gameScreenYOffset = 50;
this.gameScreenWidth = GameConfig.windowWidth - 1; //This is fine.
this.gameScreenHeight = GameConfig.windowHeight - 51; //TODO: NOT HARDCODE THIS :/
}
@ -95,19 +120,20 @@ public final class Level {
* - 1: EntityNumber - This helps to find out what Entity to actually 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.
* - 4: SpawnPosition - percentage of GameConfig.windowHeight - Where the Enemy shall spawn.
*/
for(int[] spawnrule : this.config.spawnRuleList) {
for(int[] spawnRule : this.config.spawnRuleList) {
//Skip spawn rules that are not in the current spawn interval.
if(spawnrule[0] != currentIntervalIndex) continue;
if(spawnRule[0] != currentIntervalIndex) continue;
//Divide the current interval by spawnrate
int intervalModulus = intervalLength / spawnrule[3];
int intervalModulus = intervalLength / spawnRule[3];
//Check whether the spawn rate strikes right now.
if(relativeTimeWithinCurrentInterval % Math.max(1,intervalModulus) == 0) {
//If the rule matches the current time, spawn the configured Entity in the configured amount:
for(int i=0; i<spawnrule[2]; i++) {
//TODO: More beautiful positions!
//ToDo: X is GameConfig.windowWidth - somePixels, should be the whole width (for enemies coming into the screen from the right).
this.spawnEntityByAvailableName(Entity.availableNames.values()[spawnrule[1]], GameConfig.windowWidth - 50, Random.nextInt(GameConfig.windowHeight -50)+50);
for(int i=0; i<spawnRule[2]; i++) {
int x = this.gameScreenWidth + this.gameScreenXOffset - 1;
int y = Math.round((this.gameScreenHeight * spawnRule[4]) / 100) + this.gameScreenYOffset - 1;
this.spawnEntityByAvailableName(Entity.availableNames.values()[spawnRule[1]], x, y);
}
}
}

View File

@ -43,6 +43,7 @@ public class LevelConfig {
* - 1: EntityNumber - This helps to find out what Entity to actually 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.
* - 4: SpawnPosition - percentage of GameConfig.windowHeight - Where the Enemy shall spawn.
*/
public List<int[]> spawnRuleList;
@ -119,13 +120,16 @@ public class LevelConfig {
/**
* Add a given EntitySpawnRule to the ruleList.
*/
public void addEntitySpawnRule(int intervalStart, int intervalEnd, String entityName, int amount, int spawnRate) {
public void addEntitySpawnRule(int intervalStart, int intervalEnd, String entityName, int amount, int spawnRate, int spawnPositionPercentage) {
int intervalIndex = this.getIntervalIndexByBorders(intervalStart, intervalEnd);
if(intervalIndex == -1) {
throw new LevelConfigException("No Interval for rule found!\nRule: " + intervalStart + " to " + intervalEnd + ": " + entityName + ", " + amount + ", " + spawnRate);
throw new LevelConfigException("No Interval for rule found!\nRule: " + intervalStart + " to " + intervalEnd + ": " + entityName + ", " + amount + ", " + spawnRate + ", " + spawnPositionPercentage);
} else {
int enemyNumber = Entity.availableNames.valueOf(entityName).ordinal();
int[] newRule = {intervalIndex, enemyNumber, amount, spawnRate};
if(spawnPositionPercentage < 0 || spawnPositionPercentage > 100) {
throw new LevelConfigException("Invalid spawnPosition percentage!\nRule: " + intervalStart + " to " + intervalEnd + ": " + entityName + ", " + amount + ", " + spawnRate + ", " + spawnPositionPercentage);
}
int[] newRule = {intervalIndex, enemyNumber, amount, spawnRate, spawnPositionPercentage};
this.spawnRuleList.add(newRule);
}
}

View File

@ -86,8 +86,15 @@ public class LevelConfigParser {
} else {
String[] rule = line.split(":", 2);
if(rule[0].equals("spawn")) {
String[] entitySpawnRule = rule[1].split(",", 3);
this.levelConfig.addEntitySpawnRule(this.currentIntervalStart, this.currentIntervalEnd, entitySpawnRule[0], Integer.parseInt(entitySpawnRule[1]), Integer.parseInt(entitySpawnRule[2]));
String[] entitySpawnRule = rule[1].split(",", 4);
this.levelConfig.addEntitySpawnRule(
this.currentIntervalStart,
this.currentIntervalEnd,
entitySpawnRule[0],
Integer.parseInt(entitySpawnRule[1]),
Integer.parseInt(entitySpawnRule[2]),
Integer.parseInt(entitySpawnRule[3])
);
} else {
throw new LevelConfigException("Unknown rule type: '"+rule[0]+"' : '"+line+"'");
}