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); }
public FormMain() { InitializeComponent(); this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true); Image bImg = Image.FromFile(GetAsset("images", "background.png")); Image gImg = Image.FromFile(GetAsset("images", "ground.png")); fc.AddFontFile(GetAsset("font", "flappy.ttf")); bird = new FlappyBird(this, Image.FromFile(GetAsset("images", "bird.png")), bImg, gImg, Image.FromFile(GetAsset("images", "pipe.png")), fc.Families[0], GetAsset("sounds", "jump.ogg"), GetAsset("sounds", "score.ogg"), GetAsset("sounds", "gameover.ogg"), GetAsset("sounds", "song.ogg")); bird.Exit += () => this.Close(); this.Shown += (_, __) => { Rectangle sb = Screen.FromControl(this).WorkingArea; while ((int)((bImg.Height + gImg.Height) * bird.Scale) > sb.Height - SystemInformation.CaptionHeight) { 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 this.Location = new Point((sb.Width - this.Width) / 2, (sb.Height - this.Height) / 2); }; if (!bird.CanRun) { Application.Exit(); } }