示例#1
0
        public void ControlActivity()
        {
            #if FLYING
            if (InputManager.Keyboard.KeyDown(Keys.Space))
            {
                PlayerInstance.YVelocity = 20;

            }
            #endif
            if (InputManager.Keyboard.KeyDown(Keys.Space) && Grounded())
            {
                PlayerInstance.YVelocity = 20;
                PlayerInstance.playerState = State.JUMPING;
            }

            if (InputManager.Keyboard.KeyDown(Keys.D))
            {
                PlayerInstance.XVelocity = 10;
                PlayerInstance.playerState = State.WALKING;
            }
            else if (InputManager.Keyboard.KeyDown(Keys.A))
            {
                PlayerInstance.XVelocity = -10;
                PlayerInstance.playerState = State.WALKING;
            }
            else
            {
                PlayerInstance.XVelocity = 0;
                PlayerInstance.playerState = State.IDLE;
            }

            if (InputManager.Mouse.ButtonPushed(Mouse.MouseButtons.LeftButton) && InputManager.Mouse.IsInGameWindow())
            {
                Bullet bullet = new Bullet(this.ContentManagerName);
                Random rand = new Random();
                bullet.X = PlayerInstance.X + 2 + rand.Next(2);
                bullet.Y = PlayerInstance.Y - 0.5f;
                bullet.XVelocity = 50 + rand.Next(10);
                bullet.RotationZ = rand.Next(360);

                bullets.Add(bullet);
            }
        }
示例#2
0
        private bool BulletGrounded(Bullet bullet)
        {
            // Assumes that PlayerInstance is an Entity that has a Collision shape property and
            // that LevelCollision is a valid ShapeCollection
            if (bullet.Body.CollideAgainstBounce(SceneBounds, 0, 1, 0))
            {
                // There has been a collision
                bool wasRepositionedUpward = bullet.Body.LastMoveCollisionReposition.Y > 0;

                // If the PlayerInstance was repositioned upward, then that means it was on a surface
                bullet.IsOnGround = wasRepositionedUpward;
            }
            else
            {
                // Since no collision occurred, the player isn't on the ground
                bullet.IsOnGround = false;
            }
            return bullet.IsOnGround;
        }