v5stable
Ondřej Hruška 11 years ago
parent 4e1d89d3ca
commit 2b8055d1d2
  1. BIN
      res/img/logo.png
  2. BIN
      res/img/logo.xcf
  3. 5
      src/mightypork/gamecore/core/MainLoop.java
  4. 8
      src/mightypork/gamecore/gui/components/painters/ImagePainter.java
  5. 45
      src/mightypork/gamecore/gui/screens/LayeredScreen.java
  6. 19
      src/mightypork/gamecore/gui/screens/Overlay.java
  7. 2
      src/mightypork/gamecore/gui/screens/Screen.java
  8. 7
      src/mightypork/gamecore/gui/screens/ScreenLayer.java
  9. 5
      src/mightypork/gamecore/gui/screens/impl/CrossfadeOverlay.java
  10. 3
      src/mightypork/gamecore/gui/screens/impl/CrossfadeRequest.java
  11. 149
      src/mightypork/gamecore/gui/screens/impl/FadingLayer.java
  12. 4
      src/mightypork/gamecore/gui/screens/impl/LayerColor.java
  13. 29
      src/mightypork/gamecore/input/InputSystem.java
  14. 7
      src/mightypork/gamecore/render/TaskTakeScreenshot.java
  15. 3
      src/mightypork/gamecore/resources/AsyncResourceLoader.java
  16. 4
      src/mightypork/gamecore/resources/textures/QuadGrid.java
  17. 4
      src/mightypork/gamecore/resources/textures/TxQuad.java
  18. 8
      src/mightypork/gamecore/util/Utils.java
  19. 2
      src/mightypork/gamecore/util/math/color/Color.java
  20. 37
      src/mightypork/gamecore/util/math/constraints/num/mutable/NumAnimated.java
  21. 19
      src/mightypork/rogue/RogueApp.java
  22. 7
      src/mightypork/rogue/RogueResources.java
  23. 8
      src/mightypork/rogue/RogueStateManager.java
  24. 8
      src/mightypork/rogue/screens/game/HeartBar.java
  25. 48
      src/mightypork/rogue/screens/game/LayerAskSave.java
  26. 18
      src/mightypork/rogue/screens/game/LayerDeath.java
  27. 7
      src/mightypork/rogue/screens/game/LayerGameUi.java
  28. 33
      src/mightypork/rogue/screens/game/LayerInv.java
  29. 6
      src/mightypork/rogue/screens/game/LayerMapView.java
  30. 84
      src/mightypork/rogue/screens/game/LayerWin.java
  31. 141
      src/mightypork/rogue/screens/game/ScreenGame.java
  32. 14
      src/mightypork/rogue/screens/menu/ScreenMainMenu.java
  33. 260
      src/mightypork/rogue/screens/story/ScreenStory.java
  34. 25
      src/mightypork/rogue/world/World.java
  35. 15
      src/mightypork/rogue/world/WorldProvider.java
  36. 4
      src/mightypork/rogue/world/entity/Entities.java
  37. 5
      src/mightypork/rogue/world/entity/impl/EntityBossRat.java
  38. 7
      src/mightypork/rogue/world/entity/impl/EntityPlayer.java
  39. 14
      src/mightypork/rogue/world/events/GameWinEvent.java
  40. 8
      src/mightypork/rogue/world/events/GameWinHandler.java
  41. 6
      src/mightypork/rogue/world/events/PlayerStepEndEvent.java
  42. 4
      src/mightypork/rogue/world/events/PlayerStepEndListener.java
  43. 2
      src/mightypork/rogue/world/gui/WorldConsoleRenderer.java
  44. 26
      src/mightypork/rogue/world/gui/interaction/MIPKeyboard.java
  45. 4
      src/mightypork/rogue/world/gui/interaction/MIPMouse.java
  46. 8
      src/mightypork/rogue/world/level/Level.java

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

@ -105,6 +105,11 @@ public class MainLoop extends AppModule implements ScreenshotRequestListener {
} }
/**
* Add a task to queue to be executed in the main loop (OpenGL thread)
*
* @param request task
*/
public synchronized void queueTask(Runnable request) public synchronized void queueTask(Runnable request)
{ {
taskQueue.add(request); taskQueue.add(request);

@ -14,7 +14,7 @@ import mightypork.gamecore.resources.textures.TxQuad;
*/ */
public class ImagePainter extends BaseComponent implements DynamicWidthComponent { public class ImagePainter extends BaseComponent implements DynamicWidthComponent {
private final TxQuad txQuad; private TxQuad txQuad;
/** /**
@ -38,4 +38,10 @@ public class ImagePainter extends BaseComponent implements DynamicWidthComponent
{ {
return (height / txQuad.uvs.height().value()) * txQuad.uvs.width().value(); return (height / txQuad.uvs.height().value()) * txQuad.uvs.width().value();
} }
public void setTxQuad(TxQuad txQuad)
{
this.txQuad = txQuad;
}
} }

@ -1,9 +1,11 @@
package mightypork.gamecore.gui.screens; package mightypork.gamecore.gui.screens;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.TreeSet; import java.util.List;
import mightypork.gamecore.core.AppAccess; import mightypork.gamecore.core.AppAccess;
import mightypork.gamecore.eventbus.clients.DelegatingClient; import mightypork.gamecore.eventbus.clients.DelegatingClient;
@ -39,25 +41,8 @@ public abstract class LayeredScreen extends Screen {
} }
private final Collection<ScreenLayer> layersByZIndex = new TreeSet<>(new Comparator<Overlay>() { private final List<ScreenLayer> layersByZIndex = new ArrayList<>();
private final List<ScreenLayer> layersByEventPriority = new ArrayList<>();
@Override
public int compare(Overlay o1, Overlay o2)
{
return o1.getZIndex() - o2.getZIndex();
}
});
private final Collection<ScreenLayer> layersByEventPriority = new TreeSet<>(new Comparator<Overlay>() {
@Override
public int compare(Overlay o1, Overlay o2)
{
return o2.getEventPriority() - o1.getEventPriority();
}
});
private final LayersClient layersClient = new LayersClient(); private final LayersClient layersClient = new LayersClient();
@ -90,6 +75,26 @@ public abstract class LayeredScreen extends Screen {
{ {
this.layersByZIndex.add(layer); this.layersByZIndex.add(layer);
this.layersByEventPriority.add(layer); this.layersByEventPriority.add(layer);
Collections.sort(layersByEventPriority, new Comparator<Overlay>() {
@Override
public int compare(Overlay o1, Overlay o2)
{
return o2.getEventPriority() - o1.getEventPriority();
}
});
Collections.sort(layersByZIndex, new Comparator<Overlay>() {
@Override
public int compare(Overlay o1, Overlay o2)
{
return o1.getZIndex() - o2.getZIndex();
}
});
} }

@ -1,6 +1,7 @@
package mightypork.gamecore.gui.screens; package mightypork.gamecore.gui.screens;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
@ -43,10 +44,10 @@ public abstract class Overlay extends AppSubModule implements Comparable<Overlay
protected final Vect mouse; protected final Vect mouse;
/** Extra rendered items (outside root) */ /** Extra rendered items (outside root) */
protected final Collection<Renderable> rendered = new LinkedHashSet<>(); protected final Collection<Renderable> rendered = new ArrayList<>();
/** 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 ArrayList<>();
private Num alphaMul = Num.ONE; private Num alphaMul = Num.ONE;
@ -208,4 +209,18 @@ public abstract class Overlay extends AppSubModule implements Comparable<Overlay
setVisible(false); setVisible(false);
setEnabled(false); setEnabled(false);
} }
@Override
public boolean isListening()
{
return (isVisible() || isEnabled());
}
@Override
public boolean doesDelegate()
{
return isListening();
}
} }

@ -22,7 +22,7 @@ import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
* *
* @author MightyPork * @author MightyPork
*/ */
public abstract class Screen extends AppSubModule implements Renderable, RectBound, AppAccess, KeyBinder, LayoutChangeListener { public abstract class Screen extends AppSubModule implements Renderable, RectBound, KeyBinder, LayoutChangeListener {
private final KeyBindingPool keybindings = new KeyBindingPool(); private final KeyBindingPool keybindings = new KeyBindingPool();

@ -50,11 +50,4 @@ public abstract class ScreenLayer extends Overlay {
protected void onScreenLeave() protected void onScreenLeave()
{ {
} }
@Override
public boolean isListening()
{
return (isVisible() || isEnabled()) && super.isListening();
}
} }

@ -12,6 +12,11 @@ import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated;
import mightypork.gamecore.util.math.timing.TimedTask; import mightypork.gamecore.util.math.timing.TimedTask;
/**
* Overlay used for cross-fading between screens
*
* @author MightyPork
*/
public class CrossfadeOverlay extends Overlay { public class CrossfadeOverlay extends Overlay {
private static final double T_IN = 0.4; private static final double T_IN = 0.4;

@ -1,9 +1,8 @@
package mightypork.gamecore.gui.events; package mightypork.gamecore.gui.screens.impl;
import mightypork.gamecore.eventbus.BusEvent; import mightypork.gamecore.eventbus.BusEvent;
import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent; import mightypork.gamecore.eventbus.event_flags.SingleReceiverEvent;
import mightypork.gamecore.gui.screens.impl.CrossfadeOverlay;
/** /**

@ -0,0 +1,149 @@
package mightypork.gamecore.gui.screens.impl;
import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.util.math.Easing;
import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated;
import mightypork.gamecore.util.math.timing.TimedTask;
/**
* Layer that smoothly appears/disappears when shown/hidden
*
* @author MightyPork
*/
public abstract class FadingLayer extends ScreenLayer {
private final NumAnimated numa;
private final TimedTask hideTimer = new TimedTask() {
@Override
public void run()
{
FadingLayer.super.hide();
fadingOut = false;
onHideFinished();
}
};
private final TimedTask showTimer = new TimedTask() {
@Override
public void run()
{
fadingIn = false;
onShowFinished();
}
};
private boolean fadingIn = false;
private boolean fadingOut = false;
/**
* Create with default fading time and effect
*
* @param screen
*/
public FadingLayer(Screen screen)
{
this(screen, new NumAnimated(1, Easing.QUADRATIC_OUT, 0.3));
}
/**
* @param screen
* @param easingAnim the animation num
*/
public FadingLayer(Screen screen, NumAnimated easingAnim)
{
super(screen);
numa = easingAnim;
updated.add(numa);
updated.add(hideTimer);
updated.add(showTimer);
setAlpha(numa);
}
/**
* Called after the fade-out was completed
*/
protected void onHideFinished()
{
}
/**
* Called after the fade-in was completed
*/
protected void onShowFinished()
{
}
/**
* Show with fading
*/
@Override
public void show()
{
if (fadingIn) return;
if (!isVisible() || fadingOut) {
super.show();
numa.fadeIn();
hideTimer.stop();
fadingOut = false;
fadingIn = true;
}
}
/**
* Hide without fading
*/
public void hideImmediate()
{
hideTimer.stop();
numa.setTo(0);
super.hide();
onHideFinished();
}
/**
* Show without fading
*/
public void showImmediate()
{
hideTimer.stop();
numa.setTo(1);
super.show();
onShowFinished();
}
/**
* Hide with fading
*/
@Override
public void hide()
{
if (fadingOut) return;
if (isVisible()) {
numa.fadeOut();
hideTimer.start(numa.getDefaultDuration());
fadingOut = true;
fadingIn = false;
}
}
}

@ -16,7 +16,9 @@ public class LayerColor extends ScreenLayer {
{ {
super(screen); super(screen);
root.add(new QuadPainter(color)); QuadPainter qp = new QuadPainter(color);
qp.setRect(root);
root.add(qp);
this.zIndex = zIndex; this.zIndex = zIndex;
} }

@ -26,8 +26,7 @@ import org.lwjgl.opengl.Display;
*/ */
public class InputSystem extends RootBusNode implements Updateable, KeyBinder { public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
// listeners private static boolean inited = false;
private final KeyBindingPool keybindings;
/** Current mouse position */ /** Current mouse position */
private static final Vect mousePos = new Vect() { private static final Vect mousePos = new Vect() {
@ -50,7 +49,10 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
} }
}; };
private static boolean inited = false; private final KeyBindingPool keybindings;
private final VectVar mouseMove = Vect.makeVar();
private final VectVar mouseLastPos = Vect.makeVar();
/** /**
@ -106,15 +108,11 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
keybindings.unbindKey(stroke); keybindings.unbindKey(stroke);
} }
// counters as fields to save memory.
private final VectVar mouseMove = Vect.makeVar();
private final VectVar mouseLastPos = Vect.makeVar();
@Override @Override
public synchronized void update(double delta) public synchronized void update(double delta)
{ {
// was destroyed // was destroyed or not initialized
if (!Display.isCreated()) return; if (!Display.isCreated()) return;
if (!Mouse.isCreated()) return; if (!Mouse.isCreated()) return;
if (!Keyboard.isCreated()) return; if (!Keyboard.isCreated()) return;
@ -208,12 +206,24 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
} }
/**
* Check if key is down
*
* @param key key to check (constant from the {@link Keys} class)
* @return is down
*/
public static boolean isKeyDown(int key) public static boolean isKeyDown(int key)
{ {
return Keyboard.isKeyDown(key); return Keyboard.isKeyDown(key);
} }
/**
* Check mouse button state
*
* @param button button to test (0 left, 1 right, 2 middle)
* @return button is down
*/
public static boolean isMouseButtonDown(int button) public static boolean isMouseButtonDown(int button)
{ {
return Mouse.isButtonDown(button); return Mouse.isButtonDown(button);
@ -247,6 +257,9 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
} }
/**
* @return true if the system is initialized
*/
public static boolean isReady() public static boolean isReady()
{ {
return inited; return inited;

@ -3,12 +3,10 @@ package mightypork.gamecore.render;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import mightypork.gamecore.WorkDir; import mightypork.gamecore.WorkDir;
import mightypork.gamecore.logging.Log; import mightypork.gamecore.logging.Log;
import mightypork.gamecore.util.Utils;
import org.newdawn.slick.opengl.GLUtils; import org.newdawn.slick.opengl.GLUtils;
@ -28,8 +26,7 @@ public class TaskTakeScreenshot implements Runnable {
@Override @Override
public void run() public void run()
{ {
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss"); final String fname = Utils.getTime("yyyy-MM-dd_HH-mm-ss");
final String fname = df.format(new Date());
// generate unique filename // generate unique filename
File file; File file;

@ -42,9 +42,6 @@ public class AsyncResourceLoader extends Thread implements ResourceLoader, Destr
} }
/**
* @param app app acceess
*/
public AsyncResourceLoader() public AsyncResourceLoader()
{ {
super("Deferred loader"); super("Deferred loader");

@ -35,7 +35,7 @@ public class QuadGrid {
* @param y y coordinate (cells) * @param y y coordinate (cells)
* @return the quad * @return the quad
*/ */
public TxQuad makeQuad(int x, int y) public TxQuad makeQuad(double x, double y)
{ {
if (x < 0 || x >= txWidth || y < 0 || y >= txHeight) { if (x < 0 || x >= txWidth || y < 0 || y >= txHeight) {
throw new IndexOutOfBoundsException("Requested invalid txquad coordinates."); throw new IndexOutOfBoundsException("Requested invalid txquad coordinates.");
@ -78,7 +78,7 @@ public class QuadGrid {
* @param height height (cells) * @param height height (cells)
* @return the sheet * @return the sheet
*/ */
public TxSheet makeSheet(int x, int y, int width, int height) public TxSheet makeSheet(double x, double y, double width, double height)
{ {
if (x < 0 || x >= txWidth || y < 0 || y >= txHeight) { if (x < 0 || x >= txWidth || y < 0 || y >= txHeight) {
throw new IndexOutOfBoundsException("Requested invalid txquad coordinates."); throw new IndexOutOfBoundsException("Requested invalid txquad coordinates.");

@ -114,9 +114,9 @@ public class TxQuad {
* @param height sheet height * @param height sheet height
* @return sheet * @return sheet
*/ */
public TxSheet makeSheet(int width, int height) public TxSheet makeSheet(double width, double height)
{ {
return new TxSheet(this, width, height); return new TxSheet(this, (int) Math.round(width), (int) Math.round(height));
} }

@ -2,6 +2,8 @@ package mightypork.gamecore.util;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.text.SimpleDateFormat;
import java.util.Date;
/** /**
@ -45,4 +47,10 @@ public final class Utils {
return null; // all null return null; // all null
} }
public static String getTime(String format)
{
return (new SimpleDateFormat(format)).format(new Date());
}
} }

@ -242,6 +242,6 @@ public abstract class Color {
public Color withAlpha(Num multiplier) public Color withAlpha(Num multiplier)
{ {
return new ColorAlphaAdjuster(this, Num.make(multiplier)); return new ColorAlphaAdjuster(this, multiplier);
} }
} }

@ -37,11 +37,11 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable {
protected Easing easingIn = Easing.LINEAR; protected Easing easingIn = Easing.LINEAR;
/** Default duration (seconds) */ /** Default duration (seconds) */
private double defaultDuration = 0; private double defaultDuration = 1;
/** /**
* Create linear animator * With linear easing
* *
* @param value initial value * @param value initial value
*/ */
@ -78,6 +78,37 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable {
} }
/**
* Create animator with easing
*
* @param value initial value
* @param easing easing function
* @param defaultDuration default fade duration
*/
public NumAnimated(double value, Easing easing, double defaultDuration)
{
this(value);
setEasing(easing);
setDefaultDuration(defaultDuration);
}
/**
* Create animator with easing
*
* @param value initial value
* @param easingIn easing function (fade in)
* @param easingOut easing function (fade out)
* @param defaultDuration default fade duration
*/
public NumAnimated(double value, Easing easingIn, Easing easingOut, double defaultDuration)
{
this(value);
setEasing(easingIn, easingOut);
setDefaultDuration(defaultDuration);
}
/** /**
* Create as copy of another * Create as copy of another
* *
@ -228,7 +259,7 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable {
{ {
from = to = value; from = to = value;
elapsedTime = 0; elapsedTime = 0;
duration = defaultDuration; duration = 0;
} }

@ -9,13 +9,16 @@ import mightypork.gamecore.core.events.MainLoopRequest;
import mightypork.gamecore.core.events.UserQuitRequest; import mightypork.gamecore.core.events.UserQuitRequest;
import mightypork.gamecore.eventbus.BusEvent; import mightypork.gamecore.eventbus.BusEvent;
import mightypork.gamecore.gui.screens.ScreenRegistry; import mightypork.gamecore.gui.screens.ScreenRegistry;
import mightypork.gamecore.gui.screens.impl.CrossfadeRequest;
import mightypork.gamecore.input.InputSystem; import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.input.KeyStroke.Edge; import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.render.DisplaySystem; import mightypork.gamecore.render.DisplaySystem;
import mightypork.gamecore.render.events.FullscreenToggleRequest; import mightypork.gamecore.render.events.FullscreenToggleRequest;
import mightypork.gamecore.render.events.ScreenshotRequest; import mightypork.gamecore.render.events.ScreenshotRequest;
import mightypork.gamecore.render.events.ScreenshotRequestListener;
import mightypork.gamecore.render.events.ViewportChangeEvent; import mightypork.gamecore.render.events.ViewportChangeEvent;
import mightypork.gamecore.render.events.ViewportChangeListener; import mightypork.gamecore.render.events.ViewportChangeListener;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.util.ion.Ion; import mightypork.gamecore.util.ion.Ion;
import mightypork.rogue.RogueStateManager.RogueState; import mightypork.rogue.RogueStateManager.RogueState;
import mightypork.rogue.events.RogueStateRequest; import mightypork.rogue.events.RogueStateRequest;
@ -24,6 +27,7 @@ import mightypork.rogue.screens.LoadingOverlay;
import mightypork.rogue.screens.game.ScreenGame; import mightypork.rogue.screens.game.ScreenGame;
import mightypork.rogue.screens.menu.ScreenMainMenu; import mightypork.rogue.screens.menu.ScreenMainMenu;
import mightypork.rogue.screens.select_world.ScreenSelectWorld; import mightypork.rogue.screens.select_world.ScreenSelectWorld;
import mightypork.rogue.screens.story.ScreenStory;
import mightypork.rogue.world.Inventory; import mightypork.rogue.world.Inventory;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.Level;
@ -34,7 +38,7 @@ import mightypork.rogue.world.level.Level;
* *
* @author MightyPork * @author MightyPork
*/ */
public final class RogueApp extends BaseApp implements ViewportChangeListener { public final class RogueApp extends BaseApp implements ViewportChangeListener, ScreenshotRequestListener {
public RogueApp(File workdir, boolean singleInstance) public RogueApp(File workdir, boolean singleInstance)
{ {
@ -86,6 +90,7 @@ public final class RogueApp extends BaseApp implements ViewportChangeListener {
screens.addScreen("main_menu", new ScreenMainMenu(this)); screens.addScreen("main_menu", new ScreenMainMenu(this));
screens.addScreen("select_world", new ScreenSelectWorld(this)); screens.addScreen("select_world", new ScreenSelectWorld(this));
screens.addScreen("game", new ScreenGame(this)); screens.addScreen("game", new ScreenGame(this));
screens.addScreen("story", new ScreenStory(this));
screens.addOverlay(new FpsOverlay(this)); screens.addOverlay(new FpsOverlay(this));
screens.addOverlay(new LoadingOverlay(this)); screens.addOverlay(new LoadingOverlay(this));
@ -124,8 +129,8 @@ public final class RogueApp extends BaseApp implements ViewportChangeListener {
@Override @Override
public void run() public void run()
{ {
getEventBus().send(new RogueStateRequest(RogueState.MAIN_MENU)); //getEventBus().send(new RogueStateRequest(RogueState.MAIN_MENU));
//getEventBus().send(new CrossfadeRequest("test.layout", true)); getEventBus().send(new CrossfadeRequest("story", true));
} }
})); }));
} }
@ -144,4 +149,12 @@ public final class RogueApp extends BaseApp implements ViewportChangeListener {
Config.setValue("display.height", DisplaySystem.getHeight()); Config.setValue("display.height", DisplaySystem.getHeight());
} }
} }
@Override
public void onScreenshotRequest()
{
// screenshot sound
Res.getSoundEffect("gui.shutter").play(0.8);
}
} }

@ -99,6 +99,13 @@ public class RogueResources implements ResourceSetup {
textures.add("logo", texture.makeQuad(Rect.make(0, 0, 0.543, 0.203))); textures.add("logo", texture.makeQuad(Rect.make(0, 0, 0.543, 0.203)));
grid = texture.grid(8, 8); grid = texture.grid(8, 8);
textures.add("death", grid.makeQuad(0, 2)); textures.add("death", grid.makeQuad(0, 2));
textures.add("death2", grid.makeQuad(1, 2, 1.5, 1));
textures.add("win", grid.makeQuad(2.5, 2, 1.5, 1));
grid = texture.grid(8, 4);
textures.add("story_1", grid.makeQuad(0, 2, 3, 1));
textures.add("story_2", grid.makeQuad(3, 2, 3, 1));
textures.add("story_3", grid.makeQuad(0, 3, 3, 1));
// tiles // tiles

@ -3,7 +3,7 @@ package mightypork.rogue;
import mightypork.gamecore.core.AppAccess; import mightypork.gamecore.core.AppAccess;
import mightypork.gamecore.core.AppModule; import mightypork.gamecore.core.AppModule;
import mightypork.gamecore.gui.events.CrossfadeRequest; import mightypork.gamecore.gui.screens.impl.CrossfadeRequest;
import mightypork.gamecore.logging.Log; import mightypork.gamecore.logging.Log;
@ -16,7 +16,7 @@ public class RogueStateManager extends AppModule {
public static enum RogueState public static enum RogueState
{ {
MAIN_MENU, SELECT_WORLD, PLAY_WORLD, EXIT MAIN_MENU, SELECT_WORLD, PLAY_WORLD, EXIT, STORY
} }
@ -35,6 +35,10 @@ public class RogueStateManager extends AppModule {
getEventBus().send(new CrossfadeRequest("game")); getEventBus().send(new CrossfadeRequest("game"));
break; break;
case STORY:
getEventBus().send(new CrossfadeRequest("story"));
break;
case EXIT: case EXIT:
getEventBus().send(new CrossfadeRequest(null)); getEventBus().send(new CrossfadeRequest(null));
break; break;

@ -22,14 +22,6 @@ public class HeartBar extends BaseComponent {
private final Rect heart; private final Rect heart;
/**
* @param total
* @param active
* @param img_on
* @param img_half
* @param img_off
* @param align
*/
public HeartBar(Num total, Num active, TxQuad img_on, TxQuad img_half, TxQuad img_off, AlignX align) public HeartBar(Num total, Num active, TxQuad img_on, TxQuad img_half, TxQuad img_off, AlignX align)
{ {
super(); super();

@ -11,34 +11,21 @@ import mightypork.gamecore.gui.components.layout.RowLayout;
import mightypork.gamecore.gui.components.layout.linear.LinearLayout; import mightypork.gamecore.gui.components.layout.linear.LinearLayout;
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.screens.ScreenLayer; import mightypork.gamecore.gui.screens.impl.FadingLayer;
import mightypork.gamecore.input.KeyStroke.Edge; import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.logging.Log; import mightypork.gamecore.logging.Log;
import mightypork.gamecore.resources.Res; import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.fonts.GLFont; import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.util.math.Easing;
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.num.mutable.NumAnimated;
import mightypork.gamecore.util.math.timing.TimedTask;
import mightypork.rogue.screens.game.ScreenGame.GScrState; import mightypork.rogue.screens.game.ScreenGame.GScrState;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;
public class AskSaveLayer extends ScreenLayer { public class LayerAskSave extends FadingLayer {
public Runnable task; public Runnable task;
NumAnimated numa = new NumAnimated(0, Easing.QUADRATIC_OUT);
TimedTask hideTT = new TimedTask() {
@Override
public void run()
{
gscreen.setState(GScrState.WORLD); // go back..
}
};
private final ScreenGame gscreen; private final ScreenGame gscreen;
@ -48,7 +35,16 @@ public class AskSaveLayer extends ScreenLayer {
} }
public AskSaveLayer(final ScreenGame screen) @Override
protected void onHideFinished()
{
if (gscreen.getState() != GScrState.WORLD) {
gscreen.setState(GScrState.WORLD); // go back..
}
}
public LayerAskSave(final ScreenGame screen)
{ {
super(screen); super(screen);
this.gscreen = screen; this.gscreen = screen;
@ -95,10 +91,7 @@ public class AskSaveLayer extends ScreenLayer {
@Override @Override
protected void execute() protected void execute()
{ {
if (numa.isFinished()) { hide();
numa.fadeOut(0.3);
hideTT.start(0.3);
}
} }
}; };
@ -136,28 +129,19 @@ public class AskSaveLayer extends ScreenLayer {
bindKey(Config.getKey("general.confirm"), Edge.RISING, save); bindKey(Config.getKey("general.confirm"), Edge.RISING, save);
bindKey(Config.getKey("general.no"), Edge.RISING, discard); bindKey(Config.getKey("general.no"), Edge.RISING, discard);
updated.add(numa);
updated.add(hideTT);
setAlpha(numa);
} }
@Override @Override
public int getZIndex() public int getZIndex()
{ {
return 301; return 300;
} }
@Override @Override
public void show() public void update(double delta)
{ {
if (!isVisible()) { super.update(delta);
super.show();
numa.fadeIn(0.3);
hideTT.stop();
}
} }
} }

@ -13,7 +13,7 @@ import mightypork.gamecore.gui.components.layout.linear.LinearLayout;
import mightypork.gamecore.gui.components.painters.ImagePainter; import mightypork.gamecore.gui.components.painters.ImagePainter;
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.screens.ScreenLayer; import mightypork.gamecore.gui.screens.impl.FadingLayer;
import mightypork.gamecore.input.KeyStroke.Edge; import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.logging.Log; import mightypork.gamecore.logging.Log;
import mightypork.gamecore.resources.Res; import mightypork.gamecore.resources.Res;
@ -26,9 +26,9 @@ import mightypork.rogue.screens.game.ScreenGame.GScrState;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;
public class DeathLayer extends ScreenLayer { public class LayerDeath extends FadingLayer {
public DeathLayer(final ScreenGame screen) public LayerDeath(final ScreenGame screen)
{ {
super(screen); super(screen);
@ -40,15 +40,15 @@ public class DeathLayer extends ScreenLayer {
final GLFont thick_font = Res.getFont("thick"); final GLFont thick_font = Res.getFont("thick");
final RowLayout rl = new RowLayout(root, 5); final RowLayout rl = new RowLayout(root, 5);
rl.setRect(root.shrink(Num.ZERO, root.height().perc(20))); rl.setRect(root.shrink(Num.ZERO, root.height().perc(15)));
root.add(rl); root.add(rl);
final TextPainter txp = new TextPainter(thick_font, AlignX.CENTER, RGB.YELLOW, "You're dead!"); final TextPainter txp = new TextPainter(thick_font, AlignX.CENTER, RGB.YELLOW, "Rats won!");
rl.add(txp, 1); rl.add(txp, 1);
txp.setVPaddingPercent(15); txp.setVPaddingPercent(13);
LinearLayout linl = new LinearLayout(root, AlignX.CENTER); LinearLayout linl = new LinearLayout(root, AlignX.CENTER);
linl.add(new ImagePainter(Res.getTxQuad("death"))); linl.add(new ImagePainter(Res.getTxQuad("death2")));
rl.add(linl, 3); rl.add(linl, 3);
linl = new LinearLayout(root, AlignX.CENTER); linl = new LinearLayout(root, AlignX.CENTER);
@ -56,14 +56,12 @@ public class DeathLayer extends ScreenLayer {
final TextButton btn1 = new TextButton(thick_font, "Retry", ScreenGame.COLOR_BTN_GOOD); final TextButton btn1 = new TextButton(thick_font, "Retry", ScreenGame.COLOR_BTN_GOOD);
btn1.textPainter.setAlign(AlignX.RIGHT);
btn1.textPainter.setVPaddingPercent(25); btn1.textPainter.setVPaddingPercent(25);
linl.add(btn1); linl.add(btn1);
linl.add(new LinearGap(50)); linl.add(new LinearGap(50));
final TextButton btn2 = new TextButton(thick_font, "Quit", ScreenGame.COLOR_BTN_BAD); final TextButton btn2 = new TextButton(thick_font, "Leave", ScreenGame.COLOR_BTN_BAD);
btn2.textPainter.setAlign(AlignX.LEFT);
btn2.textPainter.setVPaddingPercent(25); btn2.textPainter.setVPaddingPercent(25);
linl.add(btn2); linl.add(btn2);

@ -12,9 +12,10 @@ import mightypork.gamecore.util.strings.StringProvider;
import mightypork.rogue.world.World; import mightypork.rogue.world.World;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.gui.Minimap; import mightypork.rogue.world.gui.Minimap;
import mightypork.rogue.world.gui.WorldConsoleRenderer;
public class HudLayer extends ScreenLayer { public class LayerGameUi extends ScreenLayer {
private final Num playerHealthTotal = new Num() { private final Num playerHealthTotal = new Num() {
@ -39,7 +40,7 @@ public class HudLayer extends ScreenLayer {
private final ScreenGame gameScreen; private final ScreenGame gameScreen;
public HudLayer(ScreenGame screen) public LayerGameUi(ScreenGame screen)
{ {
super(screen); super(screen);
this.gameScreen = screen; this.gameScreen = screen;
@ -152,7 +153,7 @@ public class HudLayer extends ScreenLayer {
@Override @Override
public int getZIndex() public int getZIndex()
{ {
return 100; return 101;
} }

@ -8,7 +8,7 @@ import mightypork.gamecore.gui.components.layout.FlowColumnLayout;
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.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.gui.screens.impl.FadingLayer;
import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.KeyStroke.Edge; import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.resources.Res; import mightypork.gamecore.resources.Res;
@ -16,6 +16,7 @@ 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.screens.game.ScreenGame.GScrState;
import mightypork.rogue.world.PlayerFacade; import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.World; import mightypork.rogue.world.World;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;
@ -23,7 +24,7 @@ import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.item.ItemType; import mightypork.rogue.world.item.ItemType;
public class InventoryLayer extends ScreenLayer { public class LayerInv extends FadingLayer {
private static final int SLOT_COUNT = 8; private static final int SLOT_COUNT = 8;
private static final int SLOT_ROW = 4; private static final int SLOT_ROW = 4;
@ -65,6 +66,7 @@ public class InventoryLayer extends ScreenLayer {
}; };
private final InvSlot[] slots = new InvSlot[SLOT_COUNT]; private final InvSlot[] slots = new InvSlot[SLOT_COUNT];
private ScreenGame gscreen;
private int getSelectedSlot() private int getSelectedSlot()
@ -91,9 +93,19 @@ public class InventoryLayer extends ScreenLayer {
} }
public InventoryLayer(final ScreenGame screen) @Override
protected void onHideFinished()
{
if (gscreen.getState() == GScrState.INV) {
gscreen.actionToggleInv.run();
}
}
public LayerInv(final ScreenGame screen)
{ {
super(screen); super(screen);
this.gscreen = screen;
final Rect fg = root.shrink(root.height().perc(15)); final Rect fg = root.shrink(root.height().perc(15));
@ -149,9 +161,8 @@ public class InventoryLayer extends ScreenLayer {
@Override @Override
public void run() public void run()
{ {
if (isEnabled()) { if (!isEnabled()) return;
screen.actionToggleInv.run(); hide();
}
} }
}); });
@ -237,7 +248,7 @@ public class InventoryLayer extends ScreenLayer {
} }
selectSlot((SLOT_COUNT + (sel - 1)) % SLOT_COUNT); selectSlot((SLOT_COUNT + (sel - 1)) % SLOT_COUNT);
}; }
}); });
bindKey(Config.getKey("game.inv.move.right"), Edge.RISING, new Runnable() { bindKey(Config.getKey("game.inv.move.right"), Edge.RISING, new Runnable() {
@ -254,7 +265,7 @@ public class InventoryLayer extends ScreenLayer {
} }
selectSlot((SLOT_COUNT + (sel + 1)) % SLOT_COUNT); selectSlot((SLOT_COUNT + (sel + 1)) % SLOT_COUNT);
}; }
}); });
bindKey(Config.getKey("game.inv.move.up"), Edge.RISING, new Runnable() { bindKey(Config.getKey("game.inv.move.up"), Edge.RISING, new Runnable() {
@ -271,7 +282,7 @@ public class InventoryLayer extends ScreenLayer {
} }
selectSlot((SLOT_COUNT + (sel - SLOT_ROW)) % SLOT_COUNT); selectSlot((SLOT_COUNT + (sel - SLOT_ROW)) % SLOT_COUNT);
}; }
}); });
bindKey(Config.getKey("game.inv.move.down"), Edge.RISING, new Runnable() { bindKey(Config.getKey("game.inv.move.down"), Edge.RISING, new Runnable() {
@ -288,7 +299,7 @@ public class InventoryLayer extends ScreenLayer {
} }
selectSlot((sel + SLOT_ROW) % SLOT_COUNT); selectSlot((sel + SLOT_ROW) % SLOT_COUNT);
}; }
}); });
} }
@ -296,7 +307,7 @@ public class InventoryLayer extends ScreenLayer {
@Override @Override
public int getZIndex() public int getZIndex()
{ {
return 200; return 300;
} }
} }

@ -9,12 +9,12 @@ import mightypork.rogue.world.gui.interaction.MIPKeyboard;
import mightypork.rogue.world.gui.interaction.MIPMouse; import mightypork.rogue.world.gui.interaction.MIPMouse;
public class WorldLayer extends ScreenLayer { public class LayerMapView extends ScreenLayer {
protected final MapView map; protected final MapView map;
public WorldLayer(Screen screen) public LayerMapView(Screen screen)
{ {
super(screen); super(screen);
@ -44,7 +44,7 @@ public class WorldLayer extends ScreenLayer {
@Override @Override
public int getEventPriority() public int getEventPriority()
{ {
return 0; return 100;
} }
} }

@ -0,0 +1,84 @@
package mightypork.rogue.screens.game;
import java.io.File;
import mightypork.gamecore.Config;
import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.input.TextButton;
import mightypork.gamecore.gui.components.layout.RowLayout;
import mightypork.gamecore.gui.components.layout.linear.LinearLayout;
import mightypork.gamecore.gui.components.painters.ImagePainter;
import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.impl.FadingLayer;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.rogue.RogueStateManager.RogueState;
import mightypork.rogue.events.RogueStateRequest;
import mightypork.rogue.world.WorldProvider;
public class LayerWin extends FadingLayer {
public LayerWin(final ScreenGame screen)
{
super(screen);
// darker down to cover console.
final QuadPainter qp = new QuadPainter(RGB.BLACK_80);
qp.setRect(root);
root.add(qp);
final GLFont thick_font = Res.getFont("thick");
final RowLayout rl = new RowLayout(root, 5);
rl.setRect(root.shrink(Num.ZERO, root.height().perc(15)));
root.add(rl);
final TextPainter txp = new TextPainter(thick_font, AlignX.CENTER, RGB.YELLOW, "You won!");
rl.add(txp, 1);
txp.setVPaddingPercent(13);
LinearLayout linl = new LinearLayout(root, AlignX.CENTER);
linl.add(new ImagePainter(Res.getTxQuad("win")));
rl.add(linl, 3);
linl = new LinearLayout(root, AlignX.CENTER);
rl.add(linl);
final TextButton btn1 = new TextButton(thick_font, "Leave", ScreenGame.COLOR_BTN_GOOD);
btn1.textPainter.setVPaddingPercent(25);
linl.add(btn1);
final Action quit = new Action() {
@Override
protected void execute()
{
// delete the save file
final File f = WorldProvider.get().getWorld().getSaveFile();
f.delete();
getEventBus().send(new RogueStateRequest(RogueState.MAIN_MENU));
}
};
btn1.setAction(quit);
bindKey(Config.getKey("general.confirm"), Edge.RISING, quit);
bindKey(Config.getKey("general.close"), Edge.RISING, quit);
}
@Override
public int getZIndex()
{
return 300;
}
}

@ -17,12 +17,13 @@ import mightypork.rogue.events.RogueStateRequest;
import mightypork.rogue.screens.RogueScreen; import mightypork.rogue.screens.RogueScreen;
import mightypork.rogue.world.PlayerFacade; import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.events.GameWinHandler;
import mightypork.rogue.world.events.PlayerDeathHandler; import mightypork.rogue.world.events.PlayerDeathHandler;
import mightypork.rogue.world.events.WorldPauseRequest; import mightypork.rogue.world.events.WorldPauseRequest;
import mightypork.rogue.world.events.WorldPauseRequest.PauseAction; import mightypork.rogue.world.events.WorldPauseRequest.PauseAction;
public class ScreenGame extends RogueScreen implements PlayerDeathHandler { public class ScreenGame extends RogueScreen implements PlayerDeathHandler, GameWinHandler {
public static final Color COLOR_BTN_GOOD = Color.fromHex(0x28CB2D); public static final Color COLOR_BTN_GOOD = Color.fromHex(0x28CB2D);
public static final Color COLOR_BTN_BAD = Color.fromHex(0xCB2828); public static final Color COLOR_BTN_BAD = Color.fromHex(0xCB2828);
@ -35,14 +36,15 @@ public class ScreenGame extends RogueScreen implements PlayerDeathHandler {
*/ */
public enum GScrState public enum GScrState
{ {
WORLD, INV, DEATH, GOTO_MENU, GOTO_QUIT; WORLD, INV, DEATH, WIN, GOTO_MENU, GOTO_QUIT;
} }
private InventoryLayer invLayer; private LayerInv invLayer;
private HudLayer hudLayer; private LayerGameUi hudLayer;
private DeathLayer deathLayer; private LayerDeath deathLayer;
private LayerWin winLayer;
private WorldLayer worldLayer; private LayerMapView worldLayer;
private GScrState state = null; private GScrState state = null;
@ -65,7 +67,6 @@ public class ScreenGame extends RogueScreen implements PlayerDeathHandler {
@Override @Override
public void execute() public void execute()
{ {
System.out.println("Toggle inv action");
setState(getState() == GScrState.INV ? GScrState.WORLD : GScrState.INV); setState(getState() == GScrState.INV ? GScrState.WORLD : GScrState.INV);
} }
}; };
@ -102,6 +103,8 @@ public class ScreenGame extends RogueScreen implements PlayerDeathHandler {
@Override @Override
public void execute() public void execute()
{ {
if (WorldProvider.get().getWorld().isGameOver()) return;
try { try {
WorldProvider.get().saveWorld(); WorldProvider.get().saveWorld();
WorldProvider.get().getWorld().getConsole().msgWorldSaved(); WorldProvider.get().getWorld().getConsole().msgWorldSaved();
@ -117,6 +120,8 @@ public class ScreenGame extends RogueScreen implements PlayerDeathHandler {
@Override @Override
public void execute() public void execute()
{ {
if (WorldProvider.get().getWorld().isGameOver()) return;
try { try {
final File f = WorldProvider.get().getWorld().getSaveFile(); final File f = WorldProvider.get().getWorld().getSaveFile();
WorldProvider.get().loadWorld(f); WorldProvider.get().loadWorld(f);
@ -157,7 +162,7 @@ public class ScreenGame extends RogueScreen implements PlayerDeathHandler {
pl.dropItem(pl.getInventory().getLastAddIndex()); pl.dropItem(pl.getInventory().getLastAddIndex());
} }
}; };
private AskSaveLayer askSaveLayer; private LayerAskSave askSaveLayer;
/** /**
@ -169,56 +174,58 @@ public class ScreenGame extends RogueScreen implements PlayerDeathHandler {
{ {
if (this.state == nstate) return; if (this.state == nstate) return;
if (nstate != GScrState.WORLD) { // leaving world. final boolean gameOver = WorldProvider.get().getWorld().isGameOver();
if (nstate != GScrState.WORLD && state == GScrState.WORLD) { // leaving world.
getEventBus().send(new WorldPauseRequest(PauseAction.PAUSE)); getEventBus().send(new WorldPauseRequest(PauseAction.PAUSE));
worldActions.setEnabled(false); // disable world actions worldActions.setEnabled(false); // disable world actions
} }
if (nstate == GScrState.WORLD) {
getEventBus().send(new WorldPauseRequest(PauseAction.RESUME));
invLayer.hide();
deathLayer.hide();
askSaveLayer.hide();
worldActions.setEnabled(true);
}
if (nstate == GScrState.INV) {
invLayer.show();
}
if (nstate == GScrState.DEATH) { if (nstate != GScrState.DEATH) deathLayer.hide();
deathLayer.show(); if (nstate != GScrState.WIN) winLayer.hide();
} if (nstate != GScrState.INV) invLayer.hide();
if (nstate != GScrState.GOTO_MENU && nstate != GScrState.GOTO_QUIT) askSaveLayer.hide();
if (nstate == GScrState.GOTO_MENU) { Runnable task;
switch (nstate) {
case WORLD:
getEventBus().send(new WorldPauseRequest(PauseAction.RESUME));
worldActions.setEnabled(true);
break;
askSaveLayer.setTask(new Runnable() { case INV:
invLayer.show();
@Override break;
public void run()
{
getEventBus().send(new RogueStateRequest(RogueState.MAIN_MENU));
}
});
askSaveLayer.show(); case DEATH:
} deathLayer.show();
break;
if (nstate == GScrState.GOTO_QUIT) {
case WIN:
winLayer.show();
break;
askSaveLayer.setTask(new Runnable() { case GOTO_MENU:
case GOTO_QUIT:
final RogueState goal = (nstate == GScrState.GOTO_MENU) ? RogueState.MAIN_MENU : RogueState.EXIT;
@Override task = new Runnable() {
public void run()
{ @Override
getEventBus().send(new RogueStateRequest(RogueState.EXIT)); public void run()
{
getEventBus().send(new RogueStateRequest(goal));
}
};
if (gameOver) {
task.run();
} else {
askSaveLayer.setTask(task);
askSaveLayer.show();
} }
});
askSaveLayer.show();
} }
this.state = nstate; this.state = nstate;
@ -235,11 +242,12 @@ public class ScreenGame extends RogueScreen implements PlayerDeathHandler {
{ {
super(app); super(app);
addLayer(invLayer = new InventoryLayer(this)); addLayer(invLayer = new LayerInv(this));
addLayer(deathLayer = new DeathLayer(this)); addLayer(deathLayer = new LayerDeath(this));
addLayer(hudLayer = new HudLayer(this)); addLayer(winLayer = new LayerWin(this));
addLayer(worldLayer = new WorldLayer(this)); addLayer(hudLayer = new LayerGameUi(this));
addLayer(askSaveLayer = new AskSaveLayer(this)); addLayer(worldLayer = new LayerMapView(this));
addLayer(askSaveLayer = new LayerAskSave(this));
bindKey(Config.getKey("game.pause"), Edge.RISING, actionTogglePause); bindKey(Config.getKey("game.pause"), Edge.RISING, actionTogglePause);
@ -253,6 +261,15 @@ public class ScreenGame extends RogueScreen implements PlayerDeathHandler {
bindKey(Config.getKey("game.save"), Edge.RISING, actionSave); bindKey(Config.getKey("game.save"), Edge.RISING, actionSave);
bindKey(Config.getKey("game.quit"), Edge.RISING, actionMenu); bindKey(Config.getKey("game.quit"), Edge.RISING, actionMenu);
// bindKey(new KeyStroke(Keys.W), Edge.RISING, new Runnable() {
//
// @Override
// public void run()
// {
// setState(GScrState.WIN);
// }
// });
// add as actions - enableables. // add as actions - enableables.
worldActions.add(worldLayer); worldActions.add(worldLayer);
worldActions.add(hudLayer); worldActions.add(hudLayer);
@ -265,7 +282,6 @@ public class ScreenGame extends RogueScreen implements PlayerDeathHandler {
worldActions.add(actionSave); worldActions.add(actionSave);
worldActions.add(actionLoad); worldActions.add(actionLoad);
worldActions.add(actionMenu); worldActions.add(actionMenu);
// worldActions.add(actionQuit);
worldActions.add(actionDropLastPickedItem); worldActions.add(actionDropLastPickedItem);
worldActions.setEnabled(true); worldActions.setEnabled(true);
@ -289,6 +305,7 @@ public class ScreenGame extends RogueScreen implements PlayerDeathHandler {
WorldProvider.get().setListening(true); WorldProvider.get().setListening(true);
setState(GScrState.WORLD); setState(GScrState.WORLD);
hideAllPopups();
} }
@ -300,6 +317,15 @@ public class ScreenGame extends RogueScreen implements PlayerDeathHandler {
} }
private void hideAllPopups()
{
invLayer.hideImmediate();
deathLayer.hideImmediate();
winLayer.hideImmediate();
askSaveLayer.hideImmediate();
}
@Override @Override
public void onPlayerKilled() public void onPlayerKilled()
{ {
@ -307,9 +333,20 @@ public class ScreenGame extends RogueScreen implements PlayerDeathHandler {
} }
@Override
public void onGameWon()
{
setState(GScrState.WIN);
}
@Override @Override
public void onQuitRequest(UserQuitRequest event) public void onQuitRequest(UserQuitRequest event)
{ {
// if player is dead, don't ask don't ask for save
final PlayerFacade pl = WorldProvider.get().getPlayer();
if (pl.isDead()) return;
actionQuit.run(); actionQuit.run();
event.consume(); event.consume();
} }

@ -64,7 +64,7 @@ public class ScreenMainMenu extends RogueScreen {
bg.setRect(root); bg.setRect(root);
root.add(bg); root.add(bg);
final RowLayout rows = new RowLayout(root, menuBox, 10); final RowLayout rows = new RowLayout(root, menuBox, 13);
rows.enableCaching(true); rows.enableCaching(true);
root.add(rows); root.add(rows);
@ -90,20 +90,18 @@ public class ScreenMainMenu extends RogueScreen {
rows.add(btn, 2); rows.add(btn, 2);
rows.skip(1); rows.skip(1);
/*
// bouncy text button btn = new TextButton(btnFont, "Story", PAL16.CLOUDBLUE);
btn = new MenuButton("Bouncy", PAL16.CLOUDBLUE);
btn.setAction(new Action() { btn.setAction(new Action() {
@Override @Override
protected void execute() protected void execute()
{ {
getEventBus().send(new CrossfadeRequest("test.bouncy")); getEventBus().send(new RogueStateRequest(RogueState.STORY));
} }
}); });
layout.put(btn, r, 0, 2, 1); rows.add(btn, 2);
r += 3; rows.skip(1);
*/
// quit button // quit button
btn = new TextButton(btnFont, "Exit", PAL16.BLOODRED); btn = new TextButton(btnFont, "Exit", PAL16.BLOODRED);

@ -0,0 +1,260 @@
package mightypork.rogue.screens.story;
import mightypork.gamecore.Config;
import mightypork.gamecore.core.AppAccess;
import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.layout.RowLayout;
import mightypork.gamecore.gui.components.layout.linear.LinearLayout;
import mightypork.gamecore.gui.components.painters.ImagePainter;
import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.gui.screens.impl.FadingLayer;
import mightypork.gamecore.gui.screens.impl.LayerColor;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.events.MouseButtonEvent;
import mightypork.gamecore.input.events.MouseButtonHandler;
import mightypork.gamecore.resources.Res;
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.Num;
import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.timing.TimedTask;
import mightypork.rogue.RogueStateManager.RogueState;
import mightypork.rogue.events.RogueStateRequest;
import mightypork.rogue.screens.RogueScreen;
public class ScreenStory extends RogueScreen implements MouseButtonHandler {
private class LayerSlide extends ScreenLayer {
private TextPainter tp1;
private TextPainter tp2;
private ImagePainter img;
private NumAnimated layerAlpha = new NumAnimated(0, Easing.LINEAR, 0.8);
private NumAnimated tx1alpha = new NumAnimated(0, Easing.LINEAR, 1);
private NumAnimated tx2alpha = new NumAnimated(0, Easing.LINEAR, 1);
private String nextImg, nextT1, nextT2;
private TimedTask ttNextSlide = new TimedTask() {
@Override
public void run()
{
img.setTxQuad(Res.getTxQuad(nextImg));
if (nextT1 != null) tp1.setText(nextT1);
if (nextT2 != null) tp2.setText(nextT2);
tx1alpha.setTo(0);
tx2alpha.setTo(0);
layerAlpha.setTo(0);
layerAlpha.fadeIn();
ttText1.start(1.5);
}
};
private TimedTask ttText1 = new TimedTask() {
@Override
public void run()
{
if (nextT1 == null) {
ttText2.run();
} else {
tx1alpha.fadeIn();
ttText2.start(2);
}
}
};
private TimedTask ttText2 = new TimedTask() {
@Override
public void run()
{
if (nextT2 == null) {
ttFinish.run();
} else {
tx2alpha.fadeIn();
ttFinish.start(2);
}
}
};
private TimedTask ttFinish = new TimedTask() {
@Override
public void run()
{
System.out.println("Slide finished.");
}
};
private final Color textColor = Color.fromHex(0x7ad8ff);
public LayerSlide(Screen screen)
{
super(screen);
Rect contentRect = root.shrink(Num.ZERO, root.height().perc(3));
RowLayout rl = new RowLayout(root, 9);
rl.setRect(contentRect);
root.add(rl);
LinearLayout ll = new LinearLayout(root, AlignX.CENTER);
rl.add(ll, 7);
img = new ImagePainter(Res.getTxQuad("story_1"));
ll.add(img);
tp1 = new TextPainter(Res.getFont("tiny"), AlignX.CENTER, textColor.withAlpha(tx1alpha), "");
rl.add(tp1);
tp1.setVPaddingPercent(20);
tp2 = new TextPainter(Res.getFont("tiny"), AlignX.CENTER, textColor.withAlpha(tx2alpha), "");
rl.add(tp2);
tp2.setVPaddingPercent(20);
updated.add(layerAlpha);
updated.add(tx1alpha);
updated.add(tx2alpha);
updated.add(ttText1);
updated.add(ttText2);
updated.add(ttFinish);
updated.add(ttNextSlide);
setAlpha(layerAlpha);
}
@Override
public int getZIndex()
{
return 1;
}
public void showSlide(String image, String text1, String text2)
{
ttFinish.stop();
ttNextSlide.stop();
ttText1.stop();
ttText2.stop();
this.nextImg = image;
this.nextT1 = text1;
this.nextT2 = text2;
layerAlpha.fadeOut();
ttNextSlide.start(1);
}
public void reset()
{
ttFinish.stop();
ttNextSlide.stop();
ttText1.stop();
ttText2.stop();
layerAlpha.setTo(0);
}
}
private LayerSlide slideLayer;
private Action next = new Action() {
@Override
protected void execute()
{
showSlide(++slide);
}
};
private Action prev = new Action() {
@Override
protected void execute()
{
if (slide > 0) slide--;
showSlide(slide);
}
};
private Action close = new Action() {
@Override
protected void execute()
{
getEventBus().send(new RogueStateRequest(RogueState.MAIN_MENU));
}
};
public ScreenStory(AppAccess app)
{
super(app);
addLayer(new LayerColor(this, Color.fromHex(0x040c1e), 0));
addLayer(slideLayer = new LayerSlide(this));
bindKey(new KeyStroke(Keys.SPACE), Edge.RISING, next);
bindKey(new KeyStroke(Keys.RIGHT), Edge.RISING, next);
bindKey(new KeyStroke(Keys.BACKSPACE), Edge.RISING, prev);
bindKey(new KeyStroke(Keys.LEFT), Edge.RISING, prev);
bindKey(Config.getKey("general.close"), Edge.RISING, close);
}
private int slide = 0;
@Override
protected void onScreenEnter()
{
slide = 0;
slideLayer.reset();
showSlide(slide);
}
private void showSlide(int slide)
{
switch (slide) {
case 0:
slideLayer.showSlide("story_1", "Man, it's so hot today!", "Makes me real thirsty, ya know.");
break;
case 1:
slideLayer.showSlide("story_2", "'Guess I'll go get some booze", "from the cellar.");
break;
case 2:
slideLayer.showSlide("story_3", "Here we go.. HEY GIVE IT BACK!", "I'll hunt you down, thieves!");
break;
case 3:
getEventBus().send(new RogueStateRequest(RogueState.MAIN_MENU));
}
}
@Override
public void receive(MouseButtonEvent event)
{
if (event.isButtonEvent() && event.isUp()) {
if (event.getButton() == 0) next.run();
if (event.getButton() == 1) prev.run();
}
}
}

@ -19,6 +19,8 @@ import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.timing.Pauseable; import mightypork.gamecore.util.math.timing.Pauseable;
import mightypork.rogue.world.entity.Entities; import mightypork.rogue.world.entity.Entities;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.events.GameWinHandler;
import mightypork.rogue.world.events.PlayerDeathHandler;
import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.Level;
@ -27,7 +29,7 @@ import mightypork.rogue.world.level.Level;
* *
* @author MightyPork * @author MightyPork
*/ */
public class World implements DelegatingClient, BusAccess, IonObjBundled, Pauseable, Updateable { public class World implements DelegatingClient, BusAccess, IonObjBundled, Pauseable, Updateable, PlayerDeathHandler, GameWinHandler {
// not saved stuffs // not saved stuffs
private final PlayerFacade playerFacade = new PlayerFacade(this); private final PlayerFacade playerFacade = new PlayerFacade(this);
@ -36,6 +38,7 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
Entity playerEntity; Entity playerEntity;
private BusAccess bus; private BusAccess bus;
private int pauseDepth = 0; private int pauseDepth = 0;
private boolean gameOver = false;
/** List of world's levels */ /** List of world's levels */
final ArrayList<Level> levels = new ArrayList<>(); final ArrayList<Level> levels = new ArrayList<>();
@ -260,4 +263,24 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
{ {
return saveFile; return saveFile;
} }
@Override
public void onGameWon()
{
gameOver = true;
}
@Override
public void onPlayerKilled()
{
gameOver = true;
}
public boolean isGameOver()
{
return gameOver || getPlayer().isDead();
}
} }

@ -6,6 +6,7 @@ import java.io.IOException;
import mightypork.gamecore.eventbus.BusAccess; import mightypork.gamecore.eventbus.BusAccess;
import mightypork.gamecore.eventbus.clients.RootBusNode; import mightypork.gamecore.eventbus.clients.RootBusNode;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.util.ion.Ion; import mightypork.gamecore.util.ion.Ion;
import mightypork.rogue.world.gen.WorldCreator; import mightypork.rogue.world.gen.WorldCreator;
import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.Level;
@ -63,21 +64,13 @@ public class WorldProvider extends RootBusNode {
*/ */
public World createWorld(long seed) public World createWorld(long seed)
{ {
Log.f2("Creating a new world with seed " + seed);
final 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()
{
setWorld(null);
}
public World getWorld() public World getWorld()
{ {
return world; return world;
@ -98,6 +91,7 @@ public class WorldProvider extends RootBusNode {
public void loadWorld(File file) throws IOException public void loadWorld(File file) throws IOException
{ {
Log.f2("Loading world from: " + file);
setWorld(Ion.fromFile(file, World.class)); setWorld(Ion.fromFile(file, World.class));
world.setSaveFile(file); world.setSaveFile(file);
} }
@ -112,10 +106,11 @@ public class WorldProvider extends RootBusNode {
throw new IllegalStateException("Trying to save world to a NULL file."); throw new IllegalStateException("Trying to save world to a NULL file.");
} }
if (world.getPlayer().isDead()) { if (world.isGameOver()) {
throw new IllegalStateException("Cannot save, player is dead."); throw new IllegalStateException("Cannot save, player is dead.");
} }
Log.f2("Saving world to: " + file);
Ion.toFile(file, world); Ion.toFile(file, world);
} }

@ -9,7 +9,7 @@ import mightypork.gamecore.util.ion.IonOutput;
import mightypork.rogue.world.entity.impl.EntityBossRat; import mightypork.rogue.world.entity.impl.EntityBossRat;
import mightypork.rogue.world.entity.impl.EntityBrownRat; import mightypork.rogue.world.entity.impl.EntityBrownRat;
import mightypork.rogue.world.entity.impl.EntityGrayRat; import mightypork.rogue.world.entity.impl.EntityGrayRat;
import mightypork.rogue.world.entity.impl.PlayerEntity; import mightypork.rogue.world.entity.impl.EntityPlayer;
/** /**
@ -21,7 +21,7 @@ public final class Entities {
private static final EntityModel[] entities = new EntityModel[256]; private static final EntityModel[] entities = new EntityModel[256];
public static final EntityModel PLAYER = new EntityModel(1, PlayerEntity.class); public static final EntityModel PLAYER = new EntityModel(1, EntityPlayer.class);
public static final EntityModel RAT_GRAY = new EntityModel(2, EntityGrayRat.class); public static final EntityModel RAT_GRAY = new EntityModel(2, EntityGrayRat.class);
public static final EntityModel RAT_BROWN = new EntityModel(3, EntityBrownRat.class); public static final EntityModel RAT_BROWN = new EntityModel(3, EntityBrownRat.class);
public static final EntityModel RAT_BOSS = new EntityModel(4, EntityBossRat.class); public static final EntityModel RAT_BOSS = new EntityModel(4, EntityBossRat.class);

@ -8,6 +8,7 @@ import mightypork.rogue.world.entity.EntityPathFinder;
import mightypork.rogue.world.entity.EntityRenderer; import mightypork.rogue.world.entity.EntityRenderer;
import mightypork.rogue.world.entity.EntityType; import mightypork.rogue.world.entity.EntityType;
import mightypork.rogue.world.entity.render.EntityRendererMobLR; import mightypork.rogue.world.entity.render.EntityRendererMobLR;
import mightypork.rogue.world.events.GameWinEvent;
public class EntityBossRat extends Entity { public class EntityBossRat extends Entity {
@ -63,8 +64,8 @@ public class EntityBossRat extends Entity {
@Override @Override
public void onKilled() public void onKilled()
{ {
getWorld().getConsole().addMessage("~~~ YOU DEFEATED THE BOSS RAT ~~~"); // send kill event to listeners, after the entity has despawned (disappeared)
getWorld().getConsole().addMessage("TODO: outro"); getWorld().getEventBus().sendDelayed(new GameWinEvent(), getDespawnDelay() * 1.5); // dramatic pause
} }

@ -12,7 +12,7 @@ import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.tile.Tile; import mightypork.rogue.world.tile.Tile;
public class PlayerEntity extends Entity { public class EntityPlayer extends Entity {
class PlayerAi extends EntityModule implements EntityMoveListener { class PlayerAi extends EntityModule implements EntityMoveListener {
@ -63,7 +63,7 @@ public class PlayerEntity extends Entity {
private void fireEvt() private void fireEvt()
{ {
getWorld().getEventBus().send(new PlayerStepEndEvent(PlayerEntity.this)); getWorld().getEventBus().send(new PlayerStepEndEvent(EntityPlayer.this));
} }
@ -81,7 +81,7 @@ public class PlayerEntity extends Entity {
private final PlayerAi ai = new PlayerAi(this); private final PlayerAi ai = new PlayerAi(this);
public PlayerEntity(EntityModel model, int eid) public EntityPlayer(EntityModel model, int eid)
{ {
super(model, eid); super(model, eid);
@ -139,7 +139,6 @@ public class PlayerEntity extends Entity {
getWorld().getEventBus().sendDelayed(new PlayerKilledEvent(), getDespawnDelay()); getWorld().getEventBus().sendDelayed(new PlayerKilledEvent(), getDespawnDelay());
getWorld().getConsole().msgDie(lastAttacker); getWorld().getConsole().msgDie(lastAttacker);
} }

@ -0,0 +1,14 @@
package mightypork.rogue.world.events;
import mightypork.gamecore.eventbus.BusEvent;
public class GameWinEvent extends BusEvent<GameWinHandler> {
@Override
protected void handleBy(GameWinHandler handler)
{
handler.onGameWon();
}
}

@ -0,0 +1,8 @@
package mightypork.rogue.world.events;
public interface GameWinHandler {
void onGameWon();
}

@ -3,16 +3,16 @@ package mightypork.rogue.world.events;
import mightypork.gamecore.eventbus.BusEvent; import mightypork.gamecore.eventbus.BusEvent;
import mightypork.gamecore.eventbus.event_flags.NotLoggedEvent; import mightypork.gamecore.eventbus.event_flags.NotLoggedEvent;
import mightypork.rogue.world.entity.impl.PlayerEntity; import mightypork.rogue.world.entity.impl.EntityPlayer;
@NotLoggedEvent @NotLoggedEvent
public class PlayerStepEndEvent extends BusEvent<PlayerStepEndListener> { public class PlayerStepEndEvent extends BusEvent<PlayerStepEndListener> {
private final PlayerEntity player; private final EntityPlayer player;
public PlayerStepEndEvent(PlayerEntity player) public PlayerStepEndEvent(EntityPlayer player)
{ {
super(); super();
this.player = player; this.player = player;

@ -1,10 +1,10 @@
package mightypork.rogue.world.events; package mightypork.rogue.world.events;
import mightypork.rogue.world.entity.impl.PlayerEntity; import mightypork.rogue.world.entity.impl.EntityPlayer;
public interface PlayerStepEndListener { public interface PlayerStepEndListener {
void onStepFinished(PlayerEntity player); void onStepFinished(EntityPlayer player);
} }

@ -1,4 +1,4 @@
package mightypork.rogue.screens.game; package mightypork.rogue.world.gui;
import java.util.Collection; import java.util.Collection;

@ -16,7 +16,7 @@ import mightypork.gamecore.input.Keys;
import mightypork.gamecore.util.math.algo.Move; import mightypork.gamecore.util.math.algo.Move;
import mightypork.gamecore.util.math.algo.Moves; import mightypork.gamecore.util.math.algo.Moves;
import mightypork.gamecore.util.math.constraints.vect.Vect; import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.world.entity.impl.PlayerEntity; import mightypork.rogue.world.entity.impl.EntityPlayer;
import mightypork.rogue.world.events.PlayerStepEndListener; import mightypork.rogue.world.events.PlayerStepEndListener;
import mightypork.rogue.world.gui.MapView; import mightypork.rogue.world.gui.MapView;
@ -59,6 +59,8 @@ public class MIPKeyboard extends MapInteractionPlugin implements DelegatingClien
public MIPKeyboard(MapView mapView) public MIPKeyboard(MapView mapView)
{ {
super(mapView); super(mapView);
// bind keys
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
final int j = i; final int j = i;
@ -75,7 +77,7 @@ public class MIPKeyboard extends MapInteractionPlugin implements DelegatingClien
@Override @Override
public void onStepFinished(PlayerEntity player) public void onStepFinished(EntityPlayer player)
{ {
walkByKey(); walkByKey();
} }
@ -88,26 +90,10 @@ public class MIPKeyboard extends MapInteractionPlugin implements DelegatingClien
} }
// @Override
// public void receive(KeyEvent evt)
// {
//
// if (evt.isDown() || mapView.plc.getPlayer().isMoving()) return; // not interested
//
// if (InputSystem.getActiveModKeys() != Keys.MOD_NONE) return;
//
// for (int i = 0; i < 4; i++) {
// if (evt.getKey() == keys[i].getKey()) {
// mapView.plc.clickTile(sides[i]);
// }
// }
// }
private void clickSide(Move side) private void clickSide(Move side)
{ {
if (isImmobile()) { if (isImmobile() || getPlayer().isMoving()) return;
return;
}
mapView.plc.clickTile(side); mapView.plc.clickTile(side);
} }

@ -8,7 +8,7 @@ import mightypork.gamecore.util.math.Polar;
import mightypork.gamecore.util.math.algo.Coord; import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.algo.Moves; import mightypork.gamecore.util.math.algo.Moves;
import mightypork.gamecore.util.math.constraints.vect.Vect; import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.world.entity.impl.PlayerEntity; import mightypork.rogue.world.entity.impl.EntityPlayer;
import mightypork.rogue.world.events.PlayerStepEndListener; import mightypork.rogue.world.events.PlayerStepEndListener;
import mightypork.rogue.world.gui.MapView; import mightypork.rogue.world.gui.MapView;
import mightypork.rogue.world.tile.Tile; import mightypork.rogue.world.tile.Tile;
@ -114,7 +114,7 @@ public class MIPMouse extends MapInteractionPlugin implements PlayerStepEndListe
@Override @Override
public void onStepFinished(PlayerEntity player) public void onStepFinished(EntityPlayer player)
{ {
if (isImmobile()) return; if (isImmobile()) return;

@ -25,7 +25,7 @@ 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.EntityType; import mightypork.rogue.world.entity.EntityType;
import mightypork.rogue.world.entity.impl.PlayerEntity; import mightypork.rogue.world.entity.impl.EntityPlayer;
import mightypork.rogue.world.item.Item; import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.tile.Tile; import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileModel;
@ -257,7 +257,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
ent.setLevel(this); ent.setLevel(this);
occupyTile(ent.getCoord()); occupyTile(ent.getCoord());
entityMap.put(ent.getEntityId(), ent); entityMap.put(ent.getEntityId(), ent);
if (ent instanceof PlayerEntity) { if (ent instanceof EntityPlayer) {
playerCount++; playerCount++;
} }
} }
@ -400,7 +400,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
entityMap.put(entity.getEntityId(), entity); entityMap.put(entity.getEntityId(), entity);
entityList.add(entity); entityList.add(entity);
if (entity instanceof PlayerEntity) playerCount++; if (entity instanceof EntityPlayer) playerCount++;
// join to level & world // join to level & world
occupyTile(entity.getCoord()); occupyTile(entity.getCoord());
@ -431,7 +431,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
{ {
final Entity removed = entityMap.remove(eid); final Entity removed = entityMap.remove(eid);
if (removed == null) throw new NullPointerException("No such entity in level: " + eid); if (removed == null) throw new NullPointerException("No such entity in level: " + eid);
if (removed instanceof PlayerEntity) playerCount--; if (removed instanceof EntityPlayer) playerCount--;
entityList.remove(removed); entityList.remove(removed);
// upon kill, entities free tile themselves. // upon kill, entities free tile themselves.

Loading…
Cancel
Save