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. 1
      src/mightypork/gamecore/input/KeyBinding.java
  18. 16
      src/mightypork/gamecore/input/KeyStroke.java
  19. 4
      src/mightypork/gamecore/input/events/KeyEvent.java
  20. 4
      src/mightypork/gamecore/input/events/MouseButtonEvent.java
  21. 4
      src/mightypork/gamecore/input/events/MouseMotionEvent.java
  22. 4
      src/mightypork/gamecore/util/math/Calc.java
  23. 3
      src/mightypork/gamecore/util/math/Range.java
  24. 1
      src/mightypork/gamecore/util/math/algo/Sides.java
  25. 2
      src/mightypork/gamecore/util/math/timing/TaskRepeater.java
  26. 2
      src/mightypork/rogue/App.java
  27. 1
      src/mightypork/rogue/GameStateManager.java
  28. 1
      src/mightypork/rogue/Res.java
  29. 2
      src/mightypork/rogue/events/ActionRequest.java
  30. 5
      src/mightypork/rogue/events/GameStateRequest.java
  31. 38
      src/mightypork/rogue/events/LoadingOverlayRequest.java
  32. 9
      src/mightypork/rogue/screens/FpsOverlay.java
  33. 22
      src/mightypork/rogue/screens/LoaderRequest.java
  34. 32
      src/mightypork/rogue/screens/LoadingOverlay.java
  35. 71
      src/mightypork/rogue/screens/PushButton.java
  36. 26
      src/mightypork/rogue/screens/game/ScreenGame.java
  37. 56
      src/mightypork/rogue/screens/menu/MenuButton.java
  38. 9
      src/mightypork/rogue/screens/menu/ScreenMainMenu.java
  39. 58
      src/mightypork/rogue/screens/select_world/WorldSlot.java
  40. 50
      src/mightypork/rogue/world/PlayerFacade.java
  41. 19
      src/mightypork/rogue/world/World.java
  42. 3
      src/mightypork/rogue/world/WorldConsole.java
  43. 24
      src/mightypork/rogue/world/WorldProvider.java
  44. 21
      src/mightypork/rogue/world/WorldRenderer.java
  45. 8
      src/mightypork/rogue/world/entity/Entity.java
  46. 2
      src/mightypork/rogue/world/entity/EntityModel.java
  47. 7
      src/mightypork/rogue/world/entity/EntityModule.java
  48. 5
      src/mightypork/rogue/world/entity/EntityPathFinder.java
  49. 5
      src/mightypork/rogue/world/entity/EntityRenderer.java
  50. 7
      src/mightypork/rogue/world/entity/EntityType.java
  51. 1
      src/mightypork/rogue/world/entity/impl/BossRatAi.java
  52. 1
      src/mightypork/rogue/world/entity/impl/BrownRatAi.java
  53. 6
      src/mightypork/rogue/world/entity/impl/MonsterAi.java
  54. 53
      src/mightypork/rogue/world/entity/modules/EntityModulePosition.java
  55. 4
      src/mightypork/rogue/world/events/PlayerStepEndEvent.java
  56. 3
      src/mightypork/rogue/world/gui/Minimap.java
  57. 1
      src/mightypork/rogue/world/item/Item.java
  58. 1
      src/mightypork/rogue/world/item/ItemModel.java
  59. 7
      src/mightypork/rogue/world/level/Level.java
  60. 6
      src/mightypork/rogue/world/level/render/TileRenderContext.java
  61. 8
      src/mightypork/rogue/world/tile/Tile.java
  62. 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.DelayedEvent;
import mightypork.gamecore.eventbus.event_flags.ImmediateEvent; import mightypork.gamecore.eventbus.event_flags.ImmediateEvent;
import mightypork.gamecore.eventbus.event_flags.NonConsumableEvent; 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.SingleReceiverEvent;
import mightypork.gamecore.eventbus.event_flags.UnloggedEvent;
/** /**
@ -15,7 +15,7 @@ import mightypork.gamecore.eventbus.event_flags.UnloggedEvent;
* <p> * <p>
* Can be annotated as {@link SingleReceiverEvent} to be delivered once only, * Can be annotated as {@link SingleReceiverEvent} to be delivered once only,
* and {@link DelayedEvent} or {@link ImmediateEvent} to specify default sending * 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). * bus logging (useful for very frequent events, such as UpdateEvent).
* </p> * </p>
* <p> * <p>

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

@ -14,4 +14,4 @@ import java.lang.annotation.*;
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Inherited @Inherited
@Documented @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.BusEvent;
import mightypork.gamecore.eventbus.event_flags.ImmediateEvent; import mightypork.gamecore.eventbus.event_flags.ImmediateEvent;
import mightypork.gamecore.eventbus.event_flags.NonConsumableEvent; 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 * @author MightyPork
*/ */
@UnloggedEvent @NotLoggedEvent
@ImmediateEvent @ImmediateEvent
@NonConsumableEvent @NonConsumableEvent
public class UpdateEvent extends BusEvent<Updateable> { public class UpdateEvent extends BusEvent<Updateable> {

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

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

@ -15,7 +15,7 @@ public interface Enableable {
* *
* @param yes enabled * @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.logging.Log;
import mightypork.gamecore.render.Renderable; import mightypork.gamecore.render.Renderable;
import mightypork.gamecore.util.annot.DefaultImpl; 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.Rect;
import mightypork.gamecore.util.math.constraints.rect.caching.AbstractRectCache; import mightypork.gamecore.util.math.constraints.rect.caching.AbstractRectCache;
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound; 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 boolean visible = true;
private int disableLevel = 0; private int disableLevel = 0;
private Num alphaMul = Num.ONE;
public BaseComponent() public BaseComponent()
@ -67,7 +70,9 @@ public abstract class BaseComponent extends AbstractRectCache implements Compone
{ {
if (!isVisible()) return; if (!isVisible()) return;
Color.pushAlpha(alphaMul);
renderComponent(); renderComponent();
Color.popAlpha();
} }
@ -109,7 +114,7 @@ public abstract class BaseComponent extends AbstractRectCache implements Compone
@Override @Override
public void enable(boolean yes) public void setEnabled(boolean yes)
{ {
if (yes) { if (yes) {
if (disableLevel > 0) disableLevel--; if (disableLevel > 0) disableLevel--;
@ -124,4 +129,16 @@ public abstract class BaseComponent extends AbstractRectCache implements Compone
{ {
return disableLevel == 0; 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 @Override
public void enable(boolean yes) public void setEnabled(boolean yes)
{ {
super.enable(yes); super.setEnabled(yes);
for (final Component c : components) { for (final Component c : components) {
c.enable(yes); c.setEnabled(yes);
} }
} }

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

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

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

@ -16,6 +16,8 @@ import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.render.Renderable; import mightypork.gamecore.render.Renderable;
import mightypork.gamecore.util.annot.DefaultImpl; 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; 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) */ /** Extra updated items (outside root - those can just implement Updateable) */
protected final Collection<Updateable> updated = new LinkedHashSet<>(); protected final Collection<Updateable> updated = new LinkedHashSet<>();
private Num alphaMul = Num.ONE;
public Overlay(AppAccess app) public Overlay(AppAccess app)
@ -90,10 +93,10 @@ public abstract class Overlay extends AppSubModule implements Comparable<Overlay
@Override @Override
public void enable(boolean yes) public void setEnabled(boolean yes)
{ {
this.enabled = 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; if (!isVisible()) return;
Color.pushAlpha(alphaMul);
for (final Renderable r : rendered) { for (final Renderable r : rendered) {
r.render(); 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.events.ScreenRequest;
import mightypork.gamecore.gui.screens.Overlay; import mightypork.gamecore.gui.screens.Overlay;
import mightypork.gamecore.util.math.Easing; 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.constraints.num.mutable.NumAnimated;
import mightypork.gamecore.util.math.timing.TimedTask; import mightypork.gamecore.util.math.timing.TimedTask;
import mightypork.rogue.events.ActionRequest; 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_IN = 0.5;
private static final double T_OUT = 0.7; private static final double T_OUT = 0.7;
NumAnimated blackLevel = new NumAnimated(0); NumAnimated alpha = new NumAnimated(0);
Color color = Color.dark(blackLevel);
String requestedScreenName; String requestedScreenName;
TimedTask revealTask = new TimedTask() { TimedTask revealTask = new TimedTask() {
@ -33,8 +31,8 @@ public class CrossfadeOverlay extends Overlay {
} else { } else {
getEventBus().send(new ScreenRequest(requestedScreenName)); getEventBus().send(new ScreenRequest(requestedScreenName));
} }
blackLevel.setEasing(Easing.SINE_OUT); alpha.setEasing(Easing.SINE_OUT);
blackLevel.fadeOut(T_OUT); alpha.fadeOut(T_OUT);
} }
}; };
@ -43,12 +41,14 @@ public class CrossfadeOverlay extends Overlay {
{ {
super(app); super(app);
final QuadPainter qp = new QuadPainter(color); final QuadPainter qp = new QuadPainter(RGB.BLACK);
qp.setRect(root); qp.setRect(root);
root.add(qp); root.add(qp);
updated.add(blackLevel); updated.add(alpha);
updated.add(revealTask); updated.add(revealTask);
setAlpha(alpha);
} }
@ -64,13 +64,13 @@ public class CrossfadeOverlay extends Overlay {
requestedScreenName = screen; requestedScreenName = screen;
if (fromDark) { if (fromDark) {
blackLevel.setTo(1); alpha.setTo(1);
revealTask.run(); revealTask.run();
} else { } else {
revealTask.start(T_IN); revealTask.start(T_IN);
blackLevel.setEasing(Easing.SINE_IN); alpha.setEasing(Easing.SINE_IN);
blackLevel.fadeIn(T_IN); alpha.fadeIn(T_IN);
} }
} }

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

@ -1,10 +1,6 @@
package mightypork.gamecore.input; package mightypork.gamecore.input;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
@ -27,7 +23,8 @@ public class KeyStroke {
* @param mod_mask mods mask * @param mod_mask mods mask
* @param key key code * @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.fallingEdge = fallingEdge;
this.key = key; this.key = key;
this.mod = mod_mask; this.mod = mod_mask;
@ -36,10 +33,12 @@ public class KeyStroke {
/** /**
* Rising edge keystroke * Rising edge keystroke
*
* @param mod_mask mods mask * @param mod_mask mods mask
* @param key key code * @param key key code
*/ */
public KeyStroke(int key, int mod_mask) { public KeyStroke(int key, int mod_mask)
{
this(false, key, mod_mask); this(false, key, mod_mask);
} }
@ -49,7 +48,8 @@ public class KeyStroke {
* *
* @param key key code * @param key key code
*/ */
public KeyStroke(int key) { public KeyStroke(int key)
{
this(false, key, Keys.MOD_NONE); this(false, key, Keys.MOD_NONE);
} }
@ -115,7 +115,7 @@ public class KeyStroke {
if (this == obj) return true; if (this == obj) return true;
if (obj == null) return false; if (obj == null) return false;
if (getClass() != obj.getClass()) return false; if (getClass() != obj.getClass()) return false;
KeyStroke other = (KeyStroke) obj; final KeyStroke other = (KeyStroke) obj;
if (fallingEdge != other.fallingEdge) return false; if (fallingEdge != other.fallingEdge) return false;
if (key != other.key) return false; if (key != other.key) return false;
if (mod != other.mod) 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.BusEvent;
import mightypork.gamecore.eventbus.event_flags.UnloggedEvent; import mightypork.gamecore.eventbus.event_flags.NotLoggedEvent;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
@ -12,7 +12,7 @@ import org.lwjgl.input.Keyboard;
* *
* @author MightyPork * @author MightyPork
*/ */
@UnloggedEvent @NotLoggedEvent
public class KeyEvent extends BusEvent<KeyListener> { public class KeyEvent extends BusEvent<KeyListener> {
private final int key; private final int key;

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

@ -670,15 +670,17 @@ public class Calc {
public static int randInt(Random rand, int low, int high) 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); return low + rand.nextInt(range);
} }
public static int randInt(int low, int high) 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.) * Get ordinal version of numbers (1 = 1st, 5 = 5th etc.)
* *

@ -1,9 +1,6 @@
package mightypork.gamecore.util.math; package mightypork.gamecore.util.math;
import java.util.Random;
/** /**
* Numeric range, able to generate random numbers and give min/max values. * Numeric range, able to generate random numbers and give min/max values.
* *

@ -1,5 +1,6 @@
package mightypork.gamecore.util.math.algo; package mightypork.gamecore.util.math.algo;
import mightypork.gamecore.util.math.Calc; import mightypork.gamecore.util.math.Calc;

@ -25,7 +25,7 @@ public abstract class TaskRepeater extends AnimatorRewind implements Runnable, E
@Override @Override
public void enable(boolean yes) public void setEnabled(boolean yes)
{ {
this.enabled = 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); bindEventToKey(new GameStateRequest(GameState.MAIN_MENU), Keys.M, Keys.MOD_CONTROL);
} }
private void bindEventToKey(final BusEvent<?> event, int key) private void bindEventToKey(final BusEvent<?> event, int key)
{ {
bindEventToKey(event, key, Keys.MOD_NONE); bindEventToKey(event, key, Keys.MOD_NONE);
} }
private void bindEventToKey(final BusEvent<?> event, int key, byte mod) private void bindEventToKey(final BusEvent<?> event, int key, byte mod)
{ {
getInput().bindKey(new KeyStroke(key, mod), new Runnable() { 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.app.AppModule;
import mightypork.gamecore.gui.events.CrossfadeRequest; import mightypork.gamecore.gui.events.CrossfadeRequest;
import mightypork.gamecore.logging.Log; import mightypork.gamecore.logging.Log;
import mightypork.rogue.world.WorldProvider;
public class GameStateManager extends AppModule { 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.ne", grid.makeQuad(5, 7).flipX());
textures.add("tile.ufog.sw", grid.makeQuad(5, 7).flipY()); 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.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); 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 * @author MightyPork
*/ */

@ -6,6 +6,11 @@ import mightypork.rogue.GameStateManager;
import mightypork.rogue.GameStateManager.GameState; import mightypork.rogue.GameStateManager.GameState;
/**
* Request for a game state change
*
* @author MightyPork
*/
public class GameStateRequest extends BusEvent<GameStateManager> { public class GameStateRequest extends BusEvent<GameStateManager> {
final private GameState requested; 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; import mightypork.rogue.Res;
/**
* FPS indicator overlay
*
* @author MightyPork
*/
public class FpsOverlay extends Overlay { public class FpsOverlay extends Overlay {
TextPainter tp; TextPainter tp;
@ -43,7 +48,7 @@ public class FpsOverlay extends Overlay {
final Num h = root.height(); final Num h = root.height();
final RectBound constraint = root.shrink(h.perc(3)).topRight().startRect().growDown(h.perc(5).max(16)); 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 @Override
public String getString() public String getString()
@ -53,7 +58,7 @@ public class FpsOverlay extends Overlay {
}); });
tp.setRect(constraint); 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); 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.AlignX;
import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.events.ScreenRequest;
import mightypork.gamecore.gui.screens.Overlay; import mightypork.gamecore.gui.screens.Overlay;
import mightypork.gamecore.util.Utils; import mightypork.gamecore.util.Utils;
import mightypork.gamecore.util.math.Easing; 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.PAL16;
import mightypork.gamecore.util.math.color.pal.RGB; import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.Num; 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.math.timing.TimedTask;
import mightypork.gamecore.util.strings.StringProvider; import mightypork.gamecore.util.strings.StringProvider;
import mightypork.rogue.Res; 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 { public class LoadingOverlay extends Overlay {
private static final double T_IN = 0.5; private static final double T_IN = 0.5;
@ -42,7 +44,7 @@ public class LoadingOverlay extends Overlay {
private String msg; private String msg;
private Runnable task; private Runnable task;
private TimedTask tt = new TimedTask() { private final TimedTask tt = new TimedTask() {
@Override @Override
public void run() public void run()
@ -62,7 +64,8 @@ public class LoadingOverlay extends Overlay {
}; };
public LoadingOverlay(AppAccess app) { public LoadingOverlay(AppAccess app)
{
super(app); super(app);
final QuadPainter qp = new QuadPainter(PAL16.SEABLUE); final QuadPainter qp = new QuadPainter(PAL16.SEABLUE);
@ -80,6 +83,8 @@ public class LoadingOverlay extends Overlay {
tp.setRect(textRect); tp.setRect(textRect);
tp.setShadow(RGB.BLACK_60, tp.height().mul(1 / 8D).toVectXY()); tp.setShadow(RGB.BLACK_60, tp.height().mul(1 / 8D).toVectXY());
root.add(tp); root.add(tp);
setAlpha(alpha);
} }
@ -90,6 +95,12 @@ public class LoadingOverlay extends Overlay {
} }
/**
* Show for a task
*
* @param message task description
* @param task task
*/
public void show(String message, Runnable 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.");
@ -103,13 +114,4 @@ public class LoadingOverlay extends Overlay {
tt.start(T_IN); 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;
}
}

@ -2,8 +2,6 @@ package mightypork.rogue.screens.game;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.Random;
import mightypork.gamecore.app.AppAccess; import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.Action;
@ -98,7 +96,7 @@ public class ScreenGame extends LayeredScreen {
try { try {
WorldProvider.get().saveWorld(); WorldProvider.get().saveWorld();
WorldProvider.get().getWorld().getConsole().msgWorldSaved(); WorldProvider.get().getWorld().getConsole().msgWorldSaved();
} catch (Exception e) { } catch (final Exception e) {
Log.e("Could not save the world.", e); Log.e("Could not save the world.", e);
WorldProvider.get().getWorld().getConsole().msgWorldSaveError(); WorldProvider.get().getWorld().getConsole().msgWorldSaveError();
} }
@ -111,11 +109,11 @@ public class ScreenGame extends LayeredScreen {
public void execute() public void execute()
{ {
try { try {
File f = WorldProvider.get().getWorld().getSaveFile(); final File f = WorldProvider.get().getWorld().getSaveFile();
WorldProvider.get().loadWorld(f); WorldProvider.get().loadWorld(f);
WorldProvider.get().getWorld().getConsole().msgReloaded(); WorldProvider.get().getWorld().getConsole().msgReloaded();
} catch (Exception e) { } catch (final Exception e) {
Log.e("Could not load the world.", e); Log.e("Could not load the world.", e);
WorldProvider.get().getWorld().getConsole().msgLoadFailed(); WorldProvider.get().getWorld().getConsole().msgLoadFailed();
} }
@ -132,6 +130,8 @@ public class ScreenGame extends LayeredScreen {
getEventBus().send(new GameStateRequest(GameState.MAIN_MENU)); getEventBus().send(new GameStateRequest(GameState.MAIN_MENU));
} }
}; };
/** /**
* Set gui state (overlay) * Set gui state (overlay)
* *
@ -144,21 +144,21 @@ public class ScreenGame extends LayeredScreen {
if (nstate != GScrState.WORLD) { // leaving world. if (nstate != GScrState.WORLD) { // leaving world.
getEventBus().send(new WorldPauseRequest(PauseAction.PAUSE)); getEventBus().send(new WorldPauseRequest(PauseAction.PAUSE));
worldActions.enable(false); // disable world actions worldActions.setEnabled(false); // disable world actions
} }
if (nstate == GScrState.WORLD) { if (nstate == GScrState.WORLD) {
getEventBus().send(new WorldPauseRequest(PauseAction.RESUME)); getEventBus().send(new WorldPauseRequest(PauseAction.RESUME));
invLayer.setVisible(false); // hide all extra layers invLayer.setVisible(false); // hide all extra layers
invLayer.enable(false); invLayer.setEnabled(false);
worldActions.enable(true); worldActions.setEnabled(true);
} }
if (nstate == GScrState.INV) { if (nstate == GScrState.INV) {
invLayer.setVisible(true); invLayer.setVisible(true);
invLayer.enable(true); invLayer.setEnabled(true);
} }
this.state = nstate; this.state = nstate;
@ -176,15 +176,15 @@ public class ScreenGame extends LayeredScreen {
super(app); super(app);
addLayer(invLayer = new InvLayer(this)); addLayer(invLayer = new InvLayer(this));
invLayer.enable(false); invLayer.setEnabled(false);
invLayer.setVisible(false); invLayer.setVisible(false);
addLayer(hudLayer = new HudLayer(this)); addLayer(hudLayer = new HudLayer(this));
hudLayer.enable(true); hudLayer.setEnabled(true);
hudLayer.setVisible(true); hudLayer.setVisible(true);
addLayer(worldLayer = new WorldLayer(this)); addLayer(worldLayer = new WorldLayer(this));
worldLayer.enable(true); worldLayer.setEnabled(true);
worldLayer.setVisible(true); worldLayer.setVisible(true);
// TODO temporary, remove // TODO temporary, remove
@ -225,7 +225,7 @@ public class ScreenGame extends LayeredScreen {
worldActions.add(actionLoad); worldActions.add(actionLoad);
worldActions.add(actionMenu); worldActions.add(actionMenu);
worldActions.enable(true); worldActions.setEnabled(true);
// TMP TODO remove // TMP TODO remove
bindKey(new KeyStroke(Keys.X), new Runnable() { 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.LayeredScreen;
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.resources.fonts.GLFont;
import mightypork.gamecore.util.math.color.Color; import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.color.pal.PAL16; import mightypork.gamecore.util.math.color.pal.PAL16;
import mightypork.gamecore.util.math.constraints.num.Num; 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.GameStateManager.GameState;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.events.GameStateRequest; 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); layout.put(ip, r, 0, 4, 1);
r += 5; r += 5;
MenuButton btn; PushButton btn;
final GLFont btnFont = Res.getFont("thick");
// world button // world button
btn = new MenuButton("Play", PAL16.SLIMEGREEN); btn = new PushButton(btnFont, "Play", PAL16.SLIMEGREEN);
btn.setAction(new Action() { btn.setAction(new Action() {
@Override @Override
@ -99,7 +102,7 @@ public class ScreenMainMenu extends LayeredScreen {
*/ */
// quit button // quit button
btn = new MenuButton("Exit", PAL16.BLOODRED); btn = new PushButton(btnFont, "Exit", PAL16.BLOODRED);
btn.setAction(new Action() { btn.setAction(new Action() {
@Override @Override

@ -7,26 +7,21 @@ import java.io.IOException;
import mightypork.gamecore.app.AppAccess; import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.AlignX; 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.ConstraintLayout;
import mightypork.gamecore.gui.components.layout.GridLayout; import mightypork.gamecore.gui.components.layout.GridLayout;
import mightypork.gamecore.gui.components.painters.QuadPainter; 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.gui.events.ScreenRequest;
import mightypork.gamecore.logging.Log; import mightypork.gamecore.logging.Log;
import mightypork.gamecore.resources.fonts.GLFont; import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.util.Utils;
import mightypork.gamecore.util.ion.Ion; import mightypork.gamecore.util.ion.Ion;
import mightypork.gamecore.util.ion.IonBundle; import mightypork.gamecore.util.ion.IonBundle;
import mightypork.gamecore.util.math.color.pal.RGB; 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.gamecore.util.strings.StringProvider;
import mightypork.rogue.GameStateManager.GameState;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.events.GameStateRequest; import mightypork.rogue.events.LoadingOverlayRequest;
import mightypork.rogue.screens.LoaderRequest; import mightypork.rogue.screens.PushButton;
import mightypork.rogue.world.World; import mightypork.rogue.world.World;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;
@ -47,8 +42,13 @@ public class WorldSlot extends ConstraintLayout {
private IonBundle worldBundle; private IonBundle worldBundle;
private PushButton loadBtn;
public WorldSlot(AppAccess app, File worldFile) { private PushButton delBtn;
public WorldSlot(AppAccess app, File worldFile)
{
super(app); super(app);
this.file = worldFile; this.file = worldFile;
@ -60,7 +60,7 @@ public class WorldSlot extends ConstraintLayout {
@Override @Override
public double value() 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); add(qp);
final GridLayout gridl = new GridLayout(app, 1, 8); 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); add(gridl);
TextPainter tp;
ClickableWrapper btn;
final GLFont font = Res.getFont("thick"); final GLFont font = Res.getFont("thick");
tp = new TextPainter(font, AlignX.LEFT, RGB.WHITE, lblStrp); gridl.put(loadBtn = new PushButton(font, "", RGB.WHITE), 0, 0, 1, 7);
tp.setPaddingHPerc(0, 20); 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); loadBtn.setAction(new Action() {
btn.setAction(new Action() {
@Override @Override
protected void execute() protected void execute()
@ -92,7 +94,7 @@ public class WorldSlot extends ConstraintLayout {
msg = "Creating world..."; msg = "Creating world...";
} }
getEventBus().send(new LoaderRequest(msg, new Runnable() { getEventBus().send(new LoadingOverlayRequest(msg, new Runnable() {
@Override @Override
public void run() public void run()
@ -109,7 +111,7 @@ public class WorldSlot extends ConstraintLayout {
getEventBus().send(new ScreenRequest("game")); getEventBus().send(new ScreenRequest("game"));
} catch (Exception e) { } catch (final Exception e) {
Log.e("Could not create & save the world.", e); Log.e("Could not create & save the world.", e);
} }
@ -123,7 +125,7 @@ public class WorldSlot extends ConstraintLayout {
getEventBus().send(new ScreenRequest("game")); getEventBus().send(new ScreenRequest("game"));
} catch (IOException e) { } catch (final IOException e) {
Log.e("Could not load the world.", 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"); gridl.put(delBtn = new PushButton(font, "X", RGB.RED), 0, 7, 1, 1);
tp.setPaddingHPerc(0, 20); delBtn.textPainter.setPaddingHPerc(0, 20);
gridl.put(btn = new ClickableWrapper(tp), 0, 7, 1, 1); delBtn.textPainter.setAlign(AlignX.RIGHT);
btn.setAction(new Action() { delBtn.disableHover();
delBtn.setAction(new Action() {
@Override @Override
protected void execute() protected void execute()
@ -153,6 +157,9 @@ public class WorldSlot extends ConstraintLayout {
public void refresh() public void refresh()
{ {
delBtn.setVisible(false);
delBtn.setEnabled(false);
if (!file.exists()) { if (!file.exists()) {
label = "<empty>"; label = "<empty>";
} else { } else {
@ -162,7 +169,10 @@ public class WorldSlot extends ConstraintLayout {
if (lvl == -1) throw new RuntimeException(); // let the catch block handle it 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) { } catch (final IOException e) {
label = "<corrupt>"; label = "<corrupt>";
} }

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

@ -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 * @author MightyPork
*/ */
@ -80,8 +80,8 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
in.loadBundled("player", playerData); in.loadBundled("player", playerData);
int eid = playerData.getEID(); final int eid = playerData.getEID();
int lvl = playerData.getLevelNumber(); final int lvl = playerData.getLevelNumber();
playerEntity = levels.get(lvl).getEntity(eid); playerEntity = levels.get(lvl).getEntity(eid);
if (playerEntity == null) { if (playerEntity == null) {
@ -89,7 +89,7 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
Log.e("Player entity not found in the world: " + eid + " on floor " + lvl); Log.e("Player entity not found in the world: " + eid + " on floor " + lvl);
for (int i = 0; i < levels.size(); i++) { for (int i = 0; i < levels.size(); i++) {
Entity ent = levels.get(i).getEntity(eid); final Entity ent = levels.get(i).getEntity(eid);
if (ent != null) { if (ent != null) {
Log.f3("Player entity was really on floor: " + i); 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() public WorldConsole getConsole()
{ {
return console; return console;
} }
/**
* Set file for saving
*
* @param file save file
*/
public void setSaveFile(File file) public void setSaveFile(File file)
{ {
this.saveFile = file; this.saveFile = file;
} }
/**
* @return assigned file fro saving
*/
public File getSaveFile() public File getSaveFile()
{ {
return saveFile; return saveFile;

@ -34,7 +34,8 @@ public class WorldConsole implements Updateable {
private double elapsed = 0; private double elapsed = 0;
private Entry(String text) { private Entry(String text)
{
this.text = text; this.text = text;
this.fadeout = new NumAnimated(1, Easing.LINEAR); this.fadeout = new NumAnimated(1, Easing.LINEAR);
this.fadeout.setDefaultDuration(0.5); this.fadeout.setDefaultDuration(0.5);

@ -11,6 +11,11 @@ import mightypork.rogue.world.gen.WorldCreator;
import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.Level;
/**
* Global singleton world holder and storage
*
* @author MightyPork
*/
public class WorldProvider extends RootBusNode { public class WorldProvider extends RootBusNode {
public static synchronized void init(BusAccess busAccess) 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); super(busAccess);
setListening(false); 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) public World createWorld(long seed)
{ {
World w = WorldCreator.createWorld(seed); final World w = WorldCreator.createWorld(seed);
setWorld(w); setWorld(w);
return w; return w;
} }
/**
* Destroy world, set to null.
*/
public void destroyWorld() public void destroyWorld()
{ {
setWorld(null); 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 public void saveWorld() throws IOException
{ {
saveWorld(world.getSaveFile()); 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.rect.proxy.RectProxy;
import mightypork.gamecore.util.math.constraints.vect.Vect; import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.gamecore.util.math.constraints.vect.VectConst; import mightypork.gamecore.util.math.constraints.vect.VectConst;
import mightypork.rogue.Config;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.Level;
@ -107,13 +108,11 @@ public class WorldRenderer extends RectProxy {
if (USE_BATCH_RENDERING) { if (USE_BATCH_RENDERING) {
Render.enterBatchTexturedQuadMode(Res.getTexture("tiles")); Render.enterBatchTexturedQuadMode(Res.getTexture("tiles"));
} }
for (trc.pos.x = x1; trc.pos.x <= x2; trc.pos.x++) { for (trc.pos.x = x1; trc.pos.x <= x2; trc.pos.x++) {
for (trc.pos.y = y1; trc.pos.y <= y2; trc.pos.y++) { for (trc.pos.y = y1; trc.pos.y <= y2; trc.pos.y++) {
trc.renderTile(); trc.renderTile();
} }
} }
if (USE_BATCH_RENDERING) { if (USE_BATCH_RENDERING) {
Render.leaveBatchTexturedQuadMode(); Render.leaveBatchTexturedQuadMode();
} }
@ -141,10 +140,26 @@ public class WorldRenderer extends RectProxy {
e.render(trc); 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 === // === OVERLAY SHADOW ===
Render.popMatrix();
Render.quadGradH(leftShadow, RGB.BLACK, RGB.NONE); Render.quadGradH(leftShadow, RGB.BLACK, RGB.NONE);
Render.quadGradH(rightShadow, RGB.NONE, RGB.BLACK); Render.quadGradH(rightShadow, RGB.NONE, RGB.BLACK);

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

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

@ -2,7 +2,6 @@ package mightypork.rogue.world.entity;
import java.io.IOException; import java.io.IOException;
import java.util.Random;
import mightypork.gamecore.eventbus.events.Updateable; import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.util.annot.DefaultImpl; 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 * @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(); public abstract boolean isModuleSaved();

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

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

@ -8,5 +8,10 @@ package mightypork.rogue.world.entity;
*/ */
public enum EntityType 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); healTimer.update(delta);
} }
@Override @Override
protected double getStepTime() protected double getStepTime()
{ {

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

@ -76,7 +76,8 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
private int preyId = -1; private int preyId = -1;
public MonsterAi(final Entity entity) { public MonsterAi(final Entity entity)
{
super(entity); super(entity);
noDoorPf = new PathFinderProxy(entity.getPathFinder()) { noDoorPf = new PathFinderProxy(entity.getPathFinder()) {
@ -191,12 +192,12 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
} }
public boolean isChasing() public boolean isChasing()
{ {
return chasing; return chasing;
} }
private void lookForTarget() private void lookForTarget()
{ {
if (entity.isDead()) return; if (entity.isDead()) return;
@ -340,6 +341,7 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
return 1; // For override return 1; // For override
} }
@DefaultImpl @DefaultImpl
protected double getStepTime() protected double getStepTime()
{ {

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

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

@ -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.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.Config;
import mightypork.rogue.world.PlayerFacade; import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.level.Level; 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) { for (pos.x = 0, point.x = tl.xi(); pos.x < lw; pos.x++, point.x += unit) {
final Tile t = lvl.getTile(pos); 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(); final Color clr = t.getMapColor();

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

@ -2,7 +2,6 @@ package mightypork.rogue.world.item;
import java.io.IOException; import java.io.IOException;
import java.util.Random;
import mightypork.gamecore.util.ion.IonInput; import mightypork.gamecore.util.ion.IonInput;
import mightypork.gamecore.util.ion.IonOutput; 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.World;
import mightypork.rogue.world.entity.Entities; import mightypork.rogue.world.entity.Entities;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityPathFinder;
import mightypork.rogue.world.entity.EntityType; import mightypork.rogue.world.entity.EntityType;
import mightypork.rogue.world.entity.impl.PlayerEntity; import mightypork.rogue.world.entity.impl.PlayerEntity;
import mightypork.rogue.world.item.Item; import mightypork.rogue.world.item.Item;
@ -124,11 +123,13 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
private double timeSinceLastEntitySort; private double timeSinceLastEntitySort;
public Level() { public Level()
{
} }
public Level(int width, int height) { public Level(int width, int height)
{
size.setTo(width, height); size.setTo(width, height);
buildArray(); buildArray();
} }

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

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

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

Loading…
Cancel
Save