Пример #1
0
        }//eom

        #endregion

        #region Game Methods
        protected override void Initialize()
        {
            graphics.PreferredBackBufferWidth  = WindowWidth;
            graphics.PreferredBackBufferHeight = WindowHeight;
            graphics.ApplyChanges();
            gameBoundingBox = new Rectangle(0, 0, WindowWidth, WindowHeight);
            drawingState    = DrawingState.Initialize;
            transformToggle = TransformToggle.Shift;
            twoDObject      = new TwoDObject(Grid_Center, Vector2.Zero, Vector2.Zero);
            basicEffect     = new BasicEffect(graphics.GraphicsDevice)
            {
                VertexColorEnabled = true,
                Projection         = Matrix.CreateOrthographicOffCenter
                                         (0, graphics.GraphicsDevice.Viewport.Width, // left, right
                                         graphics.GraphicsDevice.Viewport.Height, 0, // bottom, top
                                         0, 1)                                       // near, far plane
            };
            SetVertices();
            base.Initialize();
        }//eom
Пример #2
0
        }//eom

        protected override void Update(GameTime gameTime)
        {
            InputKeyManager.Triggers currentKeys = InputKeyManager.Read();

            switch (drawingState)
            {
            case DrawingState.Initialize:
                // initialize - set drawingState to Drawing
                // user input to change shift and scale
                if ((currentKeys & InputKeyManager.Triggers.UpArrow) != 0)
                {
                    if (transformToggle == TransformToggle.Shift)
                    {
                        shiftY += 1.0f;
                    }    //end if
                    else
                    {
                        scaleY += 1.0f;
                        if (scaleY == 0)
                        {
                            scaleY = 1;
                        }
                    } //end else
                }     //end if

                if ((currentKeys & InputKeyManager.Triggers.DownArrow) != 0)
                {
                    if (transformToggle == TransformToggle.Shift)
                    {
                        shiftY -= 1.0f;
                    }    //end if
                    else
                    {
                        scaleY -= 1.0f;
                        if (scaleY == 0)
                        {
                            scaleY = 1;
                        }
                    } //end else
                }     //end if

                if ((currentKeys & InputKeyManager.Triggers.LeftArrow) != 0)
                {
                    if (transformToggle == TransformToggle.Shift)
                    {
                        shiftX -= 1.0f;
                    }    //end if
                    else
                    {
                        scaleX -= 1.0f;
                        if (scaleX == 0)
                        {
                            scaleX = 1;
                        }
                    } //end else
                }     //end if

                if ((currentKeys & InputKeyManager.Triggers.RightArrow) != 0)
                {
                    if (transformToggle == TransformToggle.Shift)
                    {
                        shiftX += 1.0f;
                    }    //end if
                    else
                    {
                        scaleX += 1.0f;
                        if (scaleX == 0)
                        {
                            scaleX = 1;
                        }
                    } //end else
                }     //end if

                if ((currentKeys & InputKeyManager.Triggers.Toggle) != 0)
                {
                    if (transformToggle == TransformToggle.Shift)
                    {
                        transformToggle = TransformToggle.Scale;
                    }    //end if
                    else
                    {
                        transformToggle = TransformToggle.Shift;
                    } //end else
                }     //end if

                // press spacebar to start the game
                if ((currentKeys & InputKeyManager.Triggers.Fire) != 0)
                {
                    twoDObject.Scale = new Vector2(scaleX, scaleY);
                    twoDObject.Shift = new Vector2(shiftX, shiftY);
                    drawingState     = DrawingState.Drawing;
                }    //end if
                if ((currentKeys & InputKeyManager.Triggers.ExitLevel) != 0)
                {
                    drawingState = DrawingState.Reset;
                }    //end if
                break;

            case DrawingState.Drawing:
                // draw objects
                // user input to transform the twoDObject
                twoDObject.Update(gameTime);
                SetVertices();
                // pause
                drawingState = DrawingState.Initialize;
                // reset
                if ((currentKeys & InputKeyManager.Triggers.ExitLevel) != 0)
                {
                    drawingState = DrawingState.Reset;
                }    //end if
                break;

            case DrawingState.Paused:
                // drawing is paused
                break;

            case DrawingState.Reset:
                // reset the drawing
                if ((currentKeys & InputKeyManager.Triggers.Reset) != 0)
                {
                    twoDObject = new TwoDObject(Grid_Center, Vector2.Zero, Vector2.Zero);
                    twoDObject.LoadContent(Content);
                    shiftX          = 0;
                    shiftY          = 0;
                    scaleX          = 1;
                    scaleY          = 1;
                    transformToggle = TransformToggle.Shift;
                    SetVertices();
                    drawingState = DrawingState.Initialize;
                }    //end if
                if ((currentKeys & InputKeyManager.Triggers.Quit) != 0)
                {
                    drawingState = DrawingState.Done;
                }    //end if
                break;

            case DrawingState.Done:
                // finished - exit
                this.Exit();
                break;
            } //end switch
            base.Update(gameTime);
        }     //eom