Ejemplo n.º 1
0
 public Snake(int length)
 {
     alive = true;
     position = new Coordinates(Global.snakeStartingPosition);
     head = new SnakeHead(Global.defaultSnakeHeadTexture, position);
     /* Link snake position to head position. */
     this.position = head.position;
     body = new SnakeBody(Global.defaultSnakeBodyTexture, position, length);
 }
Ejemplo n.º 2
0
        public void Update(SnakeHead head)
        {
            bodyParts[0].parentPosition.SetTo(head.position);

            // Move first element
            if(!bodyParts[0].targetPosition.Equals(bodyParts[0].parentPosition)){
                // Save previous position
                bodyParts[0].previousPosition.SetTo(bodyParts[0].position);
                // Set position to target position
                bodyParts[0].position.SetTo(bodyParts[0].targetPosition);
                // Set new target position
                bodyParts[0].targetPosition.SetTo(head.position);
            }

            // Save the location of the snakes trail
            trailPosition = new Coordinates(bodyParts.Last().previousPosition);

            // Rest should follow suit
            for (int i = 1; i < bodyParts.Count; i++)
            {
                // Update each part with its superior part
                bodyParts[i].Update(bodyParts[i-1]);
                                // Check for self-cannibalism while you are at it, hunny.
                if (bodyParts[i].position.Equals(head.position))
                {
                    isBitten = true;
                }

            }
        }