示例#1
0
        /// <summary>
        ///     Fires the Pre Move Event
        /// </summary>
        protected PreMoveEventArgs FirePreMove(Vector3 position)
        {
            var args = new PreMoveEventArgs
            {
                MovePosition = position
            };

            PreMove?.Invoke(Player, args);

            return(args);
        }
示例#2
0
        public void InputControl()
        {
            if (DFKeyboard.Left)
            {
                var e = new PreEventArgs();
                PreMove?.Invoke(this, e);
                if (!e.IsCanceled)
                {
                    Direction   = Direction.Left;
                    Velocity.X -= _spdAddition;
                    if (Velocity.X < -_spdlimit)
                    {
                        Velocity.X = -_spdlimit;
                    }
                }
            }
            else if (DFKeyboard.Right)
            {
                var e = new PreEventArgs();
                PreMove?.Invoke(this, e);
                if (!e.IsCanceled)
                {
                    Direction   = Direction.Right;
                    Velocity.X += _spdAddition;
                    if (Velocity.X > _spdlimit)
                    {
                        Velocity.X = _spdlimit;
                    }
                }
            }
            else
            {
                Velocity.X *= _spddivition;
                if ((Velocity.X < 0.1f) && (Velocity.X > -0.1f))
                {
                    Velocity.X = 0;
                }
            }

            if (DFKeyboard.Z.IsKeyDown)
            {
                if (!IsOnLand && DFKeyboard.Left && (CollisionLeft() == ColliderType.Land))
                {
                    Velocity.X = 3f;
                    Velocity.Y = -4f;
                    DESound.Play(Sounds.Destroy);
                }
                else if (!IsOnLand && DFKeyboard.Right && (CollisionRight() == ColliderType.Land))
                {
                    Velocity.X = -3f;
                    Velocity.Y = -4f;
                    DESound.Play(Sounds.Destroy);
                }
                else
                {
                    if (IsUnderWater)
                    {
                        DESound.Play(Sounds.Swim);
                        Velocity.Y = -2f;
                        IsJumping  = false;
                    }
                    else if (IsOnLand || (_flowtimer < 10))
                    {
                        var e = new PreEventArgs();
                        PreJump?.Invoke(this, e);
                        if (!e.IsCanceled)
                        {
                            if (!IsJumping)
                            {
                                DESound.Play(Sounds.BigJump);
                            }
                            Velocity.Y = -3.6f - Math.Abs(Velocity.X) / 6.5f;
                            IsJumping  = true;
                            Move();
                        }
                    }
                }
            }
            if (IsOnLand)
            {
                _flowtimer = 0;
            }
            else
            {
                _flowtimer++;
            }

            if (!DFKeyboard.Z && IsJumping)
            {
                Velocity.Y += 0.1f;
            }

            if (DFKeyboard.ShiftLeft)
            {
                _spdAddition = 0.4f;
                _spddivition = 0.9f;
                _spdlimit    = 2.7f;
                if (!_lshifted)
                {
                    switch (Form)
                    {
                    case PlayerForm.Fire:
                        DESound.Play(Sounds.ShootFire);
                        Parent.Add(
                            new EntityFireWeapon(Location, Mpts, Map, Parent).SetEntityData(
                                DynamicJson.Parse(@"{""SpeedX"": " +
                                                  (Direction == Direction.Right ? EntityFireWeapon.SpeedX : -EntityFireWeapon.SpeedX) + "}")));
                        break;

                    case PlayerForm.Ice:
                        DESound.Play(Sounds.ShootFire);
                        Parent.Add(
                            new EntityIceWeapon(Location, Mpts, Map, Parent).SetEntityData(
                                DynamicJson.Parse(@"{""SpeedX"": " +
                                                  (Direction == Direction.Right ? EntityIceWeapon.SpeedX : -EntityIceWeapon.SpeedX) + "}")));
                        break;

                    case PlayerForm.Magic:
                        DESound.Play(Sounds.ShootFire);
                        Parent.Add(new EntityMagicWeapon(Location, Mpts, Map, Parent));
                        break;
                    }
                }

                foreach (EntityLiving entity in Parent.FindEntitiesByType <EntityLiving>())
                {
                    var e = entity;
                    if (e.IsDying)
                    {
                        continue;
                    }
                    if ((GodTime > 0) && AteGodItem &&
                        ((e.MyGroup == EntityGroup.Enemy) || (e.MyGroup == EntityGroup.MonsterWeapon)) &&
                        new RectangleF(e.Location.X, e.Location.Y, e.Size.Width, e.Size.Height).CheckCollision(new RectangleF(Location.X,
                                                                                                                              Location.Y, Size.Width, Size.Height)))
                    {
                        e.Kill();
                    }
                }

                foreach (EntityTurcosShell e in Parent.FindEntitiesByType <EntityTurcosShell>())
                {
                    if (e.IsRunning)
                    {
                        if (new RectangleF(Location.ToPoint(), Size).CheckCollision(new RectangleF(e.Location.ToPoint(), e.Size)))
                        {
                            e.Owner = this;
                        }
                    }
                }
                _lshifted = true;
            }
            else
            {
                _lshifted    = false;
                _spdAddition = 0.2f;
                _spddivition = 0.9f;
                _spdlimit    = 1.4f;
            }
        }