示例#1
0
 public void Update(SnakeSection[] snake, GameArea gameArea)
 {
     if (!IsAlive)
     {
         IsAlive = true;
         ok = false;
         while (!ok)
         {
             int x = rnd.Next(gameArea.LeftBound / Texture.Width, gameArea.RightBound / Texture.Width) * Texture.Width;
             int y = rnd.Next(0, Global.GraphicsManager.PreferredBackBufferHeight / Texture.Height) * Texture.Height;
             base.Rectangle = new Rectangle(x, y, Texture.Width, Texture.Height);
             ok = true;
             for (int i = 0; i < snake.Length; i++)
             {
                 if (snake[i].Rectangle.Intersects(base.Rectangle)) ok = false;
             }
         }
         IsAlive = true;
     }
 }
示例#2
0
        private void Initialize()
        {
            snakeSize = 5;
            snakeSectionArray = new SnakeSection[snakeSize];
            for(int i = 0; i < snakeSectionArray.Length; i++)
            {
                int x = ( Global.Viewport.Width / Global.TextureWidth) / 2 * Global.TextureWidth;
                int y = ( Global.Viewport.Height / Global.TextureHeight) / 2 * Global.TextureHeight;

                if(Global.TextureWidth == 20)
                {
                    snakeSectionArray[i] = new SnakeSection("Snake/SmallSize/middle", new Rectangle(x + i * Global.TextureWidth, y, Global.TextureWidth, Global.TextureHeight));
                }
                else
                {
                    snakeSectionArray[i] = new SnakeSection("Snake/MediumSize/middle", new Rectangle(x + i * Global.TextureWidth, y, Global.TextureWidth, Global.TextureHeight));
                }
            }
        }