/// <summary> /// Initializes a new instance of the <see cref="SnakeEngine"/> class. /// </summary> public SnakeEngine(Texture2D buttonTexture2D, SpriteFont buttonTextSpriteFont) { _zoom = 10f; _angleLabel = new Label(buttonTextSpriteFont, "Degrees " , Color.Black); _rightRotationButtons = new Button[NumberOfFigures - 1]; _leftRotationButtons = new Button[NumberOfFigures]; _cubeVertices = new Triangle[NumberOfVertices*2]; for (int i = 0; i < NumberOfFigures; i++) { InitializeTetrahedron(i, true); InitializeTetrahedron(i, false); var i1 = i; if (i != NumberOfFigures) { _leftRotationButtons[i] = new Button(buttonTexture2D, Color.White, buttonTextSpriteFont, "L" + (i + 1), Color.Black) { Click = delegate { Rotate(FindCenterOfRotation(false, i1), i1, false); } }; } if (i == 0) continue; _rightRotationButtons[i - 1] = new Button(buttonTexture2D, Color.White, buttonTextSpriteFont, "R" + i, Color.Black) { Click = delegate { Rotate(FindCenterOfRotation(true, i1), i1, true); } }; } _clearButton = new Button(buttonTexture2D, Color.White, buttonTextSpriteFont, "CLEAR", Color.Black) { Click = delegate { for (int i = 0; i < NumberOfFigures; i++) { InitializeTetrahedron(i, true); InitializeTetrahedron(i, false); } _angleChange = 10; } }; GenerateClickListeners(buttonTexture2D, buttonTextSpriteFont); }
/// <summary> /// Generates the click listeners for all position buttons. /// </summary> /// <param name="buttonTexture2D">The button texture2d.</param> /// <param name="buttonTextSpriteFont">The button text sprite font.</param> private void GenerateClickListeners(Texture2D buttonTexture2D, SpriteFont buttonTextSpriteFont) { Vector2 scale = new Vector2(0.2f, 0.1f); _angleButtons = new Button[2]; _angleButtons[0] = new Button(buttonTexture2D, Color.White, buttonTextSpriteFont, "+", Color.Black) { Click = delegate { _angleChange += 1; }, }; _angleButtons[1] = new Button(buttonTexture2D, Color.White, buttonTextSpriteFont, "-", Color.Black) { Click = delegate { _angleChange -= 1; }, }; _rotationButton = new Button(buttonTexture2D, Color.White, buttonTextSpriteFont, "ROTATE RIGHT", Color.Black) { Click = delegate { _rightDirection = !_rightDirection; _rotationButton.Text = _rightDirection ? "ROTATE RIGHT" : "ROTATE LEFT"; }, }; _zoomInButton = new Button(buttonTexture2D, Color.White, buttonTextSpriteFont, "ZOOM IN", Color.Black) { Click = delegate { _zoom -= PositionChange; }, Scale = scale }; _zoomOutButton = new Button(buttonTexture2D, Color.White, buttonTextSpriteFont, "ZOOM OUT", Color.Black) { Click = delegate { _zoom += PositionChange; }, }; _rightButton = new Button(buttonTexture2D, Color.White, buttonTextSpriteFont, "RIGHT", Color.Black) { Click = delegate { _xPerspective += PositionChange; }, Scale = scale }; _leftButton = new Button(buttonTexture2D, Color.White, buttonTextSpriteFont, "LEFT", Color.Black) { Click = delegate { _xPerspective -= PositionChange; }, Scale = scale }; _upButton = new Button(buttonTexture2D, Color.White, buttonTextSpriteFont, "UP", Color.Black) { Click = delegate { _yPerspective += PositionChange; }, Scale = scale }; _downButton = new Button(buttonTexture2D, Color.White, buttonTextSpriteFont, "DOWN", Color.Black) { Click = delegate { _yPerspective -= PositionChange; }, Scale = scale }; }