Beispiel #1
0
 public void Clear()
 {
     SpeedModifier   = 1.0f;
     Loft            = 0.0f;
     Strength        = 0.0f;
     CreatableId     = Guid.Empty;
     Pronoun         = PronounModifier.Pronouns.None;
     Reset           = ResetModifier.Resets.None;
     Color           = Classification.Colors.None;
     Pitch           = PitchModifier.PitchDirections.None;
     Turn            = TurnModifier.TurnDirections.None;
     Make            = MakeObjectModifier.MakeObjects.None;
     Item            = ObjectModifier.ModifierObjects.None;
     TaskId          = TaskModifier.TaskIds.SIZEOF;
     Direction       = Programming.Directions.None;
     Facial          = Face.FaceState.NotApplicable;
     ExpressEmitter  = ExpressModifier.Emitters.NotApplicable;
     Verb            = GameThing.Verbs.None;
     MissileBehavior = MissileChassis.BehaviorFlags.TerrainFollowing;
     Constraints     = ConstraintModifier.Constraints.None;
     SoundUpid       = String.Empty;
     Points          = 0;
     PlayerIndex     = GamePadSensor.PlayerId.Dynamic;
     ScoreBucket     = ScoreBucket.NotApplicable;
 }
        public override bool MatchAction(Reflex reflex, out object param)
        {
            // See if there's a filter defining which player we should be.  If not, use bit0.
            if (playerId == GamePadSensor.PlayerId.Dynamic)
            {
                playerId = GamePadSensor.PlayerId.All;

                ReflexData data = reflex.Data;
                for (int i = 0; i < data.Filters.Count; i++)
                {
                    if (data.Filters[i] is PlayerFilter)
                    {
                        playerId = ((PlayerFilter)data.Filters[i]).playerIndex;
                    }
                }
            }

            bool shaken = false;

#if !NETFX_CORE
            Microbit bit = MicrobitExtras.GetMicrobitOrNull(playerId);
            if (bit != null)
            {
                int currGeneration = bit.State.Generation;

                if (currGeneration != 0 && currGeneration != prevGeneration)
                {
                    Vector3 currAccel = bit.State.Acc;
                    Vector3 accelDiff = currAccel - prevAccel;
                    prevAccel      = currAccel;
                    prevGeneration = currGeneration;
                    float strength = accelDiff.Length();

                    // Default range [1, 2]
                    float minStrength = 1;
                    float maxStrength = 2;  // 2G - This is the maximum length of micro:bit's accelerometer vector (configured in kodu-microbit.hex).

                    int stronglyCount = reflex.Data.GetFilterCount("filter.strongly");
                    // Range adjustment upward to [1.5, 2]
                    minStrength += stronglyCount * 0.166f;
                    int weaklyCount = reflex.Data.GetFilterCount("filter.weakly");
                    // Range adjustment downward to [0.075, 0.2]
                    minStrength -= weaklyCount * 0.308f;
                    maxStrength -= weaklyCount * 0.6f;

                    shaken = (strength >= minStrength && strength <= maxStrength);
                    //System.Diagnostics.Debug.WriteLine(String.Format("range [{0},{1}], value {2}, {3}", minStrength, maxStrength, strength, shaken ? "SHAKE!" : ""));
                }
            }
#endif

            param = shaken;

            return(shaken);
        }
        public static Microbit GetMicrobitOrNull(GamePadSensor.PlayerId playerId)
        {
            // TODO @*******: Decide how to handle the PlayerId.All case, for now use player one.
            if (playerId == GamePadSensor.PlayerId.All)
            {
                playerId = GamePadSensor.PlayerId.One;
            }

            Microbit microbit;

            MicrobitManager.Microbits.TryGetValue((int)playerId, out microbit);
            return(microbit);
        }
        public override bool MatchAction(Reflex reflex, out object param)
        {
            GamePadSensor.PlayerId playerIdSensor = (GamePadSensor.PlayerId)reflex.targetSet.Param;

            if (this.playerId != playerIdSensor)
            {
                this.playerId = playerIdSensor;
            }

            GamePadInput pad = null;

            // Get the correct game pad.
            switch (playerId)
            {
            case GamePadSensor.PlayerId.All:
                pad = GamePadInput.GetGamePad0();
                break;

            case GamePadSensor.PlayerId.One:
                pad = GamePadInput.GetGamePad1();
                break;

            case GamePadSensor.PlayerId.Two:
                pad = GamePadInput.GetGamePad2();
                break;

            case GamePadSensor.PlayerId.Three:
                pad = GamePadInput.GetGamePad3();
                break;

            case GamePadSensor.PlayerId.Four:
                pad = GamePadInput.GetGamePad4();
                break;
            }

            if (trigger == GamePadTrigger.LeftTrigger)
            {
                triggerValue = pad.LeftTrigger;
            }
            else if (trigger == GamePadTrigger.RightTrigger)
            {
                triggerValue = pad.RightTrigger;
            }

            // Return as a parameter a vector that can be used for input to the movement system, so
            // that players can drive and turn bots using gamepad triggers.
            param = new Vector2(0, triggerValue);

            return(triggerValue > 0); // only if pressed
        }
        public static void Reset()
        {
            activeTeam     = Classification.Colors.NotApplicable;
            activePlayer   = GamePadSensor.PlayerId.Dynamic;
            activeWinner   = false;
            activeGameOver = false;

            alphaTeam     = 0.0f;
            alphaWinner   = 0.0f;
            alphaGameOver = 0.0f;

            timeoutTeam     = 0.0;
            timeoutWinner   = 0.0;
            timeoutGameOver = 0.0;
        }
        public override bool MatchAction(Reflex reflex, out object param)
        {
            float result = 0;

            // See if there's a filter defining which player we should be.  If not, use pad0.
            if (playerId == GamePadSensor.PlayerId.Dynamic)
            {
                playerId = GamePadSensor.PlayerId.All;

                ReflexData data = reflex.Data;
                for (int i = 0; i < data.Filters.Count; i++)
                {
                    if (data.Filters[i] is PlayerFilter)
                    {
                        playerId = ((PlayerFilter)data.Filters[i]).playerIndex;
                    }
                }
            }

#if !NETFX_CORE
            Microbit bit = MicrobitExtras.GetMicrobitOrNull(playerId);
            if (bit != null)
            {
                // Get the correct button.
                switch (pin)
                {
                case MicrobitPin.Pin1:
                    result = bit.ReadPinValue(0, Microbit.EPinOperatingMode.Digital);
                    break;

                case MicrobitPin.Pin2:
                    result = bit.ReadPinValue(1, Microbit.EPinOperatingMode.Digital);
                    break;

                case MicrobitPin.Pin3:
                    result = bit.ReadPinValue(2, Microbit.EPinOperatingMode.Digital);
                    break;
                }
            }
#endif

            // Return as a parameter a vector that can be used for input to the movement system, so
            // that players can drive and turn bots using gamepad buttons.
            param = new Vector2(0, result / 255.0f);

            return(result != 0);
        }
        public override bool MatchAction(Reflex reflex, out object param)
        {
            bool result = false;

            // See if there's a filter defining which player we should be.  If not, use bit0.
            if (playerId == GamePadSensor.PlayerId.Dynamic)
            {
                playerId = GamePadSensor.PlayerId.All;

                ReflexData data = reflex.Data;
                for (int i = 0; i < data.Filters.Count; i++)
                {
                    if (data.Filters[i] is PlayerFilter)
                    {
                        playerId = ((PlayerFilter)data.Filters[i]).playerIndex;
                    }
                }
            }

#if !NETFX_CORE
            Microbit bit = MicrobitExtras.GetMicrobitOrNull(playerId);
            if (bit != null)
            {
                // Get the correct button.
                switch (button)
                {
                case MicrobitButton.Left:
                    result = bit.State.ButtonA.IsPressed();
                    break;

                case MicrobitButton.Right:
                    result = bit.State.ButtonB.IsPressed();
                    break;
                }
            }
#endif

            // Return as a parameter a vector that can be used for input to the movement system, so
            // that players can drive and turn bots using gamepad buttons.
            param = new Vector2(0, 1);

            return(result);
        }
Beispiel #8
0
        public override bool MatchAction(Reflex reflex, out object param)
        {
            UpdateCommands();

            // See if there's a filter defining which player we should be.  If not, use pad0.
            if (playerId == GamePadSensor.PlayerId.Dynamic)
            {
                playerId = GamePadSensor.PlayerId.All;

                ReflexData data = reflex.Data;
                for (int i = 0; i < data.Filters.Count; i++)
                {
                    if (data.Filters[i] is PlayerFilter)
                    {
                        playerId = ((PlayerFilter)data.Filters[i]).playerIndex;
                    }
                }
            }

            bool match = false;

            param             = null;
            this.tiltPosition = Vector2.Zero;

#if !NETFX_CORE
            // TODO @*******: use the player# to get the right Microbit, or blended from all if no player#.
            Microbit bit = MicrobitExtras.GetMicrobitOrNull(playerId);
            if (bit != null)
            {
                tiltPosition = new Vector2(bit.State.Acc.Y, -bit.State.Acc.X);
                tiltPosition = DeadZone(tiltPosition * tiltPosition * new Vector2(Math.Sign(tiltPosition.X), Math.Sign(tiltPosition.Y)), 0.01f);
            }
#endif

            param = this.tiltPosition;
            match = (this.tiltPosition != Vector2.Zero); // only if not centered

            return(match);
        }   // end of MatchAction()
        public override bool MatchAction(Reflex reflex, out object param)
        {
            GamePadSensor.PlayerId playerIdSensor = (GamePadSensor.PlayerId)reflex.targetSet.Param;
            if (this.playerId != playerIdSensor)
            {
                this.playerId = playerIdSensor;
                UpdateCommands();
            }

            bool isPitch = (reflex.Selector is MoveDownSelector) ||
                           (reflex.Selector is MoveUpDownSelector) ||
                           (reflex.Selector is MoveUpSelector);
            bool isYaw = !isPitch && reflex.Data.IsMovement();

            bool match = false;

            param = null;
            if (this.stickCommands.Count != 0)
            {
                this.stickPosition = Vector2.Zero;
                for (int indexCommand = 0; indexCommand < this.stickCommands.Count; indexCommand++)
                {
                    StickCommand command = this.stickCommands[indexCommand] as StickCommand;
                    command.Update();
                    // Bias stick input toward center if pushing forward.
                    Vector2 stick = command.Position;

                    if (isPitch)
                    {
                        bool invert = GamePadInput.InvertYAxis(command.playerIndex);
                        if (invert)
                        {
                            stick.Y = -stick.Y;
                        }
                    }
                    if (isYaw)
                    {
                        bool invert = GamePadInput.InvertXAxis(command.playerIndex);
                        if (invert)
                        {
                            stick.X = -stick.X;
                        }
                    }

                    // 5% flat deadzone.
                    Vector2 s;
                    s.X            = stick.X > 0 ? Math.Max(stick.X * 1.05f - 0.05f, 0) : Math.Min(stick.X * 1.05f + 0.05f, 0);
                    s.Y            = stick.Y > 0 ? Math.Max(stick.Y * 1.05f - 0.05f, 0) : Math.Min(stick.Y * 1.05f + 0.05f, 0);
                    stickPosition += s;

                    // If a stick is being used for input in a bot program, don't blend it into gamepad0.
                    if (command is Input.GamePadRightThumbStick)
                    {
                        GamePadInput.GetGamePad(GamePadInput.LogicalToGamePad(command.playerIndex)).RightStickIgnoreForGamePad0();
                    }
                    else if (command is Input.GamePadLeftThumbStick)
                    {
                        GamePadInput.GetGamePad(GamePadInput.LogicalToGamePad(command.playerIndex)).LeftStickIgnoreForGamePad0();
                    }
                }

                param = this.stickPosition;
                match = (this.stickPosition != Vector2.Zero); // only if not centered
            }

            return(match);
        }
 public override void Reset(Reflex reflex)
 {
     this.playerId = GamePadSensor.PlayerId.Dynamic;
     triggerValue  = 0;
     base.Reset(reflex);
 }
        public override bool MatchAction(Reflex reflex, out object param)
        {
            bool result = false;

            // Only jump through hoops the first time to get the pad.
            if (ButtonState == null)
            {
                GamePadInput pad = null;

                // See if there's a filter defining which player we should be.  If not, use pad0.
                if (playerId == GamePadSensor.PlayerId.Dynamic)
                {
                    playerId = GamePadSensor.PlayerId.All;

                    ReflexData data = reflex.Data;
                    for (int i = 0; i < data.Filters.Count; i++)
                    {
                        if (data.Filters[i] is PlayerFilter)
                        {
                            playerId = ((PlayerFilter)data.Filters[i]).playerIndex;
                        }
                    }
                }

                // Get the correct game pad.
                switch (playerId)
                {
                case GamePadSensor.PlayerId.All:
                    pad = GamePadInput.GetGamePad0();
                    break;

                case GamePadSensor.PlayerId.One:
                    pad = GamePadInput.GetGamePad1();
                    break;

                case GamePadSensor.PlayerId.Two:
                    pad = GamePadInput.GetGamePad2();
                    break;

                case GamePadSensor.PlayerId.Three:
                    pad = GamePadInput.GetGamePad3();
                    break;

                case GamePadSensor.PlayerId.Four:
                    pad = GamePadInput.GetGamePad4();
                    break;
                }

                // Get the correct game pad button.
                switch (button)
                {
                case GamePadButton.A:
                    ButtonState = pad.ButtonA;
                    break;

                case GamePadButton.B:
                    ButtonState = pad.ButtonB;
                    break;

                case GamePadButton.X:
                    ButtonState = pad.ButtonX;
                    break;

                case GamePadButton.Y:
                    ButtonState = pad.ButtonY;
                    break;

                case GamePadButton.LeftTrigger:
                    ButtonState = pad.LeftTriggerButton;
                    break;

                case GamePadButton.RightTrigger:
                    ButtonState = pad.RightTriggerButton;
                    break;
                }
            }

            result = ButtonState.IsPressed;

            // Return as a parameter a vector that can be used for input to the movement system, so
            // that players can drive and turn bots using gamepad buttons.
            param = new Vector2(0, 1);

            return(result);
        }