public List <Hex> GetEdgeHexes(HexMap map) { List <Hex> edges = new List <Hex>(); if (hexes == null || hexes.Count() < 1) { return(null); } foreach (Hex h in hexes) { foreach (Hex n in h.GetNieghbors(map)) { if (hexes.Contains <Hex>(n)) { continue; } else { edges.Add(h); } } } return(edges); }
protected void MakeHexMap() { switch (mapShape) { case MapShape.Rectangle: HexMap = new HexMap <TileData, EdgeData>(HexMapBuilder.CreateRectangularShapedMap(rectDimensions)); break; case MapShape.Hexagon: HexMap = new HexMap <TileData, EdgeData>(HexMapBuilder.CreateHexagonalShapedMap(hexRadius)); break; default: throw new ArgumentOutOfRangeException(); } TileObjects = new GameObject[HexMap.TilesByPosition.Count]; foreach (Tile <TileData> tile in HexMap.Tiles) { InstantiateNewTerrainTile(grassTilePrefab, tile); } }
// Use this for initialization void Start() { gameController = FindObjectOfType <GameController>(); hexMap = gameController.FindPlayerMap(transform.position); hexPosition = GetComponentInChildren <HexPosition>(); hexPosition.Init(hexMap); }
public List <Hex> getNeighbors(HexMap map) { List <Hex> ns = new List <Hex>(); List <Hex> edgeHexes = GetEdgeHexes(map); if (edgeHexes == null) { return(null); } foreach (Hex e in edgeHexes) { foreach (Hex n in e.GetNieghbors(map)) { if (hexes.Contains(n) || !map.GetHexesInRadius(Hex, 4).Contains(n)) { continue; } else { ns.Add(n); } } } return(ns); }
public Hex(int q, int r, HexMap hexMap) // constructor { this.Q = q; this.R = r; this.S = -(q + r); this.HexMap = hexMap; }
private void createMap() { map = new HexMap(UnityEngine.Random.Range(minSize, maxSize), UnityEngine.Random.Range(minSize, maxSize)); for (int column = 0; column < HexMap.NumColumns; column++) { for (int row = 0; row < HexMap.NumRows; row++) { // Instantiate a Hex HexContinent h = new HexContinent(column, row); Vector3 pos = h.hex.PositionFromCamera( Camera.main.transform.position, HexMap.NumRows, HexMap.NumColumns ); GameObject hexGO = (GameObject)Instantiate( HexPrefab, pos, Quaternion.identity, mapHolder.transform ); HexComponent hexC = hexGO.GetComponent <HexComponent>(); hexC.Hex = h; //hexC.Hex.hex.HexMap = map; map.AddHex(hexC.Hex); // MeshRenderer mr = hexGO.GetComponentInChildren<MeshRenderer>(); // mr.material = HexMaterials[Random.Range(0, HexMaterials.Length)]; } } JsonManager <HexMap> .saveJson(map); }
public Hex[] GetNeighbours()//GetAdjacentHexes() { if (this.neighbours == null) { List <Hex> neighbours = new List <Hex>(); neighbours.Add(HexMap.GetHex(Q + 1, R)); neighbours.Add(HexMap.GetHex(Q - 1, R)); neighbours.Add(HexMap.GetHex(Q, R + 1)); neighbours.Add(HexMap.GetHex(Q, R - 1)); neighbours.Add(HexMap.GetHex(Q + 1, R - 1)); neighbours.Add(HexMap.GetHex(Q - 1, R + 1)); List <Hex> realNeighbours = new List <Hex>(); foreach (Hex hex in neighbours) { if (hex != null) { realNeighbours.Add(hex); } } this.neighbours = realNeighbours.ToArray(); } return(this.neighbours); }
private ISector CreateSector() { var _actorManager = Container.Resolve <IActorManager>(); var _propContainerManager = Container.Resolve <IPropContainerManager>(); var sectorGenerator = Container.Resolve <SectorProceduralGenerator>(); var dropResolver = Container.Resolve <IDropResolver>(); var schemeService = Container.Resolve <ISchemeService>(); var map = new HexMap(); var sector = new Sector(map, _actorManager, _propContainerManager, dropResolver, schemeService); try { sectorGenerator.Generate(sector, map); } catch { Debug.Log(sectorGenerator.Log.ToString()); throw; } Debug.Log(sectorGenerator.Log.ToString()); return(sector); }
public void PathfindDistanceAll() { foreach (var source in AllPaths.AllCoords) { AllPaths[source] = new HexMap <Path>(Game.Size); PathfindDistanceOnlyFrom(AllPaths[source], source); } _precomputedPaths.Clear(); foreach (var source in AllPaths.AllCoords) { foreach (var destination in AllPaths.AllCoords) { var key = CoordPair.Build(source, destination); if (_precomputedPaths.ContainsKey(key)) { continue; } var path = PathFromSourceToTarget(source, destination); _precomputedPaths.Add(key, path); } } }
// Start is called before the first frame update void Start() { GameObject.FindObjectOfType <HexMap>().onCityCreated += CreateCityNamePlate; actionController = GameObject.FindObjectOfType <ActionController>(); uiController = GameObject.FindObjectOfType <UIController>(); hexMap = GameObject.FindObjectOfType <HexMap>(); }
public Hex(HexMap hexMap, int q, int r) { this.hexMap = hexMap; this.Q = q; this.R = r; this.S = -(q + r); }
/// <summary> /// Executes behavior with given context /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public override BehaviorReturnCode Behave(IBehaviorContext context) { UnitBehaviorContext unitContext = context as UnitBehaviorContext; if (unitContext == null) { returnCode = BehaviorReturnCode.Failure; return(returnCode); } if (unitContext.EnvironmentTarget == null) { returnCode = BehaviorReturnCode.Failure; return(returnCode); } StaticUnit unit = unitContext.Unit as StaticUnit; if (unit == null) { returnCode = BehaviorReturnCode.Failure; return(returnCode); } int planetDistance = HexMap.Distance(unitContext.EnvironmentTarget, unitContext.Unit); if (planetDistance > unit.SensorsEnergy) { returnCode = BehaviorReturnCode.Failure; return(returnCode); } returnCode = BehaviorReturnCode.Success; return(returnCode); }
public static void LogMap(HexMap map, List <Position> lines, List <Point> points) { var sites = points.Select(p => new Position(p.XInt, p.YInt)).ToList(); for (var y = 0; y < map.Height; y++) { var row = ""; for (var x = 0; x < map.Width; x++) { var tile = map.GetTile(x, y); var output = "x"; if (lines.Contains(tile.Position)) { output = "l"; } if (sites.Contains(tile.Position)) { output = "s"; } if (y % 2 != 0 && x == 0) { row += " "; } row += $"{output} "; } Debug.Log(row); } }
public override void OnInspectorGUI() { DrawDefaultInspector(); EditorGUILayout.Separator(); HexMap map = (HexMap)target; type = (MapType)EditorGUILayout.EnumPopup("Map grid type:", type); switch (type) { case MapType.Disc: map.Width = EditorGUILayout.IntSlider(new GUIContent("Radius:"), map.Width, 0, 16); break; case MapType.Ring: map.Width = EditorGUILayout.IntSlider(new GUIContent("Radius:"), map.Width, 0, 16); map.RingMin = EditorGUILayout.IntSlider(new GUIContent("Hole Radius:"), map.RingMin, 0, 16); break; } if (GUILayout.Button("Generate")) { map.GenerateMap(type); } }
void Awake() { if (instance == null) { instance = this; } }
// Use this for initialization void Start() { oldPosition = this.transform.position; hexMap = GameObject.FindObjectOfType <HexMap>(); updateMapPositions(); UpdateWaterPosition(); }
// Start is called before the first frame update void Start() { update_CurrentFunc = UpdateDetectModeStart; hexMap = GameObject.FindObjectOfType <HexMap>(); uiController = FindObjectOfType <UIController>(); actionController = FindObjectOfType <ActionController>(); }
private GameObject[] tileObjects; // this will contain all the GameObjects for visualisation purposes, their array index corresponds with the index of our Tiles void Start() { hexMap = new HexMap <int, bool>(HexMapBuilder.CreateRectangularShapedMap(mapSize), null); //creates a HexMap using one of the pre-defined shapes in the static MapBuilder Class hexMouse = gameObject.AddComponent <HexMouse>(); //we attach the HexMouse script to the same gameObject this script is attached to, could also attach it anywhere else hexMouse.Init(hexMap); //initializes the HexMouse tileObjects = new GameObject[hexMap.TilesByPosition.Count]; //creates an array with the size equal to the number on tiles of the map foreach (var tile in hexMap.Tiles) //loops through all the tiles, assigns them a random value and instantiates and positions a gameObject for each of them. { tile.Data = (Random.Range(0, 4)); GameObject instance = GameObject.Instantiate(tilePrefab); instance.GetComponent <Renderer>().material = materials[tile.Data]; instance.name = "MapTile_" + tile.Position; instance.transform.position = tile.CartesianPosition; tileObjects[tile.Index] = instance; } foreach (var edge in hexMap.Edges) //we randomly spawn a GameObject on some corners (could be representing walls or rivers or anything else) { int randomNumber = Random.Range(0, 100); if (randomNumber > 89) { edge.Data = true; GameObject instance = GameObject.Instantiate(edgePrefab); instance.name = "MapEdge_" + edge.Position; instance.transform.position = edge.CartesianPosition; instance.transform.rotation = Quaternion.Euler(0, edge.EdgeAlignmentAngle, 0); //as we don't change the edges during runtime we don't need to add the gameObjects of the edges to an array as we don't need to manipulate them later on } } SetupCamera(); //set camera settings so that the map is captured by it }
/// <summary> /// Create a HexMap of type SolidColorBrush and set the value to a different colored /// brush for each ring in the map /// </summary> /// <param name="orientation">Flat or pointy topped</param> /// <param name="ringCount">Number of rings around the center hex</param> private static HexMap <SolidColorBrush> CreateHexMapWithRingColors(HexOrientation orientation, int ringCount) { // Set up some colors for hex fills var ringColors = new[] { new SolidColorBrush(Colors.Red), new SolidColorBrush(Colors.Yellow), new SolidColorBrush(Colors.Blue), new SolidColorBrush(Colors.Orange), new SolidColorBrush(Colors.Green) }; var hexGrid = new HexMap <SolidColorBrush>(orientation, ringCount, 45); // Set the value of each item to a solid color brush which varies per ring for (int i = 0; i <= Math.Min(ringCount, ringColors.Length - 1); i++) { foreach (var hex in hexGrid.Ring(i)) { hex.Value = ringColors[i]; } } return(hexGrid); }
public void CtorSizeFactor0YieldsCorrectCoordinates() { var sut = new HexMap<object>(HexOrientation.FlatTopped, 0); // Center hex Assert.IsNotNull(sut.Item(0,0,0)); }
public void ShouldGetAndSetIndexer() { HexMap <HexCoordinate> map; HexCoordinate coordinate; map = new HexMap <HexCoordinate>(5); for (int r = 0; r <= 5; r++) { for (int i = 0; i < HexMap.GetCount(r); i++) { coordinate = new HexCoordinate(r, i); map[coordinate] = coordinate; } } for (int r = 0; r <= 5; r++) { for (int i = 0; i < HexMap.GetCount(r); i++) { coordinate = new HexCoordinate(r, i); Assert.AreEqual(coordinate, map[coordinate]); Assert.AreEqual(coordinate, map[coordinate.Index]); } } }
private void Update() { if (Input.GetMouseButtonUp(1)) { HexMap.AwaitFillIn(0); /*Color colour = fingerImage.color; * colour.a = fingerAlphaWhileHovering; * fingerImage.color = colour;*/ fingerWhileHovering.SetActive(true); fingerWhileTouching.SetActive(false); } else if (Input.GetMouseButtonDown(1)) { /* Color colour = fingerImage.color; * colour.a = fingerAlphaWhileTouching; * fingerImage.color = colour;*/ fingerWhileHovering.SetActive(false); fingerWhileTouching.SetActive(true); } Vector3 currentMouseGroundPosition = MouseToGroundPlane(Input.mousePosition); Vector3 fingerPosition = camera.WorldToScreenPoint(currentMouseGroundPosition); fingerTransform.position = fingerPosition; }
public void TestSubscriptOperator() { var m = new HexMap <int>(5); m[3, 4] = 6; Assert.AreEqual(6, m[new AxialCoord(3, 4)]); }
// Start is called before the first frame update void Start() { hexMap = GameObject.FindObjectOfType <HexMap>(); unitInfoPanelBehavior = GameObject.Find("Canvas_GameUI").GetComponentInChildren <UnitInfoPanelBehavior>(); unitInfoPanel = unitInfoPanelBehavior.gameObject; cityInfoPanelBehavior = GameObject.Find("Canvas_GameUI").GetComponentInChildren <CityInfoPanelBehavior>(); cityInfoPanel = cityInfoPanelBehavior.gameObject; zoneInfoPanelBehavior = GameObject.Find("Canvas_GameUI").GetComponentInChildren <ZoneInfoPanelBehavior>(); zoneInfoPanel = zoneInfoPanelBehavior.gameObject; actionController = FindObjectOfType <ActionController>(); mouseController = FindObjectOfType <MouseController>(); Button[] allButtons = GameObject.FindObjectsOfType <Button>(); nextButton = FindButtonByName("NextTurnButton", allButtons); buildCityButton = FindButtonByName("BuildCityButton", allButtons); borderLineRenderers = new Dictionary <City, LineRenderer>(); cityNamePlates = new Dictionary <City, MapObjectNamePlate>(); zoneNamePlates = new Dictionary <Zone, MapObjectNamePlate>(); hexMap.onCityCreated += UpdateCityBorders; nextButton.onClick.AddListener(actionController.NextTurn); buildCityButton.onClick.AddListener(actionController.BuildCity); UpdateSelection(null, null, null); //disable info panel by default }
public void CtorSizeFactor2YieldsCorrectCoordinates() { var sut = new HexMap<object>(HexOrientation.FlatTopped, 2); // Center hex Assert.IsNotNull(sut.Item(0, 0, 0)); // First ring Assert.IsNotNull(sut.Item(1, 0, -1)); Assert.IsNotNull(sut.Item(1, -1, 0)); Assert.IsNotNull(sut.Item(0, -1, 1)); Assert.IsNotNull(sut.Item(-1, 0, 1)); Assert.IsNotNull(sut.Item(-1, 1, 0)); Assert.IsNotNull(sut.Item(0, 1, -1)); // Second ring Assert.IsNotNull(sut.Item(2, 0, -2)); Assert.IsNotNull(sut.Item(1, 1, -2)); Assert.IsNotNull(sut.Item(0, 2, -2)); Assert.IsNotNull(sut.Item(-1, 2, -1)); Assert.IsNotNull(sut.Item(-2, 2, 0)); Assert.IsNotNull(sut.Item(-2, 1, 1)); Assert.IsNotNull(sut.Item(-2, 0, 2)); Assert.IsNotNull(sut.Item(-1, -1, 2)); Assert.IsNotNull(sut.Item(0, -2, 2)); Assert.IsNotNull(sut.Item(1, -2, 1)); Assert.IsNotNull(sut.Item(2, -2, 0)); Assert.IsNotNull(sut.Item(2, -1, -1)); }
public override void Perform(object obj) { HexMap hexmap = GetHexmap(obj); if (hexmap == null) { return; } // Find or create a camera view in tilemap editing mode CamViewPlugin camViewPlugin = DualityEditorApp.GetPlugin <CamViewPlugin>(); if (camViewPlugin == null) { return; } CamView camView = camViewPlugin.CreateOrSwitchCamView(typeof(HexMapCamViewState)); if (camViewPlugin == null) { return; } DualityEditorApp.Select(this, new ObjectSelection(hexmap)); DualityEditorApp.Highlight(this, new ObjectSelection(hexmap), HighlightMode.Spatial); }
private HexMap GetMap() { var mapIndex = SessionSettings.Instance.SelectedMapIndex; HexMap map = Stuff.Maps[mapIndex]; return(map); }
public Hex(HexMap hexMap, int q, int r) { this.HexMap = hexMap; Q = q; R = r; S = -(q + r); }
virtual public void Generate() { Random.InitState(seed); for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { HexCoordinates hexCoords = HexCoordinates.FromTilemapCoordinates(row, col); Vector3Int tilemapCoords = new Vector3Int(row, col, 0); TileBase tileToSet = biomeDefault.water; HexTile hex = new HexTile(hexCoords, tilemapCoords, tileToSet); HexMap.SetHex(hex); } } for (int i = 0; i < biome.Length; i++) { Biome currentBiome = biome[i]; for (int biomeCount = 0; biomeCount < currentBiome.count; biomeCount++) { HexTile biomeCenter = HexMap.GetHex(new Vector3Int(Random.Range(0, width), Random.Range(0, height), 0)); HexMap.PlaceBiome(biomeCenter, Random.Range(currentBiome.minRange, currentBiome.maxRange), i); } } }
public void SettingValuesWorks() { var sut = new HexMap <string>(HexOrientation.FlatTopped, 2); foreach (var item in sut.Ring(2)) { item.Value = "red"; } foreach (var item in sut.Ring(1)) { item.Value = "yellow"; } foreach (var item in sut.Ring(0)) { item.Value = "blue"; } Assert.AreEqual(0, sut.Ring(2).Count(i => i.Value != "red")); Assert.AreEqual(12, sut.Ring(2).Count(i => i.Value == "red")); Assert.AreEqual(0, sut.Ring(1).Count(i => i.Value != "yellow")); Assert.AreEqual(6, sut.Ring(1).Count(i => i.Value == "yellow")); Assert.AreEqual(0, sut.Ring(0).Count(i => i.Value != "blue")); Assert.AreEqual(1, sut.Ring(0).Count(i => i.Value == "blue")); }
public void GettingItemThatDoesNotExistReturnsNull() { // Create 1-ring map var sut = new HexMap<object>(HexOrientation.FlatTopped, 1); // Try to get an item from the 2nd ring Assert.IsNull(sut.Item(2, 0, -2)); }
public void GetItemByCubeCoordinatesReturnsCorrectResults() { var sut = new HexMap<object>(HexOrientation.FlatTopped, 1); // First ring Assert.IsNotNull(sut.Item(1, 0, -1)); Assert.IsNotNull(sut.Item(1, -1, 0)); Assert.IsNotNull(sut.Item(0, -1, 1)); Assert.IsNotNull(sut.Item(-1, 0, 1)); Assert.IsNotNull(sut.Item(-1, 1, 0)); Assert.IsNotNull(sut.Item(0, 1, -1)); }
public void GetRing1ReturnsCorrectResults() { var sut = new HexMap<object>(HexOrientation.FlatTopped, 1); var result = sut.Ring(1); // First ring Assert.AreEqual(6, result.Count); Assert.IsNotNull(result.First(i => i.X == 1 && i.Y == 0 && i.Z == -1)); Assert.IsNotNull(result.First(i => i.X == 1 && i.Y == -1 && i.Z == 0)); Assert.IsNotNull(result.First(i => i.X == 0 && i.Y == -1 && i.Z == 1)); Assert.IsNotNull(result.First(i => i.X == -1 && i.Y == 0 && i.Z == 1)); Assert.IsNotNull(result.First(i => i.X == -1 && i.Y == 1 && i.Z == 0)); Assert.IsNotNull(result.First(i => i.X == 0 && i.Y == 1 && i.Z == -1)); }
public void CreateMap() { instance = this; Clear (); nodes = new HexNode[height * width]; for (int z = 0, i = 0; z < height; z++) { for (int x = 0; x < width; x++) { CreateNode(x, z, i++); } } hexMesh.Triangulate(nodes); }
public void Init(Vector3 position, Vector3 index) { this.position = position; map = HexMap.instance; corners = new Vector3[]{ new Vector3(0f, 0f, map.outerRadius), new Vector3(map.InnerRadius, 0f, 0.5f * map.outerRadius), new Vector3(map.InnerRadius, 0f, -0.5f * map.outerRadius), new Vector3(0f, 0f, -map.outerRadius), new Vector3(-map.InnerRadius, 0f, -0.5f * map.outerRadius), new Vector3(-map.InnerRadius, 0f, 0.5f * map.outerRadius), new Vector3(0f, 0f, map.outerRadius), }; this.index = index; CreateView (); }
/* Note: This just runs over positions, so at the edge it will include outside * positions. */ public static IEnumerable<DrawInfo> drawer(HexMap map) { double rx = Screen.width / 2; double ry = Screen.height / 2; int x1, y1; double left = -rx;// + 100; double top = ry;// - 100; double right = rx - 128; // -100; double bottom = -ry;// + 100; map.get_hex_position (new Position ( (xy.x + left) / 54, (xy.y + top) / -36), out x1, out y1); var s1 = getpos (map, x1, y1); if (s1.y - top < 0) { y1--; s1.x += 54; s1.y += 36; } for (; ;) { var x = x1; var y = y1; var s = s1; for (; ;) { if (s.y + 36 < bottom) yield break; if (s.x - 36 > right) break; yield return new DrawInfo (s, x, y); x++; y--; s.x += 108; } var flip = s1.x - left > 18; if (flip) { y1++; s1.x -= 54; s1.y -= 36; } else { x1++; s1.x += 54; s1.y -= 36; } } }
private void AnnotateFaces(HexMap<SolidColorBrush> hexGrid) { foreach (var hex in hexGrid.Map) { for (int i = 0; i <= 5; i++) { var faceLine = hex.Faces(i); faceLine.StrokeThickness = 3; var direction = hex.FaceDirections[i]; switch (direction) { case HexDirection.E: faceLine.Stroke = new SolidColorBrush(Colors.BlueViolet); break; case HexDirection.N: faceLine.Stroke = new SolidColorBrush(Colors.DarkBlue); break; case HexDirection.NE: faceLine.Stroke = new SolidColorBrush(Colors.Aqua); break; case HexDirection.NW: faceLine.Stroke = new SolidColorBrush(Colors.BurlyWood); break; case HexDirection.S: faceLine.Stroke = new SolidColorBrush(Colors.Chartreuse); break; case HexDirection.SE: faceLine.Stroke = new SolidColorBrush(Colors.MediumVioletRed); break; case HexDirection.SW: faceLine.Stroke = new SolidColorBrush(Colors.DeepPink); break; case HexDirection.W: faceLine.Stroke = new SolidColorBrush(Colors.Gray); break; } CenterCanvas.Children.Add(faceLine); } } }
/// <summary> /// Create a HexMap of type SolidColorBrush and set the value to a different colored /// brush for each ring in the map /// </summary> /// <param name="orientation">Flat or pointy topped</param> /// <param name="ringCount">Number of rings around the center hex</param> private static HexMap<SolidColorBrush> CreateHexMapWithRingColors(HexOrientation orientation, int ringCount) { // Set up some colors for hex fills var ringColors = new[] { new SolidColorBrush(Colors.Red), new SolidColorBrush(Colors.Yellow), new SolidColorBrush(Colors.Blue), new SolidColorBrush(Colors.Orange), new SolidColorBrush(Colors.Green) }; var hexGrid = new HexMap<SolidColorBrush>(orientation, ringCount, 45); // Set the value of each item to a solid color brush which varies per ring for (int i = 0; i <= Math.Min(ringCount, ringColors.Length - 1); i++) foreach (var hex in hexGrid.Ring(i)) hex.Value = ringColors[i]; return hexGrid; }
void Start () { Debug.Log("MapManager: start"); //setup even-q lookup vector lists neighborEvenVectors.Add(new Vector2(1, -1)); neighborEvenVectors.Add(new Vector2(1, 0)); neighborEvenVectors.Add(new Vector2(0, 1)); neighborEvenVectors.Add(new Vector2(-1, 0)); neighborEvenVectors.Add(new Vector2(-1, -1)); neighborEvenVectors.Add(new Vector2(0, -1)); neighborOddVectors.Add(new Vector2(1, 0)); neighborOddVectors.Add(new Vector2(1, 1)); neighborOddVectors.Add(new Vector2(0, 1)); neighborOddVectors.Add(new Vector2(-1, 1)); neighborOddVectors.Add(new Vector2(-1, 0)); neighborOddVectors.Add(new Vector2(0, -1)); hexMap = new HexMap(); mapSpawner = new HexMapSpawner(); FileManager.CacheMapData(); }
public CompleteMap() { theIslandMap = new IslandMap(); theHexMap = new HexMap(); linkMapsForResources(); }
void Awake() { hex_map = this; }
/* Get the pixel position of the center of the tile at diamond grid * x/y. The hexagon center is the diamond origin. * */ public static Position getpos(HexMap map, int x, int y) { var s = map.tile_to_screen (new Position (x, y)); s.x *= 54; s.x -= xy.x; s.y *= -36; s.y -= xy.y; return s; }
public void SetupSut() { _hexMapFlat = new HexMap<object>(HexOrientation.FlatTopped, 2); _hexMapPointy = new HexMap<object>(HexOrientation.PointyTopped, 2); }
private void Awake() { instance = this; }
public static void render_map(WorldMap world) { map = world.dungeon [world.z]; if (visibility == null) { visibility = new Visibility (); } visibility.update (world, xy); if (Debugging.draw_tiles) draw_tiled_tiles (); if (Debugging.draw_tiles || Debugging.draw_transitions) draw_tiles (); if (Debugging.draw_vertex_transitions) draw_vertex_transitions (); draw_objects (); if (Debugging.draw_darkness) { // draw visibility darkness if (darkness == null) { darkness = Resources.Load<Material> ("Darkness"); } darkness.SetPass (0); Graphics.DrawMeshNow (visibility.mesh, new Vector3 ((float)-xy.x, (float)-xy.y, 0), Quaternion.identity); } draw_cursor (world); }
public void TestHexMapInitializesProperly() { var target = new HexMap(); Assert.NotNull(target); }
public HexMap CreateHexMap(int mapSize, float hexRadius) { int differentTyleTypes = (int)GameTile.TileType.COUNT - 1; for (int i = 0; i < differentTyleTypes; i++) { _curTileAmmount[i] = 0; } if (_emptyTileList.Count > 0) _emptyTileList.Clear(); HexMap gameMap = new HexMap(); List<Vector2> hiddenTiles = new List<Vector2>(); float heigth = hexRadius * 2f; float width = Mathf.Sqrt(3f) / 2f * heigth; Vector3 startOffset = new Vector3(-(mapSize * width) / 4f + width / 4f, 0, (mapSize * heigth * 3 / 4) / 2f - (heigth * 3 / 4) / 2); int count = 0; int curXoffset = 1; int curIndex = 0; int counter = 0; int Q = 0, R = 0; for (int r = 0; r < mapSize; r++) { var newRow = new List<GameObject>(); for (int q = 0; q < mapSize / 2 + curXoffset; q++) { Vector3 SpawnPos = startOffset + new Vector3((width * q - (curXoffset - 1) * width / 2), 0, -heigth * 3 / 4 * r); var tile = Instantiate(HexTile, SpawnPos, Quaternion.identity) as GameObject; tile.GetComponent<GameTile>().BorderColor = BorderColors[(int)GameTile.TileType.EMPTY]; tile.GetComponent<GameTile>().IsEmpty = true; int indexX; if (r <= mapSize / 2) indexX = q - r; else { indexX = q - r + counter; } int indexY = r - mapSize / 2; tile.name = string.Format("X: {0} Y: {1}", indexX, indexY); tile.transform.parent = transform; tile.GetComponent<GameTile>().Q = indexX; tile.GetComponent<GameTile>().R = indexY; if (indexX == 0 && indexY == 0) { } else { _emptyTileList.Add(new Vector2(q, r)); hiddenTiles.Add(new Vector2(indexX, indexY)); } newRow.Add(tile); ++count; ++Q; tile.transform.parent = transform; } if (r < mapSize / 2) ++curXoffset; else --curXoffset; gameMap.AddRow(newRow); ++R; if (R > mapSize / 2) ++counter; curIndex--; } int ammountOfTiles = _emptyTileList.Count; int[] maxTileAmmount = MaxTileAmmountEasy; switch (DifficultyStateObject.CurDifficultyState) { case DifficultyStateObject.DifficultyState.Easy: maxTileAmmount = MaxTileAmmountEasy; break; case DifficultyStateObject.DifficultyState.Medium: maxTileAmmount = MaxTileAmmountMedium; break; case DifficultyStateObject.DifficultyState.Hard: maxTileAmmount = MaxTileAmmountHard; break; } for (int i = 0; i < maxTileAmmount.Length; ++i) { maxTileAmmount[i] += Random.Range(0, VariableRandOffset); } if (SceneManager.GetActiveScene().name == "HexMap") { TutorialManager.Instance.HiddenTileList = new List<Vector2>(hiddenTiles); } for (int i = 0; i < differentTyleTypes; i++) { while (_curTileAmmount[i] < ammountOfTiles / 100f * maxTileAmmount[i]) { int randIndex = Random.Range(0, _emptyTileList.Count); Vector2 tileIndex = _emptyTileList[randIndex]; if (gameMap.GetRow((int)tileIndex.y)[(int)tileIndex.x].GetComponentInChildren<GameTile>().IsEmpty) { gameMap.GetRow((int)tileIndex.y)[(int)tileIndex.x].GetComponent<GameTile>().HiddenObject = HiddenObjectList[i][Random.Range(0, HiddenObjectList[i].Count)]; gameMap.GetRow((int)tileIndex.y)[(int)tileIndex.x].GetComponent<GameTile>().IsEmpty = false; gameMap.GetRow((int)tileIndex.y)[(int)tileIndex.x].GetComponent<GameTile>().ThisType = (GameTile.TileType)i + 1; gameMap.GetRow((int)tileIndex.y)[(int)tileIndex.x].GetComponent<GameTile>().BorderColor = BorderColors[i + 1]; if (i == (int)GameTile.TileType.BAD - 1) ++TutorialManager.Instance.MaxKrakenAmmount; if (i == (int)GameTile.TileType.TREASURE - 1) ++TutorialManager.Instance.MaxTreasureAmmount; _emptyTileList.RemoveAt(randIndex); _curTileAmmount[i]++; } } } return gameMap; }
public void TestHexMapIsCorrectSize() { var target = new HexMap(); Assert.AreEqual(25, target.map.Length); }
public void SettingValuesWorks() { var sut = new HexMap<string>(HexOrientation.FlatTopped, 2); foreach (var item in sut.Ring(2)) { item.Value = "red"; } foreach (var item in sut.Ring(1)) { item.Value = "yellow"; } foreach (var item in sut.Ring(0)) { item.Value = "blue"; } Assert.AreEqual(0, sut.Ring(2).Count(i => i.Value != "red")); Assert.AreEqual(12, sut.Ring(2).Count(i => i.Value == "red")); Assert.AreEqual(0, sut.Ring(1).Count(i => i.Value != "yellow")); Assert.AreEqual(6, sut.Ring(1).Count(i => i.Value == "yellow")); Assert.AreEqual(0, sut.Ring(0).Count(i => i.Value != "blue")); Assert.AreEqual(1, sut.Ring(0).Count(i => i.Value == "blue")); }
public void ClearMapTiles() { mapSpawner.ClearMapRoot(); selectedTile = null; hexMap = new HexMap(); loadedMapFileIndex = -1; _hexTileLookup = new Dictionary<string, int>(); }
/// <summary> /// Draw the provided hex map on the form's canvas /// </summary> private void DrawHexGrid(HexMap<SolidColorBrush> hexGrid) { const double strokeThickness = 1; foreach (var hex in hexGrid.Map) { var hexPath = new Path { Data = hex.PathGeometry(), Fill = hex.Value, Stroke = new SolidColorBrush(Colors.Black), StrokeThickness = strokeThickness }; hexPath.SetValue(Canvas.LeftProperty, hex.X - (hexPath.Width / 2)); hexPath.SetValue(Canvas.TopProperty, hex.Y - (hexPath.Height / 2)); CenterCanvas.Children.Add(hexPath); } }
public void CtorSizeFactor2Yields19Items() { var sut = new HexMap<object>(HexOrientation.FlatTopped, 2); Assert.AreEqual(19, sut.Map.Count); }
/// <summary> /// Draw textblock annotations near each verticie indicating its direction from center /// </summary> private void AnnotateVerticies(HexMap<SolidColorBrush> hexGrid) { foreach (var hex in hexGrid.Map) { for (int i = 0; i <= 5; i++ ) { var vertex = hex.Verticies(i); var direction = hex.VerticeDirections[i]; var textBlock = new TextBlock {Text = direction.ToString()}; // Force some calculations of how big the textblock wants // to be given the string that was placed in it textBlock.Measure(new Size(double.PositiveInfinity,double.PositiveInfinity)); var width = textBlock.DesiredSize.Width; var height = textBlock.DesiredSize.Height; switch (direction) { case HexDirection.W: textBlock.SetValue(Canvas.LeftProperty, vertex.X + 5); break; case HexDirection.SW: case HexDirection.NW: if (hex.Orientation == HexOrientation.FlatTopped) textBlock.SetValue(Canvas.LeftProperty, vertex.X); else textBlock.SetValue(Canvas.LeftProperty, vertex.X + 5); break; case HexDirection.E: textBlock.SetValue(Canvas.LeftProperty, vertex.X - width - 5); break; case HexDirection.SE: case HexDirection.NE: if (hex.Orientation == HexOrientation.FlatTopped) textBlock.SetValue(Canvas.LeftProperty, vertex.X - width ); else textBlock.SetValue(Canvas.LeftProperty, vertex.X - width - 5); break; case HexDirection.N: case HexDirection.S: textBlock.SetValue(Canvas.LeftProperty, vertex.X - width / 2); break; } switch (direction) { case HexDirection.SE: case HexDirection.SW: case HexDirection.S: textBlock.SetValue(Canvas.TopProperty, vertex.Y - height); break; case HexDirection.E: case HexDirection.W: textBlock.SetValue(Canvas.TopProperty, vertex.Y - height / 2); break; case HexDirection.NE: case HexDirection.NW: case HexDirection.N: textBlock.SetValue(Canvas.TopProperty, vertex.Y); break; } CenterCanvas.Children.Add(textBlock); } } }
public async Task<int> CreateNewHexMap(int gameId, string name, int width, int height) { // authenticate for game id // check that the user hasn't exceeded the allowed number of maps for subscription type // validate name/width/height var map = new HexMap() { Name = name, Width = width, Height = height }; db.HexMaps.Add(map); await db.SaveChangesAsync(); return map.Id; }