Move level buildup logic into Level.

This commit is contained in:
Jan Philipp Timme 2014-11-25 11:03:14 +01:00
parent af5bc93004
commit e17e3414cd
2 changed files with 43 additions and 22 deletions

View File

@ -1,5 +1,18 @@
package de.teamteamteam.spacescooter.level; 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.screen.GameScreen;
import de.teamteamteam.spacescooter.utility.Loader; 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<Point> points = new ArrayList<Point>();
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. * The magic will happen in here.
* Each time the Level will receive its updateTick, * Each time the Level will receive its updateTick,

View File

@ -1,17 +1,10 @@
package de.teamteamteam.spacescooter.screen; package de.teamteamteam.spacescooter.screen;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.KeyEvent; 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.control.Keyboard;
import de.teamteamteam.spacescooter.entity.Player; 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.HealthBar;
import de.teamteamteam.spacescooter.gui.InterfaceBar; import de.teamteamteam.spacescooter.gui.InterfaceBar;
import de.teamteamteam.spacescooter.gui.ScoreBar; import de.teamteamteam.spacescooter.gui.ScoreBar;
@ -27,11 +20,6 @@ import de.teamteamteam.spacescooter.utility.CollisionHandler;
*/ */
public class GameScreen extends Screen { public class GameScreen extends Screen {
/**
* Road points for EnemyFour
*/
private ArrayList<Point> points = new ArrayList<Point>();
private static Player player; private static Player player;
/** /**
@ -47,24 +35,19 @@ public class GameScreen extends Screen {
public GameScreen(Screen parent, String levelConfigName) { public GameScreen(Screen parent, String levelConfigName) {
super(parent); super(parent);
this.level = new Level(levelConfigName); this.level = new Level(levelConfigName);
this.level.doBuildUp(); //Have the level build up the whole setting.
//Old style adding stuff //Basic UI buildup - it's the same across all levels.
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);
new InterfaceBar(0, 0); new InterfaceBar(0, 0);
new HealthBar(10, 5); new HealthBar(10, 5);
new ShieldBar(10, 27); new ShieldBar(10, 27);
new ScoreBar(575, 33); 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 @Override
protected void paint(Graphics2D g) { protected void paint(Graphics2D g) {
this.entityPaintIterator.reset(); this.entityPaintIterator.reset();
@ -103,5 +86,9 @@ public class GameScreen extends Screen {
return GameScreen.player; return GameScreen.player;
} }
public static void setPlayer(Player player) {
GameScreen.player = player;
}
} }