Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        MainCameraController controller = Camera.main.GetComponent <MainCameraController> ();

        controller.SendMessage("PlayerSpawned", this.gameObject);

        body = GetComponent <Rigidbody2D> ();
        Manager.ObjectLog.Add(gameObject, this);
        GrapplingState = E_GrapplingState.Detached;
        InvokeRepeating("MapCheck", 0f, 0.5f);
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (!showboss)
        {
            if (showBossTime >= 3.0f)
            {
                //if(Input.GetMouseButton(0)){
                MainCamera.SendMessage("Warning");
                showboss = true;
            }
        }
        if (shieldEffect)
        {
            shieldEffect.transform.position = this.transform.position;
            shieldTime += Time.deltaTime;
            if (shieldTime >= 4.5f)
            {
                Destroy(shieldEffect);
                shieldTime            = 0;
                this.gameObject.layer = 8;
            }
        }



        if (isLocalPlayer)
        {
            if (this.transform.position.y <= groundY)
            {
                grounded = true;
                if (!dead)
                {
                    runningEffect.SetActive(true);
                }
                else
                {
                    runningEffect.SetActive(false);
                }
                animator.SetBool("grounded", true);
                animator.SetBool("SideJump", false);
                animator.SetBool("Jump_b", false);
            }
            else
            {
                grounded = false;
                animator.SetBool("grounded", false);
                runningEffect.SetActive(false);
            }

            if (moveLeft)
            {
                this.transform.position = new Vector3(this.transform.position.x - Time.deltaTime * 5.0f, this.transform.position.y, this.transform.position.z);
                if (this.transform.position.x <= (moveStartX - 3))
                {
                    moveLeft   = false;
                    moveStartX = this.transform.position.x;
                }
            }
            if (moveRight)
            {
                this.transform.position = new Vector3(this.transform.position.x + Time.deltaTime * 5.0f, this.transform.position.y, this.transform.position.z);
                if (this.transform.position.x >= (moveStartX + 3))
                {
                    moveRight  = false;
                    moveStartX = this.transform.position.x;
                }
            }

            //生成桥
            if (this.transform.position.z >= (spawnZ + tube_length * 1.5f))
            {
                spawnZ += tube_length;
                if (tubes [0] && tubes [1] && tubes [2])
                {
                    tubes [3] = tubes [0];
                    tubes [3].transform.localPosition = new Vector3(tubes [3].transform.localPosition.x, tubes [3].transform.localPosition.y, tubes [3].transform.localPosition.z + tubeMovedis);
                    tubes [0] = null;
                    if (nowmoveSpeed <= maxmoveSpeed)
                    {
                        nowmoveSpeed += 2.0f;
                    }
                }
                else if (tubes [1] && tubes [2] && tubes [3])
                {
                    tubes [0] = tubes [1];
                    tubes [0].transform.localPosition = new Vector3(tubes [0].transform.localPosition.x, tubes [0].transform.localPosition.y, tubes [0].transform.localPosition.z + tubeMovedis);
                    tubes [1] = null;
                }
                else if (tubes [2] && tubes [3] && tubes [0])
                {
                    tubes [1] = tubes [2];
                    tubes [1].transform.localPosition = new Vector3(tubes [1].transform.localPosition.x, tubes [1].transform.localPosition.y, tubes [1].transform.localPosition.z + tubeMovedis);
                    tubes [2] = null;
                    if (nowmoveSpeed <= maxmoveSpeed)
                    {
                        nowmoveSpeed += 1.0f;
                    }
                }
                else if (tubes [3] && tubes [0] && tubes [1])
                {
                    tubes [2] = tubes [3];
                    tubes [2].transform.localPosition = new Vector3(tubes [2].transform.localPosition.x, tubes [2].transform.localPosition.y, tubes [2].transform.localPosition.z + tubeMovedis);
                    tubes [3] = null;
                }
            }
            if (Input.GetKey(KeyCode.Space))
            {
                if (grounded)
                {
                    animator.SetBool("Jump_b", true);
                    this.rigi.AddForce(new Vector3(0, 250.0f, 0.0f));
                }
            }
            //向左向右跳以及boss和障碍物
            //animator.SetBool ("SideJump", true);
            //this.transform.Translate(new Vector3(this.transform.position+3
            if (Input.GetKey(KeyCode.A))
            {
                if (grounded)
                {
                    animator.SetBool("SideJump", true);
                    if (xPos == 0)
                    {
                        this.rigi.AddForce(new Vector3(0, 150.0f, 0));
                        //this.rigi.MovePosition (new Vector3 (this.transform.position.x + 3.0f, this.transform.position.y, this.transform.position.z));
                    }
                    else
                    {
                        xPos--;
                        this.rigi.AddForce(new Vector3(0f, 150.0f, 0));
                        moveLeft   = true;
                        moveStartX = this.transform.position.x;
                        //this.rigi.MovePosition (new Vector3 (this.transform.position.x - 3.0f, this.transform.position.y, this.transform.position.z));
                    }
                }
            }
            if (Input.GetKey(KeyCode.D))
            {
                if (grounded)
                {
                    animator.SetBool("SideJump", true);
                    if (xPos == 2)
                    {
                        this.rigi.AddForce(new Vector3(0, 250.0f, 0));
                        //this.rigi.MovePosition (new Vector3 (this.transform.position.x + 3.0f, this.transform.position.y, this.transform.position.z));
                    }
                    else
                    {
                        this.rigi.AddForce(new Vector3(0, 250.0f, 0));
                        xPos++;
                        moveRight  = true;
                        moveStartX = this.transform.position.x;
                        //this.rigi.MovePosition (new Vector3 (this.transform.position.x + 3.0f, this.transform.position.y, this.transform.position.z));
                    }
                }
            }
            if (grounded)
            {
                if (Input.touchCount > 0)
                {
                    if (Input.GetTouch(0).phase == TouchPhase.Began)
                    {
                        startPos = Input.GetTouch(0).position;
                    }
                    if (Input.GetTouch(0).phase == TouchPhase.Ended)
                    {
                        xDis = Input.GetTouch(0).position.x - startPos.x;
                        yDis = Input.GetTouch(0).position.y - startPos.y;

                        if (xDis > 0)
                        {
                            if (Mathf.Abs(yDis) > xDis)
                            {
                                if (yDis > 0)
                                {
                                    //this.transform.position = new Vector3 (this.transform.position.x, this.transform.position.y+3, this.transform.position.z);
                                    animator.SetBool("Jump_b", true);
                                    this.rigi.AddForce(new Vector3(0, 250.0f, 0.0f));
                                }
                                else if (yDis <= 0)
                                {
                                    //this.transform.position = new Vector3 (this.transform.position.x, this.transform.position.y-3, this.transform.position.z);
                                }
                            }
                            else
                            {
                                //this.transform.position = new Vector3 (this.transform.position.x+3, this.transform.position.y, this.transform.position.z);
                                animator.SetBool("SideJump", true);
                                if (xPos == 2)
                                {
                                    if (!reverse)
                                    {
                                        this.rigi.AddForce(new Vector3(0, 150.0f, 0));
                                    }
                                    else
                                    {
                                        xPos--;
                                        moveLeft   = true;
                                        moveStartX = this.transform.position.x;
                                    }
                                    //this.rigi.MovePosition (new Vector3 (this.transform.position.x + 3.0f, this.transform.position.y, this.transform.position.z));
                                }
                                else
                                {
                                    this.rigi.AddForce(new Vector3(0, 150.0f, 0));
                                    if (reverse)
                                    {
                                        if (xPos != 0)
                                        {
                                            xPos--;
                                            moveLeft   = true;
                                            moveStartX = this.transform.position.x;
                                        }
                                    }
                                    else
                                    {
                                        xPos++;
                                        moveRight  = true;
                                        moveStartX = this.transform.position.x;
                                    }
                                    //this.rigi.MovePosition (new Vector3 (this.transform.position.x + 3.0f, this.transform.position.y, this.transform.position.z));
                                }
                            }
                        }
                        else if (xDis <= 0)
                        {
                            if (Mathf.Abs(xDis) > Mathf.Abs(yDis))
                            {
                                //this.transform.position = new Vector3 (this.transform.position.x-3, this.transform.position.y, this.transform.position.z);
                                animator.SetBool("SideJump", true);
                                if (xPos == 0)
                                {
                                    if (!reverse)
                                    {
                                        this.rigi.AddForce(new Vector3(0, 150.0f, 0));
                                    }
                                    else
                                    {
                                        xPos++;
                                        moveRight  = true;
                                        moveStartX = this.transform.position.x;
                                    }
                                    //this.rigi.MovePosition (new Vector3 (this.transform.position.x + 3.0f, this.transform.position.y, this.transform.position.z));
                                }
                                else
                                {
                                    this.rigi.AddForce(new Vector3(0f, 150.0f, 0));
                                    if (reverse)
                                    {
                                        if (xPos != 2)
                                        {
                                            xPos++;
                                            moveRight  = true;
                                            moveStartX = this.transform.position.x;
                                        }
                                    }
                                    else
                                    {
                                        xPos--;
                                        moveLeft   = true;
                                        moveStartX = this.transform.position.x;
                                    }
                                    //this.rigi.MovePosition (new Vector3 (this.transform.position.x - 3.0f, this.transform.position.y, this.transform.position.z));
                                }
                            }
                            else
                            {
                                if (yDis > 0)
                                {
                                    //this.transform.position = new Vector3 (this.transform.position.x, this.transform.position.y+3, this.transform.position.z);
                                    animator.SetBool("Jump_b", true);
                                    this.rigi.AddForce(new Vector3(0, 250.0f, 0.0f));
                                }
                                else if (yDis <= 0)
                                {
                                    //this.transform.position = new Vector3 (this.transform.position.x, this.transform.position.y-3, this.transform.position.z);
                                }
                            }
                        }
                    }
                }
            }

            if (gameStart)
            {
                showBossTime           += Time.deltaTime;
                this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z + Time.deltaTime * nowmoveSpeed);
            }
        }
    }