mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-02-22 12:38:12 +07:00
Hacked together footstep sounds
This commit is contained in:
parent
87e95ad1aa
commit
c52d4aa4b6
42
core/src/gdx/diablo/entity/DT1Sound.java
Normal file
42
core/src/gdx/diablo/entity/DT1Sound.java
Normal file
@ -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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,6 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
|
|||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
@ -21,8 +20,11 @@ import gdx.diablo.codec.COFD2;
|
|||||||
import gdx.diablo.codec.D2S;
|
import gdx.diablo.codec.D2S;
|
||||||
import gdx.diablo.codec.excel.Armor;
|
import gdx.diablo.codec.excel.Armor;
|
||||||
import gdx.diablo.codec.excel.Weapons;
|
import gdx.diablo.codec.excel.Weapons;
|
||||||
|
import gdx.diablo.graphics.PaletteIndexedBatch;
|
||||||
import gdx.diablo.item.BodyLoc;
|
import gdx.diablo.item.BodyLoc;
|
||||||
import gdx.diablo.item.Item;
|
import gdx.diablo.item.Item;
|
||||||
|
import gdx.diablo.map.DT1.Tile;
|
||||||
|
import gdx.diablo.map.Map;
|
||||||
import gdx.diablo.server.Connect;
|
import gdx.diablo.server.Connect;
|
||||||
|
|
||||||
public class Player extends Entity {
|
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<BodyLoc, Item> items) {
|
private void loadEquipped(EnumMap<BodyLoc, Item> items) {
|
||||||
equipped.putAll(items);
|
equipped.putAll(items);
|
||||||
for (Map.Entry<BodyLoc, Item> entry : items.entrySet()) {
|
for (java.util.Map.Entry<BodyLoc, Item> entry : items.entrySet()) {
|
||||||
entry.getValue().load();
|
entry.getValue().load();
|
||||||
//if (DEBUG_EQUIPPED) Gdx.app.debug(TAG, entry.getKey() + ": " + entry.getValue());
|
//if (DEBUG_EQUIPPED) Gdx.app.debug(TAG, entry.getKey() + ": " + entry.getValue());
|
||||||
}
|
}
|
||||||
|
@ -272,13 +272,14 @@ public class Map implements Disposable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int round(float i) {
|
public static int round(float i) {
|
||||||
return MathUtils.round(i);
|
return MathUtils.round(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: maybe replace with R-tree? // https://en.wikipedia.org/wiki/R-tree
|
// TODO: maybe replace with R-tree? // https://en.wikipedia.org/wiki/R-tree
|
||||||
Array<Zone> zones = new Array<>();
|
Array<Zone> zones = new Array<>();
|
||||||
IntMap<DT1s> dt1s;
|
IntMap<DT1s> dt1s;
|
||||||
|
public static Map instance; // TODO: remove
|
||||||
|
|
||||||
private Map() {}
|
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) {
|
for (Zone zone : zones) {
|
||||||
if (zone.contains(x, y)) {
|
if (zone.contains(x, y)) {
|
||||||
return zone;
|
return zone;
|
||||||
@ -542,6 +543,12 @@ public class Map implements Disposable {
|
|||||||
return zone.flags(x, y);
|
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 x world sub-tile
|
||||||
* @param y world sub-tile
|
* @param y world sub-tile
|
||||||
|
@ -507,7 +507,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
|||||||
Diablo.music.stop();
|
Diablo.music.stop();
|
||||||
Diablo.assets.get(windowopenDescriptor).play();
|
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 = new MapRenderer(Diablo.batch);
|
||||||
mapRenderer.setMap(map);
|
mapRenderer.setMap(map);
|
||||||
mapRenderer.setSrc(player);
|
mapRenderer.setSrc(player);
|
||||||
|
Loading…
Reference in New Issue
Block a user