Esempio 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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            player.Update(gameTime);
            if (Collisions.CollidesWith(player.bounds, winItem.bounds))
            {
                Exit();
            }
            // TODO: Add your update logic here

            base.Update(gameTime);
        }
Esempio n. 2
0
        public void Update(GameTime gameTime)
        {
            var newKeyboardState = Keyboard.GetState();

            if (newKeyboardState.IsKeyDown(Keys.Up))
            {
                foreach (GrassBlock block in blocks)
                {
                    if (block != null)
                    {
                        if (Collisions.TouchingBottom(this.bounds, block.bounds))
                        {
                            touchcheck = true;
                        }
                    }
                }
                if (!touchcheck)
                {
                    bounds.Y    -= (int)gameTime.ElapsedGameTime.TotalMilliseconds / 2;
                    viewbound.Y -= (int)gameTime.ElapsedGameTime.TotalMilliseconds / 2;
                }

                touchcheck = false;
            }
            if (newKeyboardState.IsKeyDown(Keys.Down))
            {
                foreach (GrassBlock block in blocks)
                {
                    if (block != null)
                    {
                        if (Collisions.TouchingTop(this.bounds, block.bounds))
                        {
                            touchcheck = true;
                        }
                    }
                }
                if (!touchcheck)
                {
                    bounds.Y    += (int)gameTime.ElapsedGameTime.TotalMilliseconds / 2;
                    viewbound.Y += (int)gameTime.ElapsedGameTime.TotalMilliseconds / 2;
                }
                touchcheck = false;
            }
            if (newKeyboardState.IsKeyDown(Keys.Left))
            {
                foreach (GrassBlock block in blocks)
                {
                    if (block != null)
                    {
                        if (Collisions.TouchingRight(this.bounds, block.bounds))
                        {
                            touchcheck = true;
                        }
                    }
                }
                if (!touchcheck)
                {
                    bounds.X    -= (int)gameTime.ElapsedGameTime.TotalMilliseconds / 2;
                    viewbound.X -= (int)gameTime.ElapsedGameTime.TotalMilliseconds / 2;
                }
                touchcheck = false;
            }
            if (newKeyboardState.IsKeyDown(Keys.Right))
            {
                foreach (GrassBlock block in blocks)
                {
                    if (block != null)
                    {
                        if (Collisions.TouchingLeft(this.bounds, block.bounds))
                        {
                            touchcheck = true;
                        }
                    }
                }
                if (!touchcheck)
                {
                    bounds.X    += (int)gameTime.ElapsedGameTime.TotalMilliseconds / 2;
                    viewbound.X += (int)gameTime.ElapsedGameTime.TotalMilliseconds / 2;
                }
                touchcheck = false;
            }

            if (bounds.Y < 0)
            {
                bounds.Y = 0;
            }
            ;
            if (bounds.Y > game.GraphicsDevice.Viewport.Height - bounds.Height)
            {
                bounds.Y = game.GraphicsDevice.Viewport.Height - bounds.Height;
            }
            if (bounds.X < 0)
            {
                bounds.X = 0;
            }
            ;
            if (bounds.X > game.GraphicsDevice.Viewport.Width - bounds.Width)
            {
                bounds.X = game.GraphicsDevice.Viewport.Width - bounds.Width;
            }

            oldKeyboardState = Keyboard.GetState();
        }