Beispiel #1
6
 //initial the game
 public void Initialize()
 {
     inputControllerP1 = new InputController(Keys.A, Keys.D, Keys.W, Keys.S);
     inputControllerP2 = new InputController(Keys.Left, Keys.Right, Keys.Up, Keys.Down);
     snake = new Snake(inputControllerP1,Resources.tail2);
     food = new Food();
     foodCount = 0;
     timeCount = 0;
 }
Beispiel #2
0
        /// <summary>
        /// Snake movment anamation
        /// </summary>
        /// <param name="inputController">give a set of keys to controller</param>
        /// <param name="resources">which texture is to draw</param>
        public Snake(InputController inputController, Texture2D resources)
        {
            this.inputController = inputController;
            this.resources = resources;

            // Initialize snake
            body = new List<Vector2>();

            // Initialize head of snake on the middle of the screen
            body.Add(new Vector2(WIDTH / 2, HEIGHT / 2));

            // body to the left of the body
            for (int i = 0; i < INIT_BODY_LENGTH; i++)
            {
                body.Add(Head - (Vector2.UnitX * (i + 1)));
            }

            // Initialize moving to the right
            direction = Direction.Right;
        }