|
@@ -11,13 +11,7 @@ import pathgame.tilemap.TileMap;
|
|
|
import pathgame.tilemap.TileRenderType;
|
|
|
import pathgame.tilemap.TileType;
|
|
|
|
|
|
-
|
|
|
- * A renderer for tile maps.
|
|
|
- *
|
|
|
- * @author kajetan
|
|
|
- */
|
|
|
public class TileMapRenderer {
|
|
|
-
|
|
|
private final static float ERROR = 1.0f / 512.0F;
|
|
|
private final static float T_ERROR = 1.0f / 4096.0F;
|
|
|
|
|
@@ -30,7 +24,7 @@ public class TileMapRenderer {
|
|
|
private float scale = 1.0f;
|
|
|
|
|
|
private final static String[] OVERLAY = new String[]{
|
|
|
- "&a1", "&a2", "&a3", "&e4", "&e5", "&66", "&67", "&68", "&c9"
|
|
|
+ "#55FF551", "#55FF552", "#55FF553", "#FFFF554", "#FFFF555", "#FFAA006", "#FFAA007", "#FFAA008", "#FF55559"
|
|
|
};
|
|
|
|
|
|
private static String[] getWavePath() {
|
|
@@ -44,47 +38,18 @@ public class TileMapRenderer {
|
|
|
private final Texture.Animation waves = tileTexture.addAnimation((int) (8 * TileRenderer.TILE_SIZE), (int) (2 * TileRenderer.TILE_SIZE), getWavePath());
|
|
|
private int counter = 0;
|
|
|
|
|
|
-
|
|
|
- * Creates a new tile map renderer.
|
|
|
- *
|
|
|
- */
|
|
|
- public TileMapRenderer() {
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * Sets the scale of the map.
|
|
|
- *
|
|
|
- * @param scale the scale of the map
|
|
|
- */
|
|
|
public void setScale(float scale) {
|
|
|
this.scale = scale;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * Returns the scale of the map.
|
|
|
- *
|
|
|
- * @return the scale of the map
|
|
|
- */
|
|
|
public float getScale() {
|
|
|
return scale;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * Returns the scaled render width of a map.
|
|
|
- *
|
|
|
- * @param map a map
|
|
|
- * @return the scaled render width of a map
|
|
|
- */
|
|
|
public float getWidth(TileMap map) {
|
|
|
return map.getWidth() * TileRenderer.TILE_SIZE * scale;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * Returns the scaled render height of a map.
|
|
|
- *
|
|
|
- * @param map a map
|
|
|
- * @return the scaled render height of a map
|
|
|
- */
|
|
|
public float getHeight(TileMap map) {
|
|
|
return map.getHeight() * TileRenderer.TILE_SIZE * scale;
|
|
|
}
|
|
@@ -131,20 +96,16 @@ public class TileMapRenderer {
|
|
|
boolean s = isSwamp(map, x, y + 1);
|
|
|
boolean w = isSwamp(map, x - 1, y);
|
|
|
|
|
|
- if(!n && !w && isSwamp(map, x - 1, y - 1))
|
|
|
- {
|
|
|
+ if(!n && !w && isSwamp(map, x - 1, y - 1)) {
|
|
|
addTileOverlay(swampWaterOverlayRenderer, x, y, 7, 13);
|
|
|
}
|
|
|
- if(!n && !e && isSwamp(map, x + 1, y - 1))
|
|
|
- {
|
|
|
+ if(!n && !e && isSwamp(map, x + 1, y - 1)) {
|
|
|
addTileOverlay(swampWaterOverlayRenderer, x, y, 6, 13);
|
|
|
}
|
|
|
- if(!s && !w && isSwamp(map, x - 1, y + 1))
|
|
|
- {
|
|
|
+ if(!s && !w && isSwamp(map, x - 1, y + 1)) {
|
|
|
addTileOverlay(swampWaterOverlayRenderer, x, y, 5, 13);
|
|
|
}
|
|
|
- if(!s && !e && isSwamp(map, x + 1, y + 1))
|
|
|
- {
|
|
|
+ if(!s && !e && isSwamp(map, x + 1, y + 1)) {
|
|
|
addTileOverlay(swampWaterOverlayRenderer, x, y, 4, 13);
|
|
|
}
|
|
|
|
|
@@ -165,20 +126,16 @@ public class TileMapRenderer {
|
|
|
boolean s = isShallowWater(map, x, y + 1);
|
|
|
boolean w = isShallowWater(map, x - 1, y);
|
|
|
|
|
|
- if(!n && !w && isShallowWater(map, x - 1, y - 1))
|
|
|
- {
|
|
|
+ if(!n && !w && isShallowWater(map, x - 1, y - 1)) {
|
|
|
addTileOverlay(waterOverlayRenderer, x, y, 11, 13);
|
|
|
}
|
|
|
- if(!n && !e && isShallowWater(map, x + 1, y - 1))
|
|
|
- {
|
|
|
+ if(!n && !e && isShallowWater(map, x + 1, y - 1)) {
|
|
|
addTileOverlay(waterOverlayRenderer, x, y, 10, 13);
|
|
|
}
|
|
|
- if(!s && !w && isShallowWater(map, x - 1, y + 1))
|
|
|
- {
|
|
|
+ if(!s && !w && isShallowWater(map, x - 1, y + 1)) {
|
|
|
addTileOverlay(waterOverlayRenderer, x, y, 9, 13);
|
|
|
}
|
|
|
- if(!s && !e && isShallowWater(map, x + 1, y + 1))
|
|
|
- {
|
|
|
+ if(!s && !e && isShallowWater(map, x + 1, y + 1)) {
|
|
|
addTileOverlay(waterOverlayRenderer, x, y, 8, 13);
|
|
|
}
|
|
|
|
|
@@ -199,20 +156,16 @@ public class TileMapRenderer {
|
|
|
boolean s = isSwampOrWaterOrBorder(map, x, y + 1);
|
|
|
boolean w = isSwampOrWaterOrBorder(map, x - 1, y);
|
|
|
|
|
|
- if(n && w && !isSwampOrWaterOrBorder(map, x - 1, y - 1))
|
|
|
- {
|
|
|
+ if(n && w && !isSwampOrWaterOrBorder(map, x - 1, y - 1)) {
|
|
|
addTileOverlay(grassOverlayRenderer, x, y, 3, 13);
|
|
|
}
|
|
|
- if(n && e && !isSwampOrWaterOrBorder(map, x + 1, y - 1))
|
|
|
- {
|
|
|
+ if(n && e && !isSwampOrWaterOrBorder(map, x + 1, y - 1)) {
|
|
|
addTileOverlay(grassOverlayRenderer, x, y, 2, 13);
|
|
|
}
|
|
|
- if(s && w && !isSwampOrWaterOrBorder(map, x - 1, y + 1))
|
|
|
- {
|
|
|
+ if(s && w && !isSwampOrWaterOrBorder(map, x - 1, y + 1)) {
|
|
|
addTileOverlay(grassOverlayRenderer, x, y, 1, 13);
|
|
|
}
|
|
|
- if(s && e && !isSwampOrWaterOrBorder(map, x + 1, y + 1))
|
|
|
- {
|
|
|
+ if(s && e && !isSwampOrWaterOrBorder(map, x + 1, y + 1)) {
|
|
|
addTileOverlay(grassOverlayRenderer, x, y, 0, 13);
|
|
|
}
|
|
|
|
|
@@ -261,12 +214,7 @@ public class TileMapRenderer {
|
|
|
grassOverlayRenderer.build();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * Ticks the renderer. Used for animated tiles.
|
|
|
- *
|
|
|
- */
|
|
|
public void tick() {
|
|
|
-
|
|
|
counter++;
|
|
|
if(counter >= 1) {
|
|
|
tileTexture.bind();
|
|
@@ -275,16 +223,7 @@ public class TileMapRenderer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * Draws the given map at the given offset.
|
|
|
- *
|
|
|
- * @param map a map
|
|
|
- * @param r the renderer given by the engine
|
|
|
- * @param forceUpdate whether an update of the render data should be forced
|
|
|
- * @param offX the x coordinate of the offset
|
|
|
- * @param offY the y coordinate of the offset
|
|
|
- */
|
|
|
- public void renderTick(TileMap map, Renderer r, Player p, boolean forceUpdate, float offX, float offY) {
|
|
|
+ public void renderTick(TileMap map, Renderer r, Player p, boolean forceUpdate, float offX, float offY, Keys keys) {
|
|
|
r.setTextureEnabled(true);
|
|
|
r.setColorEnabled(false);
|
|
|
r.setMixColorEnabled(false);
|
|
@@ -309,7 +248,7 @@ public class TileMapRenderer {
|
|
|
swampWaterOverlayRenderer.draw();
|
|
|
grassOverlayRenderer.draw();
|
|
|
|
|
|
- if(Keys.OVERLAY_KEY.isDown()) {
|
|
|
+ if(keys.overlay.isDown()) {
|
|
|
r.translateTo(0.0f, 0.0f);
|
|
|
r.updateMatrix();
|
|
|
r.setTextureEnabled(false);
|
|
@@ -323,15 +262,15 @@ public class TileMapRenderer {
|
|
|
|
|
|
FontRenderer fr = r.getFontRenderer();
|
|
|
|
|
|
- float midX = (TileRenderer.TILE_SIZE - fr.getWidth() * 2) * 0.5f * 0.5f;
|
|
|
- float midY = (TileRenderer.TILE_SIZE - (fr.getHeight() - 1) * 2) * 0.5f * 0.5f;
|
|
|
+ float midX = (TileRenderer.TILE_SIZE - fr.getCharWidth() * 2) * 0.5f * 0.5f;
|
|
|
+ float midY = (TileRenderer.TILE_SIZE - (fr.getCharHeight() - 1) * 2) * 0.5f * 0.5f;
|
|
|
for(int x = 0; x < map.getWidth(); x++) {
|
|
|
for(int y = 0; y < map.getHeight(); y++) {
|
|
|
Tile t = map.getTile(x, y);
|
|
|
float tx = midX + TileRenderer.TILE_SIZE * x * 0.5f;
|
|
|
float ty = midY + TileRenderer.TILE_SIZE * y * 0.5f;
|
|
|
if(t.isBlockingMovement(p)) {
|
|
|
- fr.drawString(tx, ty, true, "&4-");
|
|
|
+ fr.drawString(tx, ty, true, "#AA0000-");
|
|
|
} else {
|
|
|
fr.drawString(tx, ty, true, OVERLAY[map.getTile(x, y).getEnergyCost(p) - 1]);
|
|
|
}
|