public SnakeType() { body = new List <BodyType>(); curves = new Dictionary <Vector2, CurveType>(); head = new HeadType(); tail = new TailType(); temp = new CurveType(); for (int i = 0; i < 4; i++) { BodyType segment = new BodyType(i + 2); body.Add(segment); } currentSegment = 3; }
/// <summary> /// Turns the snake based on the input from the user. /// </summary> /// <param name="i">The game's input handler</param> private void turn(InputHandlerComponent i) { //The new orientation of the snake OrientationType newOrientation = head.Orientation; //Get the new orientation based on the input if (i.getButton("Right", true) && head.Orientation != OrientationType.left) { newOrientation = OrientationType.right; } else if (i.getButton("Up", true) && head.Orientation != OrientationType.down) { newOrientation = OrientationType.up; } else if (i.getButton("Down", true) && head.Orientation != OrientationType.up) { newOrientation = OrientationType.down; } else if (i.getButton("Left", true) && head.Orientation != OrientationType.right) { newOrientation = OrientationType.left; } //If there has been a change in the orientation, add a curve and change the snake if (newOrientation != head.Orientation) { CurveType curve = new CurveType(); curve.deepCopy(temp); curve.Vector = head.Vector; curve.Orientation = newOrientation; curve.Rotation = MovementFunctions.calculateCurveRotation(head.Orientation, newOrientation); curves.Add(curve.Vector, curve); head.Orientation = newOrientation; canTurn = false; } }