some polishing

v5stable
Ondřej Hruška 11 years ago
parent fda6ca1a63
commit f467c01c46
  1. BIN
      res/img/tiles.png
  2. BIN
      res/img/tiles.xcf
  3. 4
      src/mightypork/gamecore/eventbus/BusEvent.java
  4. 4
      src/mightypork/gamecore/eventbus/EventBus.java
  5. 2
      src/mightypork/gamecore/eventbus/event_flags/NotLoggedEvent.java
  6. 4
      src/mightypork/gamecore/eventbus/events/UpdateEvent.java
  7. 2
      src/mightypork/gamecore/gui/Action.java
  8. 4
      src/mightypork/gamecore/gui/ActionGroup.java
  9. 2
      src/mightypork/gamecore/gui/Enableable.java
  10. 19
      src/mightypork/gamecore/gui/components/BaseComponent.java
  11. 6
      src/mightypork/gamecore/gui/components/LayoutComponent.java
  12. 6
      src/mightypork/gamecore/gui/components/layout/ClickableWrapper.java
  13. 2
      src/mightypork/gamecore/gui/events/CrossfadeRequest.java
  14. 2
      src/mightypork/gamecore/gui/events/ViewportChangeEvent.java
  15. 21
      src/mightypork/gamecore/gui/screens/Overlay.java
  16. 22
      src/mightypork/gamecore/gui/screens/impl/CrossfadeOverlay.java
  17. 12
      src/mightypork/gamecore/input/InputSystem.java
  18. 1
      src/mightypork/gamecore/input/KeyBinding.java
  19. 16
      src/mightypork/gamecore/input/KeyStroke.java
  20. 4
      src/mightypork/gamecore/input/events/KeyEvent.java
  21. 4
      src/mightypork/gamecore/input/events/MouseButtonEvent.java
  22. 4
      src/mightypork/gamecore/input/events/MouseMotionEvent.java
  23. 8
      src/mightypork/gamecore/util/math/Calc.java
  24. 5
      src/mightypork/gamecore/util/math/Range.java
  25. 5
      src/mightypork/gamecore/util/math/algo/Sides.java
  26. 2
      src/mightypork/gamecore/util/math/timing/TaskRepeater.java
  27. 2
      src/mightypork/rogue/App.java
  28. 1
      src/mightypork/rogue/GameStateManager.java
  29. 1
      src/mightypork/rogue/Res.java
  30. 2
      src/mightypork/rogue/events/ActionRequest.java
  31. 5
      src/mightypork/rogue/events/GameStateRequest.java
  32. 38
      src/mightypork/rogue/events/LoadingOverlayRequest.java
  33. 9
      src/mightypork/rogue/screens/FpsOverlay.java
  34. 22
      src/mightypork/rogue/screens/LoaderRequest.java
  35. 34
      src/mightypork/rogue/screens/LoadingOverlay.java
  36. 71
      src/mightypork/rogue/screens/PushButton.java
  37. 2
      src/mightypork/rogue/screens/game/HudLayer.java
  38. 2
      src/mightypork/rogue/screens/game/InvLayer.java
  39. 34
      src/mightypork/rogue/screens/game/ScreenGame.java
  40. 56
      src/mightypork/rogue/screens/menu/MenuButton.java
  41. 9
      src/mightypork/rogue/screens/menu/ScreenMainMenu.java
  42. 8
      src/mightypork/rogue/screens/select_world/ScreenSelectWorld.java
  43. 60
      src/mightypork/rogue/screens/select_world/WorldSlot.java
  44. 54
      src/mightypork/rogue/world/PlayerFacade.java
  45. 25
      src/mightypork/rogue/world/World.java
  46. 11
      src/mightypork/rogue/world/WorldConsole.java
  47. 24
      src/mightypork/rogue/world/WorldProvider.java
  48. 21
      src/mightypork/rogue/world/WorldRenderer.java
  49. 10
      src/mightypork/rogue/world/entity/Entity.java
  50. 2
      src/mightypork/rogue/world/entity/EntityModel.java
  51. 7
      src/mightypork/rogue/world/entity/EntityModule.java
  52. 5
      src/mightypork/rogue/world/entity/EntityPathFinder.java
  53. 5
      src/mightypork/rogue/world/entity/EntityRenderer.java
  54. 7
      src/mightypork/rogue/world/entity/EntityType.java
  55. 1
      src/mightypork/rogue/world/entity/impl/BossRatAi.java
  56. 1
      src/mightypork/rogue/world/entity/impl/BrownRatAi.java
  57. 2
      src/mightypork/rogue/world/entity/impl/GrayRatAi.java
  58. 16
      src/mightypork/rogue/world/entity/impl/MonsterAi.java
  59. 53
      src/mightypork/rogue/world/entity/modules/EntityModulePosition.java
  60. 4
      src/mightypork/rogue/world/events/PlayerStepEndEvent.java
  61. 10
      src/mightypork/rogue/world/gen/LevelGenerator.java
  62. 3
      src/mightypork/rogue/world/gui/Minimap.java
  63. 6
      src/mightypork/rogue/world/gui/interaction/MIPKeyboard.java
  64. 1
      src/mightypork/rogue/world/item/Item.java
  65. 1
      src/mightypork/rogue/world/item/ItemModel.java
  66. 9
      src/mightypork/rogue/world/level/Level.java
  67. 6
      src/mightypork/rogue/world/level/render/TileRenderContext.java
  68. 8
      src/mightypork/rogue/world/tile/Tile.java
  69. 15
      src/mightypork/rogue/world/tile/TileRenderer.java

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

@ -4,8 +4,8 @@ package mightypork.gamecore.eventbus;
import mightypork.gamecore.eventbus.event_flags.DelayedEvent;
import mightypork.gamecore.eventbus.event_flags.ImmediateEvent;
import mightypork.gamecore.eventbus.event_flags.NonConsumableEvent;
import mightypork.gamecore.eventbus.event_flags.NotLoggedEvent;
import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent;
import mightypork.gamecore.eventbus.event_flags.UnloggedEvent;
/**
@ -15,7 +15,7 @@ import mightypork.gamecore.eventbus.event_flags.UnloggedEvent;
* <p>
* Can be annotated as {@link SingleReceiverEvent} to be delivered once only,
* and {@link DelayedEvent} or {@link ImmediateEvent} to specify default sending
* mode. When marked as {@link UnloggedEvent}, it will not appear in detailed
* mode. When marked as {@link NotLoggedEvent}, it will not appear in detailed
* bus logging (useful for very frequent events, such as UpdateEvent).
* </p>
* <p>

@ -12,7 +12,7 @@ import java.util.concurrent.TimeUnit;
import mightypork.gamecore.eventbus.clients.DelegatingClient;
import mightypork.gamecore.eventbus.event_flags.DelayedEvent;
import mightypork.gamecore.eventbus.event_flags.ImmediateEvent;
import mightypork.gamecore.eventbus.event_flags.UnloggedEvent;
import mightypork.gamecore.eventbus.event_flags.NotLoggedEvent;
import mightypork.gamecore.eventbus.events.Destroyable;
import mightypork.gamecore.logging.Log;
@ -388,7 +388,7 @@ final public class EventBus implements Destroyable, BusAccess {
private boolean shallLog(BusEvent<?> event)
{
if (!detailedLogging) return false;
if (event.getClass().isAnnotationPresent(UnloggedEvent.class)) return false;
if (event.getClass().isAnnotationPresent(NotLoggedEvent.class)) return false;
return true;
}

@ -14,4 +14,4 @@ import java.lang.annotation.*;
@Target(ElementType.TYPE)
@Inherited
@Documented
public @interface UnloggedEvent {}
public @interface NotLoggedEvent {}

@ -4,7 +4,7 @@ package mightypork.gamecore.eventbus.events;
import mightypork.gamecore.eventbus.BusEvent;
import mightypork.gamecore.eventbus.event_flags.ImmediateEvent;
import mightypork.gamecore.eventbus.event_flags.NonConsumableEvent;
import mightypork.gamecore.eventbus.event_flags.UnloggedEvent;
import mightypork.gamecore.eventbus.event_flags.NotLoggedEvent;
/**
@ -12,7 +12,7 @@ import mightypork.gamecore.eventbus.event_flags.UnloggedEvent;
*
* @author MightyPork
*/
@UnloggedEvent
@NotLoggedEvent
@ImmediateEvent
@NonConsumableEvent
public class UpdateEvent extends BusEvent<Updateable> {

@ -17,7 +17,7 @@ public abstract class Action implements Runnable, Enableable {
* @param enable true to enable
*/
@Override
public final void enable(boolean enable)
public final void setEnabled(boolean enable)
{
this.enabled = enable;
}

@ -13,11 +13,11 @@ public class ActionGroup implements Enableable {
@Override
public void enable(boolean yes)
public void setEnabled(boolean yes)
{
enabled = yes;
for (final Enableable e : groupMembers)
e.enable(yes);
e.setEnabled(yes);
}

@ -15,7 +15,7 @@ public interface Enableable {
*
* @param yes enabled
*/
public void enable(boolean yes);
public void setEnabled(boolean yes);
/**

@ -8,6 +8,8 @@ import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.render.Renderable;
import mightypork.gamecore.util.annot.DefaultImpl;
import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.constraints.rect.caching.AbstractRectCache;
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
@ -26,6 +28,7 @@ public abstract class BaseComponent extends AbstractRectCache implements Compone
private boolean visible = true;
private int disableLevel = 0;
private Num alphaMul = Num.ONE;
public BaseComponent()
@ -67,7 +70,9 @@ public abstract class BaseComponent extends AbstractRectCache implements Compone
{
if (!isVisible()) return;
Color.pushAlpha(alphaMul);
renderComponent();
Color.popAlpha();
}
@ -109,7 +114,7 @@ public abstract class BaseComponent extends AbstractRectCache implements Compone
@Override
public void enable(boolean yes)
public void setEnabled(boolean yes)
{
if (yes) {
if (disableLevel > 0) disableLevel--;
@ -124,4 +129,16 @@ public abstract class BaseComponent extends AbstractRectCache implements Compone
{
return disableLevel == 0;
}
public void setAlpha(Num alpha)
{
this.alphaMul = alpha;
}
public void setAlpha(double alpha)
{
this.alphaMul = Num.make(alpha);
}
}

@ -107,11 +107,11 @@ public abstract class LayoutComponent extends BaseComponent implements ClientHub
@Override
public void enable(boolean yes)
public void setEnabled(boolean yes)
{
super.enable(yes);
super.setEnabled(yes);
for (final Component c : components) {
c.enable(yes);
c.setEnabled(yes);
}
}

@ -49,10 +49,10 @@ public class ClickableWrapper extends ClickableComponent implements DelegatingCl
@Override
public void enable(boolean yes)
public void setEnabled(boolean yes)
{
super.enable(yes);
wrapped.enable(yes);
super.setEnabled(yes);
wrapped.setEnabled(yes);
}

@ -2,12 +2,14 @@ package mightypork.gamecore.gui.events;
import mightypork.gamecore.eventbus.BusEvent;
import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent;
import mightypork.gamecore.gui.screens.impl.CrossfadeOverlay;
/**
* @author MightyPork
*/
@SingleReceiverEvent
public class CrossfadeRequest extends BusEvent<CrossfadeOverlay> {
private final String screen;

@ -3,6 +3,7 @@ package mightypork.gamecore.gui.events;
import mightypork.gamecore.eventbus.BusEvent;
import mightypork.gamecore.eventbus.event_flags.NonConsumableEvent;
import mightypork.gamecore.eventbus.event_flags.NotLoggedEvent;
import mightypork.gamecore.util.math.constraints.vect.Vect;
@ -12,6 +13,7 @@ import mightypork.gamecore.util.math.constraints.vect.Vect;
* @author MightyPork
*/
@NonConsumableEvent
@NotLoggedEvent
public class ViewportChangeEvent extends BusEvent<ViewportChangeListener> {
private final boolean fullscreen;

@ -16,6 +16,8 @@ import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.render.Renderable;
import mightypork.gamecore.util.annot.DefaultImpl;
import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.vect.Vect;
@ -44,6 +46,7 @@ public abstract class Overlay extends AppSubModule implements Comparable<Overlay
/** Extra updated items (outside root - those can just implement Updateable) */
protected final Collection<Updateable> updated = new LinkedHashSet<>();
private Num alphaMul = Num.ONE;
public Overlay(AppAccess app)
@ -90,10 +93,10 @@ public abstract class Overlay extends AppSubModule implements Comparable<Overlay
@Override
public void enable(boolean yes)
public void setEnabled(boolean yes)
{
this.enabled = yes;
root.enable(yes);
root.setEnabled(yes);
}
@ -132,9 +135,12 @@ public abstract class Overlay extends AppSubModule implements Comparable<Overlay
{
if (!isVisible()) return;
Color.pushAlpha(alphaMul);
for (final Renderable r : rendered) {
r.render();
}
Color.popAlpha();
}
@ -172,4 +178,15 @@ public abstract class Overlay extends AppSubModule implements Comparable<Overlay
{
}
public void setAlpha(Num alpha)
{
this.alphaMul = alpha;
}
public void setAlpha(double alpha)
{
this.alphaMul = Num.make(alpha);
}
}

@ -6,7 +6,7 @@ import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.events.ScreenRequest;
import mightypork.gamecore.gui.screens.Overlay;
import mightypork.gamecore.util.math.Easing;
import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated;
import mightypork.gamecore.util.math.timing.TimedTask;
import mightypork.rogue.events.ActionRequest;
@ -18,9 +18,7 @@ public class CrossfadeOverlay extends Overlay {
private static final double T_IN = 0.5;
private static final double T_OUT = 0.7;
NumAnimated blackLevel = new NumAnimated(0);
Color color = Color.dark(blackLevel);
NumAnimated alpha = new NumAnimated(0);
String requestedScreenName;
TimedTask revealTask = new TimedTask() {
@ -33,8 +31,8 @@ public class CrossfadeOverlay extends Overlay {
} else {
getEventBus().send(new ScreenRequest(requestedScreenName));
}
blackLevel.setEasing(Easing.SINE_OUT);
blackLevel.fadeOut(T_OUT);
alpha.setEasing(Easing.SINE_OUT);
alpha.fadeOut(T_OUT);
}
};
@ -43,12 +41,14 @@ public class CrossfadeOverlay extends Overlay {
{
super(app);
final QuadPainter qp = new QuadPainter(color);
final QuadPainter qp = new QuadPainter(RGB.BLACK);
qp.setRect(root);
root.add(qp);
updated.add(blackLevel);
updated.add(alpha);
updated.add(revealTask);
setAlpha(alpha);
}
@ -64,13 +64,13 @@ public class CrossfadeOverlay extends Overlay {
requestedScreenName = screen;
if (fromDark) {
blackLevel.setTo(1);
alpha.setTo(1);
revealTask.run();
} else {
revealTask.start(T_IN);
blackLevel.setEasing(Easing.SINE_IN);
blackLevel.fadeIn(T_IN);
alpha.setEasing(Easing.SINE_IN);
alpha.fadeIn(T_IN);
}
}

@ -215,25 +215,25 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
{
return Mouse.isButtonDown(button);
}
public static int getModifierKeys()
{
int mods = 0;
if(Keyboard.isKeyDown(Keys.L_ALT) || Keyboard.isKeyDown(Keys.R_ALT)) {
if (Keyboard.isKeyDown(Keys.L_ALT) || Keyboard.isKeyDown(Keys.R_ALT)) {
mods |= Keys.MOD_ALT;
}
if(Keyboard.isKeyDown(Keys.L_SHIFT) || Keyboard.isKeyDown(Keys.R_SHIFT)) {
if (Keyboard.isKeyDown(Keys.L_SHIFT) || Keyboard.isKeyDown(Keys.R_SHIFT)) {
mods |= Keys.MOD_SHIFT;
}
if(Keyboard.isKeyDown(Keys.L_CONTROL) || Keyboard.isKeyDown(Keys.R_CONTROL)) {
if (Keyboard.isKeyDown(Keys.L_CONTROL) || Keyboard.isKeyDown(Keys.R_CONTROL)) {
mods |= Keys.MOD_CONTROL;
}
if(Keyboard.isKeyDown(Keys.L_META) || Keyboard.isKeyDown(Keys.R_META)) {
if (Keyboard.isKeyDown(Keys.L_META) || Keyboard.isKeyDown(Keys.R_META)) {
mods |= Keys.MOD_META;
}

@ -3,7 +3,6 @@ package mightypork.gamecore.input;
import mightypork.gamecore.input.events.KeyEvent;
import mightypork.gamecore.input.events.KeyListener;
import mightypork.gamecore.logging.Log;
/**

@ -1,10 +1,6 @@
package mightypork.gamecore.input;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.lwjgl.input.Keyboard;
@ -27,7 +23,8 @@ public class KeyStroke {
* @param mod_mask mods mask
* @param key key code
*/
public KeyStroke(boolean fallingEdge, int key, int mod_mask) {
public KeyStroke(boolean fallingEdge, int key, int mod_mask)
{
this.fallingEdge = fallingEdge;
this.key = key;
this.mod = mod_mask;
@ -36,10 +33,12 @@ public class KeyStroke {
/**
* Rising edge keystroke
*
* @param mod_mask mods mask
* @param key key code
*/
public KeyStroke(int key, int mod_mask) {
public KeyStroke(int key, int mod_mask)
{
this(false, key, mod_mask);
}
@ -49,7 +48,8 @@ public class KeyStroke {
*
* @param key key code
*/
public KeyStroke(int key) {
public KeyStroke(int key)
{
this(false, key, Keys.MOD_NONE);
}
@ -115,7 +115,7 @@ public class KeyStroke {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
KeyStroke other = (KeyStroke) obj;
final KeyStroke other = (KeyStroke) obj;
if (fallingEdge != other.fallingEdge) return false;
if (key != other.key) return false;
if (mod != other.mod) return false;

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

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

@ -2,7 +2,7 @@ package mightypork.gamecore.input.events;
import mightypork.gamecore.eventbus.BusEvent;
import mightypork.gamecore.eventbus.event_flags.UnloggedEvent;
import mightypork.gamecore.eventbus.event_flags.NotLoggedEvent;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.gamecore.util.math.constraints.vect.VectConst;
@ -12,7 +12,7 @@ import mightypork.gamecore.util.math.constraints.vect.VectConst;
*
* @author MightyPork
*/
@UnloggedEvent
@NotLoggedEvent
public class MouseMotionEvent extends BusEvent<MouseMotionListener> {
private final VectConst move;

@ -670,15 +670,17 @@ public class Calc {
public static int randInt(Random rand, int low, int high)
{
int range = Math.abs(high - low) + 1;
final int range = Math.abs(high - low) + 1;
return low + rand.nextInt(range);
}
public static int randInt(int low, int high)
{
return randInt(rand, low, high);
return randInt(rand, low, high);
}
/**
* Get ordinal version of numbers (1 = 1st, 5 = 5th etc.)
*

@ -1,9 +1,6 @@
package mightypork.gamecore.util.math;
import java.util.Random;
/**
* Numeric range, able to generate random numbers and give min/max values.
*
@ -74,7 +71,7 @@ public class Range {
*/
public int randInt()
{
return Calc.randInt(Calc.rand, (int)Math.round(min), (int)Math.round(min));
return Calc.randInt(Calc.rand, (int) Math.round(min), (int) Math.round(min));
}

@ -1,5 +1,6 @@
package mightypork.gamecore.util.math.algo;
import mightypork.gamecore.util.math.Calc;
@ -69,8 +70,8 @@ public class Sides {
{
return (byte) (1 << (7 - i));
}
public static Step randomCardinal()
{
return CARDINAL_SIDES[Calc.randInt(0, 3)];

@ -25,7 +25,7 @@ public abstract class TaskRepeater extends AnimatorRewind implements Runnable, E
@Override
public void enable(boolean yes)
public void setEnabled(boolean yes)
{
this.enabled = yes;
}

@ -138,11 +138,13 @@ public final class App extends BaseApp {
bindEventToKey(new GameStateRequest(GameState.MAIN_MENU), Keys.M, Keys.MOD_CONTROL);
}
private void bindEventToKey(final BusEvent<?> event, int key)
{
bindEventToKey(event, key, Keys.MOD_NONE);
}
private void bindEventToKey(final BusEvent<?> event, int key, byte mod)
{
getInput().bindKey(new KeyStroke(key, mod), new Runnable() {

@ -5,7 +5,6 @@ import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.app.AppModule;
import mightypork.gamecore.gui.events.CrossfadeRequest;
import mightypork.gamecore.logging.Log;
import mightypork.rogue.world.WorldProvider;
public class GameStateManager extends AppModule {

@ -157,6 +157,7 @@ public final class Res {
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());
textures.add("tile.ufog.full", grid.makeQuad(6, 7));
texture = textures.loadTexture("items", "/res/img/items.png", FilterMode.NEAREST, WrapMode.CLAMP);

@ -6,7 +6,7 @@ import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent;
/**
* Request for a global sction to be done in the main loop.
* Request for a global action to be done in the main loop.
*
* @author MightyPork
*/

@ -6,6 +6,11 @@ import mightypork.rogue.GameStateManager;
import mightypork.rogue.GameStateManager.GameState;
/**
* Request for a game state change
*
* @author MightyPork
*/
public class GameStateRequest extends BusEvent<GameStateManager> {
final private GameState requested;

@ -0,0 +1,38 @@
package mightypork.rogue.events;
import mightypork.gamecore.eventbus.BusEvent;
import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent;
import mightypork.rogue.screens.LoadingOverlay;
/**
* Request to execute a given task in a loading overlay
*
* @author MightyPork
*/
@SingleReceiverEvent
public class LoadingOverlayRequest extends BusEvent<LoadingOverlay> {
private final String msg;
private final Runnable task;
/**
* @param msg task description
* @param task task runnable
*/
public LoadingOverlayRequest(String msg, Runnable task)
{
this.task = task;
this.msg = msg;
}
@Override
protected void handleBy(LoadingOverlay handler)
{
handler.show(msg, task);
}
}

@ -17,6 +17,11 @@ import mightypork.gamecore.util.strings.StringProvider;
import mightypork.rogue.Res;
/**
* FPS indicator overlay
*
* @author MightyPork
*/
public class FpsOverlay extends Overlay {
TextPainter tp;
@ -43,7 +48,7 @@ public class FpsOverlay extends Overlay {
final Num h = root.height();
final RectBound constraint = root.shrink(h.perc(3)).topRight().startRect().growDown(h.perc(5).max(16));
tp = new TextPainter(font, AlignX.RIGHT, RGB.WHITE, new StringProvider() {
tp = new TextPainter(font, AlignX.RIGHT, RGB.YELLOW, new StringProvider() {
@Override
public String getString()
@ -53,7 +58,7 @@ public class FpsOverlay extends Overlay {
});
tp.setRect(constraint);
tp.setShadow(RGB.BLACK, Vect.make(tp.height().div(8).round()));
tp.setShadow(RGB.BLACK_60, Vect.make(tp.height().div(8).round()));
root.add(tp);

@ -1,22 +0,0 @@
package mightypork.rogue.screens;
import mightypork.gamecore.eventbus.BusEvent;
public class LoaderRequest extends BusEvent<LoadingOverlay> {
private final String msg;
private Runnable task;
public LoaderRequest(String msg, Runnable task) {
this.task = task;
this.msg = msg;
}
@Override
protected void handleBy(LoadingOverlay handler)
{
handler.show(msg, task);
}
}

@ -5,11 +5,9 @@ import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.events.ScreenRequest;
import mightypork.gamecore.gui.screens.Overlay;
import mightypork.gamecore.util.Utils;
import mightypork.gamecore.util.math.Easing;
import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.color.pal.PAL16;
import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.Num;
@ -18,10 +16,14 @@ import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.timing.TimedTask;
import mightypork.gamecore.util.strings.StringProvider;
import mightypork.rogue.Res;
import mightypork.rogue.events.ActionRequest;
import mightypork.rogue.events.ActionRequest.RequestType;
/**
* Overlay with blue background and loading-info text, that accompanies an async
* task.
*
* @author MightyPork
*/
public class LoadingOverlay extends Overlay {
private static final double T_IN = 0.5;
@ -42,7 +44,7 @@ public class LoadingOverlay extends Overlay {
private String msg;
private Runnable task;
private TimedTask tt = new TimedTask() {
private final TimedTask tt = new TimedTask() {
@Override
public void run()
@ -62,7 +64,8 @@ public class LoadingOverlay extends Overlay {
};
public LoadingOverlay(AppAccess app) {
public LoadingOverlay(AppAccess app)
{
super(app);
final QuadPainter qp = new QuadPainter(PAL16.SEABLUE);
@ -80,6 +83,8 @@ public class LoadingOverlay extends Overlay {
tp.setRect(textRect);
tp.setShadow(RGB.BLACK_60, tp.height().mul(1 / 8D).toVectXY());
root.add(tp);
setAlpha(alpha);
}
@ -90,9 +95,15 @@ public class LoadingOverlay extends Overlay {
}
/**
* Show for a task
*
* @param message task description
* @param task task
*/
public void show(String message, Runnable task)
{
if(busy) throw new IllegalStateException("Loader is busy with another task.");
if (busy) throw new IllegalStateException("Loader is busy with another task.");
this.msg = message;
this.task = task;
@ -103,13 +114,4 @@ public class LoadingOverlay extends Overlay {
tt.start(T_IN);
}
@Override
public void render()
{
Color.pushAlpha(alpha);
super.render();
Color.popAlpha();
}
}

@ -0,0 +1,71 @@
package mightypork.rogue.screens;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.ClickableComponent;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.gamecore.util.math.constraints.vect.mutable.VectVar;
/**
* Menu-like button with shadow and push state
*
* @author MightyPork
*/
public class PushButton extends ClickableComponent {
public final TextPainter textPainter;
private final VectVar offset = Vect.makeVar();
public Vect offsetPassive = height().div(16).toVectXY();
public Vect offsetOver = height().div(20).toVectXY();
public Vect offsetUnder = height().div(32).toVectXY();
private final Color color;
private boolean hoverMove = true;
public PushButton(GLFont font, String text, Color color)
{
this.color = color;
this.textPainter = new TextPainter(font, AlignX.CENTER, this.color, text);
this.textPainter.setRect(this);
this.textPainter.setShadow(RGB.BLACK_30, offset);
textPainter.setPaddingHPerc(0, 5);
}
@Override
protected void renderComponent()
{
if (isMouseOver()) {
if (InputSystem.isMouseButtonDown(0)) {
offset.setTo(offsetUnder);
} else {
offset.setTo(hoverMove ? offsetOver : offsetPassive);
}
} else {
offset.setTo(offsetPassive);
}
textPainter.render();
}
/**
* Disable offset change on hover
*/
public void disableHover()
{
hoverMove = false;
}
}

@ -130,7 +130,7 @@ public class HudLayer extends ScreenLayer {
// TODO actions
//nav.addLeft(new NavButton(Res.txq("nav.button.fg.options")));
//nav.addLeft(new NavButton(Res.txq("nav.button.fg.help")));
nav.addLeft(btn = new NavButton(Res.txq("nav.button.fg.menu")));
btn.setAction(gameScreen.actionMenu);

@ -144,7 +144,7 @@ public class InvLayer extends ScreenLayer {
@Override
public void run()
{
if(isEnabled()) {
if (isEnabled()) {
screen.actionToggleInv.run();
}
}

@ -2,8 +2,6 @@ package mightypork.rogue.screens.game;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.gui.Action;
@ -89,7 +87,7 @@ public class ScreenGame extends LayeredScreen {
worldLayer.map.toggleMag();
}
};
public Action actionSave = new Action() {
@Override
@ -98,30 +96,30 @@ public class ScreenGame extends LayeredScreen {
try {
WorldProvider.get().saveWorld();
WorldProvider.get().getWorld().getConsole().msgWorldSaved();
} catch (Exception e) {
} catch (final Exception e) {
Log.e("Could not save the world.", e);
WorldProvider.get().getWorld().getConsole().msgWorldSaveError();
}
}
};
public Action actionLoad = new Action() {
@Override
public void execute()
{
try {
File f = WorldProvider.get().getWorld().getSaveFile();
final File f = WorldProvider.get().getWorld().getSaveFile();
WorldProvider.get().loadWorld(f);
WorldProvider.get().getWorld().getConsole().msgReloaded();
} catch (Exception e) {
} catch (final Exception e) {
Log.e("Could not load the world.", e);
WorldProvider.get().getWorld().getConsole().msgLoadFailed();
}
}
};
public Action actionMenu = new Action() {
@Override
@ -132,6 +130,8 @@ public class ScreenGame extends LayeredScreen {
getEventBus().send(new GameStateRequest(GameState.MAIN_MENU));
}
};
/**
* Set gui state (overlay)
*
@ -144,21 +144,21 @@ public class ScreenGame extends LayeredScreen {
if (nstate != GScrState.WORLD) { // leaving world.
getEventBus().send(new WorldPauseRequest(PauseAction.PAUSE));
worldActions.enable(false); // disable world actions
worldActions.setEnabled(false); // disable world actions
}
if (nstate == GScrState.WORLD) {
getEventBus().send(new WorldPauseRequest(PauseAction.RESUME));
invLayer.setVisible(false); // hide all extra layers
invLayer.enable(false);
invLayer.setEnabled(false);
worldActions.enable(true);
worldActions.setEnabled(true);
}
if (nstate == GScrState.INV) {
invLayer.setVisible(true);
invLayer.enable(true);
invLayer.setEnabled(true);
}
this.state = nstate;
@ -176,15 +176,15 @@ public class ScreenGame extends LayeredScreen {
super(app);
addLayer(invLayer = new InvLayer(this));
invLayer.enable(false);
invLayer.setEnabled(false);
invLayer.setVisible(false);
addLayer(hudLayer = new HudLayer(this));
hudLayer.enable(true);
hudLayer.setEnabled(true);
hudLayer.setVisible(true);
addLayer(worldLayer = new WorldLayer(this));
worldLayer.enable(true);
worldLayer.setEnabled(true);
worldLayer.setVisible(true);
// TODO temporary, remove
@ -206,7 +206,7 @@ public class ScreenGame extends LayeredScreen {
bindKey(new KeyStroke(Keys.E), actionEat);
bindKey(new KeyStroke(Keys.M), actionToggleMinimap);
bindKey(new KeyStroke(Keys.Z), actionToggleZoom);
bindKey(new KeyStroke(Keys.R, Keys.MOD_CONTROL), actionLoad);
bindKey(new KeyStroke(Keys.L, Keys.MOD_CONTROL), actionLoad);
@ -225,7 +225,7 @@ public class ScreenGame extends LayeredScreen {
worldActions.add(actionLoad);
worldActions.add(actionMenu);
worldActions.enable(true);
worldActions.setEnabled(true);
// TMP TODO remove
bindKey(new KeyStroke(Keys.X), new Runnable() {

@ -1,56 +0,0 @@
package mightypork.rogue.screens.menu;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.ClickableComponent;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.gamecore.util.math.constraints.vect.mutable.VectVar;
import mightypork.rogue.Res;
class MenuButton extends ClickableComponent {
private static GLFont font = Res.getFont("thick");
private final TextPainter painter;
private final VectVar offset = Vect.makeVar();
private final Vect offsetPassive = height().div(16).toVectXY();
private final Vect offsetPassive2 = height().div(20).toVectXY();
private final Vect offsetUnder = height().div(32).toVectXY();
private final Color color;
public MenuButton(String text, Color color)
{
this.color = color;
this.painter = new TextPainter(font, AlignX.CENTER, this.color, text);
this.painter.setRect(this);
this.painter.setShadow(RGB.BLACK_30, offset);
painter.setPaddingHPerc(0, 5);
}
@Override
protected void renderComponent()
{
if (isMouseOver()) {
if (InputSystem.isMouseButtonDown(0)) {
offset.setTo(offsetUnder);
} else {
offset.setTo(offsetPassive2);
}
} else {
offset.setTo(offsetPassive);
}
painter.render();
}
}

@ -9,6 +9,7 @@ import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.screens.LayeredScreen;
import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.color.pal.PAL16;
import mightypork.gamecore.util.math.constraints.num.Num;
@ -16,6 +17,7 @@ import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.rogue.GameStateManager.GameState;
import mightypork.rogue.Res;
import mightypork.rogue.events.GameStateRequest;
import mightypork.rogue.screens.PushButton;
/**
@ -67,11 +69,12 @@ public class ScreenMainMenu extends LayeredScreen {
layout.put(ip, r, 0, 4, 1);
r += 5;
MenuButton btn;
PushButton btn;
final GLFont btnFont = Res.getFont("thick");
// world button
btn = new MenuButton("Play", PAL16.SLIMEGREEN);
btn = new PushButton(btnFont, "Play", PAL16.SLIMEGREEN);
btn.setAction(new Action() {
@Override
@ -99,7 +102,7 @@ public class ScreenMainMenu extends LayeredScreen {
*/
// quit button
btn = new MenuButton("Exit", PAL16.BLOODRED);
btn = new PushButton(btnFont, "Exit", PAL16.BLOODRED);
btn.setAction(new Action() {
@Override

@ -38,8 +38,8 @@ public class ScreenSelectWorld extends LayeredScreen {
private WorldSlot slot1;
private WorldSlot slot2;
private WorldSlot slot3;
public WorldsLayer(Screen screen)
{
super(screen);
@ -66,7 +66,7 @@ public class ScreenSelectWorld extends LayeredScreen {
layout.put(tp = new TextPainter(Res.getFont("thick"), AlignX.CENTER, RGB.YELLOW, "Save slot:"), 0, 0, 1, 1);
tp.setPaddingHPerc(0, 20);
tp.setShadow(RGB.BLACK_50, tp.height().mul(0.6 / 8D).toVectXY());
slot1 = new WorldSlot(root, Paths.SAVE_SLOT_1);
layout.put(slot1, 1, 0, 1, 1);
@ -84,7 +84,7 @@ public class ScreenSelectWorld extends LayeredScreen {
return 2;
}
@Override
protected void onScreenEnter()
{

@ -7,26 +7,21 @@ import java.io.IOException;
import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.layout.ClickableWrapper;
import mightypork.gamecore.gui.components.layout.ConstraintLayout;
import mightypork.gamecore.gui.components.layout.GridLayout;
import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.events.CrossfadeRequest;
import mightypork.gamecore.gui.events.ScreenRequest;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.util.Utils;
import mightypork.gamecore.util.ion.Ion;
import mightypork.gamecore.util.ion.IonBundle;
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.GameStateManager.GameState;
import mightypork.rogue.Res;
import mightypork.rogue.events.GameStateRequest;
import mightypork.rogue.screens.LoaderRequest;
import mightypork.rogue.events.LoadingOverlayRequest;
import mightypork.rogue.screens.PushButton;
import mightypork.rogue.world.World;
import mightypork.rogue.world.WorldProvider;
@ -47,8 +42,13 @@ public class WorldSlot extends ConstraintLayout {
private IonBundle worldBundle;
private PushButton loadBtn;
public WorldSlot(AppAccess app, File worldFile) {
private PushButton delBtn;
public WorldSlot(AppAccess app, File worldFile)
{
super(app);
this.file = worldFile;
@ -60,7 +60,7 @@ public class WorldSlot extends ConstraintLayout {
@Override
public double value()
{
return isMouseOver() ? 0.2 : 0.1;
return isMouseOver() ? 0.15 : 0.1;
}
}));
@ -68,18 +68,20 @@ public class WorldSlot extends ConstraintLayout {
add(qp);
final GridLayout gridl = new GridLayout(app, 1, 8);
gridl.setRect(innerRect.shrink(width().perc(10), Num.ZERO));
final Num shrinkH = width().perc(8);
final Num shrinkV = height().perc(10);
gridl.setRect(innerRect.shrink(shrinkH, shrinkH, shrinkV, shrinkV.half()));
add(gridl);
TextPainter tp;
ClickableWrapper btn;
final GLFont font = Res.getFont("thick");
tp = new TextPainter(font, AlignX.LEFT, RGB.WHITE, lblStrp);
tp.setPaddingHPerc(0, 20);
gridl.put(loadBtn = new PushButton(font, "", RGB.WHITE), 0, 0, 1, 7);
loadBtn.textPainter.setPaddingHPerc(0, 20);
loadBtn.textPainter.setAlign(AlignX.LEFT);
loadBtn.textPainter.setText(lblStrp);
loadBtn.disableHover();
gridl.put(btn = new ClickableWrapper(tp), 0, 0, 1, 7);
btn.setAction(new Action() {
loadBtn.setAction(new Action() {
@Override
protected void execute()
@ -92,7 +94,7 @@ public class WorldSlot extends ConstraintLayout {
msg = "Creating world...";
}
getEventBus().send(new LoaderRequest(msg, new Runnable() {
getEventBus().send(new LoadingOverlayRequest(msg, new Runnable() {
@Override
public void run()
@ -109,7 +111,7 @@ public class WorldSlot extends ConstraintLayout {
getEventBus().send(new ScreenRequest("game"));
} catch (Exception e) {
} catch (final Exception e) {
Log.e("Could not create & save the world.", e);
}
@ -123,7 +125,7 @@ public class WorldSlot extends ConstraintLayout {
getEventBus().send(new ScreenRequest("game"));
} catch (IOException e) {
} catch (final IOException e) {
Log.e("Could not load the world.", e);
}
}
@ -134,10 +136,12 @@ public class WorldSlot extends ConstraintLayout {
}
});
tp = new TextPainter(font, AlignX.LEFT, RGB.RED, "X");
tp.setPaddingHPerc(0, 20);
gridl.put(btn = new ClickableWrapper(tp), 0, 7, 1, 1);
btn.setAction(new Action() {
gridl.put(delBtn = new PushButton(font, "X", RGB.RED), 0, 7, 1, 1);
delBtn.textPainter.setPaddingHPerc(0, 20);
delBtn.textPainter.setAlign(AlignX.RIGHT);
delBtn.disableHover();
delBtn.setAction(new Action() {
@Override
protected void execute()
@ -153,6 +157,9 @@ public class WorldSlot extends ConstraintLayout {
public void refresh()
{
delBtn.setVisible(false);
delBtn.setEnabled(false);
if (!file.exists()) {
label = "<empty>";
} else {
@ -161,8 +168,11 @@ public class WorldSlot extends ConstraintLayout {
final int lvl = worldBundle.get("meta.last_level", -1);
if (lvl == -1) throw new RuntimeException(); // let the catch block handle it
label = "Floor " + (lvl + 1);
label = "Level " + (lvl + 1);
delBtn.setVisible(true);
delBtn.setEnabled(true);
} catch (final IOException e) {
label = "<corrupt>";
}

@ -22,10 +22,19 @@ import mightypork.rogue.world.level.Level;
*/
public class PlayerFacade {
/** */
/** a world */
private final World world;
/**
* @return true if can go up
*/
public boolean canAscend()
{
return world.playerData.getLevelNumber() > 0;
}
/**
* @param world
*/
@ -35,12 +44,18 @@ public class PlayerFacade {
}
public boolean canAscend()
/**
* @return true if can go down
*/
public boolean canDescend()
{
return world.playerData.getLevelNumber() > 0;
return world.playerData.getLevelNumber() < world.levels.size() - 1;
}
/**
* Go one level down if applicable
*/
public void descend()
{
if (!canDescend()) return;
@ -58,12 +73,9 @@ public class PlayerFacade {
}
public boolean canDescend()
{
return world.playerData.getLevelNumber() < world.levels.size() - 1;
}
/**
* Go one level up if applicable
*/
public void ascend()
{
if (!canAscend()) return;
@ -90,36 +102,56 @@ public class PlayerFacade {
}
/**
* @return current level
*/
public Level getLevel()
{
return world.levels.get(world.playerData.getLevelNumber());
}
/**
* @return entity ID
*/
public int getEID()
{
return world.playerData.getEID();
}
/**
* @return entity coordinate in level
*/
public Coord getCoord()
{
return world.playerEntity.getCoord();
}
/**
* @return entity visual pos in level
*/
public Vect getVisualPos()
{
return world.playerEntity.pos.getVisualPos();
}
/**
* Find path to
*
* @param pos
*/
public void navigateTo(Coord pos)
{
world.playerEntity.pos.navigateTo(pos);
}
/**
* Discard steps in buffer
*/
public void cancelPath()
{
world.playerEntity.pos.cancelPath();
@ -366,8 +398,8 @@ public class PlayerFacade {
{
return world;
}
public boolean canGoTo(Step side)
{
return getEntity().pos.canGoTo(side);

@ -22,7 +22,7 @@ import mightypork.rogue.world.level.Level;
/**
* World on a server. To a server, all players and levels are equal.
* World object.
*
* @author MightyPork
*/
@ -80,18 +80,18 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
in.loadBundled("player", playerData);
int eid = playerData.getEID();
int lvl = playerData.getLevelNumber();
final int eid = playerData.getEID();
final int lvl = playerData.getLevelNumber();
playerEntity = levels.get(lvl).getEntity(eid);
if (playerEntity == null) {
Log.e("Player entity not found in the world: " + eid + " on floor " + lvl);
for(int i=0; i<levels.size(); i++) {
Entity ent = levels.get(i).getEntity(eid);
if(ent != null) {
Log.f3("Player entity was really on floor: "+i);
for (int i = 0; i < levels.size(); i++) {
final Entity ent = levels.get(i).getEntity(eid);
if (ent != null) {
Log.f3("Player entity was really on floor: " + i);
}
}
@ -231,18 +231,29 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
}
/**
* @return world console
*/
public WorldConsole getConsole()
{
return console;
}
/**
* Set file for saving
*
* @param file save file
*/
public void setSaveFile(File file)
{
this.saveFile = file;
}
/**
* @return assigned file fro saving
*/
public File getSaveFile()
{
return saveFile;

@ -34,7 +34,8 @@ public class WorldConsole implements Updateable {
private double elapsed = 0;
private Entry(String text) {
private Entry(String text)
{
this.text = text;
this.fadeout = new NumAnimated(1, Easing.LINEAR);
this.fadeout.setDefaultDuration(0.5);
@ -204,14 +205,14 @@ public class WorldConsole implements Updateable {
{
addMessage("Error while saving; See the log for details.");
}
public void msgReloaded()
{
addMessage("World loaded from file.");
}
public void msgLoadFailed()
{
addMessage("Error while loading; See the log for details.");

@ -11,6 +11,11 @@ import mightypork.rogue.world.gen.WorldCreator;
import mightypork.rogue.world.level.Level;
/**
* Global singleton world holder and storage
*
* @author MightyPork
*/
public class WorldProvider extends RootBusNode {
public static synchronized void init(BusAccess busAccess)
@ -21,7 +26,8 @@ public class WorldProvider extends RootBusNode {
}
public WorldProvider(BusAccess busAccess) {
public WorldProvider(BusAccess busAccess)
{
super(busAccess);
setListening(false);
}
@ -49,14 +55,23 @@ public class WorldProvider extends RootBusNode {
};
/**
* Create and register a world based on a seed
*
* @param seed random seed
* @return the world
*/
public World createWorld(long seed)
{
World w = WorldCreator.createWorld(seed);
final World w = WorldCreator.createWorld(seed);
setWorld(w);
return w;
}
/**
* Destroy world, set to null.
*/
public void destroyWorld()
{
setWorld(null);
@ -100,6 +115,11 @@ public class WorldProvider extends RootBusNode {
}
/**
* Save to world's assigned save file.
*
* @throws IOException
*/
public void saveWorld() throws IOException
{
saveWorld(world.getSaveFile());

@ -10,6 +10,7 @@ import mightypork.gamecore.util.math.constraints.rect.RectConst;
import mightypork.gamecore.util.math.constraints.rect.proxy.RectProxy;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.gamecore.util.math.constraints.vect.VectConst;
import mightypork.rogue.Config;
import mightypork.rogue.Res;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.level.Level;
@ -107,13 +108,11 @@ public class WorldRenderer extends RectProxy {
if (USE_BATCH_RENDERING) {
Render.enterBatchTexturedQuadMode(Res.getTexture("tiles"));
}
for (trc.pos.x = x1; trc.pos.x <= x2; trc.pos.x++) {
for (trc.pos.y = y1; trc.pos.y <= y2; trc.pos.y++) {
trc.renderTile();
}
}
if (USE_BATCH_RENDERING) {
Render.leaveBatchTexturedQuadMode();
}
@ -141,10 +140,26 @@ public class WorldRenderer extends RectProxy {
e.render(trc);
}
Render.popMatrix();
// === unexplored fog ===
// batch rendering of the tiles
if (USE_BATCH_RENDERING) {
Render.setColor(RGB.WHITE, Config.RENDER_UFOG ? 1 : 0.6);
Render.enterBatchTexturedQuadMode(Res.getTexture("tiles"));
}
for (trc.pos.x = x1; trc.pos.x <= x2; trc.pos.x++) {
for (trc.pos.y = y1; trc.pos.y <= y2; trc.pos.y++) {
trc.renderUFog();
}
}
if (USE_BATCH_RENDERING) {
Render.leaveBatchTexturedQuadMode();
}
// === OVERLAY SHADOW ===
Render.popMatrix();
Render.quadGradH(leftShadow, RGB.BLACK, RGB.NONE);
Render.quadGradH(rightShadow, RGB.NONE, RGB.BLACK);

@ -6,7 +6,6 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import mightypork.gamecore.eventbus.clients.DelegatingClient;
import mightypork.gamecore.eventbus.events.Updateable;
@ -16,7 +15,6 @@ 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.pathfinding.PathFinder;
import mightypork.rogue.Config;
import mightypork.rogue.world.World;
import mightypork.rogue.world.entity.modules.EntityModuleHealth;
import mightypork.rogue.world.entity.modules.EntityModulePosition;
@ -160,9 +158,7 @@ public abstract class Entity implements IonObjBundled, Updateable, DelegatingCli
@DefaultImpl
public final void render(MapRenderContext context)
{
if (context.getTile(getCoord()).isExplored() || !Config.RENDER_UFOG) {
getRenderer().render(context);
}
getRenderer().render(context);
}
@ -295,7 +291,9 @@ public abstract class Entity implements IonObjBundled, Updateable, DelegatingCli
return lastAttacker;
}
public double getLastAttackTime() {
public double getLastAttackTime()
{
return health.getTimeSinceLastDamage();
}
}

@ -10,7 +10,7 @@ import mightypork.rogue.world.World;
/**
* Entity model
* Entity model - builder
*
* @author MightyPork
*/

@ -2,7 +2,6 @@ package mightypork.rogue.world.entity;
import java.io.IOException;
import java.util.Random;
import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.util.annot.DefaultImpl;
@ -11,7 +10,8 @@ import mightypork.gamecore.util.ion.IonObjBundled;
/**
* Abstract entity module; Modules make up an entity AI and behavior.
* Abstract entity module<br>
* Modules make up an entity AI and behavior.
*
* @author MightyPork
*/
@ -26,6 +26,9 @@ public abstract class EntityModule implements IonObjBundled, Updateable {
}
/**
* @return whether the module should be saved into a world file
*/
public abstract boolean isModuleSaved();

@ -8,6 +8,11 @@ import mightypork.gamecore.util.math.algo.pathfinding.Heuristic;
import mightypork.gamecore.util.math.algo.pathfinding.PathFinder;
/**
* Basic Pathfinder implementation for entities
*
* @author MightyPork
*/
public class EntityPathFinder extends PathFinder {
protected final Entity entity;

@ -4,6 +4,11 @@ package mightypork.rogue.world.entity;
import mightypork.rogue.world.level.render.MapRenderContext;
/**
* Entity renderer
*
* @author MightyPork
*/
public abstract class EntityRenderer {
public abstract void render(MapRenderContext context);

@ -8,5 +8,10 @@ package mightypork.rogue.world.entity;
*/
public enum EntityType
{
PLAYER, MONSTER, PASSIVE;
/** Player entity */
PLAYER,
/** Monster entity */
MONSTER,
/** Non-mobile entity */
PASSIVE;
}

@ -48,6 +48,7 @@ public class BossRatAi extends GrayRatAi {
healTimer.update(delta);
}
@Override
protected double getStepTime()
{

@ -36,6 +36,7 @@ public class BrownRatAi extends GrayRatAi {
return Calc.randInt(7, 12);
}
@Override
protected double getStepTime()
{

@ -42,7 +42,7 @@ public class GrayRatAi extends MonsterAi {
{
return Calc.randInt(7, 11);
}
@Override
protected double getStepTime()

@ -57,14 +57,14 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
if (!isIdle()) return;
// annoyed by attacking.
if(entity.getLastAttackTime() < 0.5) {
if (entity.getLastAttackTime() < 0.5) {
lookForTarget();
return;
}
if(entity.pos.isMoving()) return;
if (entity.pos.isMoving()) return;
if(Calc.rand.nextInt(10) == 0) {
if (Calc.rand.nextInt(10) == 0) {
entity.pos.addStep(Sides.randomCardinal());
}
}
@ -76,7 +76,8 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
private int preyId = -1;
public MonsterAi(final Entity entity) {
public MonsterAi(final Entity entity)
{
super(entity);
noDoorPf = new PathFinderProxy(entity.getPathFinder()) {
@ -189,7 +190,6 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
{
return !chasing;
}
public boolean isChasing()
@ -197,10 +197,11 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
return chasing;
}
private void lookForTarget()
{
if (entity.isDead()) return;
final Entity prey = entity.getLevel().getClosestEntity(entity.pos.getVisualPos(), EntityType.PLAYER, getScanRadius());
if (prey != null) {
@ -208,7 +209,7 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
final List<Coord> noDoorPath = noDoorPf.findPath(entity.getCoord(), prey.getCoord());
if (noDoorPath == null) return; // cant reach, give up
startChasing(prey);
}
}
@ -340,6 +341,7 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
return 1; // For override
}
@DefaultImpl
protected double getStepTime()
{

@ -67,6 +67,11 @@ public class EntityModulePosition extends EntityModule {
}
/**
* Set coord without animation
*
* @param coord coord
*/
public void setCoord(Coord coord)
{
freeTile(); // release old tile
@ -79,6 +84,9 @@ public class EntityModulePosition extends EntityModule {
}
/**
* Occupy current tile in level
*/
public void occupyTile()
{
if (entity.getLevel() != null) {
@ -87,6 +95,9 @@ public class EntityModulePosition extends EntityModule {
}
/**
* free current tile in level
*/
public void freeTile()
{
if (entity.getLevel() != null) {
@ -152,12 +163,20 @@ public class EntityModulePosition extends EntityModule {
}
/**
* @return true if path buffer is empty
*/
public boolean isPathFinished()
{
return entityPos.isFinished() && path.isEmpty();
}
/**
* Add a step to path buffer
*
* @param step
*/
public void addStep(Step step)
{
if (path.isEmpty() && !canGoTo(step)) return;
@ -166,12 +185,21 @@ public class EntityModulePosition extends EntityModule {
}
/**
* Discard steps in buffer
*/
public void cancelPath()
{
path.clear();
}
/**
* Find path to
*
* @param target
* @return path found
*/
public boolean navigateTo(Coord target)
{
if (target.equals(getCoord())) return true;
@ -195,36 +223,49 @@ public class EntityModulePosition extends EntityModule {
}
/**
* Add steps to path buffer
*
* @param path steps
*/
public void addSteps(List<Step> path)
{
this.path.addAll(path);
}
/**
* @return coord in level
*/
public Coord getCoord()
{
return entityPos.getCoord();
}
public double getStepTime()
{
return stepTime;
}
/**
* Set step time (seconds)
*
* @param stepTime step time
*/
public void setStepTime(double stepTime)
{
this.stepTime = stepTime;
}
/**
* @return step progress 0..1
*/
public double getProgress()
{
return entityPos.getProgress();
}
/**
* @return visual pos in level; interpolated from last to new coord
*/
public VectConst getVisualPos()
{
return entityPos.getVisualPos();

@ -2,11 +2,11 @@ package mightypork.rogue.world.events;
import mightypork.gamecore.eventbus.BusEvent;
import mightypork.gamecore.eventbus.event_flags.UnloggedEvent;
import mightypork.gamecore.eventbus.event_flags.NotLoggedEvent;
import mightypork.rogue.world.entity.impl.PlayerEntity;
@UnloggedEvent
@NotLoggedEvent
public class PlayerStepEndEvent extends BusEvent<PlayerStepEndListener> {
private final PlayerEntity player;

@ -43,7 +43,7 @@ public class LevelGenerator {
if (rand.nextInt(6) > 0) map.addRoom(Rooms.DEAD_END, false);
}
for (int i = 0; i < Calc.randInt(rand, 1, (int)Math.ceil(level / 2D)); i++) {
for (int i = 0; i < Calc.randInt(rand, 1, (int) Math.ceil(level / 2D)); i++) {
map.addRoom(Rooms.TREASURE, false);
}
@ -103,12 +103,12 @@ public class LevelGenerator {
map.putEntityInMap(e, 30);
if(rand.nextInt(6+level/2)==0) {
map.putItemInMap(Items.CHEESE.createItem(), 10);
if (rand.nextInt(6 + level / 2) == 0) {
map.putItemInMap(Items.CHEESE.createItem(), 10);
}
if(rand.nextInt(6)==0) {
map.putItemInMap(Items.MEAT.createItem(), 10);
if (rand.nextInt(6) == 0) {
map.putItemInMap(Items.MEAT.createItem(), 10);
}
}

@ -12,6 +12,7 @@ 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.Config;
import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.level.Level;
@ -55,7 +56,7 @@ public class Minimap extends InputComponent implements MouseButtonListener {
for (pos.x = 0, point.x = tl.xi(); pos.x < lw; pos.x++, point.x += unit) {
final Tile t = lvl.getTile(pos);
if (t.isNull() || !t.isExplored()) continue;
if (t.isNull() || (!t.isExplored() && Config.RENDER_UFOG)) continue;
final Color clr = t.getMapColor();

@ -49,7 +49,7 @@ public class MIPKeyboard extends MapInteractionPlugin implements PlayerStepEndLi
if (evt.isDown() || mapView.plc.getPlayer().isMoving()) return; // not interested
if(InputSystem.getModifierKeys() != Keys.MOD_NONE) return;
if (InputSystem.getModifierKeys() != Keys.MOD_NONE) return;
for (int i = 0; i < 4; i++) {
if (evt.getKey() == keys[i]) {
@ -65,8 +65,8 @@ public class MIPKeyboard extends MapInteractionPlugin implements PlayerStepEndLi
if (mapView.plc.getPlayer().getMoveProgress() < 0.8) return false;
if(InputSystem.getModifierKeys() != Keys.MOD_NONE) return false;
if (InputSystem.getModifierKeys() != Keys.MOD_NONE) return false;
for (int i = 0; i < 4; i++) {

@ -2,7 +2,6 @@ package mightypork.rogue.world.item;
import java.io.IOException;
import java.util.Random;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.util.annot.DefaultImpl;

@ -2,7 +2,6 @@ package mightypork.rogue.world.item;
import java.io.IOException;
import java.util.Random;
import mightypork.gamecore.util.ion.IonInput;
import mightypork.gamecore.util.ion.IonOutput;

@ -24,7 +24,6 @@ import mightypork.gamecore.util.math.noise.NoiseGen;
import mightypork.rogue.world.World;
import mightypork.rogue.world.entity.Entities;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityPathFinder;
import mightypork.rogue.world.entity.EntityType;
import mightypork.rogue.world.entity.impl.PlayerEntity;
import mightypork.rogue.world.item.Item;
@ -124,11 +123,13 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
private double timeSinceLastEntitySort;
public Level() {
public Level()
{
}
public Level(int width, int height) {
public Level(int width, int height)
{
size.setTo(width, height);
buildArray();
}
@ -164,7 +165,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
public final Tile getTile(Coord pos)
{
if (!pos.isInRange(0, 0, size.x - 1, size.y - 1)) return Tiles.NULL.createTile(); // out of range
return tiles[pos.y][pos.x];
}

@ -67,6 +67,12 @@ public final class TileRenderContext extends MapRenderContext implements RectBou
}
public void renderUFog()
{
map.getTile(pos).renderUFog(this);
}
public void renderItems()
{
map.getTile(pos).renderExtra(this);

@ -2,7 +2,6 @@ package mightypork.rogue.world.tile;
import java.io.IOException;
import java.util.Random;
import mightypork.gamecore.eventbus.BusAccess;
import mightypork.gamecore.eventbus.EventBus;
@ -61,6 +60,13 @@ public abstract class Tile implements BusAccess, IonObjBlob {
renderer.renderTile(context);
if (doesReceiveShadow()) renderer.renderShadows(context);
}
@DefaultImpl
public void renderUFog(TileRenderContext context)
{
initRenderer();
renderer.renderUnexploredFog(context);
}

@ -6,7 +6,6 @@ import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.gamecore.util.math.algo.Sides;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.rogue.Config;
import mightypork.rogue.Res;
import mightypork.rogue.world.level.render.TileRenderContext;
import mightypork.rogue.world.tile.render.NullTileRenderer;
@ -22,7 +21,7 @@ public abstract class TileRenderer implements Updateable {
public static final TileRenderer NONE = new NullTileRenderer();
private static TxQuad SH_N, SH_S, SH_E, SH_W, SH_NW, SH_NE, SH_SW, SH_SE;
private static TxQuad UFOG_N, UFOG_S, UFOG_E, UFOG_W, UFOG_NW, UFOG_NE, UFOG_SW, UFOG_SE;
private static TxQuad UFOG_N, UFOG_S, UFOG_E, UFOG_W, UFOG_NW, UFOG_NE, UFOG_SW, UFOG_SE, UFOG_FULL;
private static boolean inited;
@ -62,6 +61,7 @@ public abstract class TileRenderer implements Updateable {
UFOG_NE = Res.txq("tile.ufog.ne");
UFOG_SW = Res.txq("tile.ufog.sw");
UFOG_SE = Res.txq("tile.ufog.se");
UFOG_FULL = Res.txq("tile.ufog.full");
inited = true;
}
}
@ -105,10 +105,15 @@ public abstract class TileRenderer implements Updateable {
public void renderUnexploredFog(TileRenderContext context)
{
if (!Config.RENDER_UFOG) return;
// TODO cache values, update neighbouring tiles upon "explored" flag changed.
final Rect rect = context.getRect();
if (!context.getTile().isExplored()) {
Render.quadTextured(rect, UFOG_FULL);
return;
}
byte ufog = 0;
for (int i = 0; i < 8; i++) {
@ -120,7 +125,6 @@ public abstract class TileRenderer implements Updateable {
if (ufog == 0) return;
final Rect rect = context.getRect();
if ((ufog & Sides.NW_CORNER) == Sides.MASK_NW) Render.quadTextured(rect, UFOG_NW);
if ((ufog & Sides.MASK_N) != 0) Render.quadTextured(rect, UFOG_N);
if ((ufog & Sides.NE_CORNER) == Sides.MASK_NE) Render.quadTextured(rect, UFOG_NE);
@ -131,6 +135,7 @@ public abstract class TileRenderer implements Updateable {
if ((ufog & Sides.SW_CORNER) == Sides.MASK_SW) Render.quadTextured(rect, UFOG_SW);
if ((ufog & Sides.MASK_S) != 0) Render.quadTextured(rect, UFOG_S);
if ((ufog & Sides.SE_CORNER) == Sides.MASK_SE) Render.quadTextured(rect, UFOG_SE);
}

Loading…
Cancel
Save