コード例 #1
0
        public MainForm()
        {
            JsonReader.Load(this);

            FontFamily ff = Fonts.Monospace(12).Family;

            try {
                ff = new FontFamily("04b_19");
            } catch { }

            Image bImg = new Bitmap(GetAsset("images", "background.png"));
            Image gImg = new Bitmap(GetAsset("images", "ground.png"));

            bird = new FlappyBird(Canvas,
                                  new Bitmap(GetAsset("images", "bird.png")),
                                  bImg,
                                  gImg,
                                  new Bitmap(GetAsset("images", "pipe.png")),
                                  ff,
                                  GetAsset("sounds", "jump.ogg"),
                                  GetAsset("sounds", "score.ogg"),
                                  GetAsset("sounds", "gameover.ogg"),
                                  GetAsset("sounds", "song.ogg"));

            bird.Exit += () => Application.Instance.Quit();

            this.Shown += (_, __) => {
                RectangleF sb = Screen.FromPoint(PointF.Empty).WorkingArea;
                while ((int)((bImg.Height + gImg.Height) * bird.Scale) > sb.Height - 16)
                {
                    bird.Scale -= 0.05f;
                }

                // Resize client area
                this.ClientSize = new Size((int)(bImg.Width * bird.Scale),
                                           (int)((bImg.Height + gImg.Height) * bird.Scale));

                // Center screen
                Task.Run(() => {
                    if (Platform.Detect.IsGtk)
                    {
                        System.Threading.Thread.Sleep(250);                       // Because... reasons...
                    }
                    Application.Instance.Invoke(() => this.Location = new Point((int)((sb.Width - this.Width) / 2),
                                                                                (int)(sb.Height - this.Height) / 2));
                });

                if (ff?.LocalizedName != "04b_19")
                {
                    MessageBox.Show(@"Please install the font 'flappy.ttf' under the folder 'Assets\font' before running the game", MessageBoxType.Error);
                    Application.Instance.Quit();
                }
            };

            Canvas.Paint += (object s, PaintEventArgs e) => bird.DrawScene(e);
        }
コード例 #2
0
 protected override void OnPaint(PaintEventArgs e)
 {
     bird.DrawScene(e);
 }