コード例 #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;
        }
コード例 #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);
            }
        }
コード例 #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;
                }
            }
        }
コード例 #4
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;
            }
        }
コード例 #5
0
        protected override void HandleComs(List <BaseCom> comList)
        {
            PlayerCom        playerCom  = GetCom <PlayerCom>(comList[0]);
            PlayerPhysicsCom physicsCom = GetCom <PlayerPhysicsCom>(comList[1]);

            RecoverEnergy(playerCom, physicsCom);
        }
コード例 #6
0
        //处理碰撞方向
        private void HandleCollider(List <BaseCom> comList)
        {
            PlayerPhysicsCom physicsCom = GetCom <PlayerPhysicsCom>(comList[0]);

            //地面射线
            bool isGround = Physics2D.OverlapCircle((Vector2)physicsCom.Rig2D.position + physicsCom.BottomOffset, physicsCom.CollisionRadius, physicsCom.GroundLayer);

            //右射线
            bool isRightWall = Physics2D.OverlapCircle((Vector2)physicsCom.Rig2D.position + physicsCom.RightOffset, physicsCom.CollisionRadius, physicsCom.GroundLayer);

            //左射线
            bool isLeftWall = Physics2D.OverlapCircle((Vector2)physicsCom.Rig2D.position + physicsCom.LeftOffset, physicsCom.CollisionRadius, physicsCom.GroundLayer);

            //赋值
            if (isGround)
            {
                physicsCom.CollideDir = ColliderDir.Down;
                //赋值子碰撞
                if (isRightWall)
                {
                    physicsCom.SubCollideDir = ColliderDir.Right;
                }
                else if (isLeftWall)
                {
                    physicsCom.SubCollideDir = ColliderDir.Left;
                }
                else
                {
                    physicsCom.SubCollideDir = ColliderDir.None;
                }
            }
            else
            {
                if (isRightWall)
                {
                    physicsCom.SubCollideDir = ColliderDir.Right;
                    physicsCom.CollideDir    = ColliderDir.Right;
                }
                else if (isLeftWall)
                {
                    physicsCom.SubCollideDir = ColliderDir.Left;
                    physicsCom.CollideDir    = ColliderDir.Left;
                }
                else
                {
                    physicsCom.SubCollideDir = ColliderDir.None;
                    physicsCom.CollideDir    = ColliderDir.None;
                }
            }
        }
コード例 #7
0
        //处理冲刺输入值
        private void HandleDashInput(ref bool doDash, PlayerPhysicsCom physicsCom, PlayerSpeedCom speedCom)
        {
            if (speedCom.IsDash)
            {
                doDash = false;
                return;
            }

            if (speedCom.DoDash)
            {
                doDash = false;
                return;
            }
        }
コード例 #8
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;
                });
            }
        }
コード例 #9
0
        //恢复体力
        private void RecoverEnergy(PlayerCom playerCom, PlayerPhysicsCom physicsCom)
        {
            if (physicsCom.Velocity.y > 0)
            {
                //上墙
                if (physicsCom.CollideDir == ColliderDir.Left || physicsCom.CollideDir == ColliderDir.Right)
                {
                    playerCom.Energy -= playerCom.AddEnergy * Definition.DeltaTime * 2;
                    playerCom.Energy  = playerCom.Energy <= 0?0:playerCom.Energy;
                }
            }

            if (physicsCom.CollideDir == ColliderDir.Down)
            {
                playerCom.Energy += playerCom.AddEnergy * Definition.DeltaTime;
                playerCom.Energy  = playerCom.Energy >= playerCom.MaxEnergy?playerCom.MaxEnergy:playerCom.Energy;
            }
        }
コード例 #10
0
ファイル: PlayerAnimSystem.cs プロジェクト: ALunGame/LCECS
        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);
        }
コード例 #11
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;
                }
            });
        }
コード例 #12
0
 //执行跳跃
 private void Jump(PlayerPhysicsCom phyCom)
 {
     phyCom.Rig2D.velocity = new Vector2(phyCom.Rig2D.velocity.x, phyCom.Velocity.y);
 }
コード例 #13
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;
                    }
                }
            }
        }