minimap tweaks

v5stable
ondra 11 years ago
parent 84ef9fb9fe
commit 38727fad71
  1. 2
      src/mightypork/gamecore/control/events/input/KeyEvent.java
  2. 2
      src/mightypork/gamecore/control/events/input/MouseButtonEvent.java
  3. 2
      src/mightypork/rogue/screens/gamescreen/HudLayer.java
  4. 2
      src/mightypork/rogue/screens/gamescreen/ScreenGame.java
  5. 2
      src/mightypork/rogue/screens/gamescreen/WorldLayer.java
  6. 42
      src/mightypork/rogue/screens/gamescreen/world/Minimap.java
  7. 2
      src/mightypork/rogue/world/PlayerControl.java
  8. 2
      src/mightypork/rogue/world/World.java
  9. 2
      src/mightypork/rogue/world/WorldCreator.java
  10. 1
      src/mightypork/rogue/world/WorldRenderer.java
  11. 54
      src/mightypork/rogue/world/entity/Entity.java
  12. 2
      src/mightypork/rogue/world/entity/EntityData.java
  13. 3
      src/mightypork/rogue/world/entity/EntityPos.java
  14. 3
      src/mightypork/rogue/world/entity/PathStep.java
  15. 14
      src/mightypork/rogue/world/entity/models/EntityModel.java
  16. 31
      src/mightypork/rogue/world/entity/models/PlayerModel.java
  17. 2
      src/mightypork/rogue/world/entity/renderers/PlayerRenderer.java
  18. 6
      src/mightypork/rogue/world/gen/LevelGenerator.java
  19. 30
      src/mightypork/rogue/world/gen/ScratchMap.java
  20. 2
      src/mightypork/rogue/world/pathfinding/PathFinder.java
  21. 21
      src/mightypork/rogue/world/tile/Tile.java
  22. 4
      src/mightypork/rogue/world/tile/models/Floor.java
  23. 4
      src/mightypork/rogue/world/tile/models/SimpleDoor.java
  24. 3
      src/mightypork/rogue/world/tile/models/Wall.java
  25. 2
      src/mightypork/util/control/eventbus/BusEvent.java
  26. 2
      src/mightypork/util/math/Calc.java

@ -2,6 +2,7 @@ package mightypork.gamecore.control.events.input;
import mightypork.util.control.eventbus.BusEvent;
import mightypork.util.control.eventbus.event_flags.UnloggedEvent;
import org.lwjgl.input.Keyboard;
@ -11,6 +12,7 @@ import org.lwjgl.input.Keyboard;
*
* @author MightyPork
*/
@UnloggedEvent
public class KeyEvent extends BusEvent<KeyListener> {
private final int key;

@ -2,6 +2,7 @@ package mightypork.gamecore.control.events.input;
import mightypork.util.control.eventbus.BusEvent;
import mightypork.util.control.eventbus.event_flags.UnloggedEvent;
import mightypork.util.math.constraints.rect.proxy.RectBound;
import mightypork.util.math.constraints.vect.Vect;
import mightypork.util.math.constraints.vect.VectConst;
@ -12,6 +13,7 @@ import mightypork.util.math.constraints.vect.VectConst;
*
* @author MightyPork
*/
@UnloggedEvent
public class MouseButtonEvent extends BusEvent<MouseButtonListener> {
public static final int BUTTON_LEFT = 0;

@ -85,7 +85,7 @@ public class HudLayer extends ScreenLayer {
@Override
public int getEventPriority()
{
return 100;
return 200;
}
}

@ -24,8 +24,8 @@ public class ScreenGame extends LayeredScreen {
this.world = obtainWorld();
addLayer(new WorldLayer(this, world));
addLayer(new HudLayer(this, world));
addLayer(new WorldLayer(this, world));
}

@ -39,7 +39,7 @@ public class WorldLayer extends ScreenLayer {
@Override
public int getZIndex()
{
return -1; // stay down
return 0; // stay down
}

@ -6,12 +6,14 @@ import mightypork.gamecore.control.events.input.MouseButtonListener;
import mightypork.gamecore.gui.components.InputComponent;
import mightypork.gamecore.render.Render;
import mightypork.rogue.world.Coord;
import mightypork.rogue.world.EntityPos;
import mightypork.rogue.world.World;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityPos;
import mightypork.rogue.world.level.Level;
import mightypork.rogue.world.tile.Tile;
import mightypork.util.math.color.Color;
import mightypork.util.math.color.RGB;
import mightypork.util.math.constraints.num.Num;
import mightypork.util.math.constraints.rect.Rect;
import mightypork.util.math.constraints.rect.mutable.RectMutable;
import mightypork.util.math.constraints.vect.Vect;
@ -24,12 +26,11 @@ public class Minimap extends InputComponent implements MouseButtonListener {
private final World world;
private final RectMutable bounds = Rect.makeVar();
private int unit = 0;
private final Color back = Color.rgba(0, 0.2, 0.2, 0.4);
private final Color back2 = Color.rgba(0, 0.5, 0.5, 0.5);
private final Num translucency = Num.make(0.8);
private final Color playerColor = RGB.RED;
public Minimap(World w)
{
public Minimap(World w) {
this.world = w;
}
@ -37,9 +38,10 @@ public class Minimap extends InputComponent implements MouseButtonListener {
@Override
protected void renderComponent()
{
Color.pushAlpha(translucency);
final Level lvl = world.getCurrentLevel();
unit = (int) Math.min(Math.max(2, Math.ceil(height().value() / (lvl.getHeight() + 2))), 8);
unit = (int) Math.min(Math.max(2, Math.ceil((height().value()/2) / (lvl.getHeight() + 2))), 6);
final World w = lvl.getWorld();
final Entity e = w.getPlayerEntity();
@ -52,12 +54,12 @@ public class Minimap extends InputComponent implements MouseButtonListener {
bounds.setTo(tl, unit * lw, unit * lh);
Render.quad(bounds.grow(unit * 0.5), back);
Render.quad(bounds, back2);
final Coord point = new Coord(tl.xi(), tl.yi());
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glBegin(GL11.GL_QUADS);
for (final Coord pos = Coord.zero(); pos.y < lh; pos.y++, point.y += unit) {
for (pos.x = 0, point.x = tl.xi(); pos.x < lw; pos.x++, point.x += unit) {
@ -66,7 +68,7 @@ public class Minimap extends InputComponent implements MouseButtonListener {
final Color clr = t.getMapColor();
GL11.glColor4d(clr.r(), clr.g(), clr.b(), clr.a() * 0.9);
Render.setColor(clr);
GL11.glVertex2i(point.x, point.y);
GL11.glVertex2i(point.x + unit, point.y);
@ -76,7 +78,7 @@ public class Minimap extends InputComponent implements MouseButtonListener {
}
// player
GL11.glColor3d(1, 0, 0);
Render.setColor(playerColor);
final double plx = tl.xi() + plCoord.visualX() * unit;
final double ply = tl.yi() + plCoord.visualY() * unit;
@ -87,19 +89,25 @@ public class Minimap extends InputComponent implements MouseButtonListener {
GL11.glVertex2d(plx, ply + unit);
GL11.glEnd();
Color.popAlpha();
}
@Override
public void receive(MouseButtonEvent event)
{
if (event.isOver(bounds) && event.isUp()) {
final Vect relative = event.getPos().sub(bounds.origin());
final Coord actual = Coord.make(relative.xi() / unit, relative.yi() / unit);
if (!world.getCurrentLevel().getTile(actual).data.explored) return; // unexplored
if (event.isOver(bounds)) {
if (event.isUp()) {
final Vect relative = event.getPos().sub(bounds.origin());
final Coord actual = Coord.make(relative.xi() / unit, relative.yi() / unit);
final Entity player = world.getPlayerEntity();
if (player.getLevel().getTile(actual).isExplored()) {
player.navigateTo(actual);
}
}
world.getPlayerEntity().navigateTo(actual);
event.consume();
}
}

@ -2,6 +2,8 @@ package mightypork.rogue.world;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityPos;
import mightypork.rogue.world.entity.PathStep;
import mightypork.rogue.world.entity.models.EntityMoveListener;
import mightypork.rogue.world.level.Level;

@ -104,8 +104,8 @@ public class World implements IonBundled, Updateable {
final int playerEid = getNewEID();
playerEntity = Entities.PLAYER.createEntity(playerEid);
levels.get(level).addEntity(playerEntity);
playerEntity.setPosition(levels.get(level).getEnterPoint());
levels.get(level).addEntity(playerEntity);
playerInfo.setLevel(level);
playerInfo.setEID(playerEid);

@ -23,7 +23,7 @@ public class WorldCreator {
Level l;
// first level
l = LevelGenerator.build(rand.nextLong(), 16, LevelGenerator.DUNGEON_THEME); //
l = LevelGenerator.build(rand.nextLong(), 30, LevelGenerator.DUNGEON_THEME); //
w.addLevel(l);
w.createPlayer(0);

@ -4,6 +4,7 @@ package mightypork.rogue.world;
import mightypork.gamecore.render.Render;
import mightypork.rogue.Res;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityPos;
import mightypork.rogue.world.level.Level;
import mightypork.rogue.world.level.render.TileRenderContext;
import mightypork.util.math.color.RGB;

@ -6,8 +6,6 @@ import java.util.ArrayList;
import java.util.List;
import mightypork.rogue.world.Coord;
import mightypork.rogue.world.EntityPos;
import mightypork.rogue.world.PathStep;
import mightypork.rogue.world.World;
import mightypork.rogue.world.entity.models.EntityModel;
import mightypork.rogue.world.entity.models.EntityMoveListener;
@ -27,7 +25,7 @@ import mightypork.util.files.ion.IonOutput;
*
* @author MightyPork
*/
public final class Entity implements IonBinary, EntityMoveListener {
public final class Entity implements IonBinary {
public static final int ION_MARK = 52;
@ -189,10 +187,14 @@ public final class Entity implements IonBinary, EntityMoveListener {
walking = false;
level.freeTile(lastPosition.getCoord());
onStepFinished(this);
for (final EntityMoveListener l : moveListeners) {
l.onStepFinished(this);
}
if (data.path.isEmpty()) {
onPathFinished(this);
for (final EntityMoveListener l : moveListeners) {
l.onPathFinished(this);
}
}
}
@ -206,7 +208,11 @@ public final class Entity implements IonBinary, EntityMoveListener {
if (!level.canWalkInto(planned)) {
cancelPath();
onPathInterrupted(this);
for (final EntityMoveListener l : moveListeners) {
l.onPathInterrupted(this);
}
walking = false;
} else {
@ -252,6 +258,8 @@ public final class Entity implements IonBinary, EntityMoveListener {
public boolean navigateTo(Coord pos)
{
if(pos.equals(getCoord())) return true;
final List<PathStep> path = PathFinder.findPathRelative(pfc, getPosition().getCoord(), pos);
if (path == null) return false;
@ -262,33 +270,6 @@ public final class Entity implements IonBinary, EntityMoveListener {
}
@Override
public void onStepFinished(Entity entity)
{
for (final EntityMoveListener l : moveListeners) {
l.onStepFinished(entity);
}
}
@Override
public void onPathFinished(Entity entity)
{
for (final EntityMoveListener l : moveListeners) {
l.onStepFinished(entity);
}
}
@Override
public void onPathInterrupted(Entity entity)
{
for (final EntityMoveListener l : moveListeners) {
l.onPathInterrupted(entity);
}
}
public void addMoveListener(EntityMoveListener listener)
{
moveListeners.add(listener);
@ -304,6 +285,7 @@ public final class Entity implements IonBinary, EntityMoveListener {
public void setLevel(Level level)
{
this.level = level;
model.onEnteredLevel(this);
}
@ -311,4 +293,10 @@ public final class Entity implements IonBinary, EntityMoveListener {
{
return data.position.getCoord();
}
public EntityModel getModel()
{
return model;
}
}

@ -5,8 +5,6 @@ import java.io.IOException;
import java.util.LinkedList;
import java.util.Queue;
import mightypork.rogue.world.EntityPos;
import mightypork.rogue.world.PathStep;
import mightypork.util.files.ion.IonBundle;
import mightypork.util.files.ion.IonBundled;

@ -1,8 +1,9 @@
package mightypork.rogue.world;
package mightypork.rogue.world.entity;
import java.io.IOException;
import mightypork.rogue.world.Coord;
import mightypork.util.files.ion.IonBundle;
import mightypork.util.files.ion.IonBundled;
import mightypork.util.math.Easing;

@ -1,8 +1,9 @@
package mightypork.rogue.world;
package mightypork.rogue.world.entity;
import java.io.IOException;
import mightypork.rogue.world.Coord;
import mightypork.util.files.ion.IonBinary;
import mightypork.util.files.ion.IonInput;
import mightypork.util.files.ion.IonOutput;

@ -8,6 +8,7 @@ import mightypork.rogue.world.entity.EntityData;
import mightypork.rogue.world.entity.renderers.EntityRenderer;
import mightypork.rogue.world.pathfinding.Heuristic;
import mightypork.rogue.world.pathfinding.PathFinder;
import mightypork.util.annotations.DefaultImpl;
/**
@ -22,8 +23,7 @@ public abstract class EntityModel implements EntityMoveListener {
public EntityRenderer renderer = EntityRenderer.NONE;
public EntityModel(int id)
{
public EntityModel(int id) {
Entities.register(id, this);
this.id = id;
}
@ -69,24 +69,28 @@ public abstract class EntityModel implements EntityMoveListener {
public abstract void onPathInterrupted(Entity entity);
@DefaultImpl
public boolean canWalkInto(Entity entity, Coord pos)
{
return entity.getLevel().canWalkInto(pos);
}
@DefaultImpl
public int getPathMinCost()
{
return 10;
}
@DefaultImpl
public Heuristic getPathHeuristic()
{
return PathFinder.DIAGONAL_HEURISTIC;
}
@DefaultImpl
public int getPathCost(Entity entity, Coord from, Coord to)
{
return 10;
@ -95,4 +99,10 @@ public abstract class EntityModel implements EntityMoveListener {
public abstract void initMetadata(EntityData metadata);
@DefaultImpl
public void onEnteredLevel(Entity entity)
{
}
}

@ -19,8 +19,7 @@ public class PlayerModel extends EntityModel {
private static final double STEP_TIME = 0.25;
public PlayerModel(int id)
{
public PlayerModel(int id) {
super(id);
setRenderer(new PlayerRenderer("player"));
}
@ -42,9 +41,20 @@ public class PlayerModel extends EntityModel {
@Override
public void onStepFinished(Entity entity)
{
final Level l = entity.getLevel();
exploreSurroundings(entity);
}
l.markExplored(entity.getCoord(), 4.5);
private void exploreSurroundings(Entity entity)
{
entity.getLevel().markExplored(entity.getCoord(), 4.5);
}
@Override
public void onEnteredLevel(Entity entity)
{
exploreSurroundings(entity);
}
@ -70,6 +80,17 @@ public class PlayerModel extends EntityModel {
public boolean canWalkInto(Entity entity, Coord pos)
{
final Tile t = entity.getLevel().getTile(pos);
return (t.data.explored || pos.dist(entity.getCoord()) < 6) && t.isWalkable();
return t.isWalkable();
}
@Override
public int getPathCost(Entity entity, Coord from, Coord to)
{
if (!entity.getLevel().getTile(entity.getCoord()).data.explored) {
return 1000;
}
return super.getPathCost(entity, from, to);
}
}

@ -5,8 +5,8 @@ import mightypork.gamecore.render.Render;
import mightypork.gamecore.render.textures.TxQuad;
import mightypork.gamecore.render.textures.TxSheet;
import mightypork.rogue.Res;
import mightypork.rogue.world.EntityPos;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityPos;
import mightypork.rogue.world.level.render.MapRenderContext;
import mightypork.util.math.Calc;
import mightypork.util.math.constraints.rect.Rect;

@ -22,18 +22,18 @@ public class LevelGenerator {
{
final Random rand = new Random(seed + 13);
final int max_size = 256;
final int max_size = 128;
final ScratchMap map = new ScratchMap(max_size, theme, rand);
// start
map.addRoom(ROOM_SQUARE);
for (int i = 0; i < 2 + rand.nextInt(1 + complexity + (int) Math.pow(complexity, 1.6)); i++) {
for (int i = 0; i < 1+complexity/4 + rand.nextInt(3 + complexity); i++) {
map.addRoom(ROOM_SQUARE);
}
for (int i = 0; i < 2 + rand.nextInt(1 + complexity / 3 + (int) Math.pow(complexity, 1.2)); i++) {
for (int i = 0; i < 1 + complexity/8 + rand.nextInt(1 + complexity); i++) {
map.addRoom(DEAD_END);
}

@ -2,8 +2,10 @@ package mightypork.rogue.world.gen;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import mightypork.rogue.world.Coord;
import mightypork.rogue.world.level.Level;
@ -14,6 +16,7 @@ import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.Tiles;
import mightypork.util.logging.Log;
import mightypork.util.math.Calc;
public class ScratchMap {
@ -91,8 +94,7 @@ public class ScratchMap {
private static final boolean FIX_GLITCHES = true;
public ScratchMap(int max_size, Theme theme, Random rand)
{
public ScratchMap(int max_size, Theme theme, Random rand) {
map = new Tile[max_size][max_size];
genMin = Coord.make((max_size / 2) - 1, (max_size / 2) - 1);
@ -174,7 +176,9 @@ public class ScratchMap {
public Tile get(Coord pos)
{
if (!isIn(pos)) { throw new IndexOutOfBoundsException("Tile not in map: " + pos); }
if (!isIn(pos)) {
throw new IndexOutOfBoundsException("Tile not in map: " + pos);
}
return map[pos.y][pos.x];
}
@ -188,7 +192,9 @@ public class ScratchMap {
public boolean set(Coord pos, Tile tile)
{
if (!isIn(pos)) { throw new IndexOutOfBoundsException("Tile not in map: " + pos); }
if (!isIn(pos)) {
throw new IndexOutOfBoundsException("Tile not in map: " + pos);
}
map[pos.y][pos.x] = tile;
return true;
@ -256,17 +262,25 @@ public class ScratchMap {
public void buildCorridors()
{
Log.f3("Building corridors.");
for (int i = 0; i < nodes.size(); i++) {
for (int j = i + 1; j < nodes.size(); j++) {
buildCorridor(nodes.get(i), nodes.get(j));
Coord start = nodes.get(0);
Set<Coord> starts = new HashSet<>();
for (int i = 0; i < 1+rooms.size()/8; i++) {
if (!starts.contains(start)) {
for (int j = 0; j < nodes.size(); j++) {
buildCorridor(start, nodes.get(j));
}
}
starts.add(start);
start = Calc.pick(nodes);
}
}
private void buildCorridor(Coord node1, Coord node2)
{
//Log.f3("Finding path " + node1 + " -> " + node2);
Log.f3("Building corridor " + node1 + " -> " + node2);
final List<Coord> steps = PathFinder.findPath(pfc, node1, node2);
if (steps == null) {

@ -8,7 +8,7 @@ import java.util.LinkedList;
import java.util.List;
import mightypork.rogue.world.Coord;
import mightypork.rogue.world.PathStep;
import mightypork.rogue.world.entity.PathStep;
/**

@ -39,20 +39,17 @@ public final class Tile implements IonBinary {
private boolean occupied;
public Tile(int id)
{
public Tile(int id) {
this(Tiles.get(id));
}
public Tile(TileModel model)
{
public Tile(TileModel model) {
setModel(model);
}
public Tile()
{
public Tile() {
}
@ -210,4 +207,16 @@ public final class Tile implements IonBinary {
{
return model.getMapColor(this);
}
public boolean isExplored()
{
return data.explored;
}
public void explore()
{
data.explored = true;
}
}

@ -4,6 +4,8 @@ package mightypork.rogue.world.tile.models;
import mightypork.rogue.world.tile.Tile;
import mightypork.util.math.color.COMMODORE;
import mightypork.util.math.color.Color;
import mightypork.util.math.color.PAL16;
import mightypork.util.math.color.RGB;
public class Floor extends AbstractTile {
@ -45,6 +47,6 @@ public class Floor extends AbstractTile {
@Override
public Color getMapColor(Tile tile)
{
return COMMODORE.GRAY_DARK;
return RGB.GRAY_DARK;
}
}

@ -5,6 +5,8 @@ import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.renderers.DoorRenderer;
import mightypork.util.math.color.COMMODORE;
import mightypork.util.math.color.Color;
import mightypork.util.math.color.PAL16;
import mightypork.util.math.color.RGB;
public class SimpleDoor extends AbstractTile {
@ -60,6 +62,6 @@ public class SimpleDoor extends AbstractTile {
@Override
public Color getMapColor(Tile tile)
{
return COMMODORE.BROWN;
return PAL16.NEWPOOP;
}
}

@ -4,6 +4,7 @@ package mightypork.rogue.world.tile.models;
import mightypork.rogue.world.tile.Tile;
import mightypork.util.math.color.COMMODORE;
import mightypork.util.math.color.Color;
import mightypork.util.math.color.RGB;
/**
@ -50,6 +51,6 @@ public class Wall extends AbstractTile {
@Override
public Color getMapColor(Tile tile)
{
return COMMODORE.GRAY_LIGHT;
return RGB.GRAY_LIGHT;
}
}

@ -85,7 +85,7 @@ public abstract class BusEvent<HANDLER> {
*
* @return true if consumed
*/
final boolean isConsumed()
public final boolean isConsumed()
{
return consumed;
}

@ -616,7 +616,7 @@ public class Calc {
* @param list list of choices
* @return picked element
*/
public static Object pick(List<?> list)
public static <T> T pick(List<T> list)
{
if (list.size() == 0) return null;
return list.get(rand.nextInt(list.size()));

Loading…
Cancel
Save