Ejemplo n.º 1
0
    private Vector2 UpdateInfo(Vector2 position)
    {
        position += AITool.Patrol(body.target, body, this, body.speed);

        position += AITool.ApproachOrAway(body.target, body, faceDistance, body.speed, 1);

        body.DetectGround();
        position += body.Gravity(Vector2.zero);


        //因为跳跃是要连续使用的函数,所以放在update中
        position += AITool.Jump(body, jumpHeight);

        if (body.target != null)
        {
            AITool.RandomAttack(body, 5);
            AITool.IfLost(body.target, body, lostDistance);
        }

        return(position);
    }
Ejemplo n.º 2
0
    void Update()
    {
        //Debug.Log(anim.GetFloat("Speed"));
        //Instantiate(bullet)

        horizontal    = Input.GetAxis("Horizontal"); //水平方向运动
        vertical      = Input.GetAxis("Vertical");   //垂直方向运动
        jump          = Input.GetAxis("Jump");
        attack        = Input.GetButton("Fire1");
        shieldPressed = Input.GetMouseButton(1);  //点击鼠标右键


        bool horizontalDown = Input.GetButtonDown("Horizontal");

        Vector2 position = transform.position;

        // Debug.Log(" Master.currentDirection "+Master.currentDirection+" master.status "+Master.status);

        if (Master.status == 1)
        {
            //游戏暂停时按下任意按键后继续,
            //倒放后松开按键后自动进入暂停状态
            if (jump > 0 || horizontalDown == true)
            {
                Master.Resume();
            }
        }

        body.DetectGround();
        //body.DetectWall();
        Dead();


        //Debug.Log(Master.currentDirection);

        //$$$$#$@#$@!$!
        //正向
        if (body.tenetDirection == 1 && Master.status != 1)
        {
            if (Master.currentDirection == 0 || Master.status == 2)
            {
                //当为回放状态或者逆转方向时进行查找egg
                position = mController.FindEgg(body.tenetDirection);
            }
            else if (Master.status == 0 && Master.currentDirection == 1)     //当全局状态为正常时才进行所有动作
            {
                //每时每刻都有重力
                // Debug.Log("还在动");



                position += body.Gravity(Vector2.zero);

                position += UpdateInfo();
            }
        }

        //$$$$#$@#$@!$!
        //逆向
        if (body.tenetDirection == 0 && Master.status != 1)
        {
            //此部分为逆转主角所独有的.



            if (Master.status == 0)
            {
                //盾牌函数
                Shield();


                //此时表示正常的逆向主角的操作
                position += body.Gravity(Vector2.zero);

                position += UpdateInfo();

                //Debug.Log("逆转");
            }
            else if (Master.status == 2)
            {
                //表示逆向的方向在回退
                position = mController.FindEgg(body.tenetDirection);
            }
        }

        //Debug.Log(mController.eggList.Count);
        //Debug.Log(body.tenetDirection + " " + Master.currentDirection);


        // body.AutoStop(mController.eggList,Master.frame);

        //position = Input.mousePosition;

        rigidbody.MovePosition(position);



        body.AutoStop(mController.eggList, Master.frame);

        //Debug.Log(mController.eggList.Count);
    }
Ejemplo n.º 3
0
    //awdqwfqwwad
    private Vector2 Replay(Egg egg, int direction)
    {
        Vector2 position = transform.position;

        //direction决定是否和egg原有的direction一致,如果direction都为1则一致,为-1则相反

        //根据参数来进行各自的动作
        switch (egg.movement)
        {
        case ActionEnum.movement.walk:
            position = body.Walk(direction * -egg.parm1, egg.position);
            break;

        case ActionEnum.movement.attack:
            position = body.Attack(body.direction, true, egg.position);
            //Debug.Log("Attack");
            break;

        case ActionEnum.movement.jump:
            position = body.Jumping(1, (int)egg.parm2, egg.position);      //实现跳一百帧就是插入一百次即可
            //Debug.Log(egg.parm1 + "   " + egg.parm2);
            break;

        case ActionEnum.movement.dead:
            //Debug.Log("复活");
            body.Dead(1);
            position = egg.position;      //可能也要赋予位置
            break;

        case ActionEnum.movement.gravity:
            position = body.Gravity(egg.position);
            //Debug.Log("gravity");
            break;

        case ActionEnum.movement.bulletMove:
            position = egg.position;
            //Debug.Log("gravity");
            break;

        case ActionEnum.movement.bulletBack:

            transform.GetComponent <bullet>().speed = direction * -egg.parm1;

            //gameObject.SetActive(true);
            //Debug.Log(egg.parm1);
            GetComponent <BoxCollider2D>().enabled = true;

            //修改子弹的z坐标为-3
            transform.position = new Vector3(egg.position.x, egg.position.y, 3);

            position = transform.position;
            //Debug.Log(transform.position);
            //Debug.Log("gravity");
            break;

        case ActionEnum.movement.bulletGone:
            position = egg.position;
            //当frame还可以计入事件帧时才会销毁
            if (direction == Master.currentDirection)
            {
                Debug.Log("bullet销毁");
                Destroy(gameObject, 0);        //去除子弹
            }

            break;

        case ActionEnum.movement.targetConfirm:
            position = egg.position;
            body.GetAnimator().SetFloat("Speed", 1f);
            //body.SetFloat("Speed", 1f);
            body.transform.Find("CursorCollider").GetComponent <SpriteRenderer>().color = Color.white;

            body.tenetDirection = 1;         //将其状态改回原来的
            break;

        case ActionEnum.movement.findMainguy:
            position = egg.position;

            if (body.tenetDirection == Master.currentDirection)
            {
                body.target = null;
            }

            break;

        default:
            break;
        }

        return(position);

        //123
    }