parent
							
								
									307d8d2b10
								
							
						
					
					
						commit
						7b862cb5c8
					
				@ -0,0 +1,21 @@ | 
				
			|||||||
 | 
					package mightypork.rogue.world.pathfinding; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.rogue.world.Coord; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public interface FillContext { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						boolean canEnter(Coord pos); | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						boolean canSpread(Coord pos); | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * Get the max distance filled form start point. Use -1 for unlimited range. | 
				
			||||||
 | 
						 *  | 
				
			||||||
 | 
						 * @return max distance | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						int getMaxDistance(); | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,41 @@ | 
				
			|||||||
 | 
					package mightypork.rogue.world.pathfinding; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.*; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.rogue.world.Coord; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class FloodFill { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						private static final Coord[] spread = { Coord.make(0, -1), Coord.make(0, 1), Coord.make(1, 0), Coord.make(-1, 0) }; | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						public static final Collection<Coord> fill(Coord start, FillContext context) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							Set<Coord> filled = new HashSet<>(); | 
				
			||||||
 | 
							Stack<Coord> active = new Stack<>(); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							int maxDist = context.getMaxDistance(); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							active.push(start); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							while (!active.isEmpty()) { | 
				
			||||||
 | 
								Coord current = active.pop(); | 
				
			||||||
 | 
								 | 
				
			||||||
 | 
								filled.add(current); | 
				
			||||||
 | 
								 | 
				
			||||||
 | 
								for (Coord spr : spread) { | 
				
			||||||
 | 
									Coord next = current.add(spr); | 
				
			||||||
 | 
									 | 
				
			||||||
 | 
									if (next.dist(start) > maxDist) continue; | 
				
			||||||
 | 
									 | 
				
			||||||
 | 
									if (context.canSpread(next)) { | 
				
			||||||
 | 
										active.push(next); | 
				
			||||||
 | 
									} | 
				
			||||||
 | 
								} | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							return filled; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
@ -1,54 +0,0 @@ | 
				
			|||||||
package mightypork.rogue.world.tile; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.io.IOException; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import mightypork.util.error.YouFuckedUpException; | 
					 | 
				
			||||||
import mightypork.util.files.ion.IonBinary; | 
					 | 
				
			||||||
import mightypork.util.files.ion.IonBundle; | 
					 | 
				
			||||||
import mightypork.util.files.ion.IonInput; | 
					 | 
				
			||||||
import mightypork.util.files.ion.IonOutput; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class TileData implements IonBinary { | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	private static final byte BIT_EXPLORED = 1 << 0; | 
					 | 
				
			||||||
	private static final byte BIT_LOCKED = 1 << 1; | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	public boolean explored = false; | 
					 | 
				
			||||||
	public boolean locked = false; | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	public final IonBundle extra = new IonBundle(); | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public void load(IonInput in) throws IOException | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		final byte flags = in.readByte(); | 
					 | 
				
			||||||
		in.readBundle(extra); | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		explored = (flags & BIT_EXPLORED) != 0; | 
					 | 
				
			||||||
		locked = (flags & BIT_LOCKED) != 0; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public void save(IonOutput out) throws IOException | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		byte flags = 0; | 
					 | 
				
			||||||
		if (explored) flags |= BIT_EXPLORED; | 
					 | 
				
			||||||
		if (locked) flags |= BIT_LOCKED; | 
					 | 
				
			||||||
		out.writeByte(flags); | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		out.writeBundle(extra); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public short getIonMark() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		throw new YouFuckedUpException("TileData is not to be read from ION using mark."); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
} | 
					 | 
				
			||||||
@ -0,0 +1,12 @@ | 
				
			|||||||
 | 
					package mightypork.rogue.world.tile; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Kinds of tiles | 
				
			||||||
 | 
					 *  | 
				
			||||||
 | 
					 * @author MightyPork | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public enum TileType | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
						NULL, FLOOR, WALL, DOOR; | 
				
			||||||
 | 
					} | 
				
			||||||
@ -1,53 +0,0 @@ | 
				
			|||||||
package mightypork.rogue.world.tile.models; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import mightypork.rogue.world.tile.Tile; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** | 
					 | 
				
			||||||
 * Null tile | 
					 | 
				
			||||||
 *  | 
					 | 
				
			||||||
 * @author MightyPork | 
					 | 
				
			||||||
 */ | 
					 | 
				
			||||||
public abstract class AbstractNullTile extends AbstractTile { | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	private Tile inst; | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	public AbstractNullTile(int id) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		super(id); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean isNullTile() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return true; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public Tile createTile() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		if (inst == null) { | 
					 | 
				
			||||||
			inst = new Tile(this); | 
					 | 
				
			||||||
		} | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		return inst; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean hasDroppedItems() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return false; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean doesCastShadow() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return false; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
} | 
					 | 
				
			||||||
@ -1,62 +0,0 @@ | 
				
			|||||||
package mightypork.rogue.world.tile.models; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import mightypork.rogue.world.level.Level; | 
					 | 
				
			||||||
import mightypork.rogue.world.tile.Tile; | 
					 | 
				
			||||||
import mightypork.rogue.world.tile.TileModel; | 
					 | 
				
			||||||
import mightypork.util.annotations.DefaultImpl; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** | 
					 | 
				
			||||||
 * Basic implementation of a tile. | 
					 | 
				
			||||||
 *  | 
					 | 
				
			||||||
 * @author MightyPork | 
					 | 
				
			||||||
 */ | 
					 | 
				
			||||||
public abstract class AbstractTile extends TileModel { | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	public AbstractTile(int id) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		super(id); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean isWalkable(Tile tile) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return isPotentiallyWalkable(); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean isDoor() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return false; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean isWall() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return false; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean isFloor() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return false; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean doesReceiveShadow() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return isFloor(); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	@DefaultImpl | 
					 | 
				
			||||||
	public void update(Tile tile, Level level, double delta) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
} | 
					 | 
				
			||||||
@ -1,50 +0,0 @@ | 
				
			|||||||
package mightypork.rogue.world.tile.models; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import mightypork.rogue.world.tile.Tile; | 
					 | 
				
			||||||
import mightypork.util.math.color.Color; | 
					 | 
				
			||||||
import mightypork.util.math.color.RGB; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class Floor extends AbstractTile { | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	public Floor(int id) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		super(id); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean isPotentiallyWalkable() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return true; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean hasDroppedItems() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return true; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean doesCastShadow() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return false; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean isFloor() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return true; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public Color getMapColor(Tile tile) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return RGB.GRAY_DARK; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
} | 
					 | 
				
			||||||
@ -1,29 +0,0 @@ | 
				
			|||||||
package mightypork.rogue.world.tile.models; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import mightypork.rogue.world.tile.Tile; | 
					 | 
				
			||||||
import mightypork.util.math.color.Color; | 
					 | 
				
			||||||
import mightypork.util.math.color.RGB; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class NullTile extends AbstractNullTile { | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	public NullTile(int id) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		super(id); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean isPotentiallyWalkable() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return false; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public Color getMapColor(Tile tile) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return RGB.NONE; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
} | 
					 | 
				
			||||||
@ -1,65 +0,0 @@ | 
				
			|||||||
package mightypork.rogue.world.tile.models; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import mightypork.rogue.world.tile.Tile; | 
					 | 
				
			||||||
import mightypork.rogue.world.tile.renderers.DoorRenderer; | 
					 | 
				
			||||||
import mightypork.util.math.color.Color; | 
					 | 
				
			||||||
import mightypork.util.math.color.PAL16; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SimpleDoor extends AbstractTile { | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	public SimpleDoor(int id) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		super(id); | 
					 | 
				
			||||||
		setRenderer(new DoorRenderer("tile.door.closed", "tile.door.open")); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean isPotentiallyWalkable() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return true; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean isWalkable(Tile tile) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return !isLocked(tile); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	protected boolean isLocked(Tile tile) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return false; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean isDoor() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return true; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean doesCastShadow() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return true; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean hasDroppedItems() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return false; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public Color getMapColor(Tile tile) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return PAL16.NEWPOOP; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
} | 
					 | 
				
			||||||
@ -1,55 +0,0 @@ | 
				
			|||||||
package mightypork.rogue.world.tile.models; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import mightypork.rogue.world.tile.Tile; | 
					 | 
				
			||||||
import mightypork.util.math.color.Color; | 
					 | 
				
			||||||
import mightypork.util.math.color.RGB; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** | 
					 | 
				
			||||||
 * Template for wall tiles with no metadata | 
					 | 
				
			||||||
 *  | 
					 | 
				
			||||||
 * @author MightyPork | 
					 | 
				
			||||||
 */ | 
					 | 
				
			||||||
public class Wall extends AbstractTile { | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	public Wall(int id) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		super(id); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public final boolean hasDroppedItems() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return false; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public final boolean doesCastShadow() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return true; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public final boolean isWall() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return true; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public final boolean isPotentiallyWalkable() | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return false; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public Color getMapColor(Tile tile) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return RGB.GRAY_LIGHT; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
} | 
					 | 
				
			||||||
@ -0,0 +1,58 @@ | 
				
			|||||||
 | 
					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(); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,46 @@ | 
				
			|||||||
 | 
					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 DoorTile(int id, TileRenderer renderer) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							super(id, renderer); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public boolean isPotentiallyWalkable() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return true; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public TileType getType() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return TileType.DOOR; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public boolean canHaveItems() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return false; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public boolean doesCastShadow() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return true; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public Color getMapColor() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return PAL16.NEWPOOP; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,45 @@ | 
				
			|||||||
 | 
					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 FloorTile(int id, TileRenderer renderer) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							super(id, renderer); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@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; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,36 @@ | 
				
			|||||||
 | 
					package mightypork.rogue.world.tile.tiles; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.IOException; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.rogue.world.tile.TileRenderer; | 
				
			||||||
 | 
					import mightypork.util.files.ion.IonInput; | 
				
			||||||
 | 
					import mightypork.util.files.ion.IonOutput; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class LockedDoorTile extends DoorTile { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						public boolean locked = true; | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						public LockedDoorTile(int id, TileRenderer renderer) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							super(id, renderer); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public void load(IonInput in) throws IOException | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							super.load(in); | 
				
			||||||
 | 
							locked = in.readBoolean(); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public void save(IonOutput out) throws IOException | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							super.save(out); | 
				
			||||||
 | 
							out.writeBoolean(locked); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,86 @@ | 
				
			|||||||
 | 
					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.rogue.world.tile.TileType; | 
				
			||||||
 | 
					import mightypork.util.math.color.Color; | 
				
			||||||
 | 
					import mightypork.util.math.color.RGB; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class NullTile extends Tile { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						public NullTile(int id, TileRenderer renderer) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							super(id, renderer); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public void update(Level level, double delta) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public void renderTile(TileRenderContext context) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public void renderExtra(TileRenderContext context) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public boolean isWalkable() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return false; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public boolean isPotentiallyWalkable() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return false; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public TileType getType() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return TileType.NULL; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public boolean canHaveItems() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return false; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public boolean doesCastShadow() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return false; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public boolean doesReceiveShadow() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return false; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public Color getMapColor() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return RGB.NONE; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,64 @@ | 
				
			|||||||
 | 
					package mightypork.rogue.world.tile.tiles; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.IOException; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.rogue.world.level.Level; | 
				
			||||||
 | 
					import mightypork.rogue.world.level.render.TileRenderContext; | 
				
			||||||
 | 
					import mightypork.rogue.world.tile.DroppedItemRenderer; | 
				
			||||||
 | 
					import mightypork.rogue.world.tile.TileRenderer; | 
				
			||||||
 | 
					import mightypork.util.files.ion.IonInput; | 
				
			||||||
 | 
					import mightypork.util.files.ion.IonOutput; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public abstract class TileWithItems extends BasicTile { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						private DroppedItemRenderer itemRenderer = new DroppedItemRenderer(); | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						public TileWithItems(int id, TileRenderer renderer) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							super(id, renderer); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public void renderExtra(TileRenderContext context) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							if (!items.isEmpty()) { | 
				
			||||||
 | 
								itemRenderer.render(items.peek(), context); | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public void update(Level level, double delta) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							itemRenderer.update(delta); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public boolean canHaveItems() | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return true; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public void save(IonOutput out) throws IOException | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							super.save(out); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							out.writeSequence(items); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public void load(IonInput in) throws IOException | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							super.load(in); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							in.readSequence(items); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,46 @@ | 
				
			|||||||
 | 
					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 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; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,31 @@ | 
				
			|||||||
 | 
					package mightypork.util.files.ion; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.IOException; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Binary ion object, with no mark = cannot be loaded on it's own | 
				
			||||||
 | 
					 *  | 
				
			||||||
 | 
					 * @author MightyPork | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public interface IonBinaryHeadless { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * Load data from the input stream. | 
				
			||||||
 | 
						 *  | 
				
			||||||
 | 
						 * @param in input stream | 
				
			||||||
 | 
						 * @throws IOException | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						void load(IonInput in) throws IOException; | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * Store data to output stream (in such way that the load method will later | 
				
			||||||
 | 
						 * be able to read it). | 
				
			||||||
 | 
						 *  | 
				
			||||||
 | 
						 * @param out Output stream | 
				
			||||||
 | 
						 * @throws IOException | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						void save(IonOutput out) throws IOException; | 
				
			||||||
 | 
					} | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue