Ejemplo n.º 1
0
 static void Main()
 {
     using (var game = new BaseGame())
         game.Run();
 }
Ejemplo n.º 2
0
        protected override void Draw(GameTime gameTime)
        {
            this.GraphicsDevice.Clear(Color.White);
            this.spriteBatch.Begin();

            if (this.image != null)
            {
                lock (this.image)
                {
                    var bmp = this.image;
                    bmp = BaseGame.Grayscale(bmp);
                    var t2d = BaseGame.GetTexture2DFromBitmap(this.GraphicsDevice, bmp);
                    this.spriteBatch.Draw(t2d,
                                          Vector2.Zero, null, Color.White, 0f, Vector2.Zero, new Vector2(0.4f, 0.4f),
                                          SpriteEffects.None, 0f);

                    if (BaseGame.anchorState == 4)
                    {
                        // Draw phase, apply transform
                        bmp = BaseGame.AnchorQuadrilateral(bmp);
                    }

                    bmp = BaseGame.Threshhold(bmp);
                    var t2d2 = BaseGame.GetTexture2DFromBitmap(this.GraphicsDevice, bmp);
                    this.spriteBatch.Draw(t2d2,
                                          new Vector2(this.graphics.PreferredBackBufferWidth - t2d2.Width * 0.4f, 0), null, Color.White,
                                          0f,
                                          Vector2.Zero, new Vector2(0.4f, 0.4f),
                                          SpriteEffects.None, 0f);

                    bmp = BaseGame.Shrink(bmp, 0.4f);

                    var brightPoint = BaseGame.Position(bmp);
                    if (brightPoint.HasValue)
                    {
                        var previewPos = BaseGame.ToScreenCoord(brightPoint.Value,
                                                                new Size((int)(t2d2.Width * 0.4f), (int)(t2d2.Height * 0.4f)), bmp.Size);
                        this.spriteBatch.DrawPoint(
                            previewPos.X + this.graphics.PreferredBackBufferWidth - t2d2.Width * 0.4f, previewPos.Y,
                            Color.Red, 5F);

                        if (BaseGame.anchorState < 4)
                        {
                            // Setup phase
                            if (!BaseGame.lastVisibilityState && BaseGame.anchorState >= 0)
                            {
                                // Rising edge
                                BaseGame.transformAnchors[BaseGame.anchorState] = brightPoint.Value.ToVector2() / 0.4f;
                                BaseGame.anchorState++;
                            }
                        }
                        else
                        {
                            // Draw phase
                            var truePos = BaseGame.ToScreenCoord(brightPoint.Value,
                                                                 new Size(this.graphics.PreferredBackBufferWidth, BaseGame.yHeight), bmp.Size);
                            this.drawing.Add(new Vector2(truePos.X, truePos.Y + BaseGame.yOffset));
                        }
                    }

                    BaseGame.lastVisibilityState = brightPoint.HasValue;
                }

                switch (BaseGame.anchorState)
                {
                case 0:
                    this.spriteBatch.DrawPoint(10, BaseGame.yOffset + 10, Color.Red, 10f);
                    break;

                case 1:
                    this.spriteBatch.DrawPoint(this.graphics.PreferredBackBufferWidth - 10, BaseGame.yOffset + 10,
                                               Color.Red,
                                               10f);
                    break;

                case 2:
                    this.spriteBatch.DrawPoint(this.graphics.PreferredBackBufferWidth - 10,
                                               BaseGame.yOffset + BaseGame.yHeight - 10, Color.Red, 10f);
                    break;

                case 3:
                    this.spriteBatch.DrawPoint(10, BaseGame.yHeight + BaseGame.yOffset - 10, Color.Red, 10f);
                    break;

                default:
                    foreach (var vector2 in this.drawing)
                    {
                        this.spriteBatch.DrawPoint(vector2, Color.Red, 6f);
                    }
                    break;
                }

                if (Keyboard.GetState().IsKeyDown(Keys.C))
                {
                    this.drawing.Clear();
                }

                if (Keyboard.GetState().IsKeyDown(Keys.Space))
                {
                    BaseGame.anchorState = 0;
                }
            }

            this.spriteBatch.End();
            base.Draw(gameTime);
        }