Skip to content
Snippets Groups Projects
Commit cdfab349 authored by karthurg's avatar karthurg
Browse files
parents 9fce9b74 4b371a98
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,7 @@ public class Sounds { ...@@ -26,6 +26,7 @@ public class Sounds {
clip = AudioSystem.getClip(); clip = AudioSystem.getClip();
clip.open(aStream); clip.open(aStream);
clip.loop(Clip.LOOP_CONTINUOUSLY); clip.loop(Clip.LOOP_CONTINUOUSLY);
clips.add(clip);
} catch (LineUnavailableException | IOException e1) { } catch (LineUnavailableException | IOException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
......
...@@ -16,8 +16,7 @@ public class Enemy extends Placeable implements ITickable { ...@@ -16,8 +16,7 @@ public class Enemy extends Placeable implements ITickable {
private Field prevField; private Field prevField;
private int moveTries; private int moveTries;
private static HashMap<EnemyType, Integer> moveTimes = new HashMap<EnemyType, Integer>(); private static HashMap<EnemyType, Integer> moveTimes = new HashMap<EnemyType, Integer>();
static static {
{
moveTimes.put(EnemyType.HUMAN, 4); moveTimes.put(EnemyType.HUMAN, 4);
moveTimes.put(EnemyType.DWARF, 5); moveTimes.put(EnemyType.DWARF, 5);
moveTimes.put(EnemyType.ELF, 3); moveTimes.put(EnemyType.ELF, 3);
...@@ -41,8 +40,7 @@ public class Enemy extends Placeable implements ITickable { ...@@ -41,8 +40,7 @@ public class Enemy extends Placeable implements ITickable {
split(); split();
} }
private void Die() private void Die() {
{
field.getWorld().notifyEnemyDied(this); field.getWorld().notifyEnemyDied(this);
field.stepOff(this); field.stepOff(this);
if (this.type == EnemyType.HUMAN) if (this.type == EnemyType.HUMAN)
...@@ -80,6 +78,13 @@ public class Enemy extends Placeable implements ITickable { ...@@ -80,6 +78,13 @@ public class Enemy extends Placeable implements ITickable {
reset(); reset();
potentials.get(index).stepOn(this); potentials.get(index).stepOn(this);
} }
else
{
field.stepOff(this);
prevField = field;
reset();
prevField.stepOn(this);
}
} else { } else {
moveTries++; moveTries++;
} }
...@@ -91,7 +96,8 @@ public class Enemy extends Placeable implements ITickable { ...@@ -91,7 +96,8 @@ public class Enemy extends Placeable implements ITickable {
Die(); Die();
return; return;
} }
field.getWorld().getSpawnManager().spawnEnemy(field, type, hp, prevField); field.getWorld().getSpawnManager()
.spawnEnemy(field, type, hp, prevField);
} }
private void reset() { private void reset() {
......
...@@ -16,9 +16,6 @@ public class SpawnManager implements ITickable, IEnemyObserver ...@@ -16,9 +16,6 @@ public class SpawnManager implements ITickable, IEnemyObserver
private int spawnTimeLeft; private int spawnTimeLeft;
private int currentTime; private int currentTime;
private int enemiesAlive; private int enemiesAlive;
public static boolean randomEnemySpawnPos=false;
public static EnemyType fixedSpawnType;
public static boolean isFixedSpawnType;
public SpawnManager(Engine engine, World world, ArrayList<Field> spawns) public SpawnManager(Engine engine, World world, ArrayList<Field> spawns)
{ {
...@@ -48,27 +45,11 @@ public class SpawnManager implements ITickable, IEnemyObserver ...@@ -48,27 +45,11 @@ public class SpawnManager implements ITickable, IEnemyObserver
private void spawnEnemies() private void spawnEnemies()
{ {
Field spawnField = null; Field spawnField = spawns.get(new Random().nextInt(spawns.size()));
if (!randomEnemySpawnPos)
{
spawnField = spawns.get(0);
}
else
{
spawnField = spawns.get(new Random().nextInt(spawns.size()));
}
int num = nextSpawnNum(); int num = nextSpawnNum();
for (int i = 0; i < num; i++) for (int i = 0; i < num; i++)
{ {
EnemyType t; EnemyType t = EnemyType.values()[new Random().nextInt(EnemyType.values().length)];
if (isFixedSpawnType)
{
t = fixedSpawnType;
}
else
{
t = EnemyType.values()[new Random().nextInt(EnemyType.values().length)];
}
Enemy e = new Enemy(t); Enemy e = new Enemy(t);
e.setField(spawnField); e.setField(spawnField);
spawnField.stepOn(e); spawnField.stepOn(e);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment