Ejemplo n.º 1
0
        public void Update(GameEngine engine, LinkedList <SnakeChain> snake)
        {
            lastX      = x;
            lastY      = y;
            lastVector = vector;

            if (Input.IsKeyDown(Keys.LEFT) && vector != SnakeChainVector.Right)
            {
                x     -= engine.GetPixel();
                vector = SnakeChainVector.Left;
            }
            else if (Input.IsKeyDown(Keys.RIGHT) && vector != SnakeChainVector.Left)
            {
                x     += engine.GetPixel();
                vector = SnakeChainVector.Right;
            }
            else if (Input.IsKeyDown(Keys.UP) && vector != SnakeChainVector.Down)
            {
                y     -= engine.GetPixel();
                vector = SnakeChainVector.Up;
            }
            else if (Input.IsKeyDown(Keys.DOWN) && vector != SnakeChainVector.Up)
            {
                y     += engine.GetPixel();
                vector = SnakeChainVector.Down;
            }
            else
            {
                SnakeChainVector checkedVector;

                if (isFirst == true)
                {
                    checkedVector = vector;
                }
                else
                {
                    checkedVector = lastVector;
                }

                switch (checkedVector)
                {
                case SnakeChainVector.Left:
                    x -= engine.GetPixel();
                    break;

                case SnakeChainVector.Right:
                    x += engine.GetPixel();
                    break;

                case SnakeChainVector.Up:
                    y -= engine.GetPixel();
                    break;

                case SnakeChainVector.Down:
                    y += engine.GetPixel();
                    break;
                }
            }
        }
Ejemplo n.º 2
0
 public void SetVector(SnakeChainVector newVector)
 {
     vector = newVector;
 }