refactored some stuff, world gen tweaking.
This commit is contained in:
@@ -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() {
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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<String, EntityModule> 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -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;
|
||||
}
|
||||
|
||||
+12
-10
@@ -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<EntityMoveListener> 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<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();
|
||||
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<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.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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -348,7 +348,7 @@ public class Level implements MapAccess, IonBinary {
|
||||
@Override
|
||||
public double getMaxDistance()
|
||||
{
|
||||
return 5;
|
||||
return 5.4;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user