Added a new AI & 2 rounds.

This commit is contained in:
Jeasonfire 2015-05-18 00:55:09 +03:00
parent ea3efb2205
commit cd115865a8
9 changed files with 156 additions and 29 deletions

View File

@ -65,7 +65,7 @@ public class EntityFactory {
.setDirection(initialDirection).setMoveSpeed(14f)); .setDirection(initialDirection).setMoveSpeed(14f));
// Combat // Combat
enemy.add(new CCombat().setBaseDamage(100).setHealth(1000).setSwingCD(.5f) enemy.add(new CCombat().setBaseDamage(100).setHealth(1000)
.setCombatListener(new BasicDeathListener())); .setCombatListener(new BasicDeathListener()));
enemy.add(cai); enemy.add(cai);

View File

@ -4,7 +4,7 @@ import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.saltosion.gladiator.components.CAI; import com.saltosion.gladiator.components.CAI;
import com.saltosion.gladiator.level.Level; import com.saltosion.gladiator.level.Level;
import com.saltosion.gladiator.listeners.ai.PanicAI; import com.saltosion.gladiator.listeners.ai.HeavenWorshiperAI;
import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.AppUtil;
import com.saltosion.gladiator.util.Direction; import com.saltosion.gladiator.util.Direction;
import com.saltosion.gladiator.util.Global; import com.saltosion.gladiator.util.Global;
@ -38,9 +38,11 @@ public class Round1Level implements Level {
@Override @Override
public void generate() { public void generate() {
AppUtil.levelFactory.createLevelBase(); AppUtil.levelFactory.createLevelBase();
player = AppUtil.entityFactory.createPlayer(new Vector2(-10, 2), Direction.RIGHT); player = AppUtil.entityFactory.createPlayer(new Vector2(0, 2), Direction.RIGHT);
enemies.add(AppUtil.entityFactory.createEnemy(new Vector2(10, 2), Direction.LEFT, enemies.add(AppUtil.entityFactory.createEnemy(new Vector2(10, 2), Direction.LEFT,
new CAI().setReactDistance(12f).setAIListener(new PanicAI()))); new CAI().setReactDistance(12f).setAIListener(new HeavenWorshiperAI())));
enemies.add(AppUtil.entityFactory.createEnemy(new Vector2(-10, 2), Direction.RIGHT,
new CAI().setReactDistance(12f).setAIListener(new HeavenWorshiperAI())));
} }
} }

View File

@ -4,8 +4,7 @@ import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.saltosion.gladiator.components.CAI; import com.saltosion.gladiator.components.CAI;
import com.saltosion.gladiator.level.Level; import com.saltosion.gladiator.level.Level;
import com.saltosion.gladiator.listeners.ai.HunterAI; import com.saltosion.gladiator.listeners.ai.PanicAI;
import com.saltosion.gladiator.listeners.ai.ScaredAI;
import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.AppUtil;
import com.saltosion.gladiator.util.Direction; import com.saltosion.gladiator.util.Direction;
import com.saltosion.gladiator.util.Global; import com.saltosion.gladiator.util.Global;
@ -41,9 +40,9 @@ public class Round2Level implements Level {
AppUtil.levelFactory.createLevelBase(); AppUtil.levelFactory.createLevelBase();
player = AppUtil.entityFactory.createPlayer(new Vector2(0, 2), Direction.RIGHT); player = AppUtil.entityFactory.createPlayer(new Vector2(0, 2), Direction.RIGHT);
enemies.add(AppUtil.entityFactory.createEnemy(new Vector2(10, 2), Direction.LEFT, enemies.add(AppUtil.entityFactory.createEnemy(new Vector2(10, 2), Direction.LEFT,
new CAI().setReactDistance(10f).setAIListener(new ScaredAI()))); new CAI().setReactDistance(10f).setAIListener(new PanicAI())));
enemies.add(AppUtil.entityFactory.createEnemy(new Vector2(-10, 2), Direction.RIGHT, enemies.add(AppUtil.entityFactory.createEnemy(new Vector2(-10, 2), Direction.RIGHT,
new CAI().setReactDistance(10f).setAIListener(new HunterAI()))); new CAI().setReactDistance(10f).setAIListener(new PanicAI())));
} }
} }

View File

@ -0,0 +1,48 @@
package com.saltosion.gladiator.level.premade;
import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.math.Vector2;
import com.saltosion.gladiator.components.CAI;
import com.saltosion.gladiator.level.Level;
import com.saltosion.gladiator.listeners.ai.ScaredAI;
import com.saltosion.gladiator.util.AppUtil;
import com.saltosion.gladiator.util.Direction;
import com.saltosion.gladiator.util.Global;
import java.util.ArrayList;
public class Round3Level implements Level {
public Entity player;
public ArrayList<Entity> enemies = new ArrayList<Entity>();
@Override
public String getLevelName() {
return "Round 1";
}
@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.createEnemy(new Vector2(10, 2), Direction.LEFT,
new CAI().setReactDistance(12f).setAIListener(new ScaredAI())));
enemies.add(AppUtil.entityFactory.createEnemy(new Vector2(-10, 2), Direction.RIGHT,
new CAI().setReactDistance(12f).setAIListener(new ScaredAI())));
}
}

View File

@ -0,0 +1,48 @@
package com.saltosion.gladiator.level.premade;
import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.math.Vector2;
import com.saltosion.gladiator.components.CAI;
import com.saltosion.gladiator.level.Level;
import com.saltosion.gladiator.listeners.ai.HunterAI;
import com.saltosion.gladiator.util.AppUtil;
import com.saltosion.gladiator.util.Direction;
import com.saltosion.gladiator.util.Global;
import java.util.ArrayList;
public class Round4Level implements Level {
public Entity player;
public ArrayList<Entity> enemies = new ArrayList<Entity>();
@Override
public String getLevelName() {
return "Round 1";
}
@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.createEnemy(new Vector2(10, 2), Direction.LEFT,
new CAI().setReactDistance(12f).setAIListener(new HunterAI())));
enemies.add(AppUtil.entityFactory.createEnemy(new Vector2(-10, 2), Direction.RIGHT,
new CAI().setReactDistance(12f).setAIListener(new HunterAI())));
}
}

View File

@ -0,0 +1,17 @@
package com.saltosion.gladiator.listeners.ai;
import com.badlogic.ashley.core.Entity;
import com.saltosion.gladiator.components.CCombat;
import com.saltosion.gladiator.listeners.AIListener;
import com.saltosion.gladiator.util.Direction;
import java.util.ArrayList;
public class HeavenWorshiperAI implements AIListener {
@Override
public void react(ArrayList<Entity> closeEntities, Entity host) {
CCombat co = host.getComponent(CCombat.class);
co.inputs.put(Direction.UP, true);
}
}

View File

@ -1,6 +1,7 @@
package com.saltosion.gladiator.listeners.ai; package com.saltosion.gladiator.listeners.ai;
import com.badlogic.ashley.core.Entity; import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.Gdx;
import com.saltosion.gladiator.components.CCombat; import com.saltosion.gladiator.components.CCombat;
import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.components.CPhysics;
import com.saltosion.gladiator.listeners.AIListener; import com.saltosion.gladiator.listeners.AIListener;
@ -9,6 +10,17 @@ import java.util.ArrayList;
public class PanicAI implements AIListener { public class PanicAI implements AIListener {
private float swingCd = 0;
private final float swingInterval;
public PanicAI() {
swingInterval = 0.75f;
}
public PanicAI(float swingInterval) {
this.swingInterval = swingInterval;
}
@Override @Override
public void react(ArrayList<Entity> closeEntities, Entity host) { public void react(ArrayList<Entity> closeEntities, Entity host) {
CPhysics po = host.getComponent(CPhysics.class); CPhysics po = host.getComponent(CPhysics.class);
@ -26,20 +38,24 @@ public class PanicAI implements AIListener {
po.jumping = true; po.jumping = true;
} }
switch ((int) Math.ceil(Math.random() * 4)) { if (swingCd < swingInterval) {
default: swingCd += Gdx.graphics.getDeltaTime();
case 1: } else {
co.inputs.put(Direction.LEFT, true); swingCd = 0;
break; switch ((int) Math.ceil(Math.random() * 6)) {
case 2: case 1:
co.inputs.put(Direction.RIGHT, true); co.inputs.put(Direction.LEFT, true);
break; break;
case 3: case 2:
co.inputs.put(Direction.DOWN, true); co.inputs.put(Direction.RIGHT, true);
break; break;
case 4: case 3:
co.inputs.put(Direction.UP, true); co.inputs.put(Direction.DOWN, true);
break; break;
case 4:
co.inputs.put(Direction.UP, true);
break;
}
} }
} }

View File

@ -4,6 +4,8 @@ import com.saltosion.gladiator.gui.creators.InGameGUICreator;
import com.saltosion.gladiator.level.Level; import com.saltosion.gladiator.level.Level;
import com.saltosion.gladiator.level.premade.Round1Level; import com.saltosion.gladiator.level.premade.Round1Level;
import com.saltosion.gladiator.level.premade.Round2Level; import com.saltosion.gladiator.level.premade.Round2Level;
import com.saltosion.gladiator.level.premade.Round3Level;
import com.saltosion.gladiator.level.premade.Round4Level;
import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.AppUtil;
public class InGameState extends BaseState { public class InGameState extends BaseState {
@ -11,7 +13,8 @@ public class InGameState extends BaseState {
/** /**
* Add new levels to this list * Add new levels to this list
*/ */
private static final Level[] levels = {new Round1Level(), new Round2Level()}; private static final Level[] levels = {new Round1Level(), new Round2Level(),
new Round3Level(), new Round4Level()};
private Level level; private Level level;
private InGameGUICreator guiCreator; private InGameGUICreator guiCreator;

View File

@ -6,18 +6,14 @@ import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.EntitySystem; import com.badlogic.ashley.core.EntitySystem;
import com.badlogic.ashley.core.Family; import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.utils.ImmutableArray; import com.badlogic.ashley.utils.ImmutableArray;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.saltosion.gladiator.components.CCombat; import com.saltosion.gladiator.components.CCombat;
import com.saltosion.gladiator.components.CDestructive; import com.saltosion.gladiator.components.CDestructive;
import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.components.CPhysics;
import com.saltosion.gladiator.components.CRenderedObject;
import com.saltosion.gladiator.listeners.CombatListener; import com.saltosion.gladiator.listeners.CombatListener;
import com.saltosion.gladiator.listeners.SwingHitboxListener; import com.saltosion.gladiator.listeners.SwingHitboxListener;
import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.AppUtil;
import com.saltosion.gladiator.util.Direction; import com.saltosion.gladiator.util.Direction;
import com.saltosion.gladiator.util.Name;
import com.saltosion.gladiator.util.SpriteLoader;
public class CombatSystem extends EntitySystem { public class CombatSystem extends EntitySystem {
@ -39,8 +35,6 @@ public class CombatSystem extends EntitySystem {
if (combat.swingCdCounter > 0) { if (combat.swingCdCounter > 0) {
combat.swingCdCounter -= deltaTime; combat.swingCdCounter -= deltaTime;
}
if (combat.swingCdCounter > 0) {
continue; continue;
} }