diff --git a/src/mightypork/gamecore/render/DisplaySystem.java b/src/mightypork/gamecore/render/DisplaySystem.java index b00e0ad..dfe3475 100644 --- a/src/mightypork/gamecore/render/DisplaySystem.java +++ b/src/mightypork/gamecore/render/DisplaySystem.java @@ -32,7 +32,7 @@ public class DisplaySystem extends AppModule implements RectBound { private FpsMeter fpsMeter; /** Current screen size */ - private final Vect screenSize = new Vect() { + private static final Vect screenSize = new Vect() { @Override public double y() @@ -48,7 +48,7 @@ public class DisplaySystem extends AppModule implements RectBound { } }; - private final Rect rect = Rect.make(screenSize); + private static final Rect rect = Rect.make(screenSize); /** @@ -168,7 +168,7 @@ public class DisplaySystem extends AppModule implements RectBound { /** * @return true if close was requested (i.e. click on cross) */ - public boolean isCloseRequested() + public static boolean isCloseRequested() { return Display.isCloseRequested(); } @@ -179,7 +179,7 @@ public class DisplaySystem extends AppModule implements RectBound { * * @return is fullscreen */ - public boolean isFullscreen() + public static boolean isFullscreen() { return Display.isFullscreen(); } @@ -190,16 +190,27 @@ public class DisplaySystem extends AppModule implements RectBound { * * @return size */ - public Vect getSize() + public static Vect getSize() { return screenSize; } + /** + * Get screen rect. Static version of getRect(). + * + * @return size + */ + public static Rect getBounds() + { + return rect; + } + + /** * @return screen width */ - public int getWidth() + public static int getWidth() { return screenSize.xi(); } @@ -208,7 +219,7 @@ public class DisplaySystem extends AppModule implements RectBound { /** * @return screen height */ - public int getHeight() + public static int getHeight() { return screenSize.yi(); } @@ -246,7 +257,7 @@ public class DisplaySystem extends AppModule implements RectBound { @Override public Rect getRect() { - return rect; + return getBounds(); } @@ -264,7 +275,7 @@ public class DisplaySystem extends AppModule implements RectBound { * * @return screen center. */ - public Vect getCenter() + public static Vect getCenter() { return rect.center(); } diff --git a/src/mightypork/rogue/App.java b/src/mightypork/rogue/App.java index 4830170..306aa74 100644 --- a/src/mightypork/rogue/App.java +++ b/src/mightypork/rogue/App.java @@ -24,7 +24,9 @@ import mightypork.rogue.screens.test_cat_sound.ScreenTestCat; import mightypork.rogue.screens.test_render.ScreenTestRender; import mightypork.rogue.world.WorldMap; import mightypork.rogue.world.item.Item; +import mightypork.rogue.world.item.ItemData; import mightypork.rogue.world.tile.Tile; +import mightypork.rogue.world.tile.TileData; import mightypork.util.control.eventbus.EventBus; import mightypork.util.control.eventbus.events.Event; import mightypork.util.files.ion.Ion; @@ -106,9 +108,11 @@ public final class App extends BaseApp { @Override protected void preInit() { - Ion.registerIonizable(Tile.ION_MARK, Tile.class); - Ion.registerIonizable(Item.ION_MARK, Item.class); - Ion.registerIonizable(WorldMap.ION_MARK, WorldMap.class); + Ion.registerIonizable(Tile.ION_MARK, Tile.class); // 700 + Ion.registerIonizable(Item.ION_MARK, Item.class); // 701 + Ion.registerIonizable(WorldMap.ION_MARK, WorldMap.class); // 702 + Ion.registerIonizable(TileData.ION_MARK, TileData.class); // 703 + Ion.registerIonizable(ItemData.ION_MARK, ItemData.class); // 704 } diff --git a/src/mightypork/rogue/Res.java b/src/mightypork/rogue/Res.java index ae24ce8..319ae4c 100644 --- a/src/mightypork/rogue/Res.java +++ b/src/mightypork/rogue/Res.java @@ -70,17 +70,18 @@ public final class Res { QuadGrid gui = texture.grid(4, 4); textures.addQuad("item_frame", gui.makeQuad(0, 0)); textures.addQuad("sword", gui.makeQuad(1, 0)); - textures.addQuad("meat", gui.makeQuad(2, 0)); + textures.addQuad("meat", gui.makeQuad(2, 0)); textures.addQuad("heart_on", gui.makeQuad(.0, 1, .5, .5)); - textures.addQuad("heart_off", gui.makeQuad(.5, 1, .5, .5)); + textures.addQuad("heart_off", gui.makeQuad(.5, 1, .5, .5)); textures.addQuad("xp_on", gui.makeQuad(0, 1.5, .5, .5)); - textures.addQuad("xp_off", gui.makeQuad(.5, 1.5, .5, .5)); + textures.addQuad("xp_off", gui.makeQuad(.5, 1.5, .5, .5)); textures.addQuad("panel", gui.makeQuad(0, 3.75, 4, .25)); - + texture = textures.loadTexture("tiles", "/res/img/map_tiles.png", FilterMode.NEAREST, WrapMode.CLAMP); QuadGrid tiles = texture.grid(32, 32); - + textures.addSheet("tile.mossy_bricks.wall", tiles.makeSheet(4, 0, 7, 1)); + textures.addSheet("tile.mossy_bricks.floor", tiles.makeSheet(16, 5, 7, 1)); } @@ -104,6 +105,12 @@ public final class Res { } + public static TxSheet getTxSheet(String key) + { + return textures.getSheet(key); + } + + public static LoopPlayer getLoop(String key) { return sounds.getLoop(key); diff --git a/src/mightypork/rogue/world/EntityModel.java b/src/mightypork/rogue/world/EntityModel.java index 4e147a0..034f872 100644 --- a/src/mightypork/rogue/world/EntityModel.java +++ b/src/mightypork/rogue/world/EntityModel.java @@ -54,27 +54,6 @@ public abstract class EntityModel { public abstract D createData(); - /** - * Load an entity from ION input stream. - * - * @param data data to load - * @param in input stream - * @throws IOException - */ - public abstract void load(D data, InputStream in) throws IOException; - - - /** - * Save an entity to ION output stream. - * - * @param data data to save - * @param out output stream - * @throws IOException - */ - @DefaultImpl - public abstract void save(D data, OutputStream out) throws IOException; - - /** * Render the item according to given context. * diff --git a/src/mightypork/rogue/world/WorldMap.java b/src/mightypork/rogue/world/WorldMap.java index 48289c8..dc11685 100644 --- a/src/mightypork/rogue/world/WorldMap.java +++ b/src/mightypork/rogue/world/WorldMap.java @@ -6,12 +6,12 @@ import java.io.InputStream; import java.io.OutputStream; import mightypork.rogue.world.tile.Tile; -import mightypork.rogue.world.tile.TileHolder; +import mightypork.rogue.world.tile.TileGrid; import mightypork.util.files.ion.Ion; import mightypork.util.files.ion.Ionizable; -public class WorldMap implements TileHolder, Ionizable { +public class WorldMap implements TileGrid, Ionizable { public static final int ION_MARK = 702; diff --git a/src/mightypork/rogue/world/item/ItemData.java b/src/mightypork/rogue/world/item/ItemData.java index dc65a38..dca443d 100644 --- a/src/mightypork/rogue/world/item/ItemData.java +++ b/src/mightypork/rogue/world/item/ItemData.java @@ -6,6 +6,8 @@ package mightypork.rogue.world.item; * * @author MightyPork */ -public abstract class ItemData { +public final class ItemData { + + public static final int ION_MARK = 704; } diff --git a/src/mightypork/rogue/world/tile/TileData.java b/src/mightypork/rogue/world/tile/TileData.java index 27d7774..bf0be49 100644 --- a/src/mightypork/rogue/world/tile/TileData.java +++ b/src/mightypork/rogue/world/tile/TileData.java @@ -1,9 +1,14 @@ package mightypork.rogue.world.tile; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.Stack; import mightypork.rogue.world.item.Item; +import mightypork.util.files.ion.IonList; +import mightypork.util.files.ion.Ionizable; /** @@ -11,9 +16,39 @@ import mightypork.rogue.world.item.Item; * * @author MightyPork */ -public abstract class TileData { +public final class TileData implements Ionizable { + + public static final short ION_MARK = 703; /** Items dropped onto this tile */ - public final Stack items = new Stack<>(); + public final Stack items = new Stack<>(); + + public int id; + + public boolean[] flags; + public int[] numbers; + + + @Override + public void loadFrom(InputStream in) throws IOException + { + + } + + @Override + public void saveTo(OutputStream out) throws IOException + { + } + + @Override + public short getIonMark() + { + return 0; + } + + public Tile toTile() { + Tile t = new Tile(Tiles.get(id)); + t.s + } } diff --git a/src/mightypork/rogue/world/tile/TileHolder.java b/src/mightypork/rogue/world/tile/TileGrid.java similarity index 79% rename from src/mightypork/rogue/world/tile/TileHolder.java rename to src/mightypork/rogue/world/tile/TileGrid.java index 30f470a..960094c 100644 --- a/src/mightypork/rogue/world/tile/TileHolder.java +++ b/src/mightypork/rogue/world/tile/TileGrid.java @@ -1,7 +1,7 @@ package mightypork.rogue.world.tile; -public interface TileHolder { +public interface TileGrid { Tile getTile(int x, int y); diff --git a/src/mightypork/rogue/world/tile/TileModel.java b/src/mightypork/rogue/world/tile/TileModel.java index 299319a..e3b6584 100644 --- a/src/mightypork/rogue/world/tile/TileModel.java +++ b/src/mightypork/rogue/world/tile/TileModel.java @@ -25,7 +25,7 @@ public abstract class TileModel extends EntityModel * * @return can be walked through (if discovered / open) */ - public abstract boolean isPotentiallyWalkable(); + public abstract boolean isWalkable(); /** diff --git a/src/mightypork/rogue/world/tile/TileRenderContext.java b/src/mightypork/rogue/world/tile/TileRenderContext.java index 3cad57c..f6aa249 100644 --- a/src/mightypork/rogue/world/tile/TileRenderContext.java +++ b/src/mightypork/rogue/world/tile/TileRenderContext.java @@ -4,18 +4,22 @@ package mightypork.rogue.world.tile; import mightypork.util.constraints.rect.Rect; import mightypork.util.constraints.rect.builders.TiledRect; import mightypork.util.constraints.rect.proxy.RectBound; +import mightypork.util.math.noise.NoiseGen; public final class TileRenderContext implements RectBound { - private final TileHolder map; + private final TileGrid map; private final TiledRect tiler; - private int x, y; + private final NoiseGen noise; + public int x, y; - public TileRenderContext(TileHolder map, Rect mapArea) { + + public TileRenderContext(TileGrid map, Rect drawArea, long renderNoiseSeed) { this.map = map; - this.tiler = mapArea.tiles(map.getWidth(), map.getHeight()); + this.tiler = drawArea.tiles(map.getWidth(), map.getHeight()); + this.noise = new NoiseGen(0.2, 0, 0.5, 1, renderNoiseSeed); } @@ -36,4 +40,20 @@ public final class TileRenderContext implements RectBound { { return tiler.tile(x, y); } + + + /** + * @return per-coord noise value 0..1 + */ + public double getNoise() + { + return noise.valueAt(x, y); + } + + + public void setCoord(int x, int y) + { + this.x = x; + this.y = y; + } } diff --git a/src/mightypork/rogue/world/tile/impl/SimpleFloor.java b/src/mightypork/rogue/world/tile/impl/SimpleFloor.java new file mode 100644 index 0000000..4edc21e --- /dev/null +++ b/src/mightypork/rogue/world/tile/impl/SimpleFloor.java @@ -0,0 +1,15 @@ +package mightypork.rogue.world.tile.impl; + +public class SimpleFloor extends SimpleTile { + + public SimpleFloor(int id, String sheetKey) { + super(id, sheetKey); + } + + @Override + public boolean isWalkable() + { + return true; + } + +} diff --git a/src/mightypork/rogue/world/tile/impl/SimpleTile.java b/src/mightypork/rogue/world/tile/impl/SimpleTile.java new file mode 100644 index 0000000..dfa8b58 --- /dev/null +++ b/src/mightypork/rogue/world/tile/impl/SimpleTile.java @@ -0,0 +1,71 @@ +package mightypork.rogue.world.tile.impl; + + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import mightypork.gamecore.render.DisplaySystem; +import mightypork.gamecore.render.Render; +import mightypork.gamecore.render.textures.TxSheet; +import mightypork.rogue.Res; +import mightypork.rogue.world.tile.TileData; +import mightypork.rogue.world.tile.TileModel; +import mightypork.rogue.world.tile.TileRenderContext; +import mightypork.util.annotations.DefaultImpl; + + +public abstract class SimpleTile extends TileModel { + + private TxSheet sheet; + + + public SimpleTile(int id, String sheetKey) { + super(id); + this.sheet = Res.getTxSheet(sheetKey); + } + + + @Override + @DefaultImpl + public void load(TileData data, InputStream in) throws IOException + { + // do nothing + } + + + @Override + @DefaultImpl + public void save(TileData data, OutputStream out) throws IOException + { + // do nothing + } + + + @Override + public void render(TileData data, TileRenderContext context) + { + // TODO worldmap should take care of this and break the row drawing when it encounters end of screen etc + + // not in screen -> no draw + if (!context.getRect().intersectsWith(DisplaySystem.getBounds())) return; + + Render.quadTextured(context.getRect(), sheet.getRandomQuad(context.getNoise())); + } + + + @Override + @DefaultImpl + public void update(TileData item, double delta) + { + // do nothing + } + + @Override + @DefaultImpl + public boolean isWalkable(TileData data) + { + return isWalkable(); + } + +} diff --git a/src/mightypork/rogue/world/tile/impl/SimpleWall.java b/src/mightypork/rogue/world/tile/impl/SimpleWall.java new file mode 100644 index 0000000..277e146 --- /dev/null +++ b/src/mightypork/rogue/world/tile/impl/SimpleWall.java @@ -0,0 +1,16 @@ +package mightypork.rogue.world.tile.impl; + + +public class SimpleWall extends SimpleTile { + + public SimpleWall(int id, String sheetKey) { + super(id, sheetKey); + } + + @Override + public boolean isWalkable() + { + return false; + } + +} diff --git a/src/mightypork/test/FakeTile.java b/src/mightypork/test/FakeTile.java index 8f94d8d..19ab7cd 100644 --- a/src/mightypork/test/FakeTile.java +++ b/src/mightypork/test/FakeTile.java @@ -26,7 +26,7 @@ public class FakeTile extends TileModel { @Override - public boolean isPotentiallyWalkable() + public boolean isWalkable() { return true; } diff --git a/src/mightypork/util/constraints/rect/Rect.java b/src/mightypork/util/constraints/rect/Rect.java index 2790c40..1b81f5a 100644 --- a/src/mightypork/util/constraints/rect/Rect.java +++ b/src/mightypork/util/constraints/rect/Rect.java @@ -1,6 +1,5 @@ package mightypork.util.constraints.rect; - import mightypork.util.annotations.FactoryMethod; import mightypork.util.constraints.DigestCache; import mightypork.util.constraints.Digestable; @@ -952,4 +951,37 @@ public abstract class Rect implements RectBound, Digestable { { return new TiledRect(this, 1, rows); } + + + /** + * Check for intersection + * + * @param other other rect + * @return true if they intersect + * @see org.lwjgl.util.Rectangle + */ + public boolean intersectsWith(Rect other) + { + double tw = this.size().x(); + double th = this.size().y(); + double rw = other.size().x(); + double rh = other.size().y(); + + if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) { + return false; + } + + double tx = this.origin().x(); + double ty = this.origin().y(); + double rx = other.origin().x(); + double ry = other.origin().y(); + + rw += rx; + rh += ry; + tw += tx; + th += ty; + + // overflow || intersect + return ((rw < rx || rw > tx) && (rh < ry || rh > ty) && (tw < tx || tw > rx) && (th < ty || th > ry)); + } } diff --git a/src/mightypork/util/math/noise/NoiseGen.java b/src/mightypork/util/math/noise/NoiseGen.java index f01688c..32081de 100644 --- a/src/mightypork/util/math/noise/NoiseGen.java +++ b/src/mightypork/util/math/noise/NoiseGen.java @@ -19,6 +19,19 @@ public class NoiseGen { private final double density; + /** + * make a new noise generator with a random seed + * + * @param density noise density (0..1). Lower density means larger "spots". + * @param low low bound ("valley") + * @param middle middle bound ("surface") + * @param high high bound ("hill") + */ + public NoiseGen(double density, double low, double middle, double high) { + this(density, low, middle, high, Double.doubleToLongBits(Math.random())); + } + + /** * make a new noise generator *