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

                if (columns.Count == 0)
                {
                    columns.Add(new Columns(Content.Load <Texture2D>("pipe-green"), 320));
                }

                if (Keyboard.GetState().IsKeyDown(Keys.Space) && !beforeJumpStatus && !bird.isDead)
                {
                    bird.Jump();
                }
                if (Keyboard.GetState().IsKeyDown(Keys.Space))
                {
                    beforeJumpStatus = true;
                }
                else
                {
                    beforeJumpStatus = false;
                }
                if (!bird.isDead)
                {
                    bird.Move(1);
                }
                for (int i = 0; i < columns.Count; i++)
                {
                    if (columns[i].x + columns[i].columnTexture.Width < 0)
                    {
                        columns.RemoveAt(i);
                    }
                }

                for (int i = 0; i < columns.Count; i++)
                {
                    if (!bird.isDead)
                    {
                        columns[i].Move(1);
                        columns[i].Colide(ref bird);
                    }
                }

                if (bird.isDead)
                {
                    isGameOver = true;
                }

                Console.WriteLine(bird.score);
                delay -= 30;
            }

            base.Update(gameTime);
        }
Beispiel #2
0
 public void Jump()
 {
     player.Jump();
 }