Пример #1
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));
        }
Пример #2
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));
        }
Пример #3
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));
        }
Пример #4
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));
        }
Пример #5
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));
        }
Пример #6
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));
        }