cleanup & reorg

v5stable
Ondřej Hruška 11 years ago
parent 0771a5e0d8
commit 83f21ca8c5
  1. 1
      src/mightypork/rogue/App.java
  2. 2
      src/mightypork/rogue/screens/gamescreen/HeartBar.java
  3. 4
      src/mightypork/rogue/screens/gamescreen/HudLayer.java
  4. 2
      src/mightypork/rogue/screens/gamescreen/NavItemSlot.java
  5. 1
      src/mightypork/rogue/screens/gamescreen/ScreenGame.java
  6. 6
      src/mightypork/rogue/screens/gamescreen/WorldLayer.java
  7. 8
      src/mightypork/rogue/world/PlayerControl.java
  8. 2
      src/mightypork/rogue/world/World.java
  9. 13
      src/mightypork/rogue/world/WorldProvider.java
  10. 9
      src/mightypork/rogue/world/WorldRenderer.java
  11. 20
      src/mightypork/rogue/world/entity/Entities.java
  12. 10
      src/mightypork/rogue/world/entity/Entity.java
  13. 9
      src/mightypork/rogue/world/entity/EntityModel.java
  14. 3
      src/mightypork/rogue/world/entity/EntityModule.java
  15. 3
      src/mightypork/rogue/world/entity/EntityPathfindingContext.java
  16. 6
      src/mightypork/rogue/world/entity/SimpleEntityPathFindingContext.java
  17. 9
      src/mightypork/rogue/world/entity/entities/PlayerEntity.java
  18. 4
      src/mightypork/rogue/world/entity/modules/EntityModuleHealth.java
  19. 6
      src/mightypork/rogue/world/entity/modules/EntityModulePosition.java
  20. 3
      src/mightypork/rogue/world/entity/modules/EntityMoveListener.java
  21. 2
      src/mightypork/rogue/world/entity/modules/EntityPos.java
  22. 3
      src/mightypork/rogue/world/entity/renderers/EntityRenderer.java
  23. 3
      src/mightypork/rogue/world/entity/renderers/SimpleLeftRightMobRenderer.java
  24. 4
      src/mightypork/rogue/world/gen/LevelGenerator.java
  25. 6
      src/mightypork/rogue/world/gen/ScratchMap.java
  26. 17
      src/mightypork/rogue/world/gui/MapView.java
  27. 9
      src/mightypork/rogue/world/gui/Minimap.java
  28. 3
      src/mightypork/rogue/world/gui/interaction/MIPClickPathfWalk.java
  29. 3
      src/mightypork/rogue/world/gui/interaction/MIPKeyWalk.java
  30. 3
      src/mightypork/rogue/world/gui/interaction/MIPMouseWalk.java
  31. 3
      src/mightypork/rogue/world/gui/interaction/MapInteractionPlugin.java
  32. 16
      src/mightypork/rogue/world/level/Level.java
  33. 2
      src/mightypork/rogue/world/pathfinding/FillContext.java
  34. 17
      src/mightypork/rogue/world/pathfinding/FloodFill.java
  35. 3
      src/mightypork/rogue/world/tile/Tile.java
  36. 4
      src/mightypork/rogue/world/tile/TileModel.java
  37. 4
      src/mightypork/rogue/world/tile/TileRenderer.java
  38. 3
      src/mightypork/rogue/world/tile/TileType.java
  39. 6
      src/mightypork/rogue/world/tile/Tiles.java
  40. 2
      src/mightypork/rogue/world/tile/tiles/DoorTile.java
  41. 8
      src/mightypork/rogue/world/tile/tiles/GroundTile.java
  42. 1
      src/mightypork/rogue/world/tile/tiles/LockedDoorTile.java
  43. 1
      src/mightypork/rogue/world/tile/tiles/NullTile.java
  44. 6
      src/mightypork/rogue/world/tile/tiles/SolidTile.java
  45. 2
      src/mightypork/rogue/world/tile/tiles/WallTile.java
  46. 15
      src/mightypork/util/error/IllegalValueException.java
  47. 2
      src/mightypork/util/files/ion/IonBinary.java

@ -113,6 +113,7 @@ public final class App extends BaseApp {
Ion.registerBinary(Level.ION_MARK, Level.class); Ion.registerBinary(Level.ION_MARK, Level.class);
} }
@Override @Override
protected void postInit() protected void postInit()
{ {

@ -1,4 +1,4 @@
package mightypork.rogue.screens.gamescreen.gui; package mightypork.rogue.screens.gamescreen;
import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.AlignX;

@ -9,9 +9,7 @@ import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys; import mightypork.gamecore.input.Keys;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.screens.gamescreen.gui.HeartBar; import mightypork.rogue.world.gui.Minimap;
import mightypork.rogue.screens.gamescreen.gui.NavItemSlot;
import mightypork.rogue.screens.gamescreen.world.Minimap;
import mightypork.util.math.constraints.num.Num; import mightypork.util.math.constraints.num.Num;
import mightypork.util.math.constraints.rect.Rect; import mightypork.util.math.constraints.rect.Rect;

@ -1,4 +1,4 @@
package mightypork.rogue.screens.gamescreen.gui; package mightypork.rogue.screens.gamescreen;
import mightypork.gamecore.control.events.input.MouseMotionEvent; import mightypork.gamecore.control.events.input.MouseMotionEvent;

@ -32,6 +32,7 @@ public class ScreenGame extends LayeredScreen {
WorldProvider.get().setListening(true); WorldProvider.get().setListening(true);
} }
@Override @Override
protected void onScreenLeave() protected void onScreenLeave()
{ {

@ -3,9 +3,9 @@ package mightypork.rogue.screens.gamescreen;
import mightypork.gamecore.gui.screens.Screen; import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.rogue.screens.gamescreen.world.MIPClickPathfWalk; import mightypork.rogue.world.gui.MapView;
import mightypork.rogue.screens.gamescreen.world.MIPKeyWalk; import mightypork.rogue.world.gui.interaction.MIPClickPathfWalk;
import mightypork.rogue.screens.gamescreen.world.MapView; import mightypork.rogue.world.gui.interaction.MIPKeyWalk;
import mightypork.util.math.constraints.num.Num; import mightypork.util.math.constraints.num.Num;

@ -22,10 +22,10 @@ public abstract class PlayerControl {
private World getWorld2() private World getWorld2()
{ {
World newWorld = getWorld(); final World newWorld = getWorld();
if (newWorld != lastWorld) { if (newWorld != lastWorld) {
for (EntityMoveListener eml : playerMoveListeners) { for (final EntityMoveListener eml : playerMoveListeners) {
newWorld.getPlayerEntity().pos.addMoveListener(eml); newWorld.getPlayerEntity().pos.addMoveListener(eml);
} }
} }
@ -39,7 +39,7 @@ public abstract class PlayerControl {
private Entity getPlayerEntity() private Entity getPlayerEntity()
{ {
if(getWorld2() == null) return null; if (getWorld2() == null) return null;
return getWorld2().getPlayerEntity(); return getWorld2().getPlayerEntity();
} }
@ -82,7 +82,7 @@ public abstract class PlayerControl {
public void addMoveListener(EntityMoveListener eml) public void addMoveListener(EntityMoveListener eml)
{ {
playerMoveListeners.add(eml); playerMoveListeners.add(eml);
if(getPlayerEntity() != null) { if (getPlayerEntity() != null) {
getPlayerEntity().pos.addMoveListener(eml); getPlayerEntity().pos.addMoveListener(eml);
} }
} }

@ -46,7 +46,7 @@ public class World implements IonBundled, Updateable {
in.loadBundled("player", playerInfo); in.loadBundled("player", playerInfo);
playerEntity = levels.get(playerInfo.getLevel()).getEntity(playerInfo.getEID()); playerEntity = levels.get(playerInfo.getLevel()).getEntity(playerInfo.getEID());
if(playerEntity == null) throw new RuntimeException("Player entity not found in the world."); if (playerEntity == null) throw new RuntimeException("Player entity not found in the world.");
} }

@ -11,7 +11,7 @@ import mightypork.util.control.eventbus.clients.RootBusNode;
import mightypork.util.files.ion.Ion; import mightypork.util.files.ion.Ion;
public class WorldProvider extends RootBusNode{ public class WorldProvider extends RootBusNode {
public static synchronized void init(BusAccess busAccess) public static synchronized void init(BusAccess busAccess)
{ {
@ -21,7 +21,8 @@ public class WorldProvider extends RootBusNode{
} }
public WorldProvider(BusAccess busAccess) { public WorldProvider(BusAccess busAccess)
{
super(busAccess); super(busAccess);
setListening(false); setListening(false);
} }
@ -31,9 +32,7 @@ public class WorldProvider extends RootBusNode{
public static WorldProvider get() public static WorldProvider get()
{ {
if (inst == null) { if (inst == null) { throw new IllegalStateException("World provider not initialized."); }
throw new IllegalStateException("World provider not initialized.");
}
return inst; return inst;
} }
@ -60,7 +59,9 @@ public class WorldProvider extends RootBusNode{
return world; return world;
} }
private void setWorld(World newWorld) {
private void setWorld(World newWorld)
{
if (world != null) removeChildClient(world); if (world != null) removeChildClient(world);
world = newWorld; world = newWorld;

@ -38,7 +38,8 @@ public class WorldRenderer extends RectProxy {
private TileRenderContext trc; private TileRenderContext trc;
public WorldRenderer(Rect viewport, Num tileSize) { public WorldRenderer(Rect viewport, Num tileSize)
{
super(viewport); super(viewport);
this.tileSize = tileSize; this.tileSize = tileSize;
@ -69,7 +70,7 @@ public class WorldRenderer extends RectProxy {
private VectConst getOffset() private VectConst getOffset()
{ {
Entity ent = WorldProvider.get().getPlayerEntity(); final Entity ent = WorldProvider.get().getPlayerEntity();
return Vect.make(ent.pos.getVisualPos().neg().sub(0.5, 0.5)).freeze(); return Vect.make(ent.pos.getVisualPos().neg().sub(0.5, 0.5)).freeze();
} }
@ -85,7 +86,7 @@ public class WorldRenderer extends RectProxy {
Render.translate(getOffset()); Render.translate(getOffset());
// tiles to render // tiles to render
Entity ent = WorldProvider.get().getPlayerEntity(); final Entity ent = WorldProvider.get().getPlayerEntity();
final Coord pos = ent.pos.getCoord(); final Coord pos = ent.pos.getCoord();
final double w = width().value(); final double w = width().value();
@ -131,7 +132,7 @@ public class WorldRenderer extends RectProxy {
for (final Entity e : activeLevel.getEntities()) { for (final Entity e : activeLevel.getEntities()) {
// avoid entities out of view rect // avoid entities out of view rect
Vect entPos = e.pos.getVisualPos(); final Vect entPos = e.pos.getVisualPos();
final int x = (int) Math.round(entPos.x()); final int x = (int) Math.round(entPos.x());
final int y = (int) Math.round(entPos.y()); final int y = (int) Math.round(entPos.y());

@ -23,13 +23,9 @@ public final class Entities {
public static void register(int id, EntityModel model) public static void register(int id, EntityModel model)
{ {
if (id < 0 || id >= entities.length) { if (id < 0 || id >= entities.length) { throw new IllegalArgumentException("Entity model ID " + id + " is out of range."); }
throw new IllegalArgumentException("Entity model ID " + id + " is out of range.");
}
if (entities[id] != null) { if (entities[id] != null) { throw new IllegalArgumentException("Entity model ID " + id + " already in use."); }
throw new IllegalArgumentException("Entity model ID " + id + " already in use.");
}
entities[id] = model; entities[id] = model;
} }
@ -39,9 +35,7 @@ public final class Entities {
{ {
final EntityModel e = entities[id]; final EntityModel e = entities[id];
if (e == null) { if (e == null) { throw new IllegalArgumentException("No entity model with ID " + id + "."); }
throw new IllegalArgumentException("No entity model with ID " + id + ".");
}
return e; return e;
} }
@ -58,7 +52,7 @@ public final class Entities {
public static void saveEntities(IonOutput out, Collection<Entity> entities) throws IOException public static void saveEntities(IonOutput out, Collection<Entity> entities) throws IOException
{ {
for (Entity entity : entities) { for (final Entity entity : entities) {
out.startEntry(); out.startEntry();
saveEntity(out, entity); saveEntity(out, entity);
} }
@ -69,16 +63,16 @@ public final class Entities {
public static Entity loadEntity(IonInput in) throws IOException public static Entity loadEntity(IonInput in) throws IOException
{ {
int id = in.readIntByte(); final int id = in.readIntByte();
EntityModel model = get(id); final EntityModel model = get(id);
return model.loadEntity(in); return model.loadEntity(in);
} }
public static void saveEntity(IonOutput out, Entity entity) throws IOException public static void saveEntity(IonOutput out, Entity entity) throws IOException
{ {
EntityModel model = entity.getModel(); final EntityModel model = entity.getModel();
out.writeIntByte(model.id); out.writeIntByte(model.id);

@ -7,7 +7,6 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import mightypork.rogue.world.World; import mightypork.rogue.world.World;
import mightypork.rogue.world.entity.modules.EntityModule;
import mightypork.rogue.world.entity.modules.EntityModuleHealth; import mightypork.rogue.world.entity.modules.EntityModuleHealth;
import mightypork.rogue.world.entity.modules.EntityModulePosition; import mightypork.rogue.world.entity.modules.EntityModulePosition;
import mightypork.rogue.world.entity.modules.EntityMoveListener; import mightypork.rogue.world.entity.modules.EntityMoveListener;
@ -41,7 +40,8 @@ public abstract class Entity implements IonBundled, Updateable, EntityMoveListen
public final EntityModuleHealth health = new EntityModuleHealth(this); public final EntityModuleHealth health = new EntityModuleHealth(this);
public Entity(EntityModel model, int eid) { public Entity(EntityModel model, int eid)
{
this.entityId = eid; this.entityId = eid;
this.model = model; this.model = model;
@ -57,7 +57,7 @@ public abstract class Entity implements IonBundled, Updateable, EntityMoveListen
public void save(IonBundle bundle) throws IOException public void save(IonBundle bundle) throws IOException
{ {
bundle.put("eid", entityId); bundle.put("eid", entityId);
for (Entry<String, EntityModule> entry : modules.entrySet()) { for (final Entry<String, EntityModule> entry : modules.entrySet()) {
bundle.putBundled(entry.getKey(), entry.getValue()); bundle.putBundled(entry.getKey(), entry.getValue());
} }
} }
@ -69,7 +69,7 @@ public abstract class Entity implements IonBundled, Updateable, EntityMoveListen
entityId = bundle.get("eid", -1); entityId = bundle.get("eid", -1);
if (entityId < 0) throw new IllegalValueException("Bad entity id: " + entityId); if (entityId < 0) throw new IllegalValueException("Bad entity id: " + entityId);
for (Entry<String, EntityModule> entry : modules.entrySet()) { for (final Entry<String, EntityModule> entry : modules.entrySet()) {
bundle.loadBundled(entry.getKey(), entry.getValue()); bundle.loadBundled(entry.getKey(), entry.getValue());
} }
} }
@ -117,7 +117,7 @@ public abstract class Entity implements IonBundled, Updateable, EntityMoveListen
@Override @Override
public void update(double delta) public void update(double delta)
{ {
for (Entry<String, EntityModule> entry : modules.entrySet()) { for (final Entry<String, EntityModule> entry : modules.entrySet()) {
entry.getValue().update(delta); entry.getValue().update(delta);
} }
} }

@ -27,11 +27,12 @@ public final class EntityModel {
this.tileClass = entity; this.tileClass = entity;
} }
public Entity createEntity(int eid) public Entity createEntity(int eid)
{ {
try { try {
return tileClass.getConstructor(EntityModel.class, int.class).newInstance(this, eid); return tileClass.getConstructor(EntityModel.class, int.class).newInstance(this, eid);
} catch (Exception e) { } catch (final Exception e) {
throw new RuntimeException("Could not instantiate a tile.", e); throw new RuntimeException("Could not instantiate a tile.", e);
} }
} }
@ -39,8 +40,8 @@ public final class EntityModel {
public Entity loadEntity(IonInput in) throws IOException public Entity loadEntity(IonInput in) throws IOException
{ {
IonBundle bundle = in.readBundle(); final IonBundle bundle = in.readBundle();
Entity ent = createEntity(-1); final Entity ent = createEntity(-1);
ent.load(bundle); ent.load(bundle);
return ent; return ent;
} }
@ -48,7 +49,7 @@ public final class EntityModel {
public void saveEntity(IonOutput out, Entity entity) throws IOException public void saveEntity(IonOutput out, Entity entity) throws IOException
{ {
IonBundle bundle = new IonBundle(); final IonBundle bundle = new IonBundle();
entity.save(bundle); entity.save(bundle);
out.writeBundle(bundle); out.writeBundle(bundle);
} }

@ -1,4 +1,5 @@
package mightypork.rogue.world.entity.modules; package mightypork.rogue.world.entity;
import mightypork.util.files.ion.IonBundled; import mightypork.util.files.ion.IonBundled;
import mightypork.util.timing.Updateable; import mightypork.util.timing.Updateable;

@ -13,7 +13,8 @@ public abstract class EntityPathfindingContext implements PathFindingContext {
protected final Entity entity; protected final Entity entity;
public EntityPathfindingContext(Entity entity) { public EntityPathfindingContext(Entity entity)
{
this.entity = entity; this.entity = entity;
} }

@ -1,20 +1,24 @@
package mightypork.rogue.world.entity; package mightypork.rogue.world.entity;
import mightypork.rogue.world.Coord; import mightypork.rogue.world.Coord;
public class SimpleEntityPathFindingContext extends EntityPathfindingContext { public class SimpleEntityPathFindingContext extends EntityPathfindingContext {
public SimpleEntityPathFindingContext(Entity entity) { public SimpleEntityPathFindingContext(Entity entity)
{
super(entity); super(entity);
} }
@Override @Override
public int getCost(Coord from, Coord to) public int getCost(Coord from, Coord to)
{ {
return 10; return 10;
} }
@Override @Override
public int getMinCost() public int getMinCost()
{ {

@ -21,9 +21,7 @@ public class PlayerEntity extends Entity {
public int getCost(Coord from, Coord to) public int getCost(Coord from, Coord to)
{ {
if (!getLevel().getTile(pos.getCoord()).isExplored()) { if (!getLevel().getTile(pos.getCoord()).isExplored()) { return 1000; }
return 1000;
}
return super.getCost(from, to); return super.getCost(from, to);
@ -33,7 +31,8 @@ public class PlayerEntity extends Entity {
private final EntityRenderer renderer = new SimpleLeftRightMobRenderer(this, "sprite.player"); private final EntityRenderer renderer = new SimpleLeftRightMobRenderer(this, "sprite.player");
public PlayerEntity(EntityModel model, int eid) { public PlayerEntity(EntityModel model, int eid)
{
super(model, eid); super(model, eid);
// init default values // init default values
@ -47,6 +46,7 @@ public class PlayerEntity extends Entity {
return pathfc; return pathfc;
} }
@Override @Override
public void setLevel(Level level) public void setLevel(Level level)
{ {
@ -61,6 +61,7 @@ public class PlayerEntity extends Entity {
renderer.render(context); renderer.render(context);
} }
@Override @Override
public void onStepFinished(Entity entity) public void onStepFinished(Entity entity)
{ {

@ -4,6 +4,7 @@ package mightypork.rogue.world.entity.modules;
import java.io.IOException; import java.io.IOException;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityModule;
import mightypork.util.error.IllegalValueException; import mightypork.util.error.IllegalValueException;
import mightypork.util.files.ion.IonBundle; import mightypork.util.files.ion.IonBundle;
import mightypork.util.math.Calc; import mightypork.util.math.Calc;
@ -11,7 +12,8 @@ import mightypork.util.math.Calc;
public class EntityModuleHealth implements EntityModule { public class EntityModuleHealth implements EntityModule {
public EntityModuleHealth(Entity entity) { public EntityModuleHealth(Entity entity)
{
this.entity = entity; this.entity = entity;
} }

@ -10,6 +10,7 @@ import java.util.Set;
import mightypork.rogue.world.Coord; import mightypork.rogue.world.Coord;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityModule;
import mightypork.rogue.world.entity.PathStep; import mightypork.rogue.world.entity.PathStep;
import mightypork.rogue.world.pathfinding.PathFinder; import mightypork.rogue.world.pathfinding.PathFinder;
import mightypork.rogue.world.pathfinding.PathFindingContext; import mightypork.rogue.world.pathfinding.PathFindingContext;
@ -36,7 +37,8 @@ public class EntityModulePosition implements EntityModule {
private final Set<EntityMoveListener> moveListeners = new LinkedHashSet<>(); private final Set<EntityMoveListener> moveListeners = new LinkedHashSet<>();
public EntityModulePosition(Entity entity) { public EntityModulePosition(Entity entity)
{
this.entity = entity; this.entity = entity;
} }
@ -144,7 +146,7 @@ public class EntityModulePosition implements EntityModule {
public boolean navigateTo(Coord target) public boolean navigateTo(Coord target)
{ {
if (target.equals(getCoord())) return true; if (target.equals(getCoord())) return true;
PathFindingContext pfc = entity.getPathfindingContext(); final PathFindingContext pfc = entity.getPathfindingContext();
final List<PathStep> newPath = PathFinder.findPathRelative(pfc, entityPos.getCoord(), target); final List<PathStep> newPath = PathFinder.findPathRelative(pfc, entityPos.getCoord(), target);
if (newPath == null) return false; if (newPath == null) return false;

@ -1,8 +1,7 @@
package mightypork.rogue.world.entity.modules; package mightypork.rogue.world.entity.modules;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.Entity;
public interface EntityMoveListener { public interface EntityMoveListener {

@ -181,6 +181,6 @@ public class EntityPos implements IonBundled, Updateable {
public VectConst getVisualPos() public VectConst getVisualPos()
{ {
return Vect.make(walkOffset.x()+coord.x, walkOffset.y()+coord.y); return Vect.make(walkOffset.x() + coord.x, walkOffset.y() + coord.y);
} }
} }

@ -10,7 +10,8 @@ public abstract class EntityRenderer {
protected final Entity entity; protected final Entity entity;
public EntityRenderer(Entity entity) { public EntityRenderer(Entity entity)
{
this.entity = entity; this.entity = entity;
} }

@ -17,7 +17,8 @@ public class SimpleLeftRightMobRenderer extends EntityRenderer {
private final TxSheet sheet; private final TxSheet sheet;
public SimpleLeftRightMobRenderer(Entity entity, String sheetKey) { public SimpleLeftRightMobRenderer(Entity entity, String sheetKey)
{
super(entity); super(entity);
this.sheet = Res.getTxSheet(sheetKey); this.sheet = Res.getTxSheet(sheetKey);
} }

@ -29,9 +29,9 @@ public class LevelGenerator {
// start // start
map.addRoom(ROOM_SQUARE); map.addRoom(ROOM_SQUARE);
for (int i = 0; i < 2+complexity/2+rand.nextInt((int) (1+complexity*0.3)); i++) { for (int i = 0; i < 2 + complexity / 2 + rand.nextInt((int) (1 + complexity * 0.3)); i++) {
map.addRoom(ROOM_SQUARE); map.addRoom(ROOM_SQUARE);
if(rand.nextInt(4)>0) map.addRoom(DEAD_END); if (rand.nextInt(4) > 0) map.addRoom(DEAD_END);
} }
map.buildCorridors(); map.buildCorridors();

@ -77,8 +77,10 @@ public class ScratchMap {
return PathFinder.CORNER_HEURISTIC; return PathFinder.CORNER_HEURISTIC;
} }
@Override @Override
public Coord[] getWalkSides() { public Coord[] getWalkSides()
{
return Sides.cardinalSides; return Sides.cardinalSides;
} }
@ -261,7 +263,7 @@ public class ScratchMap {
Log.f3("Building corridors."); Log.f3("Building corridors.");
Coord start = nodes.get(0); Coord start = nodes.get(0);
Set<Coord> starts = new HashSet<>(); final Set<Coord> starts = new HashSet<>();
for (int i = 0; i < 2 + rooms.size() / 5; i++) { for (int i = 0; i < 2 + rooms.size() / 5; i++) {
if (!starts.contains(start)) { if (!starts.contains(start)) {

@ -1,4 +1,4 @@
package mightypork.rogue.screens.gamescreen.world; package mightypork.rogue.world.gui;
import java.util.HashSet; import java.util.HashSet;
@ -16,6 +16,7 @@ import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.WorldRenderer; import mightypork.rogue.world.WorldRenderer;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.modules.EntityMoveListener; import mightypork.rogue.world.entity.modules.EntityMoveListener;
import mightypork.rogue.world.gui.interaction.MapInteractionPlugin;
import mightypork.util.math.Easing; import mightypork.util.math.Easing;
import mightypork.util.math.constraints.num.Num; import mightypork.util.math.constraints.num.Num;
import mightypork.util.math.constraints.num.mutable.NumAnimated; import mightypork.util.math.constraints.num.mutable.NumAnimated;
@ -23,6 +24,11 @@ import mightypork.util.math.constraints.vect.Vect;
import mightypork.util.timing.Updateable; import mightypork.util.timing.Updateable;
/**
* Level display component
*
* @author MightyPork
*/
public class MapView extends InputComponent implements KeyListener, MouseButtonListener, EntityMoveListener, Updateable { public class MapView extends InputComponent implements KeyListener, MouseButtonListener, EntityMoveListener, Updateable {
protected final WorldRenderer worldRenderer; protected final WorldRenderer worldRenderer;
@ -109,8 +115,8 @@ public class MapView extends InputComponent implements KeyListener, MouseButtonL
p.onKey(this, pc, event.getKey(), event.isDown()); p.onKey(this, pc, event.getKey(), event.isDown());
} }
if(event.getKey() == Keys.Z) { if (event.getKey() == Keys.Z) {
if(event.isDown()) { if (event.isDown()) {
zoom.fadeIn(1); zoom.fadeIn(1);
} else { } else {
zoom.fadeOut(1); zoom.fadeOut(1);
@ -123,6 +129,11 @@ public class MapView extends InputComponent implements KeyListener, MouseButtonL
} }
/**
* Add interaction plugin
*
* @param plugin
*/
public void addPlugin(MapInteractionPlugin plugin) public void addPlugin(MapInteractionPlugin plugin)
{ {
plugins.add(plugin); plugins.add(plugin);

@ -1,4 +1,4 @@
package mightypork.rogue.screens.gamescreen.world; package mightypork.rogue.world.gui;
import mightypork.gamecore.control.events.input.MouseButtonEvent; import mightypork.gamecore.control.events.input.MouseButtonEvent;
@ -6,7 +6,6 @@ import mightypork.gamecore.control.events.input.MouseButtonListener;
import mightypork.gamecore.gui.components.InputComponent; import mightypork.gamecore.gui.components.InputComponent;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.rogue.world.Coord; import mightypork.rogue.world.Coord;
import mightypork.rogue.world.World;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.Level;
@ -29,17 +28,15 @@ public class Minimap extends InputComponent implements MouseButtonListener {
private final Color playerColor = RGB.RED; private final Color playerColor = RGB.RED;
@Override @Override
protected void renderComponent() protected void renderComponent()
{ {
Color.pushAlpha(translucency); Color.pushAlpha(translucency);
final Level lvl = WorldProvider.get().getCurrentLevel(); final Level lvl = WorldProvider.get().getCurrentLevel();
unit = (int) Math.min(Math.max(2, Math.ceil((height().value()/2) / (lvl.getHeight() + 2))), 6); unit = (int) Math.min(Math.max(2, Math.ceil((height().value() / 2) / (lvl.getHeight() + 2))), 6);
final World w = lvl.getWorld(); final Entity e = WorldProvider.get().getPlayerEntity();
final Entity e = w.getPlayerEntity();
final Vect plCoord = e.pos.getVisualPos(); final Vect plCoord = e.pos.getVisualPos();
final int lw = lvl.getWidth(); final int lw = lvl.getWidth();

@ -1,9 +1,10 @@
package mightypork.rogue.screens.gamescreen.world; package mightypork.rogue.world.gui.interaction;
import mightypork.gamecore.input.InputSystem; import mightypork.gamecore.input.InputSystem;
import mightypork.rogue.world.Coord; import mightypork.rogue.world.Coord;
import mightypork.rogue.world.PlayerControl; import mightypork.rogue.world.PlayerControl;
import mightypork.rogue.world.gui.MapView;
import mightypork.util.math.constraints.vect.Vect; import mightypork.util.math.constraints.vect.Vect;

@ -1,9 +1,10 @@
package mightypork.rogue.screens.gamescreen.world; package mightypork.rogue.world.gui.interaction;
import mightypork.gamecore.input.InputSystem; import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.input.Keys; import mightypork.gamecore.input.Keys;
import mightypork.rogue.world.PlayerControl; import mightypork.rogue.world.PlayerControl;
import mightypork.rogue.world.gui.MapView;
import mightypork.util.math.constraints.vect.Vect; import mightypork.util.math.constraints.vect.Vect;

@ -1,9 +1,10 @@
package mightypork.rogue.screens.gamescreen.world; package mightypork.rogue.world.gui.interaction;
import mightypork.gamecore.input.InputSystem; import mightypork.gamecore.input.InputSystem;
import mightypork.rogue.world.Coord; import mightypork.rogue.world.Coord;
import mightypork.rogue.world.PlayerControl; import mightypork.rogue.world.PlayerControl;
import mightypork.rogue.world.gui.MapView;
import mightypork.util.math.Calc.Deg; import mightypork.util.math.Calc.Deg;
import mightypork.util.math.Polar; import mightypork.util.math.Polar;
import mightypork.util.math.constraints.vect.Vect; import mightypork.util.math.constraints.vect.Vect;

@ -1,7 +1,8 @@
package mightypork.rogue.screens.gamescreen.world; package mightypork.rogue.world.gui.interaction;
import mightypork.rogue.world.PlayerControl; import mightypork.rogue.world.PlayerControl;
import mightypork.rogue.world.gui.MapView;
import mightypork.util.math.constraints.vect.Vect; import mightypork.util.math.constraints.vect.Vect;

@ -53,11 +53,13 @@ public class Level implements MapAccess, IonBinary {
private transient NoiseGen noiseGen; private transient NoiseGen noiseGen;
public Level() { public Level()
{
} }
public Level(int width, int height) { public Level(int width, int height)
{
size.setTo(width, height); size.setTo(width, height);
buildArray(); buildArray();
} }
@ -327,16 +329,16 @@ public class Level implements MapAccess, IonBinary {
public void explore(Coord center) public void explore(Coord center)
{ {
Collection<Coord> filled = new HashSet<>(); final Collection<Coord> filled = new HashSet<>();
FloodFill.fill(center, exploreFc, filled); FloodFill.fill(center, exploreFc, filled);
for (Coord c : filled) { for (final Coord c : filled) {
getTile(c).setExplored(); getTile(c).setExplored();
} }
} }
private FillContext exploreFc = new FillContext() { private final FillContext exploreFc = new FillContext() {
@Override @Override
public Coord[] getSpreadSides() public Coord[] getSpreadSides()
@ -355,7 +357,7 @@ public class Level implements MapAccess, IonBinary {
@Override @Override
public boolean canSpreadFrom(Coord pos) public boolean canSpreadFrom(Coord pos)
{ {
Tile t = getTile(pos); final Tile t = getTile(pos);
return t.isWalkable() && t.getType() != TileType.DOOR; return t.isWalkable() && t.getType() != TileType.DOOR;
} }
@ -363,7 +365,7 @@ public class Level implements MapAccess, IonBinary {
@Override @Override
public boolean canEnter(Coord pos) public boolean canEnter(Coord pos)
{ {
Tile t = getTile(pos); final Tile t = getTile(pos);
return !t.isNull(); return !t.isNull();
} }

@ -11,8 +11,10 @@ public interface FillContext {
boolean canSpreadFrom(Coord pos); boolean canSpreadFrom(Coord pos);
Coord[] getSpreadSides(); Coord[] getSpreadSides();
/** /**
* Get the max distance filled form start point. Use -1 for unlimited range. * Get the max distance filled form start point. Use -1 for unlimited range.
* *

@ -12,6 +12,7 @@ public class FloodFill {
/** /**
* Fill an area * Fill an area
*
* @param start start point * @param start start point
* @param context filling context * @param context filling context
* @param foundNodes collection to put filled coords in * @param foundNodes collection to put filled coords in
@ -19,29 +20,29 @@ public class FloodFill {
*/ */
public static final boolean fill(Coord start, FillContext context, Collection<Coord> foundNodes) public static final boolean fill(Coord start, FillContext context, Collection<Coord> foundNodes)
{ {
Queue<Coord> activeNodes = new LinkedList<>(); final Queue<Coord> activeNodes = new LinkedList<>();
double maxDist = context.getMaxDistance(); final double maxDist = context.getMaxDistance();
activeNodes.add(start); activeNodes.add(start);
Coord[] sides = context.getSpreadSides(); final Coord[] sides = context.getSpreadSides();
boolean forceSpreadNext = context.forceSpreadStart(); boolean forceSpreadNext = context.forceSpreadStart();
boolean limitReached = false; boolean limitReached = false;
while (!activeNodes.isEmpty()) { while (!activeNodes.isEmpty()) {
Coord current = activeNodes.poll(); final Coord current = activeNodes.poll();
foundNodes.add(current); foundNodes.add(current);
if(!context.canSpreadFrom(current) && !forceSpreadNext) continue; if (!context.canSpreadFrom(current) && !forceSpreadNext) continue;
forceSpreadNext = false; forceSpreadNext = false;
for (Coord spr : sides) { for (final Coord spr : sides) {
Coord next = current.add(spr); final Coord next = current.add(spr);
if(activeNodes.contains(next) || foundNodes.contains(next)) continue; if (activeNodes.contains(next) || foundNodes.contains(next)) continue;
if (next.dist(start) > maxDist) { if (next.dist(start) > maxDist) {
limitReached = true; limitReached = true;

@ -33,7 +33,8 @@ public abstract class Tile implements IonBinaryHeadless {
protected boolean explored; protected boolean explored;
public Tile(TileModel model, TileRenderer renderer) { public Tile(TileModel model, TileRenderer renderer)
{
this.model = model; this.model = model;
this.renderer = renderer; this.renderer = renderer;
} }

@ -36,7 +36,7 @@ public final class TileModel {
{ {
try { try {
return tileClass.getConstructor(TileModel.class, TileRenderer.class).newInstance(this, renderer); return tileClass.getConstructor(TileModel.class, TileRenderer.class).newInstance(this, renderer);
} catch (Exception e) { } catch (final Exception e) {
throw new RuntimeException("Could not instantiate a tile.", e); throw new RuntimeException("Could not instantiate a tile.", e);
} }
} }
@ -44,7 +44,7 @@ public final class TileModel {
public Tile loadTile(IonInput in) throws IOException public Tile loadTile(IonInput in) throws IOException
{ {
Tile t = createTile(); final Tile t = createTile();
t.load(in); t.load(in);
return t; return t;
} }

@ -1,5 +1,6 @@
package mightypork.rogue.world.tile; package mightypork.rogue.world.tile;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.gamecore.render.textures.TxQuad; import mightypork.gamecore.render.textures.TxQuad;
import mightypork.rogue.Res; import mightypork.rogue.Res;
@ -22,7 +23,8 @@ public abstract class TileRenderer {
private static boolean inited; private static boolean inited;
public TileRenderer() { public TileRenderer()
{
if (!inited) { if (!inited) {
SH_N = Res.getTxQuad("tile.shadow.n"); SH_N = Res.getTxQuad("tile.shadow.n");
SH_S = Res.getTxQuad("tile.shadow.s"); SH_S = Res.getTxQuad("tile.shadow.s");

@ -26,7 +26,8 @@ public enum TileType
private final boolean potentiallyWalkable; private final boolean potentiallyWalkable;
private TileType(Color mapColor, boolean potentiallyWalkable) { private TileType(Color mapColor, boolean potentiallyWalkable)
{
this.mapColor = mapColor; this.mapColor = mapColor;
this.potentiallyWalkable = potentiallyWalkable; this.potentiallyWalkable = potentiallyWalkable;
} }

@ -52,16 +52,16 @@ public final class Tiles {
public static Tile loadTile(IonInput in) throws IOException public static Tile loadTile(IonInput in) throws IOException
{ {
int id = in.readIntByte(); final int id = in.readIntByte();
TileModel model = get(id); final TileModel model = get(id);
return model.loadTile(in); return model.loadTile(in);
} }
public static void saveTile(IonOutput out, Tile tile) throws IOException public static void saveTile(IonOutput out, Tile tile) throws IOException
{ {
TileModel model = tile.getModel(); final TileModel model = tile.getModel();
out.writeIntByte(model.id); out.writeIntByte(model.id);
model.saveTile(out, tile); model.saveTile(out, tile);

@ -13,12 +13,14 @@ public class DoorTile extends SolidTile {
super(model, renderer); super(model, renderer);
} }
@Override @Override
public boolean isWalkable() public boolean isWalkable()
{ {
return true; return true;
} }
@Override @Override
public TileType getType() public TileType getType()
{ {

@ -17,10 +17,11 @@ import mightypork.util.files.ion.IonOutput;
public abstract class GroundTile extends Tile { public abstract class GroundTile extends Tile {
private DroppedItemRenderer itemRenderer = new DroppedItemRenderer(); private final DroppedItemRenderer itemRenderer = new DroppedItemRenderer();
protected final Stack<Item> items = new Stack<>(); protected final Stack<Item> items = new Stack<>();
public GroundTile(TileModel model, TileRenderer renderer) public GroundTile(TileModel model, TileRenderer renderer)
{ {
super(model, renderer); super(model, renderer);
@ -60,18 +61,21 @@ public abstract class GroundTile extends Tile {
in.readSequence(items); in.readSequence(items);
} }
@Override @Override
public boolean doesCastShadow() public boolean doesCastShadow()
{ {
return false; return false;
} }
@Override @Override
public boolean isWalkable() public boolean isWalkable()
{ {
return true; return true;
} }
@Override @Override
public boolean dropItem(Item item) public boolean dropItem(Item item)
{ {
@ -79,12 +83,14 @@ public abstract class GroundTile extends Tile {
return true; return true;
} }
@Override @Override
public Item pickItem() public Item pickItem()
{ {
return hasItem() ? items.pop() : null; return hasItem() ? items.pop() : null;
} }
@Override @Override
public boolean hasItem() public boolean hasItem()
{ {

@ -19,6 +19,7 @@ public class LockedDoorTile extends DoorTile {
super(model, renderer); super(model, renderer);
} }
@Override @Override
public boolean isWalkable() public boolean isWalkable()
{ {

@ -63,6 +63,7 @@ public class NullTile extends Tile {
return false; return false;
} }
@Override @Override
public boolean dropItem(Item item) public boolean dropItem(Item item)
{ {

@ -1,5 +1,6 @@
package mightypork.rogue.world.tile.tiles; package mightypork.rogue.world.tile.tiles;
import mightypork.rogue.world.item.Item; import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.tile.Tile; import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileModel;
@ -13,30 +14,35 @@ public abstract class SolidTile extends Tile {
super(model, renderer); super(model, renderer);
} }
@Override @Override
public boolean isWalkable() public boolean isWalkable()
{ {
return false; return false;
} }
@Override @Override
public boolean doesCastShadow() public boolean doesCastShadow()
{ {
return true; return true;
} }
@Override @Override
public boolean hasItem() public boolean hasItem()
{ {
return false; return false;
} }
@Override @Override
public boolean dropItem(Item item) public boolean dropItem(Item item)
{ {
return false; return false;
} }
@Override @Override
public Item pickItem() public Item pickItem()
{ {

@ -1,5 +1,6 @@
package mightypork.rogue.world.tile.tiles; package mightypork.rogue.world.tile.tiles;
import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.TileRenderer; import mightypork.rogue.world.tile.TileRenderer;
import mightypork.rogue.world.tile.TileType; import mightypork.rogue.world.tile.TileType;
@ -12,6 +13,7 @@ public class WallTile extends SolidTile {
super(model, renderer); super(model, renderer);
} }
@Override @Override
public TileType getType() public TileType getType()
{ {

@ -3,26 +3,31 @@ package mightypork.util.error;
public class IllegalValueException extends RuntimeException { public class IllegalValueException extends RuntimeException {
public IllegalValueException() { public IllegalValueException()
{
} }
public IllegalValueException(String message) { public IllegalValueException(String message)
{
super(message); super(message);
} }
public IllegalValueException(Throwable cause) { public IllegalValueException(Throwable cause)
{
super(cause); super(cause);
} }
public IllegalValueException(String message, Throwable cause) { public IllegalValueException(String message, Throwable cause)
{
super(message, cause); super(message, cause);
} }
public IllegalValueException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { public IllegalValueException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace)
{
super(message, cause, enableSuppression, writableStackTrace); super(message, cause, enableSuppression, writableStackTrace);
} }

@ -1,8 +1,6 @@
package mightypork.util.files.ion; package mightypork.util.files.ion;
/** /**
* Binary ion object, with a mark = saveable / loadable on it's own * Binary ion object, with a mark = saveable / loadable on it's own
* *

Loading…
Cancel
Save