Beispiel #1
0
    private void SetHexSprite(GameObject hex, HexBehaviour tb)
    {
        SpriteRenderer hexSpriteRenderer = hex.GetComponent <SpriteRenderer>();
        int            randomSpriteIndex = 0 + Random.Range(1, sprites.Length) * Random.Range(0, 2);

        hexSpriteRenderer.sprite = sprites[randomSpriteIndex];

        tb.NormalLookingHex = hexSpriteRenderer.sprite;
    }
Beispiel #2
0
    private void StartCurrentlyPlayingUnitTurn()
    {
        //UnitBehaviour ub = CurrentlySelectedPlayingUnit.GetComponent<UnitBehaviour>();
        StartingTile = CurrentlySelectedPlayingUnit.CurrentHexTile;
        StartingTile.ChangeVisualToSelected();

        //shows currently playing unit's ui
        CurrentlySelectedPlayingUnit.ShowUnitUI();

        UnitMovement.instance.SetupCurrentlyOwningUnit(CurrentlySelectedPlayingUnit);
    }
Beispiel #3
0
    private void StartingTileChanged(HexBehaviour origin)
    {
        if (this == origin)
        {
            BattlefieldManager.ManagerInstance.StartingTile = null;
            TileBehaviourSpriteRenderer.sprite = NormalLookingHex;
            return;
        }

        BattlefieldManager.ManagerInstance.StartingTile = this;
        ChangeVisualToSelected();
    }
Beispiel #4
0
    internal void SelectTilesInRange(int movementRange)
    {
        if (!Board.ContainsValue(this.StartingTile))
        {
            return;
        }

        Point currentUnitPoint = Board.FirstOrDefault(x => x.Value == this.StartingTile).Key;

        Debug.Log("Unit's starting coordiantes: (" + currentUnitPoint.X.ToString() + ", " + currentUnitPoint.Y.ToString() + ")");


        //int LowerXLimit = -1 * currentUnitPoint.Y / 2;
        //int UpperXLimit =
        //int lowerX =
        //for (int i = currentUnitPoint.X - movementRange; i < currentUnitPoint.X + movementRange+1; i++)
        //{

        //}

        HexBehaviour selectedTileBehaviour = null;

        //i is row index, j is column index
        for (int i = currentUnitPoint.X - movementRange; i < currentUnitPoint.X + movementRange + 1; i++)
        {
            for (int j = currentUnitPoint.Y - movementRange; j < currentUnitPoint.Y + movementRange + 1; j++)
            {
                // range of x changes depending on Y:
                // for Y = 0,1 => 0<=X<=9 range
                // for Y = 8,9 => -4<=X<=5 range
                // upper left tile coordiantes are always 0,0
                if (j >= 0 && j < gridWidthInHexes && i >= (-1 * j / 2) && i < (gridHeightInHexes - j / 2))
                {
                    //my random formula for getting hex shaped selection
                    if (currentUnitPoint.X + currentUnitPoint.Y - movementRange <= i + j && i + j <= currentUnitPoint.X + currentUnitPoint.Y + movementRange)
                    {
                        selectedTileBehaviour = Board[new Point(i, j)];

                        if (selectedTileBehaviour.OwningTile.Passable)
                        {
                            selectedTileBehaviour.OwningTile.IsInRange = true;
                            selectedTileBehaviour.ChangeHexVisual(Color.gray);

                            Debug.Log("Distance from (" + currentUnitPoint.X.ToString() + ", " + currentUnitPoint.Y.ToString() + ") to the (" + i + ", " + j + ") is: " + Vector3.Distance(StartingTile.UnitAnchorWorldPositionVector, selectedTileBehaviour.UnitAnchorWorldPositionVector));
                        }
                    }
                }
            }
        }
    }
Beispiel #5
0
    public void CreateHex(int x, int y)
    {
        GameObject socket = hexSockets[x, y];
        HexType    type   = RandomType();
        GameObject go     = Instantiate(type.prefab, socket.transform.position + Vector3.up * 2.0f, type.prefab.transform.rotation);

        go.transform.parent = hexParent.transform;
        go.name             = "Hex(" + x + "," + y + ")";
        board[x, y]         = new Hex(go, type, x, y);
        HexBehaviour hexBehaviour = go.GetComponent <HexBehaviour>();

        hexBehaviour.hexReference = board[x, y];
        hexBehaviour.SetPosition(socket.transform.position);
    }
Beispiel #6
0
    private void CreateGrid()
    {
        //Vector2 gridSize =
        GameObject HexGridGO = new GameObject("HexGrid");

        Board = new Dictionary <Point, HexBehaviour>();

        for (int y = 0; y < gridHeightInHexes; y++)
        {
            for (int x = 0; x < gridWidthInHexes; x++)
            {
                GameObject hex     = (GameObject)Instantiate(Hex);
                Vector2    gridPos = new Vector2(x, y);
                hex.transform.position = CalculateWorldCoordinates(gridPos);
                hex.transform.parent   = HexGridGO.transform;

                //temp assigning Tile behaviour
                HexBehaviour tb = (HexBehaviour)hex.GetComponent("HexBehaviour");
                tb.OwningTile  = new HexTile((int)x - (int)(y / 2), (int)y);
                tb.coordinates = tb.OwningTile.ToString();
                //tb.UnitAnchorWorldPositionVector = hex.transform.position;

                //each has gets a random sprite
                SetHexSprite(hex, tb);

                //each hex get rotated for random r*60 degrees
                hex.transform.rotation = Quaternion.Euler(0, 0, Random.Range(0, 6) * 60);
                hex.transform.rotation = Quaternion.Euler(60, 0, 0);
                //once we rotate the hexes we set that position to tile behaviour, and set unit anchor, place where unit will stand on tile
                tb.UnitAnchorWorldPositionVector = hex.transform.position - new Vector3(0f, 0.36f, 0f);

                //adding Tile to dictionary
                Board.Add(tb.OwningTile.Location, tb);

                /*//variable to indicate if all rows have the same number of hexes in them
                 * //this is checked by comparing width of the first hex row plus half of the hexWidth with groundWidth
                 * bool equalLineLengths = (gridSize.x + 0.5) * hexWidth <= groundWidth;
                 */
            }
        }

        //Neighboring tile coordinates of all the tiles are calculated
        foreach (HexBehaviour behaviour in Board.Values)
        {
            behaviour.OwningTile.FindNeighbours(Board, new Vector2(gridWidthInHexes, gridHeightInHexes));
        }
    }
Beispiel #7
0
    public HexBehaviour [] GetSlavesBehaviors()
    {
        int slaveSideX = dotObject.slavesBoardIndex[0].x;
        int slaveSideY = dotObject.slavesBoardIndex[0].y;
        int slaveTopX  = dotObject.slavesBoardIndex[1].x;
        int slaveTopY  = dotObject.slavesBoardIndex[1].y;
        int slaveBotX  = dotObject.slavesBoardIndex[2].x;
        int slaveBotY  = dotObject.slavesBoardIndex[2].y;

        Hex hexSide = boardManager.board[slaveSideX, slaveSideY];
        Hex hexTop  = boardManager.board[slaveTopX, slaveTopY];
        Hex hexBot  = boardManager.board[slaveBotX, slaveBotY];

        HexBehaviour hexBSide = hexSide.go.GetComponent <HexBehaviour>();
        HexBehaviour hexBTop  = hexTop.go.GetComponent <HexBehaviour>();
        HexBehaviour hexBBot  = hexBot.go.GetComponent <HexBehaviour>();

        return(new HexBehaviour[3] {
            hexBSide, hexBTop, hexBBot
        });
    }
Beispiel #8
0
    public void CreateBombHex(int x, int y)
    {
        GameObject socket = hexSockets[x, y];
        HexType    type   = RandomType();
        GameObject go     = Instantiate(type.prefab, socket.transform.position + Vector3.up * 4.0f, type.prefab.transform.rotation);

        go.transform.parent = hexParent.transform;
        go.name             = "Hex(" + x + "," + y + ")";
        board[x, y]         = new Hex(go, type, x, y);
        HexBehaviour hexBehaviour = go.GetComponent <HexBehaviour>();

        hexBehaviour.hexReference = board[x, y];

        GameObject bombGO = Instantiate(bombPrefab, socket.transform.position + Vector3.up * 4.11f + Vector3.right * 0.07f, Quaternion.identity, go.transform);

        BombBehaviour bb = bombGO.GetComponent <BombBehaviour>();

        bombsReferences.Add(bb);
        bb.Init(bombStartingCountDown);

        hexBehaviour.SetPosition(socket.transform.position);
    }
Beispiel #9
0
    private void ColorPossibleTiles()
    {
        ResetPreviousHexes();
        Collider[] hitColliders = Physics.OverlapSphere(transform.position, moveRadius);

        for (int i = 0; i < hitColliders.Length; i++)
        {
            GameObject   obj = hitColliders[i].gameObject;
            HexBehaviour hex = obj.GetComponent <HexBehaviour>();
            if (hex == null)
            {
                continue;
            }
            hex.SetMovable();

            if (movableHexes == null)
            {
                movableHexes = new List <HexBehaviour>();
            }

            movableHexes.Add(hex);
        }
    }
Beispiel #10
0
    public void EndCurrentPlayingUnitTurn()
    {
        //don't know if this is necessary
        StartingTile.ChangeHexVisualToDeselected();
        DestinationTile.ChangeHexVisualToDeselected();

        //movement stuff...
        UnitBehaviour ub = CurrentlySelectedPlayingUnit.GetComponent <UnitBehaviour>();

        //...setting previously occupied tile back to being passable...
        ub.CurrentHexTile.OwningTile.Occupied = false;
        ub.CurrentHexTile.ObjectOnHex         = null;
        //...setting previous destination tile to be new current for moving unit and marking it as notpassable...
        ub.CurrentHexTile = DestinationTile;

        ub.CurrentHexTile.OwningTile.Occupied = true;
        ub.CurrentHexTile.ObjectOnHex         = ub;
        //...reseting starting and destination tiles in order to destroy path...
        StartingTile    = null;
        DestinationTile = null;

        //...this destroys path when the unit reaches destination...
        GenerateAndShowPath();

        ub.HideUnitUI();

        //detarget targeted unit
        if (TargetedUnit != null)
        {
            TargetedUnit.HideUnitUI();
            TargetedUnit = null;
        }

        //...selects next playing unit...
        SelectNextPlayingUnit();
        StartCurrentlyPlayingUnitTurn();
    }
Beispiel #11
0
    //Rotates three slaves around dot
    public void Rotate(bool clockWise)
    {
        // Take the slaves and self
        int slaveSideX = dotObject.slavesBoardIndex[0].x;
        int slaveSideY = dotObject.slavesBoardIndex[0].y;
        int slaveTopX  = dotObject.slavesBoardIndex[1].x;
        int slaveTopY  = dotObject.slavesBoardIndex[1].y;
        int slaveBotX  = dotObject.slavesBoardIndex[2].x;
        int slaveBotY  = dotObject.slavesBoardIndex[2].y;

        Hex hexSide = boardManager.board[slaveSideX, slaveSideY];
        Hex hexTop  = boardManager.board[slaveTopX, slaveTopY];
        Hex hexBot  = boardManager.board[slaveBotX, slaveBotY];

        HexBehaviour hexBSide = hexSide.go.GetComponent <HexBehaviour>();
        HexBehaviour hexBTop  = hexTop.go.GetComponent <HexBehaviour>();
        HexBehaviour hexBBot  = hexBot.go.GetComponent <HexBehaviour>();

        if (isLeft)
        {
            if (clockWise)
            {
                // Update Board
                Hex temp1 = boardManager.board[slaveTopX, slaveTopY].Clone();

                boardManager.board[slaveSideX, slaveSideY].x = slaveTopX;
                boardManager.board[slaveSideX, slaveSideY].y = slaveTopY;
                boardManager.board[slaveTopX, slaveTopY]     = boardManager.board[slaveSideX, slaveSideY];
                boardManager.board[slaveBotX, slaveBotY].x   = slaveSideX;
                boardManager.board[slaveBotX, slaveBotY].y   = slaveSideY;
                boardManager.board[slaveSideX, slaveSideY]   = boardManager.board[slaveBotX, slaveBotY];
                temp1.x = slaveBotX;
                temp1.y = slaveBotY;
                boardManager.board[slaveBotX, slaveBotY] = temp1;

                Vector3 hexSideTargetPosition = boardManager.hexSockets[slaveTopX, slaveTopY].transform.position;
                Vector3 hexTopTargetPosition  = boardManager.hexSockets[slaveBotX, slaveBotY].transform.position;
                Vector3 hexBotTargetPosition  = boardManager.hexSockets[slaveSideX, slaveSideY].transform.position;

                hexBSide.SetPosition(hexSideTargetPosition, this);
                hexBTop.SetPosition(hexTopTargetPosition, this);
                hexBBot.SetPosition(hexBotTargetPosition, this);

                // hexBSide.SetRotation(Vector3.forward*60f);
                // hexBTop.SetRotation(Vector3.forward *60f);
                // hexBBot.SetRotation(Vector3.forward *60f);

                transform.RotateAround(transform.position, transform.forward, -120.0f);
            }
            else
            {
                // Update Board
                Hex temp1 = boardManager.board[slaveBotX, slaveBotY].Clone();

                boardManager.board[slaveSideX, slaveSideY].x = slaveBotX;
                boardManager.board[slaveSideX, slaveSideY].y = slaveBotY;
                boardManager.board[slaveBotX, slaveBotY]     = boardManager.board[slaveSideX, slaveSideY];
                boardManager.board[slaveTopX, slaveTopY].x   = slaveSideX;
                boardManager.board[slaveTopX, slaveTopY].y   = slaveSideY;
                boardManager.board[slaveSideX, slaveSideY]   = boardManager.board[slaveTopX, slaveTopY];
                temp1.x = slaveTopX;
                temp1.y = slaveTopY;
                boardManager.board[slaveTopX, slaveTopY] = temp1;

                Vector3 hexSideTargetPosition = boardManager.hexSockets[slaveBotX, slaveBotY].transform.position;
                Vector3 hexTopTargetPosition  = boardManager.hexSockets[slaveSideX, slaveSideY].transform.position;
                Vector3 hexBotTargetPosition  = boardManager.hexSockets[slaveTopX, slaveTopY].transform.position;

                hexBSide.SetPosition(hexSideTargetPosition, this);
                hexBTop.SetPosition(hexTopTargetPosition, this);
                hexBBot.SetPosition(hexBotTargetPosition, this);

                // hexBSide.SetRotation(Vector3.forward * -60f);
                // hexBTop.SetRotation(Vector3.forward * -60f);
                // hexBBot.SetRotation(Vector3.forward * -60f);

                transform.RotateAround(transform.position, transform.forward, 120.0f);
            }
        }
        else
        {
            if (clockWise)
            {
                // Update Board
                Hex temp1 = boardManager.board[slaveBotX, slaveBotY].Clone();

                Hex side = boardManager.board[slaveSideX, slaveSideY];
                side.x = slaveBotX;
                side.y = slaveBotY;
                boardManager.board[slaveBotX, slaveBotY] = side;

                Hex top = boardManager.board[slaveTopX, slaveTopY];
                top.x = slaveSideX;
                top.y = slaveSideY;
                boardManager.board[slaveSideX, slaveSideY] = boardManager.board[slaveTopX, slaveTopY];
                temp1.x = slaveTopX;
                temp1.y = slaveTopY;
                boardManager.board[slaveTopX, slaveTopY] = temp1;

                Vector3 hexSideTargetPosition = boardManager.hexSockets[slaveBotX, slaveBotY].transform.position;
                Vector3 hexTopTargetPosition  = boardManager.hexSockets[slaveSideX, slaveSideY].transform.position;
                Vector3 hexBotTargetPosition  = boardManager.hexSockets[slaveTopX, slaveTopY].transform.position;

                hexBSide.SetPosition(hexSideTargetPosition, this);
                hexBTop.SetPosition(hexTopTargetPosition, this);
                hexBBot.SetPosition(hexBotTargetPosition, this);

                // hexBSide.SetRotation(Vector3.forward * -60f);
                // hexBTop.SetRotation(Vector3.forward * -60f);
                // hexBBot.SetRotation(Vector3.forward * -60f);


                transform.RotateAround(transform.position, transform.forward, 120.0f);
            }
            else
            {
                // Update Board
                Hex temp1 = boardManager.board[slaveTopX, slaveTopY].Clone();

                Hex side = boardManager.board[slaveSideX, slaveSideY];
                side.x = slaveTopX;
                side.y = slaveTopY;
                boardManager.board[slaveTopX, slaveTopY] = side;

                Hex bot = boardManager.board[slaveBotX, slaveBotY];
                bot.x = slaveSideX;
                bot.y = slaveSideY;
                boardManager.board[slaveSideX, slaveSideY] = bot;

                temp1.x = slaveBotX;
                temp1.y = slaveBotY;
                boardManager.board[slaveBotX, slaveBotY] = temp1;

                Vector3 hexSideTargetPosition = boardManager.hexSockets[slaveTopX, slaveTopY].transform.position;
                Vector3 hexTopTargetPosition  = boardManager.hexSockets[slaveBotX, slaveBotY].transform.position;
                Vector3 hexBotTargetPosition  = boardManager.hexSockets[slaveSideX, slaveSideY].transform.position;

                hexBSide.SetPosition(hexSideTargetPosition, this);
                hexBTop.SetPosition(hexTopTargetPosition, this);
                hexBBot.SetPosition(hexBotTargetPosition, this);

                // hexBSide.SetRotation(Vector3.forward * 60f);
                // hexBTop.SetRotation(Vector3.forward * 60f);
                // hexBBot.SetRotation(Vector3.forward * 60f);

                transform.RotateAround(transform.position, transform.forward, -120.0f);
            }
        }
    }
Beispiel #12
0
 private void Start()
 {
     _hexBehaviour = GetComponent <HexBehaviour>();
     GamePhase     = Phase.Begin;
 }
Beispiel #13
0
 private void Start()
 {
     _hexBehaviour  = GameObject.Find("HexGrid").GetComponent <HexBehaviour>();
     _gameBehaviour = _hexBehaviour.GetComponent <GameBehaviour>();
     _canvas        = GetComponent <CanvasGroup>();
 }