Пример #1
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))
     });
 }
Пример #2
0
        private static ObjectAction GetPhase2Action(
            Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary,
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates,
            GuidGenerator guidGenerator)
        {
            string milliHpVariable = guidGenerator.NextGuid();
            string amountOfDamageTakenVariableName = guidGenerator.NextGuid();

            ObjectAction setInitialDamageTakenAction = ObjectActionGenerator.DoOnce(ObjectAction.SetNumericVariable(amountOfDamageTakenVariableName, MathExpression.Constant(0)));

            ObjectAction setInitialMilliHpVariable = ObjectActionGenerator.DoOnce(ObjectAction.SetNumericVariable(milliHpVariable, MathExpression.MilliHP()));

            ObjectAction setDamageTakenVariableAction = ObjectAction.SetNumericVariable(
                amountOfDamageTakenVariableName,
                MathExpression.Add(
                    MathExpression.Variable(amountOfDamageTakenVariableName),
                    MathExpression.Subtract(MathExpression.Variable(milliHpVariable), MathExpression.MilliHP())));

            ObjectAction setMilliHpVariable = ObjectAction.SetNumericVariable(milliHpVariable, MathExpression.MilliHP());

            long phase2InitialMilliHp = 200 * 1000;

            IMathExpression currentMilliHp = MathExpression.Max(
                MathExpression.Subtract(MathExpression.Constant(phase2InitialMilliHp), MathExpression.Variable(amountOfDamageTakenVariableName)),
                MathExpression.Constant(0));

            ObjectAction displayHpBarAction = ObjectAction.DisplayBossHealthBar(
                healthBarMeterNumber: MathExpression.Constant(2),
                healthBarMilliPercentage: MathExpression.Divide(MathExpression.Multiply(currentMilliHp, MathExpression.Constant(100 * 1000)), MathExpression.Constant(phase2InitialMilliHp)));

            ObjectAction goToPhase3Action = ObjectAction.Condition(
                condition: BooleanExpression.Equal(currentMilliHp, MathExpression.Constant(0)),
                action: ObjectActionGenerator.DoOnce(ObjectAction.SetNumericVariable(CurrentPhaseVariableName, MathExpression.Constant(3))));

            ObjectAction shootBulletAction = Phase2ShootAction(
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                guidGenerator: guidGenerator);

            return(ObjectAction.Union(
                       setInitialDamageTakenAction,
                       setInitialMilliHpVariable,
                       setDamageTakenVariableAction,
                       setMilliHpVariable,
                       displayHpBarAction,
                       GetMoveAction(guidGenerator: guidGenerator),
                       goToPhase3Action,
                       shootBulletAction));
        }
Пример #3
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)))));
        }
Пример #4
0
        private static Tuple <ObjectAction, BooleanExpression> MoveToSpecifiedLocations_Helper(
            long startingXMillis,
            long startingYMillis,
            long endingXMillis,
            long endingYMillis,
            long speedInPixelsPerSecond,
            bool shouldStrafe,
            GuidGenerator guidGenerator)
        {
            string variableName  = guidGenerator.NextGuid();
            string variableName2 = guidGenerator.NextGuid();

            long?direction = DTDanmakuMath.GetMovementDirectionInMillidegrees(
                currentX: startingXMillis,
                currentY: startingYMillis,
                desiredX: endingXMillis,
                desiredY: endingYMillis);

            if (direction == null)
            {
                throw new Exception();
            }

            DTDanmakuMath.Offset offset = DTDanmakuMath.GetOffset(
                speedInMillipixelsPerMillisecond: speedInPixelsPerSecond, // millipixels/millisecond is equivalent to pixels/second
                movementDirectionInMillidegrees: direction.Value,
                elapsedMillisecondsPerIteration: 1000);                   // Use the 1000 to help prevent rounding issues

            ObjectAction moveAction = ObjectAction.SetPosition(
                xMillis: MathExpression.Add(MathExpression.XMillis(), MathExpression.Divide(MathExpression.Multiply(MathExpression.Constant(offset.DeltaXInMillipixels), MathExpression.ElapsedMillisecondsPerIteration()), MathExpression.Constant(1000))),
                yMillis: MathExpression.Add(MathExpression.YMillis(), MathExpression.Divide(MathExpression.Multiply(MathExpression.Constant(offset.DeltaYInMillipixels), MathExpression.ElapsedMillisecondsPerIteration()), MathExpression.Constant(1000))));

            ObjectAction setDirectionAction = shouldStrafe
                                ? ObjectAction.SetFacingDirection(facingDirectionInMillidegrees: MathExpression.Constant(180 * 1000))
                                : ObjectAction.SetFacingDirection(facingDirectionInMillidegrees: MathExpression.Constant(direction.Value));

            IMathExpression deltaX             = MathExpression.AbsoluteValue(MathExpression.Subtract(MathExpression.XMillis(), MathExpression.Constant(endingXMillis)));
            IMathExpression deltaY             = MathExpression.AbsoluteValue(MathExpression.Subtract(MathExpression.YMillis(), MathExpression.Constant(endingYMillis)));
            IMathExpression totalDelta         = MathExpression.Add(deltaX, deltaY);
            ObjectAction    setDeltaToVariable = ObjectAction.Union(
                ObjectAction.SetNumericVariable(variableName: variableName2, variableValue: MathExpression.Variable(variableName)),
                ObjectAction.SetNumericVariable(variableName: variableName, variableValue: totalDelta));
            BooleanExpression reachedDestination = BooleanExpression.And(
                BooleanExpression.LessThanOrEqualTo(
                    MathExpression.Variable(variableName2),
                    MathExpression.Variable(variableName)),
                BooleanExpression.And(
                    BooleanExpression.GreaterThanOrEqualTo(MathExpression.Variable(variableName), MathExpression.Constant(0)),
                    BooleanExpression.GreaterThanOrEqualTo(MathExpression.Variable(variableName2), MathExpression.Constant(0))
                    ));

            ObjectAction initializeVariables = ObjectAction.Union(
                ObjectAction.SetNumericVariable(variableName: variableName, variableValue: MathExpression.Constant(-1)),
                ObjectAction.SetNumericVariable(variableName: variableName2, variableValue: MathExpression.Constant(-1)));

            return(new Tuple <ObjectAction, BooleanExpression>(
                       ObjectAction.Union(
                           moveAction,
                           setDirectionAction,
                           ObjectAction.ConditionalNextAction(
                               currentAction: initializeVariables,
                               condition: BooleanExpression.True(),
                               nextAction: setDeltaToVariable)),
                       reachedDestination));
        }
Пример #5
0
        private static ObjectAction GetPhase3Action(
            Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary,
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates,
            Dictionary <string, DTDanmakuSound> soundNameToSoundDictionary,
            GuidGenerator guidGenerator)
        {
            string milliHpVariable = guidGenerator.NextGuid();
            string amountOfDamageTakenVariableName = guidGenerator.NextGuid();

            ObjectAction setInitialDamageTakenAction = ObjectActionGenerator.DoOnce(ObjectAction.SetNumericVariable(amountOfDamageTakenVariableName, MathExpression.Constant(0)));

            ObjectAction setInitialMilliHpVariable = ObjectActionGenerator.DoOnce(ObjectAction.SetNumericVariable(milliHpVariable, MathExpression.MilliHP()));

            ObjectAction setDamageTakenVariableAction = ObjectAction.SetNumericVariable(
                amountOfDamageTakenVariableName,
                MathExpression.Add(
                    MathExpression.Variable(amountOfDamageTakenVariableName),
                    MathExpression.Subtract(MathExpression.Variable(milliHpVariable), MathExpression.MilliHP())));

            ObjectAction setMilliHpVariable = ObjectAction.SetNumericVariable(milliHpVariable, MathExpression.MilliHP());

            long phase3InitialMilliHp = 200 * 1000;

            IMathExpression currentMilliHp = MathExpression.Max(
                MathExpression.Subtract(MathExpression.Constant(phase3InitialMilliHp), MathExpression.Variable(amountOfDamageTakenVariableName)),
                MathExpression.Constant(0));

            ObjectAction displayHpBarAction = ObjectAction.DisplayBossHealthBar(
                healthBarMeterNumber: MathExpression.Constant(1),
                healthBarMilliPercentage: MathExpression.Divide(MathExpression.Multiply(currentMilliHp, MathExpression.Constant(100 * 1000)), MathExpression.Constant(phase3InitialMilliHp)));

            string       soundEffectName = guidGenerator.NextGuid();
            ObjectAction playEnemyDeathSoundEffectAction = ObjectAction.PlaySoundEffect(soundEffectName: soundEffectName);

            soundNameToSoundDictionary.Add(soundEffectName, DTDanmakuSound.EnemyDeath);

            DestructionAnimationGenerator.GenerateDestructionAnimationResult generateDestructionAnimationResult = DestructionAnimationGenerator.GenerateDestructionAnimation(
                orderedSprites: new List <DTDanmakuImage>
            {
                DTDanmakuImage.Explosion1,
                DTDanmakuImage.Explosion2,
                DTDanmakuImage.Explosion3,
                DTDanmakuImage.Explosion4,
                DTDanmakuImage.Explosion5,
                DTDanmakuImage.Explosion6,
                DTDanmakuImage.Explosion7,
                DTDanmakuImage.Explosion8,
                DTDanmakuImage.Explosion9
            },
                millisecondsPerSprite: 20,
                guidGenerator: guidGenerator);

            foreach (var entry in generateDestructionAnimationResult.spriteNameToImageDictionary)
            {
                spriteNameToImageDictionary.Add(entry.Key, entry.Value);
            }
            foreach (var entry in generateDestructionAnimationResult.enemyObjectTemplates)
            {
                enemyObjectTemplates.Add(entry.Key, entry.Value);
            }

            ObjectAction destroyBoss = ObjectAction.Union(
                playEnemyDeathSoundEffectAction,
                generateDestructionAnimationResult.objectAction,
                ObjectAction.Destroy());

            ObjectAction destroyAndEndLevelAction = ObjectAction.Condition(
                condition: BooleanExpression.Equal(currentMilliHp, MathExpression.Constant(0)),
                action: ObjectAction.Union(
                    ObjectAction.EndLevel(),
                    destroyBoss));

            ObjectAction shootBulletAction = Phase3ShootAction(
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                guidGenerator: guidGenerator);

            return(ObjectAction.Union(
                       setInitialDamageTakenAction,
                       setInitialMilliHpVariable,
                       setDamageTakenVariableAction,
                       setMilliHpVariable,
                       displayHpBarAction,
                       GetMoveAction(guidGenerator: guidGenerator),
                       destroyAndEndLevelAction,
                       shootBulletAction));
        }