v5stable
Ondřej Hruška 11 years ago
parent 5235b969c9
commit 84ef9fb9fe
  1. 2
      src/mightypork/gamecore/gui/components/InputComponent.java
  2. 27
      src/mightypork/rogue/screens/gamescreen/HudLayer.java
  3. 9
      src/mightypork/rogue/screens/gamescreen/ScreenGame.java
  4. 7
      src/mightypork/rogue/screens/gamescreen/WorldLayer.java
  5. 2
      src/mightypork/rogue/screens/gamescreen/world/MIPClickPathfWalk.java
  6. 106
      src/mightypork/rogue/screens/gamescreen/world/Minimap.java
  7. 7
      src/mightypork/rogue/world/Coord.java
  8. 1
      src/mightypork/rogue/world/World.java
  9. 2
      src/mightypork/rogue/world/WorldCreator.java
  10. 14
      src/mightypork/rogue/world/entity/models/PlayerModel.java
  11. 8
      src/mightypork/rogue/world/gen/ScratchMap.java
  12. 19
      src/mightypork/rogue/world/level/Level.java
  13. 17
      src/mightypork/rogue/world/tile/Tile.java
  14. 54
      src/mightypork/rogue/world/tile/TileData.java
  15. 10
      src/mightypork/rogue/world/tile/TileModel.java
  16. 7
      src/mightypork/rogue/world/tile/models/AbstractNullTile.java
  17. 7
      src/mightypork/rogue/world/tile/models/AbstractTile.java
  18. 12
      src/mightypork/rogue/world/tile/models/Floor.java
  19. 11
      src/mightypork/rogue/world/tile/models/NullTile.java
  20. 9
      src/mightypork/rogue/world/tile/models/SimpleDoor.java
  21. 11
      src/mightypork/rogue/world/tile/models/Wall.java
  22. 29
      src/mightypork/util/error/YouFuckedUpException.java
  23. 6
      src/mightypork/util/math/Calc.java

@ -20,7 +20,7 @@ public abstract class InputComponent extends VisualComponent implements Enableab
@Override
public boolean isEnabled()
{
return enabled;
return enabled && isVisible();
}

@ -6,16 +6,20 @@ import mightypork.gamecore.gui.components.layout.HorizontalFixedFlowLayout;
import mightypork.gamecore.gui.components.painters.ImagePainter;
import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys;
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;
public class HudLayer extends ScreenLayer {
public HudLayer(Screen screen)
public HudLayer(Screen screen, World world)
{
super(screen);
@ -46,6 +50,20 @@ public class HudLayer extends ScreenLayer {
final Rect xp_box = shrunk.topRight().startRect().growDown(displays_height);
experience.setRect(xp_box);
root.add(experience);
final Minimap mm = new Minimap(world);
mm.setRect(root.shrink(root.width().perc(5), root.height().perc(15)));
root.add(mm);
bindKey(new KeyStroke(Keys.M), new Runnable() {
@Override
public void run()
{
mm.setVisible(!mm.isVisible());
}
});
}
@ -63,4 +81,11 @@ public class HudLayer extends ScreenLayer {
super.render();
}
@Override
public int getEventPriority()
{
return 100;
}
}

@ -15,12 +15,17 @@ import mightypork.util.files.ion.Ion;
public class ScreenGame extends LayeredScreen {
private final World world;
public ScreenGame(AppAccess app)
{
super(app);
addLayer(new WorldLayer(this, obtainWorld())); //TODO with provided world
addLayer(new HudLayer(this));
this.world = obtainWorld();
addLayer(new WorldLayer(this, world));
addLayer(new HudLayer(this, world));
}

@ -42,4 +42,11 @@ public class WorldLayer extends ScreenLayer {
return -1; // stay down
}
@Override
public int getEventPriority()
{
return 0;
}
}

@ -9,7 +9,7 @@ import mightypork.util.math.constraints.vect.Vect;
public class MIPClickPathfWalk implements MapInteractionPlugin {
private static final int BTN = 1; // right
private static final int BTN = 0; // left
@Override

@ -0,0 +1,106 @@
package mightypork.rogue.screens.gamescreen.world;
import mightypork.gamecore.control.events.input.MouseButtonEvent;
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.level.Level;
import mightypork.rogue.world.tile.Tile;
import mightypork.util.math.color.Color;
import mightypork.util.math.constraints.rect.Rect;
import mightypork.util.math.constraints.rect.mutable.RectMutable;
import mightypork.util.math.constraints.vect.Vect;
import org.lwjgl.opengl.GL11;
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);
public Minimap(World w)
{
this.world = w;
}
@Override
protected void renderComponent()
{
final Level lvl = world.getCurrentLevel();
unit = (int) Math.min(Math.max(2, Math.ceil(height().value() / (lvl.getHeight() + 2))), 8);
final World w = lvl.getWorld();
final Entity e = w.getPlayerEntity();
final EntityPos plCoord = e.getPosition();
final int lw = lvl.getWidth();
final int lh = lvl.getHeight();
final Vect tl = topRight().sub(unit * lw, 0);
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) {
final Tile t = lvl.getTile(pos);
if (t.isNull() || !t.data.explored) continue;
final Color clr = t.getMapColor();
GL11.glColor4d(clr.r(), clr.g(), clr.b(), clr.a() * 0.9);
GL11.glVertex2i(point.x, point.y);
GL11.glVertex2i(point.x + unit, point.y);
GL11.glVertex2i(point.x + unit, point.y + unit);
GL11.glVertex2i(point.x, point.y + unit);
}
}
// player
GL11.glColor3d(1, 0, 0);
final double plx = tl.xi() + plCoord.visualX() * unit;
final double ply = tl.yi() + plCoord.visualY() * unit;
GL11.glVertex2d(plx, ply);
GL11.glVertex2d(plx + unit, ply);
GL11.glVertex2d(plx + unit, ply + unit);
GL11.glVertex2d(plx, ply + unit);
GL11.glEnd();
}
@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
world.getPlayerEntity().navigateTo(actual);
event.consume();
}
}
}

@ -6,6 +6,7 @@ import java.io.IOException;
import mightypork.util.annotations.FactoryMethod;
import mightypork.util.files.ion.IonBundle;
import mightypork.util.files.ion.IonBundled;
import mightypork.util.math.Calc;
/**
@ -140,4 +141,10 @@ public class Coord implements IonBundled {
if (y != other.y) return false;
return true;
}
public double dist(Coord coord)
{
return Calc.dist(x, y, coord.x, coord.y);
}
}

@ -64,6 +64,7 @@ public class World implements IonBundled, Updateable {
public void addLevel(Level level)
{
levels.add(level);
level.setWorld(this);
}

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

@ -1,9 +1,12 @@
package mightypork.rogue.world.entity.models;
import mightypork.rogue.world.Coord;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityData;
import mightypork.rogue.world.entity.renderers.PlayerRenderer;
import mightypork.rogue.world.level.Level;
import mightypork.rogue.world.tile.Tile;
/**
@ -39,6 +42,9 @@ public class PlayerModel extends EntityModel {
@Override
public void onStepFinished(Entity entity)
{
final Level l = entity.getLevel();
l.markExplored(entity.getCoord(), 4.5);
}
@ -58,4 +64,12 @@ public class PlayerModel extends EntityModel {
public void initMetadata(EntityData metadata)
{
}
@Override
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();
}
}

@ -123,16 +123,16 @@ public class ScratchMap {
switch (rand.nextInt(4)) {
case 0:
center.x += 1 + rand.nextInt(5);
center.x += 2 + rand.nextInt(6);
break;
case 1:
center.x -= 1 + rand.nextInt(5);
center.x -= 2 + rand.nextInt(6);
break;
case 2:
center.y += 1 + rand.nextInt(5);
center.y += 2 + rand.nextInt(6);
break;
case 3:
center.y -= 1 + rand.nextInt(5);
center.y -= 2 + rand.nextInt(6);
}
final RoomDesc rd = rb.buildToFit(this, theme, rand, center);

@ -19,6 +19,7 @@ import mightypork.util.files.ion.IonBundle;
import mightypork.util.files.ion.IonInput;
import mightypork.util.files.ion.IonOutput;
import mightypork.util.logging.Log;
import mightypork.util.math.Calc;
import mightypork.util.math.noise.NoiseGen;
@ -320,4 +321,22 @@ public class Level implements MapAccess, IonBinary {
{
this.world = world;
}
public void markExplored(Coord coord, double radius)
{
final int cr = (int) Math.ceil(radius);
final Coord c = Coord.zero();
for (c.y = coord.y - cr; c.y <= coord.y + cr; c.y++) {
for (c.x = coord.x - cr; c.x <= coord.x + cr; c.x++) {
if (Calc.dist(coord.x, coord.y, c.x, c.y) > radius) continue;
final Tile t = getTile(c);
if (!t.isNull()) {
t.data.explored = true;
}
}
}
}
}

@ -8,9 +8,9 @@ import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.level.Level;
import mightypork.rogue.world.level.render.TileRenderContext;
import mightypork.util.files.ion.IonBinary;
import mightypork.util.files.ion.IonBundle;
import mightypork.util.files.ion.IonInput;
import mightypork.util.files.ion.IonOutput;
import mightypork.util.math.color.Color;
/**
@ -30,7 +30,7 @@ public final class Tile implements IonBinary {
private final Stack<Item> items = new Stack<>();
/** persistent field for model, reflected by renderer */
public final IonBundle metadata = new IonBundle();
public final TileData data = new TileData();
public final TileRenderData renderData = new TileRenderData();
public final TileGenData genData = new TileGenData();
@ -99,9 +99,7 @@ public final class Tile implements IonBinary {
out.writeSequence(items);
}
if (model.hasMetadata()) {
out.writeBundle(metadata);
}
data.save(out);
}
@ -119,9 +117,7 @@ public final class Tile implements IonBinary {
in.readSequence(items);
}
if (model.hasMetadata()) {
in.readBundle(metadata);
}
data.load(in);
}
@ -209,4 +205,9 @@ public final class Tile implements IonBinary {
return model.isPotentiallyWalkable();
}
public Color getMapColor()
{
return model.getMapColor(this);
}
}

@ -0,0 +1,54 @@
package mightypork.rogue.world.tile;
import java.io.IOException;
import mightypork.util.error.YouFuckedUpException;
import mightypork.util.files.ion.IonBinary;
import mightypork.util.files.ion.IonBundle;
import mightypork.util.files.ion.IonInput;
import mightypork.util.files.ion.IonOutput;
public class TileData implements IonBinary {
private static final byte BIT_EXPLORED = 1 << 0;
private static final byte BIT_LOCKED = 1 << 1;
public boolean explored = false;
public boolean locked = false;
public final IonBundle extra = new IonBundle();
@Override
public void load(IonInput in) throws IOException
{
final byte flags = in.readByte();
in.readBundle(extra);
explored = (flags & BIT_EXPLORED) != 0;
locked = (flags & BIT_LOCKED) != 0;
}
@Override
public void save(IonOutput out) throws IOException
{
byte flags = 0;
if (explored) flags |= BIT_EXPLORED;
if (locked) flags |= BIT_LOCKED;
out.writeByte(flags);
out.writeBundle(extra);
}
@Override
public short getIonMark()
{
throw new YouFuckedUpException("TileData is not to be read from ION using mark.");
}
}

@ -2,6 +2,7 @@ package mightypork.rogue.world.tile;
import mightypork.rogue.world.level.Level;
import mightypork.util.math.color.Color;
/**
@ -66,12 +67,6 @@ public abstract class TileModel {
public abstract void update(Tile tile, Level level, double delta);
/**
* @return true if this item type has metadata worth saving
*/
public abstract boolean hasMetadata();
/**
* @return true if this item can have dropped items
*/
@ -84,4 +79,7 @@ public abstract class TileModel {
*/
public abstract boolean isPotentiallyWalkable();
public abstract Color getMapColor(Tile tile);
}

@ -38,13 +38,6 @@ public abstract class AbstractNullTile extends AbstractTile {
}
@Override
public boolean hasMetadata()
{
return false;
}
@Override
public boolean hasDroppedItems()
{

@ -48,13 +48,6 @@ public abstract class AbstractTile extends TileModel {
}
@Override
public boolean hasMetadata()
{
return false;
}
@Override
@DefaultImpl
public void update(Tile tile, Level level, double delta)

@ -1,6 +1,11 @@
package mightypork.rogue.world.tile.models;
import mightypork.rogue.world.tile.Tile;
import mightypork.util.math.color.COMMODORE;
import mightypork.util.math.color.Color;
public class Floor extends AbstractTile {
public Floor(int id)
@ -35,4 +40,11 @@ public class Floor extends AbstractTile {
{
return true;
}
@Override
public Color getMapColor(Tile tile)
{
return COMMODORE.GRAY_DARK;
}
}

@ -1,6 +1,11 @@
package mightypork.rogue.world.tile.models;
import mightypork.rogue.world.tile.Tile;
import mightypork.util.math.color.Color;
import mightypork.util.math.color.RGB;
public class NullTile extends AbstractNullTile {
public NullTile(int id)
@ -15,4 +20,10 @@ public class NullTile extends AbstractNullTile {
return false;
}
@Override
public Color getMapColor(Tile tile)
{
return RGB.NONE;
}
}

@ -3,6 +3,8 @@ package mightypork.rogue.world.tile.models;
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;
public class SimpleDoor extends AbstractTile {
@ -53,4 +55,11 @@ public class SimpleDoor extends AbstractTile {
{
return false;
}
@Override
public Color getMapColor(Tile tile)
{
return COMMODORE.BROWN;
}
}

@ -1,6 +1,11 @@
package mightypork.rogue.world.tile.models;
import mightypork.rogue.world.tile.Tile;
import mightypork.util.math.color.COMMODORE;
import mightypork.util.math.color.Color;
/**
* Template for wall tiles with no metadata
*
@ -41,4 +46,10 @@ public class Wall extends AbstractTile {
return false;
}
@Override
public Color getMapColor(Tile tile)
{
return COMMODORE.GRAY_LIGHT;
}
}

@ -0,0 +1,29 @@
package mightypork.util.error;
public class YouFuckedUpException extends RuntimeException {
public YouFuckedUpException()
{
super();
}
public YouFuckedUpException(String message, Throwable cause)
{
super(message, cause);
}
public YouFuckedUpException(String message)
{
super(message);
}
public YouFuckedUpException(Throwable cause)
{
super(cause);
}
}

@ -656,4 +656,10 @@ public class Calc {
{
if (!inRange(index, 0, length - 1)) { throw new IndexOutOfBoundsException(); }
}
public static double dist(double x1, double y1, double x2, double y2)
{
return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
}
}

Loading…
Cancel
Save