// Moves the player to a hex, if the player has not moved yet. public void move(HexScript hex) { if (!hasMoved) { position = hex.getPosition (); transform.position = new Vector3 ( hex.transform.position.x, hex.transform.position.y, hex.transform.position.z - 10f); hasMoved = true; } }
// Sets the position of the unit to a hex. // NOTE: This works much better than the other set position method, // and should be used whenever possible. public void setPosition(HexScript hex) { position = hex.getPosition (); transform.position = new Vector3 ( hex.transform.position.x, hex.transform.position.y, -0.5f); }
// Finds the adjacent hexes to a hex and adds them to an iterable Set // The returns that set HashSet<HexScript> findAdj(HexScript hex) { if (!paused) { int x = (int)hex.getPosition ().x; int y = (int)hex.getPosition ().y; HashSet<HexScript> set = new HashSet<HexScript> (); // Note: The logic here is clunky and long, but it works and runs in O(1)! Hopefully // it won't need any changes. if (y % 2 == 0) { if (y - 2 >= 0) { set.Add (Map.map [x] [y - 2]); } if (y - 1 >= 0) { set.Add (Map.map [x] [y - 1]); } if (y + 1 < Map.map [x].Count) { set.Add (Map.map [x] [y + 1]); } if (y + 2 < Map.map [x].Count) { set.Add (Map.map [x] [y + 2]); } if (x - 1 >= 0) { if (y + 1 < Map.map [x].Count) { set.Add (Map.map [x - 1] [y + 1]); } if (y - 1 >= 0) { set.Add (Map.map [x - 1] [y - 1]); } } } if (y % 2 == 1) { if (y - 2 >= 0) { set.Add (Map.map [x] [y - 2]); } if (y - 1 >= 0) { set.Add (Map.map [x] [y - 1]); } if (y + 1 < Map.map [x].Count) { set.Add (Map.map [x] [y + 1]); } if (y + 2 < Map.map [x].Count) { set.Add (Map.map [x] [y + 2]); } if (x + 1 < Map.map.Count) { if (y + 1 < Map.map [x].Count) { set.Add (Map.map [x + 1] [y + 1]); } if (y - 1 >= 0) { set.Add (Map.map [x + 1] [y - 1]); } } } // Remove any hexes that cannot be landed on (water/mountains) /*foreach (HexScript hexes in set) { if(hexes.getOccupied()) set.Remove(hexes); }*/ return set; } else return null; }