Exemplo n.º 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)
        {
            msm.PreUpdate(gameTime);
            kbm.PreUpdate(gameTime);

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }



            // TODO: Add your update logic here

            base.Update(gameTime);
        }
Exemplo n.º 2
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)
        {
            msm.PreUpdate(gameTime);
            kbm.PreUpdate(gameTime);
            base.Update(gameTime);

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || kbm.KeyDown(Keys.Escape))
            {
                Exit();
            }

            // Camera controls..
            float speedTran = .1f;
            float speedRot  = .01f;

            if (kbm.KeyDown(Keys.W) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y > 0)
            {
                camera.Translate(Vector3.Forward * speedTran);
            }
            if (kbm.KeyDown(Keys.S) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y < 0)
            {
                camera.Translate(Vector3.Backward * speedTran);
            }
            if (kbm.KeyDown(Keys.A) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X < 0)
            {
                camera.Translate(Vector3.Left * speedTran);
            }
            if (kbm.KeyDown(Keys.D) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X > 0)
            {
                camera.Translate(Vector3.Right * speedTran);
            }

            if (kbm.KeyDown(Keys.Left) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X < 0)
            {
                camera.Rotate(Vector3.Up, speedRot);
            }
            if (kbm.KeyDown(Keys.Right) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X > 0)
            {
                camera.Rotate(Vector3.Up, -speedRot);
            }
            if (kbm.KeyDown(Keys.Up) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y > 0)
            {
                camera.Rotate(Vector3.Right, speedRot);
            }
            if (kbm.KeyDown(Keys.Down) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y < 0)
            {
                camera.Rotate(Vector3.Right, -speedRot);
            }


            float cdv = .1f;

            if (kbm.KeyDown(Keys.R))
            {
                cube.HatchDencity  += cdv;
                bunny.HatchDencity += cdv;
                earth.HatchDencity += cdv;
            }

            if (kbm.KeyDown(Keys.F))
            {
                cube.HatchDencity  -= cdv;
                bunny.HatchDencity -= cdv;
                earth.HatchDencity -= cdv;
            }
        }
Exemplo n.º 3
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)
        {
            msm.PreUpdate(gameTime);
            kbm.PreUpdate(gameTime);
            base.Update(gameTime);

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || kbm.KeyDown(Keys.Escape))
            {
                Exit();
            }

            // Camera controls..
            float speedTran = .1f;
            float speedRot  = .01f;

            if (kbm.KeyDown(Keys.W) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y > 0)
            {
                camera.Translate(Vector3.Forward * speedTran);
            }
            if (kbm.KeyDown(Keys.S) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y < 0)
            {
                camera.Translate(Vector3.Backward * speedTran);
            }
            if (kbm.KeyDown(Keys.A) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X < 0)
            {
                camera.Translate(Vector3.Left * speedTran);
            }
            if (kbm.KeyDown(Keys.D) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X > 0)
            {
                camera.Translate(Vector3.Right * speedTran);
            }

            if (kbm.KeyDown(Keys.Left) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X < 0)
            {
                camera.Rotate(Vector3.Up, speedRot);
            }
            if (kbm.KeyDown(Keys.Right) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X > 0)
            {
                camera.Rotate(Vector3.Up, -speedRot);
            }
            if (kbm.KeyDown(Keys.Up) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y > 0)
            {
                camera.Rotate(Vector3.Right, speedRot);
            }
            if (kbm.KeyDown(Keys.Down) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y < 0)
            {
                camera.Rotate(Vector3.Right, -speedRot);
            }

            // Do picking
            if (msm.LeftClicked)
            {
                float minD = float.MaxValue;

                foreach (Base3DObject obj in sceneObjects)
                {
                    BoundingBox tbb = GameComponentHelper.TransformedBoundingBoxAA(obj.BoundingBox, obj.Position, obj.Scale);
                    float       d   = GameComponentHelper.RayPicking(msm.ScreenPoint, tbb, camera);

                    if (d < minD)
                    {
                        minD = d;
                        if (selected != null)
                        {
                            selected.DrawBoxBounds = false;
                        }
                        selected = obj;
                        selected.DrawBoxBounds = true;
                    }
                }

                if (minD == float.MaxValue)
                {
                    if (selected != null)
                    {
                        selected.DrawBoxBounds = false;
                    }

                    selected = null;
                }
            }
        }