diff --git a/src/mightypork/rogue/App.java b/src/mightypork/rogue/App.java index 1f1ec40..016b669 100644 --- a/src/mightypork/rogue/App.java +++ b/src/mightypork/rogue/App.java @@ -23,7 +23,6 @@ import mightypork.rogue.screens.test_bouncyboxes.ScreenTestBouncy; import mightypork.rogue.screens.test_cat_sound.ScreenTestCat; import mightypork.rogue.screens.test_render.ScreenTestRender; import mightypork.rogue.world.WorldProvider; -import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.item.Item; import mightypork.rogue.world.level.Level; import mightypork.util.control.eventbus.BusEvent; @@ -118,7 +117,7 @@ public final class App extends BaseApp { protected void postInit() { // TODO tmp - WorldProvider.get().createWorld(37); + WorldProvider.get().createWorld(42); } @@ -140,14 +139,22 @@ public final class App extends BaseApp { protected void initInputSystem(InputSystem input) { // this will work only with reusable events (such as requests) - bindToKey(new ActionRequest(RequestType.FULLSCREEN), Keys.F11); - bindToKey(new ActionRequest(RequestType.SCREENSHOT), Keys.F2); - bindToKey(new CrossfadeRequest(null), Keys.L_CONTROL, Keys.Q); - bindToKey(new CrossfadeRequest("main_menu"), Keys.L_CONTROL, Keys.M); + bindEventToKey(new ActionRequest(RequestType.FULLSCREEN), Keys.F11); + bindEventToKey(new ActionRequest(RequestType.SCREENSHOT), Keys.F2); + bindEventToKey(new CrossfadeRequest(null), Keys.L_CONTROL, Keys.Q); + bindEventToKey(new CrossfadeRequest("main_menu"), Keys.L_CONTROL, Keys.M); + getInput().bindKey(new KeyStroke(Keys.N), new Runnable() { + + @Override + public void run() + { + WorldProvider.get().createWorld(Double.doubleToLongBits(Math.random())); + } + }); } - private void bindToKey(final BusEvent event, int... keys) + private void bindEventToKey(final BusEvent event, int... keys) { getInput().bindKey(new KeyStroke(keys), new Runnable() { diff --git a/src/mightypork/rogue/Const.java b/src/mightypork/rogue/Const.java index 1fc5ec9..b38d5c9 100644 --- a/src/mightypork/rogue/Const.java +++ b/src/mightypork/rogue/Const.java @@ -18,6 +18,6 @@ public final class Const { public static final int FPS_RENDER = 100; // max // INITIAL WINDOW SIZE - public static final int WINDOW_W = 800; - public static final int WINDOW_H = 600; + public static final int WINDOW_W = 640; + public static final int WINDOW_H = 480; } diff --git a/src/mightypork/rogue/screens/gamescreen/HudLayer.java b/src/mightypork/rogue/screens/gamescreen/HudLayer.java index 550dbce..e7ba14a 100644 --- a/src/mightypork/rogue/screens/gamescreen/HudLayer.java +++ b/src/mightypork/rogue/screens/gamescreen/HudLayer.java @@ -12,7 +12,6 @@ import mightypork.rogue.Res; import mightypork.rogue.screens.gamescreen.gui.HeartBar; import mightypork.rogue.screens.gamescreen.gui.NavItemSlot; import mightypork.rogue.screens.gamescreen.world.Minimap; -import mightypork.rogue.world.World; import mightypork.util.math.constraints.num.Num; import mightypork.util.math.constraints.rect.Rect; diff --git a/src/mightypork/rogue/screens/gamescreen/ScreenGame.java b/src/mightypork/rogue/screens/gamescreen/ScreenGame.java index 2ad6b91..8fdc2ab 100644 --- a/src/mightypork/rogue/screens/gamescreen/ScreenGame.java +++ b/src/mightypork/rogue/screens/gamescreen/ScreenGame.java @@ -1,17 +1,9 @@ package mightypork.rogue.screens.gamescreen; -import java.io.File; -import java.io.IOException; -import java.util.Random; - import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.gui.screens.LayeredScreen; -import mightypork.rogue.Paths; -import mightypork.rogue.world.World; -import mightypork.rogue.world.WorldCreator; import mightypork.rogue.world.WorldProvider; -import mightypork.util.files.ion.Ion; public class ScreenGame extends LayeredScreen { diff --git a/src/mightypork/rogue/screens/gamescreen/WorldLayer.java b/src/mightypork/rogue/screens/gamescreen/WorldLayer.java index 3b6c463..b66293c 100644 --- a/src/mightypork/rogue/screens/gamescreen/WorldLayer.java +++ b/src/mightypork/rogue/screens/gamescreen/WorldLayer.java @@ -6,7 +6,6 @@ import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.rogue.screens.gamescreen.world.MIPClickPathfWalk; import mightypork.rogue.screens.gamescreen.world.MIPKeyWalk; import mightypork.rogue.screens.gamescreen.world.MapView; -import mightypork.rogue.world.World; import mightypork.util.math.constraints.num.Num; diff --git a/src/mightypork/rogue/screens/gamescreen/world/MapView.java b/src/mightypork/rogue/screens/gamescreen/world/MapView.java index 4153f1f..7dc90f7 100644 --- a/src/mightypork/rogue/screens/gamescreen/world/MapView.java +++ b/src/mightypork/rogue/screens/gamescreen/world/MapView.java @@ -12,7 +12,6 @@ import mightypork.gamecore.gui.components.InputComponent; import mightypork.gamecore.input.Keys; import mightypork.rogue.world.Coord; import mightypork.rogue.world.PlayerControl; -import mightypork.rogue.world.World; import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldRenderer; import mightypork.rogue.world.entity.Entity; diff --git a/src/mightypork/rogue/screens/gamescreen/world/Minimap.java b/src/mightypork/rogue/screens/gamescreen/world/Minimap.java index daf27de..6599532 100644 --- a/src/mightypork/rogue/screens/gamescreen/world/Minimap.java +++ b/src/mightypork/rogue/screens/gamescreen/world/Minimap.java @@ -9,7 +9,6 @@ import mightypork.rogue.world.Coord; import mightypork.rogue.world.World; import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.entity.Entity; -import mightypork.rogue.world.entity.modules.EntityPos; import mightypork.rogue.world.level.Level; import mightypork.rogue.world.tile.Tile; import mightypork.util.math.color.Color; diff --git a/src/mightypork/rogue/world/PlayerControl.java b/src/mightypork/rogue/world/PlayerControl.java index 49f597e..98b08f2 100644 --- a/src/mightypork/rogue/world/PlayerControl.java +++ b/src/mightypork/rogue/world/PlayerControl.java @@ -7,7 +7,6 @@ import java.util.Set; import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.PathStep; import mightypork.rogue.world.entity.modules.EntityMoveListener; -import mightypork.rogue.world.entity.modules.EntityPos; import mightypork.rogue.world.level.Level; diff --git a/src/mightypork/rogue/world/WorldCreator.java b/src/mightypork/rogue/world/WorldCreator.java index f743e25..5334218 100644 --- a/src/mightypork/rogue/world/WorldCreator.java +++ b/src/mightypork/rogue/world/WorldCreator.java @@ -22,8 +22,10 @@ public class WorldCreator { Level l; + // TODO real algorithm + // first level - l = LevelGenerator.build(rand.nextLong(), 5, LevelGenerator.DUNGEON_THEME); // + l = LevelGenerator.build(rand.nextLong(), 20, LevelGenerator.DUNGEON_THEME); // w.addLevel(l); w.createPlayer(0); diff --git a/src/mightypork/rogue/world/WorldProvider.java b/src/mightypork/rogue/world/WorldProvider.java index e75a4f3..c519b03 100644 --- a/src/mightypork/rogue/world/WorldProvider.java +++ b/src/mightypork/rogue/world/WorldProvider.java @@ -5,16 +5,13 @@ import java.io.File; import java.io.IOException; import mightypork.rogue.world.entity.Entity; -import mightypork.rogue.world.entity.modules.EntityMoveListener; import mightypork.rogue.world.level.Level; import mightypork.util.control.eventbus.BusAccess; -import mightypork.util.control.eventbus.clients.BusNode; import mightypork.util.control.eventbus.clients.RootBusNode; import mightypork.util.files.ion.Ion; -import mightypork.util.timing.Updateable; -public class WorldProvider extends RootBusNode implements Updateable { +public class WorldProvider extends RootBusNode{ public static synchronized void init(BusAccess busAccess) { @@ -54,9 +51,7 @@ public class WorldProvider extends RootBusNode implements Updateable { public void createWorld(long seed) { - if (world != null) removeChildClient(world); - world = WorldCreator.createWorld(seed); - addChildClient(world); + setWorld(WorldCreator.createWorld(seed)); } @@ -65,10 +60,17 @@ public class WorldProvider extends RootBusNode implements Updateable { return world; } + private void setWorld(World newWorld) { + + if (world != null) removeChildClient(world); + world = newWorld; + addChildClient(world); + } + public void loadWorld(File file) throws IOException { - world = Ion.fromFile(file, World.class); + setWorld(Ion.fromFile(file, World.class)); } @@ -100,13 +102,6 @@ public class WorldProvider extends RootBusNode implements Updateable { } - @Override - public void update(double delta) - { - world.update(delta); - } - - @Override protected void deinit() { diff --git a/src/mightypork/rogue/world/WorldRenderer.java b/src/mightypork/rogue/world/WorldRenderer.java index 662e080..3bc54e3 100644 --- a/src/mightypork/rogue/world/WorldRenderer.java +++ b/src/mightypork/rogue/world/WorldRenderer.java @@ -4,11 +4,9 @@ package mightypork.rogue.world; import mightypork.gamecore.render.Render; import mightypork.rogue.Res; import mightypork.rogue.world.entity.Entity; -import mightypork.rogue.world.entity.modules.EntityPos; import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.render.TileRenderContext; import mightypork.util.math.color.RGB; -import mightypork.util.math.constraints.Pollable; import mightypork.util.math.constraints.num.Num; import mightypork.util.math.constraints.rect.Rect; import mightypork.util.math.constraints.rect.RectConst; @@ -72,7 +70,7 @@ public class WorldRenderer extends RectProxy { private VectConst getOffset() { Entity ent = WorldProvider.get().getPlayerEntity(); - return Vect.make(ent.pos.getVisualPos().neg().add(0.5, 0.5)).freeze(); + return Vect.make(ent.pos.getVisualPos().neg().sub(0.5, 0.5)).freeze(); } diff --git a/src/mightypork/rogue/world/entity/Entity.java b/src/mightypork/rogue/world/entity/Entity.java index ea98c54..e1d1ef1 100644 --- a/src/mightypork/rogue/world/entity/Entity.java +++ b/src/mightypork/rogue/world/entity/Entity.java @@ -7,15 +7,17 @@ import java.util.Map; import java.util.Map.Entry; import mightypork.rogue.world.World; -import mightypork.rogue.world.entity.modules.EntityHealthModule; import mightypork.rogue.world.entity.modules.EntityModule; -import mightypork.rogue.world.entity.modules.EntityPosModule; +import mightypork.rogue.world.entity.modules.EntityModuleHealth; +import mightypork.rogue.world.entity.modules.EntityModulePosition; +import mightypork.rogue.world.entity.modules.EntityMoveListener; import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.render.MapRenderContext; import mightypork.rogue.world.pathfinding.PathFindingContext; import mightypork.util.annotations.DefaultImpl; import mightypork.util.error.IllegalValueException; -import mightypork.util.files.ion.*; +import mightypork.util.files.ion.IonBundle; +import mightypork.util.files.ion.IonBundled; import mightypork.util.timing.Updateable; @@ -24,7 +26,7 @@ import mightypork.util.timing.Updateable; * * @author MightyPork */ -public abstract class Entity implements IonBundled, Updateable { +public abstract class Entity implements IonBundled, Updateable, EntityMoveListener { private Level level; private final EntityModel model; @@ -35,8 +37,8 @@ public abstract class Entity implements IonBundled, Updateable { private final Map modules = new HashMap<>(); // default modules - public final EntityPosModule pos = new EntityPosModule(this); - public final EntityHealthModule health = new EntityHealthModule(this); + public final EntityModulePosition pos = new EntityModulePosition(this); + public final EntityModuleHealth health = new EntityModuleHealth(this); public Entity(EntityModel model, int eid) { @@ -46,6 +48,7 @@ public abstract class Entity implements IonBundled, Updateable { // register modules modules.put("pos", pos); + pos.addMoveListener(this); modules.put("health", health); } @@ -124,4 +127,22 @@ public abstract class Entity implements IonBundled, Updateable { public void onKilled() { } + + + @Override + public void onStepFinished(Entity entity) + { + } + + + @Override + public void onPathFinished(Entity entity) + { + } + + + @Override + public void onPathInterrupted(Entity entity) + { + } } diff --git a/src/mightypork/rogue/world/entity/entities/PlayerEntity.java b/src/mightypork/rogue/world/entity/entities/PlayerEntity.java index 597c6f1..1ab4d03 100644 --- a/src/mightypork/rogue/world/entity/entities/PlayerEntity.java +++ b/src/mightypork/rogue/world/entity/entities/PlayerEntity.java @@ -8,6 +8,7 @@ import mightypork.rogue.world.entity.EntityPathfindingContext; import mightypork.rogue.world.entity.SimpleEntityPathFindingContext; import mightypork.rogue.world.entity.renderers.EntityRenderer; import mightypork.rogue.world.entity.renderers.SimpleLeftRightMobRenderer; +import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.render.MapRenderContext; import mightypork.rogue.world.pathfinding.PathFindingContext; @@ -46,10 +47,23 @@ public class PlayerEntity extends Entity { return pathfc; } + @Override + public void setLevel(Level level) + { + super.setLevel(level); + onStepFinished(this); + } + @Override public void render(MapRenderContext context) { renderer.render(context); } + + @Override + public void onStepFinished(Entity entity) + { + getLevel().explore(pos.getCoord()); + } } diff --git a/src/mightypork/rogue/world/entity/modules/EntityHealthModule.java b/src/mightypork/rogue/world/entity/modules/EntityModuleHealth.java similarity index 90% rename from src/mightypork/rogue/world/entity/modules/EntityHealthModule.java rename to src/mightypork/rogue/world/entity/modules/EntityModuleHealth.java index ee79f16..e44b6b1 100644 --- a/src/mightypork/rogue/world/entity/modules/EntityHealthModule.java +++ b/src/mightypork/rogue/world/entity/modules/EntityModuleHealth.java @@ -6,13 +6,12 @@ import java.io.IOException; import mightypork.rogue.world.entity.Entity; import mightypork.util.error.IllegalValueException; import mightypork.util.files.ion.IonBundle; -import mightypork.util.files.ion.IonBundled; import mightypork.util.math.Calc; -public class EntityHealthModule implements EntityModule { +public class EntityModuleHealth implements EntityModule { - public EntityHealthModule(Entity entity) { + public EntityModuleHealth(Entity entity) { this.entity = entity; } diff --git a/src/mightypork/rogue/world/entity/modules/EntityPosModule.java b/src/mightypork/rogue/world/entity/modules/EntityModulePosition.java similarity index 89% rename from src/mightypork/rogue/world/entity/modules/EntityPosModule.java rename to src/mightypork/rogue/world/entity/modules/EntityModulePosition.java index 4ade947..83d4e2e 100644 --- a/src/mightypork/rogue/world/entity/modules/EntityPosModule.java +++ b/src/mightypork/rogue/world/entity/modules/EntityModulePosition.java @@ -2,7 +2,11 @@ package mightypork.rogue.world.entity.modules; import java.io.IOException; -import java.util.*; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.Set; import mightypork.rogue.world.Coord; import mightypork.rogue.world.entity.Entity; @@ -13,7 +17,7 @@ import mightypork.util.files.ion.IonBundle; import mightypork.util.math.constraints.vect.VectConst; -public class EntityPosModule implements EntityModule { +public class EntityModulePosition implements EntityModule { private final Entity entity; @@ -32,7 +36,7 @@ public class EntityPosModule implements EntityModule { private final Set moveListeners = new LinkedHashSet<>(); - public EntityPosModule(Entity entity) { + public EntityModulePosition(Entity entity) { this.entity = entity; } @@ -140,14 +144,12 @@ public class EntityPosModule implements EntityModule { public boolean navigateTo(Coord target) { if (target.equals(getCoord())) return true; - PathFindingContext pfc = entity.getPathfindingContext(); - final List path = PathFinder.findPathRelative(pfc, entityPos.getCoord(), target); - - if (path == null) return false; + final List newPath = PathFinder.findPathRelative(pfc, entityPos.getCoord(), target); - this.cancelPath(); - this.addSteps(path); + if (newPath == null) return false; + cancelPath(); + addSteps(newPath); return true; } @@ -163,7 +165,7 @@ public class EntityPosModule implements EntityModule { public void addSteps(List path) { - path.addAll(path); + this.path.addAll(path); } diff --git a/src/mightypork/rogue/world/entity/renderers/SimpleLeftRightMobRenderer.java b/src/mightypork/rogue/world/entity/renderers/SimpleLeftRightMobRenderer.java index 755bca2..00cac03 100644 --- a/src/mightypork/rogue/world/entity/renderers/SimpleLeftRightMobRenderer.java +++ b/src/mightypork/rogue/world/entity/renderers/SimpleLeftRightMobRenderer.java @@ -6,21 +6,23 @@ import mightypork.gamecore.render.textures.TxQuad; import mightypork.gamecore.render.textures.TxSheet; import mightypork.rogue.Res; import mightypork.rogue.world.entity.Entity; -import mightypork.rogue.world.entity.modules.EntityPos; import mightypork.rogue.world.level.render.MapRenderContext; import mightypork.util.math.Calc; import mightypork.util.math.constraints.rect.Rect; +import mightypork.util.math.constraints.vect.Vect; public class SimpleLeftRightMobRenderer extends EntityRenderer { private final TxSheet sheet; + public SimpleLeftRightMobRenderer(Entity entity, String sheetKey) { super(entity); this.sheet = Res.getTxSheet(sheetKey); } + @Override public void render(MapRenderContext context) { @@ -30,8 +32,9 @@ public class SimpleLeftRightMobRenderer extends EntityRenderer { final Rect tileRect = context.getRectForTile(entity.pos.getCoord()); final double w = tileRect.width().value(); + final Vect visualPos = entity.pos.getVisualPos(); - Rect spriteRect = tileRect.move(entity.pos.getVisualPos().mul(w)); + Rect spriteRect = Rect.make(visualPos.x() * w, visualPos.y() * w, w, w); spriteRect = spriteRect.shrink(w * 0.1); Render.quadTextured(spriteRect, q); diff --git a/src/mightypork/rogue/world/gen/LevelGenerator.java b/src/mightypork/rogue/world/gen/LevelGenerator.java index f235787..867d14d 100644 --- a/src/mightypork/rogue/world/gen/LevelGenerator.java +++ b/src/mightypork/rogue/world/gen/LevelGenerator.java @@ -29,7 +29,7 @@ public class LevelGenerator { // start map.addRoom(ROOM_SQUARE); - for (int i = 0; i < 1+complexity/2 + rand.nextInt((int) (3 + complexity*1.5)); i++) { + for (int i = 0; i < 2+complexity/2+rand.nextInt((int) (1+complexity*0.3)); i++) { map.addRoom(ROOM_SQUARE); if(rand.nextInt(4)>0) map.addRoom(DEAD_END); } diff --git a/src/mightypork/rogue/world/gen/ScratchMap.java b/src/mightypork/rogue/world/gen/ScratchMap.java index 544b42f..2fe74df 100644 --- a/src/mightypork/rogue/world/gen/ScratchMap.java +++ b/src/mightypork/rogue/world/gen/ScratchMap.java @@ -54,7 +54,7 @@ public class ScratchMap { return 20; case WALL: - if (t.genData.isProtected) return 1000; + if (t.genData.isProtected) return 2000; return 100; @@ -159,7 +159,7 @@ public class ScratchMap { } else { failed++; - if (failed > 150) { + if (failed > 200) { Log.w("Faild to build room."); return; } @@ -435,7 +435,6 @@ public class ScratchMap { } if (isNull && (floors & Sides.DIAGONAL) != 0) { - System.out.println(c); toWall = true; // null with adjacent diagonal floor break; } diff --git a/src/mightypork/rogue/world/gen/rooms/SimpleRectRoom.java b/src/mightypork/rogue/world/gen/rooms/SimpleRectRoom.java index 43b0fe5..d93c725 100644 --- a/src/mightypork/rogue/world/gen/rooms/SimpleRectRoom.java +++ b/src/mightypork/rogue/world/gen/rooms/SimpleRectRoom.java @@ -29,7 +29,7 @@ public class SimpleRectRoom implements RoomBuilder { map.border(min, max, theme.wall()); map.protect(min, max); - for (int i = 0; i <= rand.nextInt(6); i++) { + for (int i = 0; i <= 2 + rand.nextInt(6); i++) { final Coord door = min.copy(); switch (rand.nextInt(4)) { case 0: diff --git a/src/mightypork/rogue/world/level/Level.java b/src/mightypork/rogue/world/level/Level.java index 74b43d1..752cf03 100644 --- a/src/mightypork/rogue/world/level/Level.java +++ b/src/mightypork/rogue/world/level/Level.java @@ -348,7 +348,7 @@ public class Level implements MapAccess, IonBinary { @Override public double getMaxDistance() { - return 5; + return 5.4; } diff --git a/src/mightypork/rogue/world/level/render/TileRenderContext.java b/src/mightypork/rogue/world/level/render/TileRenderContext.java index 43ecb60..6bad077 100644 --- a/src/mightypork/rogue/world/level/render/TileRenderContext.java +++ b/src/mightypork/rogue/world/level/render/TileRenderContext.java @@ -62,7 +62,6 @@ public final class TileRenderContext extends MapRenderContext implements RectBou public void renderTile() { - if(!map.getTile(pos).isExplored()) return; map.getTile(pos).renderTile(this); } diff --git a/src/mightypork/rogue/world/pathfinding/FloodFill.java b/src/mightypork/rogue/world/pathfinding/FloodFill.java index ec1c402..49f5787 100644 --- a/src/mightypork/rogue/world/pathfinding/FloodFill.java +++ b/src/mightypork/rogue/world/pathfinding/FloodFill.java @@ -1,7 +1,9 @@ package mightypork.rogue.world.pathfinding; -import java.util.*; +import java.util.Collection; +import java.util.LinkedList; +import java.util.Queue; import mightypork.rogue.world.Coord; diff --git a/src/mightypork/rogue/world/tile/Tile.java b/src/mightypork/rogue/world/tile/Tile.java index b3886d3..f0bd2cb 100644 --- a/src/mightypork/rogue/world/tile/Tile.java +++ b/src/mightypork/rogue/world/tile/Tile.java @@ -2,7 +2,6 @@ package mightypork.rogue.world.tile; import java.io.IOException; -import java.util.Stack; import mightypork.rogue.world.item.Item; import mightypork.rogue.world.level.Level;