Ejemplo n.º 1
0
		public PlayerInput(Stage stage, PlayerShip Ego, DisplayObject Owner)
		{



			#region Ego Movement


			// ego input
			stage.click +=
				e =>
				{
					if (!Enabled)
						return;

					var p = Owner.globalToLocal(e.ToStagePoint());

					if (SmartMoveTo != null)
						SmartMoveTo(p.x, p.y);
				};

			stage.mouseMove +=
				e =>
				{
					if (!Enabled)
						return;

					if (e.buttonDown)
					{
						var p = Owner.globalToLocal(e.ToStagePoint());

						if (SmartMoveTo != null)
							SmartMoveTo(p.x, p.y);
					}
				};


			var GoLeft = new KeyboardButton(stage)
			{
				Groups = new[]
                {
                    MovementWASD[Keyboard.A],
                    MovementArrows[Keyboard.LEFT],
                },
				Filter = Enabled,
				Tick = () => this.StepLeft(),
				Up = () => this.StepLeftEnd()
			};

			var GoRight = new KeyboardButton(stage)
			{
				Groups = new[]
                {
                    MovementWASD[Keyboard.D],
                    MovementArrows[Keyboard.RIGHT],
                },
				Filter = Enabled,
				Tick = () => this.StepRight(),
				Up = () => this.StepRightEnd()
			};
			#endregion


			#region EgoFire
			var DoFire = new KeyboardButton(stage, 700)
			{
				Groups = new[]
                {
                    MovementWASD[Keyboard.CONTROL , KeyLocation.LEFT],
                    MovementArrows[Keyboard.RIGHT , KeyLocation.RIGHT],
                    MovementArrows[Keyboard.SPACE],
                },
				Filter = Enabled,
				Tick = () => FireBullet()

			};

			stage.mouseDown +=
				delegate
				{
					if (!Enabled)
						return;

					DoFire.ForceKeyDown();
				};

			stage.mouseUp +=
				delegate
				{
					if (!Enabled)
						return;

					DoFire.ForceKeyUp();
				};
			#endregion
		}
Ejemplo n.º 2
0
        public PlayerInput(Stage stage, PlayerShip Ego, DisplayObject Owner)
        {
            #region Ego Movement


            // ego input
            stage.click +=
                e =>
            {
                if (!Enabled)
                {
                    return;
                }

                var p = Owner.globalToLocal(e.ToStagePoint());

                if (SmartMoveTo != null)
                {
                    SmartMoveTo(p.x, p.y);
                }
            };

            stage.mouseMove +=
                e =>
            {
                if (!Enabled)
                {
                    return;
                }

                if (e.buttonDown)
                {
                    var p = Owner.globalToLocal(e.ToStagePoint());

                    if (SmartMoveTo != null)
                    {
                        SmartMoveTo(p.x, p.y);
                    }
                }
            };


            var GoLeft = new KeyboardButton(stage)
            {
                Groups = new[]
                {
                    MovementWASD[Keyboard.A],
                    MovementArrows[Keyboard.LEFT],
                },
                Filter = Enabled,
                Tick   = () => this.StepLeft(),
                Up     = () => this.StepLeftEnd()
            };

            var GoRight = new KeyboardButton(stage)
            {
                Groups = new[]
                {
                    MovementWASD[Keyboard.D],
                    MovementArrows[Keyboard.RIGHT],
                },
                Filter = Enabled,
                Tick   = () => this.StepRight(),
                Up     = () => this.StepRightEnd()
            };
            #endregion


            #region EgoFire
            var DoFire = new KeyboardButton(stage, 700)
            {
                Groups = new[]
                {
                    MovementWASD[Keyboard.CONTROL, KeyLocation.LEFT],
                    MovementArrows[Keyboard.RIGHT, KeyLocation.RIGHT],
                    MovementArrows[Keyboard.SPACE],
                },
                Filter = Enabled,
                Tick   = () => FireBullet()
            };

            stage.mouseDown +=
                delegate
            {
                if (!Enabled)
                {
                    return;
                }

                DoFire.ForceKeyDown();
            };

            stage.mouseUp +=
                delegate
            {
                if (!Enabled)
                {
                    return;
                }

                DoFire.ForceKeyUp();
            };
            #endregion
        }