Пример #1
0
        void sizeChange(ContinuousSnake snake) // random amount of size change to snake
        {
            // get random amount to add or remove
            int delta = mainForm.engine.GetRandom(-BodyPart.SIZE * 4, BodyPart.SIZE * 4);

            snake.ChangeSize(delta);
            finalize();
            Finalized = true; // set flag up for deletion by game engine
        }
Пример #2
0
        void sizeScale(ContinuousSnake snake) // randomly scale snake size
        {
            // list of possible scales
            double[] validScales = new double[] { 0.8, 1.5, 2, 2.5 };  // 6 possible scales
            // get random scale factor
            int random = mainForm.engine.GetRandom(0, 5); double scale = validScales[random];
            // get current length of snake and get size change
            int length    = snake.Length;
            int newLength = (int)(length * scale + 0.5); // get new length (add 0.5 to round)
            int delta     = newLength - length;

            snake.ChangeSize(delta);
            finalize();
            Finalized = true;
        }
Пример #3
0
 void foodCollision(ContinuousSnake snake)
 {
     // check for collision with food
     for (int i = 0; i < foodItems.Count; i++)
     {
         // retrieve current food item
         Food food = foodItems[i];
         if ((snake.Collided(food.picBox) & ContinuousSnake.HEAD_COLLISION) != 0) // check for head collision
         {
             snake.ChangeSize(food.Change);                                       // change snake size depending on food
             // delete the food item
             food.finalize();
             foodItems.Remove(food);
             // subtract one from i to stop from skipping food items
             i--;
         }
     }
 }