Пример #1
0
    /// <summary>
    /// Fireball ability
    /// </summary>
    /// <returns>True once fireball has been cast</returns>
    public bool Fireball()
    {
        //If the player is standing on a hex (not falling, jumping)
        if (levelController[q, r, h] != null)
        {
            //Get the area around the current hex
            uiController.ShowValidTopDownRadius(q, r, h, 5, true);
        }

        //Get the cell the player is looking at
        Vector3    lineOfSight = playerCamera.transform.forward * 1000;
        RaycastHit hit;
        UICellObj  hitObj = null;

        if (Physics.Raycast(playerCamera.transform.position, lineOfSight, out hit))
        {
            //Get the UI hex cell the player is looking at
            hitObj = hit.transform.gameObject.GetComponent <UICellObj>() as UICellObj;
        }
        //if it isn't null
        if (hitObj != null)
        {
            //get the selected cell; if it's within 5 units of the starting cell show the ability AoE
            PathCell lookedCell = aiController[hitObj.q, hitObj.r, hitObj.h];
            PathCell startCell  = aiController[q, r, h];

            //if this is in the right range to cast this, it's a valid move.
            if (aiController.DistBetween(lookedCell, startCell) <= 5)
            {
                uiController.ShowValidTopDownRadius(hitObj.q, hitObj.r, hitObj.h, 1, true, TargetingMaterial.TARGETED_ZONE);

                //If the player presses the mouse button
                if (Input.GetMouseButtonUp(0))
                {
                    PathCell targetedCell = aiController[hitObj.q, hitObj.r, hitObj.h];
                    //kill any monsters on the cells you target
                    foreach (Monster m in aiController.monsters)
                    {
                        PathCell monsterLoc = aiController.pathGrid[m.CurrentCell[0], m.CurrentCell[1], m.CurrentCell[2]];
                        if (aiController.DistBetween(targetedCell, monsterLoc) <= 1)
                        {
                            m.gameObject.GetComponent <MonsterStats>().Health -= 9001;
                        }
                    }

                    //now turn the remaining tiles extra crispy
                    PathCell[] surroundingCells = aiController.pathGrid.GetRadius(hitObj.q, hitObj.r, hitObj.h, 1, -1, true);
                    foreach (PathCell cell in surroundingCells)
                    {
                        HexCellData cellData = levelController.levelGrid[cell.q, cell.r, cell.h];
                        cellData.hexCellObject.gameObject.GetComponent <Renderer>().material = this.burntTileMaterial;
                    }

                    actionPoints -= 1;
                    uiController.ClearCells();
                    uiController.setVisibility(false);
                    return(true);
                }
            }
        }

        //Not finished casting
        return(false);
    }
Пример #2
0
    /// <summary>
    /// Update the UI for player movement and item usage
    /// </summary>
    /// <returns>Returns true when movement has happened</returns>
    public bool MovePlayer()
    {
        //Check to see if the player is standing on a hex; if so show all valid moves on the minimap.
        //If the player is standing on a hex (not falling, jumping)
        if (levelController[q, r, h] != null)
        {
            //Get the neighbors of the current hex
            movable = aiController.ReachableInSteps(new int[] { q, r, h }, 2, actionPoints);
            //Give all valid neighbors the neighbor material
            uiController.ShowValidMoves(movable);
            //Give the current hex the current hex material
            uiController[q, r, h].gameObject.GetComponent <Renderer>().material = currenthexmaterial;
        }
        //Non VR Movement
        if (!vrActive)
        {
            //Get the cell the player is looking at
            Vector3    lineOfSight = playerCamera.transform.forward * 1000;
            RaycastHit hit;
            UICellObj  hitObj = null;
            if (Physics.Raycast(playerCamera.transform.position, lineOfSight, out hit))
            {
                //Get the UI hex cell the player is looking at
                hitObj = hit.transform.gameObject.GetComponent <UICellObj>() as UICellObj;
            }
            //if it isn't null
            if (hitObj != null)
            {
                //get the selected cell
                PathCell lookedCell = aiController[hitObj.q, hitObj.r, hitObj.h];
                PathCell startCell  = aiController[q, r, h];

                //loop through all cells we're close enough to reach
                for (int i = 0; i < movable.Count; i++)
                {
                    foreach (PathCell m in movable[i])
                    {
                        if (lookedCell.Equals(m) && !lookedCell.Equals(startCell))
                        {
                            //set the material
                            hitObj.gameObject.GetComponent <Renderer>().material = highlightMaterial;
                            //If the player clicked the mouse
                            if (Input.GetMouseButtonUp(0))
                            {
                                //Move the player
                                transform.parent.transform.position = levelController[hitObj.q, hitObj.r, hitObj.h].centerPos;
                                //If the target has a goal
                                if (levelController[hitObj.q, hitObj.r, hitObj.h].hasGoal)
                                {
                                    //Update the goal
                                    levelController.numOfGoals -= 1;
                                    levelController[hitObj.q, hitObj.r, hitObj.h].goal.GetComponent <Goal>().Accomplished();
                                }
                                //Reduce number of player action points remaining
                                actionPoints -= i + 1;
                                //Clear the UI controller
                                uiController.ClearCells();
                                uiController.setVisibility(false);
                                return(true);
                            }
                        }
                    }
                }
            }
            //VR Specific movement
        }
        else
        {
            if (vrMoveComplete)
            {
                vrMoveComplete = false;
                return(true);
            }
        }
        //Movement not finished
        return(false);
    }
Пример #3
0
    /// <summary>
    /// Fireball ability
    /// </summary>
    /// <returns>True once fireball has been cast</returns>
    public bool Fireball()
    {
        //If the player is standing on a hex (not falling, jumping)
        if (levelController[q, r, h] != null)
        {
            //Get the area around the current hex
            uiController.ShowValidTopDownRadius(q, r, h, 5, true);
        }

        UICellObj hitObj = null;

        //Non VR Movement
        if (!vrActive)
        {
            //Get the cell the player is looking at
            Vector3    lineOfSight = playerCamera.transform.forward * 1000;
            RaycastHit hit;
            if (Physics.Raycast(playerCamera.transform.position, lineOfSight, out hit))
            {
                //Get the UI hex cell the player is looking at
                hitObj = hit.transform.gameObject.GetComponent <UICellObj>() as UICellObj;
            }
            //VR Specific movement
        }
        else
        {
            hitObj = VRHitObj;
        }

        //if it isn't null
        if (hitObj != null)
        {
            //get the selected cell; if it's within 5 units of the starting cell show the ability AoE
            PathCell lookedCell = aiController[hitObj.q, hitObj.r, hitObj.h];
            PathCell startCell  = aiController[q, r, h];

            //False until proven true
            validVRHitObj = false;
            //if this is in the right range to cast this, it's a valid move.
            if (aiController.DistBetween(lookedCell, startCell) <= 5)
            {
                validVRHitObj = true;
                uiController.ShowValidTopDownRadius(hitObj.q, hitObj.r, hitObj.h, 1, true, TargetingMaterial.TARGETED_ZONE);

                //If the player presses the mouse button
                if (Input.GetMouseButtonUp(0) || vrPressUp)
                {
                    //PathCell targetedCell = aiController[hitObj.q, hitObj.r, hitObj.h];
                    HexCellData targetCell = levelController[hitObj.q, hitObj.r, hitObj.h];
                    ////kill any monsters on the cells you target
                    //foreach (Monster m in aiController.monsters) {
                    //    PathCell monsterLoc = aiController.pathGrid[m.CurrentCell[0], m.CurrentCell[1], m.CurrentCell[2]];
                    //    if (aiController.DistBetween(targetedCell, monsterLoc) <= 1) {
                    //        m.gameObject.GetComponent<MonsterStats>().Health -= 50;
                    //    }
                    //}

                    ////now turn the remaining tiles extra crispy
                    //PathCell[] surroundingCells = aiController.pathGrid.GetRadius(hitObj.q, hitObj.r, hitObj.h, 1, -1, true);
                    //foreach (PathCell cell in surroundingCells) {
                    //    HexCellData cellData = levelController.levelGrid[cell.q, cell.r, cell.h];
                    //    cellData.hexCellObject.gameObject.GetComponent<Renderer>().material = this.burntTileMaterial;
                    //}



                    actionPoints -= 1;
                    uiController.ClearCells();
                    uiController.setVisibility(false);
                    currentAction = AbilityEnum.NOT_USING_ABILITIES;

                    //Freeze the turn so that we don't continue past fireball if it's the last action on our turn.
                    levelController.turnFrozen = true;

                    //Make a new fireball
                    GameObject.Instantiate(fireballPrefab, targetCell.hexCellObject.transform.position, Quaternion.identity, targetCell.hexCellObject.transform);
                    return(true);
                }
            }
        }

        //Not finished casting
        return(false);
    }
    void Update()
    {
        if (!controllerInUse || thisControllerInUse)
        {
            if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad))
            {
                Vector2 touchpad = (device.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0));
                controllerInUse     = true;
                thisControllerInUse = true;
                if (player.currentAction == AbilityEnum.NOT_USING_ABILITIES)
                {
                    player.StartMove();
                }
                else
                {
                    //Up
                    if (touchpad.y > edgeThreshold && touchpad.x > -upDownThreshold && touchpad.x < upDownThreshold)
                    {
                        player.StartMove();
                        //Right
                    }
                    else if (touchpad.x > edgeThreshold && touchpad.y < upDownThreshold && touchpad.y > -upDownThreshold)
                    {
                        //Down
                    }
                    else if (touchpad.y < -edgeThreshold && touchpad.x > -upDownThreshold && touchpad.x < upDownThreshold)
                    {
                        player.CancelAction();
                        if (gameObject.GetComponent <LineRenderer> () != null)
                        {
                            Destroy(gameObject.GetComponent <LineRenderer> ());
                        }
                        controllerInUse     = false;
                        thisControllerInUse = false;
                        //Left
                    }
                    else if (touchpad.x < -edgeThreshold && touchpad.y < upDownThreshold && touchpad.y > -upDownThreshold)
                    {
                        player.StartFireball();
                    }
                }
            }

            if (device.GetPressUp(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger) && thisControllerInUse && player.validVRHitObj)
            {
                controllerInUse      = false;
                thisControllerInUse  = false;
                player.vrPressUp     = true;
                player.validVRHitObj = false;
                Debug.Log("Pressed up");
                if (gameObject.GetComponent <LineRenderer> () != null)
                {
                    Destroy(gameObject.GetComponent <LineRenderer> ());
                }
            }

            if (thisControllerInUse)
            {
                switch (player.currentAction)
                {
                case AbilityEnum.MOVE_PLAYER:
                    //draw a line
                    //Get the cell the player is looking at
                    RaycastHit moveHit;
                    if (Physics.Raycast(gameObject.transform.position, new Vector3(0, -1, 0), out moveHit))
                    {
                        //Get the UI hex cell the player is looking at
                        UICellObj hitMoveObj = moveHit.transform.gameObject.GetComponent <UICellObj> () as UICellObj;
                        if (hitMoveObj != null)
                        {
                            player.VRHitObj = hitMoveObj;
                            DrawLine(transform.position, hitMoveObj.gameObject.transform.position);
                        }
                        else
                        {
                            if (gameObject.GetComponent <LineRenderer> () != null)
                            {
                                Destroy(gameObject.GetComponent <LineRenderer> ());
                            }
                        }
                    }
                    break;

                case AbilityEnum.FIREBALL:
                    RaycastHit fireballHit;
                    if (Physics.Raycast(gameObject.transform.position, new Vector3(0, -1, 0), out fireballHit))
                    {
                        //Get the UI hex cell the player is looking at
                        UICellObj hitFireballObj = fireballHit.transform.gameObject.GetComponent <UICellObj> () as UICellObj;
                        if (hitFireballObj != null)
                        {
                            player.VRHitObj = hitFireballObj;
                            DrawLine(transform.position, hitFireballObj.gameObject.transform.position);
                        }
                        else
                        {
                            if (gameObject.GetComponent <LineRenderer> () != null)
                            {
                                Destroy(gameObject.GetComponent <LineRenderer> ());
                            }
                        }
                    }
                    break;

                default:
                    break;
                }
            }
        }
    }
Пример #5
0
    void Update()
    {
        if (device.GetPress(SteamVR_Controller.ButtonMask.Touchpad))
        {
            Vector2 touchpad = (device.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0));
            print(touchpad);
            if (player.currentAction == AbilityEnum.NOT_USING_ABILITIES)
            {
                player.StartMove();
            }
            else
            {
                //Up
                if (touchpad.y > edgeThreshold && touchpad.x > -upDownThreshold && touchpad.x < upDownThreshold)
                {
                    print("UP");
                    player.StartMove();
                    //Right
                }
                else if (touchpad.x > edgeThreshold && touchpad.y < upDownThreshold && touchpad.y > -upDownThreshold)
                {
                    print("RIGHT");
                    //Down
                }
                else if (touchpad.y < -edgeThreshold && touchpad.x > -upDownThreshold && touchpad.x < upDownThreshold)
                {
                    print("DOWN");
                    player.CancelAction();
                    //Left
                }
                else if (touchpad.x < -edgeThreshold && touchpad.y < upDownThreshold && touchpad.y > -upDownThreshold)
                {
                    print("LEFT");
                    player.StartFireball();
                }
            }
        }

        if (device.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger))
        {
            player.vrPressDown = true;
        }

        if (device.GetPressUp(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger))
        {
            player.vrPressUp = true;
        }
        if (device.GetPress(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger))
        {
            print("do something");
            //add arrow/behind back check here
            //if () {
            // player.CancelAction()
            // //equip arrow to hand
            // } else {
            switch (player.currentAction)
            {
            case AbilityEnum.MOVE_PLAYER:
                //draw a line
                //Get the cell the player is looking at
                RaycastHit moveHit;
                if (Physics.Raycast(transform.position, new Vector3(0, -1, 0), out moveHit))
                {
                    //Get the UI hex cell the player is looking at
                    UICellObj hitMoveObj = moveHit.transform.gameObject.GetComponent <UICellObj>() as UICellObj;
                    if (hitMoveObj != null)
                    {
                        player.VRHitObj = hitMoveObj;
                    }
                }
                break;

            case AbilityEnum.FIREBALL:
                RaycastHit fireballHit;
                if (Physics.Raycast(transform.position, new Vector3(0, -1, 0), out fireballHit))
                {
                    //Get the UI hex cell the player is looking at
                    UICellObj hitFireballObj = fireballHit.transform.gameObject.GetComponent <UICellObj>() as UICellObj;
                    if (hitFireballObj != null)
                    {
                        player.VRHitObj = hitFireballObj;
                    }
                }
                break;

            default:
                break;
            }
        }
    }