v0.6.3: corrected distNoDiag function, now named trueDistance

This commit is contained in:
Evan Debenham 2017-12-20 02:27:27 -05:00
parent 9f78c6b6c2
commit 608a09a92c
5 changed files with 7 additions and 6 deletions
core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels

View File

@ -950,12 +950,13 @@ public abstract class Level implements Bundlable {
return distance( a, b ) == 1;
}
public int distNoDiag( int a, int b){
//uses pythagorean theorum for true distance, as if there was no movement grid
public float trueDistance(int a, int b){
int ax = a % width();
int ay = a / width();
int bx = b % width();
int by = b / width();
return Math.abs( ax - bx ) + Math.abs( ay - by );
return (float)Math.sqrt(Math.pow(Math.abs( ax - bx ), 2) + Math.pow(Math.abs( ay - by ), 2));
}
//returns true if the input is a valid tile within the level

View File

@ -60,7 +60,7 @@ public class DisintegrationTrap extends Trap {
for (Char ch : Actor.chars()){
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
if (bolt.collisionPos == ch.pos &&
(target == null || Dungeon.level.distNoDiag(pos, ch.pos) < Dungeon.level.distNoDiag(pos, target.pos))){
(target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))){
target = ch;
}
}

View File

@ -57,7 +57,7 @@ public class GrimTrap extends Trap {
for (Char ch : Actor.chars()){
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
if (bolt.collisionPos == ch.pos &&
(target == null || Dungeon.level.distNoDiag(pos, ch.pos) < Dungeon.level.distNoDiag(pos, target.pos))){
(target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))){
target = ch;
}
}

View File

@ -57,7 +57,7 @@ public class PoisonDartTrap extends Trap {
for (Char ch : Actor.chars()){
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
if (bolt.collisionPos == ch.pos &&
(target == null || Dungeon.level.distNoDiag(pos, ch.pos) < Dungeon.level.distNoDiag(pos, target.pos))){
(target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))){
target = ch;
}
}

View File

@ -55,7 +55,7 @@ public class WornDartTrap extends Trap {
for (Char ch : Actor.chars()){
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
if (bolt.collisionPos == ch.pos &&
(target == null || Dungeon.level.distNoDiag(pos, ch.pos) < Dungeon.level.distNoDiag(pos, target.pos))){
(target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))){
target = ch;
}
}