private void GenerateMap() { hexagons = new Hexagon[width + 1, height + 1]; float[,] perlinNoiseMap = PerlinNoise.GeneratePerlinNoiseMap(width, height, 4f, 4); for (int col = 0; col < width; col++) { for (int row = 0; row < height; row++) { float latitude = perlinNoiseMap[col, row]; Hexagon h = new Hexagon(col, row); hexagons[col, row] = h; GameObject HexagonGameObject = Instantiate(hexagonPrefab, h.GetPosition(), Quaternion.identity, this.transform); MeshRenderer meshRenderer = HexagonGameObject.GetComponentInChildren <MeshRenderer>(); for (int i = 0; i < materialHeightRanges.Length; i++) { if (latitude <= materialHeightRanges[i]) { meshRenderer.material = hexagonMaterials[i]; break; } } } } }
private new void Awake() { SetState(States.MenuState); bombs = new List <Hexagon>(); hexagons = new Hexagon[gridWidth, gridHeight]; DrawLogicalGrid(); }
public Grid(Setup_Render setup, Config_Map config, TerrainType[,] types) { gridUtils.InjectDependencies(this, setup.Mat_Terrain, setup.Mat_Border); _mapConfig = config; // GRID AND TILE INFORMATION Size = config.GridSize; TileHeight = config.TileSize; TileThickness = config.TileThickness; // for grid mesh Hexagons = new Hexagon[Size, Size]; _terrainResource = new TerrainResource(setup); if (types == null) { _terrainTypes = MapGeneration.GenerateTerrainTypes(config); } else { _terrainTypes = types; } // Init Hexagons with Border InitHexagons(); InitVertexData(); }
void Start() { hexes = new Hexagon[gridHeight, gridWidth]; addGap(); calcStartPos(); materials = generateRandomMaterials(); createGrid(); }
private void SetupHexagons() { _allHexagons = new Hexagon[_width, _height]; _hexagonsParent = new GameObject("Hexagons").transform; _hexagonsParent.SetParent(this.transform); FillHexagons(); }
// private void AssignNeighbours(Hexagon[,] hexagons) { for (int x = 0; x <= hexagonsX; x += 1) { for (int y = 0; y <= hexagonsY; y += 1) { if (y > 0) { if (hexagons[x, y - 1].transform.position.x < hexagons[x, y].transform.position.x) { hexagons[x, y].neighbours[0] = hexagons[x, y - 1]; if (x != hexagonsX) { hexagons[x, y].neighbours[1] = hexagons[x + 1, y - 1]; } } else { hexagons[x, y].neighbours[1] = hexagons[x, y - 1]; if (x != 0) { hexagons[x, y].neighbours[0] = hexagons[x - 1, y - 1]; } } } if (x != 0) { hexagons[x, y].neighbours[5] = hexagons[x - 1, y]; } if (x != hexagonsX) { hexagons[x, y].neighbours[2] = hexagons[x + 1, y]; } if (y < hexagonsY) { if (hexagons[x, y + 1].transform.position.x < hexagons[x, y].transform.position.x) { hexagons[x, y].neighbours[4] = hexagons[x, y + 1]; if (x != hexagonsX) { hexagons[x, y].neighbours[3] = hexagons[x + 1, y + 1]; } } else { hexagons[x, y].neighbours[3] = hexagons[x, y + 1]; if (x != 0) { hexagons[x, y].neighbours[4] = hexagons[x - 1, y + 1]; } } } } } }
public UnityEvent OnActionMade; // Invoked when user tried to make a move. private void Start() { hexagonX = gridGO.GetComponent <SpriteRenderer>().sprite.bounds.extents.x; hexagonY = gridGO.GetComponent <SpriteRenderer>().sprite.bounds.extents.y; hexagons = new Hexagon[tileCountX, tileCountY]; OnActionMade = new UnityEvent(); CreateGrid(); }
/// <summary> /// Creates a new hexgrid with the default map width and height and fills it with hexagons. /// </summary> public HexGrid() { mGrid = new Hexagon[DEFAULT_MAP_WIDTH, DEFAULT_MAP_HEIGHT]; for (int i = 0; i < DEFAULT_MAP_WIDTH; i++) { for (int j = 0; j < DEFAULT_MAP_HEIGHT; j++) { mGrid[i, j] = new Hexagon(); } } }
public Grid(short hexagonSize, Vector2 center, byte maxValue, int mapRadius = 3) { this.hexagonSize = hexagonSize; Center = center; hexMap = new Hexagon[mapRadius * 2 + 1, mapRadius * 2 + 1]; bufferMap = new Hexagon[mapRadius * 2 + 1, mapRadius * 2 + 1]; selectedHex = new List <Hexagon>((mapRadius * 2 + 1) * (mapRadius * 2 + 1)); this.maxValue = maxValue; this.mapRadius = mapRadius; rand = new Random(); animator = new GridAnimator(this, 500f); }
private void GenerateGrid() { Hexagons = new Hexagon[Width, Height]; //Loop through whole grid and generate randomly for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { GenerateRandomHexagon(x, y); } } }
public Map(int _width, int _height) { width = _width; height = _height; terrain = new Hexagon[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { terrain[i, j] = new Hexagon { Properties = { isDry = false, ReliefType = 0, river = new bool[6], needDrawRiver = false } }; } } }
// Start is called before the first frame update void Start() { //testButton.onClick.AddListener(ButtonTest); hexagons = new Hexagon[boardWidth, boardHeight]; newlyCreatedHexagons = new List <Hexagon>(); bombs = new List <Hexagon>(); jointsWidth = boardWidth - 1; jointsHeight = 2 * (boardHeight - 1); joints = new JointPoint[jointsWidth, jointsHeight]; nextScoreForBomb = scorePerBomb; InitializeHexagonBoard(); }
public HexagonGrid(int width, int height, Canvas canvas, TappedEventHandler tapHandler ) { // Size of the grid ( size x size) Width = width; Height = height; // Determine hexagon size _canvas = canvas; _hexagonRadius = (int)(Window.Current.Bounds.Height / Height / 2); _hexagonHeight = _hexagonRadius * Math.Sin(Math.PI / 3); // Determine pixel width/height double pixelWidth = Width * 1.5 * _hexagonRadius + (Width % 2) * _hexagonRadius; double pixelHeight = _hexagonHeight * 2 * Height; // Offset for centering on screen _offsetX = (Window.Current.Bounds.Width - pixelWidth) / 2 + _hexagonRadius; _offsetY = (Window.Current.Bounds.Height - pixelHeight) / 2 + _hexagonHeight / 2; // Create grid Grid = new Hexagon[Width, Height]; // Populate grid to null for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { Hexagon hex = new Hexagon(_hexagonRadius, i, j); Point coord = coordinatesToHexagonPosition(i, j); // Position Grid hex.Top = _offsetY + coord.Y; hex.Left = _offsetX + coord.X; // Hide (for now) hex.IsVisible = false; // Save grid Grid[i, j] = hex; // Add to visual tree hex.UIElement.Tapped += tapHandler; _canvas.Children.Add(hex.UIElement); } } }
virtual public void GenMap() { hexagons = new Hexagon[nColumns, nRows]; Hex2GOMap = new Dictionary <Hexagon, GameObject>(); Go2HexMap = new Dictionary <GameObject, Hexagon>(); for (int column = 0; column < nColumns; column++) { for (int row = 0; row < nRows; row++) { Hexagon h = new Hexagon(this, column, row); h.Altitude = -0.5f; hexagons[column, row] = h; Vector3 pos = h.PositionFCamera( Camera.main.transform.position, nRows, nColumns, allow_Wrap_EW, allow_Wrap_NS ); //pos.y = +0.8355f; GameObject GO = (GameObject)Instantiate( hexagPrefab, pos, Quaternion.identity, this.transform ); Hex2GOMap[h] = GO; Go2HexMap[GO] = h; GO.name = string.Format("HEX: {0},{1}", column, row); GO.GetComponent <HexagonComponent>().Hex = h; GO.GetComponent <HexagonComponent>().HexMap = this; } } UpdateHVisual(); // StaticBatchingUtility.Combine(this.gameObject); }
/// <summary> /// Do NOT call, only used for tests. /// </summary> public static Map CreateMap(Hexagon[,] mapMatrix) { if (mapMatrix.GetLength(0) != mapMatrix.GetLength(1)) { throw new ArgumentException("Map matrix must be a square matrix"); } if (mapMatrix.GetLength(0) % 2 == 0) { throw new ArgumentException("Row and coloumn count of the map matrix must be an odd number"); } MapBuilder mapBuilder = new MapBuilder((mapMatrix.GetLength(0) + 1) / 2, mapMatrix); mapBuilder.createMap(); return(mapBuilder.Map); }
/** * \brief set all hexagons background */ private void initHexImg() { Hexagon[,] board = game.board.grid; foreach (Grid row in this.map.Children) { foreach (Object o in row.Children) { if (o is Hex) { Hex h = (Hex)o; int x = h.coord.x; int y = h.coord.y; PrintFondHex(board[x, y], h); } } } }
// Initialize Grid public void InitGrid(Level level) { // TODO: this scale will be re-calculated depending on hex width and height to fit in screen. FixHexagonScale(); _hexWidth *= HexPrefab.transform.lossyScale.x; _hexHeight *= HexPrefab.transform.lossyScale.y; // Grid Holder is being used as start position of the grid. _gridHolder = transform.GetChild(0); // Corner Holder is being used for organized display. _cornerHolder = transform.GetChild(1); _hexArray = new Hexagon[level.GridWidth, level.GridHeight]; _cornerArray = new Transform[level.GridWidth, level.GridHeight * 2]; AddGap(level.Gap); CreateGrid(level.GridWidth, level.GridHeight, level.ColorCount); CreateCornerGrid(level.GridWidth, level.GridHeight); SpawnCheckForEveryCorner(level.ColorCount); }
private MapBuilder(int sideLength, Hexagon[,] mapMatrix) { this.sideLength = sideLength; this.mapMatrix = mapMatrix; this.playerBases = new Dictionary <long, Hexagon>(); }
private List <Hexagon> checkExplosion(Hexagon[,] listToCheck) { List <Hexagon> neighbourList = new List <Hexagon>(); List <Hexagon> explosiveList = new List <Hexagon>(); Hexagon currentHexagon; Hexagon.NeighbourHexes currentNeighbours; Material currentColor; for (int y = 0; y < gridWidth; y++) { for (int x = 0; x < gridHeight; x++) { currentHexagon = listToCheck[x, y]; currentColor = currentHexagon.getMaterial(); currentNeighbours = currentHexagon.getSidehexes(); //Realizing valid side haxagons which is stars from left of grid if (isValidHexagon(currentNeighbours.up)) { neighbourList.Add(hexes[(int)currentNeighbours.up.x, (int)currentNeighbours.up.y]); } else { neighbourList.Add(null); } if (isValidHexagon(currentNeighbours.upRight)) { neighbourList.Add(hexes[(int)currentNeighbours.upRight.x, (int)currentNeighbours.upRight.y]); } else { neighbourList.Add(null); } if (isValidHexagon(currentNeighbours.downRight)) { neighbourList.Add(hexes[(int)currentNeighbours.downRight.x, (int)currentNeighbours.downRight.y]); } else { neighbourList.Add(null); } //Detect 3 hexagons that are exist like triangle for (int k = 0; k < neighbourList.Count - 1; ++k) { if (neighbourList[k] != null && neighbourList[k + 1] != null) { if (neighbourList[k].getMaterial() == currentColor && neighbourList[k + 1].getMaterial() == currentColor) { if (!explosiveList.Contains(neighbourList[k])) { explosiveList.Add(neighbourList[k]); } if (!explosiveList.Contains(neighbourList[k + 1])) { explosiveList.Add(neighbourList[k + 1]); } if (!explosiveList.Contains(currentHexagon)) { explosiveList.Add(currentHexagon); } } } } neighbourList.Clear(); } } return(explosiveList); }
public void SwapMaps() { Hexagon[,] temp = hexMap; hexMap = bufferMap; bufferMap = temp; }
#pragma warning restore 0649 public void Initialize(int columnCount, int rowCount) { _hexagons = new Hexagon[columnCount, rowCount]; }
void Start() { int count = 0; GenerationType continent_ = continent; GenerationType island_ = island; GenerationType smallIsland = island_; terrain = new Hexagon[width, height]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { GameObject vr = Instantiate(Gex); terrain[j, i] = vr.GetComponent <Hexagon>(); putGex(j, i, vr); terrain[j, i].Properties.isDry = false; terrain[j, i].Properties.ReliefType = 0; } } EarthGenerate(continent_); for (int k = 0; k < 8; k++) { island_.x = Random.Range(width / 3, width); island_.y = Random.Range(height / 9, 8 * height / 9); EarthGenerate(island_); } smallIsland.distributionC = 0.4f; smallIsland.distributionFriction = 0.1f; for (int k = 0; k < 40; k++) { island_.x = Random.Range(width / 4, width); island_.y = Random.Range(height / 9, 8 * height / 9); EarthGenerate(island_); } Smoothing(3, smothingDepth, smothingStep); for (int k = 0; k < 150; k++) { int _x = Random.Range(width / 3, width); int _y = Random.Range(0, height); if (terrain[_x, _y].Properties.isDry) { MakeRiver(_x, _y, directness, bending); } } ClimatAreaGenerate(clarityBoundaries, 0.0f); for (int k = 0; k < 5; k++) { int _x = Random.Range(0, width); int _y = Random.Range(0, height); MountainGeneration(_x, _y, Random.Range(4.0f, 5.0f), Random.Range(1.5f, 3.0f), Random.Range(120, 180), Random.Range(0.05f, 0.12f)); } for (int k = 0; k < 200; k++) { int _x = Random.Range(0, width); int _y = Random.Range(0, height); MountainGeneration(_x, _y, Random.Range(1.0f, 4.0f), Random.Range(0.25f, 2.0f), Random.Range(1, 10), Random.Range(0.5f, 0.2f)); } for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { terrain[j, i].GetComponent <Hexagon>().Draw(); } } }
public void NewGame(int width, int height, int mines) { StopTimer (); CurrentGameState = GameState.PlacingMines; Width = width; Height = height; MinesCount = mines; ClosedHexagonsCount = width * height; MarkedMinesCount = 0; Hexagons = new Hexagon[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Hexagons[x, y] = new Hexagon(x, y); } } Thread PlaceMinesThread = new Thread(PlaceMines); PlaceMinesThread.Start (); }
/// <summary> /// This method calculates every match on grid /// </summary> /// <param name="_hexagons"></param> /// <returns></returns> public List <Hexagon> CalculateMatches(Hexagon[,] _hexagons) { // this method can be improved later Hexagon cHex; Dictionary <NeighbourPos, Hexagon> currentNeighbours = new Dictionary <NeighbourPos, Hexagon>(); Color cColor; List <Hexagon> matches = new List <Hexagon>(); for (int x = 0; x < _hexagons.GetLength(0); x++) { for (int y = 0; y < _hexagons.GetLength(1); y++) { if (!Helpers.CheckNull(_hexagons[x, y])) { if (!matches.Contains(_hexagons[x, y])) { cHex = _hexagons[x, y]; cColor = cHex.Color; currentNeighbours = cHex.GetNeighbours(); // using linq for execute queries faster currentNeighbours = currentNeighbours.Where(h => h.Value.Color == cColor).ToDictionary(h => h.Key, h => h.Value); List <Hexagon> neighbourList = new List <Hexagon>(); if (currentNeighbours.Count >= 2) { if (currentNeighbours.ContainsKey(NeighbourPos.DOWN)) { neighbourList.Add(currentNeighbours[NeighbourPos.DOWN]); if (currentNeighbours.ContainsKey(NeighbourPos.DL)) { neighbourList.Add(currentNeighbours[NeighbourPos.DL]); } if (currentNeighbours.ContainsKey(NeighbourPos.DR)) { neighbourList.Add(currentNeighbours[NeighbourPos.DR]); } } else if ((currentNeighbours.ContainsKey(NeighbourPos.UP))) { neighbourList.Add(currentNeighbours[NeighbourPos.UP]); if (currentNeighbours.ContainsKey(NeighbourPos.UPL)) { neighbourList.Add(currentNeighbours[NeighbourPos.UPL]); } if (currentNeighbours.ContainsKey(NeighbourPos.UPR)) { neighbourList.Add(currentNeighbours[NeighbourPos.UPR]); } } } if (neighbourList.Count >= 2) { neighbourList.Add(cHex); neighbourList.ForEach(hex => { if (!matches.Contains(hex)) { matches.Add(hex); } }); } } } } } return(matches); }