From e17e3414cdb14f173936d46977ed8cd7a320aed0 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 25 Nov 2014 11:03:14 +0100 Subject: [PATCH] Move level buildup logic into Level. --- .../spacescooter/level/Level.java | 34 +++++++++++++++++++ .../spacescooter/screen/GameScreen.java | 31 +++++------------ 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/de/teamteamteam/spacescooter/level/Level.java b/src/de/teamteamteam/spacescooter/level/Level.java index c0fda2f..aae901e 100644 --- a/src/de/teamteamteam/spacescooter/level/Level.java +++ b/src/de/teamteamteam/spacescooter/level/Level.java @@ -1,5 +1,18 @@ package de.teamteamteam.spacescooter.level; +import java.awt.Point; +import java.util.ArrayList; + +import de.teamteamteam.spacescooter.background.StarBackground; +import de.teamteamteam.spacescooter.entity.Player; +import de.teamteamteam.spacescooter.entity.enemy.EnemyBoss; +import de.teamteamteam.spacescooter.entity.enemy.EnemyFour; +import de.teamteamteam.spacescooter.entity.enemy.EnemyThree; +import de.teamteamteam.spacescooter.entity.item.ItemChance; +import de.teamteamteam.spacescooter.gui.HealthBar; +import de.teamteamteam.spacescooter.gui.InterfaceBar; +import de.teamteamteam.spacescooter.gui.ScoreBar; +import de.teamteamteam.spacescooter.gui.ShieldBar; import de.teamteamteam.spacescooter.screen.GameScreen; import de.teamteamteam.spacescooter.utility.Loader; @@ -27,6 +40,27 @@ public final class Level { } + /** + * Initialize the level based on the LevelConfig attributes. + */ + public void doBuildUp() { + GameScreen.setPlayer(new Player(200, 300)); + + + new ItemChance(); + ArrayList points = new ArrayList(); + points.add(new Point(300,300)); + points.add(new Point(600,100)); + points.add(new Point(0,500)); + new EnemyFour(800, 400, points); + + new StarBackground(0, 50); + + + new EnemyThree(450, 100); + new EnemyBoss(200, 300); + } + /** * The magic will happen in here. * Each time the Level will receive its updateTick, diff --git a/src/de/teamteamteam/spacescooter/screen/GameScreen.java b/src/de/teamteamteam/spacescooter/screen/GameScreen.java index c11cd62..e4325ab 100644 --- a/src/de/teamteamteam/spacescooter/screen/GameScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/GameScreen.java @@ -1,17 +1,10 @@ package de.teamteamteam.spacescooter.screen; import java.awt.Graphics2D; -import java.awt.Point; import java.awt.event.KeyEvent; -import java.util.ArrayList; -import de.teamteamteam.spacescooter.background.StarBackground; import de.teamteamteam.spacescooter.control.Keyboard; import de.teamteamteam.spacescooter.entity.Player; -import de.teamteamteam.spacescooter.entity.enemy.EnemyBoss; -import de.teamteamteam.spacescooter.entity.enemy.EnemyFour; -import de.teamteamteam.spacescooter.entity.enemy.EnemyThree; -import de.teamteamteam.spacescooter.entity.item.ItemChance; import de.teamteamteam.spacescooter.gui.HealthBar; import de.teamteamteam.spacescooter.gui.InterfaceBar; import de.teamteamteam.spacescooter.gui.ScoreBar; @@ -27,11 +20,6 @@ import de.teamteamteam.spacescooter.utility.CollisionHandler; */ public class GameScreen extends Screen { - /** - * Road points for EnemyFour - */ - private ArrayList points = new ArrayList(); - private static Player player; /** @@ -47,24 +35,19 @@ public class GameScreen extends Screen { public GameScreen(Screen parent, String levelConfigName) { super(parent); this.level = new Level(levelConfigName); + this.level.doBuildUp(); //Have the level build up the whole setting. - //Old style adding stuff - new ItemChance(); - points.add(new Point(300,300)); - points.add(new Point(600,100)); - points.add(new Point(0,500)); - new StarBackground(0, 50); - GameScreen.player = new Player(200, 300); + //Basic UI buildup - it's the same across all levels. new InterfaceBar(0, 0); new HealthBar(10, 5); new ShieldBar(10, 27); new ScoreBar(575, 33); - new EnemyFour(800, 400, points); - new EnemyThree(450, 100); - new EnemyBoss(200, 300); } + /** + * This part is simple: Paint all the Entities! + */ @Override protected void paint(Graphics2D g) { this.entityPaintIterator.reset(); @@ -103,5 +86,9 @@ public class GameScreen extends Screen { return GameScreen.player; } + public static void setPlayer(Player player) { + GameScreen.player = player; + } + }