예제 #1
0
 // Update is called once per frame
 void Update()
 {
     healVal = GetComponent <Interactable>().damage * 3;
     if (healSelected)
     {
         if (Input.GetMouseButtonUp(0))
         {
             coordinate = GetComponent <Interactable>().boardCamMove.coordinate;
             foreach (GameObject unit in healableUnits)
             {
                 UnitTileCheck UTC          = unit.GetComponent <UnitTileCheck>();
                 Interactable  interactable = unit.GetComponent <Interactable>();
                 if (UTC.coordinate == coordinate)
                 {
                     interactable.health = interactable.health + healVal;
                     if (interactable.health > interactable.maxHealth)
                     {
                         interactable.health = interactable.maxHealth;
                     }
                     GetComponent <Interactable>().boardCamMove.turnSwitch();
                 }
             }
             healSelected = false;
         }
     }
 }
예제 #2
0
 // Update is called once per frame
 void Update()
 {
     if (fireBoltSelected)
     {
         if (Input.GetMouseButtonUp(0))
         {
             coordinate = GetComponent <Interactable>().boardCamMove.coordinate;
             foreach (GameObject unit in fireBoltUnits)
             {
                 UnitTileCheck UTC          = unit.GetComponent <UnitTileCheck>();
                 Interactable  interactable = unit.GetComponent <Interactable>();
                 if (UTC.coordinate == coordinate)
                 {
                     BoardCameraMovement.boardTile cTile = null;
                     foreach (BoardCameraMovement.boardTile bTile in interactable.boardCamMove.allTiles)
                     {
                         if (coordinate == bTile.pos)
                         {
                             cTile = bTile;
                             break;
                         }
                     }
                     interactable.health = interactable.health - damage;
                     interactable.boardCamMove.newLogEntry(cTile, "firebolt", unit, gameObject);
                     GetComponent <Interactable>().boardCamMove.turnSwitch();
                 }
                 unit.GetComponent <Interactable>().unitSelected = false;
             }
             fireBoltSelected = false;
         }
     }
 }
예제 #3
0
    void Move()
    {
        units = GameObject.FindGameObjectsWithTag("Unit");
        foreach (GameObject unit in units)
        {
            Interactable  interactable = unit.GetComponent <Interactable>();
            UnitTileCheck tileCheck    = unit.GetComponent <UnitTileCheck>();
            if (interactable.unitSelected)
            {
                faction = interactable.faction;
                int        range = interactable.range;
                Vector3Int coord = tileCheck.coordinate;
                tilesInRange.Add(new Vector3Int(coord.x, coord.y, 0));

                for (int i = 1; i <= range; i++)
                {
                    tempTilesInRange.Clear();
                    foreach (Vector3Int val in tilesInRange)
                    {
                        tempTilesInRange.Add(val);
                    }
                    foreach (Vector3Int tile in tempTilesInRange)
                    {
                        Vector3Int cellPos;
                        cellPos = new Vector3Int(tile.x, tile.y + 1, 0);
                        checkCell(cellPos);
                        if (tile.y % 2 == 1)
                        {
                            cellPos = new Vector3Int(tile.x + 1, tile.y + 1, 0);
                            checkCell(cellPos);
                            cellPos = new Vector3Int(tile.x + 1, tile.y - 1, 0);
                            checkCell(cellPos);
                        }
                        else if (tile.y % 2 == 0)
                        {
                            cellPos = new Vector3Int(tile.x - 1, tile.y + 1, 0);
                            checkCell(cellPos);
                            cellPos = new Vector3Int(tile.x - 1, tile.y - 1, 0);
                            checkCell(cellPos);
                        }
                        cellPos = new Vector3Int(tile.x + 1, tile.y, 0);
                        checkCell(cellPos);
                        cellPos = new Vector3Int(tile.x, tile.y - 1, 0);
                        checkCell(cellPos);
                        cellPos = new Vector3Int(tile.x - 1, tile.y, 0);
                        checkCell(cellPos);
                    }
                }
                tilesInRange.RemoveAt(0);
                foreach (Vector3Int tile in tilesInRange)
                {
                    board.SetTile(tile, rangeTile);
                }
                interactable.tileRange    = tilesInRange;
                interactable.prevState    = prevState;
                interactable.moveSelected = true;
                deselectUnits();
            }
        }
    }
예제 #4
0
    public List <Vector3Int> findPossibleMoves()
    {
        tilesInRange.Clear();
        UnitTileCheck tileCheck = GetComponent <UnitTileCheck>();

        //Vector3Int coord = tileCheck.coordinate;
        coord = currentTile.pos;

        tilesInRange.Add(new Vector3Int(coord.x, coord.y, 0));
        for (int i = 1; i <= range; i++)
        {
            tempTilesInRange.Clear();
            foreach (Vector3Int val in tilesInRange)
            {
                tempTilesInRange.Add(val);
            }
            foreach (Vector3Int tile in tempTilesInRange)
            {
                Vector3Int cellPos;
                cellPos = new Vector3Int(tile.x, tile.y + 1, 0);
                CheckCell(cellPos);
                if (tile.y % 2 == 1)
                {
                    cellPos = new Vector3Int(tile.x + 1, tile.y + 1, 0);
                    CheckCell(cellPos);
                    cellPos = new Vector3Int(tile.x + 1, tile.y - 1, 0);
                    CheckCell(cellPos);
                }
                else if (tile.y % 2 == 0)
                {
                    cellPos = new Vector3Int(tile.x - 1, tile.y + 1, 0);
                    CheckCell(cellPos);
                    cellPos = new Vector3Int(tile.x - 1, tile.y - 1, 0);
                    CheckCell(cellPos);
                }
                cellPos = new Vector3Int(tile.x + 1, tile.y, 0);
                CheckCell(cellPos);
                cellPos = new Vector3Int(tile.x, tile.y - 1, 0);
                CheckCell(cellPos);
                cellPos = new Vector3Int(tile.x - 1, tile.y, 0);
                CheckCell(cellPos);
            }
        }
        tilesInRange.RemoveAt(0);
        return(tilesInRange);
    }
예제 #5
0
 // Update is called once per frame
 void Update()
 {
     if (poisonSelected)
     {
         if (Input.GetMouseButtonUp(0))
         {
             coordinate = GetComponent <Interactable>().boardCamMove.coordinate;
             foreach (GameObject unit in poisonUnits)
             {
                 UnitTileCheck UTC          = unit.GetComponent <UnitTileCheck>();
                 Interactable  interactable = unit.GetComponent <Interactable>();
                 if (UTC.coordinate == coordinate)
                 {
                     interactable.maxHealth = interactable.maxHealth - ((interactable.maxHealth / 100) * 20);
                     interactable.poisoned  = true;
                     interactable.tileBuffCheck(interactable.coord);
                     GetComponent <Interactable>().boardCamMove.turnSwitch();
                 }
                 unit.GetComponent <Interactable>().unitSelected = false;
             }
             poisonSelected = false;
         }
     }
 }
예제 #6
0
    void Update()
    {
        if (health > maxHealth)
        {
            health = maxHealth;
        }
        if (health <= 0)
        {
            print(":(");
            switch (faction)
            {
            case "wizard":
                boardCamMove.wizardUnits.Remove(gameObject);
                boardCamMove.blockedTiles.Remove(coord);
                break;

            case "alien":
                boardCamMove.alienUnits.Remove(gameObject);
                boardCamMove.blockedTiles.Remove(coord);
                break;

            case "robot":
                boardCamMove.robotUnits.Remove(gameObject);
                boardCamMove.blockedTiles.Remove(coord);
                break;
            }
            Destroy(gameObject);
        }
        if (moveSelected)
        {
            coordinate = boardCamMove.coordinate;
            if (Input.GetMouseButtonUp(0))
            {
                UnitTileCheck UTC      = GetComponent <UnitTileCheck>();
                Vector3Int    newCoord = new Vector3Int(coordinate.x, coordinate.y, 0); //Gets coordinate of mouse position
                if (tileRange.Contains(newCoord))
                {
                    Vector3Int prevCoord = coord;
                    coord = new Vector3Int(UTC.coordinate.x, UTC.coordinate.y, 0);
                    transform.position = grid.CellToWorld(coordinate);
                    tilePrev();
                    tileBuffCheck(newCoord);
                    if (boardCamMove.blockedTiles.Contains(newCoord))
                    {
                        StaticDataScript.noFight          = false;
                        StaticDataScript.fighterNum       = 0;
                        StaticDataScript.winHealth        = 0;
                        StaticDataScript.coord            = coord;
                        StaticDataScript.player1          = gameObject.name;
                        StaticDataScript.player1Health    = health;
                        StaticDataScript.player1MaxHealth = maxHealth;
                        StaticDataScript.player1Faction   = faction;
                        StaticDataScript.player1Damage    = damage;
                        StaticDataScript.player1Colour    = colour;
                        fighterNum = 1;
                        //units = GameObject.FindGameObjectsWithTag("Unit");
                        foreach (GameObject unit in units)
                        {
                            Vector3Int enemyCoord = unit.GetComponent <UnitTileCheck>().coordinate;
                            if (newCoord == new Vector3Int(enemyCoord.x, enemyCoord.y, 0))
                            {
                                Interactable interactable = unit.GetComponent <Interactable>();
                                StaticDataScript.player2          = unit.gameObject.name;
                                StaticDataScript.player2Health    = interactable.health;
                                StaticDataScript.player2MaxHealth = interactable.maxHealth;
                                StaticDataScript.player2Faction   = interactable.faction;
                                StaticDataScript.player2Damage    = interactable.damage;
                                StaticDataScript.player2Colour    = interactable.colour;
                                interactable.fighterNum           = 2;
                            }
                        }
                        StaticDataScript.coord = newCoord;
                        fightStarted           = true;
                    }
                    boardCamMove.blockedTiles.Remove(new Vector3Int(coord.x, coord.y, 0));
                    boardCamMove.blockedTiles.Add(newCoord);
                    coord   = grid.WorldToCell(transform.position);
                    coord.z = 0;
                    foreach (BoardCameraMovement.boardTile bTile in boardCamMove.allTiles)
                    {
                        if (bTile.pos == coord)
                        {
                            foreach (BoardCameraMovement.boardTile bTile2 in boardCamMove.allTiles)
                            {
                                if (bTile2.pos == prevCoord)
                                {
                                    bTile2.inhabitant = null;
                                    break;
                                }
                            }
                            currentTile      = bTile;
                            bTile.inhabitant = gameObject;
                            break;
                        }
                    }
                    if (!fightStarted)
                    {
                        boardCamMove.turnSwitch();
                    }
                    boardCamMove.newLogEntry(currentTile, "movement", gameObject, null);
                }
                else
                {
                    print("cannot move to this tile");
                }
                moveSelected = false;
                tilePrev();
            }
        }
        healthPercentage = Mathf.Ceil((health / maxHealth) * 100);
        if (fightStarted)
        {
            SceneManager.SetActiveScene(SceneManager.GetSceneByName("Arena"));
            fightStarted = false;
        }
    }