/** * Gives a new point that represents the * first point multiplied by the second point * component-wise. * * @since 1.6 (Rect) * @since 1.7 (other) */ public FlatHexPoint Mul(FlatHexPoint otherPoint) { var x = X * otherPoint.X; var y = Y * otherPoint.Y; return(new FlatHexPoint(x, y)); }
public FlatHexShapeInfo <TCell> Hexagon(int side) { var storageSize = 2 * side - 1; var storageBottomLeft = new FlatHexPoint(1 - side, 1 - side); return(Shape(storageSize, storageSize, x => IsInsideHex(x, side), storageBottomLeft)); }
/** * Gives a new point that represents the * first point divided by the second point * component-wise. The division is integer * division. * * @since 1.6 (Rect) * @since 1.7 (other) */ public FlatHexPoint Div(FlatHexPoint otherPoint) { var x = Mathi.Div(X, otherPoint.X); var y = Mathi.Div(Y, otherPoint.Y); return(new FlatHexPoint(x, y)); }
/** * Gives a new point that represents the * reminder when the first point is divided * by the second point component-wise. The * division is integer division. * * @since 1.6 (Rect) * @since 1.7 (other) */ public FlatHexPoint Mod(FlatHexPoint otherPoint) { var x = GLMathf.Mod(X, otherPoint.X); var y = GLMathf.Mod(Y, otherPoint.Y); return(new FlatHexPoint(x, y)); }
void createSpawnpoints() { int _spawnpointBuffer = size / 3; int _point = size - _spawnpointBuffer; centerSpawn = new FlatHexPoint(0, 0); spawnpoints.Add(centerSpawn); northSpawn = new FlatHexPoint(0, _point); spawnpoints.Add(northSpawn); southSpawn = new FlatHexPoint(0, -_point); spawnpoints.Add(southSpawn); northEastSpwan = new FlatHexPoint(_point, 0); spawnpoints.Add(northEastSpwan); southEastSpwan = new FlatHexPoint(_point, -_point); spawnpoints.Add(southEastSpwan); northWestSpawn = new FlatHexPoint(-_point, _point); spawnpoints.Add(northWestSpawn); southWestSpawn = new FlatHexPoint(-_point, 0); spawnpoints.Add(southWestSpawn); Grid [northSpawn].Color = Color.red; Grid [southSpawn].Color = Color.red; Grid [northEastSpwan].Color = Color.red; Grid [southEastSpwan].Color = Color.red; Grid [northWestSpawn].Color = Color.red; Grid [southWestSpawn].Color = Color.red; }
private void BuildGrid() { grid = (FlatHexGrid <CellScript>) FlatHexGrid <CellScript> .FatRectangle((int)gridSize.x, (int)gridSize.y); map = new FlatHexMap(CellDimensions) .AnchorCellTopLeft() .WithWindow(ExampleUtils.ScreenRect) .AlignMiddleCenter(grid) .To3DXY(); gridCount = grid.Count(); foreach (FlatHexPoint point in grid) { if (Random.value < 0.5f) { SpawnCell(healthyCellPrefab, point); } } FlatHexPoint cancerSpawnPoint = grid.ToArray <FlatHexPoint> ()[(int)Random.Range(0, grid.ToArray <FlatHexPoint>().Count())]; if (grid[cancerSpawnPoint] != null) { Destroy(grid[cancerSpawnPoint].gameObject); } SpawnCell(cancerCellPrefab, cancerSpawnPoint); }
public FlatHexShapeInfo <TCell> ThinRectangle(int width, int height) { var storageWidth = width; var storageHeight = height + Mathi.Div(width - 1, 2); var storageBottomLeft = new FlatHexPoint(0, -Mathi.Div(width - 1, 2)); return(Shape(storageWidth, storageHeight, x => IsInsideThinRectangle(x, width, height), storageBottomLeft)); }
private static bool IsInsideXYParallelogram(FlatHexPoint point, int width, int height) { return (point.X >= 0 && point.X < width && point.Y >= 0 && point.Y < height); }
//public int[] HealthHistory = new int[50]; public PlayList(FlatHexPoint savePointLocation, MoveStyle saveMove, ActionStyle saveAction, EntityViewModel saveEnemyVM, EntityView saveEnemyView) { this.SavePointLocation = savePointLocation; this.SaveMove = saveMove; this.SaveAction = saveAction; this.SaveEnemyVM = saveEnemyVM; this.SaveEnemyView = saveEnemyView; //this.HealthHistory = healthHistory; }
private static bool IsInsideFatRectangle(FlatHexPoint point, int width, int height) { int startY = -(Mathi.Div(point.X, 2)); return (point.Y >= startY - Mathi.Mod(point.X, 2) && point.Y < startY + height && point.X >= 0 && point.X < width); }
private bool IsInsideThinRectangle(FlatHexPoint point, int width, int height) { int startY = -(Mathi.Div(point.X, 2)); return (point.Y >= startY && point.Y + Mathi.Mod(point.X, 2) < startY + height && point.X >= 0 && point.X < width); }
private static bool IsInsideRectangle(FlatHexPoint point, int width, int height) { int startY = -(GLMathf.Div(point.X, 2)); return (point.Y >= startY && point.Y < startY + height && point.X >= 0 && point.X < width); }
public void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 worldPosition = GridBuilderUtils.ScreenToWorld(root, Input.mousePosition); FlatHexPoint hexPoint = map[worldPosition]; if (grid.Contains(hexPoint)) { grid[hexPoint].HighlightOn = !grid[hexPoint].HighlightOn; } } }
private GameObject MakeCell(FlatHexPoint point) { GameObject cellPrefab = Resources.Load <GameObject>("SpaceCell"); var cell = Instantiate(cellPrefab); cell.transform.parent = transform; cell.transform.localPosition = map[point]; //ResetCellColor(cell); cell.name = point.ToString(); return(cell); }
public List <FlatHexPoint> GetNeighbors(FlatHexPoint point) { List <FlatHexPoint> neighbors = new List <FlatHexPoint> (); neighbors.Add(new FlatHexPoint(point.X, point.Y + 1)); neighbors.Add(new FlatHexPoint(point.X, point.Y - 1)); neighbors.Add(new FlatHexPoint(point.X + 1, point.Y + 1)); neighbors.Add(new FlatHexPoint(point.X - 1, point.Y + 1)); neighbors.Add(new FlatHexPoint(point.X + 1, point.Y)); neighbors.Add(new FlatHexPoint(point.X - 1, point.Y)); return(neighbors); }
// Update is called once per frame void Update() { Vector3 worldPosition = ExampleUtils.ScreenToWorld(area.root, Input.mousePosition); worldPosition = new Vector3(worldPosition.x, worldPosition.y, -1); this.transform.position = worldPosition; if (!Input.GetMouseButtonDown(0)) { return; // only destroy if we click } if (!area.grid.Contains(area.map[worldPosition])) { return; } Vector2 min = new Vector2(float.MaxValue, float.MaxValue); Vector2 max = new Vector2(float.MinValue, float.MinValue); foreach (Vector2 point in polygon.points) { min.x = Mathf.Min(min.x, point.x); min.y = Mathf.Min(min.y, point.y); max.x = Mathf.Max(max.x, point.x); max.y = Mathf.Max(max.y, point.y); } for (float i = min.x; i < max.x; i += area.CellDimensions.x / 2f) { for (float j = min.y; j < max.y; j += area.CellDimensions.y / 2f) { Vector3 test = transform.position + new Vector3(i, j, 0); if (!polygon.OverlapPoint(test)) { continue; } FlatHexPoint point = area.map[test]; if (area.grid.Contains(point) && area.grid[point] != null) { Destroy(area.grid[point].gameObject); } } } Use(); // adds to cooldown }
public static List <Vector3> getDeploymentArea(FlatHexPoint point, int radius) { List <Vector3> result = new List <Vector3> (); var area = Algorithms.GetPointsInRange <SectorCell, FlatHexPoint> (Sector.Grid, point, JKCell => JKCell.isAccessible, (p, q) => 1, radius ); foreach (var _point in area) { result.Add(Sector.Map [_point]); } return(result); }
public void MoveAndBump(CellScript incoming, FlatHexPoint point, FlatHexPoint dir) { if (!grid.Contains(point)) { Destroy(incoming.gameObject); return; } CellScript bumped = grid[point]; if (bumped != null) { MoveAndBump(bumped, point + dir, dir); } grid[point] = incoming; incoming.hexPoint = point; incoming.animationTarget = map[point]; incoming.animating = true; }
public void SpawnCell(CellScript prefab, FlatHexPoint point, FlatHexPoint bumpDirection) { if (!grid.Contains(point)) { Debug.LogError("tried to spawn cell outside of grid"); return; } CellScript cell = Instantiate(prefab.gameObject).GetComponent <CellScript>(); Vector3 worldPoint = map[point - bumpDirection]; if (prefab == healthyCellPrefab) { worldPoint.z = 2; } else { worldPoint.z = 1; } cell.transform.parent = root.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = worldPoint; cell.animationTarget = worldPoint; cell.animating = true; cell.grid = grid; cell.hexPoint = point; cell.area = this; if (bumpDirection != FlatHexPoint.Zero) { MoveAndBump(cell, point, bumpDirection); } else { if (grid[point] != null) { Destroy(grid[point].gameObject); } grid[point] = cell; } }
/** * Returns a list of Flat Hex Points including the start and end points * accounting for isAccesible and cost for each cell along the path * */ public List <FlatHexPoint> getGridPath(FlatHexPoint start, FlatHexPoint end) { List <FlatHexPoint> path = new List <FlatHexPoint> (); var _path = Algorithms.AStar <SectorCell, FlatHexPoint> (Grid, start, end, (p, q) => p.DistanceFrom(q), c => c.isAccessible, (p, q) => (Grid [p].Cost + Grid [q].Cost / 2) ); foreach (var step in _path) { path.Add(step); } return(path); }
public static void CreateUnit(Unit _unit, FlatHexPoint _point) { var template = Game.Manager.UnitRegister.Lookup(_unit.Designation); UnitController clone = Instantiate(template, Sector.Map [_point], Quaternion.identity) as UnitController; clone.unit = _unit; Sector.Grid [_point].unit = clone; Sector.Grid [_point].contents = SectorCell.Contents.unit; Sector.Grid [_point].isAccessible = false; clone.unit.coordinates.x = _point.X; clone.unit.coordinates.y = _point.Y; Debug.Log("Creating Unit at point: " + Sector.Grid [_point].name); }
/** Rotates a shape 120 degrees around the vertice shared by the three given points. The three points must form a close triangle (they must share a vertex). */ public static IEnumerable<FlatHexPoint> Rotate120About( IEnumerable<FlatHexPoint> shape, FlatHexPoint p1, FlatHexPoint p2, FlatHexPoint p3) { /* If t = (p1 + p2 + p3)/3, then the result is p => (p - t).Rotate120() + t. This can be rewritten p => p.Rotate120() - t.Rotate120() + t = p.Rotate120() (T - T.Rotate120())/3, where T = p1 + p2 + p3. This is what this method calculates. This is done so that all coordinates in intermediatary calculations stay integers. */ var translation = p1.Translate(p2.Translate(p3)); var correction = translation.Subtract(translation.Rotate120()).ScaleDown(3); return TransformShape(shape, point => point.Rotate120().Translate(correction)).ToList(); }
void Divide() { float rng = UnityEngine.Random.Range(0.0f, 1.0f); if (_calcDivide > rng) { foreach (FlatHexPoint direction in grid.GetNeighborDirections()) { FlatHexPoint neighbour = hexPoint + direction; if (grid.Contains(neighbour) && grid[neighbour] == null) { // send ourselves as the prefab! area.SpawnCell(this, neighbour, direction); return; } } if (grid.GetNeighbors(hexPoint, (CellScript n) => n._mutated).Count() == grid.GetNeighbors(hexPoint, (CellScript n) => n != null).Count()) { // don't split, totally surrounded by cancer. return; } if (!onlyDivideIntoEmptyNeighbour) { // divide anyway because cancer! FlatHexPoint[] directions = grid.GetNeighborDirections() .Where(d => grid.Contains(hexPoint + d)) .ToArray(); FlatHexPoint dir = directions[UnityEngine.Random.Range(0, directions.Length)]; area.SpawnCell(this, hexPoint + dir, dir); } } }
// Update is called once per frame void Update() { hexGrid.UnHighlightCell(currentCell); try { currentCell = hexGrid.Map[transform.position]; var block = hexGrid.Grid[currentCell]; if (block.transform.localScale.y > 1) { if (thisSoaActor != null) { thisSoaActor.Kill("Mountain"); } } hexGrid.HighlightCell(currentCell); } catch { Debug.Log("BAD POINT: " + transform.name + " at " + transform.position); } }
/** * Gives a coloring of the grid such that * if a point p has color k, then all points * p + m[ux, 0] + n[vx, vy] have the same color * for any integers a and b. * * More information anout grid colorings: * http://gamelogic.co.za/2013/12/18/what-are-grid-colorings/ * * @since 1.7 */ public int __GetColor__ReferenceImplementation(int ux, int vx, int vy) { var u = new FlatHexPoint(ux, 0); var v = new FlatHexPoint(vx, vy); int colorCount = u.PerpDot(v); float a = PerpDot(v) / (float)colorCount; float b = -PerpDot(u) / (float)colorCount; int m = Mathi.FloorToInt(a); int n = Mathi.FloorToInt(b); int baseVectorX = m * u.X + n * v.X; int baseVectorY = n * u.Y + n * v.Y; int offsetX = Mathi.Mod(X - baseVectorX, ux); int offsetY = Y - baseVectorY; int colorIndex = Mathi.FloorToInt(offsetX + offsetY * ux); return(colorIndex); }
/** * @version1_8 */ public InspectableVectorPoint(FlatHexPoint point) { x = point.X; y = point.Y; }
/** Rotates a shape 180 degrees around the edge shared by the two given points. The two points must be neighbors. */ public static IEnumerable<FlatHexPoint> Rotate180About( IEnumerable<FlatHexPoint> shape, FlatHexPoint p1, FlatHexPoint p2) { var translation = p1.Translate(p2); var correction = translation.Subtract(translation.Rotate180()).ScaleDown(2); return TransformShape<FlatHexPoint>(shape, point => point.Rotate180().Translate(correction)).ToList(); }
/** @version1_8 */ public InspectableVectorPoint(FlatHexPoint point) { x = point.X; y = point.Y; }
/** * This is a norm defined on the point, such that `p1.Difference(p2).Abs()` is equal to * `p1.DistanceFrom(p2)`. */ public FlatHexPoint Translate(FlatHexPoint translation) { return(new FlatHexPoint(x + translation.X, y + translation.Y)); }
/** * Subtracts the other point from this point, and returns the result. */ public FlatHexPoint Subtract(FlatHexPoint other) { return(new FlatHexPoint(x - other.X, y - other.Y)); }
/** * @since 1.7 */ public int PerpDot(FlatHexPoint other) { return(x * other.Y - y * other.x); }
/** * @since 1.7 */ public int Dot(FlatHexPoint other) { return(x * other.X + y * other.Y); }
public FlatHexPoint MoveBackBy(FlatHexPoint translation) { return(Translate(translation.Negate())); }
public FlatHexPoint MoveBy(FlatHexPoint translation) { return(Translate(translation)); }