diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-09-25 00:11:29 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-09-25 00:11:29 +0200 |
commit | e8319e6bdae1914f53f2ce8bd2d66bafc82faef4 (patch) | |
tree | aaa295778ff3c229bd947086d6c5602b3b05b55b /core/src/ch/asynk/tankontank | |
parent | 630f36b915f2e8aeff15ff8cd808f8459b67920f (diff) | |
download | RustAndDust-e8319e6bdae1914f53f2ce8bd2d66bafc82faef4.zip RustAndDust-e8319e6bdae1914f53f2ce8bd2d66bafc82faef4.tar.gz |
add Board.distance(int, int, int, int)
Diffstat (limited to 'core/src/ch/asynk/tankontank')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 2cee905..20bf494 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -110,6 +110,29 @@ public abstract class Board extends Image implements Disposable return tiles[col + (row * cfg.cols)]; } + public int distance(int col0, int row0, int col1, int row1) + { + int a = (row1 - row0); + // transform into a system where all tiles in the same row have the same value of X + // and all tiles in the same column have the same value of Y non-staggering coordinates + int b = ((col1 + ((row1 + 1) / 2)) - (col0 + ((row0 + 1) / 2))); + int c = (b - a); + int aa = Math.abs(a); + int ab = Math.abs(b); + int ac = Math.abs(c); + if (ac > aa) { + if (ac > ab) + return ac; + else + return ab; + } else { + if (aa > ab) + return aa; + else + return ab; + } + } + @Override public void setPosition(float x, float y) { |