private void Setup(GameEngine engine) { Observable.FromEvent((EventHandler<MouseButtonEventArgs> ev) => new MouseButtonEventHandler(ev), ev => this.MouseDoubleClick += ev, ev => this.MouseDoubleClick -= ev).Where(e => e.EventArgs.ChangedButton == MouseButton.Left).Subscribe(e => { if (engine.IsRunning) engine.Stop(); else engine.Start(); }); Observable.FromEvent((EventHandler<KeyEventArgs> ev) => new KeyEventHandler(ev), ev => this.KeyDown += ev, ev => this.KeyDown -= ev).Where(e => e.EventArgs.Key == Key.C).Subscribe(e => { Debug.WriteLine("C pressed."); engine.Bus.Add(new ObjectCreationRequest(engine.Timer.LastTickTime, typeof(TestTank))); }); engine.Timer.Subscribe(t => { foreach (var view in Views.Values) { view.Model.NotifyPropertyChanged(); } }); engine.Bus.OfType<SystemMessage>().Subscribe(m => SysMessage.Dispatcher.Invoke(new Action(() => SysMessage.Content += m.Message + "\n"))); engine.Bus.Filters.ObjectLifeTimeNotifications.Subscribe(m => SysMessage.Dispatcher.Invoke(new Action(() => SysMessage.Content += m.ToString() + "\n"))); engine.Bus.Add(new ObjectCreationRequest(engine.Timer.LastTickTime,typeof(TestTank))); }
private static void Setup(GameEngine engine) { engine.Timer.Subscribe(t => { foreach (var item in engine.MapItems().OfType<TempItem>()) { Console.WriteLine(item.ToString()); } }); engine.ObjectFactory.GameObjects.Add(new TempItem(engine.Bus) { Velocity = new Vector2(0, 0) }); engine.ObjectFactory.GameObjects.Add(new TempItem(engine.Bus) { Velocity = new Vector2(1, 1) }); }
public TestGameViewFactory(GameEngine engine, MessageBus bus, Canvas panel, Dictionary<IGameObject, TestTankView> views) { Engine = engine; Bus = bus; this.Panel = panel; Views = views; Bus.Filters.ObjectLifeTimeNotifications.OfType<ObjectCreated>().Subscribe(m => CreateView(m)); Bus.Filters.ObjectLifeTimeNotifications.OfType<ObjectDestroyed>().Subscribe(m => DestroyView(m)); }