Пример #1
0
    public virtual void move(UnityStandardAssets._2D.PlayerInput.Input input)
    {
        if (input.fireDown || input.fireHold)
        {
            useWeapon();
        }
        if (specialCheck(input.specialDown, input.specialHold))
        {
            useSpecial();
        }

        gameObject.transform.position += new Vector3(input.horizontal * speed * Time.fixedDeltaTime, input.vertical * speed * Time.fixedDeltaTime);
    }
Пример #2
0
        //Takes input from PlayerInput to handle all player actions
        public void Move(PlayerInput.Input input)
        {
            facing = input.lastDirection;
            TileScript currentTile = LevelManager.Instance.Tiles[location];

            //These are used to throttle their associated actions
            moveCounter += Time.deltaTime;
            fireCounter += Time.deltaTime;

            //These are used as a required channel time for their associated actions
            reloadCounter += Time.deltaTime;
            if (!input.sellHold)
            {
                sellCounter = 0;
            }
            if (!input.interactHold)
            {
                interactCounter = 0;
            }

            //Automatically reload weapon if not in use for a certain period or if clip is empty
            if (reloadCounter > reloadTime)
            {
                int missingAmmo = clipSize - ammoInClip;

                //If there's enough ammo left to reload the entire clip, do so
                if (ammo - missingAmmo > 0)
                {
                    ammo       -= missingAmmo;
                    ammoInClip += missingAmmo;
                }
                //Otherwise, just reload bullets equal to the remaining ammo
                else
                {
                    ammoInClip += ammo;
                    ammo        = 0;
                }
            }

            //If the player is selecting something from a menu
            if (selecting)
            {
                //If the player cancels the tower selection menu
                if (input.cancelDown)
                {
                    selecting = false;
                    LevelManager.Instance.TowerMenu [playerNumber - 1].SetActive(false);
                }
                //If the player releases the build button, begin building the last selected tower
                else if (input.buildUpgradeUp)
                {
                    working   = true;
                    selecting = false;
                    LevelManager.Instance.TowerMenu [playerNumber - 1].SetActive(false);
                }
                //Otherwise, the player can alter the selected tower with movement keys
                else
                {
                    if (input.upHold && !input.prevUpHold)
                    {
                        selectedOption -= optionsPerRow;
                    }                        //Move up one row
                    else if (input.downHold && !input.prevDownHold)
                    {
                        selectedOption += optionsPerRow;
                    }                        //Move down one row
                    else if (input.rightHold && !input.prevRightHold)
                    {
                        selectedOption++;
                    }                                       //Move right one space
                    else if (input.leftHold && !input.prevLeftHold)
                    {
                        selectedOption--;
                    }                                       //Move left one space
                    //All actions that can alter the selected option wrap back around
                    if (selectedOption >= towerPanel.numOptions())
                    {
                        selectedOption %= towerPanel.numOptions();
                    }
                    while (selectedOption < 0)
                    {
                        selectedOption += towerPanel.numOptions();
                    }
                    LevelManager.Instance.Tiles[location].setCurrentTile(playerNumber);
                    towerPanel.menuSelection(selectedOption);
                }
            }
            //If the player is in the process of building something
            else if (working)
            {
                int towerCost = towerPanel.Towers[selectedOption].Gold;
                if (towerCost <= gold)
                {
                    buildUpgradeCounter += Time.deltaTime;
                    transform.Rotate(new Vector3(0, 0, 90)); //temporary "working" animation

                    //If the player cancels the build command
                    if (input.cancelDown)
                    {
                        buildUpgradeCounter = 0;
                        working             = false;
                        moveSprite(location);//temporary to correct facing after random rotation
                    }
                    //If the build command completes
                    else if (buildUpgradeCounter >= buildUpgradeTime)
                    {
                        //build the selected tower on this line
                        buildUpgradeCounter = 0;
                        working             = false;
                        moveSprite(location);//temporary to correct facing after random rotation

                        towerPanel.handleSelection(playerNumber);
                        LevelManager.Instance.Tiles[location].PlaceTower(playerNumber);
                    }
                }
                else
                {
                    buildUpgradeCounter = 0;
                    working             = false;
                }
            }
            else if (operatingHook && !input.interactDown)
            {
                print("toggle operating hook");
                HookScript hs = currentTile.GetComponentInChildren <HookScript> ();
                hs.SetPilot(this);
                if (input.downHold)
                {
                    hs.MoveHookCounterClockwise();
                }
                else if (input.upHold)
                {
                    hs.MoveHookClockwise();
                }
                else if (input.leftHold)
                {
                    hs.LaunchHook();
                }
            }
            //If the player starts building something
            else if (input.buildUpgradeDown)
            {
                //Can only build on walls
                if (currentTile.Type == "wall")
                {
                    selecting = true;
                    //selectedOption = 0; //(uncomment this line if saving past selection is undesired)
                    //Build tower if there's no tower at location (open tower selection menu)
                    if (!currentTile.IsTower)
                    {
                        //Debug.Log(LevelManager.Instance.TowerMenu[playerNumber - 1]);
                        LevelManager.Instance.TowerMenu[playerNumber - 1].GetComponent <RectTransform>().transform.position = transform.position;
                        LevelManager.Instance.TowerMenu[playerNumber - 1].SetActive(true);

                        //currentTile.TowerMenu(transform.position);
                    }
                    //Upgrade tower if there is a tower at location (open tower upgrade selection menu)
                    else
                    {
                    }
                }
            }
            //If the player is selling something
            else if (input.sellHold)
            {
                //Sell tower if there is a tower at location
                if (currentTile.IsTower)
                {
                    transform.Rotate(new Vector3(0, 0, 90));//temporary "working" animation
                    sellCounter += Time.deltaTime;
                    if (sellCounter > sellTime)
                    {
                        sellCounter = 0;
                        //sell the tower on this line
                        moveSprite(location);//temporary to correct facing after random rotation
                    }
                }
            }
            //If the player is interacting with something
            else if (input.interactDown)
            {
                //TileScript next = LevelManager.Instance.Tiles[getNextPoint(facing)];
                //Interact with something if facing an object that can be interacted with
                if (currentTile.Type == "hook")
                {
                    operatingHook = operatingHook ? false : true;
                }
            }
            else
            {
                //If the player is firing their weapon (weapons are fully automatic)
                if (input.fireDown || input.fireHold)
                {
                    //Fire weapon in facing direction if there is ammo left in the clip
                    if (ammoInClip > 0 && fireCounter > fireCooldown)
                    {
                        ammoInClip--;
                        fireCounter   = 0;
                        reloadCounter = 0;
                        //fire bullet on this line
                        GameObject bullet = Instantiate(tower_projectile, transform.position, transform.rotation) as GameObject;
                        bullet.GetComponent <Rigidbody2D>().velocity = facing * projectileSpeed;
                        AudioSource.PlayClipAtPoint(pew, transform.position);
                    }
                }
                //If the player is moving (can move anywhere except water)
                if (moveCounter > moveCooldown)
                {
                    if (input.upHold || input.downHold || input.leftHold || input.rightHold)
                    {
                        moveInDirection(facing);
                        moveCounter = 0;
                    }
                }
            }

            /// Ammo reload section
            if (currentTile.Type == "room")
            {
                currentTile.updateUsables(playerNumber);
            }
        }