Player facade, UI tweaks
|
After Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 519 B After Width: | Height: | Size: 519 B |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 320 KiB After Width: | Height: | Size: 8.9 KiB |
|
Before Width: | Height: | Size: 8.9 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 320 KiB |
@@ -4,6 +4,7 @@ package mightypork.gamecore.eventbus;
|
|||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||||
import java.util.concurrent.DelayQueue;
|
import java.util.concurrent.DelayQueue;
|
||||||
import java.util.concurrent.Delayed;
|
import java.util.concurrent.Delayed;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -94,7 +95,7 @@ final public class EventBus implements Destroyable, BusAccess {
|
|||||||
try {
|
try {
|
||||||
dispatch(evt.getEvent());
|
dispatch(evt.getEvent());
|
||||||
} catch (final Throwable t) {
|
} 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;
|
private boolean dead = false;
|
||||||
|
|
||||||
/** Message channels */
|
/** Message channels */
|
||||||
private final BufferedHashSet<EventChannel<?, ?>> channels = new BufferedHashSet<>();
|
private final ConcurrentLinkedDeque<EventChannel<?, ?>> channels = new ConcurrentLinkedDeque<>();
|
||||||
|
|
||||||
/** Messages queued for delivery */
|
/** Messages queued for delivery */
|
||||||
private final DelayQueue<DelayQueueEntry> sendQueue = new DelayQueue<>();
|
private final DelayQueue<DelayQueueEntry> sendQueue = new DelayQueue<>();
|
||||||
|
|
||||||
private volatile boolean sendingDirect = false;
|
private volatile boolean sendingDirect = false;
|
||||||
|
|
||||||
|
private BusEvent<?> lastEvt;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a new bus and start it's queue thread.
|
* Make a new bus and start it's queue thread.
|
||||||
@@ -341,19 +344,9 @@ final public class EventBus implements Destroyable, BusAccess {
|
|||||||
{
|
{
|
||||||
assertLive();
|
assertLive();
|
||||||
|
|
||||||
if (sendingDirect) {
|
|
||||||
Log.w(logMark + "Already dispatching, adding event to queue instead: " + Log.str(event));
|
|
||||||
sendQueued(event);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sendingDirect = true;
|
|
||||||
|
|
||||||
clients.setBuffering(true);
|
clients.setBuffering(true);
|
||||||
doDispatch(clients, event);
|
doDispatch(clients, event);
|
||||||
clients.setBuffering(false);
|
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.
|
for (int i = 0; i < 2; i++) { // two tries.
|
||||||
|
|
||||||
channels.setBuffering(true);
|
// channels.setBuffering(true);
|
||||||
for (final EventChannel<?, ?> b : channels) {
|
for (final EventChannel<?, ?> b : channels) {
|
||||||
if (b.canBroadcast(event)) {
|
if (b.canBroadcast(event)) {
|
||||||
accepted = true;
|
accepted = true;
|
||||||
@@ -380,7 +373,7 @@ final public class EventBus implements Destroyable, BusAccess {
|
|||||||
|
|
||||||
if (event.isConsumed()) break;
|
if (event.isConsumed()) break;
|
||||||
}
|
}
|
||||||
channels.setBuffering(false);
|
// channels.setBuffering(false);
|
||||||
|
|
||||||
if (!accepted) if (addChannelForEvent(event)) continue;
|
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 {
|
public abstract class ClickableComponent extends InputComponent implements ActionTrigger, MouseButtonListener {
|
||||||
|
|
||||||
private boolean btnDownOver;
|
protected boolean btnDownOver;
|
||||||
private Action action;
|
private Action action;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ public abstract class VisualComponent extends AbstractRectCache implements Compo
|
|||||||
|
|
||||||
public VisualComponent()
|
public VisualComponent()
|
||||||
{
|
{
|
||||||
super();
|
|
||||||
enableCaching(false);
|
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 x x origin coordinate (cells)
|
||||||
* @param y y 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.app.LightAppModule;
|
||||||
import mightypork.gamecore.resources.events.ResourceLoadRequest;
|
import mightypork.gamecore.resources.events.ResourceLoadRequest;
|
||||||
import mightypork.gamecore.util.error.KeyAlreadyExistsException;
|
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
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
public class TextureBank extends LightAppModule {
|
public class TextureBank extends LightAppModule {
|
||||||
|
|
||||||
private final Map<String, GLTexture> textures = new HashMap<>();
|
private final Map<String, GLTexture> textures = new HashMap<>();
|
||||||
private final Map<String, TxQuad> quads = new HashMap<>();
|
|
||||||
private final Map<String, TxSheet> sheets = 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
|
* Load a texture from resource, with the resource-path as a name.
|
||||||
* automatically added.
|
*
|
||||||
|
* @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 key texture key
|
||||||
* @param resourcePath texture resource path
|
* @param resourcePath resource path of the texture
|
||||||
* @param filter filter
|
* @param filter
|
||||||
* @param wrap texture wrapping
|
* @param wrap
|
||||||
* @return the loaded texture.
|
* @return texture reference
|
||||||
*/
|
*/
|
||||||
public GLTexture loadTexture(String key, String resourcePath, FilterMode filter, WrapMode wrap)
|
public GLTexture loadTexture(String key, String resourcePath, FilterMode filter, WrapMode wrap)
|
||||||
{
|
{
|
||||||
@@ -50,25 +62,11 @@ public class TextureBank extends LightAppModule {
|
|||||||
texture.setFilter(filter);
|
texture.setFilter(filter);
|
||||||
texture.setWrap(wrap);
|
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));
|
getEventBus().send(new ResourceLoadRequest(texture));
|
||||||
|
|
||||||
textures.put(key, 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 quadKey key
|
||||||
* @param quad quad to add
|
* @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 sheetKey key
|
||||||
* @param sheet sheet to add
|
* @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();
|
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
|
* @param key quad key
|
||||||
* @return the quad
|
* @return the quad
|
||||||
*/
|
*/
|
||||||
public TxQuad getQuad(String key)
|
public TxQuad getQuad(String key)
|
||||||
{
|
{
|
||||||
final TxQuad qu = quads.get(key);
|
return getSheet(key).getQuad(0); // get the first
|
||||||
|
|
||||||
if (qu == null) throw new RuntimeException("There's no quad called " + key + "!");
|
|
||||||
|
|
||||||
return qu;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -126,7 +121,7 @@ public class TextureBank extends LightAppModule {
|
|||||||
{
|
{
|
||||||
final GLTexture tx = textures.get(key);
|
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;
|
return tx;
|
||||||
}
|
}
|
||||||
@@ -142,7 +137,9 @@ public class TextureBank extends LightAppModule {
|
|||||||
{
|
{
|
||||||
final TxSheet sh = sheets.get(key);
|
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;
|
return sh;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,4 +152,16 @@ public class TxQuad {
|
|||||||
{
|
{
|
||||||
return flipX;
|
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 origW = original.uvs.width().value();
|
||||||
final double origH = original.uvs.height().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];
|
return sprites[index];
|
||||||
|
|||||||
@@ -50,12 +50,13 @@ public final class Res {
|
|||||||
private static void loadFonts()
|
private static void loadFonts()
|
||||||
{
|
{
|
||||||
fonts.loadFont("polygon_pixel", new DeferredFont("/res/font/PolygonPixel5x7Standard.ttf", Glyphs.basic, 16));
|
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
|
// aliases based on concrete usage
|
||||||
fonts.addAlias("default", "polygon_pixel");
|
fonts.addAlias("default", "polygon_pixel");
|
||||||
fonts.addAlias("main_menu_button", "press_start");
|
fonts.addAlias("main_menu_button", "press_start");
|
||||||
fonts.addAlias("main_menu_title", "press_start");
|
fonts.addAlias("main_menu_title", "press_start");
|
||||||
|
fonts.addAlias("hud", "press_start");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -65,69 +66,83 @@ public final class Res {
|
|||||||
QuadGrid grid;
|
QuadGrid grid;
|
||||||
|
|
||||||
// gui
|
// gui
|
||||||
texture = textures.loadTexture("gui1", "/res/img/gui1.png", FilterMode.NEAREST, WrapMode.CLAMP);
|
texture = textures.loadTexture("/res/img/gui.png", FilterMode.NEAREST, WrapMode.CLAMP);
|
||||||
final QuadGrid gui = texture.grid(4, 4);
|
|
||||||
textures.addQuad("item_frame", gui.makeQuad(0, 0));
|
// small gui elements
|
||||||
textures.addQuad("sword", gui.makeQuad(1, 0));
|
grid = texture.grid(32, 32);
|
||||||
textures.addQuad("meat", gui.makeQuad(2, 0));
|
textures.add("hud.heart.on", grid.makeQuad(0, 0));
|
||||||
textures.addQuad("heart_on", gui.makeQuad(.0, 1, .5, .5));
|
textures.add("hud.heart.off", grid.makeQuad(1, 0));
|
||||||
textures.addQuad("heart_off", gui.makeQuad(.5, 1, .5, .5));
|
textures.add("hud.heart.half", grid.makeQuad(2, 0));
|
||||||
textures.addQuad("heart_half", gui.makeQuad(1, 1, .5, .5));
|
textures.add("hud.xp.on", grid.makeQuad(0, 1));
|
||||||
textures.addQuad("xp_on", gui.makeQuad(0, 1.5, .5, .5));
|
textures.add("hud.xp.off", grid.makeQuad(1, 1));
|
||||||
textures.addQuad("xp_off", gui.makeQuad(.5, 1.5, .5, .5));
|
|
||||||
textures.addQuad("panel", gui.makeQuad(0, 3.75, 4, .25));
|
// nav
|
||||||
|
grid = texture.grid(8, 8);
|
||||||
|
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
|
// sprites
|
||||||
texture = textures.loadTexture("mob", "/res/img/dudes.png", FilterMode.NEAREST, WrapMode.CLAMP);
|
texture = textures.loadTexture("/res/img/sprites.png", FilterMode.NEAREST, WrapMode.CLAMP);
|
||||||
grid = texture.grid(8, 8);
|
grid = texture.grid(8, 8);
|
||||||
textures.addSheet("sprite.player", grid.makeSheet(0, 0, 4, 1));
|
textures.add("sprite.player", grid.makeSheet(0, 0, 4, 1));
|
||||||
textures.addSheet("sprite.rat", grid.makeSheet(0, 1, 4, 1));
|
textures.add("sprite.rat", grid.makeSheet(0, 1, 4, 1));
|
||||||
|
|
||||||
// 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)));
|
|
||||||
|
|
||||||
// small sheet
|
// logo
|
||||||
texture = textures.loadTexture("tiles", "/res/img/tiles16.png", FilterMode.NEAREST, WrapMode.CLAMP);
|
texture = textures.loadTexture("/res/img/logo.png", FilterMode.NEAREST, WrapMode.CLAMP);
|
||||||
|
textures.add("logo", texture.makeQuad(Rect.make(0, 0, 0.543, 0.203)));
|
||||||
|
|
||||||
|
|
||||||
|
// tiles
|
||||||
|
texture = textures.loadTexture("tiles", "/res/img/tiles.png", FilterMode.NEAREST, WrapMode.CLAMP);
|
||||||
grid = texture.grid(8, 8);
|
grid = texture.grid(8, 8);
|
||||||
|
|
||||||
textures.addSheet("tile.brick.floor", grid.makeSheet(0, 1, 5, 1));
|
textures.add("tile.brick.floor", grid.makeSheet(0, 1, 5, 1));
|
||||||
textures.addSheet("tile.brick.wall", grid.makeSheet(0, 0, 8, 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.add("tile.brick.door.closed", grid.makeQuad(1, 2));
|
||||||
textures.addSheet("tile.brick.door.closed", grid.makeSheet(1, 2, 1, 1));
|
textures.add("tile.brick.door.open", grid.makeQuad(2, 2));
|
||||||
textures.addSheet("tile.brick.door.open", grid.makeSheet(2, 2, 1, 1));
|
textures.add("tile.brick.door.secret", grid.makeSheet(0, 3, 2, 1));
|
||||||
textures.addSheet("tile.brick.door.secret", grid.makeSheet(0, 3, 2, 1));
|
|
||||||
|
|
||||||
textures.addSheet("tile.brick.passage", grid.makeSheet(3, 2, 4, 1));
|
textures.add("tile.brick.passage", grid.makeSheet(3, 2, 4, 1));
|
||||||
textures.addQuad("tile.brick.stairs.up", grid.makeQuad(0, 6));
|
textures.add("tile.brick.stairs.up", grid.makeQuad(0, 6));
|
||||||
textures.addQuad("tile.brick.stairs.down", grid.makeQuad(1, 6));
|
textures.add("tile.brick.stairs.down", grid.makeQuad(1, 6));
|
||||||
|
|
||||||
textures.addQuad("tile.shadow.n", grid.makeQuad(0, 7));
|
// shadows
|
||||||
textures.addQuad("tile.shadow.s", grid.makeQuad(0, 7).flipY());
|
textures.add("tile.shadow.n", grid.makeQuad(0, 7));
|
||||||
textures.addQuad("tile.shadow.w", grid.makeQuad(1, 7));
|
textures.add("tile.shadow.s", grid.makeQuad(0, 7).flipY());
|
||||||
textures.addQuad("tile.shadow.e", grid.makeQuad(1, 7).flipX());
|
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.add("tile.shadow.nw", grid.makeQuad(2, 7));
|
||||||
textures.addQuad("tile.shadow.ne", grid.makeQuad(2, 7).flipX());
|
textures.add("tile.shadow.ne", grid.makeQuad(2, 7).flipX());
|
||||||
textures.addQuad("tile.shadow.sw", grid.makeQuad(2, 7).flipY());
|
textures.add("tile.shadow.sw", grid.makeQuad(2, 7).flipY());
|
||||||
textures.addQuad("tile.shadow.se", grid.makeQuad(2, 7).flipY().flipX());
|
textures.add("tile.shadow.se", grid.makeQuad(2, 7).flipY().flipX());
|
||||||
|
|
||||||
// unexplored fog
|
// unexplored fog
|
||||||
textures.addQuad("tile.ufog.n", grid.makeQuad(3, 7));
|
textures.add("tile.ufog.n", grid.makeQuad(3, 7));
|
||||||
textures.addQuad("tile.ufog.s", grid.makeQuad(3, 7).flipY());
|
textures.add("tile.ufog.s", grid.makeQuad(3, 7).flipY());
|
||||||
textures.addQuad("tile.ufog.w", grid.makeQuad(4, 7));
|
textures.add("tile.ufog.w", grid.makeQuad(4, 7));
|
||||||
textures.addQuad("tile.ufog.e", grid.makeQuad(4, 7).flipX());
|
textures.add("tile.ufog.e", grid.makeQuad(4, 7).flipX());
|
||||||
|
|
||||||
textures.addQuad("tile.ufog.nw", grid.makeQuad(5, 7));
|
textures.add("tile.ufog.nw", grid.makeQuad(5, 7));
|
||||||
textures.addQuad("tile.ufog.ne", grid.makeQuad(5, 7).flipX());
|
textures.add("tile.ufog.ne", grid.makeQuad(5, 7).flipX());
|
||||||
textures.addQuad("tile.ufog.sw", grid.makeQuad(5, 7).flipY());
|
textures.add("tile.ufog.sw", grid.makeQuad(5, 7).flipY());
|
||||||
textures.addQuad("tile.ufog.se", grid.makeQuad(5, 7).flipY().flipX());
|
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);
|
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()));
|
tp.setShadow(Color.BLACK, Vect.make(tp.height().div(16).round()));
|
||||||
|
|
||||||
root.add(tp);
|
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.AlignX;
|
||||||
import mightypork.gamecore.gui.components.layout.HorizontalFixedFlowLayout;
|
import mightypork.gamecore.gui.components.painters.TextPainter;
|
||||||
import mightypork.gamecore.gui.components.painters.ImagePainter;
|
|
||||||
import mightypork.gamecore.gui.screens.Screen;
|
import mightypork.gamecore.gui.screens.Screen;
|
||||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||||
import mightypork.gamecore.input.KeyStroke;
|
import mightypork.gamecore.input.KeyStroke;
|
||||||
import mightypork.gamecore.input.Keys;
|
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.num.Num;
|
||||||
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
||||||
|
import mightypork.gamecore.util.strings.StringProvider;
|
||||||
import mightypork.rogue.Res;
|
import mightypork.rogue.Res;
|
||||||
import mightypork.rogue.world.WorldProvider;
|
import mightypork.rogue.world.WorldProvider;
|
||||||
import mightypork.rogue.world.gui.Minimap;
|
import mightypork.rogue.world.gui.Minimap;
|
||||||
@@ -22,7 +23,7 @@ public class HudLayer extends ScreenLayer {
|
|||||||
@Override
|
@Override
|
||||||
public double value()
|
public double value()
|
||||||
{
|
{
|
||||||
return WorldProvider.get().getPlayerEntity().health.getMaxHealth() / 2D;
|
return WorldProvider.get().getPlayer().getHealthMax() / 2D;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -31,57 +32,22 @@ public class HudLayer extends ScreenLayer {
|
|||||||
@Override
|
@Override
|
||||||
public double value()
|
public double value()
|
||||||
{
|
{
|
||||||
return WorldProvider.get().getPlayerEntity().health.getHealth() / 2D;
|
return WorldProvider.get().getPlayer().getHealth() / 2D;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private Minimap mm;
|
||||||
|
|
||||||
|
|
||||||
public HudLayer(Screen screen)
|
public HudLayer(Screen screen)
|
||||||
{
|
{
|
||||||
super(screen);
|
super(screen);
|
||||||
|
|
||||||
final Num h = root.height();
|
buildNav();
|
||||||
final Num w = root.width();
|
|
||||||
final Num minWH = w.min(h).max(700); // avoid too small shrinking
|
|
||||||
|
|
||||||
final ImagePainter nav = new ImagePainter(Res.txq("panel"));
|
buildDisplays();
|
||||||
nav.setRect(root.bottomEdge().growUp(minWH.perc(7)));
|
|
||||||
root.add(nav);
|
|
||||||
|
|
||||||
final HorizontalFixedFlowLayout itemSlots = new HorizontalFixedFlowLayout(root, nav.height().mul(1.8), AlignX.LEFT);
|
buildMinimap();
|
||||||
itemSlots.setRect(nav.growUp(nav.height()).move(nav.height().mul(0.2), nav.height().mul(-0.2)));
|
|
||||||
root.add(itemSlots);
|
|
||||||
|
|
||||||
itemSlots.add(new NavItemSlot(Res.txq("meat")));
|
|
||||||
itemSlots.add(new NavItemSlot(Res.txq("sword")));
|
|
||||||
|
|
||||||
final Rect shrunk = root.shrink(minWH.perc(3));
|
|
||||||
final Num displays_height = minWH.perc(6);
|
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
final HeartBar hearts = new HeartBar(
|
|
||||||
playerHealthTotal,
|
|
||||||
playerHealthActive,
|
|
||||||
Res.txq("heart_on"),
|
|
||||||
Res.txq("heart_half"),
|
|
||||||
Res.txq("heart_off"),
|
|
||||||
AlignX.LEFT);
|
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
|
|
||||||
final Rect hearts_box = shrunk.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() {
|
bindKey(new KeyStroke(Keys.M), new Runnable() {
|
||||||
|
|
||||||
@@ -94,18 +60,78 @@ public class HudLayer extends ScreenLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
private void buildMinimap()
|
||||||
public int getZIndex()
|
|
||||||
{
|
{
|
||||||
return 100;
|
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 Num displays_height = h.perc(6);
|
||||||
|
|
||||||
|
//@formatter:off
|
||||||
|
final HeartBar hearts = new HeartBar(
|
||||||
|
playerHealthTotal,
|
||||||
|
playerHealthActive,
|
||||||
|
Res.txq("hud.heart.on"),
|
||||||
|
Res.txq("hud.heart.half"),
|
||||||
|
Res.txq("hud.heart.off"),
|
||||||
|
AlignX.LEFT);
|
||||||
|
//@formatter:on
|
||||||
|
|
||||||
|
|
||||||
|
final Rect hearts_box = root.shrink(h.perc(3)).topLeft().startRect().growDown(displays_height);
|
||||||
|
hearts.setRect(hearts_box);
|
||||||
|
root.add(hearts);
|
||||||
|
|
||||||
|
|
||||||
|
final TextPainter lvl = new TextPainter(Res.getFont("hud"), AlignX.RIGHT, RGB.WHITE, new StringProvider() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getString()
|
||||||
|
{
|
||||||
|
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);*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void buildNav()
|
||||||
|
{
|
||||||
|
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
|
@Override
|
||||||
public void render()
|
public int getZIndex()
|
||||||
{
|
{
|
||||||
|
return 100;
|
||||||
super.render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
//pause key
|
||||||
bindKey(new KeyStroke(Keys.L_CONTROL, Keys.P), pauseIt);
|
bindKey(new KeyStroke(Keys.P), pauseIt);
|
||||||
bindKey(new KeyStroke(Keys.PAUSE), pauseIt);
|
bindKey(new KeyStroke(Keys.PAUSE), pauseIt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class WorldLayer extends ScreenLayer {
|
|||||||
worldView.addPlugin(new MIPMouse(worldView));
|
worldView.addPlugin(new MIPMouse(worldView));
|
||||||
|
|
||||||
// size of lower navbar
|
// 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));
|
worldView.setRect(root.shrinkBottom(lownav));
|
||||||
|
|
||||||
root.add(worldView);
|
root.add(worldView);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import mightypork.gamecore.util.math.algo.Coord;
|
import mightypork.gamecore.util.math.algo.Coord;
|
||||||
import mightypork.gamecore.util.math.algo.Step;
|
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.entity.modules.EntityMoveListener;
|
||||||
import mightypork.rogue.world.level.Level;
|
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;
|
if (getWorld() == null) return null;
|
||||||
|
|
||||||
return getWorld().getPlayerEntity();
|
return getWorld().getPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -72,25 +72,19 @@ public abstract class PlayerControl {
|
|||||||
public void navigateTo(Coord pos)
|
public void navigateTo(Coord pos)
|
||||||
{
|
{
|
||||||
if (!getLevel().getTile(pos).isExplored()) return;
|
if (!getLevel().getTile(pos).isExplored()) return;
|
||||||
getPlayerEntity().pos.navigateTo(pos);
|
getPlayer().navigateTo(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Level getLevel()
|
public Level getLevel()
|
||||||
{
|
{
|
||||||
return getWorld().getCurrentLevel();
|
return getWorld().getPlayer().getLevel();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Coord getCoord()
|
|
||||||
{
|
|
||||||
return getPlayerEntity().pos.getCoord();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean canGo(Step side)
|
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)
|
public boolean clickTile(Step side)
|
||||||
{
|
{
|
||||||
return clickTile(getCoord().add(side));
|
return clickTile(getPlayer().getCoord().add(side));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean clickTile(Coord pos)
|
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();
|
return getLevel().getTile(pos).onClick();
|
||||||
}
|
}
|
||||||
@@ -116,8 +110,8 @@ public abstract class PlayerControl {
|
|||||||
|
|
||||||
public void go(Step side)
|
public void go(Step side)
|
||||||
{
|
{
|
||||||
getPlayerEntity().pos.cancelPath();
|
getPlayer().cancelPath();
|
||||||
getPlayerEntity().pos.addStep(side);
|
getPlayer().addPathStep(side);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ package mightypork.rogue.world;
|
|||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import mightypork.gamecore.util.ion.IonBundle;
|
import mightypork.gamecore.util.ion.IonBundle;
|
||||||
import mightypork.gamecore.util.ion.IonObjBundled;
|
import mightypork.gamecore.util.ion.IonObjBundled;
|
||||||
|
import mightypork.rogue.world.item.Item;
|
||||||
|
|
||||||
|
|
||||||
public class PlayerInfo implements IonObjBundled {
|
public class PlayerInfo implements IonObjBundled {
|
||||||
@@ -12,12 +15,17 @@ public class PlayerInfo implements IonObjBundled {
|
|||||||
private int eid = -1; // marks not initialized
|
private int eid = -1; // marks not initialized
|
||||||
private int level;
|
private int level;
|
||||||
|
|
||||||
|
private final List<Item> inventory = new ArrayList<>();
|
||||||
|
private int selectedWeapon = -1;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(IonBundle bundle) throws IOException
|
public void load(IonBundle bundle) throws IOException
|
||||||
{
|
{
|
||||||
eid = bundle.get("eid", 0);
|
eid = bundle.get("eid", eid);
|
||||||
level = bundle.get("floor", 0);
|
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("eid", eid);
|
||||||
bundle.put("floor", level);
|
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;
|
this.level = level;
|
||||||
}
|
}
|
||||||
@@ -48,7 +58,7 @@ public class PlayerInfo implements IonObjBundled {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getLevel()
|
public int getLevelNumber()
|
||||||
{
|
{
|
||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import mightypork.gamecore.eventbus.clients.DelegatingClient;
|
|||||||
import mightypork.gamecore.util.ion.IonBundle;
|
import mightypork.gamecore.util.ion.IonBundle;
|
||||||
import mightypork.gamecore.util.ion.IonObjBundled;
|
import mightypork.gamecore.util.ion.IonObjBundled;
|
||||||
import mightypork.gamecore.util.math.algo.Coord;
|
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.gamecore.util.math.timing.Pauseable;
|
||||||
import mightypork.rogue.world.entity.Entities;
|
import mightypork.rogue.world.entity.Entities;
|
||||||
import mightypork.rogue.world.entity.Entity;
|
import mightypork.rogue.world.entity.Entity;
|
||||||
@@ -25,12 +27,146 @@ import mightypork.rogue.world.level.Level;
|
|||||||
*/
|
*/
|
||||||
public class World implements DelegatingClient, BusAccess, IonObjBundled, Pauseable {
|
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 {
|
||||||
|
|
||||||
private final PlayerInfo playerInfo = new PlayerInfo();
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// not saved stuffs
|
||||||
|
private final PlayerFacade player = new PlayerFacade();
|
||||||
private Entity playerEntity;
|
private Entity playerEntity;
|
||||||
|
|
||||||
private BusAccess bus;
|
private BusAccess bus;
|
||||||
|
private boolean paused;
|
||||||
|
|
||||||
|
|
||||||
|
private final ArrayList<Level> levels = new ArrayList<>();
|
||||||
|
private final PlayerInfo playerInfo = new PlayerInfo();
|
||||||
|
|
||||||
|
|
||||||
/** World seed */
|
/** World seed */
|
||||||
private long seed;
|
private long seed;
|
||||||
@@ -38,8 +174,6 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
|
|||||||
/** Next entity ID */
|
/** Next entity ID */
|
||||||
private int eid;
|
private int eid;
|
||||||
|
|
||||||
private boolean paused;
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
@Override
|
@Override
|
||||||
@@ -70,7 +204,7 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
|
|||||||
|
|
||||||
in.loadBundled("player", playerInfo);
|
in.loadBundled("player", playerInfo);
|
||||||
|
|
||||||
playerEntity = levels.get(playerInfo.getLevel()).getEntity(playerInfo.getEID());
|
playerEntity = levels.get(playerInfo.getLevelNumber()).getEntity(playerInfo.getEID());
|
||||||
if (playerEntity == null) {
|
if (playerEntity == null) {
|
||||||
throw new RuntimeException("Player entity not found in the world.");
|
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()) {
|
if (playerInfo.isInitialized()) {
|
||||||
throw new RuntimeException("Player already created.");
|
throw new RuntimeException("Player already created.");
|
||||||
@@ -124,10 +258,7 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
|
|||||||
// make entity
|
// make entity
|
||||||
final int playerEid = getNewEID();
|
final int playerEid = getNewEID();
|
||||||
|
|
||||||
final Level floor = levels.get(level);
|
final Level floor = levels.get(0);
|
||||||
if (floor == null) {
|
|
||||||
throw new IndexOutOfBoundsException("No such level: " + level);
|
|
||||||
}
|
|
||||||
|
|
||||||
playerEntity = Entities.PLAYER.createEntity(playerEid);
|
playerEntity = Entities.PLAYER.createEntity(playerEid);
|
||||||
|
|
||||||
@@ -143,23 +274,11 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
|
|||||||
|
|
||||||
floor.explore(spawn);
|
floor.explore(spawn);
|
||||||
|
|
||||||
playerInfo.setLevel(level);
|
playerInfo.setLevelNumber(0);
|
||||||
playerInfo.setEID(playerEid);
|
playerInfo.setEID(playerEid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Level getCurrentLevel()
|
|
||||||
{
|
|
||||||
return levels.get(playerInfo.getLevel());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Entity getPlayerEntity()
|
|
||||||
{
|
|
||||||
return playerEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attach to an event bus
|
* Attach to an event bus
|
||||||
*
|
*
|
||||||
@@ -200,39 +319,9 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean canAscend()
|
public PlayerFacade getPlayer()
|
||||||
{
|
{
|
||||||
return playerInfo.getLevel() > 0;
|
return player;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public boolean canDescend()
|
|
||||||
{
|
|
||||||
return playerInfo.getLevel() < levels.size() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void ascend()
|
|
||||||
{
|
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ public class WorldCreator {
|
|||||||
final World w = new World();
|
final World w = new World();
|
||||||
w.setSeed(seed);
|
w.setSeed(seed);
|
||||||
|
|
||||||
int count = 6;
|
final int count = 6;
|
||||||
|
|
||||||
for (int i = 1; i <= count; i++) {
|
for (int i = 1; i <= count; i++) {
|
||||||
final Level l = LevelGenerator.build(w, rand.nextLong(), i, LevelGenerator.DUNGEON_THEME, i == count);
|
final Level l = LevelGenerator.build(w, rand.nextLong(), i, LevelGenerator.DUNGEON_THEME, i == count);
|
||||||
w.addLevel(l);
|
w.addLevel(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
w.createPlayer(0);
|
w.createPlayer();
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import java.io.IOException;
|
|||||||
import mightypork.gamecore.eventbus.BusAccess;
|
import mightypork.gamecore.eventbus.BusAccess;
|
||||||
import mightypork.gamecore.eventbus.clients.RootBusNode;
|
import mightypork.gamecore.eventbus.clients.RootBusNode;
|
||||||
import mightypork.gamecore.util.ion.Ion;
|
import mightypork.gamecore.util.ion.Ion;
|
||||||
import mightypork.rogue.world.entity.Entity;
|
import mightypork.rogue.world.World.PlayerFacade;
|
||||||
import mightypork.rogue.world.level.Level;
|
import mightypork.rogue.world.level.Level;
|
||||||
|
|
||||||
|
|
||||||
@@ -87,13 +87,13 @@ public class WorldProvider extends RootBusNode {
|
|||||||
|
|
||||||
public Level getCurrentLevel()
|
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()
|
private VectConst getOffset()
|
||||||
{
|
{
|
||||||
final Entity ent = WorldProvider.get().getPlayerEntity();
|
return Vect.make(WorldProvider.get().getPlayer().getVisualPos().neg().sub(0.5, 0.5)).freeze();
|
||||||
return Vect.make(ent.pos.getVisualPos().neg().sub(0.5, 0.5)).freeze();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -87,9 +86,8 @@ public class WorldRenderer extends RectProxy {
|
|||||||
Render.translate(getOffset());
|
Render.translate(getOffset());
|
||||||
|
|
||||||
// tiles to render
|
// 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 w = width().value();
|
||||||
final double h = height().value();
|
final double h = height().value();
|
||||||
|
|
||||||
|
|||||||
@@ -42,18 +42,18 @@ public class MapView extends InputComponent implements DelegatingClient, KeyList
|
|||||||
private static final double transition_time = 0.8;
|
private static final double transition_time = 0.8;
|
||||||
|
|
||||||
protected final WorldRenderer worldRenderer;
|
protected final WorldRenderer worldRenderer;
|
||||||
public final PlayerControl playerControl;
|
public final PlayerControl plc;
|
||||||
|
|
||||||
private final Set<MapInteractionPlugin> plugins = new LinkedHashSet<>();
|
private final Set<MapInteractionPlugin> plugins = new LinkedHashSet<>();
|
||||||
private final NumAnimated zoom = new NumAnimated(0, Easing.SINE_BOTH);
|
private final NumAnimated zoom = new NumAnimated(0, Easing.SINE_BOTH);
|
||||||
private boolean zoom_in = true;
|
private boolean zoom_in = true;
|
||||||
|
|
||||||
private NumAnimated descFadeAnim = new NumAnimated(0);
|
private final NumAnimated descFadeAnim = new NumAnimated(0);
|
||||||
private Color blackColor = RGB.BLACK.withAlpha(descFadeAnim);
|
private final Color blackColor = RGB.BLACK.withAlpha(descFadeAnim);
|
||||||
|
|
||||||
private int descDir = 0;
|
private int descDir = 0;
|
||||||
|
|
||||||
private TimedTask timerDesc1 = new TimedTask() {
|
private final TimedTask timerDesc1 = new TimedTask() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
@@ -61,14 +61,14 @@ public class MapView extends InputComponent implements DelegatingClient, KeyList
|
|||||||
descFadeAnim.fadeOut(transition_time);
|
descFadeAnim.fadeOut(transition_time);
|
||||||
timerDesc2.start(transition_time);
|
timerDesc2.start(transition_time);
|
||||||
if (descDir == 1) {
|
if (descDir == 1) {
|
||||||
WorldProvider.get().getWorld().descend();
|
WorldProvider.get().getWorld().getPlayer().descend();
|
||||||
} else {
|
} else {
|
||||||
WorldProvider.get().getWorld().ascend();
|
WorldProvider.get().getWorld().getPlayer().ascend();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private TimedTask timerDesc2 = new TimedTask() {
|
private final TimedTask timerDesc2 = new TimedTask() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
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.tileSize = height().min(width()).div(10).max(32).mul(Num.make(1).sub(zoom.mul(0.5)));
|
||||||
this.worldRenderer = new WorldRenderer(this, tileSize);
|
this.worldRenderer = new WorldRenderer(this, tileSize);
|
||||||
playerControl = WorldProvider.get().getPlayerControl();
|
plc = WorldProvider.get().getPlayerControl();
|
||||||
|
|
||||||
zoom.setDefaultDuration(0.5);
|
zoom.setDefaultDuration(0.5);
|
||||||
}
|
}
|
||||||
@@ -194,11 +194,11 @@ public class MapView extends InputComponent implements DelegatingClient, KeyList
|
|||||||
@Override
|
@Override
|
||||||
public void onAscendRequest()
|
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;
|
descDir = -1;
|
||||||
startDescAnim();
|
startDescAnim();
|
||||||
}
|
}
|
||||||
@@ -219,11 +219,11 @@ public class MapView extends InputComponent implements DelegatingClient, KeyList
|
|||||||
@Override
|
@Override
|
||||||
public void onDescendRequest()
|
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;
|
descDir = 1;
|
||||||
startDescAnim();
|
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.Rect;
|
||||||
import mightypork.gamecore.util.math.constraints.rect.mutable.RectMutable;
|
import mightypork.gamecore.util.math.constraints.rect.mutable.RectMutable;
|
||||||
import mightypork.gamecore.util.math.constraints.vect.Vect;
|
import mightypork.gamecore.util.math.constraints.vect.Vect;
|
||||||
|
import mightypork.rogue.world.World.PlayerFacade;
|
||||||
import mightypork.rogue.world.WorldProvider;
|
import mightypork.rogue.world.WorldProvider;
|
||||||
import mightypork.rogue.world.entity.Entity;
|
|
||||||
import mightypork.rogue.world.level.Level;
|
import mightypork.rogue.world.level.Level;
|
||||||
import mightypork.rogue.world.tile.Tile;
|
import mightypork.rogue.world.tile.Tile;
|
||||||
|
|
||||||
@@ -36,8 +36,7 @@ public class Minimap extends InputComponent implements MouseButtonListener {
|
|||||||
final Level lvl = WorldProvider.get().getCurrentLevel();
|
final Level lvl = WorldProvider.get().getCurrentLevel();
|
||||||
unit = (int) Math.min(Math.max(2, Math.ceil((height().value() / 2) / (lvl.getHeight() + 2))), 10);
|
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 = WorldProvider.get().getPlayer().getVisualPos();
|
||||||
final Vect plCoord = e.pos.getVisualPos();
|
|
||||||
|
|
||||||
final int lw = lvl.getWidth();
|
final int lw = lvl.getWidth();
|
||||||
final int lh = lvl.getHeight();
|
final int lh = lvl.getHeight();
|
||||||
@@ -93,10 +92,11 @@ public class Minimap extends InputComponent implements MouseButtonListener {
|
|||||||
if (event.isUp()) {
|
if (event.isUp()) {
|
||||||
final Vect relative = event.getPos().sub(bounds.origin());
|
final Vect relative = event.getPos().sub(bounds.origin());
|
||||||
final Coord actual = Coord.make(relative.xi() / unit, relative.yi() / unit);
|
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()) {
|
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
|
@Override
|
||||||
public void receive(KeyEvent evt)
|
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++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if (evt.getKey() == keys[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()
|
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++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if (InputSystem.isKeyDown(keys[i])) {
|
if (InputSystem.isKeyDown(keys[i])) {
|
||||||
|
|
||||||
final Step side = sides[i];
|
final Step side = sides[i];
|
||||||
if (mapView.playerControl.canGo(side)) {
|
if (mapView.plc.canGo(side)) {
|
||||||
mapView.playerControl.go(side);
|
mapView.plc.go(side);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -28,12 +28,14 @@ public class MIPMouse extends MapInteractionPlugin implements PlayerStepEndListe
|
|||||||
@Override
|
@Override
|
||||||
public void update(double delta)
|
public void update(double delta)
|
||||||
{
|
{
|
||||||
|
if (isImmobile()) return;
|
||||||
|
|
||||||
final Vect pos = InputSystem.getMousePos();
|
final Vect pos = InputSystem.getMousePos();
|
||||||
if (!pos.isInside(mapView)) return;
|
if (!pos.isInside(mapView)) return;
|
||||||
|
|
||||||
if (InputSystem.isMouseButtonDown(BTN)) {
|
if (InputSystem.isMouseButtonDown(BTN)) {
|
||||||
if (mouseWalk(pos)) return;
|
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
|
@Override
|
||||||
public boolean onClick(Vect mouse, int button, boolean down)
|
public boolean onClick(Vect mouse, int button, boolean down)
|
||||||
{
|
{
|
||||||
|
if (isImmobile()) return false;
|
||||||
|
|
||||||
final Coord pos = mapView.toWorldPos(mouse);
|
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()) {
|
if (button == BTN && !down && t.onClick()) {
|
||||||
return true;
|
return true;
|
||||||
@@ -59,21 +63,25 @@ public class MIPMouse extends MapInteractionPlugin implements PlayerStepEndListe
|
|||||||
|
|
||||||
private boolean troToNav(Vect mouse)
|
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);
|
final Coord clicked = mapView.toWorldPos(mouse);
|
||||||
if (clicked.equals(plpos)) return false;
|
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;
|
if (!t.isWalkable() || !t.isExplored()) return false;
|
||||||
|
|
||||||
mapView.playerControl.navigateTo(clicked);
|
mapView.plc.navigateTo(clicked);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean mouseWalk(Vect pos)
|
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);
|
final Coord clicked = mapView.toWorldPos(pos);
|
||||||
if (clicked.equals(plpos)) return false;
|
if (clicked.equals(plpos)) return false;
|
||||||
|
|
||||||
@@ -83,30 +91,33 @@ public class MIPMouse extends MapInteractionPlugin implements PlayerStepEndListe
|
|||||||
|
|
||||||
switch (dir) {
|
switch (dir) {
|
||||||
case 0:
|
case 0:
|
||||||
return mapView.playerControl.tryGo(Sides.E);
|
return mapView.plc.tryGo(Sides.E);
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
return mapView.playerControl.tryGo(Sides.S);
|
return mapView.plc.tryGo(Sides.S);
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
return mapView.playerControl.tryGo(Sides.W);
|
return mapView.plc.tryGo(Sides.W);
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
return mapView.playerControl.tryGo(Sides.N);
|
return mapView.plc.tryGo(Sides.N);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStepFinished(PlayerEntity player)
|
public void onStepFinished(PlayerEntity player)
|
||||||
{
|
{
|
||||||
|
if (isImmobile()) return;
|
||||||
|
|
||||||
final Vect pos = InputSystem.getMousePos();
|
final Vect pos = InputSystem.getMousePos();
|
||||||
if (!pos.isInside(mapView)) return;
|
if (!pos.isInside(mapView)) return;
|
||||||
|
|
||||||
if (InputSystem.isMouseButtonDown(BTN)) {
|
if (InputSystem.isMouseButtonDown(BTN)) {
|
||||||
if (mouseWalk(pos)) return;
|
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;
|
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.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;
|
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);
|
public abstract boolean onClick(Vect mouse, int button, boolean down);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ public abstract class TileBaseEntrance extends TileBaseStairs {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onClick()
|
public boolean onClick()
|
||||||
{
|
{
|
||||||
Coord plpos = getWorld().getPlayerEntity().getCoord();
|
final Coord plpos = getWorld().getPlayer().getCoord();
|
||||||
if(!plpos.equals(getLevel().getEnterPoint())) return false;
|
if (!plpos.equals(getLevel().getEnterPoint())) return false;
|
||||||
|
|
||||||
getEventBus().send(new WorldAscendRequest());
|
getEventBus().send(new WorldAscendRequest());
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ public abstract class TileBaseExit extends TileBaseStairs {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onClick()
|
public boolean onClick()
|
||||||
{
|
{
|
||||||
Coord plpos = getWorld().getPlayerEntity().getCoord();
|
final Coord plpos = getWorld().getPlayer().getCoord();
|
||||||
if(!plpos.equals(getLevel().getExitPoint())) return false;
|
if (!plpos.equals(getLevel().getExitPoint())) return false;
|
||||||
|
|
||||||
getEventBus().send(new WorldDescendRequest());
|
getEventBus().send(new WorldDescendRequest());
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class TileBrickDoor extends TileBaseDoor {
|
|||||||
//@formatter:off
|
//@formatter:off
|
||||||
super(
|
super(
|
||||||
model,
|
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.closed"),
|
||||||
Res.txs("tile.brick.door.open")
|
Res.txs("tile.brick.door.open")
|
||||||
);
|
);
|
||||||
|
|||||||