Reworked tile system

v5stable
ondra 11 years ago
parent d7348ded53
commit c5374f5f6e
  1. 77
      src/mightypork/rogue/world/tile/Tile.java
  2. 35
      src/mightypork/rogue/world/tile/TileType.java
  3. 58
      src/mightypork/rogue/world/tile/tiles/BasicTile.java
  4. 29
      src/mightypork/rogue/world/tile/tiles/DoorTile.java
  5. 26
      src/mightypork/rogue/world/tile/tiles/FloorTile.java
  6. 45
      src/mightypork/rogue/world/tile/tiles/GroundTile.java
  7. 24
      src/mightypork/rogue/world/tile/tiles/NullTile.java
  8. 43
      src/mightypork/rogue/world/tile/tiles/SolidTile.java
  9. 29
      src/mightypork/rogue/world/tile/tiles/WallTile.java

@ -7,7 +7,7 @@ import java.util.Stack;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.level.Level;
import mightypork.rogue.world.level.render.TileRenderContext;
import mightypork.util.files.ion.IonBinary;
import mightypork.util.annotations.DefaultImpl;
import mightypork.util.files.ion.IonBinaryHeadless;
import mightypork.util.files.ion.IonInput;
import mightypork.util.files.ion.IonOutput;
@ -31,14 +31,12 @@ public abstract class Tile implements IonBinaryHeadless {
protected final Stack<Item> items = new Stack<>();
// temporary flag for map.
protected boolean occupied;
protected boolean explored;
public Tile(int id, TileRenderer renderer)
{
public Tile(int id, TileRenderer renderer) {
this.id = id;
this.renderer = renderer;
}
@ -47,7 +45,17 @@ public abstract class Tile implements IonBinaryHeadless {
/**
* Render the tile, using the main texture sheet.
*/
public abstract void renderTile(TileRenderContext context);
@DefaultImpl
public void renderTile(TileRenderContext context)
{
if (!isExplored()) return;
renderer.renderTile(context);
if (doesReceiveShadow()) renderer.renderShadows(context);
renderer.renderUnexploredFog(context);
}
/**
@ -56,7 +64,8 @@ public abstract class Tile implements IonBinaryHeadless {
*
* @param context
*/
public abstract void renderExtra(TileRenderContext context);
@DefaultImpl
public void renderExtra(TileRenderContext context) {}
@Override
@ -121,27 +130,69 @@ public abstract class Tile implements IonBinaryHeadless {
}
public abstract void update(Level level, double delta);
@DefaultImpl
public void update(Level level, double delta)
{
}
public abstract boolean isWalkable();
/**
* Check if this tile is right now walkable.<br>
* If type is not potentially walkable, this method must return false.
*
* @return true if currently walkable
*/
@DefaultImpl
public boolean isWalkable()
{
return isPotentiallyWalkable();
}
public abstract boolean isPotentiallyWalkable();
public final boolean isPotentiallyWalkable()
{
return getType().isPotentiallyWalkable();
}
public abstract TileType getType();
public abstract boolean canHaveItems();
public abstract boolean doesCastShadow();
public abstract boolean doesCastShadow();
@DefaultImpl
public boolean doesReceiveShadow()
{
return !doesCastShadow();
}
public final Color getMapColor()
{
return getType().getMapColor();
}
/**
* Drop item onto this tile
*
* @param item
* @return true if dropped
*/
public abstract boolean dropItem(Item item);
public abstract boolean doesReceiveShadow();
/**
* Remove an item from this tile
* @return the picked item, or null if none
*/
public abstract Item pickItem();
public abstract Color getMapColor();
/**
* @return true if the tile has dropped items
*/
public abstract boolean hasItem();
}

@ -1,6 +1,11 @@
package mightypork.rogue.world.tile;
import mightypork.util.math.color.Color;
import mightypork.util.math.color.PAL16;
import mightypork.util.math.color.RGB;
/**
* Kinds of tiles
*
@ -8,5 +13,33 @@ package mightypork.rogue.world.tile;
*/
public enum TileType
{
NULL, FLOOR, WALL, DOOR;
/** No tile */
NULL(RGB.NONE, false),
/** Floor tile */
FLOOR(RGB.GRAY_DARK, true),
/** Wall tile */
WALL(RGB.GRAY_LIGHT, false),
/** Door/gate tile */
DOOR(PAL16.NEWPOOP, true);
private final Color mapColor;
private final boolean potentiallyWalkable;
private TileType(Color mapColor, boolean potentiallyWalkable) {
this.mapColor = mapColor;
this.potentiallyWalkable = potentiallyWalkable;
}
public Color getMapColor()
{
return mapColor;
}
public boolean isPotentiallyWalkable()
{
return potentiallyWalkable;
}
}

@ -1,58 +0,0 @@
package mightypork.rogue.world.tile.tiles;
import mightypork.rogue.world.level.Level;
import mightypork.rogue.world.level.render.TileRenderContext;
import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileRenderer;
import mightypork.util.annotations.DefaultImpl;
public abstract class BasicTile extends Tile {
public BasicTile(int id, TileRenderer renderer)
{
super(id, renderer);
}
@Override
public boolean isWalkable()
{
return isPotentiallyWalkable();
}
@Override
public void renderTile(TileRenderContext context)
{
if (!isExplored()) return;
renderer.renderTile(context);
if (doesReceiveShadow()) renderer.renderShadows(context);
renderer.renderUnexploredFog(context);
}
@Override
@DefaultImpl
public void renderExtra(TileRenderContext context)
{
}
@Override
@DefaultImpl
public void update(Level level, double delta)
{
}
@Override
public boolean doesReceiveShadow()
{
return !doesCastShadow();
}
}

@ -1,20 +1,18 @@
package mightypork.rogue.world.tile.tiles;
import mightypork.rogue.world.tile.TileRenderer;
import mightypork.rogue.world.tile.TileType;
import mightypork.util.math.color.Color;
import mightypork.util.math.color.PAL16;
public class DoorTile extends BasicTile {
public class DoorTile extends SolidTile {
public DoorTile(int id, TileRenderer renderer)
{
public DoorTile(int id, TileRenderer renderer) {
super(id, renderer);
}
@Override
public boolean isPotentiallyWalkable()
public boolean isWalkable()
{
return true;
}
@ -24,23 +22,4 @@ public class DoorTile extends BasicTile {
{
return TileType.DOOR;
}
@Override
public boolean canHaveItems()
{
return false;
}
@Override
public boolean doesCastShadow()
{
return true;
}
@Override
public Color getMapColor()
{
return PAL16.NEWPOOP;
}
}

@ -3,11 +3,9 @@ package mightypork.rogue.world.tile.tiles;
import mightypork.rogue.world.tile.TileRenderer;
import mightypork.rogue.world.tile.TileType;
import mightypork.util.math.color.Color;
import mightypork.util.math.color.RGB;
public class FloorTile extends TileWithItems {
public class FloorTile extends GroundTile {
public FloorTile(int id, TileRenderer renderer)
{
@ -15,31 +13,9 @@ public class FloorTile extends TileWithItems {
}
@Override
public boolean isPotentiallyWalkable()
{
return true;
}
@Override
public TileType getType()
{
return TileType.FLOOR;
}
@Override
public boolean doesCastShadow()
{
return false;
}
@Override
public Color getMapColor()
{
return RGB.GRAY_DARK;
}
}

@ -3,20 +3,22 @@ package mightypork.rogue.world.tile.tiles;
import java.io.IOException;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.level.Level;
import mightypork.rogue.world.level.render.TileRenderContext;
import mightypork.rogue.world.tile.DroppedItemRenderer;
import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileRenderer;
import mightypork.util.files.ion.IonInput;
import mightypork.util.files.ion.IonOutput;
public abstract class TileWithItems extends BasicTile {
public abstract class GroundTile extends Tile {
private DroppedItemRenderer itemRenderer = new DroppedItemRenderer();
public TileWithItems(int id, TileRenderer renderer)
public GroundTile(int id, TileRenderer renderer)
{
super(id, renderer);
}
@ -38,13 +40,6 @@ public abstract class TileWithItems extends BasicTile {
}
@Override
public boolean canHaveItems()
{
return true;
}
@Override
public void save(IonOutput out) throws IOException
{
@ -61,4 +56,36 @@ public abstract class TileWithItems extends BasicTile {
in.readSequence(items);
}
@Override
public boolean doesCastShadow()
{
return false;
}
@Override
public boolean isWalkable()
{
return true;
}
@Override
public boolean dropItem(Item item)
{
items.push(item);
return true;
}
@Override
public Item pickItem()
{
return hasItem() ? items.pop() : null;
}
@Override
public boolean hasItem()
{
return !items.isEmpty();
}
}

@ -1,13 +1,12 @@
package mightypork.rogue.world.tile.tiles;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.level.Level;
import mightypork.rogue.world.level.render.TileRenderContext;
import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileRenderer;
import mightypork.rogue.world.tile.TileType;
import mightypork.util.math.color.Color;
import mightypork.util.math.color.RGB;
public class NullTile extends Tile {
@ -44,43 +43,42 @@ public class NullTile extends Tile {
@Override
public boolean isPotentiallyWalkable()
public TileType getType()
{
return false;
return TileType.NULL;
}
@Override
public TileType getType()
public boolean doesCastShadow()
{
return TileType.NULL;
return false;
}
@Override
public boolean canHaveItems()
public boolean doesReceiveShadow()
{
return false;
}
@Override
public boolean doesCastShadow()
public boolean dropItem(Item item)
{
return false;
}
@Override
public boolean doesReceiveShadow()
public Item pickItem()
{
return false;
return null;
}
@Override
public Color getMapColor()
public boolean hasItem()
{
return RGB.NONE;
return false;
}
}

@ -0,0 +1,43 @@
package mightypork.rogue.world.tile.tiles;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileRenderer;
public abstract class SolidTile extends Tile {
public SolidTile(int id, TileRenderer renderer) {
super(id, renderer);
}
@Override
public boolean isWalkable()
{
return false;
}
@Override
public boolean doesCastShadow()
{
return true;
}
@Override
public boolean hasItem()
{
return false;
}
@Override
public boolean dropItem(Item item)
{
return false;
}
@Override
public Item pickItem()
{
return null;
}
}

@ -2,45 +2,18 @@ package mightypork.rogue.world.tile.tiles;
import mightypork.rogue.world.tile.TileRenderer;
import mightypork.rogue.world.tile.TileType;
import mightypork.util.math.color.Color;
import mightypork.util.math.color.RGB;
public class WallTile extends BasicTile {
public class WallTile extends SolidTile {
public WallTile(int id, TileRenderer renderer)
{
super(id, renderer);
}
@Override
public boolean isPotentiallyWalkable()
{
return false;
}
@Override
public TileType getType()
{
return TileType.WALL;
}
@Override
public boolean canHaveItems()
{
return false;
}
@Override
public boolean doesCastShadow()
{
return true;
}
@Override
public Color getMapColor()
{
return RGB.GRAY_LIGHT;
}
}

Loading…
Cancel
Save