Beispiel #1
0
        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();

            ShapeKind kindToAdd = ShapeKind.Circle;
            Drawing   mydrawing = new Drawing();

            do
            {
                mydrawing.FreeList();
                SwinGame.ClearScreen(Color.White);
                SwinGame.DrawFramerate(0, 0);
                SwinGame.RefreshScreen();
                /*Shape s = new Shape ();*/
                //Run the game loop
                while (!SwinGame.WindowCloseRequested())
                {
                    //Fetch the next batch of UI interaction
                    SwinGame.ProcessEvents();

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

                    Random rand = new Random();
                    Shape  s    = default(Shape);


                    mydrawing.Draw();
                    if (Input.KeyTyped(KeyCode.vk_r))
                    {
                        kindToAdd = ShapeKind.Rectangle;
                    }
                    if (Input.KeyTyped(KeyCode.vk_c))
                    {
                        kindToAdd = ShapeKind.Circle;
                    }
                    if (Input.KeyTyped(KeyCode.vk_l))
                    {
                        kindToAdd = ShapeKind.Line;
                    }
                    if (Input.KeyTyped(KeyCode.vk_s))
                    {
                        mydrawing.Save("File.txt");
                    }

                    if (Input.KeyDown(KeyCode.vk_KP_ENTER))
                    {
                        try
                        { mydrawing.Load("File.txt"); }
                        catch (Exception e)
                        {
                            Console.Error.WriteLine("Error loading file:{0}", e.Message);
                        }
                    }


                    if (SwinGame.MouseClicked(MouseButton.LeftButton))
                    {
                        //code written before inheritance
                        //					s.X = SwinGame.MouseX ();
                        //					s.Y = SwinGame.MouseY ();

                        //  done previously when abstract is not done->
                        //	->Shape newShape = new Shape ();

                        switch (kindToAdd)
                        {
                        case ShapeKind.Circle:
                            Circle newCircle = new Circle();
                            newCircle.X      = SwinGame.MouseX();
                            newCircle.Y      = SwinGame.MouseY();
                            newCircle.Radius = (int)(rand.NextDouble() * 100);
                            Console.WriteLine("(" + newCircle.X + "," + newCircle.Y + ")");

                            s = newCircle;
                            break;

                        case ShapeKind.Rectangle:
                            Rectangle newRect = new Rectangle();
                            newRect.Width  = (int)(rand.NextDouble() * 400);
                            newRect.Height = (int)(rand.NextDouble() * 400);
                            newRect.X      = SwinGame.MouseX() - newRect.Width / 2;
                            newRect.Y      = SwinGame.MouseY() - newRect.Height / 2;
                            Console.WriteLine("(" + newRect.X + "," + newRect.Y + ")");

                            s = newRect;
                            break;

                        case ShapeKind.Line:

                            Line newLine = new Line();
                            newLine.X = SwinGame.MouseX();
                            newLine.Y = SwinGame.MouseY();
                            //						//center of the program is about (400,300)
                            newLine.XEnd = (int)(rand.NextDouble() * 800);
                            newLine.YEnd = (int)(rand.NextDouble() * 600);
                            s            = newLine;
                            break;

                        default:
                            break;
                        }
                        mydrawing.AddShape(s);
                    }


                    if (Input.KeyDown(KeyCode.vk_SPACE))
                    {
                        mydrawing.BackgroundColor = SwinGame.RandomRGBColor(255);
                    }

                    if (SwinGame.MouseClicked(MouseButton.RightButton))
                    {
                        mydrawing.SelectShapesAt(SwinGame.MousePosition());
                        //done previously when abstract is not done
                        //					if (s is Rectangle)
                        //						(s as Rectangle).DrawOutline ();
                        //					if (s is Circle)
                        //						(s as Circle).DrawOutline ();
                        //					else if (s is Line)
                        //						(s as Line).DrawOutline ();
                    }
                    foreach (Shape Shapes in mydrawing.SelectedShapes)
                    {
                        if (Input.KeyTyped(KeyCode.vk_BACKSPACE) || Input.KeyTyped(KeyCode.vk_DELETE))
                        {
                            mydrawing.RemoveShape(Shapes);
                            //						if (s is Rectangle)
                            //							(s as Rectangle).DrawOutline ();
                            //						if (s is Circle)
                            //							(s as Circle).DrawOutline ();
                            //						else if (s is Line)
                            //							(s as Line).DrawOutline ();
                        }
                    }

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

                //End the audio
                SwinGame.CloseAudio();

                //Close any resources we were using
                SwinGame.ReleaseAllResources();
            }while(Input.KeyTyped(KeyCode.vk_z));
        }
Beispiel #2
0
        public void Run()
        {
            SwinGame.OpenAudio();
            SwinGame.OpenGraphicsWindow("Artillery3", (int)_windowRect.Width, (int)_windowRect.Height);
            SwinGame.SetIcon("H:\\repos\\Artillery3\\Resources\\images\\logoArtillery3LogoIcon.ico");

            LoadResources();
            SwinGame.ClearScreen(Color.White);



            SwitchState(MenuState.MainMenu);



            while (!SwinGame.WindowCloseRequested() && !userExitRequested)
            {
                SwinGame.ProcessEvents();
                HandleInput();

                switch (PeekState())

                {
                case MenuState.ShopState:
                    SwinGame.ClearScreen(Color.White);
                    SwinGame.DrawFramerate(0, 0);

                    SwinGame.DrawText("This is the shop menu!", Color.Black, 10, 500);

                    break;

                case MenuState.PlayerSelectState:

                    UserInterface.Instance.Update();

                    SwinGame.ClearScreen(Color.White);
                    SwinGame.DrawFramerate(0, 0);

                    UserInterface.Instance.Draw();


                    break;

                case MenuState.LoadState:
                    MenuState _holdState = PopState();
                    if (_holdState != MenuState.LoadState)
                    {
                        throw new Exception("Stack... Exception... Menustate!");
                    }
                    _holdState = PopState();
                    SwitchState(_holdState);


                    break;

                case MenuState.EscMenu:

                    SwinGame.ClearScreen(Color.White);
                    SwinGame.DrawFramerate(0, 0);
                    SwinGame.DrawText("Esc Menu", Color.Black, 10, 500);
                    SwinGame.MoveCameraTo(0, 0);

                    break;

                case MenuState.Exit:

                    userExitRequested = true;

                    break;

                case MenuState.MainMenu:


                    UserInterface.Instance.Update();

                    SwinGame.ClearScreen(Color.White);
                    SwinGame.DrawFramerate(0, 0);

                    UserInterface.Instance.Draw();



                    if (SwinGame.KeyTyped(KeyCode.KKey))
                    {
                        SwitchState(MenuState.CombatStage);
                    }


                    break;

                case MenuState.CombatStage:

                    _world.HandleInput();


                    ParticleEngine.Instance.Update();
                    PhysicsEngine.Instance.Simulate();
                    EntityManager.Instance.Update();
                    UserInterface.Instance.Update();
                    _world.Update();

                    SwinGame.ClearScreen(_world.SkyColor);
                    SwinGame.DrawFramerate(0, 0);

                    _world.Draw();
                    ParticleEngine.Instance.Draw();
                    EntityManager.Instance.Draw();
                    _world.DrawSatellite();
                    UserInterface.Instance.Draw();

                    if (SwinGame.KeyTyped(KeyCode.KKey))
                    {
                        SwitchState(MenuState.MainMenu);
                    }

                    break;
                }
                SwinGame.RefreshScreen(60);
            }

            SwinGame.CloseAudio();
            SwinGame.ReleaseAllResources();
        }
        public static void Main()
        {
            SwinGame.OpenAudio();
            SwinGame.OpenGraphicsWindow("GameMain", 800, 600);
            SwinGame.ShowSwinGameSplashScreen();

            Drawing myDrawing = new Drawing();

            ShapeKind KindtoAdd = ShapeKind.Circle;


            while (false == SwinGame.WindowCloseRequested())
            {
                SwinGame.ProcessEvents();

                SwinGame.ClearScreen(Color.White);
                SwinGame.DrawFramerate(0, 0);

                myDrawing.Draw();

                if (Input.KeyTyped(KeyCode.vk_r))
                {
                    KindtoAdd = ShapeKind.Rectangle;
                }
                if (Input.KeyTyped(KeyCode.vk_c))
                {
                    KindtoAdd = ShapeKind.Circle;
                }
                if (Input.KeyTyped(KeyCode.vk_l))
                {
                    KindtoAdd = ShapeKind.Line;
                }

                Point2D mouseLocation = SwinGame.MousePosition();


                if (SwinGameSDK.Input.MouseClicked(MouseButton.LeftButton))
                {
                    /*Shape myShape = new Shape();
                     * myShape.Color = SwinGame.RandomRGBColor (255);
                     * myShape.X = SwinGame.MouseX();
                     * myShape.Y = SwinGame.MouseY();
                     * myDrawing.AddShape (myShape);*/

                    Shape newShape = default(Shape);
                    if (KindtoAdd == ShapeKind.Circle)
                    {
                        Circle newCircle = new Circle();
                        newCircle.X = SwinGame.MouseX();
                        newCircle.Y = SwinGame.MouseY();
                        newShape    = newCircle;
                    }
                    else if (KindtoAdd == ShapeKind.Rectangle)
                    {
                        Rectangle newRect = new Rectangle();
                        newRect.X = SwinGame.MouseX();
                        newRect.Y = SwinGame.MouseY();
                        newShape  = newRect;
                    }
                    else if (KindtoAdd == ShapeKind.Line)
                    {
                        Line newLine = new Line();
                        newLine.X = SwinGame.MouseX();
                        newLine.Y = SwinGame.MouseY();
                        newShape  = newLine;
                    }
                    myDrawing.AddShape(newShape);
                }

                if (SwinGame.MouseClicked(MouseButton.RightButton))
                {
                    myDrawing.SelectShapeAt(SwinGame.MousePosition());
                }
                if (SwinGame.KeyTyped(KeyCode.vk_DELETE))
                {
                    List <Shape> selected = myDrawing.SelectedShape;
                    foreach (Shape s in selected)
                    {
                        myDrawing.RemoveShape(s);
                    }
                }

                //if (myShape.IsAt (mouseLocation))
                //{
                if (SwinGame.KeyTyped(KeyCode.vk_SPACE))
                {
                    myDrawing.Mybackground = SwinGame.RandomRGBColor(255);
                }
                //}
                SwinGame.DrawFramerate(0, 0);
                SwinGame.RefreshScreen();
            }


            //End the audio
            SwinGame.CloseAudio();

            //Close any resources we were using
            SwinGame.ReleaseAllResources();
        }