예제 #1
0
        public static void Main()
        {
            //Open the game window
            SwinGame.OpenGraphicsWindow("DrawingProgram", 1600, 900);
            SwinGame.ShowSwinGameSplashScreen();


            Drawing myDrawing = new Drawing();


            //Run the game loop
            while (false == SwinGame.WindowCloseRequested())
            {
                //Fetch the next batch of UI interaction
                SwinGame.ProcessEvents();

                if (SwinGame.MouseClicked(MouseButton.LeftButton))
                {
                    myDrawing.AddShape(new Shape((int)SwinGame.MousePosition().X, (int)SwinGame.MousePosition().Y));
                }

                if (SwinGame.KeyDown(KeyCode.SpaceKey))
                {
                    myDrawing.Background = SwinGame.RandomRGBColor(255);
                }

                if (SwinGame.KeyDown(KeyCode.DeleteKey) || SwinGame.KeyDown(KeyCode.BackspaceKey))
                {
                    myDrawing.DeleteSelectedShapes();
                }

                if (SwinGame.MouseClicked(MouseButton.RightButton))
                {
                    myDrawing.SelectShapesAt(SwinGame.MousePosition());
                }



                //Clear the screen and draw the framerate
                SwinGame.ClearScreen(Color.White);

                myDrawing.Draw();

                SwinGame.DrawFramerate(0, 0);

                //Draw onto the screen
                SwinGame.RefreshScreen(60);
            }
        }
예제 #2
0
        public static void Main()
        {
            //Register shapes
            Shape.RegisterShape("Retangle", typeof(Rectangle));
            Shape.RegisterShape("Circle", typeof(Circle));
            Shape.RegisterShape("Line", typeof(Line));

            //Open the game window
            SwinGame.OpenGraphicsWindow("DrawingProgram", 1600, 900);
            SwinGame.ShowSwinGameSplashScreen();


            ShapeKind kindToAdd = ShapeKind.Circle;

            Drawing myDrawing = new Drawing();


            //Run the game loop
            while (false == SwinGame.WindowCloseRequested())
            {
                //Fetch the next batch of UI interaction
                SwinGame.ProcessEvents();

                if (SwinGame.MouseClicked(MouseButton.LeftButton))
                {
                    Shape newShape;
                    int   x = (int)SwinGame.MouseX();
                    int   y = (int)SwinGame.MouseY();

                    if (kindToAdd == ShapeKind.Circle)
                    {
                        Circle newCircle = new Circle();
                        newShape = newCircle;
                    }
                    else if (kindToAdd == ShapeKind.Line)
                    {
                        Line newLine = new Line();
                        newShape = newLine;
                    }
                    else
                    {
                        Rectangle newRect = new Rectangle();
                        newShape = newRect;
                    }
                    newShape.X = x;
                    newShape.Y = y;

                    myDrawing.AddShape(newShape);
                }


                if (SwinGame.KeyDown(KeyCode.SKey))
                {
                    myDrawing.Save("C:\\Users\\Mikan\\Desktop\\TestDrawing.txt");
                }

                if (SwinGame.KeyDown(KeyCode.OKey))
                {
                    myDrawing.Load("C:\\Users\\Mikan\\Desktop\\TestDrawing.txt");
                }

                if (SwinGame.KeyDown(KeyCode.LKey))
                {
                    kindToAdd = ShapeKind.Line;
                }

                if (SwinGame.KeyDown(KeyCode.RKey))
                {
                    kindToAdd = ShapeKind.Rectangle;
                }

                if (SwinGame.KeyDown(KeyCode.CKey))
                {
                    kindToAdd = ShapeKind.Circle;
                }

                if (SwinGame.KeyDown(KeyCode.SpaceKey))
                {
                    myDrawing.Background = SwinGame.RandomRGBColor(255);
                }

                if (SwinGame.KeyDown(KeyCode.DeleteKey) || SwinGame.KeyDown(KeyCode.BackspaceKey))
                {
                    myDrawing.DeleteSelectedShapes();
                }

                if (SwinGame.MouseClicked(MouseButton.RightButton))
                {
                    myDrawing.SelectShapesAt(SwinGame.MousePosition());
                }



                //Clear the screen and draw the framerate
                SwinGame.ClearScreen(Color.White);

                myDrawing.Draw();

                SwinGame.DrawFramerate(0, 0);

                //Draw onto the screen
                SwinGame.RefreshScreen(60);
            }
        }
예제 #3
0
        public static void Main()
        {
            // REGISTER SHAPES:
            Shape.RegisterShape("Rectangle", typeof(Rectangle));
            Shape.RegisterShape("Circle", typeof(Circle));
            Shape.RegisterShape("Line", typeof(Line));

            // LOCAL VARIABLES:
            Drawing   drawing   = new Drawing();
            ShapeKind kindToAdd = ShapeKind.Circle;

            SwinGame.OpenGraphicsWindow("GameMain", 800, 600);
            SwinGame.ShowSwinGameSplashScreen();


            // GAME LOOP:
            while (SwinGame.WindowCloseRequested() == false)
            {
                // Fetch the next batch of UI interaction:
                SwinGame.ProcessEvents();

                // Clear the screen and draw the framerate:
                SwinGame.ClearScreen(Color.White);


                // HANDLE INPUT:

                // Background Color:
                if (SwinGame.KeyTyped(KeyCode.SpaceKey))
                {
                    drawing.Background = SwinGame.RandomRGBColor(255);
                }

                // Rectangle:
                if (SwinGame.KeyTyped(KeyCode.RKey))
                {
                    kindToAdd = ShapeKind.Rectangle;
                }

                // Circle:
                if (SwinGame.KeyTyped(KeyCode.CKey))
                {
                    kindToAdd = ShapeKind.Circle;
                }

                // Line:
                if (SwinGame.KeyTyped(KeyCode.LKey))
                {
                    kindToAdd = ShapeKind.Line;
                }

                // Draw:
                if (SwinGame.MouseClicked(MouseButton.LeftButton))
                {
                    // New Shape is created (by default as a Rectangle)
                    Shape newShape = new Rectangle();

                    // Switch statement reads from ShapeKind enum, and draws
                    // currently selected Shape Type:
                    switch (kindToAdd)
                    {
                    case ShapeKind.Circle:
                        Circle newCircle = new Circle();
                        newShape = newCircle;
                        break;

                    case ShapeKind.Rectangle:
                        Rectangle newRect = new Rectangle();
                        newShape = newRect;
                        break;

                    case ShapeKind.Line:
                        Line newLine = new Line();
                        newShape = newLine;
                        break;
                    }

                    // Apply Mouse Pointer position to Shape's x & y:
                    newShape.X = SwinGame.MouseX();
                    newShape.Y = SwinGame.MouseY();
                    drawing.AddShape(newShape);
                }

                // Select Shapes at Mouse Position when RMB is clicked:
                if (SwinGame.MouseClicked(MouseButton.RightButton))
                {
                    drawing.SelectShapesAt(SwinGame.MousePosition());
                }

                // Delete Selected Shapes when Backspace key is typed:
                if (SwinGame.KeyTyped(KeyCode.BackspaceKey))
                {
                    drawing.DeleteSelectedShapes();
                }

                // Save all Shapes when S key is typed:
                if (SwinGame.KeyTyped(KeyCode.SKey))
                {
                    try
                    {
                        drawing.Save("Users/andru/Desktop/TestDrawing.txt");
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine("Error saving to file: {0}", e.Message);
                    }
                }

                // Open from Text File when O key is typed:
                if (SwinGame.KeyTyped(KeyCode.OKey))
                {
                    try
                    {
                        drawing.Load("//Users/andru/Desktop/TestDrawing.txt");
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine("Error loading file: {0}", e.Message);
                    }
                }

                // Draw Assets in drawing Object:
                drawing.Draw();

                // Draw Assets on screen:
                SwinGame.DrawFramerate(0, 0);

                // Draw onto the screen:
                SwinGame.RefreshScreen(60);
            }
        }