From c52d4aa4b640e8c8b4e892a4b32d87148ad0a56f Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Tue, 5 Mar 2019 17:31:34 -0800 Subject: [PATCH] Hacked together footstep sounds --- core/src/gdx/diablo/entity/DT1Sound.java | 42 ++++++++++++++++++++++ core/src/gdx/diablo/entity/Player.java | 36 +++++++++++++++++-- core/src/gdx/diablo/map/Map.java | 11 ++++-- core/src/gdx/diablo/screen/GameScreen.java | 2 +- 4 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 core/src/gdx/diablo/entity/DT1Sound.java diff --git a/core/src/gdx/diablo/entity/DT1Sound.java b/core/src/gdx/diablo/entity/DT1Sound.java new file mode 100644 index 00000000..863cceaf --- /dev/null +++ b/core/src/gdx/diablo/entity/DT1Sound.java @@ -0,0 +1,42 @@ +package gdx.diablo.entity; + +import gdx.diablo.codec.excel.Levels; +import gdx.diablo.map.DT1; + +public class DT1Sound { + + private DT1Sound() {} + + public static String getType(Levels.Entry levels, DT1.Tile tile) { + int soundIndex = tile.soundIndex & 0xFF; + switch (levels.LevelType) { + case 1: return getType1(soundIndex); + case 2: return getType2(soundIndex); + default: return "dirt"; + } + + /** + * best guess: + * + * level type determines table + * soundIndex determines which sound to pull from table + * NOT ALWAYS POWER OF 2 -- some tiles in act 2 town are 1,17,65,129 + * it's possible they are flags to represent random, i.e., 17 = random 1 or 16 + */ + } + + private static String getType1(int soundIndex) { + switch (soundIndex) { + case 0: return "dirt"; + default: return "dirt"; + } + } + + private static String getType2(int soundIndex) { + switch (soundIndex) { + case 0: return "dirt"; + case 128: return "wood"; + default: return "dirt"; + } + } +} diff --git a/core/src/gdx/diablo/entity/Player.java b/core/src/gdx/diablo/entity/Player.java index eed8cd56..b3031148 100644 --- a/core/src/gdx/diablo/entity/Player.java +++ b/core/src/gdx/diablo/entity/Player.java @@ -10,7 +10,6 @@ import com.badlogic.gdx.utils.GdxRuntimeException; import org.apache.commons.lang3.ObjectUtils; import java.util.EnumMap; -import java.util.Map; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; @@ -21,8 +20,11 @@ import gdx.diablo.codec.COFD2; import gdx.diablo.codec.D2S; import gdx.diablo.codec.excel.Armor; import gdx.diablo.codec.excel.Weapons; +import gdx.diablo.graphics.PaletteIndexedBatch; import gdx.diablo.item.BodyLoc; import gdx.diablo.item.Item; +import gdx.diablo.map.DT1.Tile; +import gdx.diablo.map.Map; import gdx.diablo.server.Connect; public class Player extends Entity { @@ -108,9 +110,39 @@ public class Player extends Entity { } } + boolean ignoreFootstep = false; + + @Override + public void draw(PaletteIndexedBatch batch) { + super.draw(batch); + if (mode.equalsIgnoreCase("RN") || mode.equalsIgnoreCase("WL")) { + int frame = animation.getFrame(); + int numFrames = animation.getNumFramesPerDir(); + if (frame == 0 || frame == numFrames >>> 1) { + if (ignoreFootstep) return; + ignoreFootstep = true; + int x = Map.round(position.x); + int y = Map.round(position.y); + int tx = x < 0 + ? ((x + 1) / Tile.SUBTILE_SIZE) - 1 + : (x / Tile.SUBTILE_SIZE); + int ty = y < 0 + ? ((y + 1) / Tile.SUBTILE_SIZE) - 1 + : (y / Tile.SUBTILE_SIZE); + Map map = Map.instance; + Map.Zone zone = map.getZone(x, y); + Tile tile = map.getTile(0, tx, ty); + String type = DT1Sound.getType(zone.level, tile); + Diablo.audio.play("light_run_" + type + "_1", true); + } else { + ignoreFootstep = false; + } + } + } + private void loadEquipped(EnumMap items) { equipped.putAll(items); - for (Map.Entry entry : items.entrySet()) { + for (java.util.Map.Entry entry : items.entrySet()) { entry.getValue().load(); //if (DEBUG_EQUIPPED) Gdx.app.debug(TAG, entry.getKey() + ": " + entry.getValue()); } diff --git a/core/src/gdx/diablo/map/Map.java b/core/src/gdx/diablo/map/Map.java index 13b18791..db341826 100644 --- a/core/src/gdx/diablo/map/Map.java +++ b/core/src/gdx/diablo/map/Map.java @@ -272,13 +272,14 @@ public class Map implements Disposable { } } - static int round(float i) { + public static int round(float i) { return MathUtils.round(i); } // TODO: maybe replace with R-tree? // https://en.wikipedia.org/wiki/R-tree Array zones = new Array<>(); IntMap dt1s; + public static Map instance; // TODO: remove private Map() {} @@ -501,7 +502,7 @@ public class Map implements Disposable { } } - Zone getZone(int x, int y) { + public Zone getZone(int x, int y) { for (Zone zone : zones) { if (zone.contains(x, y)) { return zone; @@ -542,6 +543,12 @@ public class Map implements Disposable { return zone.flags(x, y); } + public DT1.Tile getTile(int l, int x, int y) { + Zone zone = getZone(x, y); + if (zone == null) return null; + return zone.get(l, x, y).tile; + } + /** * @param x world sub-tile * @param y world sub-tile diff --git a/core/src/gdx/diablo/screen/GameScreen.java b/core/src/gdx/diablo/screen/GameScreen.java index 16b25449..709195dd 100644 --- a/core/src/gdx/diablo/screen/GameScreen.java +++ b/core/src/gdx/diablo/screen/GameScreen.java @@ -507,7 +507,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable Diablo.music.stop(); Diablo.assets.get(windowopenDescriptor).play(); - map = Diablo.assets.get(mapDescriptor); + Map.instance = map = Diablo.assets.get(mapDescriptor); // TODO: remove Map.instance mapRenderer = new MapRenderer(Diablo.batch); mapRenderer.setMap(map); mapRenderer.setSrc(player);