From 2ed07b430a0386e380b8aa658f3d3ddfc63122e7 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 25 Nov 2014 14:18:10 +0100 Subject: [PATCH 1/4] Move levelClock++ to the end, adjust interval checks. --- src/de/teamteamteam/spacescooter/entity/LivingEntity.java | 3 +-- src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java | 2 +- .../spacescooter/entity/enemy/EnemyBossMinion.java | 5 ++--- src/de/teamteamteam/spacescooter/level/Level.java | 4 ++-- src/de/teamteamteam/spacescooter/level/LevelConfig.java | 2 +- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java index 2b76b7f..1e321ea 100644 --- a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java @@ -109,8 +109,7 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable * The default way the LivingEntity explodes. Override this method for a * different explosion behaviour. */ - public void explode() { - } + public void explode() {} /** * The default way the LivingEntity dies. Override this method for a diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java b/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java index b710091..f7649af 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java @@ -40,7 +40,7 @@ public abstract class Enemy extends ShootingEntity { if(willShoot == true){ this.shoot(); } - if(this.getX() < 0-getWidth()){ + if(this.getX() < 0-this.getWidth()) { this.remove(); } } diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyBossMinion.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyBossMinion.java index c6b1731..6ef4a5e 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyBossMinion.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyBossMinion.java @@ -37,7 +37,6 @@ public class EnemyBossMinion extends Enemy{ /** * Custom MultiExplosion for this enemy. */ - @Override public void explode() { new MultiExplosion(this.getX(), this.getY()); } @@ -45,12 +44,12 @@ public class EnemyBossMinion extends Enemy{ @Override public void update() { super.update(); - this.setPosition(this.getX()-1, this.getY()); + this.transpose(-1, 0); Player player = GameScreen.getPlayer(); if(this.getY() < player.getY()){ this.newY += ySpeed; this.setPosition(this.getX(), (int) newY); - }else if(this.getY() > player.getY()){ + } else if(this.getY() > player.getY()) { this.newY -= ySpeed; this.setPosition(this.getX(), (int) newY); } diff --git a/src/de/teamteamteam/spacescooter/level/Level.java b/src/de/teamteamteam/spacescooter/level/Level.java index e99f5d4..ee9fe4c 100644 --- a/src/de/teamteamteam/spacescooter/level/Level.java +++ b/src/de/teamteamteam/spacescooter/level/Level.java @@ -74,8 +74,6 @@ public final class Level { if (Keyboard.isKeyDown(KeyEvent.VK_0)) { new EnemyBoss(400,400); } - //Increase levelClock - this.levelClock++; //Check whether the current interval is configured int currentIntervalIndex = this.config.getIntervalIndexByCurrentTime(this.levelClock); if(currentIntervalIndex == -1) return; //Nothing to do @@ -105,6 +103,8 @@ public final class Level { } } } + //Increase levelClock + this.levelClock++; } /** diff --git a/src/de/teamteamteam/spacescooter/level/LevelConfig.java b/src/de/teamteamteam/spacescooter/level/LevelConfig.java index 433f1f3..acd64fa 100644 --- a/src/de/teamteamteam/spacescooter/level/LevelConfig.java +++ b/src/de/teamteamteam/spacescooter/level/LevelConfig.java @@ -93,7 +93,7 @@ public class LevelConfig { */ public int getIntervalIndexByCurrentTime(int time) { for(int[] interval : this.intervalList) { - if(interval[0] <= time && interval[1] >= time) { + if(time >= interval[0] && time < interval[1]) { return this.intervalList.indexOf(interval); } } From 63e7b7a21c65d85cb413fb6678e0e7baac24bb1c Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 25 Nov 2014 14:26:34 +0100 Subject: [PATCH 2/4] All Entities have to implement explode() from now on. --- res/levels/test.level | 10 ++++++---- .../teamteamteam/spacescooter/entity/LivingEntity.java | 2 +- src/de/teamteamteam/spacescooter/entity/Player.java | 1 - .../spacescooter/entity/enemy/EnemyFour.java | 7 +++++++ .../spacescooter/entity/enemy/EnemyOne.java | 7 +++++++ .../spacescooter/entity/enemy/EnemyTwo.java | 6 ++++++ .../teamteamteam/spacescooter/utility/GameConfig.java | 2 +- 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/res/levels/test.level b/res/levels/test.level index 1d572bf..e6bdf6e 100644 --- a/res/levels/test.level +++ b/res/levels/test.level @@ -1,10 +1,12 @@ name:Lustiger Levelname backgroundMusic:music/bla.wav -background:FooBackground +background:StarBackground - -[0-20] -spawn:EnemyTwo,2,2 -[21-25] +[0-4] +spawn:EnemyBoss,1,1 +[5-10] +spawn:EnemyTwo,2,10 +[11-25] spawn:EnemyThree,2,4 spawn:EnemyTwo,5,6 [26-30] diff --git a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java index 1e321ea..41a6705 100644 --- a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java @@ -109,7 +109,7 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable * The default way the LivingEntity explodes. Override this method for a * different explosion behaviour. */ - public void explode() {} + public abstract void explode(); /** * The default way the LivingEntity dies. Override this method for a diff --git a/src/de/teamteamteam/spacescooter/entity/Player.java b/src/de/teamteamteam/spacescooter/entity/Player.java index 54277da..b6dab6a 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -126,7 +126,6 @@ public class Player extends ShootingEntity implements KeyboardListener { */ @Override public void explode() { - super.explode(); SoundSystem.playSound("sounds/abgang.wav"); } diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyFour.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyFour.java index ed93c2a..d5fc47c 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyFour.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyFour.java @@ -3,6 +3,8 @@ package de.teamteamteam.spacescooter.entity.enemy; import java.awt.Point; import java.util.ArrayList; +import de.teamteamteam.spacescooter.entity.explosion.ExplosionOne; + public class EnemyFour extends Enemy{ private ArrayList points; @@ -61,5 +63,10 @@ public class EnemyFour extends Enemy{ this.remove(); } } + + @Override + public void explode() { + new ExplosionOne(this.getX(), this.getY()); + } } diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyOne.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyOne.java index 516c802..2a75ecb 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyOne.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyOne.java @@ -1,5 +1,7 @@ package de.teamteamteam.spacescooter.entity.enemy; +import de.teamteamteam.spacescooter.entity.explosion.ExplosionOne; + public class EnemyOne extends Enemy { public EnemyOne(int x, int y) { @@ -20,5 +22,10 @@ public class EnemyOne extends Enemy { public void update() { super.update(); } + + @Override + public void explode() { + new ExplosionOne(this.getX(), this.getY()); + } } diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java index cdf2189..cd170a4 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java @@ -1,5 +1,6 @@ package de.teamteamteam.spacescooter.entity.enemy; +import de.teamteamteam.spacescooter.entity.explosion.ExplosionTwo; import de.teamteamteam.spacescooter.utility.GameConfig; import de.teamteamteam.spacescooter.utility.Random; @@ -28,5 +29,10 @@ public class EnemyTwo extends Enemy{ this.remove(); } } + + @Override + public void explode() { + new ExplosionTwo(this.getX(), this.getY()); + } } diff --git a/src/de/teamteamteam/spacescooter/utility/GameConfig.java b/src/de/teamteamteam/spacescooter/utility/GameConfig.java index 23ab204..741271c 100644 --- a/src/de/teamteamteam/spacescooter/utility/GameConfig.java +++ b/src/de/teamteamteam/spacescooter/utility/GameConfig.java @@ -8,7 +8,7 @@ public class GameConfig { /** * Whether debug output (and more) is enabled or disabled. */ - public static boolean DEBUG = false; + public static boolean DEBUG = true; /** * Width of GameWindow. From c8b8c2fd79c1f78f4b214238e448074a02b0f7ac Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 25 Nov 2014 14:27:38 +0100 Subject: [PATCH 3/4] Disable debug mode. oops. --- src/de/teamteamteam/spacescooter/utility/GameConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/teamteamteam/spacescooter/utility/GameConfig.java b/src/de/teamteamteam/spacescooter/utility/GameConfig.java index 741271c..23ab204 100644 --- a/src/de/teamteamteam/spacescooter/utility/GameConfig.java +++ b/src/de/teamteamteam/spacescooter/utility/GameConfig.java @@ -8,7 +8,7 @@ public class GameConfig { /** * Whether debug output (and more) is enabled or disabled. */ - public static boolean DEBUG = true; + public static boolean DEBUG = false; /** * Width of GameWindow. From c005120053502f09ce77ffa7ee91873bce2764fe Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 25 Nov 2014 14:31:35 +0100 Subject: [PATCH 4/4] Add Background to configurable items. --- res/levels/test.level | 2 +- src/de/teamteamteam/spacescooter/level/Level.java | 6 ++++-- src/de/teamteamteam/spacescooter/level/LevelConfig.java | 1 - 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/res/levels/test.level b/res/levels/test.level index e6bdf6e..2426e07 100644 --- a/res/levels/test.level +++ b/res/levels/test.level @@ -3,7 +3,7 @@ backgroundMusic:music/bla.wav background:StarBackground - [0-4] -spawn:EnemyBoss,1,1 +spawn:EnemyOne,1,1 [5-10] spawn:EnemyTwo,2,10 [11-25] diff --git a/src/de/teamteamteam/spacescooter/level/Level.java b/src/de/teamteamteam/spacescooter/level/Level.java index ee9fe4c..fdad64a 100644 --- a/src/de/teamteamteam/spacescooter/level/Level.java +++ b/src/de/teamteamteam/spacescooter/level/Level.java @@ -41,7 +41,6 @@ public final class Level { public Level(String levelConfig) { this.levelClock = 0; this.config = Loader.getLevelConfigByFilename(levelConfig); - System.out.println(this.config); } @@ -49,7 +48,7 @@ public final class Level { * Initialize the level based on the LevelConfig attributes. */ public void doBuildUp() { - new StarBackground(0, 50); + this.spawnEntityByAvailableName(Entity.availableNames.valueOf(this.config.background), 0, 50); GameScreen.setPlayer(new Player(200, 300)); } @@ -122,6 +121,9 @@ public final class Level { */ private void spawnEntityByAvailableName(Entity.availableNames entity, int x, int y) { switch(entity) { + case StarBackground: + new StarBackground(x, y); + break; case EnemyOne: new EnemyOne(x, y); break; diff --git a/src/de/teamteamteam/spacescooter/level/LevelConfig.java b/src/de/teamteamteam/spacescooter/level/LevelConfig.java index acd64fa..f99facd 100644 --- a/src/de/teamteamteam/spacescooter/level/LevelConfig.java +++ b/src/de/teamteamteam/spacescooter/level/LevelConfig.java @@ -104,7 +104,6 @@ public class LevelConfig { * Add a given EntitySpawnRule to the ruleList. */ public void addEntitySpawnRule(int intervalStart, int intervalEnd, String entityName, int amount, int spawnRate) { - System.out.println("Adding rule for " + intervalStart + " to " + intervalEnd + ": " + entityName + ", " + amount + ", " + spawnRate); int intervalIndex = this.getIntervalIndexByBorders(intervalStart, intervalEnd); if(intervalIndex == -1) { System.err.println("No Interval for rule found!");