v0.6.3: corrected distNoDiag function, now named trueDistance
This commit is contained in:
@@ -950,12 +950,13 @@ public abstract class Level implements Bundlable {
|
|||||||
return distance( a, b ) == 1;
|
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 ax = a % width();
|
||||||
int ay = a / width();
|
int ay = a / width();
|
||||||
int bx = b % width();
|
int bx = b % width();
|
||||||
int by = 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
|
//returns true if the input is a valid tile within the level
|
||||||
|
|||||||
+1
-1
@@ -60,7 +60,7 @@ public class DisintegrationTrap extends Trap {
|
|||||||
for (Char ch : Actor.chars()){
|
for (Char ch : Actor.chars()){
|
||||||
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
|
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
|
||||||
if (bolt.collisionPos == ch.pos &&
|
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;
|
target = ch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ public class GrimTrap extends Trap {
|
|||||||
for (Char ch : Actor.chars()){
|
for (Char ch : Actor.chars()){
|
||||||
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
|
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
|
||||||
if (bolt.collisionPos == ch.pos &&
|
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;
|
target = ch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ public class PoisonDartTrap extends Trap {
|
|||||||
for (Char ch : Actor.chars()){
|
for (Char ch : Actor.chars()){
|
||||||
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
|
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
|
||||||
if (bolt.collisionPos == ch.pos &&
|
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;
|
target = ch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -55,7 +55,7 @@ public class WornDartTrap extends Trap {
|
|||||||
for (Char ch : Actor.chars()){
|
for (Char ch : Actor.chars()){
|
||||||
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
|
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
|
||||||
if (bolt.collisionPos == ch.pos &&
|
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;
|
target = ch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user