cleanup & format

This commit is contained in:
Ondřej Hruška
2014-05-01 01:16:59 +02:00
parent 9206396c8e
commit 7d3695d0a9
40 changed files with 176 additions and 126 deletions
@@ -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));
+10 -8
View File
@@ -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();
+18 -12
View File
@@ -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()
{