Ejemplo n.º 1
0
 private void Die(GameEngine engine)
 {
     GameOver = true;
 }
Ejemplo n.º 2
0
        private void MovePlayer(GameEngine engine)
        {
            for (int i = snake.Count - 1; i >= 0; i--)
            {
                if (i == 0)
                {
                    switch (Direction)
                    {
                    case Direction.Right:
                        snake[i].SpeedX = 1;
                        snake[i].SpeedY = 0;
                        break;

                    case Direction.Left:
                        snake[i].SpeedX = -1;
                        snake[i].SpeedY = 0;
                        break;

                    case Direction.Down:
                        snake[i].SpeedX = 0;
                        snake[i].SpeedY = 1;
                        break;

                    case Direction.Up:
                        snake[i].SpeedX = 0;
                        snake[i].SpeedY = -1;
                        break;
                    }

                    snake[i].X += snake[i].SpeedX;
                    snake[i].Y += snake[i].SpeedY;

                    int maxXPos = fieldWidth / head.Width;
                    int maxYPos = fieldHeight / head.Height;

                    if (snake[0].X < 0 || snake[0].Y < 0 || snake[0].X >= maxXPos || snake[0].Y >= maxYPos)
                    {
                        Die(engine);
                    }

                    for (int j = 1; j < snake.Count; j++)
                    {
                        if (snake[i].X == snake[j].X && snake[i].Y == snake[j].Y)
                        {
                            Die(engine);
                        }
                    }

                    if (snake[0].X == food.X && snake[0].Y == food.Y)
                    {
                        Eat(engine);
                    }
                }

                else
                {
                    snake[i].X = snake[i - 1].X;
                    snake[i].Y = snake[i - 1].Y;
                }
            }
        }
 public void Update(GameEngine engine)
 {
     x += speedX;
     y += speedY;
 }