Ejemplo n.º 1
0
        private static ObjectAction GetSatelliteMoveAndDestroyAction(
            long initialAngleInMillidegrees,
            GuidGenerator guidGenerator)
        {
            string angleVariableName = guidGenerator.NextGuid();

            ObjectAction initializeAngleVariableAction = ObjectActionGenerator.DoOnce(
                ObjectAction.SetNumericVariable(angleVariableName, MathExpression.Constant(initialAngleInMillidegrees)));

            ObjectAction updateAngleVariableAction = ObjectAction.Union(
                ObjectAction.SetNumericVariable(
                    angleVariableName,
                    MathExpression.Add(MathExpression.Variable(angleVariableName), MathExpression.Multiply(MathExpression.Constant(50), MathExpression.ElapsedMillisecondsPerIteration()))),
                ObjectAction.Condition(
                    condition: BooleanExpression.GreaterThan(MathExpression.Variable(angleVariableName), MathExpression.Constant(360 * 1000)),
                    action: ObjectAction.SetNumericVariable(angleVariableName, MathExpression.Subtract(MathExpression.Variable(angleVariableName), MathExpression.Constant(360 * 1000)))),
                ObjectAction.Condition(
                    condition: BooleanExpression.GreaterThan(MathExpression.Variable(angleVariableName), MathExpression.Constant(360 * 1000)),
                    action: ObjectAction.SetNumericVariable(angleVariableName, MathExpression.Constant(0))));

            long radius = 110;

            ObjectAction setPositionAction = ObjectAction.SetPosition(
                xMillis: MathExpression.Add(MathExpression.ParentXMillis(), MathExpression.Multiply(MathExpression.Constant(radius), MathExpression.CosineScaled(MathExpression.Multiply(MathExpression.Variable(angleVariableName), MathExpression.Constant(-1))))),
                yMillis: MathExpression.Add(MathExpression.ParentYMillis(), MathExpression.Multiply(MathExpression.Constant(radius), MathExpression.SineScaled(MathExpression.Multiply(MathExpression.Variable(angleVariableName), MathExpression.Constant(-1))))));

            string facingAngleVariableName = guidGenerator.NextGuid();

            ObjectAction initializeFacingAngleVariableAction = ObjectActionGenerator.DoOnce(
                ObjectAction.SetNumericVariable(facingAngleVariableName, MathExpression.RandomInteger(360 * 1000)));
            ObjectAction updateFacingAngleVariableAction = ObjectAction.Union(
                ObjectAction.SetNumericVariable(
                    facingAngleVariableName,
                    MathExpression.Add(MathExpression.Variable(facingAngleVariableName), MathExpression.Multiply(MathExpression.Constant(500), MathExpression.ElapsedMillisecondsPerIteration()))),
                ObjectAction.Condition(
                    condition: BooleanExpression.GreaterThan(MathExpression.Variable(facingAngleVariableName), MathExpression.Constant(360 * 1000)),
                    action: ObjectAction.SetNumericVariable(facingAngleVariableName, MathExpression.Subtract(MathExpression.Variable(facingAngleVariableName), MathExpression.Constant(360 * 1000)))),
                ObjectAction.Condition(
                    condition: BooleanExpression.GreaterThan(MathExpression.Variable(facingAngleVariableName), MathExpression.Constant(360 * 1000)),
                    action: ObjectAction.SetNumericVariable(facingAngleVariableName, MathExpression.Constant(0))));
            ObjectAction setFacingDirectionAction = ObjectAction.SetFacingDirection(MathExpression.Multiply(MathExpression.Variable(facingAngleVariableName), MathExpression.Constant(-1)));

            ObjectAction destroyAction = ObjectAction.Condition(
                condition: BooleanExpression.IsParentDestroyed(),
                action: ObjectAction.Destroy());

            return(ObjectAction.Union(
                       initializeAngleVariableAction,
                       updateAngleVariableAction,
                       setPositionAction,
                       initializeFacingAngleVariableAction,
                       updateFacingAngleVariableAction,
                       setFacingDirectionAction,
                       destroyAction));
        }
Ejemplo n.º 2
0
        /*
         *      If (currentX, currentY) == (desiredX, desiredY), then
         *      the resulting movement direction is arbitrary.
         */
        public static ObjectAction MoveTowardsLocation(
            IMathExpression currentX,
            IMathExpression currentY,
            IMathExpression desiredX,
            IMathExpression desiredY,

            /*
             *      Note that movement speed is not affected by shouldSnapshot
             */
            IMathExpression movementSpeedInPixelsPerSecond,

            /*
             *      When true, will decide movement direction on the first frame, and keep that direction.
             *      When false, will continuously move towards (desiredX, desiredY)
             */
            bool shouldSnapshot,
            GuidGenerator guidGenerator)
        {
            string deltaXVariable = guidGenerator.NextGuid();
            string deltaYVariable = guidGenerator.NextGuid();

            ObjectAction setDeltaX = ObjectAction.SetNumericVariable(deltaXVariable, MathExpression.Subtract(desiredX, currentX));
            ObjectAction setDeltaY = ObjectAction.SetNumericVariable(deltaYVariable, MathExpression.Subtract(desiredY, currentY));

            BooleanExpression areDeltasBothZero = BooleanExpression.And(
                BooleanExpression.Equal(MathExpression.Variable(deltaXVariable), MathExpression.Constant(0)),
                BooleanExpression.Equal(MathExpression.Variable(deltaYVariable), MathExpression.Constant(0)));

            string angleInMillidegreesVariable = guidGenerator.NextGuid();

            ObjectAction setAngle = ObjectAction.Union(
                shouldSnapshot ? ObjectActionGenerator.DoOnce(setDeltaX) : setDeltaX,
                shouldSnapshot ? ObjectActionGenerator.DoOnce(setDeltaY) : setDeltaY,
                ObjectAction.Condition(
                    condition: areDeltasBothZero,
                    action: ObjectAction.SetNumericVariable(angleInMillidegreesVariable, MathExpression.Constant(0))),
                ObjectAction.Condition(
                    condition: BooleanExpression.Not(areDeltasBothZero),
                    action: ObjectAction.SetNumericVariable(angleInMillidegreesVariable, MathExpression.ArcTangentScaled(MathExpression.Variable(deltaXVariable), MathExpression.Variable(deltaYVariable), false))),
                ObjectAction.SetNumericVariable(angleInMillidegreesVariable, MathExpression.Multiply(MathExpression.Variable(angleInMillidegreesVariable), MathExpression.Constant(-1))),
                ObjectAction.SetNumericVariable(angleInMillidegreesVariable, MathExpression.Add(MathExpression.Variable(angleInMillidegreesVariable), 90 * 1000)));

            IMathExpression xMillis =
                MathExpression.Divide(
                    MathExpression.Multiply(
                        movementSpeedInPixelsPerSecond,
                        MathExpression.ElapsedMillisecondsPerIteration(),
                        MathExpression.SineScaled(MathExpression.Variable(angleInMillidegreesVariable))),
                    MathExpression.Constant(1000));
            IMathExpression yMillis =
                MathExpression.Divide(
                    MathExpression.Multiply(
                        movementSpeedInPixelsPerSecond,
                        MathExpression.ElapsedMillisecondsPerIteration(),
                        MathExpression.CosineScaled(MathExpression.Variable(angleInMillidegreesVariable))),
                    MathExpression.Constant(1000));

            string       xMillisVariable    = guidGenerator.NextGuid();
            string       yMillisVariable    = guidGenerator.NextGuid();
            ObjectAction setXMillisVariable = shouldSnapshot
                                ? ObjectActionGenerator.DoOnce(ObjectAction.SetNumericVariable(xMillisVariable, xMillis))
                                : ObjectAction.SetNumericVariable(xMillisVariable, xMillis);
            ObjectAction setYMillisVariable = shouldSnapshot
                                ? ObjectActionGenerator.DoOnce(ObjectAction.SetNumericVariable(yMillisVariable, yMillis))
                                : ObjectAction.SetNumericVariable(yMillisVariable, yMillis);

            return(ObjectAction.Union(
                       setAngle,
                       setXMillisVariable,
                       setYMillisVariable,
                       ObjectAction.SetPosition(
                           xMillis: MathExpression.Add(MathExpression.XMillis(), MathExpression.Variable(xMillisVariable)),
                           yMillis: MathExpression.Add(MathExpression.YMillis(), MathExpression.Variable(yMillisVariable)))));
        }
Ejemplo n.º 3
0
 public static MathExpressionOffset GetOffset(
     IMathExpression millipixels,
     IMathExpression movementDirectionInMillidegrees)
 {
     return(new MathExpressionOffset
     {
         DeltaXInMillipixels = MathExpression.Divide(MathExpression.Multiply(millipixels, MathExpression.SineScaled(movementDirectionInMillidegrees)), MathExpression.Constant(1000L)),
         DeltaYInMillipixels = MathExpression.Divide(MathExpression.Multiply(millipixels, MathExpression.CosineScaled(movementDirectionInMillidegrees)), MathExpression.Constant(1000L))
     });
 }