v0.7.3a: refactored custom tiled visuals. Now custom tilemaps
This commit is contained in:
parent
3864d5c21e
commit
e06e4e1c85
|
@ -68,7 +68,7 @@ import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.plants.Swiftthistle;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTilemap;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.utils.BArray;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||
import com.watabou.noosa.Game;
|
||||
|
@ -136,8 +136,8 @@ public abstract class Level implements Bundlable {
|
|||
public HashMap<Class<? extends Blob>,Blob> blobs;
|
||||
public SparseArray<Plant> plants;
|
||||
public SparseArray<Trap> traps;
|
||||
public HashSet<CustomTiledVisual> customTiles;
|
||||
public HashSet<CustomTiledVisual> customWalls;
|
||||
public HashSet<CustomTilemap> customTiles;
|
||||
public HashSet<CustomTilemap> customWalls;
|
||||
|
||||
protected ArrayList<Item> itemsToSpawn = new ArrayList<>();
|
||||
|
||||
|
@ -348,13 +348,13 @@ public abstract class Level implements Bundlable {
|
|||
|
||||
collection = bundle.getCollection( CUSTOM_TILES );
|
||||
for (Bundlable p : collection) {
|
||||
CustomTiledVisual vis = (CustomTiledVisual)p;
|
||||
CustomTilemap vis = (CustomTilemap)p;
|
||||
customTiles.add(vis);
|
||||
}
|
||||
|
||||
collection = bundle.getCollection( CUSTOM_WALLS );
|
||||
for (Bundlable p : collection) {
|
||||
CustomTiledVisual vis = (CustomTiledVisual)p;
|
||||
CustomTilemap vis = (CustomTilemap)p;
|
||||
customWalls.add(vis);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,10 +41,11 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTilemap;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.TargetHealthIndicator;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.utils.BArray;
|
||||
import com.watabou.noosa.Group;
|
||||
import com.watabou.noosa.Tilemap;
|
||||
import com.watabou.noosa.audio.Sample;
|
||||
import com.watabou.utils.Bundlable;
|
||||
import com.watabou.utils.Bundle;
|
||||
|
@ -372,7 +373,7 @@ public class PrisonBossLevel extends Level {
|
|||
case FIGHT_ARENA:
|
||||
unseal();
|
||||
|
||||
CustomTiledVisual vis = new exitVisual();
|
||||
CustomTilemap vis = new exitVisual();
|
||||
vis.pos(11, 8);
|
||||
customTiles.add(vis);
|
||||
((GameScene)ShatteredPixelDungeon.scene()).addCustomTile(vis);
|
||||
|
@ -582,8 +583,17 @@ public class PrisonBossLevel extends Level {
|
|||
W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W};
|
||||
|
||||
|
||||
public static class exitVisual extends CustomTiledVisual {
|
||||
|
||||
public static class exitVisual extends CustomTilemap {
|
||||
|
||||
{
|
||||
texture = Assets.PRISON_EXIT;
|
||||
|
||||
tileW = 12;
|
||||
tileH = 14;
|
||||
}
|
||||
|
||||
final int TEX_WIDTH = 256;
|
||||
|
||||
private static short[] render = new short[]{
|
||||
0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
@ -600,26 +610,33 @@ public class PrisonBossLevel extends Level {
|
|||
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
public exitVisual() {
|
||||
super(Assets.PRISON_EXIT);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CustomTiledVisual create() {
|
||||
tileW = 12;
|
||||
tileH = 14;
|
||||
mapSimpleImage(0, 0);
|
||||
return super.create();
|
||||
public Tilemap create() {
|
||||
|
||||
Tilemap v = super.create();
|
||||
int[] data = mapSimpleImage(0, 0, TEX_WIDTH);
|
||||
for (int i = 0; i < data.length; i++){
|
||||
if (render[i] == 0) data[i] = -1;
|
||||
}
|
||||
|
||||
v.map(data, tileW);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needsRender(int pos) {
|
||||
return render[pos] != 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class exitVisualWalls extends CustomTiledVisual {
|
||||
public static class exitVisualWalls extends CustomTilemap {
|
||||
|
||||
{
|
||||
texture = Assets.PRISON_EXIT;
|
||||
|
||||
tileW = 12;
|
||||
tileH = 14;
|
||||
}
|
||||
|
||||
final int TEX_WIDTH = 256;
|
||||
|
||||
private static short[] render = new short[]{
|
||||
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
@ -637,21 +654,19 @@ public class PrisonBossLevel extends Level {
|
|||
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
public exitVisualWalls() {
|
||||
super(Assets.PRISON_EXIT);
|
||||
@Override
|
||||
public Tilemap create() {
|
||||
|
||||
Tilemap v = super.create();
|
||||
|
||||
int[] data = mapSimpleImage(4, 0, TEX_WIDTH);
|
||||
for (int i = 0; i < data.length; i++){
|
||||
if (render[i] == 0) data[i] = -1;
|
||||
}
|
||||
|
||||
v.map(data, tileW);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomTiledVisual create() {
|
||||
tileW = 12;
|
||||
tileH = 14;
|
||||
mapSimpleImage(4, 0);
|
||||
return super.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needsRender(int pos) {
|
||||
return render[pos] != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,9 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTilemap;
|
||||
import com.watabou.noosa.Image;
|
||||
import com.watabou.noosa.Tilemap;
|
||||
import com.watabou.utils.Random;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -94,24 +95,25 @@ public class MassGraveRoom extends SpecialRoom {
|
|||
}
|
||||
}
|
||||
|
||||
public static class Bones extends CustomTiledVisual {
|
||||
public static class Bones extends CustomTilemap {
|
||||
|
||||
private static final int WALL_OVERLAP = 3;
|
||||
private static final int FLOOR = 7;
|
||||
|
||||
public Bones(){
|
||||
super(Assets.PRISON_QUEST);
|
||||
{
|
||||
texture = Assets.PRISON_QUEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomTiledVisual create() {
|
||||
int data[] = new int[tileW*tileH];
|
||||
public Tilemap create() {
|
||||
Tilemap v = super.create();
|
||||
int[] data = new int[tileW*tileH];
|
||||
for (int i = 0; i < data.length; i++){
|
||||
if (i < tileW) data[i] = WALL_OVERLAP;
|
||||
else data[i] = FLOOR;
|
||||
}
|
||||
map( data, tileW );
|
||||
return super.create();
|
||||
v.map( data, tileW );
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,7 +27,8 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTilemap;
|
||||
import com.watabou.noosa.Tilemap;
|
||||
import com.watabou.utils.Point;
|
||||
import com.watabou.utils.Random;
|
||||
|
||||
|
@ -66,22 +67,23 @@ public class WeakFloorRoom extends SpecialRoom {
|
|||
}
|
||||
|
||||
Painter.set(level, well, Terrain.CHASM);
|
||||
CustomTiledVisual vis = new HiddenWell();
|
||||
CustomTilemap vis = new HiddenWell();
|
||||
vis.pos(well.x, well.y);
|
||||
level.customTiles.add(vis);
|
||||
}
|
||||
|
||||
public static class HiddenWell extends CustomTiledVisual {
|
||||
public static class HiddenWell extends CustomTilemap {
|
||||
|
||||
public HiddenWell(){
|
||||
super(Assets.WEAK_FLOOR);
|
||||
{
|
||||
texture = Assets.WEAK_FLOOR;
|
||||
tileW = tileH = 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomTiledVisual create() {
|
||||
tileW = tileH = 1;
|
||||
map( new int[]{Dungeon.depth/5}, 1);
|
||||
return super.create();
|
||||
public Tilemap create() {
|
||||
Tilemap v = super.create();
|
||||
v.map( new int[]{Dungeon.depth/5}, 1);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,7 +27,8 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTilemap;
|
||||
import com.watabou.noosa.Tilemap;
|
||||
import com.watabou.utils.Point;
|
||||
|
||||
public class RitualSiteRoom extends StandardRoom {
|
||||
|
@ -67,17 +68,21 @@ public class RitualSiteRoom extends StandardRoom {
|
|||
CeremonialCandle.ritualPos = c.x + (level.width() * c.y);
|
||||
}
|
||||
|
||||
public static class RitualMarker extends CustomTiledVisual {
|
||||
|
||||
public RitualMarker(){
|
||||
super( Assets.PRISON_QUEST );
|
||||
public static class RitualMarker extends CustomTilemap {
|
||||
|
||||
{
|
||||
texture = Assets.PRISON_QUEST;
|
||||
|
||||
tileW = tileH = 3;
|
||||
}
|
||||
|
||||
final int TEX_WIDTH = 64;
|
||||
|
||||
@Override
|
||||
public CustomTiledVisual create() {
|
||||
tileH = tileW = 3;
|
||||
mapSimpleImage(0, 0);
|
||||
return super.create();
|
||||
public Tilemap create() {
|
||||
Tilemap v = super.create();
|
||||
v.map(mapSimpleImage(0, 0, TEX_WIDTH), 3);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -56,7 +56,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.sprites.DiscardedItemSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTilemap;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTerrainTilemap;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTileSheet;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
|
||||
|
@ -211,7 +211,7 @@ public class GameScene extends PixelScene {
|
|||
customTiles = new Group();
|
||||
terrain.add(customTiles);
|
||||
|
||||
for( CustomTiledVisual visual : Dungeon.level.customTiles){
|
||||
for( CustomTilemap visual : Dungeon.level.customTiles){
|
||||
addCustomTile(visual);
|
||||
}
|
||||
|
||||
|
@ -256,7 +256,7 @@ public class GameScene extends PixelScene {
|
|||
customWalls = new Group();
|
||||
add(customWalls);
|
||||
|
||||
for( CustomTiledVisual visual : Dungeon.level.customWalls){
|
||||
for( CustomTilemap visual : Dungeon.level.customWalls){
|
||||
addCustomWall(visual);
|
||||
}
|
||||
|
||||
|
@ -611,11 +611,11 @@ public class GameScene extends PixelScene {
|
|||
}
|
||||
}
|
||||
|
||||
public void addCustomTile( CustomTiledVisual visual){
|
||||
public void addCustomTile( CustomTilemap visual){
|
||||
customTiles.add( visual.create() );
|
||||
}
|
||||
|
||||
public void addCustomWall( CustomTiledVisual visual){
|
||||
public void addCustomWall( CustomTilemap visual){
|
||||
customWalls.add( visual.create() );
|
||||
}
|
||||
|
||||
|
|
|
@ -28,16 +28,15 @@ import com.watabou.noosa.Tilemap;
|
|||
import com.watabou.utils.Bundlable;
|
||||
import com.watabou.utils.Bundle;
|
||||
|
||||
public abstract class CustomTiledVisual extends Tilemap implements Bundlable {
|
||||
public abstract class CustomTilemap implements Bundlable {
|
||||
|
||||
protected static final int SIZE = DungeonTilemap.SIZE;
|
||||
|
||||
public int tileX, tileY; //x and y coords for texture within a level
|
||||
public int tileW = 1, tileH = 1; //width and height in tiles
|
||||
|
||||
public CustomTiledVisual(Object tx) {
|
||||
super(tx, new TextureFilm( tx, SIZE, SIZE ) );
|
||||
}
|
||||
|
||||
protected Object texture;
|
||||
private Tilemap vis = null;
|
||||
|
||||
public void pos(int pos) {
|
||||
pos( pos%Dungeon.level.width(), pos/Dungeon.level.width() );
|
||||
|
@ -62,40 +61,39 @@ public abstract class CustomTiledVisual extends Tilemap implements Bundlable {
|
|||
this.tileW = tileW;
|
||||
this.tileH = tileH;
|
||||
}
|
||||
|
||||
public CustomTiledVisual create(){
|
||||
camera = null;
|
||||
x = tileX*SIZE;
|
||||
y = tileY*SIZE;
|
||||
return this;
|
||||
}
|
||||
|
||||
//assumes that width and height are already set.
|
||||
protected void mapSimpleImage(int txX, int txY){
|
||||
int data[] = new int[tileW * tileH];
|
||||
int texTileWidth = texture.width/SIZE;
|
||||
|
||||
//utility method for getting data for a simple image
|
||||
//assumes tileW and tileH have already been set
|
||||
protected int[] mapSimpleImage(int txX, int txY, int texW){
|
||||
int[] data = new int[tileW * tileH];
|
||||
int texTileWidth = texW/SIZE;
|
||||
int x = txX, y = txY;
|
||||
for (int i = 0; i < data.length; i++){
|
||||
data[i] = x + (texTileWidth*y);
|
||||
|
||||
|
||||
x++;
|
||||
if ((x - txX) == tileW){
|
||||
x = txX;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
map(data, tileW);
|
||||
return data;
|
||||
}
|
||||
|
||||
public Tilemap create(){
|
||||
if (vis != null && vis.alive) vis.killAndErase();
|
||||
vis = new Tilemap(texture, new TextureFilm( texture, SIZE, SIZE ));
|
||||
vis.x = tileX*SIZE;
|
||||
vis.y = tileY*SIZE;
|
||||
return vis;
|
||||
}
|
||||
|
||||
//x and y here are the coordinates tapped within the tile visual
|
||||
public Image image(int tileX, int tileY){
|
||||
if (!needsRender(tileX + mapWidth*tileY)){
|
||||
if (vis == null){
|
||||
return null;
|
||||
} else {
|
||||
Image img = new Image(texture);
|
||||
img.frame(tileset.get(data[tileX + mapWidth * tileY]));
|
||||
return img;
|
||||
return vis.image(tileX, tileY);
|
||||
}
|
||||
}
|
||||
|
|
@ -103,6 +103,6 @@ public class DungeonTerrainTilemap extends DungeonTilemap {
|
|||
|
||||
@Override
|
||||
protected boolean needsRender(int pos) {
|
||||
return data[pos] >= 0 && data[pos] != DungeonTileSheet.WATER;
|
||||
return super.needsRender(pos) && data[pos] != DungeonTileSheet.WATER;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,9 +97,5 @@ public class DungeonWallsTilemap extends DungeonTilemap {
|
|||
public boolean overlapsScreenPoint( int x, int y ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needsRender(int pos) {
|
||||
return data[pos] != -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -60,9 +60,4 @@ public class GridTileMap extends DungeonTilemap {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needsRender(int pos) {
|
||||
return data[pos] != -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,9 +49,4 @@ public class RaisedTerrainTilemap extends DungeonTilemap {
|
|||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needsRender(int pos) {
|
||||
return data[pos] != -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,8 +108,4 @@ public class TerrainFeaturesTilemap extends DungeonTilemap {
|
|||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needsRender(int pos) {
|
||||
return data[pos] != -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -215,9 +215,5 @@ public class WallBlockingTilemap extends Tilemap {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needsRender(int pos) {
|
||||
return data[pos] > BLOCK_NONE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTilemap;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTerrainTilemap;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
|
||||
|
@ -50,11 +50,11 @@ public class WndInfoCell extends Window {
|
|||
tile = Terrain.CHASM;
|
||||
}
|
||||
|
||||
CustomTiledVisual customTile = null;
|
||||
CustomTilemap customTile = null;
|
||||
Image customImage = null;
|
||||
int x = cell % Dungeon.level.width();
|
||||
int y = cell / Dungeon.level.width();
|
||||
for (CustomTiledVisual i : Dungeon.level.customTiles){
|
||||
for (CustomTilemap i : Dungeon.level.customTiles){
|
||||
if ((x >= i.tileX && x < i.tileX+i.tileW) &&
|
||||
(y >= i.tileY && y < i.tileY+i.tileH)){
|
||||
if ((customImage = i.image(x - i.tileX, y - i.tileY)) != null) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user