Exemple #1
0
    public void RenderHexGrid()
    {
        HexagonMap hc = new HexagonMap();

        AxisCoordinate[] ac = new AxisCoordinate[] {
            new AxisCoordinate(0, 0),
            new AxisCoordinate(1, 0),
            new AxisCoordinate(2, 0),
            new AxisCoordinate(3, 0),

            new AxisCoordinate(0, 1),
            new AxisCoordinate(1, 1),
            new AxisCoordinate(2, 1),
            new AxisCoordinate(3, 1),

            new AxisCoordinate(-1, 2),
            new AxisCoordinate(0, 2),
            new AxisCoordinate(1, 2),
            new AxisCoordinate(2, 2),

            new AxisCoordinate(-1, 3),
            new AxisCoordinate(0, 3),
            new AxisCoordinate(1, 3),
            new AxisCoordinate(2, 3),
        };

        var ac1 = new List <AxisCoordinate>();

        foreach (AxisCoordinate a in ac)
        {
            DrawHexagon(a, 10);
        }
    }
Exemple #2
0
 public override void Initialize()
 {
     objname    = "";
     _corner    = new CornerMap();
     _lateral   = new LateralMap();
     _longitude = new LongitudeMap();
     _rect      = new RectMap();
     _hexagon   = new HexagonMap();
 }
Exemple #3
0
        public void ResetGame()
        {
            CurrentGameState = GameState.NotStarted;
            if (gameMode == GameMode.Multiplayer)
            {
                if (connectionState == ConnectionState.Waiting || connectionState == ConnectionState.Connected)
                {
                    HexagonServer.Emit("unregister");
                }

                connectionState = ConnectionState.NotConnected;
            }

            hexMap = null;
        }
Exemple #4
0
 public void StartGameSingle()
 {
     Global.UnfocusAllTextBox();
     gameMode         = GameMode.Single;
     CurrentGameState = GameState.Started;
     if (hexMap == null)
     {
         string[] textures = new string[3];
         textures[0] = "Hexa";
         textures[1] = "hexa_near";
         textures[2] = "hexa_far";
         hexMap      = new HexagonMap((int)(375.0f * ScreenScaleFactor.X), (int)(110.0f * ScreenScaleFactor.Y), 9, 45, 26, textures);
     }
     hexMap.StartSingle();
 }
        public void Setup()
        {
            _map = new HexagonMap
            {
                columnCount          = 10,
                rowCount             = 15,
                cellWidth            = 2.5f,
                cellHeight           = 2.5f,
                cellHorizontalOffset = 1f,
                cellVerticalOffset   = 1f,
                gemAssetCount        = 5
            };

            _map.Instantiate(true, 0);
        }
Exemple #6
0
        public void StartGameMultiplayer()
        {
            Global.UnfocusAllTextBox();
            gameMode         = GameMode.Multiplayer;
            CurrentGameState = GameState.Started;
            if (hexMap == null)
            {
                string[] textures = new string[3];
                textures[0] = "Hexa";
                textures[1] = "hexa_near";
                textures[2] = "hexa_far";
                hexMap      = new HexagonMap((int)(375.0f * ScreenScaleFactor.X), (int)(110.0f * ScreenScaleFactor.Y), 9, 45, 26, textures);
            }

            var username = TextBoxName.GetText();
            var roomid   = TextBoxRoom.GetText();

            if (ServerReady)
            {
                HexagonServer.Emit("register", username + "|" + roomid);
            }

            hexMap.StartMultiplayer();
        }
Exemple #7
0
        private Node TreeDistribution(Rectangle area, Color[] colors, BodyRenderer renderer)
        {
            var hexagons = new Node();

            var radius = 2;
            var spacing = 4;
            var mapWidth = area.Width / spacing - 3;
            var mapHeight = area.Height / spacing - 1;
            var map = new HexagonMap<bool>(mapWidth, mapHeight);

            var first = new Hexagon(Rand.Floor(mapWidth), Rand.Floor(mapHeight));
            map[first] = true;
            hexagons.Add(BuildHexagon(renderer, colors, first, radius, spacing));

            var current = first;
            var n = 5 + Rand.Floor(10);
            for (int i = 0; i < n; i++)
            {
                var freeNeighbors = current.GetNeighborsWhere(hexagon => map.IsInBound(hexagon) && !map[hexagon]).ToArray();
                if (!freeNeighbors.Any())
                    break;

                current = freeNeighbors.RandomItem();
                map[current] = true;

                hexagons.Add(BuildHexagon(renderer, colors, current, radius, spacing));
            }

            return hexagons;
        }
Exemple #8
0
    public void DrawHexagon(AxisCoordinate axisCorrdinate, float size)
    {
        Color color = Color.white;

        // using new formula
        Vector2 gridPosition = (new Vector2(
                                    size * (Mathf.Sqrt(3) * (axisCorrdinate.Q + axisCorrdinate.R * 0.5f)),
                                    size * (axisCorrdinate.R * 1.5f)));

        Ray     ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        float   rayDistance;
        Vector3 mousePlanePosition;
        Color   crossair = Color.white;


        if (groundPlane.Raycast(ray, out rayDistance))
        {
            mousePlanePosition = ray.GetPoint(rayDistance);
            DrawLine(
                new Vector3(mousePlanePosition.x + size, 0, mousePlanePosition.z),
                new Vector3(mousePlanePosition.x - size, 0, mousePlanePosition.z), Color.green);
            DrawLine(
                new Vector3(mousePlanePosition.x, 0, mousePlanePosition.z + size),
                new Vector3(mousePlanePosition.x, 0, mousePlanePosition.z - size), Color.green);

            float angleSideRight = 2 * Mathf.PI / 6 * (1 + 0.5f);
            float angleSideLeft  = 2 * Mathf.PI / 6 * (5 + 0.5f);
            float diameter       = size * (float)Math.Cos(angleSideLeft) - size * (float)Math.Cos(angleSideRight);

            var angle = 2.0f * Mathf.PI / 6.0f * (0.5f);
            var x     = gridPosition.x + size * Mathf.Cos(angle);
            var y     = gridPosition.y + size * Mathf.Sin(angle);
            //var selectedHex = HexagonCoordinates.ConvertPointCoordToAxialCoord(mousePlanePosition.x + 5, mousePlanePosition.z + 10f, diameter);
            var selectedHex = HexagonMap.ConvertPointCoordToAxialCoord(mousePlanePosition.x + diameter, mousePlanePosition.z + size, diameter, size);
            if (axisCorrdinate.Equals(selectedHex))
            {
                crossair = Color.red;
            }
        }

        Vector3[] hexPoints = new Vector3[6];
        for (int k = 0; k < 6; k++)
        {
            var angle = 2.0f * Mathf.PI / 6.0f * (k + 0.5f);

            var x = gridPosition.x + size * Mathf.Cos(angle);
            var y = gridPosition.y + size * Mathf.Sin(angle);

            if (k == 0)
            {
                hexPoints[0] = new Vector3(x, 0, y);
            }
            else
            {
                hexPoints[k] = new Vector3(x, 0, y);
                DrawLine(hexPoints[k - 1], hexPoints[k], color);
            }
        }
        DrawLine(hexPoints[5], hexPoints[0], color);

        DrawLine(
            new Vector3(gridPosition.x + 5, 0, gridPosition.y),
            new Vector3(gridPosition.x - 5, 0, gridPosition.y), crossair);
        DrawLine(
            new Vector3(gridPosition.x, 0, gridPosition.y + 5),
            new Vector3(gridPosition.x, 0, gridPosition.y - 5), crossair);
    }