diff --git a/core/src/com/saltosion/gladiator/level/premade/Round1Level.java b/core/src/com/saltosion/gladiator/level/premade/Round1Level.java index 8501b35..19ba2f2 100644 --- a/core/src/com/saltosion/gladiator/level/premade/Round1Level.java +++ b/core/src/com/saltosion/gladiator/level/premade/Round1Level.java @@ -6,7 +6,6 @@ import com.saltosion.gladiator.level.Level; import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.Direction; import com.saltosion.gladiator.util.Global; -import com.saltosion.gladiator.util.Log; import java.util.ArrayList; public class Round1Level implements Level { diff --git a/core/src/com/saltosion/gladiator/level/premade/Round2Level.java b/core/src/com/saltosion/gladiator/level/premade/Round2Level.java new file mode 100644 index 0000000..d05a039 --- /dev/null +++ b/core/src/com/saltosion/gladiator/level/premade/Round2Level.java @@ -0,0 +1,44 @@ +package com.saltosion.gladiator.level.premade; + +import com.badlogic.ashley.core.Entity; +import com.badlogic.gdx.math.Vector2; +import com.saltosion.gladiator.level.Level; +import com.saltosion.gladiator.util.AppUtil; +import com.saltosion.gladiator.util.Direction; +import com.saltosion.gladiator.util.Global; +import java.util.ArrayList; + +public class Round2Level implements Level { + + public Entity player; + public ArrayList enemies = new ArrayList(); + + @Override + public String getLevelName() { + return "Round 2"; + } + + @Override + public boolean levelCleared() { + for (Entity enemy : enemies) { + if ((enemy.flags & Global.FLAG_ALIVE) == Global.FLAG_ALIVE) { + return false; + } + } + return true; + } + + @Override + public boolean levelFailed() { + return (player.flags & Global.FLAG_ALIVE) == 0; + } + + @Override + public void generate() { + AppUtil.levelFactory.createLevelBase(); + player = AppUtil.entityFactory.createPlayer(new Vector2(0, 2), Direction.RIGHT); + enemies.add(AppUtil.entityFactory.createDummy(new Vector2(10, 2), Direction.LEFT)); + enemies.add(AppUtil.entityFactory.createDummy(new Vector2(-10, 2), Direction.RIGHT)); + } + +} diff --git a/core/src/com/saltosion/gladiator/state/InGameState.java b/core/src/com/saltosion/gladiator/state/InGameState.java index f00f77c..1e7a44a 100644 --- a/core/src/com/saltosion/gladiator/state/InGameState.java +++ b/core/src/com/saltosion/gladiator/state/InGameState.java @@ -3,11 +3,15 @@ package com.saltosion.gladiator.state; import com.saltosion.gladiator.gui.creators.InGameGUICreator; import com.saltosion.gladiator.level.Level; import com.saltosion.gladiator.level.premade.Round1Level; +import com.saltosion.gladiator.level.premade.Round2Level; import com.saltosion.gladiator.util.AppUtil; public class InGameState extends BaseState { - private static final Level[] levels = {new Round1Level()}; + /** + * Add new levels to this list + */ + private static final Level[] levels = {new Round1Level(), new Round2Level()}; private Level level; private InGameGUICreator guiCreator; @@ -17,6 +21,12 @@ public class InGameState extends BaseState { private final float levelChangeTextDelay = 2; private boolean levelChangeTextChanged = false; + private float timeSinceLevelFailed; + private final float levelFailedDelay = 1.5f; + + private float timeSinceLevelWon; + private final float levelWonDelay = 1.5f; + @Override public void create() { // Start from a clean slate @@ -46,22 +56,30 @@ public class InGameState extends BaseState { } if (level.levelCleared()) { - currentLevel++; - if (currentLevel >= levels.length) { - setState(new WinState()); - } else { - changeLevel(levels[currentLevel]); + timeSinceLevelWon += deltaTime; + if (timeSinceLevelWon > levelWonDelay) { + currentLevel++; + timeSinceLevelWon = 0; + if (currentLevel >= levels.length) { + setState(new WinState()); + } else { + changeLevel(levels[currentLevel]); + } } } if (level.levelFailed()) { - //setState(new GameOverState()); + timeSinceLevelFailed += deltaTime; + if (timeSinceLevelFailed > levelFailedDelay) { + setState(new GameOverState()); + } } } public void changeLevel(Level level) { AppUtil.engine.removeAllEntities(); this.level = level; + this.level.generate(); this.timeSinceLevelChange = 0; }