preparing for rewrite of tile and item system
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -54,27 +54,6 @@ public abstract class EntityModel<D, R extends RectBound> {
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Item> items = new Stack<>();
|
||||
public final Stack<Item> 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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package mightypork.rogue.world.tile;
|
||||
|
||||
|
||||
public interface TileHolder {
|
||||
public interface TileGrid {
|
||||
|
||||
Tile getTile(int x, int y);
|
||||
|
||||
@@ -25,7 +25,7 @@ public abstract class TileModel extends EntityModel<TileData, TileRenderContext>
|
||||
*
|
||||
* @return can be walked through (if discovered / open)
|
||||
*/
|
||||
public abstract boolean isPotentiallyWalkable();
|
||||
public abstract boolean isWalkable();
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user