Ejemplo n.º 1
0
        private void HandleCollision()
        {
            CollisionType collision = collisionManager.Collision(grid, snake);

            if (collision == CollisionType.PowerUp)
            {
                snake.AddTail();
                grid.Clear(snake.X, snake.Y);
                grid.AddRandomPowerUp(snake.GetPositions());
            }

            if (collision == CollisionType.Fatal)
            {
                Exit();
            }
        }
Ejemplo n.º 2
0
        protected override void Update(GameTime gameTime)
        {
            KeyboardState state = Keyboard.GetState();

            if (state.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (_gameOver)
            {
                if (state.IsKeyDown(Keys.Space))
                {
                    ResetGame();
                }

                return;
            }

            _snake.Update((float)gameTime.ElapsedGameTime.TotalSeconds);

            if (IsPositionOnBorder(_snake.HeadPosition))
            {
                _gameOver = true;
            }

            if (_snake.IsPositionInBody(_foodPosition))
            {
                _score++;

                _snake.AddTail();
                SetRandomFoodPosition();
            }

            base.Update(gameTime);
        }