Exemplo n.º 1
0
 // Start is called before the first frame update
 void Start()
 {
     gs  = GameObject.FindGameObjectWithTag("SceneController").GetComponent <gridScript>();
     pos = new Vector2(Random.Range(0, gs.grid.GetLength(1)), Random.Range(0, gs.grid.GetLength(0)));
     // gs.occupySpace(pos);
     this.transform.position = gs.getGridPosition(pos);
 }
Exemplo n.º 2
0
 // Start is called before the first frame update
 void Start()
 {
     gs                 = GameObject.FindGameObjectWithTag("SceneController").GetComponent <gridScript>();
     pos                = new Vector2(0, 0);
     prevPos            = pos;
     transform.position = gs.getGridPosition(pos);
     StartCoroutine("walk");
 }
Exemplo n.º 3
0
 //get the starting position on the map
 public void getStartPos()
 {
     gs = GameObject.FindGameObjectWithTag("SceneController").GetComponent <gridScript>();
     u  = GameObject.FindGameObjectWithTag("SceneController").GetComponent <uitl>();
     while (!getRandomPos())
     {
         ;
     }
     prevPos = pos;
 }
Exemplo n.º 4
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
 }
Exemplo n.º 5
0
 public MeshCollider currentTile;                        //what tile are we currently hovering over, this fixes rotation issues and can be used to grab data about what is there (once we change the type....)
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
     buildMenu.SetActive(false);
 }
Exemplo n.º 6
0
    // Thus far this will execute when the moveButton is pressed. It will turn the grid  blue.
    public void changeMaterial()
    {
        exemptHex = false;
        grid      = GameObject.Find("GridMap");

        // The attack button should be hidden if in movement mode, maybe in the future there should be a stand-alone script for this.
        attackButton.SetActive(false);
        hexPrefabChild = hexPrefab.transform.Find("hex_frame").gameObject;

        // Return to normal mode, grid becomes yellow.
        if (moveButton.GetComponentInChildren <Text>().text == "Confirm Move")
        {
            gridScript gridScript = GameObject.Find("GridMap").GetComponent <gridScript>();
            gridScript.warp(exemptHexName);
            gridScript.choseATile = false;

            moveButton.GetComponentInChildren <Text>().text = "Move";
            moveButton.SetActive(false);

            for (i = 0; i <= 32; i++)
            {
                for (j = 0; j <= 12; j++)
                {
                    specificHex = grid.transform.Find("Tile_" + i + "_" + j).gameObject;
                    gridObject  = grid.transform.Find("Tile_" + i + "_" + j).Find("hex_frame").gameObject;
                    gridObject.GetComponent <MeshRenderer>().material = materialList[(int)GridColor.yellow];
                }
            }
        }

        else
        {  // Enter Movement mode, grid becomes blue.
            moveButton.GetComponentInChildren <Text>().text = "Confirm Move";
            gridScript    gridScript    = GameObject.Find("GridMap").GetComponent <gridScript>();
            gridPlacement gridPlacement = GameObject.Find("GridMap").GetComponent <gridPlacement>();
            isBlue = true;

            for (i = 0; i <= 32; i++)
            {
                for (j = 0; j <= 12; j++)
                {
                    specificHex = grid.transform.Find("Tile_" + i + "_" + j).gameObject;
                    gridObject  = grid.transform.Find("Tile_" + i + "_" + j).Find("hex_frame").gameObject;

                    if (exemptHexName == specificHex.name)
                    {
                        exemptHex = true;
                    }

                    if (exemptHex == false)
                    {
                        gridObject.GetComponent <MeshRenderer>().material = materialList[(int)GridColor.blue];
                    }
                    exemptHex = false;
                }
            }

            switch (gridScript.selectedCharacter.name)
            {
            case "player1SlotA":
                displayRangeofMovement(gridPlacement.leftA);
                break;

            case "player1SlotB":
                displayRangeofMovement(gridPlacement.leftB);
                break;

            case "player1SlotC":
                displayRangeofMovement(gridPlacement.leftC);
                break;

            case "player2SlotA":
                displayRangeofMovement(gridPlacement.rightA);
                break;

            case "player2SlotB":
                displayRangeofMovement(gridPlacement.rightB);
                break;

            case "player2SlotC":
                displayRangeofMovement(gridPlacement.rightC);
                break;
            }
        }
    }
Exemplo n.º 7
0
    // Should be executed when the player selects the Melee button.
    public void meleeAttack()
    {
        gridPlacement         gridPlacement = GameObject.Find("GridMap").GetComponent <gridPlacement>();
        gridScript            gridScript = GameObject.Find("GridMap").GetComponent <gridScript>();
        stringTileToIntCoords stringTileToIntCoords = GameObject.Find("GridMap").GetComponent <stringTileToIntCoords>();
        playerSelect          playerSelect = GameObject.Find("GameCamera").GetComponent <playerSelect>();
        playerStatus          playerStatus = GameObject.Find("GridMap").GetComponent <playerStatus>();
        string        currentPosition, enemyApos, enemyBpos, enemyCpos;
        int           currentX, currentY;
        List <string> surroundingTiles = new List <string>();
        // bool AisOK = false, BisOK = false, CisOK = false;
        GameObject meleeButton = GameObject.Find("MeleeButton"), infoBar = GameObject.Find("InfoBar"), chosenEnemy;
        GameObject gridObject = GameObject.Find("GridMap");


        // Clicked Melee button when text is Melee
        if (meleeButton.GetComponentInChildren <Text>().text == "Melee")
        {
            meleeButton.GetComponentInChildren <Text>().text = "Confirm Melee";


            // Check to see if another monkey of the oposing team is next to your currently selected character.

            // Find the current position of currently selected monkey.
            switch (playerSelect.currentCharacter)
            {
            case "A":
                currentPosition = gridPlacement.leftA;
                break;

            case "B":
                currentPosition = gridPlacement.leftB;
                break;

            case "C":
                currentPosition = gridPlacement.leftC;
                break;

            case "A2":
                currentPosition = gridPlacement.rightA;
                break;

            case "B2":
                currentPosition = gridPlacement.rightB;
                break;

            case "C2":
                currentPosition = gridPlacement.rightC;
                break;

            default:
                currentPosition = "Tile_0_0";
                break;
            }

            currentX = stringTileToIntCoords.getXposition(currentPosition);
            currentY = stringTileToIntCoords.getYposition(currentPosition);

            Debug.Log("currentPosInMelee = " + currentX + ", " + currentY);

            // Find positions of enemies.
            if (playerStatus.turn == 0)
            {
                enemyApos = gridPlacement.rightA;
                enemyBpos = gridPlacement.rightB;
                enemyCpos = gridPlacement.rightC;
            }
            else
            {
                enemyApos = gridPlacement.leftA;
                enemyBpos = gridPlacement.leftB;
                enemyCpos = gridPlacement.leftB;
            }

            // Compile list of surroindg tiles.
            if (currentY % 2 == 0)// even hex row
            {
                surroundingTiles.Add("Tile_" + currentX + "_" + (currentY + 1));
                surroundingTiles.Add("Tile_" + (currentX - 1) + "_" + (currentY + 1));
                surroundingTiles.Add("Tile_" + (currentX - 1) + "_" + currentY);
                surroundingTiles.Add("Tile_" + (currentX - 1) + "_" + (currentY - 1));
                surroundingTiles.Add("Tile_" + currentX + "_" + (currentY - 1));
                surroundingTiles.Add("Tile_" + (currentX + 1) + "_" + currentY);
            }
            else
            {// odd hex row
                surroundingTiles.Add("Tile_" + (currentX + 1) + "_" + (currentY + 1));
                surroundingTiles.Add("Tile_" + currentX + "_" + (currentY + 1));
                surroundingTiles.Add("Tile_" + (currentX - 1) + "_" + currentY);
                surroundingTiles.Add("Tile_" + currentX + "_" + (currentY - 1));
                surroundingTiles.Add("Tile_" + (currentX + 1) + "_" + (currentY - 1));
                surroundingTiles.Add("Tile_" + (currentX + 1) + "_" + currentY);
            }

            // Loop thru surrounding tiles to see if any ememyPositions conflict, if so mark that.
            for (int i = 0; i < 6; i++)
            {
                if (enemyApos == surroundingTiles[i])
                {
                    playerStatus.AisOK = true;
                    Debug.Log("AisOK");
                }
                if (enemyBpos == surroundingTiles[i])
                {
                    playerStatus.BisOK = true;
                    Debug.Log("BisOK");
                }
                if (enemyCpos == surroundingTiles[i])
                {
                    playerStatus.CisOK = true;
                    Debug.Log("CisOK");
                }
            }
        }

        if (meleeButton.GetComponentInChildren <Text>().text == "Confirm Melee")
        {
            if (playerStatus.turn == 1)
            {
                switch (playerSelect.meleeingCharacter)
                {
                case "A":

                    if (playerStatus.AisOK)
                    {
                        chooseA = true;
                        chooseB = false;
                        chooseC = false;
                    }
                    break;

                case "B":

                    if (playerStatus.BisOK)
                    {
                        chooseA = false;
                        chooseB = true;
                        chooseC = false;
                    }
                    break;

                case "C":

                    if (playerStatus.CisOK)
                    {
                        chooseA = false;
                        chooseB = false;
                        chooseC = true;
                    }
                    break;

                default:
                    return;
                }
            }
            else
            {
                switch (playerSelect.meleeingCharacter)
                {
                case "A2":

                    if (playerStatus.AisOK)
                    {
                        chooseA = true;
                        chooseB = false;
                        chooseC = false;
                    }
                    break;

                case "B2":
                    if (playerStatus.BisOK)
                    {
                        chooseA = false;
                        chooseB = true;
                        chooseC = false;
                    }
                    break;

                case "C2":
                    if (playerStatus.CisOK)
                    {
                        chooseA = false;
                        chooseB = false;
                        chooseC = true;
                    }
                    break;

                default:
                    return;
                }
            }

            // Make call to doMelee function.
            if (chooseA)
            {
                doMelee("A");
            }
            if (chooseB)
            {
                doMelee("B");
            }
            if (chooseC)
            {
                doMelee("C");
            }

            chooseA            = false;
            chooseB            = false;
            chooseC            = false;
            playerStatus.AisOK = false;
            playerStatus.BisOK = false;
            playerStatus.CisOK = false;
        }
    }
 // Start is called before the first frame update
 void Start()
 {
     pos = new Vector2(1, 1);
     ma  = Component.FindObjectOfType <MoveAgent>();
     gs  = GameObject.FindGameObjectWithTag("SceneController").gameObject.GetComponent <gridScript>();
 }
Exemplo n.º 9
0
    // Update is called once per frame
    void Update()
    {
        //selecting cubes to swap
        if (Input.GetMouseButtonDown(0))
        {
            lightScript.destroy = true;
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, 1000.0f))
            {
                ;
            }
            {
                try {
                    if (selectionCounter == 0) //holds instance of first cube
                    {
                        selection1 = hit.collider.gameObject;

                        selectionHold       = hit.collider.gameObject;
                        selectionCounter    = 1;
                        lightScript.destroy = false;
                        highlight           = Instantiate(Newlight, new Vector3(selection1.GetComponent <Cubevar>().xpos * 7, selection1.GetComponent <Cubevar>().ypos * 7, selection1.GetComponent <Cubevar>().zpos * 7), Quaternion.identity) as GameObject;
                    }
                    else if (selectionCounter == 1) // holds instance of second cube
                    {
                        selection2 = hit.collider.gameObject;
                        //swapping cubes

                        if (selection1.GetComponent <Cubevar>().xpos == selection2.GetComponent <Cubevar>().xpos - 1 ^ // ^ = xor to stop diagonal selection
                            selection1.GetComponent <Cubevar>().xpos == selection2.GetComponent <Cubevar>().xpos + 1 ^
                            selection1.GetComponent <Cubevar>().ypos == selection2.GetComponent <Cubevar>().ypos - 1 ^ //check if selections are adjacent to each other
                            selection1.GetComponent <Cubevar>().ypos == selection2.GetComponent <Cubevar>().ypos + 1 ^
                            selection1.GetComponent <Cubevar>().zpos == selection2.GetComponent <Cubevar>().zpos - 1 ^
                            selection1.GetComponent <Cubevar>().zpos == selection2.GetComponent <Cubevar>().zpos + 1)
                        {
                            GameController = GameObject.FindObjectOfType(typeof(gridScript)) as gridScript;    //switches cubes 2 = 1, 3 = 2, 1 = 3
                            colour[selectionHold.GetComponent <Cubevar>().xpos, selectionHold.GetComponent <Cubevar>().ypos, selectionHold.GetComponent <Cubevar>().zpos] =
                                GameController.grid[selection1.GetComponent <Cubevar>().xpos, selection1.GetComponent <Cubevar>().ypos, selection1.GetComponent <Cubevar>().zpos];

                            GameController.grid[selection1.GetComponent <Cubevar>().xpos, selection1.GetComponent <Cubevar>().ypos, selection1.GetComponent <Cubevar>().zpos] =
                                GameController.grid[selection2.GetComponent <Cubevar>().xpos, selection2.GetComponent <Cubevar>().ypos, selection2.GetComponent <Cubevar>().zpos];

                            GameController.grid[selection2.GetComponent <Cubevar>().xpos, selection2.GetComponent <Cubevar>().ypos, selection2.GetComponent <Cubevar>().zpos] =
                                colour[selectionHold.GetComponent <Cubevar>().xpos, selectionHold.GetComponent <Cubevar>().ypos, selectionHold.GetComponent <Cubevar>().zpos];
                            music.volume = titleScript.volumelvl;
                            music.PlayOneShot(swapnoise, 1);
                            lightScript.destroy = true;
                            GameController.matchCheck();
                            // GameController.refreshGrid(); removing this means the code will be more efficiant as refresggrid() is called at the beginning of mathchcheck now.
                            // Debug.Log("swappable");
                        }
                        else
                        {
                            // Debug.Log("not swappable");
                        }
                        selectionCounter = 0; //lets you select the first cube again
                    }
                }
                catch
                {
                    selection1          = null;
                    selection2          = null; //if you goof it resets both selestions.
                    selectionHold       = null;
                    selectionCounter    = 0;
                    lightScript.destroy = true;
                    //  Debug.Log("try clicking a cube numbnuts");
                }
                // Debug.Log("you selected this" + hit.collider.gameObject.name);
                // Debug.Log("seletion1" + selection1);
                // Debug.Log("seletion2" + selection2);
            }
        }
    }
Exemplo n.º 10
0
 void Awake()
 {
     secondsTillNextSpawn = Random.Range(15, 20);
     gs = GameObject.FindGameObjectWithTag("SceneController").GetComponent <gridScript>();
 }
Exemplo n.º 11
0
    void Update()
    {
        infoBar = GameObject.Find("InfoBar");
        if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
        {
            RaycastHit   hit;
            Ray          ray          = Camera.main.ScreenPointToRay(Input.mousePosition);
            playerStatus playerStatus = GameObject.Find("GridMap").GetComponent <playerStatus>();
            gridScript   gridScript   = GameObject.Find("GridMap").GetComponent <gridScript>();

            // Click the character you want to play as, esnure that you're not already in movement mode.
            if (Physics.Raycast(ray, out hit, rayLength, layermask))
            {
                if (hit.collider.name == "player1SlotA")
                {
                    // Melee Mode
                    if (meleeButton.GetComponentInChildren <Text>().text == "Confirm Melee")
                    {
                        meleeingCharacter = "A";
                        if (playerStatus.AisOK && playerStatus.turn == 1)
                        {
                            infoBar.GetComponentInChildren <Text>().text = "Choosing to melee left team's A player";
                        }
                        else if (!playerStatus.AisOK && playerStatus.turn == 1)
                        {
                            infoBar.GetComponentInChildren <Text>().text = "Player out of range";
                        }
                    }
                    else
                    {
                        currentCharacter = "A";

                        if (gridScript.selectedCharacter == GameObject.Find("player1SlotA")) // double check with grid script
                        {
                            infoBar.GetComponentInChildren <Text>().text = "Left Player A Selected";
                            if (playerStatus.leftA.moved == false)
                            {
                                moveButton.SetActive(true);
                            }
                            if (playerStatus.leftA.attacked == false)
                            {
                                attackButton.SetActive(true);
                            }
                        }
                    }
                }
                if (hit.collider.name == "player1SlotB")
                {
                    // Melee Mode
                    if (meleeButton.GetComponentInChildren <Text>().text == "Confirm Melee")
                    {
                        meleeingCharacter = "B";
                        if (playerStatus.BisOK && playerStatus.turn == 1)
                        {
                            infoBar.GetComponentInChildren <Text>().text = "Choosing to melee left team's A player";
                        }
                        else if (!playerStatus.BisOK && playerStatus.turn == 1)
                        {
                            infoBar.GetComponentInChildren <Text>().text = "Player out of range";
                        }
                    }
                    else
                    {
                        currentCharacter = "B";

                        if (gridScript.selectedCharacter == GameObject.Find("player1SlotB"))
                        {
                            infoBar.GetComponentInChildren <Text>().text = "Left Player B Selected";
                            if (playerStatus.leftB.moved == false)
                            {
                                moveButton.SetActive(true);
                            }
                            if (playerStatus.leftB.attacked == false)
                            {
                                attackButton.SetActive(true);
                            }
                        }
                    }
                }
                if (hit.collider.name == "player1SlotC")
                {
                    // Melee Mode
                    if (meleeButton.GetComponentInChildren <Text>().text == "Confirm Melee")
                    {
                        meleeingCharacter = "C";
                        if (playerStatus.CisOK && playerStatus.turn == 1)
                        {
                            infoBar.GetComponentInChildren <Text>().text = "Choosing to melee left team's C player";
                        }
                        else if (!playerStatus.CisOK && playerStatus.turn == 1)
                        {
                            infoBar.GetComponentInChildren <Text>().text = "Player out of range";
                        }
                    }
                    else
                    {
                        currentCharacter = "C";

                        if (gridScript.selectedCharacter == GameObject.Find("player1SlotC"))
                        {
                            infoBar.GetComponentInChildren <Text>().text = "Left Player C Selected";
                            if (playerStatus.leftC.moved == false)
                            {
                                moveButton.SetActive(true);
                            }
                            if (playerStatus.leftC.attacked == false)
                            {
                                attackButton.SetActive(true);
                            }
                        }
                    }
                }


                if (hit.collider.name == "player2SlotA")
                {
                    // Melee Mode
                    if (meleeButton.GetComponentInChildren <Text>().text == "Confirm Melee")
                    {
                        meleeingCharacter = "A2";
                        if (playerStatus.AisOK && playerStatus.turn == 0)
                        {
                            infoBar.GetComponentInChildren <Text>().text = "Choosing to melee right team's A player";
                        }
                        else if (!playerStatus.AisOK && playerStatus.turn == 0)
                        {
                            infoBar.GetComponentInChildren <Text>().text = "Player out of range";
                        }
                    }
                    else
                    {
                        currentCharacter = "A2";

                        if (gridScript.selectedCharacter == GameObject.Find("player2SlotA"))
                        {
                            infoBar.GetComponentInChildren <Text>().text = "Right Player A Selected";
                            if (playerStatus.rightA.moved == false)
                            {
                                moveButton.SetActive(true);
                            }
                            if (playerStatus.rightA.attacked == false)
                            {
                                attackButton.SetActive(true);
                            }
                        }
                    }
                }
                if (hit.collider.name == "player2SlotB")
                {
                    // Melee Mode
                    if (meleeButton.GetComponentInChildren <Text>().text == "Confirm Melee")
                    {
                        meleeingCharacter = "B2";
                        if (playerStatus.BisOK && playerStatus.turn == 0)
                        {
                            infoBar.GetComponentInChildren <Text>().text = "Choosing to melee right team's B player";
                        }
                        else if (!playerStatus.BisOK && playerStatus.turn == 0)
                        {
                            infoBar.GetComponentInChildren <Text>().text = "Player out of range";
                        }
                    }
                    else
                    {
                        currentCharacter = "B2";
                    }

                    if (gridScript.selectedCharacter == GameObject.Find("player2SlotB"))
                    {
                        infoBar.GetComponentInChildren <Text>().text = "Right Player B Selected";
                        if (playerStatus.rightB.moved == false)
                        {
                            moveButton.SetActive(true);
                        }
                        if (playerStatus.rightB.attacked == false)
                        {
                            attackButton.SetActive(true);
                        }
                    }
                }
                if (hit.collider.name == "player2SlotC")
                {
                    // Melee Mode
                    if (meleeButton.GetComponentInChildren <Text>().text == "Confirm Melee")
                    {
                        meleeingCharacter = "C2";
                        if (playerStatus.CisOK && playerStatus.turn == 0)
                        {
                            infoBar.GetComponentInChildren <Text>().text = "Choosing to melee right team's C player";
                        }
                        else if (!playerStatus.CisOK && playerStatus.turn == 0)
                        {
                            infoBar.GetComponentInChildren <Text>().text = "Player out of range";
                        }
                    }
                    else
                    {
                        currentCharacter = "C2";

                        if (gridScript.selectedCharacter == GameObject.Find("player2SlotC"))
                        {
                            infoBar.GetComponentInChildren <Text>().text = "Right Player C Selected";
                            if (playerStatus.rightC.moved == false)
                            {
                                moveButton.SetActive(true);
                            }
                            if (playerStatus.rightC.attacked == false)
                            {
                                attackButton.SetActive(true);
                            }
                        }
                    }
                }
            }
            else // clicking away
            {
                infoBar = GameObject.Find("InfoBar");
                if (moveButton.GetComponentInChildren <Text>().text == "Move" && meleeButton.GetComponentInChildren <Text>().text != "Confirm Melee")
                {
                    Debug.Log("clicking away");
                    moveButton.SetActive(false);
                    attackButton.SetActive(false);
                    meleeButton.SetActive(false);
                    infoBar.GetComponentInChildren <Text>().text = "";
                    currentCharacter  = "none";
                    meleeingCharacter = "none";
                }
            }
        }
    }