Skip to content

Commit

Permalink
Tile elevators adjust their wall heights now
Browse files Browse the repository at this point in the history
  • Loading branch information
Interrupt committed Oct 13, 2020
1 parent 00f2e01 commit e14c3a8
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,17 @@ public void tick(Level level, float delta) {
if(t != null) {
if (elevatorType == ElevatorType.FLOOR || elevatorType == ElevatorType.BOTH) {
t.floorHeight += moving;
t.offsetBottomWallSurfaces(moving);
}
if (elevatorType == ElevatorType.CEILING || elevatorType == ElevatorType.BOTH) {
t.ceilHeight += moving;
t.offsetTopWallSurfaces(moving);
}
if (elevatorType == ElevatorType.OPPOSITE) {
t.floorHeight += moving;
t.ceilHeight -= moving;
t.offsetTopWallSurfaces(-moving);
t.offsetBottomWallSurfaces(moving);
}

// Make this tile totally solid when fully closed
Expand Down
34 changes: 28 additions & 6 deletions Dungeoneer/src/com/interrupt/dungeoneer/game/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ private enum Direction { NORTH, SOUTH, EAST, WEST }

public int width, height;
public Tile[] tiles;

// Used to store tile materials when saving / loading levels
public TileMaterials[] savedTileMaterials;
public TileMaterials[] tileMaterials;

public Array<Entity> entities;
public Array<Entity> non_collidable_entities;
Expand Down Expand Up @@ -243,6 +241,8 @@ public Level(int width, int height) {
version = CURRENT_VERSION;

tiles = new Tile[width * height];
tileMaterials = new TileMaterials[width * height];

entities = new Array<Entity>();
non_collidable_entities = new Array<Entity>();
static_entities = new Array<Entity>();
Expand Down Expand Up @@ -392,6 +392,8 @@ public void generate(Source source) {
width = generated.width;
height = generated.height;
tiles = generated.tiles;
tileMaterials = generated.tileMaterials;

editorMarkers = generated.editorMarkers;
genTheme = generated.genTheme;

Expand Down Expand Up @@ -517,6 +519,17 @@ private void overrideSpriteAtlas(Entity e) {
}
}

// Called after a level was unserialized from bytes or a file
public void postLoad() {
// Make sure the tile materials array matches the size of the tiles, and is filled
if(tileMaterials == null || tileMaterials.length != tiles.length) {
tileMaterials = new TileMaterials[tiles.length];
for(int i = 0; i < tiles.length; i++) {
tileMaterials[i] = new TileMaterials();
}
}
}

public void load() {
load(Source.LEVEL_START);
}
Expand Down Expand Up @@ -545,6 +558,8 @@ public void load(Source source) {
width = openLevel.width;
height = openLevel.height;
tiles = openLevel.tiles;
tileMaterials = openLevel.tileMaterials;

editorMarkers = openLevel.editorMarkers;
genTheme = DungeonGenerator.GetGenData(theme);

Expand Down Expand Up @@ -606,6 +621,8 @@ else if(!copy.isSolid && !(copy instanceof ButtonDecal))
width = generated.width;
height = generated.height;
tiles = generated.tiles;
tileMaterials = generated.tileMaterials;

editorMarkers = generated.editorMarkers;
genTheme = generated.genTheme;

Expand Down Expand Up @@ -1552,9 +1569,14 @@ public void init(Source source) {
}

// initialize tiles
for(Tile tile : tiles) {
if(tile != null)
tile.init(source);
for(int i = 0; i < tiles.length; i++) {
if(tiles[i] != null) {
tiles[i].init(source);

// attach the tile materials to the Tile
if(tileMaterials != null && i < tileMaterials.length)
tiles[i].materials = tileMaterials[i];
}
}

// init the drawables
Expand Down
4 changes: 2 additions & 2 deletions Dungeoneer/src/com/interrupt/dungeoneer/gfx/Tesselator.java
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,9 @@ else if(dir == TileEdges.East) {
float v;

if(bottomWallIndex != null && bottomWallIndex >= i) {
v = reg.getV() + checkDir.getBottomWallYOffset(dir) * 0.0625f;
v = reg.getV() + checkDir.getBottomWallYOffset(dir);
} else {
v = reg.getV() + checkDir.getWallYOffset(dir) * 0.0625f;
v = reg.getV() + checkDir.getWallYOffset(dir);
}

// This is ugly!
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public class LevelSerializer {
kryo.register(Array.class);

// register some serializers
kryo.register(Level.class, new LevelFieldSerializer(kryo, Level.class));
kryo.register(Prefab.class, new PrefabSerializer());
kryo.register(ArrayIterator.class, new LibGdxArrayIteratorSerializer());
kryo.register(Tile.class, new TileSerializer());
Expand All @@ -62,6 +61,7 @@ public static Level loadLevel(FileHandle file) {
Input input = new Input(file.read());
Level level = kryo.readObject(input, Level.class);
input.close();
level.postLoad();
return level;
}

Expand All @@ -70,6 +70,7 @@ public static Level loadLevel(File file) {
Input input = new Input(new FileInputStream(file));
Level level = kryo.readObject(input, Level.class);
input.close();
level.postLoad();
return level;
}
catch (Exception ex) {
Expand All @@ -81,13 +82,15 @@ public static Level loadLevel(byte[] bytes) {
Input input = new Input(bytes);
Level level = kryo.readObject(input, Level.class);
input.close();
level.postLoad();
return level;
}

public static OverworldLevel loadOverworldLevel(FileHandle file) {
Input input = new Input(file.read());
OverworldLevel level = kryo.readObject(input, OverworldLevel.class);
input.close();
level.postLoad();
return level;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public ThreadSafeLevelSerializer() {
kryo.register(Array.class);

// register some serializers
kryo.register(Level.class, new LevelFieldSerializer(kryo, Level.class));
kryo.register(Prefab.class, new PrefabSerializer());
kryo.register(Array.ArrayIterator.class, new LibGdxArrayIteratorSerializer());
kryo.register(Tile.class, new TileSerializer());
Expand Down
38 changes: 31 additions & 7 deletions Dungeoneer/src/com/interrupt/dungeoneer/tiles/Tile.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class Tile implements Serializable {
private static final long serialVersionUID = 7907569533774959788L;

public enum TileSpaceType { EMPTY, SOLID, OPEN_NW, OPEN_NE, OPEN_SW, OPEN_SE };
public enum TileSpaceType { EMPTY, SOLID, OPEN_NW, OPEN_NE, OPEN_SW, OPEN_SE };
public TileSpaceType tileSpaceType = TileSpaceType.EMPTY;
public transient boolean drawCeiling = true;
public transient boolean drawWalls = true;
Expand Down Expand Up @@ -1032,8 +1032,8 @@ public String getWallBottomTexAtlas(TileEdges dir) {
return null;
}

public byte getWallYOffset(TileEdges dir) {
Byte found = null;
public float getWallYOffset(TileEdges dir) {
Float found = null;

if(materials != null) {
TileSurface s = materials.getTopSurface(dir);
Expand All @@ -1049,7 +1049,7 @@ public byte getWallYOffset(TileEdges dir) {
return found;
}

public void setWallYOffset(TileEdges dir, byte val) {
public void setWallYOffset(TileEdges dir, float val) {
if(materials == null) {
materials = new TileMaterials();
}
Expand All @@ -1063,8 +1063,8 @@ public void setWallYOffset(TileEdges dir, byte val) {
s.yOffset = val;
}

public byte getBottomWallYOffset(TileEdges dir) {
Byte found = null;
public float getBottomWallYOffset(TileEdges dir) {
Float found = null;

if(materials != null) {
TileSurface s = materials.getBottomSurface(dir);
Expand All @@ -1080,7 +1080,7 @@ public byte getBottomWallYOffset(TileEdges dir) {
return found;
}

public void setBottomWallYOffset(TileEdges dir, byte val) {
public void setBottomWallYOffset(TileEdges dir, float val) {
if(materials == null) {
materials = new TileMaterials();
}
Expand All @@ -1094,6 +1094,30 @@ public void setBottomWallYOffset(TileEdges dir, byte val) {
s.yOffset = val;
}

public void offsetTopWallSurfaces(float amount) {
for(int i = 0; i < TileEdges.values().length; i++) {
TileEdges edge = TileEdges.values()[i];
TileSurface surface = materials.getTopSurface(edge);
if(surface == null) {
surface = new TileSurface();
materials.setTopSurface(edge, surface);
}
surface.yOffset += amount;
}
}

public void offsetBottomWallSurfaces(float amount) {
for(int i = 0; i < TileEdges.values().length; i++) {
TileEdges edge = TileEdges.values()[i];
TileSurface surface = materials.getBottomSurface(edge);
if(surface == null) {
surface = new TileSurface();
materials.setBottomSurface(edge, surface);
}
surface.yOffset += amount;
}
}

public void setWallTexture(TileEdges dir, byte tex, String atlas) {
if(dir == TileEdges.North) {
northTex = tex;
Expand Down
12 changes: 12 additions & 0 deletions Dungeoneer/src/com/interrupt/dungeoneer/tiles/TileMaterials.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,16 @@ public void setTopSurface(TileEdges dir, TileSurface s) {
public void setBottomSurface(TileEdges dir, TileSurface s) {
bottomSurfaces.put(dir, s);
}

public void offsetBottomSurfaces(float moving) {
for(int i = 0; i < bottomSurfaces.size; i++) {
bottomSurfaces.getValueAt(i).yOffset += moving;
}
}

public void offsetTopSurfaces(float moving) {
for(int i = 0; i < topSurfaces.size; i++) {
topSurfaces.getValueAt(i).yOffset += moving;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ public class TileSurface {
// TODO: Someday move the texture and texture atlas into here as well

// Texture Offsets
public byte yOffset = 0;
public byte xOffset = 0;
public float yOffset = 0;
public float xOffset = 0;

public TileSurface() { }
}

0 comments on commit e14c3a8

Please sign in to comment.