Changed the Test Level a bit

EnemyFour can now be spawn with the Level Config
EnemyFour now drops Items
Removed simicolon from Keyboard Debugcode
This commit is contained in:
JJTCM 2014-12-09 15:12:33 +01:00
parent 130152aba0
commit a0788fc08d
6 changed files with 127 additions and 27 deletions

View File

@ -4,19 +4,82 @@ background:CloudBackground
nextLevel:levels/second.level nextLevel:levels/second.level
- -
[0-1] [0-1]
spawn:EnemyBoss,1,1,50 spawn:EnemyTwo,1,4,5
spawn:EnemyTwo,1,4,25
spawn:EnemyTwo,1,4,45
spawn:EnemyTwo,1,4,65
spawn:EnemyTwo,1,4,85
spawn:EnemyTwo,1,4,100
[1-2] [1-2]
spawn:EnemyTwo,1,6,15
spawn:EnemyTwo,1,6,35
spawn:EnemyTwo,1,6,55
spawn:EnemyTwo,1,6,75
spawn:EnemyTwo,1,6,95
[2-3]
spawn:EnemyTwo,1,4,5
spawn:EnemyTwo,1,4,25
spawn:EnemyTwo,1,4,45
spawn:EnemyTwo,1,4,65
spawn:EnemyTwo,1,4,85
spawn:EnemyTwo,1,4,100
[3-4]
spawn:EnemyTwo,1,6,15
spawn:EnemyTwo,1,6,35
spawn:EnemyTwo,1,6,55
spawn:EnemyTwo,1,6,75
spawn:EnemyTwo,1,6,95
[4-5]
spawn:EnemyTwo,1,4,5
spawn:EnemyTwo,1,4,25
spawn:EnemyTwo,1,4,45
spawn:EnemyTwo,1,4,65
spawn:EnemyTwo,1,4,85
spawn:EnemyTwo,1,4,100
[5-6]
spawn:EnemyTwo,1,6,15
spawn:EnemyTwo,1,6,35
spawn:EnemyTwo,1,6,55
spawn:EnemyTwo,1,6,75
spawn:EnemyTwo,1,6,95
[6-7]
spawn:EnemyTwo,1,4,5
spawn:EnemyTwo,1,4,25
spawn:EnemyTwo,1,4,45
spawn:EnemyTwo,1,4,65
spawn:EnemyTwo,1,4,85
spawn:EnemyTwo,1,4,100
[7-8]
spawn:EnemyTwo,1,6,15
spawn:EnemyTwo,1,6,35
spawn:EnemyTwo,1,6,55
spawn:EnemyTwo,1,6,75
spawn:EnemyTwo,1,6,95
[8-9]
spawn:EnemyTwo,1,4,5
spawn:EnemyTwo,1,4,25
spawn:EnemyTwo,1,4,45
spawn:EnemyTwo,1,4,65
spawn:EnemyTwo,1,4,85
spawn:EnemyTwo,1,4,100
[9-10]
spawn:EnemyTwo,1,6,15
spawn:EnemyTwo,1,6,35
spawn:EnemyTwo,1,6,55
spawn:EnemyTwo,1,6,75
spawn:EnemyTwo,1,6,95
[10-12]
spawn:StoneOne,2,1,0 spawn:StoneOne,2,1,0
spawn:StoneOne,2,1,80 spawn:StoneOne,2,1,80
spawn:StoneThree,2,1,90 spawn:StoneThree,2,1,90
spawn:StoneThree,2,1,100 spawn:StoneThree,2,1,100
[2-4] [12-14]
spawn:EnemyOne,1,5,20 spawn:EnemyOne,1,5,20
spawn:StoneOne,4,5,50 spawn:StoneOne,4,5,50
[4-10] [14-20]
spawn:EnemyTwo,1,10,60 spawn:EnemyTwo,1,10,60
[10-25] [20-35]
spawn:EnemyThree,2,4,33 spawn:EnemyThree,2,4,33
spawn:EnemyTwo,5,6,10 spawn:EnemyTwo,5,6,10
[25-30] [35-40]
spawn:EnemyBoss,1,1,50 spawn:EnemyBoss,1,1,50

View File

@ -117,7 +117,7 @@ public class Keyboard implements KeyListener {
} }
if(e.getKeyCode() == KeyEvent.VK_4) { if(e.getKeyCode() == KeyEvent.VK_4) {
ArrayList<Point> points = new ArrayList<Point>(); ArrayList<Point> points = new ArrayList<Point>();
points.add(new Point(398,306));; points.add(new Point(398,306));
points.add(new Point(10,300)); points.add(new Point(10,300));
new EnemyFour(700,51,points); new EnemyFour(700,51,points);
} }

View File

@ -4,6 +4,8 @@ import java.awt.Point;
import java.util.ArrayList; import java.util.ArrayList;
import de.teamteamteam.spacescooter.entity.explosion.ExplosionOne; import de.teamteamteam.spacescooter.entity.explosion.ExplosionOne;
import de.teamteamteam.spacescooter.entity.item.Item;
import de.teamteamteam.spacescooter.utility.Random;
public class EnemyFour extends Enemy{ public class EnemyFour extends Enemy{
@ -21,7 +23,8 @@ public class EnemyFour extends Enemy{
this.setImage("images/enemy01.png"); this.setImage("images/enemy01.png");
this.setPrimaryShotImage("images/shots/laser_yellow.png"); this.setPrimaryShotImage("images/shots/laser_yellow.png");
this.setShootSpeed(4); this.setShootSpeed(4);
this.setShootDelay(62); this.setShootDelay(60);
this.setCanShoot(false);
this.setShootSpawn(-10, 10); this.setShootSpawn(-10, 10);
this.setShootDamage(5); this.setShootDamage(5);
this.setCollisionDamage(5); this.setCollisionDamage(5);
@ -70,4 +73,13 @@ public class EnemyFour extends Enemy{
new ExplosionOne(this.getCenteredX(), this.getCenteredY()); new ExplosionOne(this.getCenteredX(), this.getCenteredY());
} }
/**
* This enemy spawns an Item on its death and causes another enemy to appear.
*/
@Override
public void die() {
if(Random.nextInt(100) < 5) Item.create(getX(), getY());
super.die();
}
} }

View File

@ -1,5 +1,8 @@
package de.teamteamteam.spacescooter.level; package de.teamteamteam.spacescooter.level;
import java.awt.Point;
import java.util.ArrayList;
import de.teamteamteam.spacescooter.background.CloudBackground; import de.teamteamteam.spacescooter.background.CloudBackground;
import de.teamteamteam.spacescooter.background.EarthBackground; import de.teamteamteam.spacescooter.background.EarthBackground;
import de.teamteamteam.spacescooter.background.StarBackground; import de.teamteamteam.spacescooter.background.StarBackground;
@ -10,6 +13,7 @@ import de.teamteamteam.spacescooter.entity.Entity;
import de.teamteamteam.spacescooter.entity.Player; import de.teamteamteam.spacescooter.entity.Player;
import de.teamteamteam.spacescooter.entity.enemy.Enemy; import de.teamteamteam.spacescooter.entity.enemy.Enemy;
import de.teamteamteam.spacescooter.entity.enemy.EnemyBoss; import de.teamteamteam.spacescooter.entity.enemy.EnemyBoss;
import de.teamteamteam.spacescooter.entity.enemy.EnemyFour;
import de.teamteamteam.spacescooter.entity.enemy.EnemyOne; import de.teamteamteam.spacescooter.entity.enemy.EnemyOne;
import de.teamteamteam.spacescooter.entity.enemy.EnemyThree; import de.teamteamteam.spacescooter.entity.enemy.EnemyThree;
import de.teamteamteam.spacescooter.entity.enemy.EnemyTwo; import de.teamteamteam.spacescooter.entity.enemy.EnemyTwo;
@ -88,7 +92,7 @@ public final class Level {
* show the level name in a LevelHeadline. * show the level name in a LevelHeadline.
*/ */
public void doBuildUp() { public void doBuildUp() {
this.spawnEntityByAvailableName(Entity.availableNames.valueOf(this.config.background), 0, 50); this.spawnEntityByAvailableName(Entity.availableNames.valueOf(this.config.background), 0, 50, null);
GameScreen.setPlayer(new Player(200, 300)); GameScreen.setPlayer(new Player(200, 300));
this.backgroundMusic = SoundSystem.playSound(this.config.backgroundMusic); this.backgroundMusic = SoundSystem.playSound(this.config.backgroundMusic);
new LevelHeadline(100,100, this.config.name); new LevelHeadline(100,100, this.config.name);
@ -119,21 +123,30 @@ public final class Level {
* - 2: Amount - The amount of Entities to spawn at a time. * - 2: Amount - The amount of Entities to spawn at a time.
* - 3: SpawnRate - The rate at which the Entities are supposed to be spawned. * - 3: SpawnRate - The rate at which the Entities are supposed to be spawned.
* - 4: SpawnPosition - percentage of GameConfig.windowHeight - Where the Enemy shall spawn. * - 4: SpawnPosition - percentage of GameConfig.windowHeight - Where the Enemy shall spawn.
* - 5: Points - points for EnemyFour
*/ */
for(int[] spawnRule : this.config.spawnRuleList) { for(String[] spawnRule : this.config.spawnRuleList) {
//Skip spawn rules that are not in the current spawn interval. //Skip spawn rules that are not in the current spawn interval.
if(spawnRule[0] != currentIntervalIndex) continue; if(Integer.parseInt(spawnRule[0]) != currentIntervalIndex) continue;
//Divide the current interval by spawnrate //Divide the current interval by spawnrate
int intervalModulus = intervalLength / spawnRule[3]; int intervalModulus = intervalLength / Integer.parseInt(spawnRule[3]);
//Check whether the spawn rate strikes right now. //Check whether the spawn rate strikes right now.
if(relativeTimeWithinCurrentInterval % Math.max(1,intervalModulus) == 0) { if(relativeTimeWithinCurrentInterval % Math.max(1,intervalModulus) == 0) {
//If the rule matches the current time, spawn the configured Entity in the configured amount: //If the rule matches the current time, spawn the configured Entity in the configured amount:
for(int i=0; i<spawnRule[2]; i++) { for(int i=0; i<Integer.parseInt(spawnRule[2]); i++) {
ArrayList<Point> points = null;
//Minus one because the upper border is _excluded_ from the range! //Minus one because the upper border is _excluded_ from the range!
int x = GameConfig.gameScreenWidth + GameConfig.gameScreenXOffset - 1; int x = GameConfig.gameScreenWidth + GameConfig.gameScreenXOffset - 1;
if (!spawnRule[5].equals("")) {
points = new ArrayList<Point>();
String [] lol = spawnRule[5].split(";");
for(int run = 0; run < lol.length; run = run+2) {
points.add(new Point(Integer.parseInt(lol[run]),Integer.parseInt(lol[run+1])));
}
}
//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 y = Math.round((GameConfig.gameScreenHeight * Integer.parseInt(spawnRule[4])) / 100) + GameConfig.gameScreenYOffset - 1;
this.spawnEntityByAvailableName(Entity.availableNames.values()[spawnRule[1]], x, y); this.spawnEntityByAvailableName(Entity.availableNames.values()[Integer.parseInt(spawnRule[1])], x, y, points);
} }
} }
} }
@ -210,7 +223,7 @@ public final class Level {
* Spawn an Entity by name on the given position. * Spawn an Entity by name on the given position.
* Uses Entity.availableNames to determine the actual Entity to spawn. * Uses Entity.availableNames to determine the actual Entity to spawn.
*/ */
private void spawnEntityByAvailableName(Entity.availableNames entity, int x, int y) { private void spawnEntityByAvailableName(Entity.availableNames entity, int x, int y, ArrayList<Point> points) {
switch(entity) { switch(entity) {
case StarBackground: case StarBackground:
new StarBackground(x, y); new StarBackground(x, y);
@ -231,7 +244,7 @@ public final class Level {
new EnemyThree(x, y); new EnemyThree(x, y);
break; break;
case EnemyFour: case EnemyFour:
//TODO: FIX CONSTRUCTOR new EnemyFour(x, y); new EnemyFour(x, y, points);
break; break;
case EnemyBoss: case EnemyBoss:
new EnemyBoss(x, y); new EnemyBoss(x, y);
@ -250,5 +263,4 @@ public final class Level {
break; break;
} }
} }
} }

View File

@ -50,12 +50,12 @@ public class LevelConfig {
* - 3: SpawnRate - The rate at which the Entities are supposed to be spawned. * - 3: SpawnRate - The rate at which the Entities are supposed to be spawned.
* - 4: SpawnPosition - percentage of GameConfig.windowHeight - Where the Enemy shall spawn. * - 4: SpawnPosition - percentage of GameConfig.windowHeight - Where the Enemy shall spawn.
*/ */
public List<int[]> spawnRuleList; public List<String[]> spawnRuleList;
public LevelConfig() { public LevelConfig() {
this.intervalList = new ArrayList<int[]>(); this.intervalList = new ArrayList<int[]>();
this.spawnRuleList = new ArrayList<int[]>(); this.spawnRuleList = new ArrayList<String[]>();
} }
public String toString() { public String toString() {
@ -70,7 +70,7 @@ public class LevelConfig {
sb.append(" nextLevelName="); sb.append(" nextLevelName=");
sb.append(this.nextLevel); sb.append(this.nextLevel);
sb.append("\\\n\tRules:\n"); sb.append("\\\n\tRules:\n");
for(int[] rule : this.spawnRuleList) { for(String[] rule : this.spawnRuleList) {
sb.append("\t"); sb.append("\t");
sb.append(rule); sb.append(rule);
sb.append("\n"); sb.append("\n");
@ -126,17 +126,19 @@ public class LevelConfig {
/** /**
* Add a given EntitySpawnRule to the ruleList. * Add a given EntitySpawnRule to the ruleList.
* @param wayPoints
* @param enemyWayPoints
*/ */
public void addEntitySpawnRule(int intervalStart, int intervalEnd, String entityName, int amount, int spawnRate, int spawnPositionPercentage) { public void addEntitySpawnRule(int intervalStart, int intervalEnd, String entityName, String amount, String spawnRate, String spawnPositionPercentage, String wayPoints) {
int intervalIndex = this.getIntervalIndexByBorders(intervalStart, intervalEnd); int intervalIndex = this.getIntervalIndexByBorders(intervalStart, intervalEnd);
if(intervalIndex == -1) { if(intervalIndex == -1) {
throw new LevelConfigException("No Interval for rule found!\nRule: " + intervalStart + " to " + intervalEnd + ": " + entityName + ", " + amount + ", " + spawnRate + ", " + spawnPositionPercentage); throw new LevelConfigException("No Interval for rule found!\nRule: " + intervalStart + " to " + intervalEnd + ": " + entityName + ", " + amount + ", " + spawnRate + ", " + spawnPositionPercentage);
} else { } else {
int enemyNumber = Entity.availableNames.valueOf(entityName).ordinal(); int enemyNumber = Entity.availableNames.valueOf(entityName).ordinal();
if(spawnPositionPercentage < 0 || spawnPositionPercentage > 100) { if(Integer.parseInt(spawnPositionPercentage) < 0 || Integer.parseInt(spawnPositionPercentage) > 100) {
throw new LevelConfigException("Invalid spawnPosition percentage!\nRule: " + intervalStart + " to " + intervalEnd + ": " + entityName + ", " + amount + ", " + spawnRate + ", " + spawnPositionPercentage); throw new LevelConfigException("Invalid spawnPosition percentage!\nRule: " + intervalStart + " to " + intervalEnd + ": " + entityName + ", " + amount + ", " + spawnRate + ", " + spawnPositionPercentage);
} }
int[] newRule = {intervalIndex, enemyNumber, amount, spawnRate, spawnPositionPercentage}; String[] newRule = {""+intervalIndex, ""+enemyNumber, ""+amount, ""+spawnRate, ""+spawnPositionPercentage, wayPoints};
this.spawnRuleList.add(newRule); this.spawnRuleList.add(newRule);
} }
} }

View File

@ -31,6 +31,11 @@ public class LevelConfigParser {
*/ */
private int currentIntervalStart; private int currentIntervalStart;
/**
* The start of the last read interval.
*/
private String wayPoints;
/** /**
* The end of the last read interval. * The end of the last read interval.
*/ */
@ -88,14 +93,20 @@ public class LevelConfigParser {
} else { } else {
String[] rule = line.split(":", 2); String[] rule = line.split(":", 2);
if(rule[0].equals("spawn")) { if(rule[0].equals("spawn")) {
String[] entitySpawnRule = rule[1].split(",", 4); String[] entitySpawnRule = rule[1].split(",", 5);
if (entitySpawnRule.length <= 4) {
wayPoints = "";
} else {
wayPoints = entitySpawnRule[4];
}
this.levelConfig.addEntitySpawnRule( this.levelConfig.addEntitySpawnRule(
this.currentIntervalStart, this.currentIntervalStart,
this.currentIntervalEnd, this.currentIntervalEnd,
entitySpawnRule[0], entitySpawnRule[0],
Integer.parseInt(entitySpawnRule[1]), entitySpawnRule[1],
Integer.parseInt(entitySpawnRule[2]), entitySpawnRule[2],
Integer.parseInt(entitySpawnRule[3]) entitySpawnRule[3],
wayPoints
); );
} else { } else {
throw new LevelConfigException("Unknown rule type: '"+rule[0]+"' : '"+line+"'"); throw new LevelConfigException("Unknown rule type: '"+rule[0]+"' : '"+line+"'");