示例#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));
        }