public static void Main() { ShapeKind kindToAdd = ShapeKind.Circle; //Start the audio system so sound can be played SwinGame.OpenAudio(); //Open the game window SwinGame.OpenGraphicsWindow("GameMain", 800, 600); // SwinGame.ShowSwinGameSplashScreen(); Drawing myDrawing = new Drawing (); //Run the game loop while(false == SwinGame.WindowCloseRequested()) { if (SwinGame.KeyTyped (KeyCode.vk_r)) { kindToAdd = ShapeKind.Rectangle; } if (SwinGame.KeyTyped (KeyCode.vk_c)) { kindToAdd = ShapeKind.Circle; } if (SwinGame.KeyTyped (KeyCode.vk_l)) { kindToAdd = ShapeKind.Line; } //Fetch the next batch of UI interaction SwinGame.ProcessEvents(); //Clear the screen and draw the framerate SwinGame.ClearScreen(Color.White); //Change location of shape if (SwinGame.MouseClicked(MouseButton.LeftButton)) { Shape newShape; if (kindToAdd == ShapeKind.Circle) { Circle newCircle = new Circle (); newShape = newCircle; } else if (kindToAdd == ShapeKind.Rectangle) { Rectangle newRect = new Rectangle (); newShape = newRect; } else { Line newLine = new Line (); newShape = newLine; } newShape.X = SwinGame.MouseX (); newShape.Y = SwinGame.MouseY (); myDrawing.AddShape (newShape); } if (SwinGame.MouseClicked (MouseButton.RightButton)) { myDrawing.SelectShapesAt (SwinGame.MousePosition ()); } //Check if mouse is within shape bounds and spacebar pressed //If true change color of shape to random RGB color if (SwinGame.KeyTyped(KeyCode.vk_SPACE)) { myDrawing.BackgroundColor = SwinGame.RandomRGBColor (255); } if ((SwinGame.KeyTyped (KeyCode.vk_DELETE)) || (SwinGame.KeyTyped (KeyCode.vk_BACKSPACE))) { foreach (Shape s in myDrawing.SelectedShapes) { myDrawing.RemoveShape (s); } } SwinGame.DrawFramerate(0,0); myDrawing.Draw (); //Draw onto the screen SwinGame.RefreshScreen(); } //End the audio SwinGame.CloseAudio(); //Close any resources we were using SwinGame.ReleaseAllResources(); }
public static void Main() { Shape.RegisterShape("Rectangle", typeof(Rectangle)); Shape.RegisterShape("Circle", typeof(Circle)); Shape.RegisterShape("Line", typeof(Line)); //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); } }