Пример #1
0
        public static EnemyObjectTemplate Placeholder(ObjectAction action)
        {
            EnemyObjectTemplate template = new EnemyObjectTemplate();

            template.ObjectType = EnemyObjectType.Placeholder;
            template.Action     = action;
            return(template);
        }
Пример #2
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));
        }
Пример #3
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)));
        }
Пример #4
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));
        }
Пример #5
0
        public static ObjectAction ShootBulletStraightDownAction(
            IMathExpression initialShootCooldownInMillis,
            IMathExpression shootCooldownInMillis,
            // Where the bullet should spawn (relative to the enemy shooting the bullet)
            long xOffset,
            long yOffset,
            long bulletSpeedInPixelsPerSecond,
            Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary,
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates,
            GuidGenerator guidGenerator)
        {
            string cooldownVariableName    = guidGenerator.NextGuid();
            string childObjectTemplateName = guidGenerator.NextGuid();
            string enemyBulletSpriteName   = 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         = ObjectAction.SpawnChild(
                childXMillis: MathExpression.Add(MathExpression.XMillis(), MathExpression.Constant(xOffset)),
                childYMillis: MathExpression.Add(MathExpression.YMillis(), MathExpression.Constant(yOffset)),
                childObjectTemplateName: childObjectTemplateName,
                childInitialNumericVariables: null,
                childInitialBooleanVariables: null);

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

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

            enemyObjectTemplates.Add(childObjectTemplateName,
                                     EnemyObjectTemplate.EnemyBullet(
                                         action: BulletStraightDownAction(bulletSpeedInPixelsPerSecond: bulletSpeedInPixelsPerSecond),
                                         initialMilliHP: null,
                                         damageBoxes: null,
                                         collisionBoxes: collisionBoxes,
                                         spriteName: enemyBulletSpriteName));

            spriteNameToImageDictionary.Add(enemyBulletSpriteName, DTDanmakuImage.EnemyBullet);

            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)));
        }
Пример #6
0
        public static EnemyObjectTemplate Enemy(ObjectAction action, IMathExpression initialMilliHP, List <ObjectBox> damageBoxes, List <ObjectBox> collisionBoxes, string spriteName)
        {
            EnemyObjectTemplate template = new EnemyObjectTemplate();

            template.ObjectType     = EnemyObjectType.Enemy;
            template.Action         = action;
            template.InitialMilliHP = initialMilliHP;
            if (damageBoxes != null)
            {
                template.DamageBoxes = new DTImmutableList <ObjectBox>(list: damageBoxes);
            }
            if (collisionBoxes != null)
            {
                template.CollisionBoxes = new DTImmutableList <ObjectBox>(list: collisionBoxes);
            }
            template.SpriteName = spriteName;
            return(template);
        }
Пример #7
0
        // Returns true if player still has at least one life remaining
        // Returns false if game over
        public bool DestroyPlayer(
            List <EnemyObject> enemyObjects,
            long elapsedMillisecondsPerIteration,
            IDTDeterministicRandom rng)
        {
            if (this.isDead)
            {
                throw new Exception();
            }

            long playerXMillis = this.xMillis;
            long playerYMillis = this.yMillis;

            EnemyObjectTemplate template = EnemyObjectTemplate.Placeholder(action: ObjectAction.ConditionalNextAction(
                                                                               currentAction: this.playerDeathSpawnDestructionAnimationAction,
                                                                               condition: BooleanExpression.True(),
                                                                               nextAction: ObjectAction.Destroy()));

            enemyObjects.Add(new EnemyObject(
                                 template: template,
                                 initialXMillis: playerXMillis,
                                 initialYMillis: playerYMillis,
                                 playerXMillis: playerXMillis,
                                 playerYMillis: playerYMillis,
                                 elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                                 isPlayerDestroyed: true,
                                 parent: null,
                                 initialNumericVariables: null,
                                 initialBooleanVariables: null,
                                 rng: rng));

            this.isDead = true;

            if (this.numLivesLeft > 0)
            {
                this.numLivesLeft = this.numLivesLeft - 1;
                this.respawnTimeRemainingMillis = 750;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #8
0
        public static ObjectAction SpawnBossEnemy(
            Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary,
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates,
            Dictionary <string, DTDanmakuSound> soundNameToSoundDictionary,
            GuidGenerator guidGenerator)
        {
            string spriteName = guidGenerator.NextGuid();

            spriteNameToImageDictionary.Add(spriteName, DTDanmakuImage.Boss);

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

            damageBoxes.Add(new ObjectBox(lowerXMillis: -96500, upperXMillis: 96500, lowerYMillis: -10000, upperYMillis: 30000));
            damageBoxes.Add(new ObjectBox(lowerXMillis: -71500, upperXMillis: 71500, lowerYMillis: -35000, upperYMillis: 30000));
            damageBoxes.Add(new ObjectBox(lowerXMillis: -50000, upperXMillis: 50000, lowerYMillis: -81000, upperYMillis: 48000));
            damageBoxes.Add(new ObjectBox(lowerXMillis: -35000, upperXMillis: 35000, lowerYMillis: 0, upperYMillis: 68000));

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

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

            EnemyObjectTemplate enemyObjectTemplate = EnemyObjectTemplate.Enemy(
                action: GetBossAction(
                    spriteNameToImageDictionary: spriteNameToImageDictionary,
                    enemyObjectTemplates: enemyObjectTemplates,
                    soundNameToSoundDictionary: soundNameToSoundDictionary,
                    guidGenerator: guidGenerator),
                initialMilliHP: MathExpression.Constant(50L * 1000L * 1000L * 1000L * 1000L),
                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));
        }
Пример #9
0
        private static ObjectAction GetSpawnOrbiterSatellitesAction(
            Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary,
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates,
            GuidGenerator guidGenerator)
        {
            string spriteName = guidGenerator.NextGuid();

            spriteNameToImageDictionary.Add(spriteName, DTDanmakuImage.EliteOrbiterSatellite);

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

            for (long i = 0; i < 5; i++)
            {
                EnemyObjectTemplate orbiterSatelliteTemplate = EnemyObjectTemplate.EnemyBullet(
                    action: ObjectAction.Union(
                        GetSatelliteMoveAndDestroyAction(
                            initialAngleInMillidegrees: 72L * 1000L * i,
                            guidGenerator: guidGenerator),
                        GetSatelliteShootAction(
                            spriteNameToImageDictionary: spriteNameToImageDictionary,
                            enemyObjectTemplates: enemyObjectTemplates,
                            guidGenerator: guidGenerator)),
                    initialMilliHP: null,
                    damageBoxes: null,
                    collisionBoxes: null,
                    spriteName: spriteName);

                string templateName = guidGenerator.NextGuid();
                enemyObjectTemplates.Add(templateName, orbiterSatelliteTemplate);

                ObjectAction spawnSatelliteAction = ObjectAction.SpawnChild(
                    childXMillis: MathExpression.Constant(-1000 * 1000),
                    childYMillis: MathExpression.Constant(-1000 * 1000),
                    childObjectTemplateName: templateName,
                    childInitialNumericVariables: null,
                    childInitialBooleanVariables: null);

                objectActions.Add(spawnSatelliteAction);
            }

            return(ObjectActionGenerator.DoOnce(ObjectAction.Union(objectActions)));
        }
Пример #10
0
        private static Tuple <ObjectAction, EnemyObjectTemplate> SpawnOneDestructionSpriteImage(
            long startMilliseconds,
            long endMilliseconds,
            string childObjectTemplateName,
            string spriteName,
            bool isLast)
        {
            List <ObjectAction> destroyActions = new List <ObjectAction>();

            destroyActions.Add(ObjectAction.Destroy());
            destroyActions.Add(ObjectAction.DestroyParent());

            ObjectAction destroySelfAction = ObjectAction.Condition(
                condition: BooleanExpression.GreaterThanOrEqualTo(
                    leftSide: MathExpression.ParentVariable(elapsedTimeInMillisVariableName),
                    rightSide: MathExpression.Constant(endMilliseconds)),
                action: isLast ? ObjectAction.Union(destroyActions) : ObjectAction.Destroy());

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

            ObjectAction delayedSpawnChildAction =
                ObjectAction.Condition(
                    condition: BooleanExpression.GreaterThanOrEqualTo(
                        leftSide: MathExpression.Variable(elapsedTimeInMillisVariableName),
                        rightSide: MathExpression.Constant(startMilliseconds)),
                    action: ObjectActionGenerator.DoOnce(spawnChildAction));

            EnemyObjectTemplate template = EnemyObjectTemplate.Enemy(
                action: destroySelfAction,
                initialMilliHP: null,
                damageBoxes: null,
                collisionBoxes: null,
                spriteName: spriteName);

            return(new Tuple <ObjectAction, EnemyObjectTemplate>(delayedSpawnChildAction, template));
        }
Пример #11
0
 private static EnemyObject CreateActionExecutor(
     long millisecondsToWait,
     ObjectAction action,
     long elapsedMillisecondsPerIteration,
     IDTDeterministicRandom rng,
     GuidGenerator guidGenerator)
 {
     return(new EnemyObject(
                template: EnemyObjectTemplate.Placeholder(
                    action: ObjectActionGenerator.Delay(
                        action: ObjectAction.Union(action, ObjectAction.Destroy()),
                        milliseconds: millisecondsToWait,
                        guidGenerator: guidGenerator)),
                initialXMillis: 0,
                initialYMillis: 0,
                playerXMillis: 0,
                playerYMillis: 0,
                elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                isPlayerDestroyed: false,
                parent: null,
                initialNumericVariables: null,
                initialBooleanVariables: null,
                rng: rng));
 }
Пример #12
0
        private static ObjectAction SpawnPhase3Bullet(
            IMathExpression bulletDirectionInMillidegrees,
            Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary,
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates,
            GuidGenerator guidGenerator)
        {
            string bulletSpriteName = guidGenerator.NextGuid();

            spriteNameToImageDictionary.Add(bulletSpriteName, DTDanmakuImage.BossPhase3EnemyBullet);

            string snapshotBulletDirectionInMillidegreesVariable = guidGenerator.NextGuid();

            ObjectAction snapshotDirectionAction = ObjectActionGenerator.DoOnce(ObjectAction.SetNumericVariable(
                                                                                    snapshotBulletDirectionInMillidegreesVariable,
                                                                                    bulletDirectionInMillidegrees));

            long buffer = 100;

            BooleanExpression shouldDestroy = 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 destroyAction = ObjectAction.Condition(
                condition: shouldDestroy,
                action: ObjectAction.Destroy());

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

            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 bulletTemplate = EnemyObjectTemplate.EnemyBullet(
                action: ObjectAction.Union(
                    snapshotDirectionAction,
                    ObjectAction.SetFacingDirection(MathExpression.Variable(snapshotBulletDirectionInMillidegreesVariable)),
                    ObjectAction.SetPosition(
                        xMillis: MathExpression.Add(MathExpression.XMillis(), offset.DeltaXInMillipixels),
                        yMillis: MathExpression.Add(MathExpression.YMillis(), offset.DeltaYInMillipixels)),
                    destroyAction),
                initialMilliHP: null,
                damageBoxes: null,
                collisionBoxes: collisionBoxes,
                spriteName: bulletSpriteName);

            string templateName = guidGenerator.NextGuid();

            enemyObjectTemplates.Add(templateName, bulletTemplate);

            return(ObjectAction.SpawnChild(
                       childXMillis: MathExpression.XMillis(),
                       childYMillis: MathExpression.Subtract(MathExpression.YMillis(), MathExpression.Constant(60000)),
                       childObjectTemplateName: templateName,
                       childInitialNumericVariables: null,
                       childInitialBooleanVariables: null));
        }
Пример #13
0
        public static ObjectAction SpawnEnemyThatMovesToSpecificLocation(
            long initialXMillis,
            long initialYMillis,
            List <Tuple <long, long> > movementPath,
            long movementSpeedInPixelsPerSecond,
            bool shouldStrafe,
            long bulletXOffset,
            long bulletYOffset,
            IMathExpression initialShootCooldownInMillis,
            IMathExpression shootCooldownInMillis,
            long bulletSpeedInPixelsPerSecond,
            IMathExpression initialMilliHP,
            long chanceToDropPowerUpInMilliPercent,  // ranges from 0 (meaning 0%) to 100,000 (meaning 100%)
            List <ObjectBox> damageBoxes,            // nullable
            List <ObjectBox> collisionBoxes,         // nullable
            DTDanmakuImage sprite,
            Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary,
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates,
            Dictionary <string, DTDanmakuSound> soundNameToSoundDictionary,
            GuidGenerator guidGenerator)
        {
            ObjectAction moveAction = MoveToSpecifiedLocations(
                initialXMillis: initialXMillis,
                initialYMillis: initialYMillis,
                movementPath: movementPath,
                speedInPixelsPerSecond: movementSpeedInPixelsPerSecond,
                shouldStrafe: shouldStrafe,
                shouldDestroyAtEndOfMovementPath: true,
                guidGenerator: guidGenerator);

            ObjectAction shootAction = ShootBulletStraightDownAction(
                initialShootCooldownInMillis: initialShootCooldownInMillis,
                shootCooldownInMillis: shootCooldownInMillis,
                xOffset: bulletXOffset,
                yOffset: bulletYOffset,
                bulletSpeedInPixelsPerSecond: bulletSpeedInPixelsPerSecond,
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                guidGenerator: guidGenerator);

            ObjectAction destroyAction = DestroyWhenHpIsZeroAndMaybeDropPowerUp(
                chanceToDropPowerUpInMilliPercent: chanceToDropPowerUpInMilliPercent,
                spriteNameToImageDictionary: spriteNameToImageDictionary,
                enemyObjectTemplates: enemyObjectTemplates,
                soundNameToSoundDictionary: soundNameToSoundDictionary,
                guidGenerator: guidGenerator);

            string spriteName = guidGenerator.NextGuid();

            spriteNameToImageDictionary.Add(spriteName, sprite);

            EnemyObjectTemplate enemyObjectTemplate = EnemyObjectTemplate.Enemy(
                action: ObjectAction.Union(moveAction, shootAction, destroyAction),
                initialMilliHP: initialMilliHP,
                damageBoxes: damageBoxes,
                collisionBoxes: collisionBoxes,
                spriteName: spriteName);

            string templateName = guidGenerator.NextGuid();

            enemyObjectTemplates.Add(templateName, enemyObjectTemplate);

            return(ObjectAction.SpawnChild(
                       childXMillis: MathExpression.Constant(initialXMillis),
                       childYMillis: MathExpression.Constant(initialYMillis),
                       childObjectTemplateName: templateName,
                       childInitialNumericVariables: null,
                       childInitialBooleanVariables: null));
        }
Пример #14
0
        private static ResultOfAction HandleAction(
            ObjectAction action,
            EnemyObject obj,
            long playerXMillis,
            long playerYMillis,
            long elapsedMillisecondsPerIteration,
            bool isPlayerDestroyed,
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates,
            IDTDeterministicRandom rng)
        {
            bool?isParentDestroyed;

            if (obj.ParentObject == null)
            {
                isParentDestroyed = null;
            }
            else
            {
                isParentDestroyed = obj.ParentObject.IsDestroyed;
            }

            switch (action.ObjectActionType)
            {
            case ObjectAction.Type.Move:
            case ObjectAction.Type.StrafeMove:
                long desiredX = action.MoveToXMillis.Evaluate(
                    obj.GetEnemyObjectExpressionInfo(),
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    rng: rng);
                long desiredY = action.MoveToYMillis.Evaluate(
                    obj.GetEnemyObjectExpressionInfo(),
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    rng: rng);
                long?directionInMillidegrees = DTDanmakuMath.GetMovementDirectionInMillidegrees(currentX: obj.XMillis, currentY: obj.YMillis, desiredX: desiredX, desiredY: desiredY);

                if (directionInMillidegrees != null)
                {
                    obj.MovementDirectionInMillidegrees = directionInMillidegrees.Value;
                    if (action.ObjectActionType == ObjectAction.Type.Move)
                    {
                        obj.FacingDirectionInMillidegrees = directionInMillidegrees.Value;
                    }
                    else if (action.ObjectActionType == ObjectAction.Type.StrafeMove)
                    {
                        obj.FacingDirectionInMillidegrees = 180L * 1000L;
                    }
                    else
                    {
                        throw new Exception();
                    }
                }

                return(new ResultOfAction(
                           newObjectAction: action,
                           shouldEndLevel: false,
                           newEnemyObjects: new List <EnemyObject>(),
                           newPowerUps: new List <Tuple <long, long> >(),
                           newSoundEffectsToPlay: new List <string>(),
                           bossHealthMeterNumber: null,
                           bossHealthMeterMilliPercentage: null));

            case ObjectAction.Type.SetSpeed:
            case ObjectAction.Type.IncreaseSpeed:
            case ObjectAction.Type.DecreaseSpeed:
                long speed = action.SpeedInMillipixelsPerMillisecond.Evaluate(
                    obj.GetEnemyObjectExpressionInfo(),
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    rng: rng);

                if (action.ObjectActionType == ObjectAction.Type.SetSpeed)
                {
                    obj.SpeedInMillipixelsPerMillisecond = speed;
                }
                else if (action.ObjectActionType == ObjectAction.Type.IncreaseSpeed)
                {
                    obj.SpeedInMillipixelsPerMillisecond += speed;
                }
                else if (action.ObjectActionType == ObjectAction.Type.DecreaseSpeed)
                {
                    obj.SpeedInMillipixelsPerMillisecond -= speed;
                }
                else
                {
                    throw new Exception();
                }

                if (obj.SpeedInMillipixelsPerMillisecond < 0)
                {
                    obj.SpeedInMillipixelsPerMillisecond = 0;
                }

                return(new ResultOfAction(
                           newObjectAction: action,
                           shouldEndLevel: false,
                           newEnemyObjects: new List <EnemyObject>(),
                           newPowerUps: new List <Tuple <long, long> >(),
                           newSoundEffectsToPlay: new List <string>(),
                           bossHealthMeterNumber: null,
                           bossHealthMeterMilliPercentage: null));

            case ObjectAction.Type.SetPosition:
                long newXMillisPosition = action.SetXMillisPosition.Evaluate(
                    obj.GetEnemyObjectExpressionInfo(),
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    rng: rng);
                long newYMillisPosition = action.SetYMillisPosition.Evaluate(
                    obj.GetEnemyObjectExpressionInfo(),
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    rng: rng);
                obj.XMillis = newXMillisPosition;
                obj.YMillis = newYMillisPosition;

                return(new ResultOfAction(
                           newObjectAction: action,
                           shouldEndLevel: false,
                           newEnemyObjects: new List <EnemyObject>(),
                           newPowerUps: new List <Tuple <long, long> >(),
                           newSoundEffectsToPlay: new List <string>(),
                           bossHealthMeterNumber: null,
                           bossHealthMeterMilliPercentage: null));

            case ObjectAction.Type.SetFacingDirection:

                long newFacingDirection = action.SetFacingDirectionInMillidegrees.Evaluate(
                    obj.GetEnemyObjectExpressionInfo(),
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    rng: rng);

                obj.FacingDirectionInMillidegrees = newFacingDirection;

                return(new ResultOfAction(
                           newObjectAction: action,
                           shouldEndLevel: false,
                           newEnemyObjects: new List <EnemyObject>(),
                           newPowerUps: new List <Tuple <long, long> >(),
                           newSoundEffectsToPlay: new List <string>(),
                           bossHealthMeterNumber: null,
                           bossHealthMeterMilliPercentage: null));

            case ObjectAction.Type.Destroy:
                obj.IsDestroyed = true;

                return(new ResultOfAction(
                           newObjectAction: action,
                           shouldEndLevel: false,
                           newEnemyObjects: new List <EnemyObject>(),
                           newPowerUps: new List <Tuple <long, long> >(),
                           newSoundEffectsToPlay: new List <string>(),
                           bossHealthMeterNumber: null,
                           bossHealthMeterMilliPercentage: null));

            case ObjectAction.Type.DestroyParent:
                if (obj.ParentObject == null)
                {
                    throw new Exception();
                }

                obj.ParentObject.IsDestroyed = true;

                return(new ResultOfAction(
                           newObjectAction: action,
                           shouldEndLevel: false,
                           newEnemyObjects: new List <EnemyObject>(),
                           newPowerUps: new List <Tuple <long, long> >(),
                           newSoundEffectsToPlay: new List <string>(),
                           bossHealthMeterNumber: null,
                           bossHealthMeterMilliPercentage: null));

            case ObjectAction.Type.SpawnChild:
                long childXMillis = action.SpawnChildXMillis.Evaluate(
                    obj.GetEnemyObjectExpressionInfo(),
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    rng: rng);
                long childYMillis = action.SpawnChildYMillis.Evaluate(
                    obj.GetEnemyObjectExpressionInfo(),
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    rng: rng);

                EnemyObjectTemplate childObjectTemplate = enemyObjectTemplates[action.SpawnChildObjectTemplateName];

                var childObjectNumericVariables = new Dictionary <string, IMathExpression>();
                var childObjectBooleanVariables = new Dictionary <string, BooleanExpression>();

                if (action.SpawnChildInitialChildNumericVariables != null)
                {
                    for (int i = 0; i < action.SpawnChildInitialChildNumericVariables.Count; i++)
                    {
                        childObjectNumericVariables.Add(action.SpawnChildInitialChildNumericVariables[i].Name, action.SpawnChildInitialChildNumericVariables[i].Value);
                    }
                }
                if (action.SpawnChildInitialChildBooleanVariables != null)
                {
                    for (int i = 0; i < action.SpawnChildInitialChildBooleanVariables.Count; i++)
                    {
                        childObjectBooleanVariables.Add(action.SpawnChildInitialChildBooleanVariables[i].Name, action.SpawnChildInitialChildBooleanVariables[i].Value);
                    }
                }

                var newEnemyObjects = new List <EnemyObject>();

                newEnemyObjects.Add(new EnemyObject(
                                        template: childObjectTemplate,
                                        initialXMillis: childXMillis,
                                        initialYMillis: childYMillis,
                                        playerXMillis: playerXMillis,
                                        playerYMillis: playerYMillis,
                                        elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                                        isPlayerDestroyed: isPlayerDestroyed,
                                        parent: obj,
                                        initialNumericVariables: childObjectNumericVariables,
                                        initialBooleanVariables: childObjectBooleanVariables,
                                        rng: rng));

                return(new ResultOfAction(
                           newObjectAction: action,
                           shouldEndLevel: false,
                           newEnemyObjects: newEnemyObjects,
                           newPowerUps: new List <Tuple <long, long> >(),
                           newSoundEffectsToPlay: new List <string>(),
                           bossHealthMeterNumber: null,
                           bossHealthMeterMilliPercentage: null));

            case ObjectAction.Type.SpawnPowerUp:
                var powerUpList = new List <Tuple <long, long> >();
                powerUpList.Add(new Tuple <long, long>(obj.XMillis, obj.YMillis));

                return(new ResultOfAction(
                           newObjectAction: action,
                           shouldEndLevel: false,
                           newEnemyObjects: new List <EnemyObject>(),
                           newPowerUps: powerUpList,
                           newSoundEffectsToPlay: new List <string>(),
                           bossHealthMeterNumber: null,
                           bossHealthMeterMilliPercentage: null));

            case ObjectAction.Type.SetNumericVariable:

                obj.NumericVariables[action.SetVariableName] = action.SetNumericVariableValue.Evaluate(
                    obj.GetEnemyObjectExpressionInfo(),
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    rng: rng);

                return(new ResultOfAction(
                           newObjectAction: action,
                           shouldEndLevel: false,
                           newEnemyObjects: new List <EnemyObject>(),
                           newPowerUps: new List <Tuple <long, long> >(),
                           newSoundEffectsToPlay: new List <string>(),
                           bossHealthMeterNumber: null,
                           bossHealthMeterMilliPercentage: null));

            case ObjectAction.Type.SetBooleanVariable:
                obj.BooleanVariables[action.SetVariableName] = action.SetBooleanVariableValue.Evaluate(
                    obj.GetEnemyObjectExpressionInfo(),
                    isParentDestroyed: isParentDestroyed,
                    isPlayerDestroyed: isPlayerDestroyed,
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    rng: rng);

                return(new ResultOfAction(
                           newObjectAction: action,
                           shouldEndLevel: false,
                           newEnemyObjects: new List <EnemyObject>(),
                           newPowerUps: new List <Tuple <long, long> >(),
                           newSoundEffectsToPlay: new List <string>(),
                           bossHealthMeterNumber: null,
                           bossHealthMeterMilliPercentage: null));

            case ObjectAction.Type.SetParentNumericVariable:

                if (obj.ParentObject == null)
                {
                    throw new Exception();
                }

                obj.ParentObject.NumericVariables[action.SetVariableName] = action.SetNumericVariableValue.Evaluate(
                    obj.GetEnemyObjectExpressionInfo(),
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    rng: rng);

                return(new ResultOfAction(
                           newObjectAction: action,
                           shouldEndLevel: false,
                           newEnemyObjects: new List <EnemyObject>(),
                           newPowerUps: new List <Tuple <long, long> >(),
                           newSoundEffectsToPlay: new List <string>(),
                           bossHealthMeterNumber: null,
                           bossHealthMeterMilliPercentage: null));

            case ObjectAction.Type.SetParentBooleanVariable:
            {
                if (obj.ParentObject == null)
                {
                    throw new Exception();
                }

                obj.ParentObject.BooleanVariables[action.SetVariableName] = action.SetBooleanVariableValue.Evaluate(
                    obj.GetEnemyObjectExpressionInfo(),
                    isParentDestroyed: obj.ParentObject.IsDestroyed,
                    isPlayerDestroyed: isPlayerDestroyed,
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    rng: rng);

                return(new ResultOfAction(
                           newObjectAction: action,
                           shouldEndLevel: false,
                           newEnemyObjects: new List <EnemyObject>(),
                           newPowerUps: new List <Tuple <long, long> >(),
                           newSoundEffectsToPlay: new List <string>(),
                           bossHealthMeterNumber: null,
                           bossHealthMeterMilliPercentage: null));
            }

            case ObjectAction.Type.EndLevel:

                return(new ResultOfAction(
                           newObjectAction: action,
                           shouldEndLevel: true,
                           newEnemyObjects: new List <EnemyObject>(),
                           newPowerUps: new List <Tuple <long, long> >(),
                           newSoundEffectsToPlay: new List <string>(),
                           bossHealthMeterNumber: null,
                           bossHealthMeterMilliPercentage: null));

            case ObjectAction.Type.PlaySoundEffect:
            {
                var newSoundEffectsToPlay = new List <string>();
                newSoundEffectsToPlay.Add(action.SoundEffectName);

                return(new ResultOfAction(
                           newObjectAction: action,
                           shouldEndLevel: false,
                           newEnemyObjects: new List <EnemyObject>(),
                           newPowerUps: new List <Tuple <long, long> >(),
                           newSoundEffectsToPlay: newSoundEffectsToPlay,
                           bossHealthMeterNumber: null,
                           bossHealthMeterMilliPercentage: null));
            }

            case ObjectAction.Type.DisplayBossHealthBar:
            {
                long bossHealthMeterNumber = action.BossHealthBarMeterNumber.Evaluate(
                    obj.GetEnemyObjectExpressionInfo(),
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    rng: rng);

                long bossHealthMeterMilliPercentage = action.BossHealthBarMilliPercentage.Evaluate(
                    obj.GetEnemyObjectExpressionInfo(),
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    rng: rng);

                return(new ResultOfAction(
                           newObjectAction: action,
                           shouldEndLevel: false,
                           newEnemyObjects: new List <EnemyObject>(),
                           newPowerUps: new List <Tuple <long, long> >(),
                           newSoundEffectsToPlay: new List <string>(),
                           bossHealthMeterNumber: bossHealthMeterNumber,
                           bossHealthMeterMilliPercentage: bossHealthMeterMilliPercentage));
            }

            case ObjectAction.Type.SetSpriteName:

                obj.SpriteName = action.SpriteName;

                return(new ResultOfAction(
                           newObjectAction: action,
                           shouldEndLevel: false,
                           newEnemyObjects: new List <EnemyObject>(),
                           newPowerUps: new List <Tuple <long, long> >(),
                           newSoundEffectsToPlay: new List <string>(),
                           bossHealthMeterNumber: null,
                           bossHealthMeterMilliPercentage: null));

            case ObjectAction.Type.Conditional:
                bool shouldExecute = action.Conditional.Evaluate(
                    obj.GetEnemyObjectExpressionInfo(),
                    isParentDestroyed: isParentDestroyed,
                    isPlayerDestroyed: isPlayerDestroyed,
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    rng: rng);

                if (shouldExecute)
                {
                    var a = HandleAction(
                        action: action.ConditionalAction,
                        obj: obj,
                        playerXMillis: playerXMillis,
                        playerYMillis: playerYMillis,
                        elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                        isPlayerDestroyed: isPlayerDestroyed,
                        enemyObjectTemplates: enemyObjectTemplates,
                        rng: rng);

                    return(new ResultOfAction(
                               newObjectAction: ObjectAction.Condition(action.Conditional, a.NewObjectAction),
                               shouldEndLevel: a.ShouldEndLevel,
                               newEnemyObjects: a.NewEnemyObjects,
                               newPowerUps: a.NewPowerUps,
                               newSoundEffectsToPlay: a.NewSoundEffectsToPlay,
                               bossHealthMeterNumber: a.BossHealthMeterNumber,
                               bossHealthMeterMilliPercentage: a.BossHealthMeterMilliPercentage));
                }
                else
                {
                    return(new ResultOfAction(
                               newObjectAction: action,
                               shouldEndLevel: false,
                               newEnemyObjects: new List <EnemyObject>(),
                               newPowerUps: new List <Tuple <long, long> >(),
                               newSoundEffectsToPlay: new List <string>(),
                               bossHealthMeterNumber: null,
                               bossHealthMeterMilliPercentage: null));
                }

            case ObjectAction.Type.ConditionalNextAction:
                ResultOfAction actionResult = HandleAction(
                    action: action.ConditionalNextActionCurrentAction,
                    obj: obj,
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    isPlayerDestroyed: isPlayerDestroyed,
                    enemyObjectTemplates: enemyObjectTemplates,
                    rng: rng);

                bool shouldMoveToNext = action.ConditionalNextActionConditional.Evaluate(
                    obj.GetEnemyObjectExpressionInfo(),
                    isParentDestroyed: isParentDestroyed,
                    isPlayerDestroyed: isPlayerDestroyed,
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    rng: rng);

                return(new ResultOfAction(
                           newObjectAction: shouldMoveToNext
                                                        ? action.ConditionalNextActionNextAction
                                                        : ObjectAction.ConditionalNextAction(actionResult.NewObjectAction, action.ConditionalNextActionConditional, action.ConditionalNextActionNextAction),
                           shouldEndLevel: actionResult.ShouldEndLevel,
                           newEnemyObjects: actionResult.NewEnemyObjects,
                           newPowerUps: actionResult.NewPowerUps,
                           newSoundEffectsToPlay: actionResult.NewSoundEffectsToPlay,
                           bossHealthMeterNumber: actionResult.BossHealthMeterNumber,
                           bossHealthMeterMilliPercentage: actionResult.BossHealthMeterMilliPercentage));

            case ObjectAction.Type.Union:
            {
                bool shouldEndLevel                 = false;
                var  newUnionActions                = new List <ObjectAction>();
                var  enemyObjects                   = new List <EnemyObject>();
                var  newPowerUps                    = new List <Tuple <long, long> >();
                var  newSoundEffectsToPlay          = new List <string>();
                long?bossHealthMeterNumber          = null;
                long?bossHealthMeterMilliPercentage = null;

                for (var i = 0; i < action.UnionActions.Count; i++)
                {
                    ResultOfAction r = HandleAction(
                        action: action.UnionActions[i],
                        obj: obj,
                        playerXMillis: playerXMillis,
                        playerYMillis: playerYMillis,
                        elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                        isPlayerDestroyed: isPlayerDestroyed,
                        enemyObjectTemplates: enemyObjectTemplates,
                        rng: rng);

                    newUnionActions.Add(r.NewObjectAction);

                    if (r.ShouldEndLevel)
                    {
                        shouldEndLevel = true;
                    }

                    foreach (EnemyObject newEnemyObj in r.NewEnemyObjects)
                    {
                        enemyObjects.Add(newEnemyObj);
                    }

                    foreach (var newPowerUp in r.NewPowerUps)
                    {
                        newPowerUps.Add(newPowerUp);
                    }

                    foreach (var newSoundEffect in r.NewSoundEffectsToPlay)
                    {
                        newSoundEffectsToPlay.Add(newSoundEffect);
                    }

                    if (r.BossHealthMeterNumber != null)
                    {
                        bossHealthMeterNumber = r.BossHealthMeterNumber;
                    }

                    if (r.BossHealthMeterMilliPercentage != null)
                    {
                        bossHealthMeterMilliPercentage = r.BossHealthMeterMilliPercentage;
                    }
                }

                return(new ResultOfAction(
                           newObjectAction: ObjectAction.Union(newUnionActions),
                           shouldEndLevel: shouldEndLevel,
                           newEnemyObjects: enemyObjects,
                           newPowerUps: newPowerUps,
                           newSoundEffectsToPlay: newSoundEffectsToPlay,
                           bossHealthMeterNumber: bossHealthMeterNumber,
                           bossHealthMeterMilliPercentage: bossHealthMeterMilliPercentage));
            }

            default:
                throw new Exception();
            }
        }
Пример #15
0
        public EnemyObject(
            EnemyObjectTemplate template,
            long initialXMillis,
            long initialYMillis,
            long playerXMillis,
            long playerYMillis,
            long elapsedMillisecondsPerIteration,
            bool isPlayerDestroyed,
            EnemyObject parent /* nullable */,
            Dictionary <string, IMathExpression> initialNumericVariables,            /* MathExpression is with respect to the parent */ /* nullable */
            Dictionary <string, BooleanExpression> initialBooleanVariables /* BooleanExpression is with respect to the parent */ /* nullable */,
            IDTDeterministicRandom rng)
        {
            this._objectType     = template.ObjectType;
            this._damageBoxes    = template.DamageBoxes;
            this._collisionBoxes = template.CollisionBoxes;
            this.SpriteName      = template.SpriteName;
            this.Action          = template.Action;
            if (template.InitialMilliHP != null)
            {
                EnemyObjectExpressionInfo enemyObjectExpressionInfo;

                if (parent != null)
                {
                    enemyObjectExpressionInfo = parent.GetEnemyObjectExpressionInfo();
                }
                else
                {
                    enemyObjectExpressionInfo = null;
                }

                this.MilliHP = template.InitialMilliHP.Evaluate(
                    enemyObjectExpressionInfo: enemyObjectExpressionInfo,
                    playerXMillis: playerXMillis,
                    playerYMillis: playerYMillis,
                    elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                    rng: rng);
            }
            else
            {
                this.MilliHP = null;
            }
            this.XMillis = initialXMillis;
            this.YMillis = initialYMillis;
            this.SpeedInMillipixelsPerMillisecond = 0;
            this.MovementDirectionInMillidegrees  = 180 * 1000;
            this.FacingDirectionInMillidegrees    = 180 * 1000;
            this.IsDestroyed      = false;
            this._parentObject    = parent;
            this.NumericVariables = new Dictionary <string, long>();
            this.BooleanVariables = new Dictionary <string, bool>();
            if (initialNumericVariables != null)
            {
                foreach (var keyValuePair in initialNumericVariables)
                {
                    string variableName = keyValuePair.Key;
                    EnemyObjectExpressionInfo enemyObjectExpressionInfo;
                    if (parent != null)
                    {
                        enemyObjectExpressionInfo = parent.GetEnemyObjectExpressionInfo();
                    }
                    else
                    {
                        enemyObjectExpressionInfo = null;
                    }

                    this.NumericVariables.Add(variableName,
                                              keyValuePair.Value.Evaluate(
                                                  enemyObjectExpressionInfo: enemyObjectExpressionInfo,
                                                  playerXMillis: playerXMillis,
                                                  playerYMillis: playerYMillis,
                                                  elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                                                  rng: rng));
                }
            }
            if (initialBooleanVariables != null)
            {
                foreach (var keyValuePair in initialBooleanVariables)
                {
                    string variableName = keyValuePair.Key;
                    EnemyObjectExpressionInfo enemyObjectExpressionInfo;
                    if (parent != null)
                    {
                        enemyObjectExpressionInfo = parent.GetEnemyObjectExpressionInfo();
                    }
                    else
                    {
                        enemyObjectExpressionInfo = null;
                    }

                    bool?isParentDestroyed;
                    if (parent != null)
                    {
                        isParentDestroyed = parent.IsDestroyed;
                    }
                    else
                    {
                        isParentDestroyed = null;
                    }

                    this.BooleanVariables.Add(variableName,
                                              keyValuePair.Value.Evaluate(
                                                  enemyObjectExpressionInfo: enemyObjectExpressionInfo,
                                                  isParentDestroyed: isParentDestroyed,
                                                  isPlayerDestroyed: isPlayerDestroyed,
                                                  playerXMillis: playerXMillis,
                                                  playerYMillis: playerYMillis,
                                                  elapsedMillisecondsPerIteration: elapsedMillisecondsPerIteration,
                                                  rng: rng));
                }
            }
        }
Пример #16
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));
        }
Пример #17
0
        public static GenerateDestructionAnimationResult GenerateDestructionAnimation(
            List <DTDanmakuImage> orderedSprites,
            long millisecondsPerSprite,
            GuidGenerator guidGenerator)
        {
            Dictionary <string, DTDanmakuImage>      spriteNameToImageDictionary = new Dictionary <string, DTDanmakuImage>();
            Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates        = new Dictionary <string, EnemyObjectTemplate>();

            ObjectAction incrementElapsedTimeVariable = ObjectAction.SetNumericVariable(
                variableName: elapsedTimeInMillisVariableName,
                variableValue: MathExpression.Add(
                    leftSide: MathExpression.Variable(variableName: elapsedTimeInMillisVariableName),
                    rightSide: MathExpression.ElapsedMillisecondsPerIteration()));

            long startMilliseconds = 0;
            List <ObjectAction> actionsToUnionTogether = new List <ObjectAction>();

            actionsToUnionTogether.Add(incrementElapsedTimeVariable);
            for (int i = 0; i < orderedSprites.Count; i++)
            {
                DTDanmakuImage image      = orderedSprites[i];
                string         spriteName = guidGenerator.NextGuid();
                string         childObjectTemplateName = guidGenerator.NextGuid();

                Tuple <ObjectAction, EnemyObjectTemplate> result = SpawnOneDestructionSpriteImage(
                    startMilliseconds: startMilliseconds,
                    endMilliseconds: startMilliseconds + millisecondsPerSprite,
                    childObjectTemplateName: childObjectTemplateName,
                    spriteName: spriteName,
                    isLast: i == orderedSprites.Count - 1);
                startMilliseconds += millisecondsPerSprite;

                actionsToUnionTogether.Add(result.Item1);
                spriteNameToImageDictionary.Add(spriteName, image);
                enemyObjectTemplates.Add(childObjectTemplateName, result.Item2);
            }

            string placeholderObjectTemplateName = guidGenerator.NextGuid();

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

            initialChildNumericVariables.Add(new ObjectAction.InitialChildNumericVariableInfo(elapsedTimeInMillisVariableName, MathExpression.Constant(0)));
            ObjectAction action = ObjectAction.SpawnChild(
                childXMillis: MathExpression.XMillis(),
                childYMillis: MathExpression.YMillis(),
                childObjectTemplateName: placeholderObjectTemplateName,
                childInitialNumericVariables: initialChildNumericVariables,
                childInitialBooleanVariables: null);

            EnemyObjectTemplate placeholderObjectTemplate = EnemyObjectTemplate.Enemy(
                action: ObjectAction.Union(actionsToUnionTogether),
                initialMilliHP: null,
                damageBoxes: null,
                collisionBoxes: null,
                spriteName: null);

            enemyObjectTemplates.Add(placeholderObjectTemplateName, placeholderObjectTemplate);

            return(new GenerateDestructionAnimationResult(
                       objectAction: action,
                       spriteNameToImageDictionary: spriteNameToImageDictionary,
                       enemyObjectTemplates: enemyObjectTemplates));
        }
Пример #18
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));
        }