예제 #1
0
    void OnCollisionStay(Collision col)
    {
        //player attacks override enemy attacks
        if (col.gameObject.tag == "Enemy" && cSlice.getState() != CombatSlice.combatState.ATTACK)
        {
            FollowTest lame = col.gameObject.GetComponent <FollowTest>();
            Debug.Log(lame.ToString());
            CombatSlice cs = lame.getSlice();

            //...but not if the enemy attacked first
            if (cs.getState() == CombatSlice.combatState.ATTACK)
            {
                EntityStats es  = col.gameObject.GetComponent <FollowTest>().stats;
                float       esa = es.attack * 4;
                cSlice.damage(esa, es);
            }
        }
    }
예제 #2
0
    //TODO rework to use the combatSlice
    private void handleInput()
    {
        //get controller state
        controllerState.x  = gamepad.Move_X();
        controllerState.y  = gamepad.Move_Y();
        controllerStateR.x = gamepad.Aim_X();
        controllerStateR.y = gamepad.Aim_Y();

        //get keyboard state
        bool attacking = false;

        if (Input.GetKey(KeyCode.W))
        {
            controllerState.y = 1;
        }
        if (Input.GetKey(KeyCode.A))
        {
            controllerState.x = -1;
        }
        if (Input.GetKey(KeyCode.S))
        {
            controllerState.y = -1;
        }
        if (Input.GetKey(KeyCode.D))
        {
            controllerState.x = 1;
        }
        if (Input.GetKey(KeyCode.Space))
        {
            cSlice.attack();
        }
        //attacking = true; } //anim.SetBool("Attack", true); }
        if (Input.GetKey(KeyCode.UpArrow))
        {
            controllerStateR.y = 1;
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            controllerStateR.y = -1;
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            controllerStateR.x = 1;
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            controllerStateR.x = -1;
        }

        controllerState.Normalize();         //make sure our vectors don't get larger than 1
        controllerStateR.Normalize();

        //Handle Right Stick Input
        if (controllerStateR.x > 0.2 || controllerStateR.x < -0.2 || controllerStateR.y > 0.2 || controllerStateR.y < -0.2)
        {
            //need to edit the y rotation some ammount.
            Vector3 controllerStateR2 = new Vector3(controllerStateR.x, 0, controllerStateR.y);
            this.transform.LookAt(controllerStateR2 + this.transform.position, Vector3.up);
            oldControllerStateR = controllerStateR;
        }
        else
        {
            controllerStateR = oldControllerStateR;
        }

        //Handle Left Stick Input
        if (controllerState.x > 0.2 || controllerState.x < -0.2 || controllerState.y > 0.2 || controllerState.y < -0.2)
        {
            float   stickAngle = Vector2.Angle(controllerState, controllerStateR);
            Vector3 cross      = Vector3.Cross(controllerState, controllerStateR);
            if (cross.z < 0)
            {
                stickAngle = -stickAngle;
            }
            if (stickAngle >= -90 && stickAngle <= 90)
            {
                anim.SetBool("WalkForward", true);
                anim.SetBool("WalkBack", false);
                anim.SetFloat("Angle", stickAngle);
            }
            else
            {
                anim.SetBool("WalkForward", false);
                anim.SetBool("WalkBack", true);
                if (stickAngle < 0)
                {
                    anim.SetFloat("Angle", -1 * (180 + stickAngle));
                }
                else
                {
                    anim.SetFloat("Angle", 180 - stickAngle);
                }
            }
            //below is the code that transforms the player if they are moving
            if (stats.topSpeed > stats.currentSpeed)
            {
                stats.currentSpeed = stats.currentSpeed + stats.acceleration;
                if (stats.currentSpeed > stats.topSpeed)
                {
                    stats.currentSpeed = stats.topSpeed;
                }
            }
        }
        else
        {
            //goto idle animation
            anim.SetBool("WalkForward", false);
            anim.SetBool("WalkBack", false);
            anim.SetFloat("Angle", 0);
            //reduce speed if left sitck isnt used
            if (stats.currentSpeed > 0)
            {
                stats.currentSpeed = stats.currentSpeed - stats.acceleration;
                if (stats.currentSpeed < 0)
                {
                    stats.currentSpeed = 0;
                }
            }
        }

        //Vector3 tempPos = this.transform.position + new Vector3(stats.currentSpeed * controllerState.x * Time.deltaTime, 0, stats.currentSpeed * controllerState.y * Time.deltaTime);
        Vector3 tempPos = this.transform.position;

        if (stats.canMove = true)
        {
            this.gameObject.GetComponent <Rigidbody> ().AddForce(new Vector3(stats.currentSpeed * controllerState.x * Time.deltaTime, 0, stats.currentSpeed * controllerState.y * Time.deltaTime) * 1000f);
        }
        if (tempPos.x < 1)
        {
            tempPos.x = 1;
        }
        else if (tempPos.x > 68)
        {
            tempPos.x = 68;
        }

        if (tempPos.z < 1)
        {
            tempPos.z = 1;
        }
        else if (tempPos.z > 68)
        {
            tempPos.z = 68;
        }

        this.transform.position = tempPos;

        /*
         *      //Move the player
         *      anim.SetFloat("Speed", controllerState.y);
         *      anim.SetFloat("Direction", controllerState.x);
         */

        /*
         *      //Handle turning
         *      float rStickX = gamepad.Aim_X();
         *      if(controllerState.x > 0.3){
         *              //anim.SetFloat("Turn", rStickX, turnSpeed, Time.deltaTime);
         *              this.transform.Rotate(Vector3.up * (Time.deltaTime + 5), Space.World);
         *      }
         *      else if (controllerState.x < -0.3){
         *              //anim.SetFloat("Turn", rStickX, turnSpeed, Time.deltaTime);
         *              this.transform.Rotate(Vector3.up * (Time.deltaTime + -5), Space.World);
         *      }
         */

        //Set rotation
        playerCamera.transform.position = new Vector3(transform.position.x, cameraHeight, transform.position.z - 2);
        playerCamera.transform.LookAt(transform.position);

        //TODO Combat controls
        if (gamepad.R2() > 0.1f || attacking)
        {
            //turns attacking to true if R2 is being pressed and there was no attack currently happening
            cSlice.attack();
        }
        if (gamepad.L1())
        {
            if (stats.resources > 1000)
            {
                GameObject turr = Instantiate(turrit, new Vector3(this.transform.position.x, 5, this.transform.position.z), this.transform.rotation) as GameObject;
                turr.GetComponent <FlyingTurret>().init(playerID);
                stats.resources -= 1000;
            }
            else
            {
                Debug.Log("not enough resources to spawn a turret!!!!!!");
            }
        }
        if (gamepad.R1())
        {
            if (shooting)
            {
                return;
            }
            shooting = true;
            if (stats.resources > 100 && cSlice.getState() == CombatSlice.combatState.NORMAL)
            {
                stats.resources -= 100;
                hud.updateResourceText();
                Debug.Log("shooting for player " + playerID);
                cSlice.shoot(projectile, this.gameObject.transform.position, this.gameObject.transform.forward, this.gameObject.transform.rotation, false);                     //shoot something
            }
            else
            {
                Debug.Log("100 resources needed to shoot.");
            }
            shooting = false;
        }
        if (gamepad.L2() > 0.1f)
        {
            Debug.Log("L2");
            cSlice.parry();
        }
    }