private OffsetHex ConvertCubeCoordinatesToOffset(CubeHex cubeHex) { var row = cubeHex.r; var col = cubeHex.q + (cubeHex.r - 1 * (cubeHex.r & 1)) / 2; return(new OffsetHex(row, col)); }
public static OffsetHex FromPixel(float hexSize, float x, float y) { float q = x * 2.0f / 3.0f / hexSize; float r = (-x / 3.0f + HexHandler.SQRT3 / 3.0f * y) / hexSize; return(CubeHex.CubeRound(q, -q - r, r).ToOffset()); }
public List <CubeHex> GetTouches() { var result = new List <CubeHex>(); for (int i = 0; i < 3; i++) { CubeHex offset = _Touches[i + 3 * (int)_direction]; result.Add(offset + _hex); } return(result); }
public override bool Equals(object obj) { if (obj == null || GetType() != obj.GetType()) { return(false); } else { CubeHex b = (CubeHex)obj; return(this == b); } }
public CubeHex GetCube() { CubeHex pos = new CubeHex(0, 0, 0); int x = value; int i = 0; while (x > 0) { int k = x % 7; x /= 7; pos += decode[i, k]; i += 1; } return(pos); }
public CubeCorner(int q, int r, CornerDirection direction) { _hex = new CubeHex(q, r); _direction = direction; }
// # Constructors public CubeCorner(CubeHex hex, CornerDirection direction) { _hex = hex; _direction = direction; }
// Constructor using CubeHex public OffsetHex(CubeHex cube) : this(cube.X, cube.Y, cube.Z) { }
// Returns a HexTile based on its cube coordinates // See reference for info on cube coordinates HexTile GetHexTileByCube(CubeHex cube) { var offsetHex = new OffsetHex(cube); if (!IsHexWithinBounds(offsetHex.X, offsetHex.Y)) { return null; } return GameBoard[offsetHex.X, offsetHex.Y]; }
// Gets tile distance between A and B int DistanceBetween(HexTile tileA, HexTile tileB) { var a = new CubeHex(tileA); var b = new CubeHex(tileB); var maxParam = new int[3]; maxParam[0] = Mathf.Abs(a.X - b.X); maxParam[1] = Mathf.Abs(a.Y - b.Y); maxParam[2] = Mathf.Abs(a.Z - b.Z); return Mathf.Max(maxParam); }
// Get all tiles within range r, centered at (x, y) // - includeCenter decides if the center tile is returned // See reference for explanation of algorithm // // Used for AOE skills public List<HexTile> GetTilesInRange(int x, int y, int r) { List<HexTile> inRangeTiles = new List<HexTile>(); // Convert center offset coord to cube coord var centerCube = new CubeHex(x, y); // Loop over all tiles within the range based on cube coordinates for (var dx = -r; dx <= r; dx++) { var start = Mathf.Max(-r, -dx - r); var end = Mathf.Min(r, -dx + r); for (var dy = start; dy <= end; dy++) { var dz = -dx - dy; // Add the dx, dy, and dz to the center coord var tempCube = new CubeHex(centerCube.X + dx, centerCube.Y + dy, centerCube.Z + dz); var tile = GetHexTileByCube(tempCube); // Skip if tile is invalid, or it's the center tile and includeCenter is false if (tile == null) { continue; } inRangeTiles.Add(tile); } } return inRangeTiles; }
public CubeCorner GetCube() { var hex = CubeHex.FromGBT(_value & HexMask); return(new CubeCorner(hex, ((_value & Left) > 0 ? CornerDirection.L : CornerDirection.R))); }
public static GBTHex FromCartesian(Vector2 position) { return((GBTHex)CubeHex.FromCartesian(position)); }