parent
880bcfb553
commit
9e4a237192
@ -0,0 +1,16 @@ |
||||
package mightypork.rogue.world; |
||||
|
||||
import mightypork.rogue.world.map.Level; |
||||
import mightypork.util.control.timing.Updateable; |
||||
|
||||
|
||||
/** |
||||
* Abstraction of client-server connection from the client's view |
||||
* |
||||
* @author MightyPork |
||||
*/ |
||||
public abstract class ClientWorldAccess implements Updateable { |
||||
|
||||
public abstract Level getLevel(); |
||||
|
||||
} |
@ -0,0 +1,64 @@ |
||||
package mightypork.rogue.world; |
||||
|
||||
|
||||
import mightypork.rogue.world.map.Level; |
||||
import mightypork.rogue.world.map.TileRenderContext; |
||||
import mightypork.util.constraints.rect.Rect; |
||||
import mightypork.util.constraints.rect.RectConst; |
||||
import mightypork.util.constraints.rect.proxy.RectBound; |
||||
import mightypork.util.constraints.vect.VectConst; |
||||
|
||||
|
||||
public class LevelRenderer { |
||||
|
||||
/** |
||||
* Draw on screen |
||||
* |
||||
* @param viewport rendering area on screen |
||||
* @param xTiles Desired nr of tiles horizontally |
||||
* @param yTiles Desired nr of tiles vertically |
||||
* @param minSize minimum tile size |
||||
*/ |
||||
public static void render(Level level, PlayerEntity player, RectBound viewport, final int yTiles, final int xTiles, final int minSize) |
||||
{ |
||||
final Rect r = viewport.getRect(); |
||||
final double vpH = r.height().value(); |
||||
final double vpW = r.width().value(); |
||||
|
||||
// adjust tile size to fit desired amount of tiles
|
||||
|
||||
final double allowedSizeW = vpW / xTiles; |
||||
final double allowedSizeH = vpH / yTiles; |
||||
int tileSize = (int) Math.round(Math.max(Math.min(allowedSizeH, allowedSizeW), minSize)); |
||||
|
||||
tileSize -= tileSize % 16; |
||||
|
||||
final VectConst vpCenter = r.center().sub(tileSize * 0.5, tileSize).freeze(); // 0.5 to center, 1 to move up (down is teh navbar)
|
||||
|
||||
final double playerX = player.getPosition().getVisualX(); |
||||
final double playerY = player.getPosition().getVisualY(); |
||||
|
||||
// total map area
|
||||
//@formatter:off
|
||||
final RectConst mapRect = vpCenter.startRect().grow( |
||||
playerX*tileSize, |
||||
(level.getWidth() - playerX) * tileSize, |
||||
playerY*tileSize, |
||||
(level.getHeight() - playerY) * tileSize |
||||
).freeze(); |
||||
//@formatter:on
|
||||
|
||||
// tiles to render
|
||||
final int x1 = (int) Math.floor(playerX - (vpW / tileSize)); |
||||
final int y1 = (int) Math.floor(playerY - (vpH / tileSize)); |
||||
final int x2 = (int) Math.ceil(playerX + (vpW / tileSize)); |
||||
final int y2 = (int) Math.ceil(playerY + (vpH / tileSize)); |
||||
|
||||
final TileRenderContext trc = new TileRenderContext(level, mapRect); //-tileSize*0.5
|
||||
for (trc.y = y1; trc.y <= y2; trc.y++) { |
||||
for (trc.x = x1; trc.x <= x2; trc.x++) { |
||||
trc.render(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,6 +0,0 @@ |
||||
package mightypork.rogue.world; |
||||
|
||||
|
||||
public class LocalWorldAccess implements WorldAccess { |
||||
|
||||
} |
@ -0,0 +1,50 @@ |
||||
package mightypork.rogue.world.tile; |
||||
|
||||
|
||||
import mightypork.rogue.world.item.Item; |
||||
import mightypork.rogue.world.map.TileRenderContext; |
||||
import mightypork.rogue.world.tile.renderers.NullTileRenderer; |
||||
|
||||
|
||||
/** |
||||
* Renderer for a tile model, in client |
||||
* |
||||
* @author MightyPork |
||||
*/ |
||||
public abstract class TileRenderer { |
||||
|
||||
public static final TileRenderer NONE = new NullTileRenderer(); |
||||
|
||||
private DroppedItemRenderer itemRenderer; |
||||
|
||||
|
||||
/** |
||||
* Update tile renderer |
||||
* |
||||
* @param delta delta time |
||||
*/ |
||||
public void update(double delta) |
||||
{ |
||||
if (itemRenderer != null) { |
||||
itemRenderer.update(delta); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Render the tile. |
||||
* |
||||
* @param context |
||||
*/ |
||||
public abstract void render(TileRenderContext context); |
||||
|
||||
|
||||
public void renderItemOnTile(Item item, TileRenderContext context) |
||||
{ |
||||
if (itemRenderer == null) { |
||||
itemRenderer = new DroppedItemRenderer(); |
||||
} |
||||
|
||||
itemRenderer.render(item, context); |
||||
} |
||||
} |
@ -1,79 +1,53 @@ |
||||
package mightypork.rogue.world.tile.models; |
||||
|
||||
|
||||
import mightypork.gamecore.render.Render; |
||||
import mightypork.gamecore.render.textures.TxSheet; |
||||
import mightypork.rogue.Res; |
||||
import mightypork.rogue.world.map.TileRenderContext; |
||||
import mightypork.rogue.world.WorldAccess; |
||||
import mightypork.rogue.world.map.Level; |
||||
import mightypork.rogue.world.tile.Tile; |
||||
import mightypork.rogue.world.tile.TileModel; |
||||
import mightypork.util.annotations.DefaultImpl; |
||||
import mightypork.util.ion.IonBundle; |
||||
|
||||
|
||||
/** |
||||
* Basic implementation of a tile with coord-random texture and no animation. |
||||
* Basic implementation of a tile. |
||||
* |
||||
* @author MightyPork |
||||
*/ |
||||
public abstract class SimpleTile extends TileModel { |
||||
|
||||
protected final TxSheet sheet; |
||||
|
||||
|
||||
public SimpleTile(int id, String sheetKey) |
||||
public SimpleTile(int id) |
||||
{ |
||||
super(id); |
||||
this.sheet = Res.getTxSheet(sheetKey); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void render(TileRenderContext context) |
||||
{ |
||||
Render.quadTextured(context.getRect(), sheet.getRandomQuad(context.getTileNoise())); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
@DefaultImpl |
||||
public void updateLogic(Tile tile, double delta) |
||||
{ |
||||
} |
||||
|
||||
|
||||
/* |
||||
* Items can override this if their walkability changes based on something |
||||
*/ |
||||
@Override |
||||
public boolean isWalkable(Tile tile) |
||||
{ |
||||
return isPotentiallyWalkable(); |
||||
return isWalkable(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public abstract boolean isPotentiallyWalkable(); |
||||
public abstract boolean isWalkable(); |
||||
|
||||
|
||||
@Override |
||||
@DefaultImpl |
||||
public boolean hasMetadata() |
||||
public boolean hasPersistentMetadata() |
||||
{ |
||||
return false; // it's a SIMPLE tile
|
||||
return false; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
@DefaultImpl |
||||
public void loadMetadata(Tile tile, IonBundle ib) |
||||
public void updateLogic(Tile tile, WorldAccess world, Level level, double delta) |
||||
{ |
||||
} |
||||
|
||||
|
||||
@Override |
||||
@DefaultImpl |
||||
public void saveMetadata(Tile tile, IonBundle ib) |
||||
public void updateVisual(Tile tile, WorldAccess world, Level level, double delta) |
||||
{ |
||||
} |
||||
} |
||||
|
@ -0,0 +1,27 @@ |
||||
package mightypork.rogue.world.tile.renderers; |
||||
|
||||
|
||||
import mightypork.gamecore.render.Render; |
||||
import mightypork.gamecore.render.textures.TxSheet; |
||||
import mightypork.rogue.Res; |
||||
import mightypork.rogue.world.map.TileRenderContext; |
||||
import mightypork.rogue.world.tile.TileRenderer; |
||||
|
||||
|
||||
public class BasicTileRenderer extends TileRenderer { |
||||
|
||||
private TxSheet sheet; |
||||
|
||||
|
||||
public BasicTileRenderer(String sheetKey) |
||||
{ |
||||
this.sheet = Res.getTxSheet(sheetKey); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void render(TileRenderContext context) |
||||
{ |
||||
Render.quadTextured(context.getRect(), sheet.getRandomQuad(context.getTileNoise())); |
||||
} |
||||
} |
@ -0,0 +1,15 @@ |
||||
package mightypork.rogue.world.tile.renderers; |
||||
|
||||
import mightypork.rogue.world.map.TileRenderContext; |
||||
import mightypork.rogue.world.tile.TileRenderer; |
||||
|
||||
|
||||
public class NullTileRenderer extends TileRenderer { |
||||
|
||||
@Override |
||||
public void render(TileRenderContext context) |
||||
{ |
||||
// nope
|
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue