private static Dictionary <Axial, Vector2> CreateNewField(Axial center) { return(new Dictionary <Axial, Vector2>() { { center, Vector2.zero }, }); }
public VectorField(Axial center, Dictionary <Axial, Vector2> field) { creationTime = Time.time; this.center = center; this.field = field; }
private static Dictionary <Axial, Node> CreateClosedCollection(Axial center) { return(new Dictionary <Axial, Node>() { { center, new Node(center, 0) } }); }
/// <summary> /// Will try to get the farthest position in <paramref name="direction"/> starting from <paramref name="start"/> /// </summary> /// <returns>World-Space Position</returns> public static Vector2 GetFarthestWalkablePositionInDirection(Vector2 startingPosition, Vector2 direction, float maxDistance) { Vector2 positionOffsetPerStep = ScaleToOrthographicVector(direction); Vector2 positionToCheck = startingPosition + positionOffsetPerStep; Vector2 farthestWalkablePosition = startingPosition; while (true) { if (OrthographicDistance(startingPosition, positionToCheck) > maxDistance) { break; } Axial nearestAxialPosition = WorldToAxialPosition(positionToCheck); if (IsAxialPositionWalkable(nearestAxialPosition)) { farthestWalkablePosition = positionToCheck; } positionToCheck += positionOffsetPerStep; } return(farthestWalkablePosition); }
protected override void DoRightClick(Axial position, RoomData room) { if (room.Prefabs.ContainsKey(position)) { room.Prefabs.Remove(position); } }
void cannonFacing(Axial currentAxis) { Axial axis = currentAxis; Quaternion actualRotation; actualRotation = transform.rotation; switch (axis) { case Axial.RIGHT: transform.rotation = Quaternion.Lerp(actualRotation, Quaternion.Euler(0, 0, (float)Axial.RIGHT), 10f * Time.deltaTime); break; case Axial.LEFT: transform.rotation = Quaternion.Lerp(actualRotation, Quaternion.Euler(0, 0, (float)Axial.LEFT), 10f * Time.deltaTime); break; case Axial.UP: transform.rotation = Quaternion.Lerp(actualRotation, Quaternion.Euler(0, 0, (float)Axial.UP), 10f * Time.deltaTime); break; case Axial.DOWN: transform.rotation = Quaternion.Lerp(actualRotation, Quaternion.Euler(0, 0, (float)Axial.DOWN), 10f * Time.deltaTime); break; } }
/// <summary> /// Enumerates over 6 adjacent axial positions to <paramref name="center"/> /// </summary> public static void AdjacentHexagons(Axial center, System.Action <Axial> callback) { for (int i = 0; i < 6; i++) { callback(center + AxialDirection.AllDirections[i]); } }
/// <inheritdoc/> public override void RunCombination(int combinationIndex, Combination combination, CalculationContext context) { Shear.Run(context); Moment.Run(context); Axial.Run(context); Deflection.Run(context); }
public Node(Axial position, float cost, float heuristic, Node parent) { Parent = parent; this.Position = position; this.Cost = cost; this.Heuristic = heuristic; }
public Node(Axial target, int steps) { Target = new NodePosition() { Position = target, Steps = steps, }; }
private static void HandleException(Axial current, Dictionary <Axial, Node> closed) { #if UNITY_EDITOR HandleExceptionInEditor(current, closed); #else Debug.LogError("Exception thrown when building vector field"); #endif }
public static Vector3 AxialToCube(Axial hex) { float x = hex.q; float z = hex.r; float y = -x - z; return(new Vector3(x, y, z)); }
public bool ShouldUpdate(Axial currentPosition) { if (Time.time - creationTime >= MaxBuildInterval) { return(center != currentPosition); } return(false); }
protected override void DoLeftClick(Axial position, RoomData room) { #if UNITY_EDITOR if (Selection.activeGameObject != null) { room.Prefabs.Overwrite(position, Selection.activeGameObject); } #endif }
public void AddPrefab(Axial position, GameObject prefab) { if (Prefabs.ContainsKey(position)) { Debug.LogError($"Attempted to overwrite prefab at position {position}"); } Prefabs.Add(position, prefab); }
private static bool FieldShouldBeRebuilt(GameObject target, Axial targetPosition) { if (!TargetHasField(target)) { throw new System.NullReferenceException($"{target} doesn't have a field!"); } return(fields[target].ShouldUpdate(targetPosition)); }
public void AddTile(Axial position, TileData tile) { if (Tiles.ContainsKey(position)) { Debug.LogError($"Attempted to overwrite tile at position {position}"); } Tiles.Add(position, tile); }
private Axial GetFromPan(Panel pan) { var res = new Axial(); var rw = pan.Name.Split('_'); int.TryParse(rw[1], out res.Q); int.TryParse(rw[2], out res.R); return(res); }
/// <summary> /// Can an entity walk at the given position? /// </summary> public static bool IsAxialPositionWalkable(Dictionary <Axial, TileData> tiles, Axial position) { if (tiles.ContainsKey(position)) { return(tiles[position].IsWalkable); } return(false); }
private static void DrawVector(Axial start, Vector2 end) { Vector2 startWorldPos = Utility.AxialToWorldPosition(start); Vector2 delta = end - startWorldPos; Vector2 direction = delta.normalized; float orthographicScale = Utility.ScaleToOrthographicVector(direction).magnitude; Debug.DrawRay(startWorldPos, direction * (DirectionLength * orthographicScale), Color.cyan, 5, false); }
/// <summary> /// Converts an axial position to world coordinates /// </summary> public static Vector2 AxialToWorldPosition(Axial axial) { Vector2 axialVector = axial; return(new Vector2() { x = (axialVector.x - axialVector.y * (Utility.HexelWidth / 2)) * OrthographicScale.x, y = (axialVector.y /= Utility.HexelHeightMultiplier) * OrthographicScale.y, }); }
public TileData this[Axial index] { get { return(Tiles[index]); } set { Tiles[index] = value; } }
private static void DrawNeighborsOfCurrentPosition(Axial current) { Vector2 currentWorldPos = Utility.AxialToWorldPosition(current); for (int i = 0; i < AxialDirection.AllDirections.Length; i++) { Vector2 end = currentWorldPos + Utility.AxialToWorldPosition(AxialDirection.AllDirections[i]); Debug.DrawLine(currentWorldPos, end, Color.red, 5); } }
public Vector2 GetNextPosition(Vector2 currentPosition) { Axial currentAxial = Utility.WorldToAxialPosition(currentPosition); Axial firstPathNodeAxial = Utility.WorldToAxialPosition(rawPath.First.Value); if (currentAxial == firstPathNodeAxial) { rawPath.RemoveFirst(); } return(rawPath.First.Value); }
private static void EnqueueNeighbors(Axial center, Dictionary <Axial, Node> closed, Queue <Axial> open) { for (int i = 0; i < AxialDirection.AllDirections.Length; i++) { Axial neighbor = center + AxialDirection.AllDirections[i]; if (IsValidPoint(neighbor) && !closed.ContainsKey(neighbor) && !open.Contains(neighbor)) { open.Enqueue(neighbor); } } }
private static void SpawnEnemiesAtPosition(Axial center, EntityCollection collection) { List <Axial> spawnablePositions = GetSpawnablePositions(center, collection.Count); foreach (Entity prefab in collection) { Axial position = spawnablePositions.Random(); spawnablePositions.Remove(position); Entity instance = Entity.Instantiate(prefab); instance.transform.position = Utility.AxialToWorldPosition(position); } }
/// <summary> /// Calculates a bitmask based on the surroundings of a tile /// </summary> /// <param name="center">The tile whose bitmask we're calculating. Hexagonal coordinate</param> /// <param name="allTiles">All tiles in hexagonal coordinates</param> /// <returns>The bitmask of <paramref name="center"/></returns> public static byte GetBitmask(Axial center, HashSet <Axial> allTiles) { byte bitmask = 0; foreach (AxialDirection direction in AxialDirection.AllDirections) { if (allTiles.Contains(center + direction)) { bitmask |= direction; } } return(bitmask); }
private bool IsPositionValidConnetionPoint(Axial point) { bool isValid = false; Utility.AdjacentHexagons(point, x => { if (!Tiles.ContainsKey(x)) { isValid = true; } }); return(isValid); }
private void PlaceOnLevel(LevelBuildData levelData, Axial offset) { Position = offset; foreach (var pair in Tiles) { levelData.AddTile(pair.Key + offset, pair.Value); } foreach (var pair in Prefabs) { levelData.AddPrefab(pair.Key + offset, pair.Value); } }
private static void ShouldSpawn(Axial position, LevelBuildData data, Theme theme) { int adjacentCount = 0; Utility.AdjacentHexagons(position, w => { if (data.Tiles.ContainsKey(w)) { adjacentCount++; } }); if (adjacentCount >= SpawnFloorCount) { data.Tiles.Add(position, theme.FloorTile); } }
public static Vector2 AxialToWorld(Axial axial, float pointRadius, OffsetType type) { float x; float y; if (type == OffsetType.EvenR || type == OffsetType.OddR) { x = pointRadius * Mathf.Sqrt( 3 ) * (axial.q + axial.r / 2); y = pointRadius * 3 / 2 * axial.r; } else { x = pointRadius * 3 / 2 * axial.q; y = pointRadius * Mathf.Sqrt( 3 ) * (axial.r + axial.q / 2); } return new Vector2( x, y ); }