Exemplo n.º 1
0
 public PlayerMotionType(PlayerMotionType copy)
 {
     moveSpeed          = copy.moveSpeed;
     canLedgeJump       = copy.canLedgeJump;
     canRoomChange      = copy.canRoomChange;
     isStrafing         = copy.isStrafing;
     isSlippery         = copy.isSlippery;
     acceleration       = copy.acceleration;
     deceleration       = copy.deceleration;
     minSpeed           = copy.minSpeed;
     directionSnapCount = copy.directionSnapCount;
 }
 public PlayerMotionType(PlayerMotionType copy)
 {
     moveSpeed			= copy.moveSpeed;
     canLedgeJump		= copy.canLedgeJump;
     canRoomChange		= copy.canRoomChange;
     isStrafing			= copy.isStrafing;
     isSlippery			= copy.isSlippery;
     acceleration		= copy.acceleration;
     deceleration		= copy.deceleration;
     minSpeed			= copy.minSpeed;
     directionSnapCount	= copy.directionSnapCount;
 }
Exemplo n.º 3
0
        private PlayerMotionType moveModeWater;                         // For swimming.


        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------

        public PlayerMoveComponent(Player player)
        {
            this.player = player;

            // Default settings.
            autoAccelerate   = false;
            moveSpeedScale   = 1.0f;
            moveCondition    = PlayerMoveCondition.FreeMovement;
            canLedgeJump     = true;
            canJump          = true;
            canPush          = true;
            canUseWarpPoint  = true;
            isStrafing       = false;
            isSprinting      = false;
            sprintTimer      = 0;
            sprintSpeedScale = 1.5f;

            // Internal.
            allowMovementControl = true;
            moveAxes             = new bool[] { false, false };
            motion               = Vector2F.Zero;
            isMoving             = false;
            velocityPrev         = Vector2F.Zero;
            moveAngle            = Angles.South;
            mode                 = new PlayerMotionType();
            jumpStartTile        = -Point2I.One;
            isCapeDeployed       = false;
            doomedToFallInHole   = false;
            holeTile             = null;
            holeDoomTimer        = 0;
            holeSlipVelocity     = Vector2F.Zero;
            fallingInHole        = false;
            isOnColorBarrier     = false;
            isOnSideScrollLadder = false;
            climbCollisionBox    = new Rectangle2F(-1, -7, 2, 9);

            // Controls.
            analogMode  = false;
            analogStick = GamePad.GetStick(Buttons.LeftStick);
            analogAngle = 0.0f;
            moveButtons = new InputControl[4];
            moveButtons[Directions.Up]    = Controls.Up;
            moveButtons[Directions.Down]  = Controls.Down;
            moveButtons[Directions.Left]  = Controls.Left;
            moveButtons[Directions.Right] = Controls.Right;

            // Normal movement.
            moveModeNormal               = new PlayerMotionType();
            moveModeNormal.MoveSpeed     = 1.0f;
            moveModeNormal.CanLedgeJump  = true;
            moveModeNormal.CanRoomChange = true;

            // Slow movement.
            moveModeSlow           = new PlayerMotionType(moveModeNormal);
            moveModeSlow.MoveSpeed = 0.5f;

            // Grass movement.
            moveModeGrass           = new PlayerMotionType(moveModeNormal);
            moveModeGrass.MoveSpeed = 0.75f;

            // Ice movement.
            moveModeIce                    = new PlayerMotionType();
            moveModeIce.MoveSpeed          = 1.0f;
            moveModeIce.CanLedgeJump       = true;
            moveModeIce.CanRoomChange      = true;
            moveModeIce.IsSlippery         = true;
            moveModeIce.Acceleration       = 0.02f;
            moveModeIce.Deceleration       = 0.05f;
            moveModeIce.MinSpeed           = 0.05f;
            moveModeIce.DirectionSnapCount = 32;

            // Air/jump movement.
            moveModeAir                    = new PlayerMotionType();
            moveModeAir.IsStrafing         = true;
            moveModeAir.MoveSpeed          = 1.0f;
            moveModeAir.CanLedgeJump       = false;
            moveModeAir.CanRoomChange      = false;
            moveModeAir.IsSlippery         = true;
            moveModeAir.Acceleration       = 0.1f;
            moveModeAir.Deceleration       = 0.0f;
            moveModeAir.MinSpeed           = 0.05f;
            moveModeAir.DirectionSnapCount = 8;                     //32;

            // Water/swim movement.
            moveModeWater                    = new PlayerMotionType();
            moveModeWater.MoveSpeed          = 0.5f;
            moveModeWater.CanLedgeJump       = true;
            moveModeWater.CanRoomChange      = true;
            moveModeWater.IsSlippery         = true;
            moveModeWater.Acceleration       = 0.08f;
            moveModeWater.Deceleration       = 0.05f;
            moveModeWater.MinSpeed           = 0.05f;
            moveModeWater.DirectionSnapCount = 32;

            mode = moveModeNormal;
        }
Exemplo n.º 4
0
        //-----------------------------------------------------------------------------
        // Update
        //-----------------------------------------------------------------------------

        public void Update()
        {
            // Determine movement mode.
            if (player.RoomControl.IsSideScrolling && isOnSideScrollLadder)
            {
                mode = moveModeNormal;
            }
            else if (player.Physics.IsInAir)
            {
                mode = moveModeAir;
            }
            else if (player.Physics.IsInWater)
            {
                mode = moveModeWater;
            }
            else if (player.Physics.IsOnIce)
            {
                mode = moveModeIce;
            }
            else if (player.Physics.IsOnStairs || player.Physics.IsOnLadder)
            {
                mode = moveModeSlow;
            }
            else if (player.Physics.IsInGrass)
            {
                mode = moveModeGrass;
            }
            else
            {
                mode = moveModeNormal;
            }

            // Update movement.
            UpdateMoveControls();
            UpdateFallingInHoles();
            velocityPrev = player.Physics.Velocity;

            // Update sprinting.
            if (isSprinting)
            {
                // Create the sprint effect.
                if (sprintTimer % GameSettings.PLAYER_SPRINT_EFFECT_INTERVAL == 0 &&
                    player.IsOnGround && player.CurrentState != player.SwimState)
                {
                    AudioSystem.PlaySound(GameData.SOUND_PLAYER_LAND);
                    Effect sprintEffect = new Effect(GameData.ANIM_EFFECT_SPRINT_PUFF, DepthLayer.EffectSprintPuff, true);
                    player.RoomControl.SpawnEntity(sprintEffect, player.Position);
                }
                sprintTimer--;
                if (sprintTimer <= 0)
                {
                    isSprinting = false;
                }
            }

            // Check for ledge jumping (ledges/waterfalls)
            CollisionInfo collisionInfo = player.Physics.CollisionInfo[moveDirection];

            if (canLedgeJump && mode.CanLedgeJump && isMoving &&
                collisionInfo.Type == CollisionType.Tile &&
                !player.RoomControl.IsSideScrolling)
            {
                Tile tile = collisionInfo.Tile;
                if (tile.IsLedge && moveDirection == tile.LedgeDirection && !tile.IsMoving)
                {
                    TryLedgeJump(tile.LedgeDirection);
                }
            }

            // Check for walking on color barriers.
            if (player.IsOnGround && (player.Physics.TopTile is TileColorBarrier) &&
                ((TileColorBarrier)player.Physics.TopTile).IsRaised)
            {
                IsOnColorBarrier = true;
            }
            else if (player.IsOnGround)
            {
                IsOnColorBarrier = false;
            }

            // Face up if climbing a side-scroll ladder.
            if (player.RoomControl.IsSideScrolling && isOnSideScrollLadder)
            {
                bool faceUp = false;
                if (HighestSideScrollLadderTile != null)
                {
                    faceUp = (player.Y > HighestSideScrollLadderTile.Bounds.Top + 4.0f);
                }
                if (faceUp && allowMovementControl)
                {
                    player.Direction = Directions.Up;
                }
            }
        }
Exemplo n.º 5
0
        private Vector2F velocityPrev; // The player's velocity on the previous frame.

        #endregion Fields

        #region Constructors

        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------
        public PlayerMoveComponent(Player player)
        {
            this.player = player;

            // Default settings.
            autoAccelerate			= false;
            moveSpeedScale			= 1.0f;
            moveCondition			= PlayerMoveCondition.FreeMovement;
            canLedgeJump			= true;
            canJump					= true;
            isStrafing				= false;

            // Internal.
            allowMovementControl	= true;
            moveAxes				= new bool[] { false, false };
            motion					= Vector2F.Zero;
            isMoving				= false;
            velocityPrev			= Vector2F.Zero;
            moveAngle				= Angles.South;
            mode					= new PlayerMotionType();

            // Controls.
            analogMode		= false;
            analogStick		= GamePad.GetStick(Buttons.LeftStick);
            analogAngle		= 0.0f;
            moveButtons		= new InputControl[4];
            moveButtons[Directions.Up]		= Controls.Up;
            moveButtons[Directions.Down]	= Controls.Down;
            moveButtons[Directions.Left]	= Controls.Left;
            moveButtons[Directions.Right]	= Controls.Right;

            // Normal movement.
            moveModeNormal = new PlayerMotionType();
            moveModeNormal.MoveSpeed			= 1.0f;
            moveModeNormal.CanLedgeJump			= true;
            moveModeNormal.CanRoomChange		= true;

            // Slow movement.
            moveModeSlow = new PlayerMotionType();
            moveModeSlow.MoveSpeed				= 0.5f;
            moveModeSlow.CanLedgeJump			= true;
            moveModeSlow.CanRoomChange			= true;

            // Ice movement.
            moveModeIce = new PlayerMotionType();
            moveModeIce.MoveSpeed				= 1.0f;
            moveModeIce.CanLedgeJump			= true;
            moveModeIce.CanRoomChange			= true;
            moveModeIce.IsSlippery				= true;
            moveModeIce.Acceleration			= 0.02f;
            moveModeIce.Deceleration			= 0.05f;
            moveModeIce.MinSpeed				= 0.05f;
            moveModeIce.DirectionSnapCount		= 32;

            // Air/jump movement.
            moveModeAir = new PlayerMotionType();
            moveModeAir.IsStrafing				= true;
            moveModeAir.MoveSpeed				= 1.0f;
            moveModeAir.CanLedgeJump			= false;
            moveModeAir.CanRoomChange			= false;
            moveModeAir.IsSlippery				= true;
            moveModeAir.Acceleration			= 0.1f;
            moveModeAir.Deceleration			= 0.0f;
            moveModeAir.MinSpeed				= 0.05f;
            moveModeAir.DirectionSnapCount		= 8;//32;

            // Water/swim movement.
            moveModeWater = new PlayerMotionType();
            moveModeWater.MoveSpeed				= 0.5f;
            moveModeWater.CanLedgeJump			= true;
            moveModeWater.CanRoomChange			= true;
            moveModeWater.IsSlippery			= true;
            moveModeWater.Acceleration			= 0.08f;
            moveModeWater.Deceleration			= 0.05f;
            moveModeWater.MinSpeed				= 0.05f;
            moveModeWater.DirectionSnapCount	= 32;

            mode = moveModeNormal;
        }
Exemplo n.º 6
0
        //-----------------------------------------------------------------------------
        // Update
        //-----------------------------------------------------------------------------
        public void Update()
        {
            // Determine movement mode.
            if (player.Physics.IsInAir)
                mode = moveModeAir;
            else if (player.Physics.IsInWater)
                mode = moveModeWater;
            else if (player.Physics.IsOnIce)
                mode = moveModeIce;
            else if (player.Physics.IsOnLadder || player.Physics.IsOnStairs)
                mode = moveModeSlow;
            else
                mode = moveModeNormal;

            // Update movement.
            UpdateMoveControls();
            velocityPrev = player.Physics.Velocity;

            // Check for ledge jumping (ledges/waterfalls)
            CollisionInfo collisionInfo = player.Physics.CollisionInfo[moveDirection];
            if (canLedgeJump && mode.CanLedgeJump && isMoving && collisionInfo.Type == CollisionType.Tile && !collisionInfo.Tile.IsMoving) {
                Tile tile = collisionInfo.Tile;

                if (tile.IsLedge &&
                    moveDirection == tile.LedgeDirection &&
                    collisionInfo.Direction == tile.LedgeDirection)
                {
                    // Ledge jump!
                    player.LedgeJumpState.LedgeBeginTile = tile;
                    player.BeginState(player.LedgeJumpState);
                    return;
                }
            }
        }
        private Vector2F velocityPrev; // The player's velocity on the previous frame.

        #endregion Fields

        #region Constructors

        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------
        public PlayerMoveComponent(Player player)
        {
            this.player = player;

            // Default settings.
            autoAccelerate			= false;
            moveSpeedScale			= 1.0f;
            moveCondition			= PlayerMoveCondition.FreeMovement;
            canLedgeJump			= true;
            canJump					= true;
            canPush					= true;
            canUseWarpPoint			= true;
            isStrafing				= false;
            isSprinting				= false;
            sprintTimer				= 0;
            sprintSpeedScale		= 1.5f;

            // Internal.
            allowMovementControl	= true;
            moveAxes				= new bool[] { false, false };
            motion					= Vector2F.Zero;
            isMoving				= false;
            velocityPrev			= Vector2F.Zero;
            moveAngle				= Angles.South;
            mode					= new PlayerMotionType();
            jumpStartTile			= -Point2I.One;
            isCapeDeployed			= false;
            doomedToFallInHole		= false;
            holeTile				= null;
            holeDoomTimer			= 0;
            holeSlipVelocity		= Vector2F.Zero;
            fallingInHole			= false;
            isOnColorBarrier		= false;
            isOnSideScrollLadder	= false;
            climbCollisionBox		= new Rectangle2F(-1, -7, 2, 9);

            // Controls.
            analogMode		= false;
            analogStick		= GamePad.GetStick(Buttons.LeftStick);
            analogAngle		= 0.0f;
            moveButtons		= new InputControl[4];
            moveButtons[Directions.Up]		= Controls.Up;
            moveButtons[Directions.Down]	= Controls.Down;
            moveButtons[Directions.Left]	= Controls.Left;
            moveButtons[Directions.Right]	= Controls.Right;

            // Normal movement.
            moveModeNormal = new PlayerMotionType();
            moveModeNormal.MoveSpeed			= 1.0f;
            moveModeNormal.CanLedgeJump			= true;
            moveModeNormal.CanRoomChange		= true;

            // Slow movement.
            moveModeSlow = new PlayerMotionType(moveModeNormal);
            moveModeSlow.MoveSpeed = 0.5f;

            // Grass movement.
            moveModeGrass = new PlayerMotionType(moveModeNormal);
            moveModeGrass.MoveSpeed = 0.75f;

            // Ice movement.
            moveModeIce = new PlayerMotionType();
            moveModeIce.MoveSpeed				= 1.0f;
            moveModeIce.CanLedgeJump			= true;
            moveModeIce.CanRoomChange			= true;
            moveModeIce.IsSlippery				= true;
            moveModeIce.Acceleration			= 0.02f;
            moveModeIce.Deceleration			= 0.05f;
            moveModeIce.MinSpeed				= 0.05f;
            moveModeIce.DirectionSnapCount		= 32;

            // Air/jump movement.
            moveModeAir = new PlayerMotionType();
            moveModeAir.IsStrafing				= true;
            moveModeAir.MoveSpeed				= 1.0f;
            moveModeAir.CanLedgeJump			= false;
            moveModeAir.CanRoomChange			= false;
            moveModeAir.IsSlippery				= true;
            moveModeAir.Acceleration			= 0.1f;
            moveModeAir.Deceleration			= 0.0f;
            moveModeAir.MinSpeed				= 0.05f;
            moveModeAir.DirectionSnapCount		= 8;//32;

            // Water/swim movement.
            moveModeWater = new PlayerMotionType();
            moveModeWater.MoveSpeed				= 0.5f;
            moveModeWater.CanLedgeJump			= true;
            moveModeWater.CanRoomChange			= true;
            moveModeWater.IsSlippery			= true;
            moveModeWater.Acceleration			= 0.08f;
            moveModeWater.Deceleration			= 0.05f;
            moveModeWater.MinSpeed				= 0.05f;
            moveModeWater.DirectionSnapCount	= 32;

            mode = moveModeNormal;
        }
        //-----------------------------------------------------------------------------
        // Update
        //-----------------------------------------------------------------------------
        public void Update()
        {
            // Determine movement mode.
            if (player.RoomControl.IsSideScrolling && isOnSideScrollLadder)
                mode = moveModeNormal;
            else if (player.Physics.IsInAir)
                mode = moveModeAir;
            else if (player.Physics.IsInWater)
                mode = moveModeWater;
            else if (player.Physics.IsOnIce)
                mode = moveModeIce;
            else if (player.Physics.IsOnStairs || player.Physics.IsOnLadder)
                mode = moveModeSlow;
            else if (player.Physics.IsInGrass)
                mode = moveModeGrass;
            else
                mode = moveModeNormal;

            // Update movement.
            UpdateMoveControls();
            UpdateFallingInHoles();
            velocityPrev = player.Physics.Velocity;

            // Update sprinting.
            if (isSprinting) {
                // Create the sprint effect.
                if (sprintTimer % GameSettings.PLAYER_SPRINT_EFFECT_INTERVAL == 0 &&
                    player.IsOnGround && player.CurrentState != player.SwimState)
                {
                    AudioSystem.PlaySound(GameData.SOUND_PLAYER_LAND);
                    Effect sprintEffect = new Effect(GameData.ANIM_EFFECT_SPRINT_PUFF, DepthLayer.EffectSprintPuff, true);
                    player.RoomControl.SpawnEntity(sprintEffect, player.Position);
                }
                sprintTimer--;
                if (sprintTimer <= 0)
                    isSprinting = false;
            }

            // Check for ledge jumping (ledges/waterfalls)
            CollisionInfo collisionInfo = player.Physics.CollisionInfo[moveDirection];
            if (canLedgeJump && mode.CanLedgeJump && isMoving &&
                collisionInfo.Type == CollisionType.Tile &&
                !player.RoomControl.IsSideScrolling)
            {
                Tile tile = collisionInfo.Tile;
                if (tile.IsLedge && moveDirection == tile.LedgeDirection && !tile.IsMoving)
                    TryLedgeJump(tile.LedgeDirection);
            }

            // Check for walking on color barriers.
            if (player.IsOnGround && (player.Physics.TopTile is TileColorBarrier) &&
                ((TileColorBarrier) player.Physics.TopTile).IsRaised)
            {
                IsOnColorBarrier = true;
            }
            else if (player.IsOnGround)
                IsOnColorBarrier = false;

            // Face up if climbing a side-scroll ladder.
            if (player.RoomControl.IsSideScrolling && isOnSideScrollLadder) {
                bool faceUp = false;
                if (HighestSideScrollLadderTile != null)
                    faceUp = (player.Y > HighestSideScrollLadderTile.Bounds.Top + 4.0f);
                if (faceUp && allowMovementControl)
                    player.Direction = Directions.Up;
            }
        }