Added bi-directional warping between 1 and 8

Added bi-directional warping between 1 and 8 (see #12)
Warps are set through the build process, I don't know how viable this is for all warps
This commit is contained in:
Collin Smith 2019-03-15 02:38:58 -07:00
parent e3366849fa
commit f40646fb5a
3 changed files with 48 additions and 11 deletions

View File

@ -2,7 +2,6 @@ package com.riiablo.entity;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.IntIntMap;
@ -23,6 +22,7 @@ public class Warp extends Entity {
public final Map map;
public final Map.Zone zone;
public final int index;
public final LvlWarp.Entry warp;
public final Levels.Entry dstLevel;
@ -31,10 +31,15 @@ public class Warp extends Entity {
BBox box;
public final IntIntMap substs;
public Warp(Map map, Map.Zone zone, int orientation, int mainIndex, int subIndex, int x, int y) {
public Warp(Map map, Map.Zone zone, int index, int x, int y) {
super(Type.WRP, "warp", null);
this.map = map;
this.zone = zone;
this.map = map;
this.zone = zone;
this.index = index;
final int mainIndex = DT1.Tile.Index.mainIndex(index);
final int subIndex = DT1.Tile.Index.subIndex(index);
final int orientation = DT1.Tile.Index.orientation(index);
int dst = zone.level.Vis[mainIndex];
assert dst > 0 : "Warp to unknown level!";
@ -61,9 +66,12 @@ public class Warp extends Entity {
if (warp.LitVersion) {
substs = new IntIntMap();
// FIXME: Below will cover overwhelming majority of cases -- need to solve act 5 ice cave case where 3 tiles are used
// I think this can be done by checking if there's a texture with the same id, else it's a floor warp
if (subIndex < 2) {
substs.put(DT1.Tile.Index.create(orientation, mainIndex, 0), DT1.Tile.Index.create(orientation, mainIndex, 2));
substs.put(DT1.Tile.Index.create(orientation, mainIndex, 1), DT1.Tile.Index.create(orientation, mainIndex, 3));
for (int i = 0; i < 2; i++) {
substs.put(DT1.Tile.Index.create(orientation, mainIndex, i), DT1.Tile.Index.create(orientation, mainIndex, i + warp.Tiles));
}
} else {
substs.put(DT1.Tile.Index.create(0, subIndex, 0), DT1.Tile.Index.create(0, subIndex, 4));
substs.put(DT1.Tile.Index.create(0, subIndex, 1), DT1.Tile.Index.create(0, subIndex, 5));
@ -79,9 +87,10 @@ public class Warp extends Entity {
public void interact(GameScreen gameScreen) {
System.out.println("zim zim zala bim");
Map.Zone dst = map.findZone(dstLevel);
GridPoint2 point = dst.find(0, 1, Map.ID.VIS_0_03);
System.out.println(point);
gameScreen.player.position.set(dst.getGlobalX(point.x * 5) + 2, dst.getGlobalY(point.y * 5) + 24 * 5 + 5);
int dstIndex = zone.getWarp(index);
Vector2 dstPos = dst.find(dstIndex);
if (dstPos == null) throw new AssertionError("Invalid dstPos: " + dstIndex);
gameScreen.player.position.set(dstPos);
gameScreen.player.setPath(map, null);
}

View File

@ -369,6 +369,7 @@ public class Map implements Disposable {
// ID_VIS_5_42
zone.presets[5][zone.gridsY - 2] = Preset.of(Riiablo.files.LvlPrest.get(52), 0);
zone.setWarp(ID.VIS_5_42, ID.VIS_0_03);
zone.generator = new Zone.Generator() {
@Override
@ -389,6 +390,7 @@ public class Map implements Disposable {
zone.presets[0][1] = Preset.of(Riiablo.files.LvlPrest.get(84), 0);
zone.presets[1][1] = Preset.of(Riiablo.files.LvlPrest.get(61), 1);
zone.presets[1][0] = Preset.of(Riiablo.files.LvlPrest.get(97), 0);
zone.setWarp(ID.VIS_0_03, ID.VIS_5_42);
return map;
}
@ -635,6 +637,7 @@ public class Map implements Disposable {
public static class Zone {
static final Array<Entity> EMPTY_ENTITY_ARRAY = new Array<>(0);
static final IntIntMap EMPTY_INT_INT_MAP = new IntIntMap(0);
int x, y;
int width, height;
@ -651,6 +654,7 @@ public class Map implements Disposable {
Tile tiles[][][];
byte flags[][];
Array<Entity> entities;
IntIntMap warps;
Generator generator;
@ -673,6 +677,7 @@ public class Map implements Disposable {
presets = new Preset[gridsX][gridsY];
flags = new byte[width][height];
entities = EMPTY_ENTITY_ARRAY;
warps = EMPTY_INT_INT_MAP;
}
/**
@ -694,6 +699,7 @@ public class Map implements Disposable {
presets = new Preset[gridsX][gridsY];
flags = new byte[width][height];
entities = EMPTY_ENTITY_ARRAY;
warps = EMPTY_INT_INT_MAP;
}
private void loadEntities(DS1 ds1, int gridX, int gridY) {
@ -713,10 +719,19 @@ public class Map implements Disposable {
final int x = this.x + (warpX * DT1.Tile.SUBTILE_SIZE);
final int y = this.y + (warpY * DT1.Tile.SUBTILE_SIZE);
if (entities == EMPTY_ENTITY_ARRAY) entities = new Array<>();
Warp warp = new Warp(map, this, tile.cell.orientation, tile.cell.mainIndex, tile.cell.subIndex, x, y);
Warp warp = new Warp(map, this, tile.cell.id, x, y);
entities.add(warp);
}
void setWarp(int src, int dst) {
if (warps == EMPTY_INT_INT_MAP) warps = new IntIntMap(4);
warps.put(src, dst);
}
public int getWarp(int src) {
return warps.get(src, -1);
}
public void setPosition(int x, int y) {
this.x = x;
this.y = y;
@ -729,6 +744,19 @@ public class Map implements Disposable {
return presets[x][y].ds1.find(id);
}
public Vector2 find(int id) {
for (Entity entity : entities) {
if (entity instanceof Warp) {
Warp warp = (Warp) entity;
if (warp.index == id) {
return warp.position();
}
}
}
return null;
}
@Override
public String toString() {
return new ToStringBuilder(this)

View File

@ -56,7 +56,7 @@ public class MapLoader extends AsynchronousAssetLoader<Map, MapLoader.MapParamet
@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle file, MapLoader.MapParameters params) {
Array<AssetDescriptor> dependencies = new Array<>();
for (int def = Map.ACT_DEF[params.act]; def < /*53*/Map.ACT_DEF[params.act + 1]; def++) {
for (int def = Map.ACT_DEF[params.act]; def < 108/*Map.ACT_DEF[params.act + 1]*/; def++) {
LvlPrest.Entry preset = Riiablo.files.LvlPrest.get(def);
for (int i = 0; i < preset.File.length; i++) {
if (preset.File[i].charAt(0) != '0') {