Here you can find the source of distance(int x, int y, int targetX, int targetY, int minDist, int[] outCoords)
Parameter | Description |
---|---|
x | real X-coord |
y | real Y-coord |
targetX | X target point (grid) |
targetY | Y target point (grid) |
minDist | current minimum distance |
outCoords | the coordinates associated with the minimum distance found |
private static int distance(int x, int y, int targetX, int targetY, int minDist, int[] outCoords)
//package com.java2s; /*/*from w w w . j a v a 2s .co m*/ * [[ Frozen-Bubble ]] * * Copyright (c) 2000-2003 Guillaume Cottenceau. * Java sourcecode - Copyright (c) 2003 Glenn Sanson. * Additional source - Copyright (c) 2013 Eric Fortin. * * This code is distributed under the GNU General Public License * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 or 3, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to: * Free Software Foundation, Inc. * 675 Mass Ave * Cambridge, MA 02139, USA * * Artwork: * Alexis Younes <73lab at free.fr> * (everything but the bubbles) * Amaury Amblard-Ladurantie <amaury at linuxfr.org> * (the bubbles) * * Soundtrack: * Matthias Le Bidan <matthias.le_bidan at caramail.com> * (the three musics and all the sound effects) * * Design & Programming: * Guillaume Cottenceau <guillaume.cottenceau at free.fr> * (design and manage the project, whole Perl sourcecode) * * Java version: * Glenn Sanson <glenn.sanson at free.fr> * (whole Java sourcecode, including JIGA classes * http://glenn.sanson.free.fr/jiga/) * * Android port: * Pawel Aleksander Fedorynski <pfedor@fuw.edu.pl> * Eric Fortin <videogameboy76 at yahoo.com> * Copyright (c) Google Inc. * * [[ http://glenn.sanson.free.fr/fb/ ]] * [[ http://www.frozen-bubble.org/ ]] */ public class Main { /** * Calculates the distance between real position and a specific point in the grid * @param x real X-coord * @param y real Y-coord * @param targetX X target point (grid) * @param targetY Y target point (grid) * @param minDist current minimum distance * @param outCoords the coordinates associated with the minimum distance found * @return The real distance or the current minDist if the point is out of the grid or empty */ private static int distance(int x, int y, int targetX, int targetY, int minDist, int[] outCoords) { int distance = minDist; if (targetX >= 0 && targetX < 8 && targetY >= 0 && targetY < 13) { int dx = (targetX << 5) - ((targetY % 2) << 4) - x; int dy = targetY * 28 - y; distance = dx * dx + dy * dy; if (distance < minDist) { outCoords[0] = targetX; outCoords[1] = targetY; } else { distance = minDist; } } return distance; } }