Player facade, UI tweaks

v5stable
Ondřej Hruška 11 years ago
parent c74869d3b7
commit 98826985e1
  1. BIN
      res/img/gui.png
  2. BIN
      res/img/gui.xcf
  3. BIN
      res/img/gui1.png
  4. BIN
      res/img/gui1.xcf
  5. 0
      res/img/items.png
  6. 0
      res/img/items.xcf
  7. BIN
      res/img/logo.png
  8. BIN
      res/img/logo.xcf
  9. BIN
      res/img/logo2.png
  10. BIN
      res/img/logo2.xcf
  11. 0
      res/img/sprites.png
  12. 0
      res/img/sprites.xcf
  13. BIN
      res/img/tiles.png
  14. BIN
      res/img/tiles.xcf
  15. BIN
      res/img/tiles16.png
  16. BIN
      res/img/tiles16.xcf
  17. BIN
      res/img/~trash/gui1.png
  18. BIN
      res/img/~trash/gui1.xcf
  19. BIN
      res/img/~trash/logo.png
  20. BIN
      res/img/~trash/logo.xcf
  21. BIN
      res/img/~trash/tiles.png
  22. BIN
      res/img/~trash/tiles.xcf
  23. 21
      src/mightypork/gamecore/eventbus/EventBus.java
  24. 2
      src/mightypork/gamecore/gui/components/ClickableComponent.java
  25. 1
      src/mightypork/gamecore/gui/components/VisualComponent.java
  26. 2
      src/mightypork/gamecore/resources/textures/QuadGrid.java
  27. 69
      src/mightypork/gamecore/resources/textures/TextureBank.java
  28. 12
      src/mightypork/gamecore/resources/textures/TxQuad.java
  29. 5
      src/mightypork/gamecore/resources/textures/TxSheet.java
  30. 109
      src/mightypork/rogue/Res.java
  31. 2
      src/mightypork/rogue/screens/FpsOverlay.java
  32. 104
      src/mightypork/rogue/screens/game/HudLayer.java
  33. 74
      src/mightypork/rogue/screens/game/IngameNav.java
  34. 47
      src/mightypork/rogue/screens/game/NavButton.java
  35. 89
      src/mightypork/rogue/screens/game/NavItemSlot.java
  36. 2
      src/mightypork/rogue/screens/game/ScreenGame.java
  37. 2
      src/mightypork/rogue/screens/game/WorldLayer.java
  38. 26
      src/mightypork/rogue/world/PlayerControl.java
  39. 18
      src/mightypork/rogue/world/PlayerInfo.java
  40. 201
      src/mightypork/rogue/world/World.java
  41. 4
      src/mightypork/rogue/world/WorldCreator.java
  42. 8
      src/mightypork/rogue/world/WorldProvider.java
  43. 6
      src/mightypork/rogue/world/WorldRenderer.java
  44. 34
      src/mightypork/rogue/world/gui/MapView.java
  45. 10
      src/mightypork/rogue/world/gui/Minimap.java
  46. 14
      src/mightypork/rogue/world/gui/interaction/MIPKeyboard.java
  47. 33
      src/mightypork/rogue/world/gui/interaction/MIPMouse.java
  48. 25
      src/mightypork/rogue/world/gui/interaction/MapInteractionPlugin.java
  49. 4
      src/mightypork/rogue/world/tile/tiles/TileBaseEntrance.java
  50. 4
      src/mightypork/rogue/world/tile/tiles/TileBaseExit.java
  51. 2
      src/mightypork/rogue/world/tile/tiles/brick/TileBrickDoor.java

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 519 B

After

Width:  |  Height:  |  Size: 519 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 320 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 KiB

Binary file not shown.

@ -4,6 +4,7 @@ package mightypork.gamecore.eventbus;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;
@ -94,7 +95,7 @@ final public class EventBus implements Destroyable, BusAccess {
try {
dispatch(evt.getEvent());
} catch (final Throwable t) {
Log.w(logMark + "Error while dispatching event: " + t);
Log.w(logMark + "Error while dispatching event: ", t);
}
}
}
@ -136,13 +137,15 @@ final public class EventBus implements Destroyable, BusAccess {
private boolean dead = false;
/** Message channels */
private final BufferedHashSet<EventChannel<?, ?>> channels = new BufferedHashSet<>();
private final ConcurrentLinkedDeque<EventChannel<?, ?>> channels = new ConcurrentLinkedDeque<>();
/** Messages queued for delivery */
private final DelayQueue<DelayQueueEntry> sendQueue = new DelayQueue<>();
private volatile boolean sendingDirect = false;
private BusEvent<?> lastEvt;
/**
* Make a new bus and start it's queue thread.
@ -341,19 +344,9 @@ final public class EventBus implements Destroyable, BusAccess {
{
assertLive();
if (sendingDirect) {
Log.w(logMark + "Already dispatching, adding event to queue instead: " + Log.str(event));
sendQueued(event);
return;
}
sendingDirect = true;
clients.setBuffering(true);
doDispatch(clients, event);
clients.setBuffering(false);
sendingDirect = false;
}
@ -371,7 +364,7 @@ final public class EventBus implements Destroyable, BusAccess {
for (int i = 0; i < 2; i++) { // two tries.
channels.setBuffering(true);
// channels.setBuffering(true);
for (final EventChannel<?, ?> b : channels) {
if (b.canBroadcast(event)) {
accepted = true;
@ -380,7 +373,7 @@ final public class EventBus implements Destroyable, BusAccess {
if (event.isConsumed()) break;
}
channels.setBuffering(false);
// channels.setBuffering(false);
if (!accepted) if (addChannelForEvent(event)) continue;

@ -9,7 +9,7 @@ import mightypork.gamecore.input.events.MouseButtonListener;
public abstract class ClickableComponent extends InputComponent implements ActionTrigger, MouseButtonListener {
private boolean btnDownOver;
protected boolean btnDownOver;
private Action action;

@ -26,7 +26,6 @@ public abstract class VisualComponent extends AbstractRectCache implements Compo
public VisualComponent()
{
super();
enableCaching(false);
}

@ -70,7 +70,7 @@ public class QuadGrid {
/**
* Make a sheet of given cells.
* Make a sheet.
*
* @param x x origin coordinate (cells)
* @param y y origin coordinate (cells)

@ -8,18 +8,17 @@ import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.app.LightAppModule;
import mightypork.gamecore.resources.events.ResourceLoadRequest;
import mightypork.gamecore.util.error.KeyAlreadyExistsException;
import mightypork.gamecore.util.math.constraints.rect.Rect;
/**
* Texture loader and quad registry
* Texture storage and quad/sheet registry. Quads and Sheets are interchangeable
* once registered.
*
* @author MightyPork
*/
public class TextureBank extends LightAppModule {
private final Map<String, GLTexture> textures = new HashMap<>();
private final Map<String, TxQuad> quads = new HashMap<>();
private final Map<String, TxSheet> sheets = new HashMap<>();
@ -33,14 +32,27 @@ public class TextureBank extends LightAppModule {
/**
* Load a texture from resource. A full-sized quad with the same key will be
* automatically added.
* Load a texture from resource, with the resource-path as a name.
*
* @param resourcePath resource path of the texture
* @param filter
* @param wrap
* @return texture reference
*/
public GLTexture loadTexture(String resourcePath, FilterMode filter, WrapMode wrap)
{
return loadTexture(resourcePath, resourcePath, filter, wrap);
}
/**
* Load a texture from resource
*
* @param key texture key
* @param resourcePath texture resource path
* @param filter filter
* @param wrap texture wrapping
* @return the loaded texture.
* @param resourcePath resource path of the texture
* @param filter
* @param wrap
* @return texture reference
*/
public GLTexture loadTexture(String key, String resourcePath, FilterMode filter, WrapMode wrap)
{
@ -50,25 +62,11 @@ public class TextureBank extends LightAppModule {
texture.setFilter(filter);
texture.setWrap(wrap);
loadTexture(key, texture);
return texture;
}
/**
* Add an already initialized deferred texture to textures registry
*
* @param key
* @param texture
*/
public void loadTexture(String key, DeferredTexture texture)
{
getEventBus().send(new ResourceLoadRequest(texture));
textures.put(key, texture);
addQuad(key, texture.makeQuad(Rect.ONE));
return texture;
}
@ -78,11 +76,11 @@ public class TextureBank extends LightAppModule {
* @param quadKey key
* @param quad quad to add
*/
public void addQuad(String quadKey, TxQuad quad)
public void add(String quadKey, TxQuad quad)
{
if (quads.containsKey(quadKey)) throw new KeyAlreadyExistsException();
if (sheets.containsKey(quadKey)) throw new KeyAlreadyExistsException();
quads.put(quadKey, quad);
sheets.put(quadKey, quad.makeSheet(1, 1));
}
@ -92,7 +90,7 @@ public class TextureBank extends LightAppModule {
* @param sheetKey key
* @param sheet sheet to add
*/
public void addSheet(String sheetKey, TxSheet sheet)
public void add(String sheetKey, TxSheet sheet)
{
if (sheets.containsKey(sheetKey)) throw new KeyAlreadyExistsException();
@ -101,18 +99,15 @@ public class TextureBank extends LightAppModule {
/**
* Get a {@link TxQuad} for key
* Get a {@link TxQuad} for key; if it was added as sheet, the first quad
* ofthe sheet is returned.
*
* @param key quad key
* @return the quad
*/
public TxQuad getQuad(String key)
{
final TxQuad qu = quads.get(key);
if (qu == null) throw new RuntimeException("There's no quad called " + key + "!");
return qu;
return getSheet(key).getQuad(0); // get the first
}
@ -126,7 +121,7 @@ public class TextureBank extends LightAppModule {
{
final GLTexture tx = textures.get(key);
if (tx == null) throw new RuntimeException("There's no texture called " + key + "!");
if (tx == null) throw new RuntimeException("There's no texture called \"" + key + "\"!");
return tx;
}
@ -142,7 +137,9 @@ public class TextureBank extends LightAppModule {
{
final TxSheet sh = sheets.get(key);
if (sh == null) throw new RuntimeException("There's no sheet called " + key + "!");
if (sh == null) {
throw new RuntimeException("There's no sheet called \"" + key + "\"!");
}
return sh;
}

@ -152,4 +152,16 @@ public class TxQuad {
{
return flipX;
}
/**
* Use the same flit/other attributes as the original txQuad
*
* @param original
*/
public void dupeAttrs(TxQuad original)
{
this.flipX = original.flipX;
this.flipY = original.flipY;
}
}

@ -74,7 +74,10 @@ public class TxSheet {
final double origW = original.uvs.width().value();
final double origH = original.uvs.height().value();
sprites[index] = new TxQuad(original.tx, original.uvs.move(x * origW, y * origH));
final TxQuad txq = new TxQuad(original.tx, original.uvs.move(x * origW, y * origH));
txq.dupeAttrs(original);
sprites[index] = txq;
}
return sprites[index];

@ -50,12 +50,13 @@ public final class Res {
private static void loadFonts()
{
fonts.loadFont("polygon_pixel", new DeferredFont("/res/font/PolygonPixel5x7Standard.ttf", Glyphs.basic, 16));
fonts.loadFont("press_start", new DeferredFont("/res/font/PressStart2P.ttf", Glyphs.latin, 16));
fonts.loadFont("press_start", new DeferredFont("/res/font/PressStart2P.ttf", Glyphs.basic, 16));
// aliases based on concrete usage
fonts.addAlias("default", "polygon_pixel");
fonts.addAlias("main_menu_button", "press_start");
fonts.addAlias("main_menu_title", "press_start");
fonts.addAlias("hud", "press_start");
}
@ -65,69 +66,83 @@ public final class Res {
QuadGrid grid;
// gui
texture = textures.loadTexture("gui1", "/res/img/gui1.png", FilterMode.NEAREST, WrapMode.CLAMP);
final QuadGrid gui = texture.grid(4, 4);
textures.addQuad("item_frame", gui.makeQuad(0, 0));
textures.addQuad("sword", gui.makeQuad(1, 0));
textures.addQuad("meat", gui.makeQuad(2, 0));
textures.addQuad("heart_on", gui.makeQuad(.0, 1, .5, .5));
textures.addQuad("heart_off", gui.makeQuad(.5, 1, .5, .5));
textures.addQuad("heart_half", gui.makeQuad(1, 1, .5, .5));
textures.addQuad("xp_on", gui.makeQuad(0, 1.5, .5, .5));
textures.addQuad("xp_off", gui.makeQuad(.5, 1.5, .5, .5));
textures.addQuad("panel", gui.makeQuad(0, 3.75, 4, .25));
texture = textures.loadTexture("/res/img/gui.png", FilterMode.NEAREST, WrapMode.CLAMP);
// sprites
texture = textures.loadTexture("mob", "/res/img/dudes.png", FilterMode.NEAREST, WrapMode.CLAMP);
// small gui elements
grid = texture.grid(32, 32);
textures.add("hud.heart.on", grid.makeQuad(0, 0));
textures.add("hud.heart.off", grid.makeQuad(1, 0));
textures.add("hud.heart.half", grid.makeQuad(2, 0));
textures.add("hud.xp.on", grid.makeQuad(0, 1));
textures.add("hud.xp.off", grid.makeQuad(1, 1));
// nav
grid = texture.grid(8, 8);
textures.addSheet("sprite.player", grid.makeSheet(0, 0, 4, 1));
textures.addSheet("sprite.rat", grid.makeSheet(0, 1, 4, 1));
textures.add("nav.bg", grid.makeQuad(0, 7, 4, 1));
textures.add("nav.button.bg.base", grid.makeQuad(4, 7));
textures.add("nav.button.bg.hover", grid.makeQuad(5, 7));
textures.add("nav.button.bg.down", grid.makeQuad(6, 7));
textures.add("nav.button.fg.eat", grid.makeQuad(0, 6));
textures.add("nav.button.fg.inventory", grid.makeQuad(1, 6));
textures.add("nav.button.fg.attack", grid.makeQuad(2, 6));
textures.add("nav.button.fg.options", grid.makeQuad(3, 6));
textures.add("nav.button.fg.help", grid.makeQuad(4, 6));
// sprites
texture = textures.loadTexture("logo2", "/res/img/logo2.png", FilterMode.NEAREST, WrapMode.CLAMP);
textures.addQuad("logo", texture.makeQuad(Rect.make(0, 0, 0.543, 0.203)));
texture = textures.loadTexture("/res/img/sprites.png", FilterMode.NEAREST, WrapMode.CLAMP);
grid = texture.grid(8, 8);
textures.add("sprite.player", grid.makeSheet(0, 0, 4, 1));
textures.add("sprite.rat", grid.makeSheet(0, 1, 4, 1));
// logo
texture = textures.loadTexture("/res/img/logo.png", FilterMode.NEAREST, WrapMode.CLAMP);
textures.add("logo", texture.makeQuad(Rect.make(0, 0, 0.543, 0.203)));
// small sheet
texture = textures.loadTexture("tiles", "/res/img/tiles16.png", FilterMode.NEAREST, WrapMode.CLAMP);
// tiles
texture = textures.loadTexture("tiles", "/res/img/tiles.png", FilterMode.NEAREST, WrapMode.CLAMP);
grid = texture.grid(8, 8);
textures.addSheet("tile.brick.floor", grid.makeSheet(0, 1, 5, 1));
textures.addSheet("tile.brick.wall", grid.makeSheet(0, 0, 8, 1));
textures.add("tile.brick.floor", grid.makeSheet(0, 1, 5, 1));
textures.add("tile.brick.wall", grid.makeSheet(0, 0, 8, 1));
textures.addSheet("tile.brick.door.locked", grid.makeSheet(1, 2, 1, 1));//TODO unique tx
textures.addSheet("tile.brick.door.closed", grid.makeSheet(1, 2, 1, 1));
textures.addSheet("tile.brick.door.open", grid.makeSheet(2, 2, 1, 1));
textures.addSheet("tile.brick.door.secret", grid.makeSheet(0, 3, 2, 1));
textures.add("tile.brick.door.closed", grid.makeQuad(1, 2));
textures.add("tile.brick.door.open", grid.makeQuad(2, 2));
textures.add("tile.brick.door.secret", grid.makeSheet(0, 3, 2, 1));
textures.addSheet("tile.brick.passage", grid.makeSheet(3, 2, 4, 1));
textures.addQuad("tile.brick.stairs.up", grid.makeQuad(0, 6));
textures.addQuad("tile.brick.stairs.down", grid.makeQuad(1, 6));
textures.add("tile.brick.passage", grid.makeSheet(3, 2, 4, 1));
textures.add("tile.brick.stairs.up", grid.makeQuad(0, 6));
textures.add("tile.brick.stairs.down", grid.makeQuad(1, 6));
textures.addQuad("tile.shadow.n", grid.makeQuad(0, 7));
textures.addQuad("tile.shadow.s", grid.makeQuad(0, 7).flipY());
textures.addQuad("tile.shadow.w", grid.makeQuad(1, 7));
textures.addQuad("tile.shadow.e", grid.makeQuad(1, 7).flipX());
// shadows
textures.add("tile.shadow.n", grid.makeQuad(0, 7));
textures.add("tile.shadow.s", grid.makeQuad(0, 7).flipY());
textures.add("tile.shadow.w", grid.makeQuad(1, 7));
textures.add("tile.shadow.e", grid.makeQuad(1, 7).flipX());
textures.addQuad("tile.shadow.nw", grid.makeQuad(2, 7));
textures.addQuad("tile.shadow.ne", grid.makeQuad(2, 7).flipX());
textures.addQuad("tile.shadow.sw", grid.makeQuad(2, 7).flipY());
textures.addQuad("tile.shadow.se", grid.makeQuad(2, 7).flipY().flipX());
textures.add("tile.shadow.nw", grid.makeQuad(2, 7));
textures.add("tile.shadow.ne", grid.makeQuad(2, 7).flipX());
textures.add("tile.shadow.sw", grid.makeQuad(2, 7).flipY());
textures.add("tile.shadow.se", grid.makeQuad(2, 7).flipY().flipX());
// unexplored fog
textures.addQuad("tile.ufog.n", grid.makeQuad(3, 7));
textures.addQuad("tile.ufog.s", grid.makeQuad(3, 7).flipY());
textures.addQuad("tile.ufog.w", grid.makeQuad(4, 7));
textures.addQuad("tile.ufog.e", grid.makeQuad(4, 7).flipX());
textures.add("tile.ufog.n", grid.makeQuad(3, 7));
textures.add("tile.ufog.s", grid.makeQuad(3, 7).flipY());
textures.add("tile.ufog.w", grid.makeQuad(4, 7));
textures.add("tile.ufog.e", grid.makeQuad(4, 7).flipX());
textures.addQuad("tile.ufog.nw", grid.makeQuad(5, 7));
textures.addQuad("tile.ufog.ne", grid.makeQuad(5, 7).flipX());
textures.addQuad("tile.ufog.sw", grid.makeQuad(5, 7).flipY());
textures.addQuad("tile.ufog.se", grid.makeQuad(5, 7).flipY().flipX());
textures.add("tile.ufog.nw", grid.makeQuad(5, 7));
textures.add("tile.ufog.ne", grid.makeQuad(5, 7).flipX());
textures.add("tile.ufog.sw", grid.makeQuad(5, 7).flipY());
textures.add("tile.ufog.se", grid.makeQuad(5, 7).flipY().flipX());
texture = textures.loadTexture("items", "/res/img/items16.png", FilterMode.NEAREST, WrapMode.CLAMP);
texture = textures.loadTexture("items", "/res/img/items.png", FilterMode.NEAREST, WrapMode.CLAMP);
grid = texture.grid(8, 8);
textures.addQuad("item.meat", grid.makeQuad(0, 0));
textures.add("item.meat", grid.makeQuad(0, 0));
}

@ -56,6 +56,8 @@ public class FpsOverlay extends Overlay {
tp.setShadow(Color.BLACK, Vect.make(tp.height().div(16).round()));
root.add(tp);
setVisible(false); // initially hide.
}

@ -2,14 +2,15 @@ package mightypork.rogue.screens.game;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.layout.HorizontalFixedFlowLayout;
import mightypork.gamecore.gui.components.painters.ImagePainter;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.strings.StringProvider;
import mightypork.rogue.Res;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.gui.Minimap;
@ -22,7 +23,7 @@ public class HudLayer extends ScreenLayer {
@Override
public double value()
{
return WorldProvider.get().getPlayerEntity().health.getMaxHealth() / 2D;
return WorldProvider.get().getPlayer().getHealthMax() / 2D;
}
};
@ -31,81 +32,106 @@ public class HudLayer extends ScreenLayer {
@Override
public double value()
{
return WorldProvider.get().getPlayerEntity().health.getHealth() / 2D;
return WorldProvider.get().getPlayer().getHealth() / 2D;
}
};
private Minimap mm;
public HudLayer(Screen screen)
{
super(screen);
final Num h = root.height();
final Num w = root.width();
final Num minWH = w.min(h).max(700); // avoid too small shrinking
buildNav();
final ImagePainter nav = new ImagePainter(Res.txq("panel"));
nav.setRect(root.bottomEdge().growUp(minWH.perc(7)));
root.add(nav);
buildDisplays();
final HorizontalFixedFlowLayout itemSlots = new HorizontalFixedFlowLayout(root, nav.height().mul(1.8), AlignX.LEFT);
itemSlots.setRect(nav.growUp(nav.height()).move(nav.height().mul(0.2), nav.height().mul(-0.2)));
root.add(itemSlots);
buildMinimap();
itemSlots.add(new NavItemSlot(Res.txq("meat")));
itemSlots.add(new NavItemSlot(Res.txq("sword")));
bindKey(new KeyStroke(Keys.M), new Runnable() {
@Override
public void run()
{
mm.setVisible(!mm.isVisible());
}
});
}
private void buildMinimap()
{
mm = new Minimap();
mm.setRect(root.shrink(root.width().perc(5), root.height().perc(15)));
root.add(mm);
}
private void buildDisplays()
{
final Num h = root.height();
final Rect shrunk = root.shrink(minWH.perc(3));
final Num displays_height = minWH.perc(6);
final Num displays_height = h.perc(6);
//@formatter:off
final HeartBar hearts = new HeartBar(
playerHealthTotal,
playerHealthActive,
Res.txq("heart_on"),
Res.txq("heart_half"),
Res.txq("heart_off"),
Res.txq("hud.heart.on"),
Res.txq("hud.heart.half"),
Res.txq("hud.heart.off"),
AlignX.LEFT);
//@formatter:on
final Rect hearts_box = shrunk.topLeft().startRect().growDown(displays_height);
final Rect hearts_box = root.shrink(h.perc(3)).topLeft().startRect().growDown(displays_height);
hearts.setRect(hearts_box);
root.add(hearts);
/*final HeartBar experience = new HeartBar(6, 2, Res.getTxQuad("xp_on"), Res.getTxQuad("xp_off"), AlignX.RIGHT);
final Rect xp_box = shrunk.topRight().startRect().growDown(displays_height);
experience.setRect(xp_box);
root.add(experience);*/
final Minimap mm = new Minimap();
mm.setRect(root.shrink(root.width().perc(5), root.height().perc(15)));
root.add(mm);
bindKey(new KeyStroke(Keys.M), new Runnable() {
final TextPainter lvl = new TextPainter(Res.getFont("hud"), AlignX.RIGHT, RGB.WHITE, new StringProvider() {
@Override
public void run()
public String getString()
{
mm.setVisible(!mm.isVisible());
return "Floor " + (1 + WorldProvider.get().getWorld().getPlayer().getLevelNumber());
}
});
final Rect rr = root.shrink(h.perc(3)).topEdge().growDown(displays_height);
lvl.setRect(rr.shrink(Num.ZERO, rr.height().perc(20)));
root.add(lvl);
/*final HeartBar experience = new HeartBar(6, 2, Res.getTxQuad("xp_on"), Res.getTxQuad("xp_off"), AlignX.RIGHT);
final Rect xp_box = shrunk.topRight().startRect().growDown(displays_height);
experience.setRect(xp_box);
root.add(experience);*/
}
@Override
public int getZIndex()
private void buildNav()
{
return 100;
final IngameNav nav = new IngameNav(this);
nav.setRect(root.bottomEdge().growUp(root.height().perc(12)));
root.add(nav);
// ltr
nav.addLeft(new NavButton(Res.txq("nav.button.fg.inventory")));
nav.addLeft(new NavButton(Res.txq("nav.button.fg.eat")));
nav.addLeft(new NavButton(Res.txq("nav.button.fg.attack")));
// rtl
nav.addRight(new NavButton(Res.txq("nav.button.fg.options")));
nav.addRight(new NavButton(Res.txq("nav.button.fg.help")));
}
@Override
public void render()
public int getZIndex()
{
super.render();
return 100;
}

@ -0,0 +1,74 @@
package mightypork.rogue.screens.game;
import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.LayoutComponent;
import mightypork.gamecore.gui.components.layout.HorizontalFixedFlowLayout;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
import mightypork.rogue.Res;
public class IngameNav extends LayoutComponent {
private final HorizontalFixedFlowLayout leftFlow;
private final HorizontalFixedFlowLayout rightFlow;
private final Rect paintHelper;
private final TxQuad bg;
public IngameNav(AppAccess app)
{
this(app, null);
}
public IngameNav(AppAccess app, RectBound context)
{
super(app, context);
final Rect shr = this.shrink(height().perc(5));
leftFlow = new HorizontalFixedFlowLayout(app, context, shr.height(), AlignX.LEFT);
rightFlow = new HorizontalFixedFlowLayout(app, context, shr.height(), AlignX.RIGHT);
leftFlow.setRect(shr);
rightFlow.setRect(shr);
attach(leftFlow);
attach(rightFlow);
paintHelper = leftEdge().growRight(height().mul(4));
bg = Res.txq("nav.bg");
}
public void addLeft(NavButton comp)
{
leftFlow.add(comp);
}
public void addRight(NavButton comp)
{
rightFlow.add(comp);
}
@Override
public void renderComponent()
{
// draw BG (manually repeat)
for (int i = 0; i < Math.ceil(width().value() / paintHelper.width().value()); i++) {
Render.quadTextured(paintHelper.moveX(paintHelper.width().value() * i), bg);
}
super.renderComponent();
}
}

@ -0,0 +1,47 @@
package mightypork.rogue.screens.game;
import mightypork.gamecore.gui.components.ClickableComponent;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.rogue.Res;
/**
* Button in the ingame nav
*
* @author MightyPork
*/
public class NavButton extends ClickableComponent {
private final TxQuad base, hover, down, fg;
public NavButton(TxQuad fg)
{
super();
this.base = Res.txq("nav.button.bg.base");
this.hover = Res.txq("nav.button.bg.hover");
this.down = Res.txq("nav.button.bg.down");
this.fg = fg;
}
@Override
protected void renderComponent()
{
TxQuad bg;
if (btnDownOver) {
bg = down;
} else if (isMouseOver()) {
bg = hover;
} else {
bg = base;
}
Render.quadTextured(this, bg);
Render.quadTextured(this, fg);
}
}

@ -1,89 +0,0 @@
package mightypork.rogue.screens.game;
import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.gui.components.ClickableComponent;
import mightypork.gamecore.input.events.MouseMotionEvent;
import mightypork.gamecore.input.events.MouseMotionListener;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.gamecore.util.math.Easing;
import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.constraints.rect.caching.RectCache;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.Res;
public class NavItemSlot extends ClickableComponent implements MouseMotionListener, Updateable {
private final TxQuad image;
private final TxQuad frame;
private final RectCache paintBox;
private final NumAnimated yOffset;
private boolean wasInside = false;
public NavItemSlot(TxQuad image)
{
this.image = image;
this.frame = Res.txq("item_frame");
final Rect ref = shrink(height().perc(8));
yOffset = new NumAnimated(0, Easing.LINEAR);
yOffset.setDefaultDuration(0.05);
final Num h = ref.width().min(ref.height());
this.paintBox = ref.bottomLeft().startRect().grow(Num.ZERO, h, h, Num.ZERO).moveY(yOffset.mul(h.perc(-5))).cached();
}
@Override
protected void renderComponent()
{
Render.quadTextured(paintBox, frame);
Render.pushMatrix();
Render.translateXY(paintBox.center());
Render.scaleXY(0.7);
Render.rotateZ(45);
Render.quadTextured(Rect.make(paintBox.height()).centerTo(Vect.ZERO), image);
Render.popMatrix();
}
@Override
public void updateLayout()
{
paintBox.poll();
}
@Override
public void receive(MouseMotionEvent event)
{
if (event.getPos().isInside(this) != wasInside) {
if (wasInside) {
// left
yOffset.fadeOut();
} else {
// entered
yOffset.fadeIn();
}
wasInside = !wasInside;
}
}
@Override
public void update(double delta)
{
if (yOffset.isInProgress()) {
yOffset.update(delta);
paintBox.poll();
}
}
}

@ -43,7 +43,7 @@ public class ScreenGame extends LayeredScreen {
};
//pause key
bindKey(new KeyStroke(Keys.L_CONTROL, Keys.P), pauseIt);
bindKey(new KeyStroke(Keys.P), pauseIt);
bindKey(new KeyStroke(Keys.PAUSE), pauseIt);
}

@ -27,7 +27,7 @@ public class WorldLayer extends ScreenLayer {
worldView.addPlugin(new MIPMouse(worldView));
// size of lower navbar
final Num lownav = root.width().min(root.height()).max(700).perc(7);
final Num lownav = root.height().perc(12);
worldView.setRect(root.shrinkBottom(lownav));
root.add(worldView);

@ -6,7 +6,7 @@ import java.util.Set;
import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.algo.Step;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.World.PlayerFacade;
import mightypork.rogue.world.entity.modules.EntityMoveListener;
import mightypork.rogue.world.level.Level;
@ -37,11 +37,11 @@ public abstract class PlayerControl {
}
public Entity getPlayerEntity()
public PlayerFacade getPlayer()
{
if (getWorld() == null) return null;
return getWorld().getPlayerEntity();
return getWorld().getPlayer();
}
@ -72,25 +72,19 @@ public abstract class PlayerControl {
public void navigateTo(Coord pos)
{
if (!getLevel().getTile(pos).isExplored()) return;
getPlayerEntity().pos.navigateTo(pos);
getPlayer().navigateTo(pos);
}
public Level getLevel()
{
return getWorld().getCurrentLevel();
}
public Coord getCoord()
{
return getPlayerEntity().pos.getCoord();
return getWorld().getPlayer().getLevel();
}
public boolean canGo(Step side)
{
return getLevel().getTile(getCoord().add(side)).isWalkable();
return getLevel().getTile(getPlayer().getCoord().add(side)).isWalkable();
}
@ -102,13 +96,13 @@ public abstract class PlayerControl {
*/
public boolean clickTile(Step side)
{
return clickTile(getCoord().add(side));
return clickTile(getPlayer().getCoord().add(side));
}
public boolean clickTile(Coord pos)
{
if (pos.dist(getCoord()) > 8) return false; // too far
if (pos.dist(getPlayer().getCoord()) > 8) return false; // too far
return getLevel().getTile(pos).onClick();
}
@ -116,8 +110,8 @@ public abstract class PlayerControl {
public void go(Step side)
{
getPlayerEntity().pos.cancelPath();
getPlayerEntity().pos.addStep(side);
getPlayer().cancelPath();
getPlayer().addPathStep(side);
}

@ -2,9 +2,12 @@ package mightypork.rogue.world;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import mightypork.gamecore.util.ion.IonBundle;
import mightypork.gamecore.util.ion.IonObjBundled;
import mightypork.rogue.world.item.Item;
public class PlayerInfo implements IonObjBundled {
@ -12,12 +15,17 @@ public class PlayerInfo implements IonObjBundled {
private int eid = -1; // marks not initialized
private int level;
private final List<Item> inventory = new ArrayList<>();
private int selectedWeapon = -1;
@Override
public void load(IonBundle bundle) throws IOException
{
eid = bundle.get("eid", 0);
level = bundle.get("floor", 0);
eid = bundle.get("eid", eid);
level = bundle.get("floor", level);
selectedWeapon = bundle.get("weapon", selectedWeapon);
bundle.loadSequence("inv", inventory);
}
@ -26,6 +34,8 @@ public class PlayerInfo implements IonObjBundled {
{
bundle.put("eid", eid);
bundle.put("floor", level);
bundle.put("weapon", selectedWeapon);
bundle.putSequence("inv", inventory);
}
@ -36,7 +46,7 @@ public class PlayerInfo implements IonObjBundled {
}
public void setLevel(int level)
public void setLevelNumber(int level)
{
this.level = level;
}
@ -48,7 +58,7 @@ public class PlayerInfo implements IonObjBundled {
}
public int getLevel()
public int getLevelNumber()
{
return level;
}

@ -12,6 +12,8 @@ import mightypork.gamecore.eventbus.clients.DelegatingClient;
import mightypork.gamecore.util.ion.IonBundle;
import mightypork.gamecore.util.ion.IonObjBundled;
import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.algo.Step;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.gamecore.util.math.timing.Pauseable;
import mightypork.rogue.world.entity.Entities;
import mightypork.rogue.world.entity.Entity;
@ -25,12 +27,146 @@ import mightypork.rogue.world.level.Level;
*/
public class World implements DelegatingClient, BusAccess, IonObjBundled, Pauseable {
private final ArrayList<Level> levels = new ArrayList<>();
/**
* Convenient access to player-related methods and data
*
* @author MightyPork
*/
public class PlayerFacade {
public boolean canAscend()
{
return playerInfo.getLevelNumber() > 0;
}
public void descend()
{
if (!canDescend()) return;
final int lvl_num = getLevelNumber();
getLevel().removeEntity(playerEntity);
playerInfo.setLevelNumber(lvl_num + 1);
getLevel().addEntity(playerEntity, getLevel().getEnterPoint());
getLevel().explore(getCoord());
}
public boolean canDescend()
{
return playerInfo.getLevelNumber() < levels.size() - 1;
}
public void ascend()
{
if (!canAscend()) return;
final int lvl_num = getLevelNumber();
getLevel().removeEntity(playerEntity);
playerInfo.setLevelNumber(lvl_num - 1);
getLevel().addEntity(playerEntity, getLevel().getExitPoint());
getLevel().explore(getCoord());
}
/**
* @return current level number, zero based.
*/
public int getLevelNumber()
{
return playerInfo.getLevelNumber();
}
public Level getLevel()
{
return levels.get(playerInfo.getLevelNumber());
}
public int getEID()
{
return playerInfo.getEID();
}
public Coord getCoord()
{
return playerEntity.getCoord();
}
public Vect getVisualPos()
{
return playerEntity.pos.getVisualPos();
}
public void navigateTo(Coord pos)
{
playerEntity.pos.navigateTo(pos);
}
public void cancelPath()
{
playerEntity.pos.cancelPath();
}
public void addPathStep(Step step)
{
playerEntity.pos.addStep(step);
}
public boolean isMoving()
{
return playerEntity.pos.isMoving();
}
public double getMoveProgress()
{
return playerEntity.pos.getProgress();
}
public boolean isDead()
{
return playerEntity.isDead();
}
public int getHealth()
{
return playerEntity.health.getHealth();
}
public int getHealthMax()
{
return playerEntity.health.getMaxHealth();
}
}
private final PlayerInfo playerInfo = new PlayerInfo();
// not saved stuffs
private final PlayerFacade player = new PlayerFacade();
private Entity playerEntity;
private BusAccess bus;
private boolean paused;
private final ArrayList<Level> levels = new ArrayList<>();
private final PlayerInfo playerInfo = new PlayerInfo();
/** World seed */
private long seed;
@ -38,8 +174,6 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
/** Next entity ID */
private int eid;
private boolean paused;
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
@ -70,7 +204,7 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
in.loadBundled("player", playerInfo);
playerEntity = levels.get(playerInfo.getLevel()).getEntity(playerInfo.getEID());
playerEntity = levels.get(playerInfo.getLevelNumber()).getEntity(playerInfo.getEID());
if (playerEntity == null) {
throw new RuntimeException("Player entity not found in the world.");
}
@ -115,7 +249,7 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
}
public void createPlayer(int level)
public void createPlayer()
{
if (playerInfo.isInitialized()) {
throw new RuntimeException("Player already created.");
@ -124,10 +258,7 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
// make entity
final int playerEid = getNewEID();
final Level floor = levels.get(level);
if (floor == null) {
throw new IndexOutOfBoundsException("No such level: " + level);
}
final Level floor = levels.get(0);
playerEntity = Entities.PLAYER.createEntity(playerEid);
@ -143,23 +274,11 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
floor.explore(spawn);
playerInfo.setLevel(level);
playerInfo.setLevelNumber(0);
playerInfo.setEID(playerEid);
}
public Level getCurrentLevel()
{
return levels.get(playerInfo.getLevel());
}
public Entity getPlayerEntity()
{
return playerEntity;
}
/**
* Attach to an event bus
*
@ -200,39 +319,9 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
}
public boolean canAscend()
{
return playerInfo.getLevel() > 0;
}
public boolean canDescend()
{
return playerInfo.getLevel() < levels.size() - 1;
}
public void ascend()
public PlayerFacade getPlayer()
{
if (!canAscend()) return;
int lvl_num = playerInfo.getLevel();
getCurrentLevel().removeEntity(playerEntity);
playerInfo.setLevel(lvl_num - 1);
getCurrentLevel().addEntity(playerEntity, getCurrentLevel().getExitPoint());
getCurrentLevel().explore(playerEntity.getCoord());
}
public void descend()
{
if (!canDescend()) return;
int lvl_num = playerInfo.getLevel();
getCurrentLevel().removeEntity(playerEntity);
playerInfo.setLevel(lvl_num + 1);
getCurrentLevel().addEntity(playerEntity, getCurrentLevel().getEnterPoint());
getCurrentLevel().explore(playerEntity.getCoord());
return player;
}
}

@ -20,14 +20,14 @@ public class WorldCreator {
final World w = new World();
w.setSeed(seed);
int count = 6;
final int count = 6;
for (int i = 1; i <= count; i++) {
final Level l = LevelGenerator.build(w, rand.nextLong(), i, LevelGenerator.DUNGEON_THEME, i == count);
w.addLevel(l);
}
w.createPlayer(0);
w.createPlayer();
return w;
}

@ -7,7 +7,7 @@ import java.io.IOException;
import mightypork.gamecore.eventbus.BusAccess;
import mightypork.gamecore.eventbus.clients.RootBusNode;
import mightypork.gamecore.util.ion.Ion;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.World.PlayerFacade;
import mightypork.rogue.world.level.Level;
@ -87,13 +87,13 @@ public class WorldProvider extends RootBusNode {
public Level getCurrentLevel()
{
return getWorld().getCurrentLevel();
return getWorld().getPlayer().getLevel();
}
public Entity getPlayerEntity()
public PlayerFacade getPlayer()
{
return getWorld().getPlayerEntity();
return getWorld().getPlayer();
}

@ -71,8 +71,7 @@ public class WorldRenderer extends RectProxy {
private VectConst getOffset()
{
final Entity ent = WorldProvider.get().getPlayerEntity();
return Vect.make(ent.pos.getVisualPos().neg().sub(0.5, 0.5)).freeze();
return Vect.make(WorldProvider.get().getPlayer().getVisualPos().neg().sub(0.5, 0.5)).freeze();
}
@ -87,9 +86,8 @@ public class WorldRenderer extends RectProxy {
Render.translate(getOffset());
// tiles to render
final Entity ent = WorldProvider.get().getPlayerEntity();
final Coord pos = ent.getCoord();
final Coord pos = WorldProvider.get().getPlayer().getCoord();
final double w = width().value();
final double h = height().value();

@ -42,33 +42,33 @@ public class MapView extends InputComponent implements DelegatingClient, KeyList
private static final double transition_time = 0.8;
protected final WorldRenderer worldRenderer;
public final PlayerControl playerControl;
public final PlayerControl plc;
private final Set<MapInteractionPlugin> plugins = new LinkedHashSet<>();
private final NumAnimated zoom = new NumAnimated(0, Easing.SINE_BOTH);
private boolean zoom_in = true;
private NumAnimated descFadeAnim = new NumAnimated(0);
private Color blackColor = RGB.BLACK.withAlpha(descFadeAnim);
private final NumAnimated descFadeAnim = new NumAnimated(0);
private final Color blackColor = RGB.BLACK.withAlpha(descFadeAnim);
private int descDir = 0;
private TimedTask timerDesc1 = new TimedTask() {
private final TimedTask timerDesc1 = new TimedTask() {
@Override
public void run()
{
descFadeAnim.fadeOut(transition_time);
timerDesc2.start(transition_time);
timerDesc2.start(transition_time);
if (descDir == 1) {
WorldProvider.get().getWorld().descend();
WorldProvider.get().getWorld().getPlayer().descend();
} else {
WorldProvider.get().getWorld().ascend();
WorldProvider.get().getWorld().getPlayer().ascend();
}
}
};
private TimedTask timerDesc2 = new TimedTask() {
private final TimedTask timerDesc2 = new TimedTask() {
@Override
public void run()
@ -100,7 +100,7 @@ public class MapView extends InputComponent implements DelegatingClient, KeyList
{
this.tileSize = height().min(width()).div(10).max(32).mul(Num.make(1).sub(zoom.mul(0.5)));
this.worldRenderer = new WorldRenderer(this, tileSize);
playerControl = WorldProvider.get().getPlayerControl();
plc = WorldProvider.get().getPlayerControl();
zoom.setDefaultDuration(0.5);
}
@ -194,11 +194,11 @@ public class MapView extends InputComponent implements DelegatingClient, KeyList
@Override
public void onAscendRequest()
{
if(descFadeAnim.isInProgress()) return;
if (descFadeAnim.isInProgress()) return;
World w = WorldProvider.get().getWorld();
final World w = WorldProvider.get().getWorld();
if (w.canAscend()) {
if (w.getPlayer().canAscend()) {
descDir = -1;
startDescAnim();
}
@ -214,16 +214,16 @@ public class MapView extends InputComponent implements DelegatingClient, KeyList
descFadeAnim.setTo(0);
descFadeAnim.fadeIn(transition_time);
}
@Override
public void onDescendRequest()
{
if(descFadeAnim.isInProgress()) return;
if (descFadeAnim.isInProgress()) return;
World w = WorldProvider.get().getWorld();
final World w = WorldProvider.get().getWorld();
if (w.canDescend()) {
if (w.getPlayer().canDescend()) {
descDir = 1;
startDescAnim();
}

@ -12,8 +12,8 @@ import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.constraints.rect.mutable.RectMutable;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.world.World.PlayerFacade;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.level.Level;
import mightypork.rogue.world.tile.Tile;
@ -36,8 +36,7 @@ public class Minimap extends InputComponent implements MouseButtonListener {
final Level lvl = WorldProvider.get().getCurrentLevel();
unit = (int) Math.min(Math.max(2, Math.ceil((height().value() / 2) / (lvl.getHeight() + 2))), 10);
final Entity e = WorldProvider.get().getPlayerEntity();
final Vect plCoord = e.pos.getVisualPos();
final Vect plCoord = WorldProvider.get().getPlayer().getVisualPos();
final int lw = lvl.getWidth();
final int lh = lvl.getHeight();
@ -93,10 +92,11 @@ public class Minimap extends InputComponent implements MouseButtonListener {
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 = WorldProvider.get().getPlayerEntity();
final PlayerFacade player = WorldProvider.get().getPlayer();
if (player.getLevel().getTile(actual).isExplored()) {
player.pos.navigateTo(actual);
player.navigateTo(actual);
}
}

@ -43,11 +43,13 @@ public class MIPKeyboard extends MapInteractionPlugin implements PlayerStepEndLi
@Override
public void receive(KeyEvent evt)
{
if (evt.isDown() || mapView.playerControl.getPlayerEntity().pos.isMoving()) return; // not interested
if (isImmobile()) return;
if (evt.isDown() || mapView.plc.getPlayer().isMoving()) return; // not interested
for (int i = 0; i < 4; i++) {
if (evt.getKey() == keys[i]) {
mapView.playerControl.clickTile(sides[i]);
mapView.plc.clickTile(sides[i]);
}
}
}
@ -55,14 +57,16 @@ public class MIPKeyboard extends MapInteractionPlugin implements PlayerStepEndLi
private boolean walkByKey()
{
if (mapView.playerControl.getPlayerEntity().pos.getProgress()<0.8) return false;
if (isImmobile()) return false;
if (mapView.plc.getPlayer().getMoveProgress() < 0.8) return false;
for (int i = 0; i < 4; i++) {
if (InputSystem.isKeyDown(keys[i])) {
final Step side = sides[i];
if (mapView.playerControl.canGo(side)) {
mapView.playerControl.go(side);
if (mapView.plc.canGo(side)) {
mapView.plc.go(side);
return true;
} else {
return false;

@ -28,12 +28,14 @@ public class MIPMouse extends MapInteractionPlugin implements PlayerStepEndListe
@Override
public void update(double delta)
{
if (isImmobile()) return;
final Vect pos = InputSystem.getMousePos();
if (!pos.isInside(mapView)) return;
if (InputSystem.isMouseButtonDown(BTN)) {
if (mouseWalk(pos)) return;
if (mapView.playerControl.getPlayerEntity().pos.isMoving() && troToNav(pos)) return;
if (mapView.plc.getPlayer().isMoving() && troToNav(pos)) return;
}
}
@ -41,8 +43,10 @@ public class MIPMouse extends MapInteractionPlugin implements PlayerStepEndListe
@Override
public boolean onClick(Vect mouse, int button, boolean down)
{
if (isImmobile()) return false;
final Coord pos = mapView.toWorldPos(mouse);
final Tile t = mapView.playerControl.getLevel().getTile(pos);
final Tile t = mapView.plc.getLevel().getTile(pos);
if (button == BTN && !down && t.onClick()) {
return true;
@ -59,21 +63,25 @@ public class MIPMouse extends MapInteractionPlugin implements PlayerStepEndListe
private boolean troToNav(Vect mouse)
{
final Coord plpos = mapView.playerControl.getCoord();
if (isImmobile()) return false;
final Coord plpos = mapView.plc.getPlayer().getCoord();
final Coord clicked = mapView.toWorldPos(mouse);
if (clicked.equals(plpos)) return false;
final Tile t = mapView.playerControl.getLevel().getTile(clicked);
final Tile t = mapView.plc.getLevel().getTile(clicked);
if (!t.isWalkable() || !t.isExplored()) return false;
mapView.playerControl.navigateTo(clicked);
mapView.plc.navigateTo(clicked);
return true;
}
private boolean mouseWalk(Vect pos)
{
final Coord plpos = mapView.playerControl.getCoord();
if (isImmobile()) return false;
final Coord plpos = mapView.plc.getPlayer().getCoord();
final Coord clicked = mapView.toWorldPos(pos);
if (clicked.equals(plpos)) return false;
@ -83,30 +91,33 @@ public class MIPMouse extends MapInteractionPlugin implements PlayerStepEndListe
switch (dir) {
case 0:
return mapView.playerControl.tryGo(Sides.E);
return mapView.plc.tryGo(Sides.E);
case 1:
return mapView.playerControl.tryGo(Sides.S);
return mapView.plc.tryGo(Sides.S);
case 2:
return mapView.playerControl.tryGo(Sides.W);
return mapView.plc.tryGo(Sides.W);
case 3:
return mapView.playerControl.tryGo(Sides.N);
return mapView.plc.tryGo(Sides.N);
}
return false;
}
@Override
public void onStepFinished(PlayerEntity player)
{
if (isImmobile()) return;
final Vect pos = InputSystem.getMousePos();
if (!pos.isInside(mapView)) return;
if (InputSystem.isMouseButtonDown(BTN)) {
if (mouseWalk(pos)) return;
if (mapView.playerControl.getPlayerEntity().pos.isMoving() && troToNav(pos)) return;
if (mapView.plc.getPlayer().isMoving() && troToNav(pos)) return;
}
}

@ -1,11 +1,10 @@
package mightypork.rogue.world.gui.interaction;
import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.input.events.KeyEvent;
import mightypork.gamecore.input.events.KeyListener;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.world.events.PlayerStepEndListener;
import mightypork.rogue.world.World;
import mightypork.rogue.world.World.PlayerFacade;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.gui.MapView;
@ -21,5 +20,23 @@ public abstract class MapInteractionPlugin {
}
protected PlayerFacade getPlayer()
{
return mapView.plc.getPlayer();
}
protected boolean isImmobile()
{
return getPlayer().isDead() || getWorld().isPaused();
}
protected World getWorld()
{
return WorldProvider.get().getWorld();
}
public abstract boolean onClick(Vect mouse, int button, boolean down);
}

@ -17,8 +17,8 @@ public abstract class TileBaseEntrance extends TileBaseStairs {
@Override
public boolean onClick()
{
Coord plpos = getWorld().getPlayerEntity().getCoord();
if(!plpos.equals(getLevel().getEnterPoint())) return false;
final Coord plpos = getWorld().getPlayer().getCoord();
if (!plpos.equals(getLevel().getEnterPoint())) return false;
getEventBus().send(new WorldAscendRequest());

@ -17,8 +17,8 @@ public abstract class TileBaseExit extends TileBaseStairs {
@Override
public boolean onClick()
{
Coord plpos = getWorld().getPlayerEntity().getCoord();
if(!plpos.equals(getLevel().getExitPoint())) return false;
final Coord plpos = getWorld().getPlayer().getCoord();
if (!plpos.equals(getLevel().getExitPoint())) return false;
getEventBus().send(new WorldDescendRequest());

@ -13,7 +13,7 @@ public class TileBrickDoor extends TileBaseDoor {
//@formatter:off
super(
model,
Res.txs("tile.brick.door.locked"),
Res.txs("tile.brick.door.closed"), // LOCKED
Res.txs("tile.brick.door.closed"),
Res.txs("tile.brick.door.open")
);

Loading…
Cancel
Save