Here you can find the source of makeNeighbor(Point theHex, int direction)
Parameter | Description |
---|---|
theHex | The location of the hexagon whose neighbor is sought. |
direction | The direction to get the neighbor. Valid range is 0 to 5, with 0 meaning up and advancing clockwise around the hex. |
public static Point makeNeighbor(Point theHex, int direction)
//package com.java2s; /*// w ww . j a v a2s . c o m * JOGRE (Java Online Gaming Real-time Engine) - API * Copyright (C) 2006 Richard Walter (rwalter42@yahoo.com) * http://jogre.sourceforge.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * 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 the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import java.awt.Point; public class Main { private static int[] neighborCols = { 0, 1, 1, 0, -1, -1 }; private static int[][] neighborRows = { { -1, -1, 0, 1, 0, -1 }, { -1, 0, 1, 1, 1, 0 } }; /** * This method will return a point that is the neighbor of the given point * in the given direction. * * @param theHex The location of the hexagon whose neighbor is sought. * @param direction The direction to get the neighbor. Valid range is * 0 to 5, with 0 meaning up and advancing clockwise * around the hex. * @return a new point that is the neighbor of the given hex in the requested * direction. */ public static Point makeNeighbor(Point theHex, int direction) { int colPolarity = (theHex.x & 0x01); return new Point(theHex.x + neighborCols[direction], theHex.y + neighborRows[colPolarity][direction]); } }