/// <summary> /// Creates a new PinballGameControl based on a machine template. /// </summary> /// <param name="machine">Template for the game machine.</param> public GameView(Game game) : base() { Game = game; gameWorld = new GameWorld(Game); HUD = new GameHUD(Game); Camera = new GameFieldCamera(gameWorld, HUD); // Little hack needed so that we get all input events. Focusable = true; Loaded += (s, e) => { Focus(); }; // Init camera Camera.Size = new Size(Width, Height); // Set up the update timer timer = new System.Windows.Forms.Timer(); timer.Interval = 1000 / MAX_FPS; timer.Tick += OnTick; timer.Start(); // Wire up a few event listeners PreviewKeyDown += HandleKeyDown; SizeChanged += ResizeCamera; Game.StatusChanged += delegate { Dispatcher.Invoke(delegate { InvalidateVisual(); }, System.Windows.Threading.DispatcherPriority.Render); }; // Let's draw with high quality SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality); }
public GameHUD(Game game) { Game = game; Width = 300; Height = (int)(Width / BG.Width * BG.Height); lineWidth = 10; lineHeight = lineWidth / Line.Width * Line.Height; smilieWidth = 100; smilieHeight = smilieWidth / GoodSmilie.Width * GoodSmilie.Height; }
public PlayForm(PinballMachine pbm, SelectionForm selectionForm) { InitializeComponent(); // Initialize game originalMachine = pbm; game = new Game(pbm, Environment.UserName); gameView = new GameView(game); gameContainer = new WPFContainer(gameView); game.GameOver += onGameOver; //this.MinimumSize = gameView.MinimumSize; gameView.MouseUp += onMouseUp; gameView.MouseMove += onMouseMove; // Fill entire space gameContainer.Dock = DockStyle.Fill; mainContainer.ContentPanel.Controls.Add(gameContainer); this.selectionForm = selectionForm; debugModeButton.Checked = Properties.Settings.Default.Debug; }
public void Setup() { user = "******"; pbm = new PinballMachine(); game = new Game(pbm, user); }
public GameWorld(Game game) { Game = game; }
protected override void OnDispose() { // ElementHost sometimes fails to properly remove all references to a WPF control, // which is why we set all our own references to NULL so that at least those aren't kept alive forever. timer.Dispose(); Game = null; gameWorld = null; HUD = null; Camera = null; }