Exemple #1
0
        //处理质量
        private void HandleMass(List <BaseCom> comList)
        {
            PlayerPhysicsCom physicsCom = GetCom <PlayerPhysicsCom>(comList[0]);
            PlayerSpeedCom   speedCom   = GetCom <PlayerSpeedCom>(comList[1]);
            PlayerCom        playerCom  = GetCom <PlayerCom>(comList[2]);

            //冲刺时无重力
            if (speedCom.IsDash)
            {
                physicsCom.Mass = 0;
                return;
            }

            //没有体力了(直接默认质量)
            if (playerCom.Energy <= 0)
            {
                physicsCom.Mass = physicsCom.DefaultMass;
                return;
            }

            //墙上质量降低(摩擦)
            if (physicsCom.CollideDir == ColliderDir.Left || physicsCom.CollideDir == ColliderDir.Right)
            {
                physicsCom.Mass = physicsCom.DefaultMass * 0.6f;
            }

            physicsCom.Mass = physicsCom.DefaultMass;
        }
Exemple #2
0
        //处理移动
        private void HandleMove(List <BaseCom> comList)
        {
            PlayerPhysicsCom physicsCom = GetCom <PlayerPhysicsCom>(comList[0]);
            PlayerSpeedCom   speedCom   = GetCom <PlayerSpeedCom>(comList[1]);
            PlayerCom        playerCom  = GetCom <PlayerCom>(comList[2]);

            if (speedCom.DoDash)
            {
                Dash(physicsCom, speedCom, playerCom);
                speedCom.DoDash = false;
                return;
            }

            if (speedCom.IsDash)
            {
                return;
            }

            //速度赋值
            physicsCom.Velocity.x = speedCom.Speed;
            Movement(physicsCom);

            if (speedCom.UpSpeed != 0)
            {
                physicsCom.Velocity.y = speedCom.UpSpeed;
                Jump(physicsCom);
            }
        }
Exemple #3
0
        //处理重力速度
        private void HandleGravityVelocity(List <BaseCom> comList)
        {
            PlayerPhysicsCom phyCom   = GetCom <PlayerPhysicsCom>(comList[0]);
            PlayerSpeedCom   speedCom = GetCom <PlayerSpeedCom>(comList[1]);

            //phyCom.Rig2D.gravityScale = phyCom.Mass;

            // if (phyCom.CollideDir==ColliderDir.Down&&speedCom.UpSpeed==0)
            // {
            //     phyCom.Rig2D.velocity=new Vector2(phyCom.Rig2D.velocity.x,0);
            //     return;
            // }
            //降落
            if (phyCom.Rig2D.velocity.y < 0)
            {
                phyCom.Rig2D.velocity += Definition.Gravity * speedCom.FallMultiplier * phyCom.Mass * Time.deltaTime;
            }
            //跳跃
            else if (phyCom.Rig2D.velocity.y > 0)
            {
                if (speedCom.UpSpeed == 0)
                {
                    phyCom.Rig2D.velocity += Definition.Gravity * speedCom.LowJumpMultiplier * phyCom.Mass * Time.deltaTime;
                }
            }
        }
Exemple #4
0
 private bool CheckCanJump(PlayerSpeedCom speedCom)
 {
     if (speedCom.CurrJumpIndex < speedCom.MaxJumpIndex)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #5
0
        //处理冲刺输入值
        private void HandleDashInput(ref bool doDash, PlayerPhysicsCom physicsCom, PlayerSpeedCom speedCom)
        {
            if (speedCom.IsDash)
            {
                doDash = false;
                return;
            }

            if (speedCom.DoDash)
            {
                doDash = false;
                return;
            }
        }
Exemple #6
0
        protected override void OnEnter(NodeData wData)
        {
            EntityWorkData workData = wData as EntityWorkData;
            //参数
            bool    doDash    = workData.GetReqParam(EntityReqId.PlayerMove).GetBool();
            Vector2 inputMove = workData.GetReqParam(LCECS.EntityReqId.PlayerMove).GetVect2();

            //组件
            PlayerCom        playerCom  = workData.MEntity.GetCom <PlayerCom>();
            PlayerSpeedCom   speedCom   = workData.MEntity.GetCom <PlayerSpeedCom>();
            PlayerPhysicsCom physicsCom = workData.MEntity.GetCom <PlayerPhysicsCom>();

            #region 点击加速
            //初始速度
            //speedCom.Speed = speedCom.MinSpeed;
            #endregion

            HandleDashInput(ref doDash, physicsCom, speedCom);
            HandleWallInputMove(ref inputMove, physicsCom, speedCom, playerCom);
            HandleNormalInputMove(ref inputMove, physicsCom, speedCom);

            if (doDash)
            {
                ECSLocate.ECSLog.LogR("请求冲刺》》》", speedCom.DoDash, speedCom.IsDash);
            }
            speedCom.DoDash  = doDash;
            speedCom.UpSpeed = speedCom.MaxUpSpeed * inputMove.y;
            speedCom.Speed   = speedCom.MaxSpeed * inputMove.x;

            #region 点击加速
            // if (inputMove.x>0)
            // {
            //     speedCom.Speed  += speedCom.AddSpeed * inputMove.x;
            //     speedCom.Speed   = speedCom.Speed > speedCom.MaxSpeed ? speedCom.MaxSpeed : speedCom.Speed;
            // }
            #endregion

            //水平速度限制
            speedCom.Speed = speedCom.Speed > speedCom.MaxSpeed ? speedCom.MaxSpeed : speedCom.Speed;

            //请求冲刺
            if (speedCom.DoDash)
            {
                ECSLocate.ECS.SetGlobalSingleComData((EffectCom com) =>
                {
                    com.CurrShowEffectId = 1001;
                    com.EntityId         = workData.Id;
                });
            }
        }
Exemple #7
0
        private void SetInputJumpValue(PlayerSpeedCom speedCom, ref Vector2 inputMove, float value)
        {
            if (value == 0)
            {
                inputMove.y = 0;
                return;
            }

            if (CheckCanJump(speedCom))
            {
                inputMove.y = value;
                speedCom.CurrJumpIndex++;
            }
            else
            {
                inputMove.y = 0;
            }
        }
Exemple #8
0
        protected override void HandleComs(List <BaseCom> comList)
        {
            PlayerAnimCom    animCom    = GetCom <PlayerAnimCom>(comList[0]);
            PlayerSpeedCom   speedCom   = GetCom <PlayerSpeedCom>(comList[1]);
            PlayerCom        playerCom  = GetCom <PlayerCom>(comList[2]);
            PlayerPhysicsCom physicsCom = GetCom <PlayerPhysicsCom>(comList[3]);

            animCom.Animtor.SetFloat("Speed", physicsCom.Velocity.x);
            animCom.Animtor.SetFloat("UpSpeed", physicsCom.Velocity.y);
            animCom.Animtor.SetBool("IsGround", physicsCom.CollideDir == ColliderDir.Down);
            if (speedCom.Speed > 0)
            {
                playerCom.SpriteRender.flipX = false;
            }
            else if (speedCom.Speed < 0)
            {
                playerCom.SpriteRender.flipX = true;
            }

            animCom.WaveAnimTor.SetFloat("UpSpeed", physicsCom.Velocity.y);
            animCom.WaveAnimTor.SetBool("IsGround", physicsCom.CollideDir == ColliderDir.Down);
            animCom.WaveAnimTor.SetBool("IsRight", playerCom.SpriteRender.flipX == false);
        }
Exemple #9
0
        //执行冲刺
        private void Dash(PlayerPhysicsCom phyCom, PlayerSpeedCom speedCom, PlayerCom playerCom)
        {
            speedCom.IsDash = true;

            //速度归零
            phyCom.Rig2D.velocity = Vector2.zero;

            //计算冲刺速度
            Vector2 dir = Vector2.zero;

            dir.x = playerCom.SpriteRender.flipX ? -1:1;
            dir.y = speedCom.UpSpeed == 0?0:1;
            phyCom.Rig2D.velocity += dir * speedCom.MaxDashSpeed;

            //拖拽还原状态
            DOVirtual.Float(8, 0, speedCom.DashDragTime, (x) => {
                phyCom.Rig2D.drag = x;
                if (x == 0)
                {
                    speedCom.IsDash = false;
                    phyCom.Mass     = phyCom.DefaultMass;
                }
            });
        }
Exemple #10
0
        //处理墙上移动输入值
        private void HandleWallInputMove(ref Vector2 inputMove, PlayerPhysicsCom physicsCom, PlayerSpeedCom speedCom, PlayerCom playerCom)
        {
            if (physicsCom.CollideDir != ColliderDir.Left && physicsCom.CollideDir != ColliderDir.Right)
            {
                return;
            }

            if (playerCom.Energy <= 0)
            {
                ECSLocate.ECSLog.LogR("体力用完了");
                return;
            }

            //上墙
            if (inputMove.y == 0)
            {
                if (physicsCom.CollideDir == ColliderDir.Left)
                {
                    if (inputMove.x >= 0)
                    {
                        //TODO
                        //玩家动画方向
                        inputMove.x = 0;
                    }
                    else
                    {
                        inputMove.y = -inputMove.x;
                        inputMove.x = 0;
                    }
                }
                else if (physicsCom.CollideDir == ColliderDir.Right)
                {
                    if (inputMove.x <= 0)
                    {
                        //TODO
                        //玩家动画方向
                        inputMove.x = 0;
                    }
                    else
                    {
                        inputMove.y = inputMove.x;
                        inputMove.x = 0;
                    }
                }
            }

            //横跳
            if (inputMove.y != 0)
            {
                if (physicsCom.CollideDir == ColliderDir.Left)
                {
                    //右横跳
                    if (inputMove.x > 0)
                    {
                        inputMove.x = 1;
                        inputMove.y = 1;
                    }
                }
                else if (physicsCom.CollideDir == ColliderDir.Right)
                {
                    //左横跳
                    if (inputMove.x < 0)
                    {
                        inputMove.x = -1;
                        inputMove.y = 1;
                    }
                }
            }
        }
Exemple #11
0
        //处理普通移动输入值
        private void HandleNormalInputMove(ref Vector2 inputMove, PlayerPhysicsCom physicsCom, PlayerSpeedCom speedCom)
        {
            //if (physicsCom.CollideDir != ColliderDir.None && physicsCom.CollideDir != ColliderDir.Down &&
            //    physicsCom.CollideDir != ColliderDir.Up)
            //    return;

            //浮空时受力
            //if (physicsCom.CollideDir == ColliderDir.None)
            //{
            //    inputMove.x *= 0.5f;
            //}

            //重置跳跃索引
            if (physicsCom.CollideDir == ColliderDir.Down)
            {
                speedCom.CurrJumpIndex = 0;
            }

            //垂直输入处理(左右方向爬墙)
            if (physicsCom.CollideDir != ColliderDir.Right && physicsCom.CollideDir != ColliderDir.Left)
            {
                SetInputJumpValue(speedCom, ref inputMove, inputMove.y);
            }

            //水平输入处理
            //地面左右有阻挡
            if (physicsCom.SubCollideDir == ColliderDir.Left && inputMove.x < 0)
            {
                inputMove.x = 0;
            }
            if (physicsCom.SubCollideDir == ColliderDir.Right && inputMove.x > 0)
            {
                inputMove.x = 0;
            }
        }