Added round 2 & fixed the round system.

This commit is contained in:
Jeasonfire 2015-05-17 04:05:55 +03:00
parent 7a7adda2c5
commit d70e438647
3 changed files with 69 additions and 8 deletions

View File

@ -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 {

View File

@ -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<Entity> enemies = new ArrayList<Entity>();
@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));
}
}

View File

@ -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;
}