Ejemplo n.º 1
0
        protected override InputConfiguration CreateInputConfiguration()
        {
            var inputConfiguration = new InputConfiguration();

            inputConfiguration.AddDigitalButton("Back").Assign(KeyboardKeys.Escape)
                .MapClickTo(gt => this.screenNavigation.NavigateBack());

            inputConfiguration.AddDigitalButton("CameraLeft").Assign(KeyboardKeys.Left)
                .MapTo(gt => this.MoveCamera(gt.ElapsedSeconds * -CameraSpeed, 0));
            inputConfiguration.AddDigitalButton("CameraRight").Assign(KeyboardKeys.Right)
                .MapTo(gt => this.MoveCamera(gt.ElapsedSeconds * CameraSpeed, 0));
            inputConfiguration.AddDigitalButton("CameraUp").Assign(KeyboardKeys.Up)
                .MapTo(gt => this.MoveCamera(0, gt.ElapsedSeconds * -CameraSpeed));
            inputConfiguration.AddDigitalButton("CameraDown").Assign(KeyboardKeys.Down)
                .MapTo(gt => this.MoveCamera(0, gt.ElapsedSeconds * CameraSpeed));
            inputConfiguration.AddDigitalButton("ZoomIn").Assign(KeyboardKeys.Add).Assign(KeyboardKeys.OemPlus)
                .MapTo(gt => this.Camera.ZoomFactor += gt.ElapsedSeconds);
            inputConfiguration.AddDigitalButton("ZoomOut").Assign(KeyboardKeys.OemMinus)
                .MapTo(gt => this.Camera.ZoomFactor -= gt.ElapsedSeconds);

            inputConfiguration.AddDigitalButton("SwitchSampler").Assign(KeyboardKeys.Tab)
                .MapClickTo(gt => { foreach (var l in this.tileLayers) l.UseLinearSampler = !l.UseLinearSampler; });

            return inputConfiguration;
        }
Ejemplo n.º 2
0
        protected override InputConfiguration CreateInputConfiguration()
        {
            var inputConfiguration = new InputConfiguration();

            inputConfiguration.AddDigitalButton("Back").Assign(KeyboardKeys.Escape)
                .MapClickTo(gt => this.screenNavigation.NavigateBack());

            //inputConfiguration.AddTouchTracking(this.Camera).OnTouch((ts, gt) => this.touchState = ts);

            inputConfiguration.AddEvent("Tap").Assign(TouchGestureType.Tap).MapTo(gt => this.tapCount++);
            inputConfiguration.AddEvent("Hold").Assign(TouchGestureType.Hold).MapTo(gt => this.holdCount++);
            inputConfiguration.AddEvent("DoubleTap").Assign(TouchGestureType.DoubleTap).MapTo(gt => this.doubleTapCount++);
            inputConfiguration.AddEvent("DragComplete").Assign(TouchGestureType.DragComplete).MapTo(gt => this.dragCompleteCount++);
            inputConfiguration.AddEvent("Flick").Assign(TouchGestureType.Flick).MapTo(gt => this.flickCount++);
            inputConfiguration.AddEvent("FreeDrag").Assign(TouchGestureType.FreeDrag).MapTo(gt => this.freeDragCount++);
            inputConfiguration.AddEvent("HorizontalDrag").Assign(TouchGestureType.HorizontalDrag).MapTo(gt => this.horizontalDragCount++);
            inputConfiguration.AddEvent("Pinch").Assign(TouchGestureType.Pinch).MapTo(gt => this.pinchCount++);
            inputConfiguration.AddEvent("PinchComplete").Assign(TouchGestureType.PinchComplete).MapTo(gt => this.pinchCompleteCount++);
            inputConfiguration.AddEvent("VerticalDrag").Assign(TouchGestureType.VerticalDrag).MapTo(gt => this.verticalDragCount++);

            var viewport = this.Camera.Viewport;
            //var size = new Size(viewport.Width, viewport.Height);
            var s2 = viewport.Size.Scale(0.1f);
            var backRectangle = new Rectangle(viewport.Width - s2.X * 2, viewport.Height - s2.Y * 2, s2.X, s2.Y);

            this.visualBackButton = inputConfiguration.AddVisualButton("Back", backRectangle)
                .Assign(TouchGestureType.Tap)
                .MapTouchTo(gt => this.isHoveringBackButton = true)
                .MapClickTo(gt => this.screenNavigation.NavigateBack());

            return inputConfiguration;
        }
Ejemplo n.º 3
0
        protected override InputConfiguration CreateInputConfiguration()
        {
            var inputConfiguration = new InputConfiguration();

            inputConfiguration.AddDigitalButton("Back").Assign(KeyboardKeys.Escape)
                .MapClickTo(gt => this.screenNavigation.NavigateBack());

            inputConfiguration.AddDigitalButton("DiagToggle").Assign(KeyboardKeys.F1).MapClickTo(gt => this.diagnosticHud.ViewStateToggle());

            inputConfiguration.AddDigitalButton("Left").Assign(KeyboardKeys.Left).MapTo(gt => this.Camera.Move(-60 * gt.ElapsedSeconds, 0));
            inputConfiguration.AddDigitalButton("Right").Assign(KeyboardKeys.Right).MapTo(gt => this.Camera.Move(60 * gt.ElapsedSeconds, 0));
            inputConfiguration.AddDigitalButton("Up").Assign(KeyboardKeys.Up).MapTo(gt => this.Camera.Move(0, -60 * gt.ElapsedSeconds));
            inputConfiguration.AddDigitalButton("Down").Assign(KeyboardKeys.Down).MapTo(gt => this.Camera.Move(0, 60 * gt.ElapsedSeconds));

            inputConfiguration.AddDigitalButton("ZoomIn").Assign(KeyboardKeys.A).MapTo(gt => this.Camera.ZoomFactor *= 1.2f * (1 + gt.ElapsedSeconds));
            inputConfiguration.AddDigitalButton("ZoomOut").Assign(KeyboardKeys.Z).MapTo(gt => this.Camera.ZoomFactor *= 1 / (1.2f * (1 + gt.ElapsedSeconds)));

            inputConfiguration.AddDigitalButton("SwitchSampler").Assign(KeyboardKeys.Tab)
                .MapClickTo(gt => this.Scene.UseLinearSampler = !this.Scene.UseLinearSampler);

            inputConfiguration.AddDigitalButton("RangeUp").Assign(KeyboardKeys.W).MapTo(gt => this.range *= 1.2f * (1 + gt.ElapsedSeconds));
            inputConfiguration.AddDigitalButton("RangeDown").Assign(KeyboardKeys.Q).MapTo(gt => this.range *= 1 / (1.2f * (1 + gt.ElapsedSeconds)));

            inputConfiguration.AddDigitalButton("RotateLeft").Assign(KeyboardKeys.X).MapTo(gt => this.linkMouseFollow.Rotation -= 4 * gt.ElapsedSeconds);
            inputConfiguration.AddDigitalButton("RotateRight").Assign(KeyboardKeys.C).MapTo(gt => this.linkMouseFollow.Rotation += 4 * gt.ElapsedSeconds);

            inputConfiguration.AddDigitalButton("Selection").Assign(MouseButtons.Left).MapTo(elapse =>
            {
                this.hits = this.Scene.GetHits(this.mouseState.AbsolutePosition, this.Camera).ToList();
            });

            inputConfiguration.AddDigitalButton("Play sound").Assign(MouseButtons.Right).MapClickTo(e =>
            {
                this.coinSound.Pan = (this.mouseState.AbsolutePosition.X / this.Camera.SceneViewport.Width) - 0.5f;
                this.coinSound.Play();
            });

            inputConfiguration.AddDigitalButton("PlayPause music").Assign(KeyboardKeys.Space).MapClickTo(e =>
            {
                if (this.music.IsPlaying)
                    this.music.Pause();
                //else if (this.music.IsPaused)
                //    this.music.Resume();
                else if (this.music.IsPaused)
                    this.music.Play();
                else if (this.music.IsStopped)
                    this.music.Play();
            });

            inputConfiguration.CreateMouseTracking(this.Camera).OnUpdate((mt, e) =>
            {
                this.mouseState = mt;

                this.linkMouseFollow.Position = mt.AbsolutePosition;
            });

            return inputConfiguration;
        }
Ejemplo n.º 4
0
        protected override InputConfiguration CreateInputConfiguration()
        {
            var inputConfiguration = new InputConfiguration();

            inputConfiguration.AddDigitalButton("Back").Assign(KeyboardKeys.Escape)
                .MapClickTo(gt => this.screenNavigation.NavigateBack());

            inputConfiguration.AddDigitalButton("Left").Assign(KeyboardKeys.Left);
            inputConfiguration.AddDigitalButton("Right").Assign(KeyboardKeys.Right);
            inputConfiguration.AddDigitalButton("Up").Assign(KeyboardKeys.Up);
            inputConfiguration.AddDigitalButton("Down").Assign(KeyboardKeys.Down);
            inputConfiguration.AddDigitalButton("Fire Weapon").Assign(KeyboardKeys.Space);

            return inputConfiguration;
        }
Ejemplo n.º 5
0
        protected override InputConfiguration CreateInputConfiguration()
        {
            var inputConfiguration = new InputConfiguration();

            // Keyboard
            inputConfiguration.AddDigitalButton("Back").Assign(KeyboardKeys.Escape)
                //.MapClickTo(gt => this.screenNavigation.Exit());
                .MapClickTo(gt => this.Exit());

            inputConfiguration.AddDigitalButton("GotoSandbox").Assign(KeyboardKeys.D1)
                .MapClickTo(gt => this.LaunchSandboxSample());

            inputConfiguration.AddDigitalButton("GotoShootEmUp").Assign(KeyboardKeys.D2)
                .MapClickTo(gt => this.LaunchShootEmUpSample());

            inputConfiguration.AddDigitalButton("GotoTiled").Assign(KeyboardKeys.D3)
                .MapClickTo(gt => this.LaunchTiledSample());

            inputConfiguration.AddDigitalButton("GotoTouch").Assign(KeyboardKeys.D4)
                .MapClickTo(gt => this.LaunchTouchSample());

            // Mouse
            Func<RectangleHit, Samples> hitToSampleFunc = hit =>
            {
                if (hit != null)
                {
                    if (hit.RectangleElement == this.sandboxRectangle) return Samples.Sandbox;
                    if (hit.RectangleElement == this.shootEmUpRectangle) return Samples.ShootEmUp;
                    if (hit.RectangleElement == this.tiledRectangle) return Samples.Tiled;
                    if (hit.RectangleElement == this.touchRectangle) return Samples.Touch;
                }

                return Samples.None;
            };

            inputConfiguration.CreateMouseTracking(this.Camera).OnUpdate((mt, e) =>
            {
                this.mouseState = mt;

                var hit = this.Scene.GetHits(this.mouseState.AbsolutePosition, this.Camera).OfType<RectangleHit>().FirstOrDefault();
                this.hoveringSample = hitToSampleFunc(hit);
            });

            inputConfiguration.AddDigitalButton("MouseSelection").Assign(MouseButtons.Left).MapClickTo(elapse =>
            {
                var hit = this.Scene.GetHits(this.mouseState.AbsolutePosition, this.Camera).OfType<RectangleHit>().FirstOrDefault();
                var hitSample = hitToSampleFunc(hit);

                switch (hitSample)
                {
                    case Samples.Sandbox:
                        this.LaunchSandboxSample();
                        break;
                    case Samples.ShootEmUp:
                        this.LaunchShootEmUpSample();
                        break;
                    case Samples.Tiled:
                        this.LaunchTiledSample();
                        break;
                    case Samples.Touch:
                        this.LaunchTouchSample();
                        break;
                }
            });

            // Touch
            inputConfiguration.CreateTouchTracking(this.Camera).OnUpdate((ts, gt) =>
            {
                this.touchState = ts;

                if (this.touchState.Touches.Any())
                {
                    var hit = this.touchState.Touches
                        .SelectMany(t => this.Scene.GetHits(t.Position, this.Camera))
                        .OfType<RectangleHit>().FirstOrDefault();

                    this.hoveringSample = hitToSampleFunc(hit);
                }
            });

            inputConfiguration.AddEvent("TouchSelection").Assign(TouchGestureType.Tap).MapTo(gt =>
            {
                var hit = this.Scene.GetHits(this.touchState.CurrentGesture.Position, this.Camera)
                    .OfType<RectangleHit>().FirstOrDefault();

                var hitSample = hitToSampleFunc(hit);

                switch (hitSample)
                {
                    case Samples.Sandbox:
                        this.LaunchSandboxSample();
                        break;
                    case Samples.ShootEmUp:
                        this.LaunchShootEmUpSample();
                        break;
                    case Samples.Tiled:
                        this.LaunchTiledSample();
                        break;
                    case Samples.Touch:
                        this.LaunchTouchSample();
                        break;
                }
            });

            return inputConfiguration;
        }