removed test screens; reorg, added "Passage" tile, WorldGen tweaks

v5stable
ondra 11 years ago
parent a8ed021156
commit 9206396c8e
  1. BIN
      res/audio/wilderness.ogg
  2. BIN
      res/img/kitten.png
  3. BIN
      res/img/kitten_npot.png
  4. BIN
      res/img/tiles16.png
  5. BIN
      res/img/tiles16.xcf
  6. 2
      src/mightypork/gamecore/app/BaseApp.java
  7. 9
      src/mightypork/gamecore/gui/components/VisualComponent.java
  8. 7
      src/mightypork/gamecore/gui/components/painters/TextPainter.java
  9. 44
      src/mightypork/gamecore/gui/events/CrossfadeRequest.java
  10. 158
      src/mightypork/gamecore/gui/screens/BaseScreen.java
  11. 36
      src/mightypork/gamecore/gui/screens/CrossfadeRequest.java
  12. 2
      src/mightypork/gamecore/gui/screens/LayeredScreen.java
  13. 135
      src/mightypork/gamecore/gui/screens/Screen.java
  14. 4
      src/mightypork/gamecore/gui/screens/ScreenRegistry.java
  15. 53
      src/mightypork/gamecore/gui/screens/impl/CrossfadeOverlay.java
  16. 12
      src/mightypork/gamecore/gui/screens/impl/LayerColor.java
  17. 2
      src/mightypork/gamecore/resources/fonts/FontRenderer.java
  18. 2
      src/mightypork/gamecore/util/ion/Ion.java
  19. 5
      src/mightypork/gamecore/util/math/algo/Coord.java
  20. 66
      src/mightypork/gamecore/util/math/algo/Sides.java
  21. 5
      src/mightypork/gamecore/util/math/algo/Step.java
  22. 1
      src/mightypork/gamecore/util/math/color/pal/RGB.java
  23. 36
      src/mightypork/rogue/App.java
  24. 18
      src/mightypork/rogue/Res.java
  25. 2
      src/mightypork/rogue/screens/FpsOverlay.java
  26. 2
      src/mightypork/rogue/screens/game/HeartBar.java
  27. 2
      src/mightypork/rogue/screens/game/HudLayer.java
  28. 2
      src/mightypork/rogue/screens/game/NavItemSlot.java
  29. 25
      src/mightypork/rogue/screens/game/ScreenGame.java
  30. 2
      src/mightypork/rogue/screens/game/WorldLayer.java
  31. 26
      src/mightypork/rogue/screens/menu/MenuButton.java
  32. 72
      src/mightypork/rogue/screens/menu/MenuLayer.java
  33. 10
      src/mightypork/rogue/screens/menu/ScreenMainMenu.java
  34. 4
      src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java
  35. 17
      src/mightypork/rogue/screens/test_bouncyboxes/ScreenTestBouncy.java
  36. 108
      src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java
  37. 52
      src/mightypork/rogue/screens/test_cat_sound/ScreenTestCat.java
  38. 41
      src/mightypork/rogue/screens/test_render/LayerTestGradient.java
  39. 24
      src/mightypork/rogue/screens/test_render/ScreenTestRender.java
  40. 2
      src/mightypork/rogue/world/WorldRenderer.java
  41. 8
      src/mightypork/rogue/world/gen/LevelGenerator.java
  42. 4
      src/mightypork/rogue/world/gen/MapTheme.java
  43. 2
      src/mightypork/rogue/world/gen/RoomBuilder.java
  44. 5
      src/mightypork/rogue/world/gen/ScratchMap.java
  45. 12
      src/mightypork/rogue/world/gen/rooms/DeadEndRoom.java
  46. 19
      src/mightypork/rogue/world/gen/rooms/SimpleRectRoom.java
  47. 16
      src/mightypork/rogue/world/gen/themes/ThemeBrick.java
  48. 2
      src/mightypork/rogue/world/level/Level.java
  49. 2
      src/mightypork/rogue/world/tile/Tile.java
  50. 32
      src/mightypork/rogue/world/tile/TileRenderer.java
  51. 4
      src/mightypork/rogue/world/tile/TileType.java
  52. 8
      src/mightypork/rogue/world/tile/Tiles.java
  53. 13
      src/mightypork/rogue/world/tile/renderers/DoorTileRenderer.java
  54. 31
      src/mightypork/rogue/world/tile/tiles/WallPassageTile.java

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

@ -9,8 +9,8 @@ import javax.swing.JOptionPane;
import mightypork.gamecore.eventbus.EventBus; import mightypork.gamecore.eventbus.EventBus;
import mightypork.gamecore.eventbus.events.DestroyEvent; import mightypork.gamecore.eventbus.events.DestroyEvent;
import mightypork.gamecore.gui.screens.CrossfadeOverlay;
import mightypork.gamecore.gui.screens.ScreenRegistry; import mightypork.gamecore.gui.screens.ScreenRegistry;
import mightypork.gamecore.gui.screens.impl.CrossfadeOverlay;
import mightypork.gamecore.input.InputSystem; import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.logging.Log; import mightypork.gamecore.logging.Log;
import mightypork.gamecore.logging.SlickLogRedirector; import mightypork.gamecore.logging.SlickLogRedirector;

@ -31,13 +31,6 @@ public abstract class VisualComponent extends AbstractRectCache implements Compo
} }
@Override
public final Rect getRect()
{
return super.getRect();
}
@Override @Override
public final void setRect(RectBound rect) public final void setRect(RectBound rect)
{ {
@ -62,7 +55,7 @@ public abstract class VisualComponent extends AbstractRectCache implements Compo
@Override @Override
public final Rect getCacheSource() public final Rect getCacheSource()
{ {
return source; return source.round(); // round to avoid visual artifacts in fonts and such
} }

@ -28,7 +28,7 @@ public class TextPainter extends VisualComponent {
private boolean shadow; private boolean shadow;
private Color shadowColor = Color.BLACK; private Color shadowColor = Color.BLACK;
private Vect shadowOffset = Vect.make(1, 1); private Vect shadowOffset = Vect.make(2, 2);
/** /**
@ -91,9 +91,10 @@ public class TextPainter extends VisualComponent {
final Rect rect = getRect(); final Rect rect = getRect();
if (shadow) { if (shadow) {
font.draw(str, rect.move(shadowOffset), align, shadowColor); font.draw(str, rect.round(), align, shadowColor);
} }
font.draw(str, rect, align, color);
font.draw(str, rect.move(shadowOffset.neg()).round(), align, color);
} }

@ -0,0 +1,44 @@
package mightypork.gamecore.gui.events;
import mightypork.gamecore.eventbus.BusEvent;
import mightypork.gamecore.gui.screens.impl.CrossfadeOverlay;
/**
* @author MightyPork
*/
public class CrossfadeRequest extends BusEvent<CrossfadeOverlay> {
private final String screen;
private final boolean fromDark;
/**
* @param screen screen key to show. Null = exit the app.
* @param fromDark true to fade from full black (ie. start of the game)
*/
public CrossfadeRequest(String screen, boolean fromDark)
{
super();
this.screen = screen;
this.fromDark = fromDark;
}
/**
* @param screen screen key to show. Null = exit the app.
*/
public CrossfadeRequest(String screen)
{
super();
this.screen = screen;
this.fromDark = false;
}
@Override
public void handleBy(CrossfadeOverlay handler)
{
handler.goToScreen(screen, fromDark);
}
}

@ -1,158 +0,0 @@
package mightypork.gamecore.gui.screens;
import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.app.AppSubModule;
import mightypork.gamecore.gui.events.LayoutChangeEvent;
import mightypork.gamecore.gui.events.LayoutChangeListener;
import mightypork.gamecore.input.KeyBinder;
import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.util.annot.DefaultImpl;
import mightypork.gamecore.util.math.constraints.rect.Rect;
/**
* Screen class.
*
* @author MightyPork
*/
public abstract class BaseScreen extends AppSubModule implements Screen, KeyBinder, LayoutChangeListener {
private final KeyBindingPool keybindings = new KeyBindingPool();
private volatile boolean active;
private volatile boolean needSetupViewport = false;
/**
* @param app app access
*/
public BaseScreen(AppAccess app)
{
super(app);
// disable events initially
setListening(false);
addChildClient(keybindings);
}
private void fireLayoutChangeEvent()
{
getEventBus().sendDirectToChildren(this, new LayoutChangeEvent());
}
@Override
public final void bindKey(KeyStroke stroke, Runnable task)
{
keybindings.bindKey(stroke, task);
}
@Override
public final void unbindKey(KeyStroke stroke)
{
keybindings.unbindKey(stroke);
}
/**
* Prepare for being shown
*
* @param shown true to show, false to hide
*/
@Override
public final void setActive(boolean shown)
{
if (shown) {
active = true;
needSetupViewport = true;
fireLayoutChangeEvent();
onScreenEnter();
// enable events
setListening(true);
} else {
onScreenLeave();
active = false;
// disable events
setListening(false);
}
}
/**
* @return true if screen is the current screen
*/
@Override
public final boolean isActive()
{
return active;
}
@Override
public void onLayoutChanged()
{
if (!isActive()) return;
needSetupViewport = true;
}
@Override
public final Rect getRect()
{
return getDisplay().getRect();
}
@Override
public void render()
{
if (!isActive()) return;
if (needSetupViewport) {
Render.setupOrtho(getDisplay().getSize());
}
Render.pushState();
renderScreen();
Render.popState();
}
/**
* Called when the screen becomes active
*/
@DefaultImpl
protected void onScreenEnter()
{
}
/**
* Called when the screen is no longer active
*/
@DefaultImpl
protected void onScreenLeave()
{
}
/**
* Render screen contents (context is ready for 2D rendering)
*/
protected abstract void renderScreen();
}

@ -1,36 +0,0 @@
package mightypork.gamecore.gui.screens;
import mightypork.gamecore.eventbus.BusEvent;
/**
* @author MightyPork
*/
public class CrossfadeRequest extends BusEvent<CrossfadeRequest.Listener> {
private final String screen;
/**
* @param screen screen key to show. Null = exit the app.
*/
public CrossfadeRequest(String screen)
{
super();
this.screen = screen;
}
public interface Listener {
void goToScreen(String screen);
}
@Override
public void handleBy(Listener handler)
{
handler.goToScreen(screen);
}
}

@ -14,7 +14,7 @@ import mightypork.gamecore.eventbus.clients.DelegatingClient;
* *
* @author MightyPork * @author MightyPork
*/ */
public abstract class LayeredScreen extends BaseScreen { public abstract class LayeredScreen extends Screen {
private class LayersClient implements DelegatingClient { private class LayersClient implements DelegatingClient {

@ -2,34 +2,157 @@ package mightypork.gamecore.gui.screens;
import mightypork.gamecore.app.AppAccess; import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.app.AppSubModule;
import mightypork.gamecore.gui.events.LayoutChangeEvent;
import mightypork.gamecore.gui.events.LayoutChangeListener;
import mightypork.gamecore.input.KeyBinder;
import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.render.DisplaySystem;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.render.Renderable; import mightypork.gamecore.render.Renderable;
import mightypork.gamecore.util.annot.DefaultImpl;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound; import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
/** /**
* Game screen * Screen class.
* *
* @author MightyPork * @author MightyPork
*/ */
public interface Screen extends Renderable, RectBound, AppAccess { public abstract class Screen extends AppSubModule implements Renderable, RectBound, AppAccess, KeyBinder, LayoutChangeListener {
private final KeyBindingPool keybindings = new KeyBindingPool();
private volatile boolean active;
private volatile boolean needSetupViewport = false;
/**
* @param app app access
*/
public Screen(AppAccess app) {
super(app);
// disable events initially
setListening(false);
addChildClient(keybindings);
}
private void fireLayoutChangeEvent()
{
getEventBus().sendDirectToChildren(this, new LayoutChangeEvent());
}
@Override
public final void bindKey(KeyStroke stroke, Runnable task)
{
keybindings.bindKey(stroke, task);
}
@Override
public final void unbindKey(KeyStroke stroke)
{
keybindings.unbindKey(stroke);
}
/** /**
* Prepare for being shown * Prepare for being shown
* *
* @param shown true to show, false to hide * @param shown true to show, false to hide
*/ */
void setActive(boolean shown); public final void setActive(boolean shown)
{
if (shown) {
active = true;
needSetupViewport = true;
fireLayoutChangeEvent();
onScreenEnter();
// enable events
setListening(true);
} else {
onScreenLeave();
active = false;
// disable events
setListening(false);
}
}
/** /**
* @return true if screen is the current screen * @return true if screen is the current screen
*/ */
boolean isActive(); public final boolean isActive()
{
return active;
}
@Override
public void onLayoutChanged()
{
if (!isActive()) return;
needSetupViewport = true;
}
@Override
public final Rect getRect()
{
return getDisplay().getRect();
}
@Override
public void render()
{
if (!isActive()) return;
if (needSetupViewport) {
Render.setupOrtho(DisplaySystem.getSize());
}
Render.pushState();
renderScreen();
Render.popState();
}
/**
* Called when the screen becomes active
*/
@DefaultImpl
protected void onScreenEnter()
{
}
/**
* Called when the screen is no longer active
*/
@DefaultImpl
protected void onScreenLeave()
{
}
/** /**
* @return screen identifier to be used for requests. * Render screen contents (context is ready for 2D rendering)
*/ */
String getName(); protected abstract void renderScreen();
} }

@ -43,9 +43,9 @@ public class ScreenRegistry extends AppModule implements ScreenRequestListener,
* *
* @param screen added screen * @param screen added screen
*/ */
public void addScreen(Screen screen) public void addScreen(String name, Screen screen)
{ {
screens.put(screen.getName(), screen); screens.put(name, screen);
addChildClient(screen); addChildClient(screen);
} }

@ -1,9 +1,10 @@
package mightypork.gamecore.gui.screens; package mightypork.gamecore.gui.screens.impl;
import mightypork.gamecore.app.AppAccess; import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.events.ScreenRequestEvent; import mightypork.gamecore.gui.events.ScreenRequestEvent;
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.Color;
import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated; import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated;
@ -12,17 +13,17 @@ import mightypork.rogue.events.ActionRequest;
import mightypork.rogue.events.ActionRequest.RequestType; import mightypork.rogue.events.ActionRequest.RequestType;
public class CrossfadeOverlay extends Overlay implements CrossfadeRequest.Listener { 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 level = new NumAnimated(0); NumAnimated blackLevel = new NumAnimated(0);
Color color = Color.dark(level); Color color = Color.dark(blackLevel);
String requestedScreenName; String requestedScreenName;
TimedTask tt = new TimedTask() { TimedTask revealTask = new TimedTask() {
@Override @Override
public void run() public void run()
@ -32,51 +33,45 @@ public class CrossfadeOverlay extends Overlay implements CrossfadeRequest.Listen
} else { } else {
getEventBus().send(new ScreenRequestEvent(requestedScreenName)); getEventBus().send(new ScreenRequestEvent(requestedScreenName));
} }
} blackLevel.setEasing(Easing.SINE_OUT);
}; blackLevel.fadeOut(T_OUT);
TimedTask tt2 = new TimedTask() {
@Override
public void run()
{
level.setEasing(Easing.SINE_OUT);
level.fadeOut(T_OUT);
} }
}; };
public CrossfadeOverlay(AppAccess app) public CrossfadeOverlay(AppAccess app) {
{
super(app); super(app);
final QuadPainter qp = new QuadPainter(color); final QuadPainter qp = new QuadPainter(color);
qp.setRect(root); qp.setRect(root);
root.add(qp); root.add(qp);
updated.add(level); updated.add(blackLevel);
updated.add(tt); updated.add(revealTask);
updated.add(tt2);
} }
@Override @Override
public int getZIndex() public int getZIndex()
{ {
return Integer.MAX_VALUE - 1; // let FPS go on top return 10000; // not too high, so app can put something on top
} }
@Override public void goToScreen(String screen, boolean fromDark)
public void goToScreen(String screen)
{ {
tt.start(T_IN);
tt2.start(T_IN);
level.setEasing(Easing.SINE_IN);
level.fadeIn(T_IN);
requestedScreenName = screen; requestedScreenName = screen;
if (fromDark) {
blackLevel.setTo(1);
revealTask.run();
} else {
revealTask.start(T_IN);
blackLevel.setEasing(Easing.SINE_IN);
blackLevel.fadeIn(T_IN);
}
} }
} }

@ -1,26 +1,30 @@
package mightypork.rogue.screens.test_cat_sound; package mightypork.gamecore.gui.screens.impl;
import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.screens.BaseScreen; import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.util.math.color.Color; import mightypork.gamecore.util.math.color.Color;
public class LayerColor extends ScreenLayer { public class LayerColor extends ScreenLayer {
public LayerColor(BaseScreen screen, Color color) private int zIndex;
public LayerColor(Screen screen, Color color, int zIndex)
{ {
super(screen); super(screen);
root.add(new QuadPainter(color)); root.add(new QuadPainter(color));
this.zIndex = zIndex;
} }
@Override @Override
public int getZIndex() public int getZIndex()
{ {
return Integer.MIN_VALUE; return this.zIndex;
} }
} }

@ -106,7 +106,7 @@ public class FontRenderer {
{ {
Render.pushMatrix(); Render.pushMatrix();
Render.translateXY(pos.round()); Render.translateXY(pos);
Render.scaleXY(getScale(height)); Render.scaleXY(getScale(height));
font.draw(text, color); font.draw(text, color);

@ -104,7 +104,7 @@ public class Ion {
try { try {
objClass.getConstructor(); objClass.getConstructor();
} catch (NoSuchMethodException | SecurityException e) { } catch (NoSuchMethodException | SecurityException e) {
throw new IllegalArgumentException("Class " + Log.str(objClass) + " doesn't have an implicit constructor."); throw new RuntimeException("Class " + Log.str(objClass) + " doesn't have an implicit constructor.");
} }
registered[mark] = objClass; registered[mark] = objClass;

@ -46,7 +46,10 @@ public class Coord implements IonObjBundled, IonObjBinary {
{ {
return make(0, 0); return make(0, 0);
} }
public Coord() {
// for ion
}
public Coord(int x, int y) { public Coord(int x, int y) {
super(); super();

@ -3,40 +3,50 @@ package mightypork.gamecore.util.math.algo;
public class Sides { public class Sides {
public static final byte NW = (byte) 0b10000000; public static final byte MASK_NW = (byte) 0b10000000;
public static final byte N = (byte) 0b01000000; public static final byte MASK_N = (byte) 0b01000000;
public static final byte NE = (byte) 0b00100000; public static final byte MASK_NE = (byte) 0b00100000;
public static final byte E = (byte) 0b00010000; public static final byte MASK_E = (byte) 0b00010000;
public static final byte SE = (byte) 0b00001000; public static final byte MASK_SE = (byte) 0b00001000;
public static final byte S = (byte) 0b00000100; public static final byte MASK_S = (byte) 0b00000100;
public static final byte SW = (byte) 0b00000010; public static final byte MASK_SW = (byte) 0b00000010;
public static final byte W = (byte) 0b00000001; public static final byte MASK_W = (byte) 0b00000001;
public static final byte CARDINAL = N | S | E | W; public static final byte CARDINAL = MASK_N | MASK_S | MASK_E | MASK_W;
public static final byte DIAGONAL = NE | NW | SE | SW; public static final byte DIAGONAL = MASK_NE | MASK_NW | MASK_SE | MASK_SW;
public static final byte NW_CORNER = W | NW | N; public static final byte NW_CORNER = MASK_W | MASK_NW | MASK_N;
public static final byte NE_CORNER = E | NE | N; public static final byte NE_CORNER = MASK_E | MASK_NE | MASK_N;
public static final byte SW_CORNER = W | SW | S; public static final byte SW_CORNER = MASK_W | MASK_SW | MASK_S;
public static final byte SE_CORNER = E | SE | S; public static final byte SE_CORNER = MASK_E | MASK_SE | MASK_S;
public static final Step NW = Step.make(-1, -1);
public static final Step N = Step.make(0, -1);
public static final Step NE = Step.make(1, -1);
public static final Step E = Step.make(1, 0);
public static final Step SE = Step.make(1, 1);
public static final Step S = Step.make(0, 1);
public static final Step SW = Step.make(-1, 1);
public static final Step W = Step.make(-1, 0);
//@formatter:off //@formatter:off
/** All sides, in the order of bits. */
public final static Step[] allSides = { public final static Step[] allSides = {
Step.make(-1, -1), NW,
Step.make(0, -1), N,
Step.make(1, -1), NE,
Step.make(1, 0), E,
Step.make(1, 1), SE,
Step.make(0, 1), S,
Step.make(-1, 1), SW,
Step.make(-1, 0) W
}; };
public final static Step[] cardinalSides = { public final static Step[] cardinalSides = {
Step.make(0, -1), N,
Step.make(1, 0), E,
Step.make(0, 1), S,
Step.make(-1, 0) W
}; };
//@formatter:on //@formatter:on

@ -43,7 +43,10 @@ public class Step implements IonObjBinary, IonObjBundled {
private byte x; private byte x;
private byte y; private byte y;
public Step() {
// for ion
}
public Step(int x, int y) { public Step(int x, int y) {
this.x = (byte) (x < 0 ? -1 : x > 0 ? 1 : 0); this.x = (byte) (x < 0 ? -1 : x > 0 ? 1 : 0);

@ -13,6 +13,7 @@ public interface RGB {
Color WHITE = Color.fromHex(0xFFFFFF); Color WHITE = Color.fromHex(0xFFFFFF);
Color BLACK = Color.fromHex(0x000000); Color BLACK = Color.fromHex(0x000000);
Color GRAY_DARK = Color.fromHex(0x808080); Color GRAY_DARK = Color.fromHex(0x808080);
Color GRAY = Color.fromHex(0xA0A0A0);
Color GRAY_LIGHT = Color.fromHex(0xC0C0C0); Color GRAY_LIGHT = Color.fromHex(0xC0C0C0);
Color RED = Color.fromHex(0xFF0000); Color RED = Color.fromHex(0xFF0000);

@ -8,7 +8,7 @@ import mightypork.gamecore.app.BaseApp;
import mightypork.gamecore.app.MainLoop; import mightypork.gamecore.app.MainLoop;
import mightypork.gamecore.eventbus.BusEvent; import mightypork.gamecore.eventbus.BusEvent;
import mightypork.gamecore.eventbus.EventBus; import mightypork.gamecore.eventbus.EventBus;
import mightypork.gamecore.gui.screens.CrossfadeRequest; import mightypork.gamecore.gui.events.CrossfadeRequest;
import mightypork.gamecore.gui.screens.ScreenRegistry; import mightypork.gamecore.gui.screens.ScreenRegistry;
import mightypork.gamecore.input.InputSystem; import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.input.KeyStroke;
@ -21,11 +21,9 @@ import mightypork.gamecore.util.ion.Ion;
import mightypork.rogue.events.ActionRequest; import mightypork.rogue.events.ActionRequest;
import mightypork.rogue.events.ActionRequest.RequestType; import mightypork.rogue.events.ActionRequest.RequestType;
import mightypork.rogue.screens.FpsOverlay; import mightypork.rogue.screens.FpsOverlay;
import mightypork.rogue.screens.gamescreen.ScreenGame; import mightypork.rogue.screens.game.ScreenGame;
import mightypork.rogue.screens.main_menu.ScreenMainMenu; import mightypork.rogue.screens.menu.ScreenMainMenu;
import mightypork.rogue.screens.test_bouncyboxes.ScreenTestBouncy; import mightypork.rogue.screens.test_bouncyboxes.ScreenTestBouncy;
import mightypork.rogue.screens.test_cat_sound.ScreenTestCat;
import mightypork.rogue.screens.test_render.ScreenTestRender;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.item.Item; import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.Level;
@ -61,8 +59,6 @@ public final class App extends BaseApp {
{ {
Config.init(); Config.init();
Config.save(); Config.save();
WorldProvider.init(this);
} }
@ -115,11 +111,13 @@ public final class App extends BaseApp {
{ {
super.initScreens(screens); super.initScreens(screens);
screens.addScreen(new ScreenTestBouncy(this)); /* game screen references world provider instance */
screens.addScreen(new ScreenTestCat(this)); WorldProvider.init(this);
screens.addScreen(new ScreenTestRender(this));
screens.addScreen(new ScreenMainMenu(this)); screens.addScreen("test.bouncy", new ScreenTestBouncy(this));
screens.addScreen(new ScreenGame(this));
screens.addScreen("menu", new ScreenMainMenu(this));
screens.addScreen("game", new ScreenGame(this));
screens.addOverlay(new FpsOverlay(this)); screens.addOverlay(new FpsOverlay(this));
} }
@ -131,18 +129,10 @@ public final class App extends BaseApp {
// this will work only with reusable events (such as requests) // this will work only with reusable events (such as requests)
bindEventToKey(new ActionRequest(RequestType.FULLSCREEN), Keys.F11); bindEventToKey(new ActionRequest(RequestType.FULLSCREEN), Keys.F11);
bindEventToKey(new ActionRequest(RequestType.SCREENSHOT), Keys.F2); bindEventToKey(new ActionRequest(RequestType.SCREENSHOT), Keys.F2);
bindEventToKey(new CrossfadeRequest(null), Keys.L_CONTROL, Keys.Q); bindEventToKey(new CrossfadeRequest(null), Keys.L_CONTROL, Keys.Q);
bindEventToKey(new CrossfadeRequest("main_menu"), Keys.L_CONTROL, Keys.M);
// TODO tmp bindEventToKey(new CrossfadeRequest("menu"), Keys.ESCAPE);
getInput().bindKey(new KeyStroke(Keys.N), new Runnable() {
@Override
public void run()
{
WorldProvider.get().createWorld(Double.doubleToLongBits(Math.random()));
}
});
} }
@ -172,6 +162,6 @@ public final class App extends BaseApp {
// TODO tmp // TODO tmp
WorldProvider.get().createWorld(42); WorldProvider.get().createWorld(42);
getEventBus().send(new CrossfadeRequest("game_screen")); getEventBus().send(new CrossfadeRequest("menu", true));
} }
} }

@ -63,10 +63,6 @@ public final class Res {
GLTexture texture; GLTexture texture;
QuadGrid tiles; QuadGrid tiles;
// tests
texture = textures.loadTexture("test.kitten", "/res/img/kitten.png", FilterMode.LINEAR, WrapMode.CLAMP);
texture = textures.loadTexture("test.kitten2", "/res/img/kitten_npot.png", FilterMode.LINEAR, WrapMode.CLAMP);
// gui // gui
texture = textures.loadTexture("gui1", "/res/img/gui1.png", FilterMode.NEAREST, WrapMode.CLAMP); texture = textures.loadTexture("gui1", "/res/img/gui1.png", FilterMode.NEAREST, WrapMode.CLAMP);
final QuadGrid gui = texture.grid(4, 4); final QuadGrid gui = texture.grid(4, 4);
@ -85,14 +81,16 @@ public final class Res {
textures.addSheet("sprite.player", tiles.makeSheet(0, 0, 4, 1)); textures.addSheet("sprite.player", tiles.makeSheet(0, 0, 4, 1));
// small sheet // small sheet
texture = textures.loadTexture("tiles16", "/res/img/tiles16.png", FilterMode.NEAREST, WrapMode.CLAMP); texture = textures.loadTexture("tiles", "/res/img/tiles16.png", FilterMode.NEAREST, WrapMode.CLAMP);
tiles = texture.grid(8, 8); tiles = texture.grid(8, 8);
textures.addSheet("tile.floor.dark", tiles.makeSheet(0, 1, 5, 1)); textures.addSheet("tile.brick.floor", tiles.makeSheet(0, 1, 5, 1));
textures.addSheet("tile.wall.brick", tiles.makeSheet(0, 0, 5, 1)); textures.addSheet("tile.brick.wall", tiles.makeSheet(0, 0, 5, 1));
textures.addSheet("tile.brick.door.closed", tiles.makeSheet(1, 2, 1, 1));
textures.addSheet("tile.brick.door.open", tiles.makeSheet(2, 2, 1, 1));
textures.addQuad("tile.door.closed", tiles.makeQuad(1, 2)); textures.addSheet("tile.brick.passage", tiles.makeSheet(3, 2, 2, 1));
textures.addQuad("tile.door.open", tiles.makeQuad(2, 2));
textures.addQuad("tile.shadow.n", tiles.makeQuad(0, 7)); textures.addQuad("tile.shadow.n", tiles.makeQuad(0, 7));
textures.addQuad("tile.shadow.s", tiles.makeQuad(0, 7).flipY()); textures.addQuad("tile.shadow.s", tiles.makeQuad(0, 7).flipY());
@ -120,8 +118,6 @@ public final class Res {
private static void loadSounds() private static void loadSounds()
{ {
sounds.addEffect("gui.shutter", "/res/audio/shutter.ogg", 1, 1); sounds.addEffect("gui.shutter", "/res/audio/shutter.ogg", 1, 1);
//sounds.addLoop("test.wilderness", "/res/audio/wilderness.ogg", 1, 1, 3, 3);
} }

@ -53,7 +53,7 @@ public class FpsOverlay extends Overlay {
}); });
tp.setRect(constraint); tp.setRect(constraint);
tp.setShadow(Color.BLACK, Vect.make(tp.height().div(16))); tp.setShadow(Color.BLACK, Vect.make(tp.height().div(16).round()));
root.add(tp); root.add(tp);
} }

@ -1,4 +1,4 @@
package mightypork.rogue.screens.gamescreen; package mightypork.rogue.screens.game;
import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.AlignX;

@ -1,4 +1,4 @@
package mightypork.rogue.screens.gamescreen; package mightypork.rogue.screens.game;
import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.AlignX;

@ -1,4 +1,4 @@
package mightypork.rogue.screens.gamescreen; package mightypork.rogue.screens.game;
import mightypork.gamecore.eventbus.events.Updateable; import mightypork.gamecore.eventbus.events.Updateable;

@ -1,27 +1,36 @@
package mightypork.rogue.screens.gamescreen; package mightypork.rogue.screens.game;
import java.util.Random;
import mightypork.gamecore.app.AppAccess; import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.gui.screens.LayeredScreen; import mightypork.gamecore.gui.screens.LayeredScreen;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;
public class ScreenGame extends LayeredScreen { public class ScreenGame extends LayeredScreen {
private Random rand = new Random();
public ScreenGame(AppAccess app) public ScreenGame(AppAccess app)
{ {
super(app); super(app);
addLayer(new HudLayer(this)); addLayer(new HudLayer(this));
addLayer(new WorldLayer(this)); addLayer(new WorldLayer(this));
}
bindKey(new KeyStroke(Keys.N), new Runnable() {
@Override @Override
public String getName() public void run()
{ {
return "game_screen"; WorldProvider.get().createWorld(rand .nextLong());
}
});
} }

@ -1,4 +1,4 @@
package mightypork.rogue.screens.gamescreen; package mightypork.rogue.screens.game;
import mightypork.gamecore.gui.screens.Screen; import mightypork.gamecore.gui.screens.Screen;

@ -1,12 +1,12 @@
package mightypork.rogue.screens.main_menu; package mightypork.rogue.screens.menu;
import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.ClickableComponent; import mightypork.gamecore.gui.components.ClickableComponent;
import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.resources.fonts.GLFont; 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.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.vect.Vect; import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.gamecore.util.math.constraints.vect.mutable.VectVar; import mightypork.gamecore.util.math.constraints.vect.mutable.VectVar;
import mightypork.rogue.Res; import mightypork.rogue.Res;
@ -16,18 +16,20 @@ class MenuButton extends ClickableComponent {
private static GLFont font = Res.getFont("main_menu_button"); private static GLFont font = Res.getFont("main_menu_button");
private final TextPainter painter; private final TextPainter painter;
private final VectVar offset = Vect.makeVar();
private final Vect offsetActive = Vect.make(this.height().perc(-5), Num.ZERO); private final VectVar offset = Vect.makeVar();
private final Vect offsetPassive = height().div(16).toVectXY();
private final Vect offsetPassive2 = height().div(24).toVectXY();
private final Color color; private final Color color;
public MenuButton(String text, Color color) public MenuButton(String text, Color color) {
{
this.color = color; this.color = color;
this.painter = new TextPainter(font, AlignX.CENTER, this.color, text); this.painter = new TextPainter(font, AlignX.CENTER, this.color, text);
this.painter.setRect(this.shrink(this.height().perc(8)).move(offset)); this.painter.setRect(this);
this.painter.setShadow(Color.BLACK.withAlpha(0.3), height().div(24).toVectXY()); this.painter.setShadow(Color.BLACK.withAlpha(0.3), offset);
} }
@ -35,9 +37,13 @@ class MenuButton extends ClickableComponent {
protected void renderComponent() protected void renderComponent()
{ {
if (isMouseOver()) { if (isMouseOver()) {
offset.setTo(offsetActive); if (InputSystem.isMouseButtonDown(0)) {
offset.setTo(Vect.ZERO);
} else {
offset.setTo(offsetPassive2);
}
} else { } else {
offset.setTo(Vect.ZERO); offset.setTo(offsetPassive);
} }
painter.render(); painter.render();

@ -1,4 +1,4 @@
package mightypork.rogue.screens.main_menu; package mightypork.rogue.screens.menu;
import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.Action;
@ -6,8 +6,8 @@ import mightypork.gamecore.gui.AlignX;
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.BaseScreen; import mightypork.gamecore.gui.events.CrossfadeRequest;
import mightypork.gamecore.gui.screens.CrossfadeRequest; import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.util.math.color.pal.COMMODORE; import mightypork.gamecore.util.math.color.pal.COMMODORE;
import mightypork.gamecore.util.math.color.pal.PAL16; import mightypork.gamecore.util.math.color.pal.PAL16;
@ -18,8 +18,7 @@ import mightypork.rogue.Res;
class MenuLayer extends ScreenLayer { class MenuLayer extends ScreenLayer {
public MenuLayer(BaseScreen screen) public MenuLayer(Screen screen) {
{
super(screen); super(screen);
init(); init();
@ -39,49 +38,31 @@ class MenuLayer extends ScreenLayer {
root.add(layout); root.add(layout);
TextPainter tp;
MenuButton b0, b1, b2, b3, b4;
tp = new TextPainter(Res.getFont("main_menu_title"), AlignX.CENTER, COMMODORE.PURPLE, "Rogue!");
b0 = new MenuButton("World Test", PAL16.SLIMEGREEN);
b1 = new MenuButton("Gradientz", PAL16.BLAZE);
b2 = new MenuButton("Bouncy Cubes", PAL16.CLOUDBLUE);
b3 = new MenuButton("Flying Cat", PAL16.PIGMEAT);
b4 = new MenuButton("Bye!", PAL16.BLOODRED);
int r = 0; int r = 0;
TextPainter tp = new TextPainter(Res.getFont("main_menu_title"), AlignX.CENTER, COMMODORE.PURPLE, "Rogue!");
layout.put(tp, r, 0, 3, 1); layout.put(tp, r, 0, 3, 1);
r += 5; r += 5;
layout.put(b0, r, 0, 2, 1);
r += 3;
layout.put(b1, r, 0, 2, 1);
r += 2;
layout.put(b2, r, 0, 2, 1);
r += 2;
layout.put(b3, r, 0, 2, 1);
r += 3;
layout.put(b4, r, 0, 2, 1);
root.add(layout); MenuButton btn;
b0.setAction(new Action() {
@Override
protected void execute()
{
getEventBus().send(new CrossfadeRequest("game_screen"));
}
});
b1.setAction(new Action() { // world button
btn = new MenuButton("World Test", PAL16.SLIMEGREEN);
btn.setAction(new Action() {
@Override @Override
protected void execute() protected void execute()
{ {
getEventBus().send(new CrossfadeRequest("test.render")); getEventBus().send(new CrossfadeRequest("game"));
} }
}); });
layout.put(btn, r, 0, 2, 1);
r += 3;
b2.setAction(new Action() { // bouncy text button
btn = new MenuButton("Bouncy Cubes Test", PAL16.CLOUDBLUE);
btn.setAction(new Action() {
@Override @Override
protected void execute() protected void execute()
@ -89,18 +70,13 @@ class MenuLayer extends ScreenLayer {
getEventBus().send(new CrossfadeRequest("test.bouncy")); getEventBus().send(new CrossfadeRequest("test.bouncy"));
} }
}); });
layout.put(btn, r, 0, 2, 1);
r += 3;
b3.setAction(new Action() {
@Override
protected void execute()
{
getEventBus().send(new CrossfadeRequest("test.cat"));
}
});
b4.setAction(new Action() { // quit button
btn = new MenuButton("Bye!", PAL16.BLOODRED);
btn.setAction(new Action() {
@Override @Override
protected void execute() protected void execute()
@ -108,6 +84,10 @@ class MenuLayer extends ScreenLayer {
getEventBus().send(new CrossfadeRequest(null)); // null -> fade and halt getEventBus().send(new CrossfadeRequest(null)); // null -> fade and halt
} }
}); });
layout.put(btn, r, 0, 2, 1);
root.add(layout);
} }

@ -1,4 +1,4 @@
package mightypork.rogue.screens.main_menu; package mightypork.rogue.screens.menu;
import mightypork.gamecore.app.AppAccess; import mightypork.gamecore.app.AppAccess;
@ -13,12 +13,4 @@ public class ScreenMainMenu extends LayeredScreen {
addLayer(new MenuLayer(this)); addLayer(new MenuLayer(this));
} }
@Override
public String getName()
{
return "main_menu";
}
} }

@ -7,7 +7,7 @@ import java.util.List;
import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.layout.RowHolder; import mightypork.gamecore.gui.components.layout.RowHolder;
import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.BaseScreen; import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys; import mightypork.gamecore.input.Keys;
@ -23,7 +23,7 @@ public class LayerBouncyBoxes extends ScreenLayer {
private RowHolder layout; private RowHolder layout;
public LayerBouncyBoxes(BaseScreen screen) public LayerBouncyBoxes(Screen screen)
{ {
super(screen); super(screen);

@ -7,23 +7,10 @@ import mightypork.gamecore.gui.screens.LayeredScreen;
public class ScreenTestBouncy extends LayeredScreen { public class ScreenTestBouncy extends LayeredScreen {
private final LayerBouncyBoxes layer; public ScreenTestBouncy(AppAccess app) {
public ScreenTestBouncy(AppAccess app)
{
super(app); super(app);
layer = new LayerBouncyBoxes(this); addLayer(new LayerBouncyBoxes(this));
addLayer(layer);
}
@Override
public String getName()
{
return "test.bouncy";
} }
} }

@ -1,108 +0,0 @@
package mightypork.rogue.screens.test_cat_sound;
import java.util.Random;
import mightypork.gamecore.gui.AlignX;
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.BaseScreen;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.input.events.MouseButtonEvent;
import mightypork.gamecore.input.events.MouseButtonListener;
import mightypork.gamecore.util.math.Easing;
import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.gamecore.util.math.constraints.vect.mutable.VectAnimated;
import mightypork.rogue.Res;
public class LayerFlyingCat extends ScreenLayer implements MouseButtonListener {
private final NumAnimated size = new NumAnimated(300, Easing.SINE_BOTH);
private final VectAnimated cat_position = VectAnimated.makeVar(Easing.ELASTIC_OUT);
private final Random rand = new Random();
public LayerFlyingCat(BaseScreen screen)
{
super(screen);
// timing
updated.add(size);
updated.add(cat_position);
size.setTo(root.height().perc(60));
// cat
cat_position.setTo(getDisplay().getCenter());
cat_position.setDefaultDuration(3);
final ImagePainter cat = new ImagePainter(Res.getTxQuad("test.kitten2"));
cat.setRect(Rect.make(size).centerTo(cat_position));
cat.enableCaching(false);
// frame around cat
final QuadPainter cat_frame = QuadPainter.gradV(Color.YELLOW, Color.RED);
cat_frame.setRect(cat.grow(cat.height().mul(0.05)));
cat_frame.enableCaching(false);
// frame shadow
final QuadPainter cat_shadow = new QuadPainter(Color.dark(0.4));
cat_shadow.setRect(cat_frame.move(Vect.make(cat.height().mul(0.05))));
cat_shadow.enableCaching(false);
// add to root layout
root.add(cat_shadow);
root.add(cat_frame);
root.add(cat);
// Meow
final TextPainter tp = new TextPainter(Res.getFont("press_start"));
tp.setAlign(AlignX.CENTER);
tp.setColor(Color.YELLOW);
tp.setText("Meow!");
tp.setShadow(Color.dark(0.5), Vect.make(tp.height().div(16)));
tp.setRect(Rect.make(cat.height().half()).centerTo(mouse));
tp.enableCaching(false);
root.add(tp);
/*
* Register keys
*/
bindKey(new KeyStroke(Keys.RETURN), new Runnable() {
@Override
public void run()
{
cat_position.setTo(getDisplay().getCenter());
}
});
}
@Override
public void receive(MouseButtonEvent event)
{
if (!event.isDown()) return;
cat_position.animate(event.getPos());
final double newSize = root.height().perc(10 + rand.nextInt(40)).value();
size.animate(newSize, 1);
}
@Override
public int getZIndex()
{
return 10;
}
}

@ -1,52 +0,0 @@
package mightypork.rogue.screens.test_cat_sound;
import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.gui.screens.LayeredScreen;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys;
import mightypork.rogue.events.ActionRequest;
import mightypork.rogue.events.ActionRequest.RequestType;
public class ScreenTestCat extends LayeredScreen {
public ScreenTestCat(AppAccess app)
{
super(app);
addLayer(new LayerFlyingCat(this));
bindKey(new KeyStroke(Keys.ESCAPE), new Runnable() {
@Override
public void run()
{
getSoundSystem().fadeOutAllLoops();
getEventBus().sendDelayed(new ActionRequest(RequestType.SHUTDOWN), 3);
}
});
}
@Override
protected void onScreenEnter()
{
getSoundSystem().fadeOutAllLoops();
//Res.getLoop("test.wilderness").fadeIn();
}
@Override
protected void onScreenLeave()
{
//Res.getLoop("test.wilderness").fadeOut();
}
@Override
public String getName()
{
return "test.cat";
}
}

@ -1,41 +0,0 @@
package mightypork.rogue.screens.test_render;
import mightypork.gamecore.gui.screens.BaseScreen;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.render.Render;
import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
public class LayerTestGradient extends ScreenLayer {
private final RectBound pos1;
private final RectBound pos2;
public LayerTestGradient(BaseScreen screen)
{
super(screen);
pos1 = root.topEdge().growDown(64);
pos2 = root.leftEdge().growUp(-64).growRight(64);
}
@Override
public void render()
{
Render.quadColor(root, Color.WHITE, Color.BLUE, Color.BLACK, Color.MAGENTA);
Render.quadGradH(pos1.getRect(), Color.GREEN, Color.RED);
Render.quadGradV(pos2.getRect(), Color.WHITE, Color.MAGENTA);
}
@Override
public int getZIndex()
{
return 0;
}
}

@ -1,24 +0,0 @@
package mightypork.rogue.screens.test_render;
import mightypork.gamecore.app.AppAccess;
import mightypork.gamecore.gui.screens.LayeredScreen;
public class ScreenTestRender extends LayeredScreen {
public ScreenTestRender(AppAccess app)
{
super(app);
addLayer(new LayerTestGradient(this));
}
@Override
public String getName()
{
return "test.render";
}
}

@ -107,7 +107,7 @@ public class WorldRenderer extends RectProxy {
// batch rendering of the tiles // batch rendering of the tiles
if (USE_BATCH_RENDERING) { if (USE_BATCH_RENDERING) {
Render.enterBatchTexturedQuadMode(Res.getTexture("tiles16")); 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++) {

@ -6,19 +6,19 @@ import java.util.Random;
import mightypork.gamecore.util.math.algo.Coord; import mightypork.gamecore.util.math.algo.Coord;
import mightypork.rogue.world.gen.rooms.DeadEndRoom; import mightypork.rogue.world.gen.rooms.DeadEndRoom;
import mightypork.rogue.world.gen.rooms.SimpleRectRoom; import mightypork.rogue.world.gen.rooms.SimpleRectRoom;
import mightypork.rogue.world.gen.themes.ThemeDungeon; import mightypork.rogue.world.gen.themes.ThemeBrick;
import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.Level;
public class LevelGenerator { public class LevelGenerator {
public static final Theme DUNGEON_THEME = new ThemeDungeon(); public static final MapTheme DUNGEON_THEME = new ThemeBrick();
public static final RoomBuilder ROOM_SQUARE = new SimpleRectRoom(); public static final RoomBuilder ROOM_SQUARE = new SimpleRectRoom();
private static final RoomBuilder DEAD_END = new DeadEndRoom(); private static final RoomBuilder DEAD_END = new DeadEndRoom();
public static Level build(long seed, int complexity, Theme theme) public static Level build(long seed, int complexity, MapTheme theme)
{ {
final Random rand = new Random(seed + 13); final Random rand = new Random(seed + 13);
@ -31,7 +31,7 @@ public class LevelGenerator {
for (int i = 0; i < 2 + complexity / 2 + rand.nextInt((int) (1 + complexity * 0.3)); i++) { for (int i = 0; i < 2 + complexity / 2 + rand.nextInt((int) (1 + complexity * 0.3)); i++) {
map.addRoom(ROOM_SQUARE); map.addRoom(ROOM_SQUARE);
if (rand.nextInt(4) > 0) map.addRoom(DEAD_END); if (rand.nextInt(6) > 0) map.addRoom(DEAD_END);
} }
map.buildCorridors(); map.buildCorridors();

@ -9,7 +9,7 @@ import mightypork.rogue.world.tile.TileModel;
* *
* @author MightyPork * @author MightyPork
*/ */
public interface Theme { public interface MapTheme {
TileModel wall(); TileModel wall();
@ -18,4 +18,6 @@ public interface Theme {
TileModel door(); TileModel door();
TileModel passage();
} }

@ -13,5 +13,5 @@ import mightypork.gamecore.util.math.algo.Coord;
*/ */
public interface RoomBuilder { public interface RoomBuilder {
RoomDesc buildToFit(ScratchMap map, Theme theme, Random rand, Coord center); RoomDesc buildToFit(ScratchMap map, MapTheme theme, Random rand, Coord center);
} }

@ -56,6 +56,7 @@ public class ScratchMap {
return 60; return 60;
case DOOR: case DOOR:
case PASSAGE:
return 10; return 10;
case FLOOR: case FLOOR:
@ -97,14 +98,14 @@ public class ScratchMap {
Coord genMin; Coord genMin;
Coord genMax; Coord genMax;
private final Theme theme; private final MapTheme theme;
private final Random rand; private final Random rand;
private Coord enterPoint; private Coord enterPoint;
private static final boolean FIX_GLITCHES = true; private static final boolean FIX_GLITCHES = true;
public ScratchMap(int max_size, Theme theme, Random rand) public ScratchMap(int max_size, MapTheme theme, Random rand)
{ {
map = new Tile[max_size][max_size]; map = new Tile[max_size][max_size];

@ -4,22 +4,24 @@ package mightypork.rogue.world.gen.rooms;
import java.util.Random; import java.util.Random;
import mightypork.gamecore.util.math.algo.Coord; import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.algo.Sides;
import mightypork.rogue.world.gen.RoomBuilder; import mightypork.rogue.world.gen.RoomBuilder;
import mightypork.rogue.world.gen.RoomDesc; import mightypork.rogue.world.gen.RoomDesc;
import mightypork.rogue.world.gen.ScratchMap; import mightypork.rogue.world.gen.ScratchMap;
import mightypork.rogue.world.gen.Theme; import mightypork.rogue.world.gen.MapTheme;
public class DeadEndRoom implements RoomBuilder { public class DeadEndRoom implements RoomBuilder {
@Override @Override
public RoomDesc buildToFit(ScratchMap map, Theme theme, Random rand, Coord center) public RoomDesc buildToFit(ScratchMap map, MapTheme theme, Random rand, Coord center)
{ {
Coord low = center.add(-1, -1);
if (!map.isClear(center, center)) return null; Coord high = center;
if (!map.isClear(low, high)) return null;
map.set(center, theme.floor()); map.set(center, theme.floor());
return new RoomDesc(center, center); return new RoomDesc(low, high);
} }
} }

@ -8,13 +8,14 @@ import mightypork.gamecore.util.math.algo.Sides;
import mightypork.rogue.world.gen.RoomBuilder; import mightypork.rogue.world.gen.RoomBuilder;
import mightypork.rogue.world.gen.RoomDesc; import mightypork.rogue.world.gen.RoomDesc;
import mightypork.rogue.world.gen.ScratchMap; import mightypork.rogue.world.gen.ScratchMap;
import mightypork.rogue.world.gen.Theme; import mightypork.rogue.world.gen.MapTheme;
import mightypork.rogue.world.tile.TileModel;
public class SimpleRectRoom implements RoomBuilder { public class SimpleRectRoom implements RoomBuilder {
@Override @Override
public RoomDesc buildToFit(ScratchMap map, Theme theme, Random rand, Coord center) public RoomDesc buildToFit(ScratchMap map, MapTheme theme, Random rand, Coord center)
{ {
// half width, half height actually // half width, half height actually
final int width = 2 + rand.nextInt(2); final int width = 2 + rand.nextInt(2);
@ -29,6 +30,8 @@ public class SimpleRectRoom implements RoomBuilder {
map.border(min, max, theme.wall()); map.border(min, max, theme.wall());
map.protect(min, max); map.protect(min, max);
boolean holes = rand.nextInt(4) == 0;
for (int i = 0; i <= 2 + rand.nextInt(6); i++) { for (int i = 0; i <= 2 + rand.nextInt(6); i++) {
final Coord door = min.copy(); final Coord door = min.copy();
switch (rand.nextInt(4)) { switch (rand.nextInt(4)) {
@ -51,11 +54,19 @@ public class SimpleRectRoom implements RoomBuilder {
} }
if ((map.findDoors(door) & Sides.CARDINAL) == 0) { if ((map.findDoors(door) & Sides.CARDINAL) == 0) {
map.set(door, theme.door()); TileModel placed;
switch (rand.nextInt(8)) {
case 0:
case 1:
placed = theme.passage();
break;
default:
placed = holes ? theme.floor() : theme.door();
}
map.set(door, placed);
} }
} }
return new RoomDesc(min.add(-1, -1), max); return new RoomDesc(min.add(-1, -1), max);
} }
} }

@ -1,32 +1,38 @@
package mightypork.rogue.world.gen.themes; package mightypork.rogue.world.gen.themes;
import mightypork.rogue.world.gen.Theme; import mightypork.rogue.world.gen.MapTheme;
import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.Tiles; import mightypork.rogue.world.tile.Tiles;
// basic dungeon theme // basic dungeon theme
public class ThemeDungeon implements Theme { public class ThemeBrick implements MapTheme {
@Override @Override
public TileModel wall() public TileModel wall()
{ {
return Tiles.WALL_BRICK; return Tiles.BRICK_WALL;
} }
@Override @Override
public TileModel floor() public TileModel floor()
{ {
return Tiles.FLOOR_DARK; return Tiles.BRICK_FLOOR;
} }
@Override @Override
public TileModel door() public TileModel door()
{ {
return Tiles.DOOR; return Tiles.BRICK_DOOR;
} }
@Override
public TileModel passage()
{
return Tiles.BRICK_PASSAGE;
}
} }

@ -362,7 +362,7 @@ public class Level implements MapAccess, IonObjBinary {
public boolean canSpreadFrom(Coord pos) public boolean canSpreadFrom(Coord pos)
{ {
final Tile t = getTile(pos); final Tile t = getTile(pos);
return t.isWalkable() && t.getType() != TileType.DOOR; return t.isWalkable() && !t.isDoor();
} }

@ -126,7 +126,7 @@ public abstract class Tile implements IonObjBlob {
public final boolean isDoor() public final boolean isDoor()
{ {
return getType() == TileType.DOOR; return getType() == TileType.DOOR || getType() == TileType.PASSAGE;
} }

@ -72,16 +72,16 @@ public abstract class TileRenderer {
if (trd.shadows == 0) return; if (trd.shadows == 0) return;
final Rect rect = context.getRect(); final Rect rect = context.getRect();
if ((trd.shadows & Sides.NW) != 0) Render.quadTextured(rect, SH_NW); if ((trd.shadows & Sides.MASK_NW) != 0) Render.quadTextured(rect, SH_NW);
if ((trd.shadows & Sides.N) != 0) Render.quadTextured(rect, SH_N); if ((trd.shadows & Sides.MASK_N) != 0) Render.quadTextured(rect, SH_N);
if ((trd.shadows & Sides.NE) != 0) Render.quadTextured(rect, SH_NE); if ((trd.shadows & Sides.MASK_NE) != 0) Render.quadTextured(rect, SH_NE);
if ((trd.shadows & Sides.W) != 0) Render.quadTextured(rect, SH_W); if ((trd.shadows & Sides.MASK_W) != 0) Render.quadTextured(rect, SH_W);
if ((trd.shadows & Sides.E) != 0) Render.quadTextured(rect, SH_E); if ((trd.shadows & Sides.MASK_E) != 0) Render.quadTextured(rect, SH_E);
if ((trd.shadows & Sides.SW) != 0) Render.quadTextured(rect, SH_SW); if ((trd.shadows & Sides.MASK_SW) != 0) Render.quadTextured(rect, SH_SW);
if ((trd.shadows & Sides.S) != 0) Render.quadTextured(rect, SH_S); if ((trd.shadows & Sides.MASK_S) != 0) Render.quadTextured(rect, SH_S);
if ((trd.shadows & Sides.SE) != 0) Render.quadTextured(rect, SH_SE); if ((trd.shadows & Sides.MASK_SE) != 0) Render.quadTextured(rect, SH_SE);
} }
@ -103,15 +103,15 @@ public abstract class TileRenderer {
if (ufog == 0) return; if (ufog == 0) return;
final Rect rect = context.getRect(); final Rect rect = context.getRect();
if ((ufog & Sides.NW_CORNER) == Sides.NW) Render.quadTextured(rect, UFOG_NW); if ((ufog & Sides.NW_CORNER) == Sides.MASK_NW) Render.quadTextured(rect, UFOG_NW);
if ((ufog & Sides.N) != 0) Render.quadTextured(rect, UFOG_N); if ((ufog & Sides.MASK_N) != 0) Render.quadTextured(rect, UFOG_N);
if ((ufog & Sides.NE_CORNER) == Sides.NE) Render.quadTextured(rect, UFOG_NE); if ((ufog & Sides.NE_CORNER) == Sides.MASK_NE) Render.quadTextured(rect, UFOG_NE);
if ((ufog & Sides.W) != 0) Render.quadTextured(rect, UFOG_W); if ((ufog & Sides.MASK_W) != 0) Render.quadTextured(rect, UFOG_W);
if ((ufog & Sides.E) != 0) Render.quadTextured(rect, UFOG_E); if ((ufog & Sides.MASK_E) != 0) Render.quadTextured(rect, UFOG_E);
if ((ufog & Sides.SW_CORNER) == Sides.SW) Render.quadTextured(rect, UFOG_SW); if ((ufog & Sides.SW_CORNER) == Sides.MASK_SW) Render.quadTextured(rect, UFOG_SW);
if ((ufog & Sides.S) != 0) Render.quadTextured(rect, UFOG_S); if ((ufog & Sides.MASK_S) != 0) Render.quadTextured(rect, UFOG_S);
if ((ufog & Sides.SE_CORNER) == Sides.SE) Render.quadTextured(rect, UFOG_SE); if ((ufog & Sides.SE_CORNER) == Sides.MASK_SE) Render.quadTextured(rect, UFOG_SE);
} }
} }

@ -20,7 +20,9 @@ public enum TileType
/** Wall tile */ /** Wall tile */
WALL(RGB.GRAY_LIGHT, false), WALL(RGB.GRAY_LIGHT, false),
/** Door/gate tile */ /** Door/gate tile */
DOOR(PAL16.NEWPOOP, true); DOOR(PAL16.NEWPOOP, true),
/** Passage (ie secret door) */
PASSAGE(RGB.GRAY, true);
private final Color mapColor; private final Color mapColor;
private final boolean potentiallyWalkable; private final boolean potentiallyWalkable;

@ -11,6 +11,7 @@ import mightypork.rogue.world.tile.renderers.NullTileRenderer;
import mightypork.rogue.world.tile.tiles.DoorTile; import mightypork.rogue.world.tile.tiles.DoorTile;
import mightypork.rogue.world.tile.tiles.FloorTile; import mightypork.rogue.world.tile.tiles.FloorTile;
import mightypork.rogue.world.tile.tiles.NullTile; import mightypork.rogue.world.tile.tiles.NullTile;
import mightypork.rogue.world.tile.tiles.WallPassageTile;
import mightypork.rogue.world.tile.tiles.WallTile; import mightypork.rogue.world.tile.tiles.WallTile;
@ -25,9 +26,10 @@ public final class Tiles {
public static final TileModel NULL = new TileModel(0, NullTile.class, new NullTileRenderer()); public static final TileModel NULL = new TileModel(0, NullTile.class, new NullTileRenderer());
public static final TileModel FLOOR_DARK = new TileModel(10, FloorTile.class, new BasicTileRenderer("tile.floor.dark")); public static final TileModel BRICK_FLOOR = new TileModel(10, FloorTile.class, new BasicTileRenderer("tile.brick.floor"));
public static final TileModel WALL_BRICK = new TileModel(11, WallTile.class, new BasicTileRenderer("tile.wall.brick")); public static final TileModel BRICK_WALL = new TileModel(11, WallTile.class, new BasicTileRenderer("tile.brick.wall"));
public static final TileModel DOOR = new TileModel(12, DoorTile.class, new DoorTileRenderer("tile.door.closed", "tile.door.open")); public static final TileModel BRICK_DOOR = new TileModel(12, DoorTile.class, new DoorTileRenderer("tile.brick.door.closed", "tile.brick.door.open"));
public static final TileModel BRICK_PASSAGE = new TileModel(13, WallPassageTile.class, new BasicTileRenderer("tile.brick.passage"));
public static void register(int id, TileModel model) public static void register(int id, TileModel model)

@ -3,6 +3,7 @@ package mightypork.rogue.world.tile.renderers;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.textures.TxQuad; import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.gamecore.resources.textures.TxSheet;
import mightypork.gamecore.util.math.constraints.rect.Rect; import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.world.level.render.TileRenderContext; import mightypork.rogue.world.level.render.TileRenderContext;
@ -12,14 +13,14 @@ import mightypork.rogue.world.tile.TileRenderer;
public class DoorTileRenderer extends TileRenderer { public class DoorTileRenderer extends TileRenderer {
private final TxQuad closed; private final TxSheet closed;
private final TxQuad open; private final TxSheet open;
public DoorTileRenderer(String quadClosed, String quadOpen) public DoorTileRenderer(String quadClosed, String quadOpen)
{ {
this.closed = Res.getTxQuad(quadClosed); this.closed = Res.getTxSheet(quadClosed);
this.open = Res.getTxQuad(quadOpen); this.open = Res.getTxSheet(quadOpen);
} }
@ -30,9 +31,9 @@ public class DoorTileRenderer extends TileRenderer {
final Rect rect = context.getRect(); final Rect rect = context.getRect();
if (t.isOccupied()) { if (t.isOccupied()) {
Render.quadTextured(rect, open); Render.quadTextured(rect, open.getRandomQuad(context.getTileNoise()));
} else { } else {
Render.quadTextured(rect, closed); Render.quadTextured(rect, closed.getRandomQuad(context.getTileNoise()));
} }
} }

@ -0,0 +1,31 @@
package mightypork.rogue.world.tile.tiles;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.TileRenderer;
import mightypork.rogue.world.tile.TileType;
/**
* Collapsed wall that's walk-through
*
* @author MightyPork
*/
public class WallPassageTile extends SolidTile {
public WallPassageTile(TileModel model, TileRenderer renderer) {
super(model, renderer);
}
@Override
public TileType getType()
{
return TileType.PASSAGE;
}
@Override
public boolean isWalkable()
{
return true;
}
}
Loading…
Cancel
Save