Merge branch 'ai'

Conflicts:
	core/src/com/saltosion/gladiator/systems/CombatSystem.java
This commit is contained in:
Jeasonfire 2015-05-18 01:14:21 +03:00
commit ffec32ec77
9 changed files with 161 additions and 32 deletions

View File

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

View File

@ -4,7 +4,7 @@ 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.PanicAI;
import com.saltosion.gladiator.listeners.ai.HeavenWorshiperAI;
import com.saltosion.gladiator.util.AppUtil;
import com.saltosion.gladiator.util.Direction;
import com.saltosion.gladiator.util.Global;
@ -38,9 +38,11 @@ public class Round1Level implements Level {
@Override
public void generate() {
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,
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.saltosion.gladiator.components.CAI;
import com.saltosion.gladiator.level.Level;
import com.saltosion.gladiator.listeners.ai.HunterAI;
import com.saltosion.gladiator.listeners.ai.ScaredAI;
import com.saltosion.gladiator.listeners.ai.PanicAI;
import com.saltosion.gladiator.util.AppUtil;
import com.saltosion.gladiator.util.Direction;
import com.saltosion.gladiator.util.Global;
@ -41,9 +40,9 @@ public class Round2Level implements Level {
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(10f).setAIListener(new ScaredAI())));
new CAI().setReactDistance(10f).setAIListener(new PanicAI())));
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;
import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.Gdx;
import com.saltosion.gladiator.components.CCombat;
import com.saltosion.gladiator.components.CPhysics;
import com.saltosion.gladiator.listeners.AIListener;
@ -9,6 +10,17 @@ import java.util.ArrayList;
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
public void react(ArrayList<Entity> closeEntities, Entity host) {
CPhysics po = host.getComponent(CPhysics.class);
@ -26,20 +38,24 @@ public class PanicAI implements AIListener {
po.jumping = true;
}
switch ((int) Math.ceil(Math.random() * 4)) {
default:
case 1:
co.inputs.put(Direction.LEFT, true);
break;
case 2:
co.inputs.put(Direction.RIGHT, true);
break;
case 3:
co.inputs.put(Direction.DOWN, true);
break;
case 4:
co.inputs.put(Direction.UP, true);
break;
if (swingCd < swingInterval) {
swingCd += Gdx.graphics.getDeltaTime();
} else {
swingCd = 0;
switch ((int) Math.ceil(Math.random() * 6)) {
case 1:
co.inputs.put(Direction.LEFT, true);
break;
case 2:
co.inputs.put(Direction.RIGHT, true);
break;
case 3:
co.inputs.put(Direction.DOWN, true);
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.premade.Round1Level;
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.AudioLoader;
import com.saltosion.gladiator.util.Name;
@ -13,7 +15,8 @@ public class InGameState extends BaseState {
/**
* 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 InGameGUICreator guiCreator;

View File

@ -38,8 +38,6 @@ public class CombatSystem extends EntitySystem {
if (combat.swingCdCounter > 0) {
combat.swingCdCounter -= deltaTime;
}
if (combat.swingCdCounter > 0) {
continue;
}
@ -59,7 +57,7 @@ public class CombatSystem extends EntitySystem {
}
if (!combat.getSwing().isZero() && combat.swingCdCounter <= 0) {
// Swinging
Vector2 pos = obj.getPosition().cpy();
@ -73,16 +71,14 @@ public class CombatSystem extends EntitySystem {
pos.add(0, -combat.getSwingSize().y / 3 * 2);
}
createSwingHitbox(e, combat.getSwingDirection(), pos);
// SFX
Sound s = AppUtil.jukebox.returnRandomSound(AudioLoader.getSound(Name.SOUND_SWING01),
AudioLoader.getSound(Name.SOUND_SWING02),
// SFX
Sound s = AppUtil.jukebox.returnRandomSound(AudioLoader.getSound(Name.SOUND_SWING01),
AudioLoader.getSound(Name.SOUND_SWING02),
AudioLoader.getSound(Name.SOUND_SWING03));
s.play(AppUtil.sfxVolume);
// After-swing
combat.swingCdCounter = combat.getSwingDuration();
}
}