Exemplo n.º 1
0
        /// <summary>
        /// Assigns the colliding objects and their touching directions.
        /// </summary>
        /// <param name="objectA">The first object involved in the collision.</param>
        /// <param name="objectB">The second object involved in the collision.</param>
        /// <param name="touchingA">The direction that the first object is colliding in.</param>
        /// <param name="touchingB">The direction that the second object is colliding in.</param>
        public GenCollideEvent(GenObject objectA, GenObject objectB, GenObject.Direction touchingA, GenObject.Direction touchingB)
        {
            ObjectA = objectA;
            ObjectB = objectB;
            TouchingA = touchingA;
            TouchingB = touchingB;

            // TODO: Return the force of the collision as well.
        }
Exemplo n.º 2
0
 /// <summary>
 /// Clears the movement directions of the control object to prepare for the next update.
 /// </summary>
 public override void PreUpdate()
 {
     // Clear the bit field for the control object movement directions.
     MoveState = GenObject.Direction.None;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Moves the control object along the y-axis.
        /// </summary>
        /// <param name="speedFactor">The factor determining the amount of the y movement speed to use, a value from -1.0 (up) to 1.0 (down).</param>
        public void MoveY(float speedFactor)
        {
            if (MovementType == Movement.Instant)
                ControlObject.Velocity.Y = MathHelper.Clamp(MovementSpeedY, 0f, ControlObject.MaxVelocity.Y) * speedFactor;
            else if (MovementType == Movement.Accelerates)
                ControlObject.Acceleration.Y = MovementSpeedY * speedFactor;

            if (speedFactor < 0)
                MoveState |= GenObject.Direction.Up;
            else if (speedFactor > 0)
                MoveState |= GenObject.Direction.Down;

            SetState(State.Moving);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Moves the control object along the x-axis.
        /// </summary>
        /// <param name="speedFactor">The factor determining the amount of the x movement speed to use, a value from -1.0 (left) to 1.0 (right).</param>
        public void MoveX(float speedFactor)
        {
            if (MovementType == Movement.Instant)
                ControlObject.Velocity.X = MathHelper.Clamp(MovementSpeedX, 0f, ControlObject.MaxVelocity.X) * speedFactor;
            else if (MovementType == Movement.Accelerates)
            {
                // If the control object is being moved in the opposite direction it is currently moving, set its x velocity to 0 to prevent delayed movement from acceleration.
                if (((ControlObject.Velocity.X < 0) && (speedFactor > 0)) || ((ControlObject.Velocity.X > 0) && (speedFactor < 0)))
                    ControlObject.Velocity.X = 0f;

                ControlObject.Acceleration.X = MovementSpeedX * speedFactor;
            }

            if (speedFactor < 0)
            {
                MoveState |= GenObject.Direction.Left;
                (ControlObject as GenSprite).Facing = GenObject.Direction.Left;
            }
            else if (speedFactor > 0)
            {
                MoveState |= GenObject.Direction.Right;
                (ControlObject as GenSprite).Facing = GenObject.Direction.Right;
            }

            if ((ControlMode == ControlType.TopDown) || !_inAir)
                SetState(State.Moving);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sets up a control scheme for moving a given object.
        /// </summary>
        /// <param name="controlObject">The object that is controlled.</param>
        /// <param name="controlMode">The type of control available to the control object.</param>
        /// <param name="movementType">How acceleration or velocity should be handled as the object moves.</param>
        /// <param name="stoppingType">How acceleration or velocity should be handled as the object stops.</param>
        /// <param name="playerIndex">The index number of the player controlling the object.</param>
        public GenControl(GenObject controlObject, ControlType controlMode = ControlType.TopDown, Movement movementType = Movement.Instant, Stopping stoppingType = Stopping.Instant, PlayerIndex playerIndex = PlayerIndex.One)
        {
            ControlMode = controlMode;
            ControlObject = controlObject;
            MovementType = movementType;
            StoppingType = stoppingType;
            PlayerIndex = playerIndex;
            _keyboardControls = new Keys[5];
            _gamePadControls = new Buttons[5];
            ButtonsSpecial = GenGamePad.ButtonsSpecial.None;
            UseInput = true;
            #if WINDOWS
            UseKeyboard = true;
            #endif
            UseGamePad = true;
            MovementSpeedX = 0;
            MovementSpeedY = 0;
            JumpSpeed = 0;
            JumpInheritVelocity = false;
            JumpCount = 1;

            // Start the jump counter at 1, since the control object spawns in the air initially.
            _jumpCounter = 1;

            Gravity = Vector2.Zero;
            _inAir = true;_state = State.Idle;
            MoveState = GenObject.Direction.None;
            IdleAnimation = null;
            MoveAnimation = null;
            JumpAnimation = null;
            FallAnimation = null;
            UseSpeedAnimation = false;
            MinAnimationFps = 0f;
            MaxAnimationFps = 12f;
            JumpCallback = null;
            LandCallback = null;

            // Set the default movement direction keyboard controls.
            SetDirectionControls(Keys.Left, Keys.Right, Keys.Up, Keys.Down);

            // Set the default jumping keyboard control.
            SetJumpControl(Keys.Space);

            // Set the default movement direction game pad controls.
            SetDirectionControls(Buttons.LeftThumbstickLeft, Buttons.LeftThumbstickRight, Buttons.LeftThumbstickUp, Buttons.LeftThumbstickDown);

            // Set the default jumping game pad control.
            SetJumpControl(Buttons.A);
        }