Create a basic test level config, make the Loader parse it and do first steps actually implementing the concept.
This commit is contained in:
parent
aad17c1032
commit
420cbd67b1
|
@ -4,7 +4,7 @@ background:FooBackground
|
|||
bossEnemy:TheBigOne
|
||||
-
|
||||
[0-2025]
|
||||
GegnerOne,2,6
|
||||
spawn:GegnerOne,2,6
|
||||
[2026-2168]
|
||||
GegnerOne,2,4
|
||||
GegnerTwo,5,6
|
||||
spawn:GegnerOne,2,4
|
||||
spawn:GegnerTwo,5,6
|
|
@ -0,0 +1,33 @@
|
|||
package de.teamteamteam.spacescooter.level;
|
||||
|
||||
import de.teamteamteam.spacescooter.utility.Loader;
|
||||
|
||||
public final class Level {
|
||||
|
||||
/**
|
||||
* Internal LevelConfig containing all the details about how this Level will manage GamePlay.
|
||||
*/
|
||||
private LevelConfig config;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor creating a LevelConfig based on a given config file.
|
||||
*/
|
||||
public Level(String levelConfig) {
|
||||
this.config = Loader.getLevelConfigByFilename(levelConfig);
|
||||
System.out.println(this.config);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The magic will happen in here.
|
||||
* Each time the Level will receive its updateTick,
|
||||
* it will do some checks, increase an internal counter and do
|
||||
* evil stuff like looking up what monsters to spawn and whatever else
|
||||
* is neccessary to torture the player.
|
||||
*/
|
||||
public void handleUpdateTick() {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +1,10 @@
|
|||
package de.teamteamteam.spacescooter.level;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class LevelConfigParser {
|
||||
|
||||
/* DEBUG */
|
||||
public static void main(String[] args) {
|
||||
LevelConfigParser lcp = new LevelConfigParser();
|
||||
LevelConfig lc = lcp.parse("/home/stud/timmeja/Programmierprojekt/SpaceScooter/src/de/teamteamteam/spacescooter/level/temp.properties");
|
||||
System.out.println(lc);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Internal LevelConfig instance to fill with data.
|
||||
|
@ -50,7 +43,7 @@ public class LevelConfigParser {
|
|||
/**
|
||||
* Takes a given configFile and turns it into a LevelConfig object.
|
||||
*/
|
||||
public LevelConfig parse(String configFile) {
|
||||
public LevelConfig parse(InputStream configFile) {
|
||||
this.reset();
|
||||
this.prepareScanner(configFile);
|
||||
while (this.scanner.hasNextLine()) {
|
||||
|
@ -103,9 +96,9 @@ public class LevelConfigParser {
|
|||
/**
|
||||
* Prepares a Scanner for the file to parse.
|
||||
*/
|
||||
private void prepareScanner(String filename) {
|
||||
private void prepareScanner(InputStream configStream) {
|
||||
try {
|
||||
this.scanner = new Scanner(new File(filename));
|
||||
this.scanner = new Scanner(configStream);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ public class GameOverScreen extends Screen {
|
|||
} else if(this.animationStatus == 2) {
|
||||
switch (this.menuPoint) {
|
||||
case 0:
|
||||
this.parent.setOverlay(new GameScreen(this.parent));
|
||||
this.parent.setOverlay(new GameScreen(this.parent, "levels/test.level"));
|
||||
break;
|
||||
case 1:
|
||||
this.parent.setOverlay(new MainMenuScreen(this.parent));
|
||||
|
|
|
@ -16,6 +16,7 @@ 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.level.Level;
|
||||
import de.teamteamteam.spacescooter.utility.CollisionHandler;
|
||||
|
||||
/**
|
||||
|
@ -33,8 +34,21 @@ public class GameScreen extends Screen {
|
|||
|
||||
private static Player player;
|
||||
|
||||
public GameScreen(Screen parent) {
|
||||
/**
|
||||
* Level instance to handle all the stuff based on its LevelConfig.
|
||||
*/
|
||||
private Level level;
|
||||
|
||||
|
||||
/**
|
||||
* GameScreen Constructor.
|
||||
* Takes the level as its second parameter.
|
||||
*/
|
||||
public GameScreen(Screen parent, String levelConfigName) {
|
||||
super(parent);
|
||||
this.level = new Level(levelConfigName);
|
||||
|
||||
//Old style adding stuff
|
||||
new ItemChance();
|
||||
points.add(new Point(300,300));
|
||||
points.add(new Point(600,100));
|
||||
|
@ -50,6 +64,7 @@ public class GameScreen extends Screen {
|
|||
new EnemyBoss(200, 300);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void paint(Graphics2D g) {
|
||||
this.entityPaintIterator.reset();
|
||||
|
@ -58,8 +73,18 @@ public class GameScreen extends Screen {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger level logic, trigger updates on all entities,
|
||||
* take care of user input such as pressing escape and
|
||||
* do a little(!) check on the gameover condition.
|
||||
* TODO: Let the level take care of that.
|
||||
*/
|
||||
@Override
|
||||
protected void update() {
|
||||
//The level will take care of whatever happens next.
|
||||
this.level.handleUpdateTick();
|
||||
|
||||
//Take care of the usual bussiness
|
||||
this.entityUpdateIterator.reset();
|
||||
while (this.entityUpdateIterator.hasNext()) {
|
||||
this.entityUpdateIterator.next().update();
|
||||
|
@ -69,7 +94,7 @@ public class GameScreen extends Screen {
|
|||
if (Keyboard.isKeyDown(KeyEvent.VK_ESCAPE)) {
|
||||
this.setOverlay(new GamePausedScreen(this));
|
||||
}
|
||||
if (!GameScreen.player.isAlive()) {
|
||||
if (!GameScreen.player.isAlive()) { //The level shall take this over.
|
||||
this.parent.setOverlay(new GameOverScreen(this.parent));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ public class MainMenuScreen extends Screen {
|
|||
} else if(animationStatus == 2) {
|
||||
switch (menuPoint) {
|
||||
case 0:
|
||||
this.parent.setOverlay(new GameScreen(this.parent));
|
||||
this.parent.setOverlay(new GameScreen(this.parent, "levels/test.level"));
|
||||
break;
|
||||
case 1:
|
||||
this.parent.setOverlay(new ShopScreen(this.parent));
|
||||
|
|
|
@ -3,6 +3,7 @@ package de.teamteamteam.spacescooter.utility;
|
|||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Hashtable;
|
||||
|
||||
|
@ -10,6 +11,8 @@ import javax.imageio.ImageIO;
|
|||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
|
||||
import de.teamteamteam.spacescooter.level.LevelConfig;
|
||||
import de.teamteamteam.spacescooter.level.LevelConfigParser;
|
||||
import de.teamteamteam.spacescooter.screen.LoadingScreen;
|
||||
import de.teamteamteam.spacescooter.sound.SoundSystem;
|
||||
|
||||
|
@ -19,6 +22,12 @@ import de.teamteamteam.spacescooter.sound.SoundSystem;
|
|||
*/
|
||||
public class Loader {
|
||||
|
||||
/**
|
||||
* Private instance of the LevelConfigParser to parse LevelConfigs.
|
||||
* Sorry, i know this is kind of bad, but it is a TODO to clean that up. :-/
|
||||
*/
|
||||
private static LevelConfigParser levelConfigParser;
|
||||
|
||||
/**
|
||||
* HashTable containing loaded BufferedImages
|
||||
*/
|
||||
|
@ -29,12 +38,20 @@ public class Loader {
|
|||
*/
|
||||
private static Hashtable<String, URL> sounds;
|
||||
|
||||
/**
|
||||
* HashTable containing the parsed LevelConfigs.
|
||||
*/
|
||||
private static Hashtable<String, LevelConfig> levelConfigs;
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the HashTables on load.
|
||||
*/
|
||||
static {
|
||||
Loader.images = new Hashtable<String, BufferedImage>();
|
||||
Loader.sounds = new Hashtable<String, URL>();
|
||||
Loader.levelConfigs = new Hashtable<String, LevelConfig>();
|
||||
Loader.levelConfigParser = new LevelConfigParser();
|
||||
}
|
||||
|
||||
|
||||
|
@ -71,7 +88,19 @@ public class Loader {
|
|||
return Loader.sounds.get(filename.replace("/", File.separator));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the LevelConfig by its relative filename.
|
||||
*/
|
||||
public static LevelConfig getLevelConfigByFilename(String filename) {
|
||||
if(CodeEnvironment.isJar()) {
|
||||
return Loader.levelConfigs.get(filename);
|
||||
} else {
|
||||
return Loader.levelConfigs.get(filename.replace("/", File.separator));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform the initial loading of everything and show the progress on the
|
||||
* given LoadingScreen.
|
||||
|
@ -98,10 +127,25 @@ public class Loader {
|
|||
System.out.println("Creating AudioInputStream for: " + e);
|
||||
Loader.addSoundURLByFilename(e);
|
||||
}
|
||||
if(e.endsWith(".level")) {
|
||||
if(GameConfig.DEBUG) {
|
||||
System.out.println("Creating LevelConfig for: " + e);
|
||||
}
|
||||
Loader.addLevelByFilename(e);
|
||||
}
|
||||
loadingScreen.increaseCurrentProcessed();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Preload a LevelConfig by simply parsing it into a LevelConfig object.
|
||||
*/
|
||||
private static void addLevelByFilename(String levelFilename) {
|
||||
InputStream foo = Loader.class.getClassLoader().getResourceAsStream(levelFilename);
|
||||
LevelConfig levelConfig = Loader.levelConfigParser.parse(foo);
|
||||
Loader.levelConfigs.put(levelFilename, levelConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Preload a given class by its filename using the ClassLoader.
|
||||
* This way, we avoid reading out of a jar later.
|
||||
|
|
Loading…
Reference in New Issue