Merge branch 'ai'
Conflicts: core/src/com/saltosion/gladiator/systems/CombatSystem.java
This commit is contained in:
commit
ffec32ec77
@ -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);
|
||||||
|
|
||||||
|
@ -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())));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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())));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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())));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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())));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
import com.saltosion.gladiator.util.AudioLoader;
|
import com.saltosion.gladiator.util.AudioLoader;
|
||||||
import com.saltosion.gladiator.util.Name;
|
import com.saltosion.gladiator.util.Name;
|
||||||
@ -13,7 +15,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;
|
||||||
|
@ -38,8 +38,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +57,7 @@ public class CombatSystem extends EntitySystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!combat.getSwing().isZero() && combat.swingCdCounter <= 0) {
|
if (!combat.getSwing().isZero() && combat.swingCdCounter <= 0) {
|
||||||
|
|
||||||
// Swinging
|
// Swinging
|
||||||
Vector2 pos = obj.getPosition().cpy();
|
Vector2 pos = obj.getPosition().cpy();
|
||||||
|
|
||||||
@ -73,16 +71,14 @@ public class CombatSystem extends EntitySystem {
|
|||||||
pos.add(0, -combat.getSwingSize().y / 3 * 2);
|
pos.add(0, -combat.getSwingSize().y / 3 * 2);
|
||||||
}
|
}
|
||||||
createSwingHitbox(e, combat.getSwingDirection(), pos);
|
createSwingHitbox(e, combat.getSwingDirection(), pos);
|
||||||
|
|
||||||
// SFX
|
|
||||||
|
|
||||||
Sound s = AppUtil.jukebox.returnRandomSound(AudioLoader.getSound(Name.SOUND_SWING01),
|
// SFX
|
||||||
AudioLoader.getSound(Name.SOUND_SWING02),
|
Sound s = AppUtil.jukebox.returnRandomSound(AudioLoader.getSound(Name.SOUND_SWING01),
|
||||||
|
AudioLoader.getSound(Name.SOUND_SWING02),
|
||||||
AudioLoader.getSound(Name.SOUND_SWING03));
|
AudioLoader.getSound(Name.SOUND_SWING03));
|
||||||
s.play(AppUtil.sfxVolume);
|
s.play(AppUtil.sfxVolume);
|
||||||
|
|
||||||
// After-swing
|
// After-swing
|
||||||
|
|
||||||
combat.swingCdCounter = combat.getSwingDuration();
|
combat.swingCdCounter = combat.getSwingDuration();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user