refactored some stuff, world gen tweaking.

v5stable
ondra 11 years ago
parent 19d13c7903
commit a836c6f69a
  1. 21
      src/mightypork/rogue/App.java
  2. 4
      src/mightypork/rogue/Const.java
  3. 1
      src/mightypork/rogue/screens/gamescreen/HudLayer.java
  4. 8
      src/mightypork/rogue/screens/gamescreen/ScreenGame.java
  5. 1
      src/mightypork/rogue/screens/gamescreen/WorldLayer.java
  6. 1
      src/mightypork/rogue/screens/gamescreen/world/MapView.java
  7. 1
      src/mightypork/rogue/screens/gamescreen/world/Minimap.java
  8. 1
      src/mightypork/rogue/world/PlayerControl.java
  9. 4
      src/mightypork/rogue/world/WorldCreator.java
  10. 25
      src/mightypork/rogue/world/WorldProvider.java
  11. 4
      src/mightypork/rogue/world/WorldRenderer.java
  12. 33
      src/mightypork/rogue/world/entity/Entity.java
  13. 14
      src/mightypork/rogue/world/entity/entities/PlayerEntity.java
  14. 5
      src/mightypork/rogue/world/entity/modules/EntityModuleHealth.java
  15. 22
      src/mightypork/rogue/world/entity/modules/EntityModulePosition.java
  16. 7
      src/mightypork/rogue/world/entity/renderers/SimpleLeftRightMobRenderer.java
  17. 2
      src/mightypork/rogue/world/gen/LevelGenerator.java
  18. 5
      src/mightypork/rogue/world/gen/ScratchMap.java
  19. 2
      src/mightypork/rogue/world/gen/rooms/SimpleRectRoom.java
  20. 2
      src/mightypork/rogue/world/level/Level.java
  21. 1
      src/mightypork/rogue/world/level/render/TileRenderContext.java
  22. 4
      src/mightypork/rogue/world/pathfinding/FloodFill.java
  23. 1
      src/mightypork/rogue/world/tile/Tile.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_cat_sound.ScreenTestCat;
import mightypork.rogue.screens.test_render.ScreenTestRender; import mightypork.rogue.screens.test_render.ScreenTestRender;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.item.Item; import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.Level;
import mightypork.util.control.eventbus.BusEvent; import mightypork.util.control.eventbus.BusEvent;
@ -118,7 +117,7 @@ public final class App extends BaseApp {
protected void postInit() protected void postInit()
{ {
// TODO tmp // 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) protected void initInputSystem(InputSystem input)
{ {
// this will work only with reusable events (such as requests) // this will work only with reusable events (such as requests)
bindToKey(new ActionRequest(RequestType.FULLSCREEN), Keys.F11); bindEventToKey(new ActionRequest(RequestType.FULLSCREEN), Keys.F11);
bindToKey(new ActionRequest(RequestType.SCREENSHOT), Keys.F2); bindEventToKey(new ActionRequest(RequestType.SCREENSHOT), Keys.F2);
bindToKey(new CrossfadeRequest(null), Keys.L_CONTROL, Keys.Q); bindEventToKey(new CrossfadeRequest(null), Keys.L_CONTROL, Keys.Q);
bindToKey(new CrossfadeRequest("main_menu"), Keys.L_CONTROL, Keys.M); 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() { getInput().bindKey(new KeyStroke(keys), new Runnable() {

@ -18,6 +18,6 @@ public final class Const {
public static final int FPS_RENDER = 100; // max public static final int FPS_RENDER = 100; // max
// INITIAL WINDOW SIZE // INITIAL WINDOW SIZE
public static final int WINDOW_W = 800; public static final int WINDOW_W = 640;
public static final int WINDOW_H = 600; public static final int WINDOW_H = 480;
} }

@ -12,7 +12,6 @@ import mightypork.rogue.Res;
import mightypork.rogue.screens.gamescreen.gui.HeartBar; import mightypork.rogue.screens.gamescreen.gui.HeartBar;
import mightypork.rogue.screens.gamescreen.gui.NavItemSlot; import mightypork.rogue.screens.gamescreen.gui.NavItemSlot;
import mightypork.rogue.screens.gamescreen.world.Minimap; import mightypork.rogue.screens.gamescreen.world.Minimap;
import mightypork.rogue.world.World;
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,17 +1,9 @@
package mightypork.rogue.screens.gamescreen; 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.control.AppAccess;
import mightypork.gamecore.gui.screens.LayeredScreen; 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.rogue.world.WorldProvider;
import mightypork.util.files.ion.Ion;
public class ScreenGame extends LayeredScreen { public class ScreenGame extends LayeredScreen {

@ -6,7 +6,6 @@ import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.rogue.screens.gamescreen.world.MIPClickPathfWalk; import mightypork.rogue.screens.gamescreen.world.MIPClickPathfWalk;
import mightypork.rogue.screens.gamescreen.world.MIPKeyWalk; import mightypork.rogue.screens.gamescreen.world.MIPKeyWalk;
import mightypork.rogue.screens.gamescreen.world.MapView; import mightypork.rogue.screens.gamescreen.world.MapView;
import mightypork.rogue.world.World;
import mightypork.util.math.constraints.num.Num; import mightypork.util.math.constraints.num.Num;

@ -12,7 +12,6 @@ import mightypork.gamecore.gui.components.InputComponent;
import mightypork.gamecore.input.Keys; import mightypork.gamecore.input.Keys;
import mightypork.rogue.world.Coord; import mightypork.rogue.world.Coord;
import mightypork.rogue.world.PlayerControl; import mightypork.rogue.world.PlayerControl;
import mightypork.rogue.world.World;
import mightypork.rogue.world.WorldProvider; 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;

@ -9,7 +9,6 @@ import mightypork.rogue.world.Coord;
import mightypork.rogue.world.World; 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.entity.modules.EntityPos;
import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.Level;
import mightypork.rogue.world.tile.Tile; import mightypork.rogue.world.tile.Tile;
import mightypork.util.math.color.Color; import mightypork.util.math.color.Color;

@ -7,7 +7,6 @@ import java.util.Set;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.PathStep; import mightypork.rogue.world.entity.PathStep;
import mightypork.rogue.world.entity.modules.EntityMoveListener; import mightypork.rogue.world.entity.modules.EntityMoveListener;
import mightypork.rogue.world.entity.modules.EntityPos;
import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.Level;

@ -22,8 +22,10 @@ public class WorldCreator {
Level l; Level l;
// TODO real algorithm
// first level // first level
l = LevelGenerator.build(rand.nextLong(), 5, LevelGenerator.DUNGEON_THEME); // l = LevelGenerator.build(rand.nextLong(), 20, LevelGenerator.DUNGEON_THEME); //
w.addLevel(l); w.addLevel(l);
w.createPlayer(0); w.createPlayer(0);

@ -5,16 +5,13 @@ import java.io.File;
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.modules.EntityMoveListener;
import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.Level;
import mightypork.util.control.eventbus.BusAccess; import mightypork.util.control.eventbus.BusAccess;
import mightypork.util.control.eventbus.clients.BusNode;
import mightypork.util.control.eventbus.clients.RootBusNode; import mightypork.util.control.eventbus.clients.RootBusNode;
import mightypork.util.files.ion.Ion; 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) public static synchronized void init(BusAccess busAccess)
{ {
@ -54,9 +51,7 @@ public class WorldProvider extends RootBusNode implements Updateable {
public void createWorld(long seed) public void createWorld(long seed)
{ {
if (world != null) removeChildClient(world); setWorld(WorldCreator.createWorld(seed));
world = WorldCreator.createWorld(seed);
addChildClient(world);
} }
@ -65,10 +60,17 @@ public class WorldProvider extends RootBusNode implements Updateable {
return world; return world;
} }
private void setWorld(World newWorld) {
if (world != null) removeChildClient(world);
world = newWorld;
addChildClient(world);
}
public void loadWorld(File file) throws IOException 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 @Override
protected void deinit() protected void deinit()
{ {

@ -4,11 +4,9 @@ package mightypork.rogue.world;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.modules.EntityPos;
import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.Level;
import mightypork.rogue.world.level.render.TileRenderContext; import mightypork.rogue.world.level.render.TileRenderContext;
import mightypork.util.math.color.RGB; import mightypork.util.math.color.RGB;
import mightypork.util.math.constraints.Pollable;
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;
import mightypork.util.math.constraints.rect.RectConst; import mightypork.util.math.constraints.rect.RectConst;
@ -72,7 +70,7 @@ public class WorldRenderer extends RectProxy {
private VectConst getOffset() private VectConst getOffset()
{ {
Entity ent = WorldProvider.get().getPlayerEntity(); 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();
} }

@ -7,15 +7,17 @@ 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.EntityHealthModule;
import mightypork.rogue.world.entity.modules.EntityModule; 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.Level;
import mightypork.rogue.world.level.render.MapRenderContext; import mightypork.rogue.world.level.render.MapRenderContext;
import mightypork.rogue.world.pathfinding.PathFindingContext; import mightypork.rogue.world.pathfinding.PathFindingContext;
import mightypork.util.annotations.DefaultImpl; import mightypork.util.annotations.DefaultImpl;
import mightypork.util.error.IllegalValueException; 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; import mightypork.util.timing.Updateable;
@ -24,7 +26,7 @@ import mightypork.util.timing.Updateable;
* *
* @author MightyPork * @author MightyPork
*/ */
public abstract class Entity implements IonBundled, Updateable { public abstract class Entity implements IonBundled, Updateable, EntityMoveListener {
private Level level; private Level level;
private final EntityModel model; private final EntityModel model;
@ -35,8 +37,8 @@ public abstract class Entity implements IonBundled, Updateable {
private final Map<String, EntityModule> modules = new HashMap<>(); private final Map<String, EntityModule> modules = new HashMap<>();
// default modules // default modules
public final EntityPosModule pos = new EntityPosModule(this); public final EntityModulePosition pos = new EntityModulePosition(this);
public final EntityHealthModule health = new EntityHealthModule(this); public final EntityModuleHealth health = new EntityModuleHealth(this);
public Entity(EntityModel model, int eid) { public Entity(EntityModel model, int eid) {
@ -46,6 +48,7 @@ public abstract class Entity implements IonBundled, Updateable {
// register modules // register modules
modules.put("pos", pos); modules.put("pos", pos);
pos.addMoveListener(this);
modules.put("health", health); modules.put("health", health);
} }
@ -124,4 +127,22 @@ public abstract class Entity implements IonBundled, Updateable {
public void onKilled() public void onKilled()
{ {
} }
@Override
public void onStepFinished(Entity entity)
{
}
@Override
public void onPathFinished(Entity entity)
{
}
@Override
public void onPathInterrupted(Entity entity)
{
}
} }

@ -8,6 +8,7 @@ import mightypork.rogue.world.entity.EntityPathfindingContext;
import mightypork.rogue.world.entity.SimpleEntityPathFindingContext; import mightypork.rogue.world.entity.SimpleEntityPathFindingContext;
import mightypork.rogue.world.entity.renderers.EntityRenderer; import mightypork.rogue.world.entity.renderers.EntityRenderer;
import mightypork.rogue.world.entity.renderers.SimpleLeftRightMobRenderer; import mightypork.rogue.world.entity.renderers.SimpleLeftRightMobRenderer;
import mightypork.rogue.world.level.Level;
import mightypork.rogue.world.level.render.MapRenderContext; import mightypork.rogue.world.level.render.MapRenderContext;
import mightypork.rogue.world.pathfinding.PathFindingContext; import mightypork.rogue.world.pathfinding.PathFindingContext;
@ -46,10 +47,23 @@ public class PlayerEntity extends Entity {
return pathfc; return pathfc;
} }
@Override
public void setLevel(Level level)
{
super.setLevel(level);
onStepFinished(this);
}
@Override @Override
public void render(MapRenderContext context) public void render(MapRenderContext context)
{ {
renderer.render(context); renderer.render(context);
} }
@Override
public void onStepFinished(Entity entity)
{
getLevel().explore(pos.getCoord());
}
} }

@ -6,13 +6,12 @@ import java.io.IOException;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
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.files.ion.IonBundled;
import mightypork.util.math.Calc; 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; this.entity = entity;
} }

@ -2,7 +2,11 @@ package mightypork.rogue.world.entity.modules;
import java.io.IOException; 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.Coord;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
@ -13,7 +17,7 @@ import mightypork.util.files.ion.IonBundle;
import mightypork.util.math.constraints.vect.VectConst; import mightypork.util.math.constraints.vect.VectConst;
public class EntityPosModule implements EntityModule { public class EntityModulePosition implements EntityModule {
private final Entity entity; private final Entity entity;
@ -32,7 +36,7 @@ public class EntityPosModule implements EntityModule {
private final Set<EntityMoveListener> moveListeners = new LinkedHashSet<>(); private final Set<EntityMoveListener> moveListeners = new LinkedHashSet<>();
public EntityPosModule(Entity entity) { public EntityModulePosition(Entity entity) {
this.entity = entity; this.entity = entity;
} }
@ -140,14 +144,12 @@ public class EntityPosModule 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(); PathFindingContext pfc = entity.getPathfindingContext();
final List<PathStep> path = PathFinder.findPathRelative(pfc, entityPos.getCoord(), target); final List<PathStep> newPath = PathFinder.findPathRelative(pfc, entityPos.getCoord(), target);
if (path == null) return false;
this.cancelPath(); if (newPath == null) return false;
this.addSteps(path); cancelPath();
addSteps(newPath);
return true; return true;
} }
@ -163,7 +165,7 @@ public class EntityPosModule implements EntityModule {
public void addSteps(List<PathStep> path) public void addSteps(List<PathStep> path)
{ {
path.addAll(path); this.path.addAll(path);
} }

@ -6,21 +6,23 @@ import mightypork.gamecore.render.textures.TxQuad;
import mightypork.gamecore.render.textures.TxSheet; import mightypork.gamecore.render.textures.TxSheet;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.modules.EntityPos;
import mightypork.rogue.world.level.render.MapRenderContext; import mightypork.rogue.world.level.render.MapRenderContext;
import mightypork.util.math.Calc; import mightypork.util.math.Calc;
import mightypork.util.math.constraints.rect.Rect; import mightypork.util.math.constraints.rect.Rect;
import mightypork.util.math.constraints.vect.Vect;
public class SimpleLeftRightMobRenderer extends EntityRenderer { 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);
} }
@Override @Override
public void render(MapRenderContext context) public void render(MapRenderContext context)
{ {
@ -30,8 +32,9 @@ public class SimpleLeftRightMobRenderer extends EntityRenderer {
final Rect tileRect = context.getRectForTile(entity.pos.getCoord()); final Rect tileRect = context.getRectForTile(entity.pos.getCoord());
final double w = tileRect.width().value(); 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); spriteRect = spriteRect.shrink(w * 0.1);
Render.quadTextured(spriteRect, q); Render.quadTextured(spriteRect, q);

@ -29,7 +29,7 @@ public class LevelGenerator {
// start // start
map.addRoom(ROOM_SQUARE); 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); map.addRoom(ROOM_SQUARE);
if(rand.nextInt(4)>0) map.addRoom(DEAD_END); if(rand.nextInt(4)>0) map.addRoom(DEAD_END);
} }

@ -54,7 +54,7 @@ public class ScratchMap {
return 20; return 20;
case WALL: case WALL:
if (t.genData.isProtected) return 1000; if (t.genData.isProtected) return 2000;
return 100; return 100;
@ -159,7 +159,7 @@ public class ScratchMap {
} else { } else {
failed++; failed++;
if (failed > 150) { if (failed > 200) {
Log.w("Faild to build room."); Log.w("Faild to build room.");
return; return;
} }
@ -435,7 +435,6 @@ public class ScratchMap {
} }
if (isNull && (floors & Sides.DIAGONAL) != 0) { if (isNull && (floors & Sides.DIAGONAL) != 0) {
System.out.println(c);
toWall = true; // null with adjacent diagonal floor toWall = true; // null with adjacent diagonal floor
break; break;
} }

@ -29,7 +29,7 @@ public class SimpleRectRoom implements RoomBuilder {
map.border(min, max, theme.wall()); map.border(min, max, theme.wall());
map.protect(min, max); 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(); final Coord door = min.copy();
switch (rand.nextInt(4)) { switch (rand.nextInt(4)) {
case 0: case 0:

@ -348,7 +348,7 @@ public class Level implements MapAccess, IonBinary {
@Override @Override
public double getMaxDistance() public double getMaxDistance()
{ {
return 5; return 5.4;
} }

@ -62,7 +62,6 @@ public final class TileRenderContext extends MapRenderContext implements RectBou
public void renderTile() public void renderTile()
{ {
if(!map.getTile(pos).isExplored()) return;
map.getTile(pos).renderTile(this); map.getTile(pos).renderTile(this);
} }

@ -1,7 +1,9 @@
package mightypork.rogue.world.pathfinding; 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; import mightypork.rogue.world.Coord;

@ -2,7 +2,6 @@ package mightypork.rogue.world.tile;
import java.io.IOException; import java.io.IOException;
import java.util.Stack;
import mightypork.rogue.world.item.Item; import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.Level;

Loading…
Cancel
Save