cleanup & format
This commit is contained in:
@@ -148,14 +148,15 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
|
||||
Log.i("=== Initialized sequence completed ===");
|
||||
}
|
||||
|
||||
|
||||
@DefaultImpl
|
||||
protected void registerIonizables()
|
||||
{
|
||||
Ion.registerType(Coord.ION_MARK, Coord.class);
|
||||
Ion.registerType(Step.ION_MARK, Step.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Called at the beginning of the initialization sequence, right after lock
|
||||
* was obtained.
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package mightypork.gamecore.gui;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Triggered action
|
||||
*
|
||||
|
||||
@@ -13,6 +13,7 @@ public class CrossfadeRequest extends BusEvent<CrossfadeOverlay> {
|
||||
private final String screen;
|
||||
private final boolean fromDark;
|
||||
|
||||
|
||||
/**
|
||||
* @param screen screen key to show. Null = exit the app.
|
||||
* @param fromDark true to fade from full black (ie. start of the game)
|
||||
@@ -24,6 +25,7 @@ public class CrossfadeRequest extends BusEvent<CrossfadeOverlay> {
|
||||
this.fromDark = fromDark;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param screen screen key to show. Null = exit the app.
|
||||
*/
|
||||
|
||||
@@ -32,7 +32,8 @@ public abstract class Screen extends AppSubModule implements Renderable, RectBou
|
||||
/**
|
||||
* @param app app access
|
||||
*/
|
||||
public Screen(AppAccess app) {
|
||||
public Screen(AppAccess app)
|
||||
{
|
||||
super(app);
|
||||
|
||||
// disable events initially
|
||||
|
||||
@@ -39,7 +39,8 @@ public class CrossfadeOverlay extends Overlay {
|
||||
};
|
||||
|
||||
|
||||
public CrossfadeOverlay(AppAccess app) {
|
||||
public CrossfadeOverlay(AppAccess app)
|
||||
{
|
||||
super(app);
|
||||
|
||||
final QuadPainter qp = new QuadPainter(color);
|
||||
|
||||
@@ -9,9 +9,9 @@ import mightypork.gamecore.util.math.color.Color;
|
||||
|
||||
public class LayerColor extends ScreenLayer {
|
||||
|
||||
private int zIndex;
|
||||
|
||||
|
||||
private final int zIndex;
|
||||
|
||||
|
||||
public LayerColor(Screen screen, Color color, int zIndex)
|
||||
{
|
||||
super(screen);
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.logging.Level;
|
||||
|
||||
import mightypork.gamecore.logging.writers.LogWriter;
|
||||
|
||||
|
||||
/**
|
||||
* Used to redirect slick log into main logger.
|
||||
*
|
||||
|
||||
@@ -93,13 +93,9 @@ public class Ion {
|
||||
if (mark > 255) throw new IllegalArgumentException("Mark must be < 256.");
|
||||
if (mark < 0) throw new IllegalArgumentException("Mark must be positive.");
|
||||
|
||||
if (reservedMarkChecking && mark < 50) {
|
||||
throw new IllegalArgumentException("Marks 0..49 are reserved.");
|
||||
}
|
||||
if (reservedMarkChecking && mark < 50) { throw new IllegalArgumentException("Marks 0..49 are reserved."); }
|
||||
|
||||
if (registered[mark] != null) {
|
||||
throw new IllegalArgumentException("Mark " + mark + " is already in use.");
|
||||
}
|
||||
if (registered[mark] != null) { throw new IllegalArgumentException("Mark " + mark + " is already in use."); }
|
||||
|
||||
try {
|
||||
objClass.getConstructor();
|
||||
@@ -125,7 +121,7 @@ public class Ion {
|
||||
*/
|
||||
public static <T extends IonObjBinary> T fromFile(File file) throws IOException
|
||||
{
|
||||
try (InputStream in = new FileInputStream(file)) {
|
||||
try(InputStream in = new FileInputStream(file)) {
|
||||
return fromStream(in);
|
||||
}
|
||||
}
|
||||
@@ -145,7 +141,7 @@ public class Ion {
|
||||
*/
|
||||
public static <T extends IonObjBundled> T fromFile(File file, Class<? extends T> objClass) throws IOException
|
||||
{
|
||||
try (InputStream in = new FileInputStream(file)) {
|
||||
try(InputStream in = new FileInputStream(file)) {
|
||||
|
||||
return fromStream(in, objClass);
|
||||
|
||||
@@ -182,7 +178,7 @@ public class Ion {
|
||||
*/
|
||||
public static void toFile(File file, IonObjBinary obj) throws IOException
|
||||
{
|
||||
try (OutputStream out = new FileOutputStream(file)) {
|
||||
try(OutputStream out = new FileOutputStream(file)) {
|
||||
|
||||
toStream(out, obj);
|
||||
|
||||
@@ -282,13 +278,9 @@ public class Ion {
|
||||
|
||||
final Class<? extends IonObjBinary> clz = Ion.getClassForMark(mark);
|
||||
|
||||
if (clz == null) {
|
||||
throw new IOException("Not registered - mark: " + mark + ", class: " + Log.str(obj.getClass()));
|
||||
}
|
||||
if (clz == null) { throw new IOException("Not registered - mark: " + mark + ", class: " + Log.str(obj.getClass())); }
|
||||
|
||||
if (clz != obj.getClass()) {
|
||||
throw new IOException("Class mismatch - mark: " + mark + ", class: " + Log.str(obj.getClass()));
|
||||
}
|
||||
if (clz != obj.getClass()) { throw new IOException("Class mismatch - mark: " + mark + ", class: " + Log.str(obj.getClass())); }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -137,12 +137,14 @@ public class IonBundle implements IonObjBinary {
|
||||
{
|
||||
backingMap.put(key, value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void put(String key, byte value)
|
||||
{
|
||||
backingMap.put(key, value);
|
||||
}
|
||||
|
||||
|
||||
public void put(String key, char value)
|
||||
{
|
||||
backingMap.put(key, value);
|
||||
|
||||
@@ -46,19 +46,24 @@ public class Coord implements IonObjBundled, IonObjBinary {
|
||||
{
|
||||
return make(0, 0);
|
||||
}
|
||||
|
||||
public Coord() {
|
||||
|
||||
|
||||
public Coord()
|
||||
{
|
||||
// for ion
|
||||
}
|
||||
|
||||
public Coord(int x, int y) {
|
||||
|
||||
public Coord(int x, int y)
|
||||
{
|
||||
super();
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
|
||||
public Coord(Coord other) {
|
||||
public Coord(Coord other)
|
||||
{
|
||||
this.x = other.x;
|
||||
this.y = other.y;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class Sides {
|
||||
public static final byte NE_CORNER = MASK_E | MASK_NE | MASK_N;
|
||||
public static final byte SW_CORNER = MASK_W | MASK_SW | MASK_S;
|
||||
public static final byte SE_CORNER = MASK_E | MASK_SE | MASK_S;
|
||||
|
||||
|
||||
public static final Step NW = Step.make(-1, -1);
|
||||
public static final Step N = Step.make(0, -1);
|
||||
public static final Step NE = Step.make(1, -1);
|
||||
|
||||
@@ -43,12 +43,16 @@ public class Step implements IonObjBinary, IonObjBundled {
|
||||
|
||||
private byte x;
|
||||
private byte y;
|
||||
|
||||
public Step() {
|
||||
|
||||
|
||||
public Step()
|
||||
{
|
||||
// for ion
|
||||
}
|
||||
|
||||
public Step(int x, int y) {
|
||||
|
||||
public Step(int x, int y)
|
||||
{
|
||||
this.x = (byte) (x < 0 ? -1 : x > 0 ? 1 : 0);
|
||||
this.y = (byte) (y < 0 ? -1 : y > 0 ? 1 : 0);
|
||||
}
|
||||
@@ -66,7 +70,6 @@ public class Step implements IonObjBinary, IonObjBundled {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Coord toCoord()
|
||||
{
|
||||
return Coord.make(x, y);
|
||||
@@ -85,7 +88,7 @@ public class Step implements IonObjBinary, IonObjBundled {
|
||||
{
|
||||
return "(" + x + ";" + y + ")";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void load(IonInput in) throws IOException
|
||||
@@ -102,6 +105,7 @@ public class Step implements IonObjBinary, IonObjBundled {
|
||||
out.writeByte(y);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void load(IonBundle bundle) throws IOException
|
||||
{
|
||||
|
||||
@@ -13,10 +13,11 @@ import mightypork.gamecore.util.math.algo.Step;
|
||||
*/
|
||||
public class PathFindingContextProxy implements PathFindingContext {
|
||||
|
||||
private PathFindingContext source;
|
||||
private final PathFindingContext source;
|
||||
|
||||
|
||||
public PathFindingContextProxy(PathFindingContext other) {
|
||||
public PathFindingContextProxy(PathFindingContext other)
|
||||
{
|
||||
this.source = other;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mightypork.gamecore.util.math.color.pal;
|
||||
|
||||
|
||||
import mightypork.gamecore.util.math.color.Color;
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mightypork.gamecore.util.math.color.pal;
|
||||
|
||||
|
||||
import mightypork.gamecore.util.math.color.Color;
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mightypork.gamecore.util.math.color.pal;
|
||||
|
||||
|
||||
import mightypork.gamecore.util.math.color.Color;
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mightypork.gamecore.util.math.color.pal;
|
||||
|
||||
|
||||
import mightypork.gamecore.util.math.color.Color;
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mightypork.gamecore.util.math.color.pal;
|
||||
|
||||
|
||||
import mightypork.gamecore.util.math.color.Color;
|
||||
|
||||
|
||||
|
||||
@@ -54,7 +54,8 @@ public abstract class Animator extends Num implements Updateable, Pauseable {
|
||||
}
|
||||
|
||||
|
||||
public void start() {
|
||||
public void start()
|
||||
{
|
||||
resume();
|
||||
}
|
||||
|
||||
@@ -78,17 +79,22 @@ public abstract class Animator extends Num implements Updateable, Pauseable {
|
||||
numAnim.reset();
|
||||
}
|
||||
|
||||
public void restart() {
|
||||
|
||||
public void restart()
|
||||
{
|
||||
reset();
|
||||
nextCycle(numAnim);
|
||||
}
|
||||
|
||||
|
||||
public void setDuration(double secs) {
|
||||
public void setDuration(double secs)
|
||||
{
|
||||
numAnim.setDefaultDuration(secs);
|
||||
}
|
||||
|
||||
public double getDuration() {
|
||||
|
||||
public double getDuration()
|
||||
{
|
||||
return numAnim.getDefaultDuration();
|
||||
}
|
||||
|
||||
@@ -111,13 +117,17 @@ public abstract class Animator extends Num implements Updateable, Pauseable {
|
||||
return num.value();
|
||||
}
|
||||
|
||||
public void setProgress(double value) {
|
||||
double target = numAnim.getEnd();
|
||||
|
||||
public void setProgress(double value)
|
||||
{
|
||||
final double target = numAnim.getEnd();
|
||||
numAnim.setTo(Calc.clamp(value, lowValue, highValue));
|
||||
numAnim.animate(target, numAnim.getDefaultDuration());
|
||||
}
|
||||
|
||||
public double getProgress() {
|
||||
|
||||
public double getProgress()
|
||||
{
|
||||
return numAnim.value();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ public abstract class TaskRepeater extends AnimatorRewind implements Runnable, E
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
public TaskRepeater(double period) {
|
||||
|
||||
public TaskRepeater(double period)
|
||||
{
|
||||
super(period);
|
||||
}
|
||||
|
||||
@@ -21,22 +23,25 @@ public abstract class TaskRepeater extends AnimatorRewind implements Runnable, E
|
||||
super.nextCycle(anim);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void enable(boolean yes)
|
||||
{
|
||||
this.enabled = yes;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isEnabled()
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(double delta)
|
||||
{
|
||||
if(!enabled) return;
|
||||
if (!enabled) return;
|
||||
|
||||
super.update(delta);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mightypork.gamecore.util.strings;
|
||||
|
||||
|
||||
/**
|
||||
* String provider with constant string
|
||||
*
|
||||
@@ -22,4 +23,4 @@ public class StringWrapper implements StringProvider {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ import mightypork.rogue.world.WorldProvider;
|
||||
public class ScreenGame extends LayeredScreen {
|
||||
|
||||
|
||||
private Random rand = new Random();
|
||||
|
||||
|
||||
private final Random rand = new Random();
|
||||
|
||||
|
||||
public ScreenGame(AppAccess app)
|
||||
{
|
||||
super(app);
|
||||
@@ -28,7 +28,7 @@ public class ScreenGame extends LayeredScreen {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
WorldProvider.get().createWorld(rand .nextLong());
|
||||
WorldProvider.get().createWorld(rand.nextLong());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,14 +17,15 @@ class MenuButton extends ClickableComponent {
|
||||
private static GLFont font = Res.getFont("main_menu_button");
|
||||
private final TextPainter painter;
|
||||
|
||||
private final VectVar offset = Vect.makeVar();
|
||||
private final VectVar offset = Vect.makeVar();
|
||||
private final Vect offsetPassive = height().div(16).toVectXY();
|
||||
private final Vect offsetPassive2 = height().div(24).toVectXY();
|
||||
|
||||
private final Color color;
|
||||
|
||||
|
||||
public MenuButton(String text, Color color) {
|
||||
public MenuButton(String text, Color color)
|
||||
{
|
||||
this.color = color;
|
||||
|
||||
this.painter = new TextPainter(font, AlignX.CENTER, this.color, text);
|
||||
|
||||
@@ -18,7 +18,8 @@ import mightypork.rogue.Res;
|
||||
|
||||
class MenuLayer extends ScreenLayer {
|
||||
|
||||
public MenuLayer(Screen screen) {
|
||||
public MenuLayer(Screen screen)
|
||||
{
|
||||
super(screen);
|
||||
|
||||
init();
|
||||
@@ -39,7 +40,7 @@ class MenuLayer extends ScreenLayer {
|
||||
root.add(layout);
|
||||
|
||||
int r = 0;
|
||||
TextPainter tp = new TextPainter(Res.getFont("main_menu_title"), AlignX.CENTER, COMMODORE.PURPLE, "Rogue!");
|
||||
final TextPainter tp = new TextPainter(Res.getFont("main_menu_title"), AlignX.CENTER, COMMODORE.PURPLE, "Rogue!");
|
||||
layout.put(tp, r, 0, 3, 1);
|
||||
r += 5;
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ import mightypork.gamecore.gui.screens.LayeredScreen;
|
||||
|
||||
public class ScreenTestBouncy extends LayeredScreen {
|
||||
|
||||
public ScreenTestBouncy(AppAccess app) {
|
||||
public ScreenTestBouncy(AppAccess app)
|
||||
{
|
||||
super(app);
|
||||
|
||||
addLayer(new LayerBouncyBoxes(this));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mightypork.rogue.world.entity;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import mightypork.gamecore.util.ion.IonBundle;
|
||||
@@ -9,20 +10,21 @@ import mightypork.gamecore.util.math.timing.TaskRepeater;
|
||||
|
||||
public abstract class AiTimer extends TaskRepeater implements IonObjBundled {
|
||||
|
||||
public AiTimer(double duration) {
|
||||
public AiTimer(double duration)
|
||||
{
|
||||
super(duration);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public abstract void run();
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void load(IonBundle bundle) throws IOException
|
||||
{
|
||||
boolean wasPaused = bundle.get("paused", isPaused());
|
||||
if(wasPaused) {
|
||||
final boolean wasPaused = bundle.get("paused", isPaused());
|
||||
if (wasPaused) {
|
||||
pause();
|
||||
} else {
|
||||
resume();
|
||||
@@ -31,14 +33,14 @@ public abstract class AiTimer extends TaskRepeater implements IonObjBundled {
|
||||
setProgress(bundle.get("progress", getProgress()));
|
||||
setDuration(bundle.get("duration", getDuration()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void save(IonBundle bundle) throws IOException
|
||||
{
|
||||
bundle.put("paused", isPaused());
|
||||
bundle.put("progress", getProgress());
|
||||
bundle.put("duration", getDuration());
|
||||
bundle.put("duration", getDuration());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,8 @@ public abstract class Entity implements IonObjBundled, Updateable {
|
||||
public final EntityModuleHealth health = new EntityModuleHealth(this);
|
||||
|
||||
|
||||
public Entity(EntityModel model, int eid) {
|
||||
public Entity(EntityModel model, int eid)
|
||||
{
|
||||
|
||||
this.entityId = eid;
|
||||
this.model = model;
|
||||
@@ -57,13 +58,13 @@ public abstract class Entity implements IonObjBundled, Updateable {
|
||||
{
|
||||
bundle.put("eid", entityId);
|
||||
|
||||
IonBundle modulesBundle = new IonBundle();
|
||||
final IonBundle modulesBundle = new IonBundle();
|
||||
for (final Entry<String, EntityModule> entry : modules.entrySet()) {
|
||||
modulesBundle.putBundled(entry.getKey(), entry.getValue());
|
||||
}
|
||||
bundle.put("modules", modulesBundle);
|
||||
|
||||
IonBundle extra = new IonBundle();
|
||||
final IonBundle extra = new IonBundle();
|
||||
saveExtra(extra);
|
||||
bundle.put("extra", extra);
|
||||
}
|
||||
@@ -81,13 +82,13 @@ public abstract class Entity implements IonObjBundled, Updateable {
|
||||
entityId = bundle.get("eid", -1);
|
||||
if (entityId < 0) throw new IllegalValueException("Bad entity id: " + entityId);
|
||||
|
||||
IonBundle modulesBundle = bundle.get("modules", new IonBundle());
|
||||
final IonBundle modulesBundle = bundle.get("modules", new IonBundle());
|
||||
|
||||
for (final Entry<String, EntityModule> entry : modules.entrySet()) {
|
||||
modulesBundle.loadBundled(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
IonBundle extra = bundle.get("extra", new IonBundle());
|
||||
final IonBundle extra = bundle.get("extra", new IonBundle());
|
||||
loadExtra(extra);
|
||||
}
|
||||
|
||||
@@ -100,9 +101,7 @@ public abstract class Entity implements IonObjBundled, Updateable {
|
||||
|
||||
protected final void addModule(String key, EntityModule module)
|
||||
{
|
||||
if (modules.containsKey(key)) {
|
||||
throw new RuntimeException("Entity module " + key + " already defined.");
|
||||
}
|
||||
if (modules.containsKey(key)) { throw new RuntimeException("Entity module " + key + " already defined."); }
|
||||
modules.put(key, module);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,10 +21,12 @@ public abstract class EntityModule implements IonObjBundled, Updateable {
|
||||
protected final Random rand = new Random();
|
||||
|
||||
|
||||
public EntityModule(Entity entity) {
|
||||
public EntityModule(Entity entity)
|
||||
{
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
|
||||
public abstract boolean isModuleSaved();
|
||||
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
|
||||
private boolean sleeping = true;
|
||||
private boolean chasing = false;
|
||||
|
||||
private AiTimer timerFindPrey = new AiTimer(3) {
|
||||
private final AiTimer timerFindPrey = new AiTimer(3) {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
@@ -34,7 +34,7 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
|
||||
}
|
||||
};
|
||||
|
||||
private AiTimer timerSleepStart = new AiTimer(10) {
|
||||
private final AiTimer timerSleepStart = new AiTimer(10) {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
@@ -49,7 +49,8 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
|
||||
private int targetId = -1;
|
||||
|
||||
|
||||
public MonsterAi(final Entity entity) {
|
||||
public MonsterAi(final Entity entity)
|
||||
{
|
||||
super(entity);
|
||||
|
||||
pathfcNoDoor = new PathFindingContextProxy(entity.getPathfindingContext()) {
|
||||
@@ -57,7 +58,7 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
|
||||
@Override
|
||||
public boolean isAccessible(Coord pos)
|
||||
{
|
||||
Tile t = entity.getLevel().getTile(pos);
|
||||
final Tile t = entity.getLevel().getTile(pos);
|
||||
if (t.isDoor()) return false;
|
||||
|
||||
return super.isAccessible(pos);
|
||||
@@ -70,15 +71,14 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
|
||||
private void lookForTarget()
|
||||
{
|
||||
if (rand.nextInt(3) == 0) return; // not hungry right now
|
||||
|
||||
Entity prey = entity.getLevel().getClosestEntity(entity, EntityType.PLAYER, getScanRadius());
|
||||
|
||||
final Entity prey = entity.getLevel().getClosestEntity(entity, EntityType.PLAYER, getScanRadius());
|
||||
if (prey != null) {
|
||||
|
||||
// check if reachable without leaving room
|
||||
List<Coord> noDoorPath = PathFinder.findPath(pathfcNoDoor, entity.getCoord(), prey.getCoord());
|
||||
final List<Coord> noDoorPath = PathFinder.findPath(pathfcNoDoor, entity.getCoord(), prey.getCoord());
|
||||
|
||||
if (noDoorPath == null) {
|
||||
return; // cant reach, give up
|
||||
if (noDoorPath == null) { return; // cant reach, give up
|
||||
}
|
||||
|
||||
startChasing(prey);
|
||||
@@ -136,7 +136,7 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
|
||||
public void onStepFinished()
|
||||
{
|
||||
if (chasing) {
|
||||
Entity prey = entity.getLevel().getEntity(targetId);
|
||||
final Entity prey = entity.getLevel().getEntity(targetId);
|
||||
if (prey == null || prey.isDead()) {
|
||||
stopChasing();
|
||||
return;
|
||||
@@ -153,13 +153,13 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
|
||||
private void stepTowardsPrey(Entity prey)
|
||||
{
|
||||
// if close enough
|
||||
Coord preyPos = prey.getCoord();
|
||||
if(preyPos.dist(entity.getCoord()) <= 1.5) {
|
||||
final Coord preyPos = prey.getCoord();
|
||||
if (preyPos.dist(entity.getCoord()) <= 1.5) {
|
||||
attackPrey(prey);
|
||||
return;
|
||||
}
|
||||
|
||||
List<Step> preyPath = getPathToPrey(prey);
|
||||
final List<Step> preyPath = getPathToPrey(prey);
|
||||
|
||||
if (preyPath.size() > getPreyAbandonDistance()) {
|
||||
stopChasing();
|
||||
@@ -174,13 +174,14 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
|
||||
{
|
||||
prey.receiveAttack(entity, getAttackStrength());
|
||||
}
|
||||
|
||||
|
||||
protected int getAttackStrength() {
|
||||
|
||||
|
||||
protected int getAttackStrength()
|
||||
{
|
||||
return 1; // For override
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onPathFinished()
|
||||
{
|
||||
|
||||
@@ -14,7 +14,8 @@ public class PlayerEntity extends Entity {
|
||||
|
||||
class PlayerAi extends EntityModule implements EntityMoveListener {
|
||||
|
||||
public PlayerAi(Entity entity) {
|
||||
public PlayerAi(Entity entity)
|
||||
{
|
||||
super(entity);
|
||||
}
|
||||
|
||||
@@ -46,13 +47,14 @@ public class PlayerEntity extends Entity {
|
||||
|
||||
}
|
||||
|
||||
private EntityPathfindingContext pathfc;
|
||||
private EntityPathfindingContext pathfc;
|
||||
private EntityRenderer renderer;
|
||||
|
||||
private final PlayerAi ai = new PlayerAi(this);
|
||||
|
||||
|
||||
public PlayerEntity(EntityModel model, int eid) {
|
||||
public PlayerEntity(EntityModel model, int eid)
|
||||
{
|
||||
super(model, eid);
|
||||
|
||||
pos.setStepTime(0.25);
|
||||
@@ -72,9 +74,7 @@ public class PlayerEntity extends Entity {
|
||||
public int getCost(Coord from, Coord to)
|
||||
{
|
||||
|
||||
if (!getLevel().getTile(pos.getCoord()).isExplored()) {
|
||||
return 1000;
|
||||
}
|
||||
if (!getLevel().getTile(pos.getCoord()).isExplored()) { return 1000; }
|
||||
|
||||
return super.getCost(from, to);
|
||||
|
||||
@@ -104,6 +104,7 @@ public class PlayerEntity extends Entity {
|
||||
return renderer;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EntityType getType()
|
||||
{
|
||||
|
||||
@@ -10,15 +10,17 @@ public abstract class SimpleMonster extends Entity {
|
||||
/** Navigation PFC */
|
||||
private EntityPathfindingContext pathfc;
|
||||
|
||||
private EntityModule ai = new MonsterAi(this);
|
||||
private final EntityModule ai = new MonsterAi(this);
|
||||
|
||||
public SimpleMonster(EntityModel model, int eid) {
|
||||
|
||||
public SimpleMonster(EntityModel model, int eid)
|
||||
{
|
||||
super(model, eid);
|
||||
|
||||
addModule("ai", ai);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public PathFindingContext getPathfindingContext()
|
||||
{
|
||||
@@ -29,6 +31,7 @@ public abstract class SimpleMonster extends Entity {
|
||||
return pathfc;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EntityType getType()
|
||||
{
|
||||
|
||||
@@ -12,7 +12,8 @@ import mightypork.rogue.world.entity.EntityModule;
|
||||
|
||||
public class EntityModuleHealth extends EntityModule {
|
||||
|
||||
public EntityModuleHealth(Entity entity) {
|
||||
public EntityModuleHealth(Entity entity)
|
||||
{
|
||||
super(entity);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,8 @@ public class EntityModulePosition extends EntityModule {
|
||||
|
||||
stepTime = bundle.get("step_time", stepTime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isModuleSaved()
|
||||
{
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package mightypork.rogue.world.entity.modules;
|
||||
|
||||
|
||||
|
||||
|
||||
public interface EntityMoveListener {
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,5 +19,6 @@ public interface MapTheme {
|
||||
|
||||
TileModel door();
|
||||
|
||||
|
||||
TileModel passage();
|
||||
}
|
||||
|
||||
@@ -4,11 +4,10 @@ package mightypork.rogue.world.gen.rooms;
|
||||
import java.util.Random;
|
||||
|
||||
import mightypork.gamecore.util.math.algo.Coord;
|
||||
import mightypork.gamecore.util.math.algo.Sides;
|
||||
import mightypork.rogue.world.gen.MapTheme;
|
||||
import mightypork.rogue.world.gen.RoomBuilder;
|
||||
import mightypork.rogue.world.gen.RoomDesc;
|
||||
import mightypork.rogue.world.gen.ScratchMap;
|
||||
import mightypork.rogue.world.gen.MapTheme;
|
||||
|
||||
|
||||
public class DeadEndRoom implements RoomBuilder {
|
||||
@@ -16,8 +15,8 @@ public class DeadEndRoom implements RoomBuilder {
|
||||
@Override
|
||||
public RoomDesc buildToFit(ScratchMap map, MapTheme theme, Random rand, Coord center)
|
||||
{
|
||||
Coord low = center.add(-1, -1);
|
||||
Coord high = center;
|
||||
final Coord low = center.add(-1, -1);
|
||||
final Coord high = center;
|
||||
if (!map.isClear(low, high)) return null;
|
||||
|
||||
map.set(center, theme.floor());
|
||||
|
||||
@@ -5,10 +5,10 @@ import java.util.Random;
|
||||
|
||||
import mightypork.gamecore.util.math.algo.Coord;
|
||||
import mightypork.gamecore.util.math.algo.Sides;
|
||||
import mightypork.rogue.world.gen.MapTheme;
|
||||
import mightypork.rogue.world.gen.RoomBuilder;
|
||||
import mightypork.rogue.world.gen.RoomDesc;
|
||||
import mightypork.rogue.world.gen.ScratchMap;
|
||||
import mightypork.rogue.world.gen.MapTheme;
|
||||
import mightypork.rogue.world.tile.TileModel;
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class SimpleRectRoom implements RoomBuilder {
|
||||
map.border(min, max, theme.wall());
|
||||
map.protect(min, max);
|
||||
|
||||
boolean holes = rand.nextInt(4) == 0;
|
||||
final boolean holes = rand.nextInt(4) == 0;
|
||||
|
||||
for (int i = 0; i <= 2 + rand.nextInt(6); i++) {
|
||||
final Coord door = min.copy();
|
||||
|
||||
@@ -2,7 +2,11 @@ package mightypork.rogue.world.level;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import mightypork.gamecore.logging.Log;
|
||||
import mightypork.gamecore.util.ion.IonBundle;
|
||||
@@ -21,7 +25,6 @@ import mightypork.rogue.world.entity.Entity;
|
||||
import mightypork.rogue.world.entity.EntityType;
|
||||
import mightypork.rogue.world.tile.Tile;
|
||||
import mightypork.rogue.world.tile.TileModel;
|
||||
import mightypork.rogue.world.tile.TileType;
|
||||
import mightypork.rogue.world.tile.Tiles;
|
||||
|
||||
|
||||
@@ -51,11 +54,13 @@ public class Level implements MapAccess, IonObjBinary {
|
||||
private transient NoiseGen noiseGen;
|
||||
|
||||
|
||||
public Level() {
|
||||
public Level()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public Level(int width, int height) {
|
||||
public Level(int width, int height)
|
||||
{
|
||||
size.setTo(width, height);
|
||||
buildArray();
|
||||
}
|
||||
@@ -87,7 +92,7 @@ public class Level implements MapAccess, IonObjBinary {
|
||||
public final Tile getTile(Coord pos)
|
||||
{
|
||||
if (!pos.isInRange(0, 0, size.x - 1, size.y - 1)) return Tiles.NULL.createTile(); // out of range
|
||||
|
||||
|
||||
return tiles[pos.y][pos.x];
|
||||
}
|
||||
|
||||
@@ -290,17 +295,18 @@ public class Level implements MapAccess, IonObjBinary {
|
||||
getTile(pos).setOccupied(false);
|
||||
}
|
||||
|
||||
public void cleanCorpses() {
|
||||
for(Iterator<Entity> i = entitySet.iterator(); i.hasNext();) {
|
||||
Entity e = i.next();
|
||||
|
||||
if(e.isDead() && e.canRemoveCorpse()) {
|
||||
|
||||
public void cleanCorpses()
|
||||
{
|
||||
for (final Entity e : entitySet) {
|
||||
if (e.isDead() && e.canRemoveCorpse()) {
|
||||
e.onCorpseRemoved();
|
||||
removeEntity(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Collection<Entity> getEntities()
|
||||
{
|
||||
return entitySet;
|
||||
@@ -387,12 +393,12 @@ public class Level implements MapAccess, IonObjBinary {
|
||||
Entity closest = null;
|
||||
double minDist = Double.MAX_VALUE;
|
||||
|
||||
for (Entity e : entitySet) {
|
||||
for (final Entity e : entitySet) {
|
||||
if (e == self) continue;
|
||||
if (e.isDead()) continue;
|
||||
|
||||
if (e.getType() == type) {
|
||||
double dist = e.getCoord().dist(self.getCoord());
|
||||
final double dist = e.getCoord().dist(self.getCoord());
|
||||
|
||||
if (dist <= radius && dist < minDist) {
|
||||
minDist = dist;
|
||||
|
||||
@@ -2,7 +2,6 @@ package mightypork.rogue.world.tile.renderers;
|
||||
|
||||
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.gamecore.resources.textures.TxQuad;
|
||||
import mightypork.gamecore.resources.textures.TxSheet;
|
||||
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
||||
import mightypork.rogue.Res;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mightypork.rogue.world.tile.tiles;
|
||||
|
||||
|
||||
import mightypork.rogue.world.tile.TileModel;
|
||||
import mightypork.rogue.world.tile.TileRenderer;
|
||||
import mightypork.rogue.world.tile.TileType;
|
||||
@@ -11,17 +12,20 @@ import mightypork.rogue.world.tile.TileType;
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class WallPassageTile extends SolidTile {
|
||||
|
||||
public WallPassageTile(TileModel model, TileRenderer renderer) {
|
||||
|
||||
public WallPassageTile(TileModel model, TileRenderer renderer)
|
||||
{
|
||||
super(model, renderer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public TileType getType()
|
||||
{
|
||||
return TileType.PASSAGE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isWalkable()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user