Exemplo n.º 1
0
        private static ObjectAction GetSatelliteShootAction(
            Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary,
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates,
            GuidGenerator guidGenerator)
        {
            IMathExpression initialShootCooldownInMillis = MathExpression.RandomInteger(6000);
            IMathExpression shootCooldownInMillis        = MathExpression.Add(5000, MathExpression.RandomInteger(1000));

            string cooldownVariableName = guidGenerator.NextGuid();

            ObjectAction initialStartCooldownAction = ObjectAction.SetNumericVariable(cooldownVariableName, initialShootCooldownInMillis);
            ObjectAction startCooldownAction        = ObjectAction.SetNumericVariable(cooldownVariableName, shootCooldownInMillis);
            ObjectAction decrementCooldownAction    = ObjectAction.SetNumericVariable(cooldownVariableName, MathExpression.Subtract(MathExpression.Variable(cooldownVariableName), MathExpression.ElapsedMillisecondsPerIteration()));
            ObjectAction createBulletAction         = SpawnSatelliteBullet(
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                guidGenerator: guidGenerator);

            var createBulletWhenCooldownFinishedAction = ObjectAction.Condition(
                condition: BooleanExpression.LessThanOrEqualTo(MathExpression.Variable(cooldownVariableName), MathExpression.Constant(0)),
                action: ObjectAction.Union(startCooldownAction, createBulletAction));

            return(ObjectAction.ConditionalNextAction(
                       currentAction: initialStartCooldownAction,
                       condition: BooleanExpression.True(),
                       nextAction: ObjectAction.Union(decrementCooldownAction, createBulletWhenCooldownFinishedAction)));
        }
Exemplo n.º 2
0
        public static ObjectAction DestroyWhenHpIsZeroAndMaybeDropPowerUp(
            long chanceToDropPowerUpInMilliPercent,             // ranges from 0 (meaning 0%) to 100,000 (meaning 100%)
            Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary,
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates,
            Dictionary <string, DTDanmakuSound> soundNameToSoundDictionary,
            GuidGenerator guidGenerator)
        {
            string soundEffectName = guidGenerator.NextGuid();

            BooleanExpression isHpZero = BooleanExpression.LessThanOrEqualTo(
                MathExpression.MilliHP(),
                MathExpression.Constant(0));

            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 possiblySpawnPowerUpAction = ObjectAction.Condition(
                condition: BooleanExpression.LessThan(
                    MathExpression.RandomInteger(MathExpression.Constant(100 * 1000)),
                    MathExpression.Constant(chanceToDropPowerUpInMilliPercent)),
                action: ObjectAction.SpawnPowerUp());

            return(ObjectAction.Condition(
                       condition: isHpZero,
                       action: ObjectAction.Union(
                           playEnemyDeathSoundEffectAction,
                           generateDestructionAnimationResult.objectAction,
                           possiblySpawnPowerUpAction,
                           ObjectAction.Destroy())));
        }
Exemplo n.º 3
0
        public static ObjectAction SpawnBarrageEnemy(
            IMathExpression xMillis,
            Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary,
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates,
            Dictionary <string, DTDanmakuSound> soundNameToSoundDictionary,
            GuidGenerator guidGenerator)
        {
            // Should be called first so it sets the "can shoot" variable that the shootBullet action will need
            ObjectAction moveAction = GetMoveAndSetCanShootVariableAction(
                xMillis: xMillis,
                guidGenerator: guidGenerator);

            ObjectAction shootAction = GetShootBulletAction(
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                guidGenerator: guidGenerator);

            ObjectAction destroyAction = ObjectActionGenerator.DestroyWhenHpIsZeroAndMaybeDropPowerUp(
                chanceToDropPowerUpInMilliPercent: 15 * 1000,
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                soundNameToSoundDictionary: soundNameToSoundDictionary,
                guidGenerator: guidGenerator);

            string spriteName = guidGenerator.NextGuid();

            spriteNameToImageDictionary.Add(spriteName, DTDanmakuImage.BarrageEnemyShip);

            List <ObjectBox> damageBoxes = new List <ObjectBox>();

            damageBoxes.Add(new ObjectBox(lowerXMillis: -46500, upperXMillis: 46500, lowerYMillis: 0, upperYMillis: 40000));
            damageBoxes.Add(new ObjectBox(lowerXMillis: -31500, upperXMillis: 31500, lowerYMillis: -35000, upperYMillis: 30000));

            List <ObjectBox> collisionBoxes = new List <ObjectBox>();

            collisionBoxes.Add(new ObjectBox(lowerXMillis: -10000, upperXMillis: 10000, lowerYMillis: -25000, upperYMillis: 25000));
            collisionBoxes.Add(new ObjectBox(lowerXMillis: -25000, upperXMillis: 25000, lowerYMillis: -10000, upperYMillis: 10000));

            EnemyObjectTemplate enemyObjectTemplate = EnemyObjectTemplate.Enemy(
                action: ObjectAction.Union(moveAction, shootAction, destroyAction),
                initialMilliHP: MathExpression.Add(MathExpression.Constant(38000), MathExpression.RandomInteger(MathExpression.Constant(10000))),
                damageBoxes: damageBoxes,
                collisionBoxes: collisionBoxes,
                spriteName: spriteName);

            string templateName = guidGenerator.NextGuid();

            enemyObjectTemplates.Add(templateName, enemyObjectTemplate);

            return(ObjectAction.SpawnChild(
                       childXMillis: MathExpression.Constant(-1000 * 1000),
                       childYMillis: MathExpression.Constant(-1000 * 1000),
                       childObjectTemplateName: templateName,
                       childInitialNumericVariables: null,
                       childInitialBooleanVariables: null));
        }
Exemplo n.º 4
0
        private static ObjectAction GetShootBulletAction(
            Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary,
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates,
            GuidGenerator guidGenerator)
        {
            IMathExpression initialShootCooldownInMillis = MathExpression.RandomInteger(2750);
            IMathExpression shootCooldownInMillis        = MathExpression.Add(1750, MathExpression.RandomInteger(1000));

            string cooldownVariableName    = guidGenerator.NextGuid();
            string childObjectTemplateName = guidGenerator.NextGuid();
            string enemyBulletSpriteName   = guidGenerator.NextGuid();

            IMathExpression facingAngleInMillidegrees = DTDanmakuMath.GetMovementDirectionInMillidegrees(
                currentX: MathExpression.XMillis(),
                currentY: MathExpression.YMillis(),
                desiredX: MathExpression.PlayerXMillis(),
                desiredY: MathExpression.Min(MathExpression.PlayerYMillis(), 300 * 1000));

            DTDanmakuMath.MathExpressionOffset deltaXAndY = DTDanmakuMath.GetOffset(
                millipixels: MathExpression.Constant(40000),
                movementDirectionInMillidegrees: facingAngleInMillidegrees);

            ObjectAction initialStartCooldownAction = ObjectAction.SetNumericVariable(cooldownVariableName, initialShootCooldownInMillis);
            ObjectAction startCooldownAction        = ObjectAction.SetNumericVariable(cooldownVariableName, shootCooldownInMillis);
            ObjectAction decrementCooldownAction    = ObjectAction.SetNumericVariable(cooldownVariableName, MathExpression.Subtract(MathExpression.Variable(cooldownVariableName), MathExpression.ElapsedMillisecondsPerIteration()));
            ObjectAction createBulletAction         = ObjectAction.SpawnChild(
                childXMillis: MathExpression.Add(MathExpression.XMillis(), deltaXAndY.DeltaXInMillipixels),
                childYMillis: MathExpression.Add(MathExpression.YMillis(), deltaXAndY.DeltaYInMillipixels),
                childObjectTemplateName: childObjectTemplateName,
                childInitialNumericVariables: null,
                childInitialBooleanVariables: null);

            List <ObjectBox> collisionBoxes = new List <ObjectBox>();

            collisionBoxes.Add(new ObjectBox(lowerXMillis: -4000, upperXMillis: 4000, lowerYMillis: -4000, upperYMillis: 4000));

            enemyObjectTemplates.Add(childObjectTemplateName,
                                     EnemyObjectTemplate.EnemyBullet(
                                         action: ObjectAction.Union(GetBulletMovementAction(guidGenerator: guidGenerator), GetBulletAnimationAction(guidGenerator: guidGenerator)),
                                         initialMilliHP: null,
                                         damageBoxes: null,
                                         collisionBoxes: collisionBoxes,
                                         spriteName: enemyBulletSpriteName));

            spriteNameToImageDictionary.Add(enemyBulletSpriteName, DTDanmakuImage.EliteSniperEnemyBullet);

            var createBulletWhenCooldownFinishedAction = ObjectAction.Condition(
                condition: BooleanExpression.LessThanOrEqualTo(MathExpression.Variable(cooldownVariableName), MathExpression.Constant(0)),
                action: ObjectAction.Union(startCooldownAction, createBulletAction));

            return(ObjectAction.ConditionalNextAction(
                       currentAction: initialStartCooldownAction,
                       condition: BooleanExpression.True(),
                       nextAction: ObjectAction.Union(decrementCooldownAction, createBulletWhenCooldownFinishedAction)));
        }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
0
        public static ObjectAction SpawnEliteOrbiterEnemy(
            IMathExpression xMillis,
            Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary,
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates,
            Dictionary <string, DTDanmakuSound> soundNameToSoundDictionary,
            GuidGenerator guidGenerator)
        {
            ObjectAction moveAction = GetMoveAction(
                xMillis: xMillis);

            ObjectAction destroyAction = ObjectActionGenerator.DestroyWhenHpIsZeroAndMaybeDropPowerUp(
                chanceToDropPowerUpInMilliPercent: 15 * 1000,
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                soundNameToSoundDictionary: soundNameToSoundDictionary,
                guidGenerator: guidGenerator);

            string spriteName = guidGenerator.NextGuid();

            spriteNameToImageDictionary.Add(spriteName, DTDanmakuImage.EliteOrbiterEnemyShip);

            List <ObjectBox> damageBoxes = new List <ObjectBox>();

            damageBoxes.Add(new ObjectBox(lowerXMillis: -68000, upperXMillis: 68000, lowerYMillis: -30000, upperYMillis: 50000));
            damageBoxes.Add(new ObjectBox(lowerXMillis: -46000, upperXMillis: 46000, lowerYMillis: -48000, upperYMillis: 68000));
            damageBoxes.Add(new ObjectBox(lowerXMillis: -26000, upperXMillis: 26000, lowerYMillis: -68000, upperYMillis: 74000));

            List <ObjectBox> collisionBoxes = new List <ObjectBox>();

            collisionBoxes.Add(new ObjectBox(lowerXMillis: -58000, upperXMillis: 58000, lowerYMillis: -35000, upperYMillis: 50000));

            ObjectAction spawnOrbiterSatellitesAction = GetSpawnOrbiterSatellitesAction(
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                guidGenerator: guidGenerator);

            EnemyObjectTemplate enemyObjectTemplate = EnemyObjectTemplate.Enemy(
                action: ObjectAction.Union(moveAction, spawnOrbiterSatellitesAction, destroyAction),
                initialMilliHP: MathExpression.Add(MathExpression.Constant(45000), MathExpression.RandomInteger(MathExpression.Constant(15000))),
                damageBoxes: damageBoxes,
                collisionBoxes: collisionBoxes,
                spriteName: spriteName);

            string templateName = guidGenerator.NextGuid();

            enemyObjectTemplates.Add(templateName, enemyObjectTemplate);

            return(ObjectAction.SpawnChild(
                       childXMillis: MathExpression.Constant(-1000 * 1000),
                       childYMillis: MathExpression.Constant(-1000 * 1000),
                       childObjectTemplateName: templateName,
                       childInitialNumericVariables: null,
                       childInitialBooleanVariables: null));
        }
Exemplo n.º 7
0
        private static ObjectAction GetShootBulletAction(
            Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary,
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates,
            GuidGenerator guidGenerator)
        {
            string angleVariable         = guidGenerator.NextGuid();
            string shootCooldownVariable = guidGenerator.NextGuid();

            ObjectAction initializeAngleVariable = ObjectActionGenerator.DoOnce(
                ObjectAction.SetNumericVariable(angleVariable, MathExpression.RandomInteger(360 * 1000)));

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

            ObjectAction createBulletAction = ObjectAction.Condition(
                condition: BooleanExpression.Variable("can shoot"),
                action: SpawnBullet(
                    bulletDirectionInMillidegrees: MathExpression.ParentVariable(angleVariable),
                    spriteNameToImageDictionary: spriteNameToImageDictionary,
                    enemyObjectTemplates: enemyObjectTemplates,
                    guidGenerator: guidGenerator));

            IMathExpression shootCooldownInMillis   = MathExpression.Constant(50);
            ObjectAction    startCooldownAction     = ObjectAction.SetNumericVariable(shootCooldownVariable, shootCooldownInMillis);
            ObjectAction    decrementCooldownAction = ObjectAction.SetNumericVariable(shootCooldownVariable, MathExpression.Subtract(MathExpression.Variable(shootCooldownVariable), MathExpression.ElapsedMillisecondsPerIteration()));
            ObjectAction    createBulletWhenCooldownFinishedAction = ObjectAction.Condition(
                condition: BooleanExpression.LessThanOrEqualTo(MathExpression.Variable(shootCooldownVariable), MathExpression.Constant(0)),
                action: ObjectAction.Union(startCooldownAction, createBulletAction));

            return(ObjectAction.Union(
                       initializeAngleVariable,
                       updateAngleVariableAction,
                       ObjectActionGenerator.DoOnce(startCooldownAction),
                       decrementCooldownAction,
                       createBulletWhenCooldownFinishedAction));
        }
Exemplo n.º 8
0
        private static ObjectAction SpawnBasicEnemy(
            long initialXMillis,
            long initialYMillis,
            List <Tuple <long, long> > movementPath,
            Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary,
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates,
            Dictionary <string, DTDanmakuSound> soundNameToSoundDictionary,
            GuidGenerator guidGenerator)
        {
            List <ObjectBox> damageBoxes = new List <ObjectBox>();

            damageBoxes.Add(new ObjectBox(lowerXMillis: -46500, upperXMillis: 46500, lowerYMillis: 0, upperYMillis: 40000));
            damageBoxes.Add(new ObjectBox(lowerXMillis: -31500, upperXMillis: 31500, lowerYMillis: -25000, upperYMillis: 40000));
            damageBoxes.Add(new ObjectBox(lowerXMillis: -21500, upperXMillis: 21500, lowerYMillis: -35000, upperYMillis: 40000));

            List <ObjectBox> collisionBoxes = new List <ObjectBox>();

            collisionBoxes.Add(new ObjectBox(lowerXMillis: -10000, upperXMillis: 10000, lowerYMillis: -25000, upperYMillis: 25000));
            collisionBoxes.Add(new ObjectBox(lowerXMillis: -25000, upperXMillis: 25000, lowerYMillis: -10000, upperYMillis: 10000));

            return(ObjectActionGenerator.SpawnEnemyThatMovesToSpecificLocation(
                       initialXMillis: initialXMillis,
                       initialYMillis: initialYMillis,
                       movementPath: movementPath,
                       movementSpeedInPixelsPerSecond: 100,
                       shouldStrafe: true,
                       bulletXOffset: 0,
                       bulletYOffset: -52000,
                       initialShootCooldownInMillis: MathExpression.RandomInteger(5000),
                       shootCooldownInMillis: MathExpression.Add(3000, MathExpression.RandomInteger(2000)),
                       bulletSpeedInPixelsPerSecond: 250,
                       initialMilliHP: MathExpression.Add(MathExpression.Constant(6000), MathExpression.RandomInteger(MathExpression.Constant(5000))),
                       chanceToDropPowerUpInMilliPercent: 15 * 1000,
                       damageBoxes: damageBoxes,
                       collisionBoxes: collisionBoxes,
                       sprite: DTDanmakuImage.BasicEnemyShip,
                       spriteNameToImageDictionary: spriteNameToImageDictionary,
                       enemyObjectTemplates: enemyObjectTemplates,
                       soundNameToSoundDictionary: soundNameToSoundDictionary,
                       guidGenerator: guidGenerator));
        }
Exemplo n.º 9
0
        private static ObjectAction GetBulletAnimationAction(
            GuidGenerator guidGenerator)
        {
            string variableName = guidGenerator.NextGuid();

            return(ObjectAction.Union(
                       ObjectActionGenerator.DoOnce(ObjectAction.SetNumericVariable(variableName, MathExpression.RandomInteger(360 * 1000))),
                       ObjectAction.SetNumericVariable(variableName, MathExpression.Add(MathExpression.Variable(variableName), MathExpression.Multiply(MathExpression.ElapsedMillisecondsPerIteration(), MathExpression.Constant(315)))),
                       ObjectAction.Condition(
                           condition: BooleanExpression.GreaterThan(MathExpression.Variable(variableName), MathExpression.Constant(360 * 1000)),
                           action: ObjectAction.SetNumericVariable(variableName, MathExpression.Subtract(MathExpression.Variable(variableName), MathExpression.Constant(360 * 1000)))),
                       ObjectAction.Condition(
                           condition: BooleanExpression.GreaterThan(MathExpression.Variable(variableName), MathExpression.Constant(360 * 1000)),
                           action: ObjectAction.SetNumericVariable(variableName, MathExpression.Constant(0))),
                       ObjectAction.SetFacingDirection(MathExpression.Multiply(MathExpression.Variable(variableName), MathExpression.Constant(-1)))));
        }
Exemplo n.º 10
0
        private static ObjectAction GetMoveAction(
            GuidGenerator guidGenerator)
        {
            string variableName = guidGenerator.NextGuid();

            ObjectAction initializeVariable = ObjectAction.SetNumericVariable(
                variableName: variableName,
                variableValue: MathExpression.Constant(0));

            ObjectAction incrementVariable = ObjectAction.SetNumericVariable(
                variableName: variableName,
                variableValue: MathExpression.Add(MathExpression.Variable(variableName), MathExpression.ElapsedMillisecondsPerIteration()));

            ObjectAction initializeAndIncrementVariable = ObjectAction.ConditionalNextAction(
                currentAction: initializeVariable,
                condition: BooleanExpression.True(),
                nextAction: incrementVariable);

            ObjectAction teleportToInitialLocation = ObjectAction.SetPosition(
                xMillis: MathExpression.Add(50 * 1000, MathExpression.RandomInteger(900 * 1000)),
                yMillis: MathExpression.Constant(800 * 1000));

            ObjectAction faceTowardsPlayer = ObjectAction.Move(
                moveToXMillis: MathExpression.PlayerXMillis(),
                moveToYMillis: MathExpression.Min(MathExpression.PlayerYMillis(), 300 * 1000));

            ObjectAction setInitialSpeed = ObjectActionGenerator.DoOnce(
                ObjectAction.SetSpeed(
                    speedInMillipixelsPerMillisecond: MathExpression.Constant(60)));

            ObjectAction slowDownSpeed1 = ObjectAction.Condition(
                condition: BooleanExpression.GreaterThanOrEqualTo(
                    MathExpression.Variable(variableName),
                    1 * 1000),
                action: ObjectActionGenerator.DoOnce(
                    ObjectAction.SetSpeed(
                        speedInMillipixelsPerMillisecond: MathExpression.Constant(40))));

            ObjectAction slowDownSpeed2 = ObjectAction.Condition(
                condition: BooleanExpression.GreaterThanOrEqualTo(
                    MathExpression.Variable(variableName),
                    2 * 1000),
                action: ObjectActionGenerator.DoOnce(
                    ObjectAction.SetSpeed(
                        speedInMillipixelsPerMillisecond: MathExpression.Constant(20))));

            ObjectAction stopMovement = ObjectAction.Condition(
                condition: BooleanExpression.GreaterThanOrEqualTo(
                    MathExpression.Variable(variableName),
                    3 * 1000),
                action: ObjectActionGenerator.DoOnce(
                    ObjectAction.SetSpeed(
                        speedInMillipixelsPerMillisecond: MathExpression.Constant(0))));

            BooleanExpression ShouldLeave1 = BooleanExpression.GreaterThanOrEqualTo(
                MathExpression.Variable(variableName),
                10 * 1000);

            ObjectAction leave1 = ObjectAction.SetPosition(
                xMillis: MathExpression.XMillis(),
                yMillis: MathExpression.Add(MathExpression.YMillis(), MathExpression.Multiply(MathExpression.ElapsedMillisecondsPerIteration(), MathExpression.Constant(25))));

            ObjectAction leave1ConditionalAction = ObjectAction.Condition(
                condition: ShouldLeave1,
                action: leave1);

            BooleanExpression shouldLeave2 = BooleanExpression.GreaterThanOrEqualTo(
                MathExpression.Variable(variableName),
                11 * 1000);

            ObjectAction leave2 = ObjectAction.SetPosition(
                xMillis: MathExpression.XMillis(),
                yMillis: MathExpression.Add(MathExpression.YMillis(), MathExpression.Multiply(MathExpression.ElapsedMillisecondsPerIteration(), MathExpression.Constant(50))));

            ObjectAction leave2ConditionalAction = ObjectAction.ConditionalNextAction(
                currentAction: leave1ConditionalAction,
                condition: shouldLeave2,
                nextAction: leave2);

            ObjectAction shouldDestroy = ObjectAction.Condition(
                condition: BooleanExpression.And(shouldLeave2, BooleanExpression.GreaterThanOrEqualTo(MathExpression.YMillis(), 800 * 1000)),
                action: ObjectAction.Destroy());

            return(ObjectAction.ConditionalNextAction(
                       currentAction: teleportToInitialLocation,
                       condition: BooleanExpression.True(),
                       nextAction: ObjectAction.Union(faceTowardsPlayer, initializeAndIncrementVariable, setInitialSpeed, slowDownSpeed1, slowDownSpeed2, stopMovement, leave2ConditionalAction, shouldDestroy)));
        }
Exemplo n.º 11
0
        // Spawns 12 bullets (30 degrees apart)
        private static ObjectAction SpawnSatelliteBullet(
            Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary,
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates,
            GuidGenerator guidGenerator)
        {
            string singleBulletSpriteName = guidGenerator.NextGuid();

            spriteNameToImageDictionary.Add(singleBulletSpriteName, DTDanmakuImage.EliteOrbiterEnemyBullet);

            long buffer = 100;

            BooleanExpression shouldDestroySingleBullet = BooleanExpression.Or(
                BooleanExpression.GreaterThan(MathExpression.XMillis(), MathExpression.Constant((1000 + buffer) * 1000)),
                BooleanExpression.LessThan(MathExpression.XMillis(), MathExpression.Constant((0 - buffer) * 1000)),
                BooleanExpression.GreaterThan(MathExpression.YMillis(), MathExpression.Constant((700 + buffer) * 1000)),
                BooleanExpression.LessThan(MathExpression.YMillis(), MathExpression.Constant((0 - buffer) * 1000)));

            ObjectAction destroySingleBulletAction = ObjectAction.Condition(
                condition: shouldDestroySingleBullet,
                action: ObjectAction.Destroy());

            DTDanmakuMath.MathExpressionOffset singleBulletOffset = DTDanmakuMath.GetOffset(
                millipixels: MathExpression.Multiply(MathExpression.Constant(100), MathExpression.ElapsedMillisecondsPerIteration()),
                movementDirectionInMillidegrees: MathExpression.Variable("direction"));

            List <ObjectBox> collisionBoxes = new List <ObjectBox>();

            collisionBoxes.Add(new ObjectBox(lowerXMillis: -3000, upperXMillis: 3000, lowerYMillis: -5000, upperYMillis: 5000));
            collisionBoxes.Add(new ObjectBox(lowerXMillis: -5000, upperXMillis: 5000, lowerYMillis: -3000, upperYMillis: 3000));

            EnemyObjectTemplate singleBulletTemplate = EnemyObjectTemplate.EnemyBullet(
                action: ObjectAction.Union(
                    ObjectAction.SetFacingDirection(MathExpression.Variable("direction")),
                    ObjectAction.SetPosition(
                        xMillis: MathExpression.Add(MathExpression.XMillis(), singleBulletOffset.DeltaXInMillipixels),
                        yMillis: MathExpression.Add(MathExpression.YMillis(), singleBulletOffset.DeltaYInMillipixels)),
                    destroySingleBulletAction),
                initialMilliHP: null,
                damageBoxes: null,
                collisionBoxes: collisionBoxes,
                spriteName: singleBulletSpriteName);

            string singleBulletTemplateName = guidGenerator.NextGuid();

            enemyObjectTemplates.Add(singleBulletTemplateName, singleBulletTemplate);

            List <ObjectAction.InitialChildNumericVariableInfo> initialNumericVariables1 = new List <ObjectAction.InitialChildNumericVariableInfo>();

            initialNumericVariables1.Add(new ObjectAction.InitialChildNumericVariableInfo(name: "direction", value: MathExpression.Add(MathExpression.Variable("random offset"), MathExpression.Constant(0))));

            ObjectAction spawnSingleBulletAction1 = ObjectAction.SpawnChild(
                childXMillis: MathExpression.XMillis(),
                childYMillis: MathExpression.YMillis(),
                childObjectTemplateName: singleBulletTemplateName,
                childInitialNumericVariables: initialNumericVariables1,
                childInitialBooleanVariables: null);

            List <ObjectAction.InitialChildNumericVariableInfo> initialNumericVariables2 = new List <ObjectAction.InitialChildNumericVariableInfo>();

            initialNumericVariables2.Add(new ObjectAction.InitialChildNumericVariableInfo(name: "direction", value: MathExpression.Add(MathExpression.Variable("random offset"), MathExpression.Constant(30 * 1000))));

            ObjectAction spawnSingleBulletAction2 = ObjectAction.SpawnChild(
                childXMillis: MathExpression.XMillis(),
                childYMillis: MathExpression.YMillis(),
                childObjectTemplateName: singleBulletTemplateName,
                childInitialNumericVariables: initialNumericVariables2,
                childInitialBooleanVariables: null);

            List <ObjectAction.InitialChildNumericVariableInfo> initialNumericVariables3 = new List <ObjectAction.InitialChildNumericVariableInfo>();

            initialNumericVariables3.Add(new ObjectAction.InitialChildNumericVariableInfo(name: "direction", value: MathExpression.Add(MathExpression.Variable("random offset"), MathExpression.Constant(60 * 1000))));

            ObjectAction spawnSingleBulletAction3 = ObjectAction.SpawnChild(
                childXMillis: MathExpression.XMillis(),
                childYMillis: MathExpression.YMillis(),
                childObjectTemplateName: singleBulletTemplateName,
                childInitialNumericVariables: initialNumericVariables3,
                childInitialBooleanVariables: null);

            List <ObjectAction.InitialChildNumericVariableInfo> initialNumericVariables4 = new List <ObjectAction.InitialChildNumericVariableInfo>();

            initialNumericVariables4.Add(new ObjectAction.InitialChildNumericVariableInfo(name: "direction", value: MathExpression.Add(MathExpression.Variable("random offset"), MathExpression.Constant(90 * 1000))));

            ObjectAction spawnSingleBulletAction4 = ObjectAction.SpawnChild(
                childXMillis: MathExpression.XMillis(),
                childYMillis: MathExpression.YMillis(),
                childObjectTemplateName: singleBulletTemplateName,
                childInitialNumericVariables: initialNumericVariables4,
                childInitialBooleanVariables: null);

            List <ObjectAction.InitialChildNumericVariableInfo> initialNumericVariables5 = new List <ObjectAction.InitialChildNumericVariableInfo>();

            initialNumericVariables5.Add(new ObjectAction.InitialChildNumericVariableInfo(name: "direction", value: MathExpression.Add(MathExpression.Variable("random offset"), MathExpression.Constant(120 * 1000))));

            ObjectAction spawnSingleBulletAction5 = ObjectAction.SpawnChild(
                childXMillis: MathExpression.XMillis(),
                childYMillis: MathExpression.YMillis(),
                childObjectTemplateName: singleBulletTemplateName,
                childInitialNumericVariables: initialNumericVariables5,
                childInitialBooleanVariables: null);

            List <ObjectAction.InitialChildNumericVariableInfo> initialNumericVariables6 = new List <ObjectAction.InitialChildNumericVariableInfo>();

            initialNumericVariables6.Add(new ObjectAction.InitialChildNumericVariableInfo(name: "direction", value: MathExpression.Add(MathExpression.Variable("random offset"), MathExpression.Constant(150 * 1000))));

            ObjectAction spawnSingleBulletAction6 = ObjectAction.SpawnChild(
                childXMillis: MathExpression.XMillis(),
                childYMillis: MathExpression.YMillis(),
                childObjectTemplateName: singleBulletTemplateName,
                childInitialNumericVariables: initialNumericVariables6,
                childInitialBooleanVariables: null);

            List <ObjectAction.InitialChildNumericVariableInfo> initialNumericVariables7 = new List <ObjectAction.InitialChildNumericVariableInfo>();

            initialNumericVariables7.Add(new ObjectAction.InitialChildNumericVariableInfo(name: "direction", value: MathExpression.Add(MathExpression.Variable("random offset"), MathExpression.Constant(180 * 1000))));

            ObjectAction spawnSingleBulletAction7 = ObjectAction.SpawnChild(
                childXMillis: MathExpression.XMillis(),
                childYMillis: MathExpression.YMillis(),
                childObjectTemplateName: singleBulletTemplateName,
                childInitialNumericVariables: initialNumericVariables7,
                childInitialBooleanVariables: null);

            List <ObjectAction.InitialChildNumericVariableInfo> initialNumericVariables8 = new List <ObjectAction.InitialChildNumericVariableInfo>();

            initialNumericVariables8.Add(new ObjectAction.InitialChildNumericVariableInfo(name: "direction", value: MathExpression.Add(MathExpression.Variable("random offset"), MathExpression.Constant(210 * 1000))));

            ObjectAction spawnSingleBulletAction8 = ObjectAction.SpawnChild(
                childXMillis: MathExpression.XMillis(),
                childYMillis: MathExpression.YMillis(),
                childObjectTemplateName: singleBulletTemplateName,
                childInitialNumericVariables: initialNumericVariables8,
                childInitialBooleanVariables: null);

            List <ObjectAction.InitialChildNumericVariableInfo> initialNumericVariables9 = new List <ObjectAction.InitialChildNumericVariableInfo>();

            initialNumericVariables9.Add(new ObjectAction.InitialChildNumericVariableInfo(name: "direction", value: MathExpression.Add(MathExpression.Variable("random offset"), MathExpression.Constant(240 * 1000))));

            ObjectAction spawnSingleBulletAction9 = ObjectAction.SpawnChild(
                childXMillis: MathExpression.XMillis(),
                childYMillis: MathExpression.YMillis(),
                childObjectTemplateName: singleBulletTemplateName,
                childInitialNumericVariables: initialNumericVariables9,
                childInitialBooleanVariables: null);

            List <ObjectAction.InitialChildNumericVariableInfo> initialNumericVariables10 = new List <ObjectAction.InitialChildNumericVariableInfo>();

            initialNumericVariables10.Add(new ObjectAction.InitialChildNumericVariableInfo(name: "direction", value: MathExpression.Add(MathExpression.Variable("random offset"), MathExpression.Constant(270 * 1000))));

            ObjectAction spawnSingleBulletAction10 = ObjectAction.SpawnChild(
                childXMillis: MathExpression.XMillis(),
                childYMillis: MathExpression.YMillis(),
                childObjectTemplateName: singleBulletTemplateName,
                childInitialNumericVariables: initialNumericVariables10,
                childInitialBooleanVariables: null);

            List <ObjectAction.InitialChildNumericVariableInfo> initialNumericVariables11 = new List <ObjectAction.InitialChildNumericVariableInfo>();

            initialNumericVariables11.Add(new ObjectAction.InitialChildNumericVariableInfo(name: "direction", value: MathExpression.Add(MathExpression.Variable("random offset"), MathExpression.Constant(300 * 1000))));

            ObjectAction spawnSingleBulletAction11 = ObjectAction.SpawnChild(
                childXMillis: MathExpression.XMillis(),
                childYMillis: MathExpression.YMillis(),
                childObjectTemplateName: singleBulletTemplateName,
                childInitialNumericVariables: initialNumericVariables11,
                childInitialBooleanVariables: null);

            List <ObjectAction.InitialChildNumericVariableInfo> initialNumericVariables12 = new List <ObjectAction.InitialChildNumericVariableInfo>();

            initialNumericVariables12.Add(new ObjectAction.InitialChildNumericVariableInfo(name: "direction", value: MathExpression.Add(MathExpression.Variable("random offset"), MathExpression.Constant(330 * 1000))));

            ObjectAction spawnSingleBulletAction12 = ObjectAction.SpawnChild(
                childXMillis: MathExpression.XMillis(),
                childYMillis: MathExpression.YMillis(),
                childObjectTemplateName: singleBulletTemplateName,
                childInitialNumericVariables: initialNumericVariables12,
                childInitialBooleanVariables: null);

            List <ObjectAction> actionList = new List <ObjectAction>();

            actionList.Add(ObjectAction.SetNumericVariable("random offset", MathExpression.RandomInteger(MathExpression.Constant(360 * 1000))));
            actionList.Add(spawnSingleBulletAction1);
            actionList.Add(spawnSingleBulletAction2);
            actionList.Add(spawnSingleBulletAction3);
            actionList.Add(spawnSingleBulletAction4);
            actionList.Add(spawnSingleBulletAction5);
            actionList.Add(spawnSingleBulletAction6);
            actionList.Add(spawnSingleBulletAction7);
            actionList.Add(spawnSingleBulletAction8);
            actionList.Add(spawnSingleBulletAction9);
            actionList.Add(spawnSingleBulletAction10);
            actionList.Add(spawnSingleBulletAction11);
            actionList.Add(spawnSingleBulletAction12);
            actionList.Add(ObjectAction.Destroy());

            EnemyObjectTemplate placeholderTemplate = EnemyObjectTemplate.Placeholder(
                action: ObjectAction.Union(actionList));

            string placeholderTemplateName = guidGenerator.NextGuid();

            enemyObjectTemplates.Add(placeholderTemplateName, placeholderTemplate);

            return(ObjectAction.SpawnChild(
                       childXMillis: MathExpression.XMillis(),
                       childYMillis: MathExpression.YMillis(),
                       childObjectTemplateName: placeholderTemplateName,
                       childInitialNumericVariables: null,
                       childInitialBooleanVariables: null));
        }
Exemplo n.º 12
0
        private static ObjectAction GetMoveAction(
            GuidGenerator guidGenerator)
        {
            string movementCooldownVariable = guidGenerator.NextGuid();

            ObjectAction setMovementCooldownAction = ObjectAction.SetNumericVariable(
                movementCooldownVariable,
                MathExpression.Add(MathExpression.Constant(500), MathExpression.RandomInteger(5000)));

            ObjectAction decrementMovementCooldownAction = ObjectAction.SetNumericVariable(
                movementCooldownVariable,
                MathExpression.Subtract(MathExpression.Variable(movementCooldownVariable), MathExpression.ElapsedMillisecondsPerIteration()));

            BooleanExpression shouldChangeMovement = BooleanExpression.LessThanOrEqualTo(
                MathExpression.Variable(movementCooldownVariable),
                MathExpression.Constant(0));

            IMathExpression randomMilliAngle = MathExpression.RandomInteger(MathExpression.Constant(360 * 1000));

            string       angleVariable           = guidGenerator.NextGuid();
            ObjectAction writeNewAngleToVariable = ObjectAction.SetNumericVariable(
                angleVariable,
                randomMilliAngle);

            ObjectAction normalizeAngleVariable = ObjectAction.Union(
                ObjectAction.Condition(
                    condition: BooleanExpression.LessThan(MathExpression.Variable(angleVariable), MathExpression.Constant(0)),
                    action: ObjectAction.SetNumericVariable(angleVariable, MathExpression.Add(MathExpression.Variable(angleVariable), MathExpression.Constant(360 * 1000)))),
                ObjectAction.Condition(
                    condition: BooleanExpression.GreaterThanOrEqualTo(MathExpression.Variable(angleVariable), MathExpression.Constant(360 * 1000)),
                    action: ObjectAction.SetNumericVariable(angleVariable, MathExpression.Subtract(MathExpression.Variable(angleVariable), MathExpression.Constant(360 * 1000)))));

            BooleanExpression tooCloseToLeftEdge = BooleanExpression.LessThanOrEqualTo(
                MathExpression.XMillis(),
                MathExpression.Constant(200 * 1000));

            ObjectAction updateAngleVariableLeft = ObjectAction.Condition(
                condition: BooleanExpression.And(tooCloseToLeftEdge, BooleanExpression.And(
                                                     BooleanExpression.GreaterThanOrEqualTo(MathExpression.Variable(angleVariable), MathExpression.Constant(180 * 1000)),
                                                     BooleanExpression.LessThanOrEqualTo(MathExpression.Variable(angleVariable), MathExpression.Constant(360 * 1000)))),
                action: ObjectAction.SetNumericVariable(
                    angleVariable,
                    MathExpression.Multiply(MathExpression.Variable(angleVariable), MathExpression.Constant(-1))));

            BooleanExpression tooCloseToRightEdge = BooleanExpression.GreaterThanOrEqualTo(
                MathExpression.XMillis(),
                MathExpression.Constant(800 * 1000));

            ObjectAction updateAngleVariableRight = ObjectAction.Condition(
                condition: BooleanExpression.And(tooCloseToRightEdge, BooleanExpression.And(
                                                     BooleanExpression.GreaterThanOrEqualTo(MathExpression.Variable(angleVariable), MathExpression.Constant(0 * 1000)),
                                                     BooleanExpression.LessThanOrEqualTo(MathExpression.Variable(angleVariable), MathExpression.Constant(180 * 1000)))),
                action: ObjectAction.SetNumericVariable(
                    angleVariable,
                    MathExpression.Multiply(MathExpression.Variable(angleVariable), MathExpression.Constant(-1))));

            BooleanExpression tooCloseToTopEdge = BooleanExpression.GreaterThanOrEqualTo(
                MathExpression.YMillis(),
                MathExpression.Constant(600 * 1000));

            ObjectAction updateAngleVariableTop = ObjectAction.Condition(
                condition: BooleanExpression.And(tooCloseToTopEdge, BooleanExpression.Or(
                                                     BooleanExpression.GreaterThanOrEqualTo(MathExpression.Variable(angleVariable), MathExpression.Constant(270 * 1000)),
                                                     BooleanExpression.LessThanOrEqualTo(MathExpression.Variable(angleVariable), MathExpression.Constant(90 * 1000)))),
                action: ObjectAction.SetNumericVariable(
                    angleVariable,
                    MathExpression.Subtract(
                        MathExpression.Multiply(MathExpression.Add(MathExpression.Variable(angleVariable), MathExpression.Constant(90 * 1000)), MathExpression.Constant(-1)),
                        MathExpression.Constant(90 * 1000))));

            BooleanExpression tooCloseToBottomEdge = BooleanExpression.LessThanOrEqualTo(
                MathExpression.YMillis(),
                MathExpression.Constant(400 * 1000));

            ObjectAction updateAngleVariableBottom = ObjectAction.Condition(
                condition: BooleanExpression.And(tooCloseToBottomEdge, BooleanExpression.And(
                                                     BooleanExpression.GreaterThanOrEqualTo(MathExpression.Variable(angleVariable), MathExpression.Constant(90 * 1000)),
                                                     BooleanExpression.LessThanOrEqualTo(MathExpression.Variable(angleVariable), MathExpression.Constant(270 * 1000)))),
                action: ObjectAction.SetNumericVariable(
                    angleVariable,
                    MathExpression.Subtract(
                        MathExpression.Multiply(MathExpression.Add(MathExpression.Variable(angleVariable), MathExpression.Constant(90 * 1000)), MathExpression.Constant(-1)),
                        MathExpression.Constant(90 * 1000))));

            string angleSnapshotVariable = guidGenerator.NextGuid();

            ObjectAction initializeAngleSnapshotVariable = ObjectActionGenerator.DoOnce(
                ObjectAction.SetNumericVariable(angleSnapshotVariable, MathExpression.RandomInteger(360 * 1000)));

            DTDanmakuMath.MathExpressionOffset offset = DTDanmakuMath.GetOffset(
                millipixels: MathExpression.Multiply(MathExpression.Constant(80), MathExpression.ElapsedMillisecondsPerIteration()),
                movementDirectionInMillidegrees: MathExpression.Variable(angleSnapshotVariable));

            ObjectAction updatePositionAction = ObjectAction.SetPosition(
                xMillis: MathExpression.Add(MathExpression.XMillis(), offset.DeltaXInMillipixels),
                yMillis: MathExpression.Add(MathExpression.YMillis(), offset.DeltaYInMillipixels));

            ObjectAction updatePositionWhenCooldownIsZero = ObjectAction.Condition(
                condition: shouldChangeMovement,
                action: ObjectAction.Union(
                    ObjectAction.SetNumericVariable(angleSnapshotVariable, MathExpression.Variable(angleVariable)),
                    setMovementCooldownAction));

            ObjectAction immediateMoveWhenTooClose = ObjectAction.Condition(
                condition: BooleanExpression.Or(tooCloseToLeftEdge, tooCloseToRightEdge, tooCloseToTopEdge, tooCloseToBottomEdge),
                action: ObjectAction.SetNumericVariable(movementCooldownVariable, MathExpression.Constant(0)));

            List <ObjectAction> actionList = new List <ObjectAction>();

            actionList.Add(initializeAngleSnapshotVariable);
            actionList.Add(ObjectActionGenerator.DoOnce(setMovementCooldownAction));
            actionList.Add(decrementMovementCooldownAction);
            actionList.Add(writeNewAngleToVariable);
            actionList.Add(updateAngleVariableLeft);
            actionList.Add(normalizeAngleVariable);
            actionList.Add(updateAngleVariableRight);
            actionList.Add(normalizeAngleVariable);
            actionList.Add(updateAngleVariableTop);
            actionList.Add(normalizeAngleVariable);
            actionList.Add(normalizeAngleVariable);
            actionList.Add(updateAngleVariableBottom);
            actionList.Add(normalizeAngleVariable);
            actionList.Add(normalizeAngleVariable);
            actionList.Add(updatePositionWhenCooldownIsZero);
            actionList.Add(updatePositionAction);
            actionList.Add(immediateMoveWhenTooClose);

            return(ObjectAction.Union(actionList));
        }
Exemplo n.º 13
0
        private static ObjectAction Phase1ShootAction(
            Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary,
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates,
            GuidGenerator guidGenerator)
        {
            string singleBulletSpriteName = guidGenerator.NextGuid();

            spriteNameToImageDictionary.Add(singleBulletSpriteName, DTDanmakuImage.BossPhase1EnemyBullet);

            long buffer = 100;

            BooleanExpression shouldDestroySingleBullet = BooleanExpression.Or(
                BooleanExpression.GreaterThan(MathExpression.XMillis(), MathExpression.Constant((1000 + buffer) * 1000)),
                BooleanExpression.LessThan(MathExpression.XMillis(), MathExpression.Constant((0 - buffer) * 1000)),
                BooleanExpression.GreaterThan(MathExpression.YMillis(), MathExpression.Constant((700 + buffer) * 1000)),
                BooleanExpression.LessThan(MathExpression.YMillis(), MathExpression.Constant((0 - buffer) * 1000)));

            ObjectAction destroySingleBulletAction = ObjectAction.Condition(
                condition: shouldDestroySingleBullet,
                action: ObjectAction.Destroy());

            DTDanmakuMath.MathExpressionOffset singleBulletOffset = DTDanmakuMath.GetOffset(
                millipixels: MathExpression.Multiply(MathExpression.Variable("speed"), MathExpression.ElapsedMillisecondsPerIteration()),
                movementDirectionInMillidegrees: MathExpression.Variable("direction"));

            List <ObjectBox> collisionBoxes = new List <ObjectBox>();

            collisionBoxes.Add(new ObjectBox(lowerXMillis: -3000, upperXMillis: 3000, lowerYMillis: -5000, upperYMillis: 5000));
            collisionBoxes.Add(new ObjectBox(lowerXMillis: -5000, upperXMillis: 5000, lowerYMillis: -3000, upperYMillis: 3000));

            EnemyObjectTemplate singleBulletTemplate = EnemyObjectTemplate.EnemyBullet(
                action: ObjectAction.Union(
                    ObjectAction.SetFacingDirection(MathExpression.Variable("direction")),
                    ObjectAction.SetPosition(
                        xMillis: MathExpression.Add(MathExpression.XMillis(), singleBulletOffset.DeltaXInMillipixels),
                        yMillis: MathExpression.Add(MathExpression.YMillis(), singleBulletOffset.DeltaYInMillipixels)),
                    destroySingleBulletAction),
                initialMilliHP: null,
                damageBoxes: null,
                collisionBoxes: collisionBoxes,
                spriteName: singleBulletSpriteName);

            string singleBulletTemplateName = guidGenerator.NextGuid();

            enemyObjectTemplates.Add(singleBulletTemplateName, singleBulletTemplate);

            List <ObjectAction> spawnBulletActions = new List <ObjectAction>();

            string randomOffsetVariable = guidGenerator.NextGuid();

            for (int i = 0; i < 36; i++)
            {
                List <ObjectAction.InitialChildNumericVariableInfo> initialNumericVariables = new List <ObjectAction.InitialChildNumericVariableInfo>();
                initialNumericVariables.Add(
                    new ObjectAction.InitialChildNumericVariableInfo(
                        name: "direction",
                        value: MathExpression.Add(MathExpression.Variable(randomOffsetVariable), MathExpression.Constant(i * 10 * 1000))));
                initialNumericVariables.Add(
                    new ObjectAction.InitialChildNumericVariableInfo(
                        name: "speed",
                        value: MathExpression.Add(MathExpression.Constant(100), MathExpression.RandomInteger(100))));

                spawnBulletActions.Add(ObjectAction.SpawnChild(
                                           childXMillis: MathExpression.XMillis(),
                                           childYMillis: MathExpression.Add(MathExpression.YMillis(), MathExpression.Constant(-60000)),
                                           childObjectTemplateName: singleBulletTemplateName,
                                           childInitialNumericVariables: initialNumericVariables,
                                           childInitialBooleanVariables: null));
            }

            List <ObjectAction> actionList = new List <ObjectAction>();

            actionList.Add(ObjectAction.SetNumericVariable(randomOffsetVariable, MathExpression.RandomInteger(MathExpression.Constant(360 * 1000))));
            foreach (ObjectAction spawnBulletAction in spawnBulletActions)
            {
                actionList.Add(spawnBulletAction);
            }

            ObjectAction shootBulletAction = ObjectAction.Union(actionList);

            string shootCooldown = guidGenerator.NextGuid();

            ObjectAction initializeShootCooldown = ObjectAction.SetNumericVariable(
                variableName: shootCooldown,
                variableValue: MathExpression.Constant(2000));

            ObjectAction decrementShootCooldown = ObjectAction.SetNumericVariable(
                variableName: shootCooldown,
                variableValue: MathExpression.Subtract(MathExpression.Variable(shootCooldown), MathExpression.ElapsedMillisecondsPerIteration()));

            ObjectAction shootWhenCooldownIsZero = ObjectAction.Condition(
                condition: BooleanExpression.LessThanOrEqualTo(MathExpression.Variable(shootCooldown), MathExpression.Constant(0)),
                action: ObjectAction.Union(initializeShootCooldown, shootBulletAction));

            return(ObjectAction.Union(
                       ObjectActionGenerator.DoOnce(initializeShootCooldown),
                       decrementShootCooldown,
                       shootWhenCooldownIsZero));
        }
Exemplo n.º 14
0
 public static IMathExpression RandomInteger(long value)
 {
     return(MathExpression.RandomInteger(MathExpression.Constant(value)));
 }
Exemplo n.º 15
0
        public static GenerateEnemiesResult GenerateEnemies(
            long elapsedMillisecondsPerIteration,
            IDTDeterministicRandom rng,
            GuidGenerator guidGenerator)
        {
            List <EnemyObject> enemyObjects = new List <EnemyObject>();
            Dictionary <string, DTDanmakuImage>      spriteNameToImageDictionary = new Dictionary <string, DTDanmakuImage>();
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates        = new Dictionary <string, EnemyObjectTemplate>();
            Dictionary <string, DTDanmakuSound>      soundNameToSoundDictionary  = new Dictionary <string, DTDanmakuSound>();

            ObjectAction spawnWave1Enemy = GenerateWave1Enemy(
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                soundNameToSoundDictionary: soundNameToSoundDictionary,
                guidGenerator: guidGenerator);

            ObjectAction spawnWave2Enemy = GenerateWave2Enemy(
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                soundNameToSoundDictionary: soundNameToSoundDictionary,
                guidGenerator: guidGenerator);

            ObjectAction spawnWave3Enemy = GenerateWave3Enemy(
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                soundNameToSoundDictionary: soundNameToSoundDictionary,
                guidGenerator: guidGenerator);

            ObjectAction spawnWave4Enemy = GenerateWave4Enemy(
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                soundNameToSoundDictionary: soundNameToSoundDictionary,
                guidGenerator: guidGenerator);

            ObjectAction spawnSniperEnemy = SniperEnemyGenerator.SpawnSniperEnemy(
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                soundNameToSoundDictionary: soundNameToSoundDictionary,
                guidGenerator: guidGenerator);

            ObjectAction spawnEliteSniperEnemy = EliteSniperEnemyGenerator.SpawnEliteSniperEnemy(
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                soundNameToSoundDictionary: soundNameToSoundDictionary,
                guidGenerator: guidGenerator);

            ObjectAction spawnOrbiterEnemy = OrbiterEnemyGenerator.SpawnOrbiterEnemy(
                xMillis: MathExpression.Add(MathExpression.Constant(300 * 1000), MathExpression.RandomInteger(400 * 1000)),
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                soundNameToSoundDictionary: soundNameToSoundDictionary,
                guidGenerator: guidGenerator);

            ObjectAction spawnEliteOrbiterEnemy = EliteOrbiterEnemyGenerator.SpawnEliteOrbiterEnemy(
                xMillis: MathExpression.Add(MathExpression.Constant(300 * 1000), MathExpression.RandomInteger(400 * 1000)),
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                soundNameToSoundDictionary: soundNameToSoundDictionary,
                guidGenerator: guidGenerator);

            ObjectAction spawnBarrageEnemy = BarrageEnemyGenerator.SpawnBarrageEnemy(
                xMillis: MathExpression.Add(MathExpression.Constant(300 * 1000), MathExpression.RandomInteger(400 * 1000)),
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                soundNameToSoundDictionary: soundNameToSoundDictionary,
                guidGenerator: guidGenerator);

            ObjectAction spawnEliteBarrageEnemy = EliteBarrageEnemyGenerator.SpawnEliteBarrageEnemy(
                xMillis: MathExpression.Add(MathExpression.Constant(300 * 1000), MathExpression.RandomInteger(400 * 1000)),
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                soundNameToSoundDictionary: soundNameToSoundDictionary,
                guidGenerator: guidGenerator);

            ObjectAction spawnBoss = BossEnemyGenerator.SpawnBossEnemy(
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                soundNameToSoundDictionary: soundNameToSoundDictionary,
                guidGenerator: guidGenerator);

            for (int i = 0; i < 10; i++)
            {
                enemyObjects.Add(CreateActionExecutor(
                                     millisecondsToWait: 1000 * i,
                                     action: spawnWave1Enemy,
                                     elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                                     rng: rng,
                                     guidGenerator: guidGenerator));
            }

            for (int i = 0; i < 10; i++)
            {
                enemyObjects.Add(CreateActionExecutor(
                                     millisecondsToWait: 3000 + 1000 * i,
                                     action: spawnWave2Enemy,
                                     elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                                     rng: rng,
                                     guidGenerator: guidGenerator));
            }

            for (int i = 0; i < 6; i++)
            {
                enemyObjects.Add(CreateActionExecutor(
                                     millisecondsToWait: 16000 + 1000 * i,
                                     action: spawnSniperEnemy,
                                     elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                                     rng: rng,
                                     guidGenerator: guidGenerator));
            }

            for (int i = 0; i < 6; i++)
            {
                enemyObjects.Add(CreateActionExecutor(
                                     millisecondsToWait: 20000 + 6000 * i,
                                     action: spawnOrbiterEnemy,
                                     elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                                     rng: rng,
                                     guidGenerator: guidGenerator));
            }

            for (int i = 0; i < 6; i++)
            {
                enemyObjects.Add(CreateActionExecutor(
                                     millisecondsToWait: 23000 + 1500 * i,
                                     action: spawnWave3Enemy,
                                     elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                                     rng: rng,
                                     guidGenerator: guidGenerator));
            }

            for (int i = 0; i < 6; i++)
            {
                enemyObjects.Add(CreateActionExecutor(
                                     millisecondsToWait: 25500 + 1500 * i,
                                     action: spawnWave4Enemy,
                                     elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                                     rng: rng,
                                     guidGenerator: guidGenerator));
            }

            for (int i = 0; i < 4; i++)
            {
                enemyObjects.Add(CreateActionExecutor(
                                     millisecondsToWait: 29000 + 1700 * i,
                                     action: spawnBarrageEnemy,
                                     elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                                     rng: rng,
                                     guidGenerator: guidGenerator));
            }

            for (int i = 0; i < 7; i++)
            {
                enemyObjects.Add(CreateActionExecutor(
                                     millisecondsToWait: 33000 + 1250 * i,
                                     action: spawnEliteSniperEnemy,
                                     elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                                     rng: rng,
                                     guidGenerator: guidGenerator));
            }

            for (int i = 0; i < 4; i++)
            {
                enemyObjects.Add(CreateActionExecutor(
                                     millisecondsToWait: 38000 + 2100 * i,
                                     action: spawnEliteBarrageEnemy,
                                     elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                                     rng: rng,
                                     guidGenerator: guidGenerator));
            }

            for (int i = 0; i < 8; i++)
            {
                enemyObjects.Add(CreateActionExecutor(
                                     millisecondsToWait: 43000 + 500 * i,
                                     action: spawnSniperEnemy,
                                     elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                                     rng: rng,
                                     guidGenerator: guidGenerator));
            }

            for (int i = 0; i < 8; i++)
            {
                enemyObjects.Add(CreateActionExecutor(
                                     millisecondsToWait: 43250 + 500 * i,
                                     action: spawnEliteSniperEnemy,
                                     elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                                     rng: rng,
                                     guidGenerator: guidGenerator));
            }

            for (int i = 0; i < 2; i++)
            {
                enemyObjects.Add(CreateActionExecutor(
                                     millisecondsToWait: 56000 + 6000 * i,
                                     action: spawnEliteOrbiterEnemy,
                                     elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                                     rng: rng,
                                     guidGenerator: guidGenerator));
            }

            enemyObjects.Add(CreateActionExecutor(
                                 millisecondsToWait: 82000,
                                 action: spawnBoss,
                                 elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                                 rng: rng,
                                 guidGenerator: guidGenerator));

            return(new GenerateEnemiesResult(
                       enemyObjects: enemyObjects,
                       spriteNameToImageDictionary: spriteNameToImageDictionary,
                       enemyObjectTemplates: enemyObjectTemplates,
                       soundNameToSoundDictionary: soundNameToSoundDictionary));
        }