Esempio n. 1
0
 // Update is called once per frame
 void Update()
 {
     if (IsDown)
     {
         Globals.isXNBtn = true;
         if (dx < 156)
         {
             playerObj.RunLeft(-moveNums);
             btnImg.transform.position = new Vector2(chushi.x - 10, chushi.y);
         }
         else if (dx > 190)
         {
             playerObj.RunRight(moveNums);
             btnImg.transform.position = new Vector2(chushi.x + 10, chushi.y);
         }
         else
         {
             btnImg.transform.position = chushi;
         }
     }
     else
     {
         Globals.isXNBtn = false;
         //playerObj.ReSetLR();
     }
 }
Esempio n. 2
0
 //3 靠近 达到攻击距离
 bool NearRoleInDistance(float distance)
 {
     if (gameObj.transform.position.x - transform.position.x > distance)
     {
         //目标在右
         gameBody.RunRight(0.9f);
         return(false);
     }
     else if (gameObj.transform.position.x - transform.position.x < -distance)
     {
         //目标在左
         gameBody.RunLeft(-0.9f);
         return(false);
     }
     else
     {
         //print(gameBody.GetDB().animation.lastAnimationName);
         //进入范围
         //gameBody.GetAtk();
         return(true);
     }
 }
Esempio n. 3
0
    void startRunToTarget()
    {
        //被攻击 中断
        if (GetComponent <RoleDate>().isDie || GetComponent <RoleDate>().isBeHiting)
        {
            ReSetAll();
            return;
        }

        //判断 前面如果撞墙 就结束
        if (_gameBody.IsHitWall)
        {
            print("-------------------------------------------  冲刺撞墙 ");
            ReSetAll();
            return;
        }


        if (IsHasQSAC && !_isQiShiAcOver)
        {
            //print("进来没?????   " + QishiACName+"  shifouhanyouAC  "+);
            //起始动作做完
            if (_gameBody.GetDB().animation.lastAnimationName != QishiACName)
            {
                //_player.GetComponent<GameBody>().GetDB().animation.GotoAndPlayByFrame(QishiACName);
                //print("?????????????进来没??");
                _gameBody.GetAcMsg(QishiACName);
            }
            else
            {
                //print("------->> 1");
                if (_gameBody.GetDB().animation.isCompleted)
                {
                    _isQiShiAcOver = true;
                }
            }
            return;
        }



        //下压的力 放置 角色飞起来了
        //_gameBody.GetPlayerRigidbody2D().AddForce(new Vector2(0, -20));
        _gameBody.GetZongTuili(new Vector2(0, -20));

        if (runDirection == "right")
        {
            _gameBody.RunRight(3f);
        }
        else
        {
            _gameBody.RunLeft(-3f);
        }
        if (Mathf.Abs(this.transform.position.x - _positionX) >= Distances)
        {
            ReSetAll();
        }


        if (!IsShowTXAndHitKuai && _isStarting)
        {
            //print("  速度是多少: "+_gameBody.GetPlayerRigidbody2D().velocity.x);
            if (Mathf.Abs(_gameBody.GetPlayerRigidbody2D().velocity.x) < 3)
            {
                return;
            }
            IsShowTXAndHitKuai = true;
            //print("_gameBody.GetDB().animation.lastAnimationName   " + _gameBody.GetDB().animation.lastAnimationName);
            HitKuai.SetActive(true);
            //HitKuai.transform.position = this.transform.position;
            ShowTX();
        }
        if (HitKuai)
        {
            //hitkuai跟随 特效的位置  后面也可以加一个参照点 跟随参照点
            HitKuai.transform.position = Lizi.transform.position;
        }
    }
Esempio n. 4
0
    private void Move()
    {
        if (this.transform.position.x > _player.transform.position.x && this.transform.localScale.x == -1)
        {
            //玩家 在我左边  左转向
            _ZhuangxiangJishi += Time.deltaTime;
            if (_ZhuangxiangJishi >= _ZhuanxiangTimes)
            {
                _ZhuangxiangJishi = 0;
                isRunLeft         = true;
                isRunRight        = false;
            }
        }
        else if (this.transform.position.x < _player.transform.position.x && this.transform.localScale.x == 1)
        {
            //右转向
            _ZhuangxiangJishi += Time.deltaTime;
            if (_ZhuangxiangJishi >= _ZhuanxiangTimes)
            {
                _ZhuangxiangJishi = 0;
                isRunLeft         = false;
                isRunRight        = true;
            }
        }
        else
        {
            _ZhuangxiangJishi = 0;
        }

        if (gameBody.IsEndGround || gameBody.IsHitWall)
        {
            return;
        }


        if (isRunLeft)
        {
            gameBody.RunLeft(flyXSpeed);
            //print("   左 "+flySpeed);
            if (gameBody.IsEndGround || gameBody.IsHitWall)
            {
                isRunLeft  = false;
                isRunRight = true;
            }
        }
        else if (isRunRight)
        {
            gameBody.RunRight(flyXSpeed);
            //print("   右!!! " + flySpeed);
            if (gameBody.IsEndGround || gameBody.IsHitWall)
            {
                isRunLeft  = true;
                isRunRight = false;
            }
        }


        //if (isRunLeft)
        //{
        //    gameBody.RunLeft(flyXSpeed);
        //    //print("   左 "+flySpeed);
        //    if (this.transform.position.x - myPosition.x < -patrolDistance || gameBody.IsEndGround || gameBody.IsHitWall)
        //    {
        //        isRunLeft = false;
        //        isRunRight = true;

        //    }
        //}
        //else if (isRunRight)
        //{
        //    gameBody.RunRight(flyXSpeed);
        //    //print("   右!!! " + flySpeed);
        //    if (this.transform.position.x - myPosition.x > patrolDistance || gameBody.IsEndGround || gameBody.IsHitWall)
        //    {
        //        isRunLeft = true;
        //        isRunRight = false;

        //    }
        //}
    }
Esempio n. 5
0
    void ShouBing()
    {
        //var values = Enum.GetValues(typeof(KeyCode));//存储所有的按键
        //for (int x = 0; x < values.Length; x++)
        //{
        //    if (Input.GetKeyDown((KeyCode)values.GetValue(x)))
        //    {
        //        currentButton = values.GetValue(x).ToString();//遍历并获取当前按下的按键
        //        print("手柄按键  " + currentButton);
        //    }
        //}
        //detectPressedKeyOrButton();

        //float hl = Input.GetAxis("Horizontal_L");
        //float vl = Input.GetAxis("Vertical_L");

        //print("  hl "+hl);
        //print("  vl " + vl);



        horizontalDirection = Input.GetAxis(HORIZONTAL);

        verticalDirection = Input.GetAxis(VERTICAL);

        if (horizontalDirection > 0.8 || horizontalDirection < -0.8)
        {
            IsInShoubing = true;
        }

        if (verticalDirection > 0.6)
        {
            IsInShoubing      = true;
            Globals.isKeyUp   = true;
            Globals.isKeyDown = false;
        }
        else if (verticalDirection < -0.6)
        {
            IsInShoubing      = true;
            Globals.isKeyUp   = false;
            Globals.isKeyDown = true;
        }
        else
        {
            if (IsInShoubing)
            {
                Globals.isKeyUp   = false;
                Globals.isKeyDown = false;
            }
        }



        //if (Input.GetKeyDown(KeyCode.Joystick1Button3) && Globals.isKeyUp)
        //{
        //    //if (IsCanControl()) _body.GetSkill1();
        //    //print("技能释放---------   right ");

        //    ObjectEventDispatcher.dispatcher.dispatchEvent(new UEvent(EventTypeName.RELEASE_SKILL, "center"), this);
        //    return;
        //}
        if (Input.GetKeyDown(KeyCode.Joystick1Button3) && Globals.isKeyUp)
        {
            //if (IsCanControl()) _body.GetSkill1();
            //print("技能释放---------  up");
            ObjectEventDispatcher.dispatcher.dispatchEvent(new UEvent(EventTypeName.RELEASE_SKILL, "up"), this);
            return;
        }

        if (Input.GetKeyDown(KeyCode.Joystick1Button3) && Globals.isKeyDown)
        {
            //if (IsCanControl()) _body.GetSkill1();
            //print("技能释放---------  down");
            ObjectEventDispatcher.dispatcher.dispatchEvent(new UEvent(EventTypeName.RELEASE_SKILL, "down"), this);
            return;
        }

        if (Input.GetKeyDown(KeyCode.Joystick1Button3))
        {
            //if (IsCanControl()) _body.GetSkill1();
            //print("技能释放---------   center");
            ObjectEventDispatcher.dispatcher.dispatchEvent(new UEvent(EventTypeName.RELEASE_SKILL, "center"), this);
            return;
        }



        if (IsInShoubing)
        {
            if (horizontalDirection > 0)
            {
                if (IsCanControl())
                {
                    _body.RunRight(horizontalDirection);
                }
            }
            else if (horizontalDirection < 0)
            {
                if (IsCanControl())
                {
                    _body.RunLeft(horizontalDirection);
                }
            }
            else
            {
                if (IsCanControl() && !Globals.isXNBtn)
                {
                    _body.ReSetLR();
                }
            }
        }

        //print("verticalDirection    " + verticalDirection);


        if (Input.GetKeyDown(KeyCode.Joystick1Button5))
        {
            //if (IsCanControl()) _body.GetSkill1();
            //print("技能释放---------   center");
            //ObjectEventDispatcher.dispatcher.dispatchEvent(new UEvent(EventTypeName.RELEASE_SKILL, "center"), this);

            if (IsCanControl())
            {
                _body.Gedang();
            }
            return;
        }


        if (Input.GetKeyDown(KeyCode.Joystick1Button0))
        {
            if (Globals.IsHitPlotKuai)
            {
                return;
            }
            //print(">>>>>>>>>>>???????  JJJJJJJ  Globals.isKeyUp    "+ Globals.isKeyUp);
            if (IsCanControl())
            {
                _body.GetAtk();
            }
        }
        if (Input.GetKeyDown(KeyCode.Joystick1Button1))
        {
            if (IsCanControl())
            {
                _body.GetJump();
            }
        }

        if (Input.GetKeyDown(KeyCode.Joystick1Button2) || Input.GetKeyDown(KeyCode.Joystick1Button7))
        {
            if (IsCanControl())
            {
                _body.GetDodge1();
            }
        }
    }
Esempio n. 6
0
    public virtual bool NearRoleInDistance(float distance, float distanceY = 0)
    {
        if (_player == null)
        {
            return(true);
        }

        if (_player.GetComponent <RoleDate>().isDie)
        {
            ReSetAll();
            return(false);
        }



        float dyU = _player.transform.position.y + 2;
        float dyD = _player.transform.position.y - 2;

        if (distanceY != 0)
        {
            dyU = _player.transform.position.y + 2 + distanceY;
            dyD = _player.transform.position.y - 2 + distanceY;
        }

        if (GetComponent <RoleDate>().IsAirEnemy)
        {
            //先找点

            if (transform.position.y >= dyU)
            {
                GetComponent <AirGameBody>().RunY(-GetComponent <AirGameBody>().moveSpeedY);
                if (GetComponent <AIAirRunAway>().IsHitDown)
                {
                    //直接取消动作
                    GetComponent <AIAirBase>().QuXiaoAC();
                }
                return(false);
            }
            else if (transform.position.y <= dyD)
            {
                GetComponent <AirGameBody>().RunY(GetComponent <AirGameBody>().moveSpeedY);
                if (GetComponent <AIAirRunAway>().IsHitTop)
                {
                    //直接取消动作
                    GetComponent <AIAirBase>().QuXiaoAC();
                }
                return(false);
            }
        }

        //print("  --------->distance    " + distance+"       "+NearSpeed+"   ?????    "+(_player.transform.position.x - transform.position.x));
        if (_player.transform.position.x - transform.position.x >= distance)
        {
            //print("右跑!");
            //目标在右
            _gameBody.RunRight(NearSpeed);
            return(false);
        }
        else if (_player.transform.position.x - transform.position.x <= -distance)
        {
            //print("左 跑!");
            //目标在左
            if (GetComponent <AirGameBody>())
            {
                _gameBody.RunLeft(NearSpeed);
            }
            else
            {
                _gameBody.RunLeft(-NearSpeed);
            }

            return(false);
        }
        else
        {
            return(true);
        }
    }
Esempio n. 7
0
    void ShouBing()
    {
        var values = Enum.GetValues(typeof(KeyCode));//存储所有的按键

        for (int x = 0; x < values.Length; x++)
        {
            if (Input.GetKeyDown((KeyCode)values.GetValue(x)))
            {
                currentButton = values.GetValue(x).ToString();//遍历并获取当前按下的按键
                //print("手柄按键  " + currentButton);
            }
        }
        //detectPressedKeyOrButton();

        //float hl = Input.GetAxis("Horizontal_L");
        //float vl = Input.GetAxis("Vertical_L");

        //print("  hl "+hl);
        //print("  vl " + vl);



        horizontalDirection = Input.GetAxis(HORIZONTAL);

        verticalDirection = Input.GetAxis(VERTICAL);



        if (horizontalDirection > 0)
        {
            if (IsCanControl())
            {
                _body.RunRight(horizontalDirection);
            }
        }
        else if (horizontalDirection < 0)
        {
            if (IsCanControl())
            {
                _body.RunLeft(horizontalDirection);
            }
        }
        else
        {
            if (IsCanControl() && !Globals.isXNBtn)
            {
                _body.ReSetLR();
            }
        }

        //print("verticalDirection    " + verticalDirection);

        if (verticalDirection > 0.6)
        {
            Globals.isKeyUp   = true;
            Globals.isKeyDown = false;
        }
        else if (verticalDirection < -0.6)
        {
            Globals.isKeyUp   = false;
            Globals.isKeyDown = true;
        }
        else
        {
            Globals.isKeyUp   = false;
            Globals.isKeyDown = false;
        }



        //if (Input.GetKeyDown("Joystick1Button0"))
        //{
        //    if (Globals.IsHitPlotKuai) return;
        //    //print(">>>>>>>>>>>???????  JJJJJJJ  Globals.isKeyUp    "+ Globals.isKeyUp);
        //    if (IsCanControl()) _body.GetAtk();
        //}
        //if (Input.GetKeyDown("Joystick1Button1"))
        //{
        //    if (IsCanControl()) _body.GetJump();
        //}

        //if (Input.GetKeyDown(KeyCode.U))
        //{
        //    //if (IsCanControl()) _body.GetSkill1();
        //}

        //if (Input.GetKeyDown("Joystick1Button3"))
        //{
        //    if (IsCanControl()) _body.GetSkill2();
        //}

        //if (Input.GetKeyDown("Joystick1Button2"))
        //{
        //    if (IsCanControl()) _body.GetDodge1();
        //}



        //Debug.Log("手柄按钮控制!!");

        if (currentButton == "Joystick1Button0" || currentButton == "JoystickButton0")
        {
            //Debug.Log("Joystick1Button0 !!!!! ");
            if (Globals.IsHitPlotKuai)
            {
                return;
            }
            if (IsCanControl())
            {
                _body.GetAtk();
            }
            currentButton = "";
        }

        if (currentButton == "Joystick1Button1")
        {
            if (IsCanControl())
            {
                _body.GetJump();
            }
            currentButton = "";
        }

        if (currentButton == "Joystick1Button2")
        {
            if (IsCanControl())
            {
                _body.GetDodge1();
            }
            currentButton = "";
        }

        if (currentButton == "Joystick1Button3")
        {
            currentButton = "";
        }
    }