Beispiel #1
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            //================================
            // test
            if (KeyboardAndMouse.HasBeenPressed(Keys.F))
            {
                Console.WriteLine("PRESSED BUTTON");
                OrderNumber = 1;
            }

            Move(gameTime);
        }
Beispiel #2
0
        /// <summary>
        /// Handles input from the user. Input includes moving the camera and camerazoom.
        /// </summary>
        private static void HandleInput()
        {
            //KeyboardState keyState = KeyboardAndMouse.GetState();
            velocity = Vector2.Zero;

            if (KeyboardAndMouse.IsPressed(Keys.W) && CamPos.Y > 0 + (GameWorld.ScrSize.Y / 2))             // Up
            {
                velocity.Y -= 1;
            }

            if (KeyboardAndMouse.IsPressed(Keys.S) && CamPos.Y < 0 + Asset.BackgroundPic.Height - GameWorld.ScrSize.Y / 2)             // Down
            {
                velocity.Y += 1;
            }

            if (KeyboardAndMouse.IsPressed(Keys.A) && CamPos.X > 0 + (GameWorld.ScrSize.X / 2))             // Left
            {
                velocity.X -= 1;
            }

            if (KeyboardAndMouse.IsPressed(Keys.D) && CamPos.X < 0 + Asset.BackgroundPic.Width - GameWorld.ScrSize.X / 2)             // Right
            {
                velocity.X += 1;
            }


            //if (keyState.IsKeyDown(Keys.E)) // Zoom in
            //{
            //	CamZoom += 0.05f * CamZoom; // value * CamZoom to negate warping effect
            //}
            //else if (GameWorld.Mousestate.ScrollWheelValue > previousScrollValue)
            //{
            //    CamZoom += 0.05f * CamZoom * 5;
            //}

            //if (keyState.IsKeyDown(Keys.Q)) // Zoom out
            //{
            //	CamZoom -= 0.05f * CamZoom;
            //}
            //else if (GameWorld.Mousestate.ScrollWheelValue < previousScrollValue)
            //{
            //    CamZoom -= 0.05f * CamZoom * 5;
            //}

            // Changes cameraposition based on velocity multiplied by speed. Speed is divided by CamZoom to avoid slowing down when zooming in
            // or speeding up when zooming out.
            CamPos += velocity * speed / CamZoom;;

            //previousScrollValue = GameWorld.Mousestate.ScrollWheelValue;
        }
        /// <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 || KeyboardAndMouse.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            // TODO: Add your update logic here
            Camera.Update();
            mouseState = Mouse.GetState();
            Point      = new Point(mouseState.X + (int)(Camera.CamPos.X - Camera.CamPosStart.X), mouseState.Y + (int)(Camera.CamPos.Y - Camera.CamPosStart.Y));

            // TODO: Add your update logic here

            Camera.Update();

            foreach (GameObject gameObject in GameObjects)
            {
                //Update all objects in active room
                gameObject.Update(gameTime);
                foreach (GameObject other in GameObjects)
                {
                    gameObject.CheckCollision(other);
                }
            }

            // Adds new objects to rooms
            foreach (GameObject gameObject in NewGameObjects)
            {
                GameObjects.Add(gameObject);
            }
            NewGameObjects.Clear();

            // Removes gameobjects from the map.
            foreach (GameObject gameObject in RemoveGameObjects)
            {
                GameObjects.Remove(gameObject);
            }
            RemoveGameObjects.Clear();

            base.Update(gameTime);
        }