Ejemplo n.º 1
0
    public ShipController(ShipModel model, ShipView view)
    {
        _view = view;


        // Init Player Controls
        BindDirKeys();
        Observable
        .EveryUpdate()
        .Where(_ => Input.GetMouseButtonDown(0) && !Utils.IsPointerOverGameObject())
        .Subscribe(_ => model.Fire())
        .AddTo(_disposables);


        // Bind View
        view.Direction = MergeDirKeys();
        view.Speed     = model.Speed.ToReadOnlyReactiveProperty();

        // Bind Model
        {
            model.Position = Observable.EveryFixedUpdate()
                             .Select(_ => view.Position)
                             .ToReadOnlyReactiveProperty();

            view.TriggerEnterEvents
            .Subscribe(_ => model.TakeDamage());

            model.OnDestroyed += Destroy;
        }
    }