Exemple #1
0
        // I am a bit sad that this method turned out to be responsable for
        // managing the whole snake and not just moving it
        public bool Move()
        {
            PosChixel snakeHead = chixelList.First();
            PosChixel snakeTail = chixelList.Last();

            // Apply movement gotten from the controls to snake

            // Why is there a stack here, you ask? Well it's made so that if (between updates) the player presses
            // something that causes a change in direction
            // then follows it up by something that doesn't, the latest change causing press is applied and not caneled
            // this will hopefully make the controls more responsive.
            while (deltaDirectionStack.Count != 0)
            {
                Directions outDirection;
                if (!deltaDirectionStack.TryPop(out outDirection))
                {
                    continue;
                }
                if (DoesDirectionCauseTurn(outDirection))
                {
                    CurrentDirection = outDirection;
                    break;
                }
            }
            deltaDirectionStack.Clear();

            // Change in the position of the head.
            (int deltaX, int deltaY) = Utility.DirectionToXY(CurrentDirection);

            int newX = snakeHead.x + deltaX;

            // Implement looping around the screen like pacman
            if (newX > FrameBuffer.Instance.Width - 1)
            {
                newX = FrameBuffer.Instance.Left;
            }
            else if (newX < FrameBuffer.Instance.Left)
            {
                newX = FrameBuffer.Instance.Width - 1;
            }

            int newY = snakeHead.y + deltaY;

            // Implement looping around the screen like pacman
            if (newY > FrameBuffer.Instance.Height - 1)
            {
                newY = FrameBuffer.Instance.Top;
            }
            else if (newY < FrameBuffer.Instance.Top)
            {
                newY = FrameBuffer.Instance.Height - 1;
            }

            // Eat the Growthball if on it;
            if (GrowthBall.GrowthBallDict.ContainsKey((newX, newY)))
            {
                this.Grow(GrowthBall.GrowthBallDict[(newX, newY)].GrowthValue);
                GrowthBall.EatAt(newX, newY);
            }
Exemple #2
0
 public PosChixel(PosChixel other) : this(other.x, other.y, other)
 {
 }
Exemple #3
0
 public static void SetChixel(this FrameBuffer frame, PosChixel posChixel)
 {
     frame.SetChixel(posChixel.x, posChixel.y, posChixel);
 }