From e8319e6bdae1914f53f2ce8bd2d66bafc82faef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 25 Sep 2014 00:11:29 +0200 Subject: add Board.distance(int, int, int, int) --- core/src/ch/asynk/tankontank/engine/Board.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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) { -- cgit v1.1-2-g2b99