Beispiel #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            Vector2 previousGhostPos = ghost.Position;
            Vector2 previousCamPos   = cam.CamPos;

            #region Controls
            if (Keyboard.GetState().IsKeyDown(Keys.W)) //&& ghost.Position.Y <= GraphicsDevice.Viewport.Bounds.Height - ghost.Image.Height)
            {
                ghost.Move(new Vector2(0, -1) * speed);
                cam.Move((new Vector2(0, -1) * speed), GraphicsDevice.Viewport);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.S))// && ghost.Position.Y > 0)
            {
                ghost.Move(new Vector2(0, 1) * speed);
                cam.Move((new Vector2(0, 1) * speed), GraphicsDevice.Viewport);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.A))// && ghost.Position.X > 0)
            {
                ghost.Move(new Vector2(-1, 0) * speed);
                cam.Move((new Vector2(-1, 0) * speed), GraphicsDevice.Viewport);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.D))// && ghost.Position.X <= GraphicsDevice.Viewport.Bounds.Width - ghost.Image.Width)
            {
                ghost.Move(new Vector2(1, 0) * speed);
                cam.Move((new Vector2(1, 0) * speed), GraphicsDevice.Viewport);
            }
            #endregion

            if (!GraphicsDevice.Viewport.Bounds.Contains(ghost.Bounds))
            {
                ghost.Move(previousGhostPos - ghost.Position);
                cam.Move(previousCamPos - cam.CamPos, GraphicsDevice.Viewport);
            }
            // TODO: Add your update logic here

            base.Update(gameTime);
        }