public static void Main() { //Start the audio system so sound can be played SwinGame.OpenAudio(); //Open the game window SwinGame.OpenGraphicsWindow("GameMain", 800, 600); SwinGame.ShowSwinGameSplashScreen(); //Run the game loop Drawing myDrawing = new Drawing(); ShapeKind KindToAdd = new ShapeKind(); KindToAdd = ShapeKind.Circle; while (false == SwinGame.WindowCloseRequested()) { //Fetch the next batch of UI interaction SwinGame.ProcessEvents(); //Clear the screen and draw the framerate SwinGame.ClearScreen(Color.White); myDrawing.Draw(); SwinGame.DrawFramerate(0, 0); // Adds shape if left click if (SwinGame.MouseClicked(MouseButton.LeftButton)) { Shape newShape; if (KindToAdd == ShapeKind.Circle) { Circle newCircle = new Circle(); newCircle.PosX = SwinGame.MouseX(); newCircle.PosY = SwinGame.MouseY(); newShape = newCircle; } else if (KindToAdd == ShapeKind.Rectangle) { Rectangle newRect = new Rectangle(); newRect.PosX = SwinGame.MouseX(); newRect.PosY = SwinGame.MouseY(); newShape = newRect; } else { Line newLine = new Line(); newLine.PosX = SwinGame.MouseX() - 40; newLine.PosY = SwinGame.MouseY(); newLine.PosXEnd = SwinGame.MouseX() + 40; newLine.PosYEnd = SwinGame.MouseY(); newShape = newLine; } myDrawing.AddShape(newShape); } // Selects || Deselects shape if (SwinGame.MouseClicked(MouseButton.RightButton)) { myDrawing.SelectShapesAt(SwinGame.MousePosition()); } // Deletes selected shapes if ((SwinGame.KeyDown(KeyCode.BackspaceKey)) || (SwinGame.KeyDown(KeyCode.DeleteKey))) { myDrawing.RemoveShapes(); } // Changes background color if space pressed. if (SwinGame.KeyDown(KeyCode.SpaceKey)) { myDrawing.Background = SwinGame.RandomColor(); } //Press R change KindToAdd to Rectangle if (SwinGame.KeyDown(KeyCode.RKey)) { KindToAdd = ShapeKind.Rectangle; } //Press C KindToAdd to change to Circle if (SwinGame.KeyDown(KeyCode.CKey)) { KindToAdd = ShapeKind.Circle; } //Press L KindToAdd to change to Line if (SwinGame.KeyDown(KeyCode.LKey)) { KindToAdd = ShapeKind.Line; } if (SwinGame.KeyDown(KeyCode.SKey)) { myDrawing.Save("ShapeSaveFile.txt"); } if (SwinGame.KeyDown(KeyCode.OKey)) { try { myDrawing.Load("ShapeSaveFile.txt"); } catch (Exception e) { Console.WriteLine("Error loading file: {0}", e.Message); } } SwinGame.RefreshScreen(60); } }
public static void Main() { ShapeKind kindToAdd; kindToAdd = ShapeKind.Rectangle; // Open the game window SwinGame.OpenGraphicsWindow("GameMain", 800, 600); // SwinGame.ShowSwinGameSplashScreen(); Drawing drawing = new Drawing(); //Run the game loop while (false == SwinGame.WindowCloseRequested()) { // Fetch the next batch of UI interaction SwinGame.ProcessEvents(); // Clear the screen and draw the framerate SwinGame.ClearScreen(drawing.Background); SwinGame.DrawFramerate(0, 0); // Sets shape type based on user input if (Input.KeyTyped(KeyCode.RKey)) { kindToAdd = ShapeKind.Rectangle; } else if (Input.KeyTyped(KeyCode.CKey)) { kindToAdd = ShapeKind.Circle; } else if (Input.KeyTyped(KeyCode.LKey)) { kindToAdd = ShapeKind.Line; } // Sets shapes position from mouse click if (Input.MouseClicked(MouseButton.LeftButton)) { Shape myShape; if (kindToAdd == ShapeKind.Circle) { myShape = new Circle(); } else if (kindToAdd == ShapeKind.Rectangle) { myShape = new Rectangle(); } else { myShape = new Line(); } myShape.X = SwinGame.MouseX(); myShape.Y = SwinGame.MouseY(); drawing.AddShape(myShape); } if (Input.KeyTyped(KeyCode.SpaceKey)) { drawing.Background = SwinGame.RandomRGBColor(255); } if (Input.MouseClicked(MouseButton.RightButton)) { drawing.SelectShapesAt(SwinGame.MousePosition()); } if (Input.KeyTyped(KeyCode.DeleteKey)) { drawing.RemoveShapes(); } if (Input.KeyTyped(KeyCode.SKey)) { drawing.Save(@"C:\Testing\TestDrawing.txt"); } if (Input.KeyTyped(KeyCode.OKey)) { drawing.Load(@"C:\Testing\TestDrawing.txt"); } drawing.Draw(); // Draw onto the screen SwinGame.RefreshScreen(60); } }