예제 #1
0
        /// <summary>
        /// Windows Controls
        /// </summary>
        /// <param name="gameTime">Time since the last update</param>
        void WindowsInput(GameTime gameTime)
        {
            // Space for missile and bomb
            if (Keyboard.KeyPressed(Keys.Space))
            {
                if (direction == ChopperDirections.Forward)
                {
                    DropBomb();
                }
                else
                {
                    FireMissile();
                }
            }

            // Right and left
            if (Keyboard.KeyDown(Keys.Right))
            {
                XSpeed += Accaleration * 2 * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (XSpeed > DirectionChangeSpeed)
                {
                    if (direction != ChopperDirections.Right)
                    {
                        direction = ChopperDirections.Right;
                        SetCostume(ChopperRight);
                    }
                }
                else
                {
                    if (direction != ChopperDirections.Forward)
                    {
                        direction = ChopperDirections.Forward;
                        SetCostume(ChopperFront);
                    }
                }
            }
            else if (Keyboard.KeyDown(Keys.Left))
            {
                XSpeed -= Accaleration * 2 * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (XSpeed < DirectionChangeSpeed * -1)
                {
                    if (direction != ChopperDirections.Left)
                    {
                        direction = ChopperDirections.Left;
                        SetCostume(ChopperLeft);
                    }
                }
                else
                {
                    if (direction != ChopperDirections.Forward)
                    {
                        direction = ChopperDirections.Forward;
                        SetCostume(ChopperFront);
                    }
                }
            }
            else
            {
                // When you let go of left or right, auto-level out
                if (XSpeed > 0)
                {
                    XSpeed -= ChopperLeveling * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
                else if (XSpeed < 0)
                {
                    XSpeed += ChopperLeveling * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
            }

            // Up and Down
            if (Keyboard.KeyDown(Keys.Up))
            {
                YSpeed += Accaleration * (float)gameTime.ElapsedGameTime.TotalSeconds;
                float GroundY = (Scene as PlayScene).GroundY;
                if (Y <= GroundY && YSpeed < 0.5f)
                {
                    YSpeed = 0.5f;
                }
            }
            else if (Keyboard.KeyDown(Keys.Down))
            {
                YSpeed -= Accaleration * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            else
            {
                YSpeed -= ChopperGravity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            AnimationSpeed = 1 / Math.Min((0.1f / Math.Max(YSpeed, 0)), 1f);
            Rotation = 45f * (XSpeed / MaxXSpeed);
        }
예제 #2
0
        /// <summary>
        /// Phone Controls
        /// </summary>
        /// <param name="gameTime">Time since the last update</param>
        void PhoneInput(GameTime gameTime)
        {
            // Tap for missile and bomb
            if (Touch.Taps.Any())
            {
                if (direction == ChopperDirections.Forward)
                {
                    DropBomb();
                }
                else
                {
                    FireMissile();
                }
            }

            // Left and right
            Rotation = Accelerometer.Y * -90f;
            if (Rotation > 45)
            {
                Rotation = 45;
            }
            else if (Rotation < -45)
            {
                Rotation = -45;
            }

            XSpeed = Rotation * MaxXSpeed * Accaleration * (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (XSpeed > DirectionChangeSpeed)
            {
                if (direction != ChopperDirections.Right)
                {
                    direction = ChopperDirections.Right;
                    SetCostume(ChopperRight);
                }
            }
            else if (XSpeed < DirectionChangeSpeed * -1)
            {
                if (direction != ChopperDirections.Left)
                {
                    direction = ChopperDirections.Left;
                    SetCostume(ChopperLeft);
                }
            }
            else if (Math.Abs(XSpeed) < DirectionChangeSpeed * .8) // Anti-jitter
            {
                if (direction != ChopperDirections.Forward)
                {
                    direction = ChopperDirections.Forward;
                    SetCostume(ChopperFront);
                }
            }

            // Up and down
            float YTarget = Accelerometer.Z * -300f;
            YSpeed = (float)(YTarget - Y) * Accaleration * (float)gameTime.ElapsedGameTime.TotalSeconds;

            AnimationSpeed = 1 / Math.Min((0.1f / Math.Max(YSpeed, 0)), 1f);
        }