private static ObjectAction Phase3ShootAction( Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary, Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates, GuidGenerator guidGenerator) { string angleVariable = guidGenerator.NextGuid(); string shootCooldownVariable = guidGenerator.NextGuid(); ObjectAction initializeAngleVariable = ObjectActionGenerator.DoOnce( ObjectAction.SetNumericVariable(angleVariable, MathExpression.Constant(0))); ObjectAction updateAngleVariableAction = ObjectAction.Union( ObjectAction.SetNumericVariable( angleVariable, MathExpression.Add(MathExpression.Variable(angleVariable), MathExpression.Multiply(MathExpression.Constant(431), MathExpression.ElapsedMillisecondsPerIteration()))), ObjectAction.Condition( condition: BooleanExpression.GreaterThan(MathExpression.Variable(angleVariable), MathExpression.Constant(360 * 1000)), action: ObjectAction.SetNumericVariable(angleVariable, MathExpression.Subtract(MathExpression.Variable(angleVariable), MathExpression.Constant(360 * 1000)))), ObjectAction.Condition( condition: BooleanExpression.GreaterThan(MathExpression.Variable(angleVariable), MathExpression.Constant(360 * 1000)), action: ObjectAction.SetNumericVariable(angleVariable, MathExpression.Constant(0)))); ObjectAction createBulletAction1 = SpawnPhase3Bullet( bulletDirectionInMillidegrees: MathExpression.Multiply(MathExpression.ParentVariable(angleVariable), MathExpression.Constant(1)), spriteNameToImageDictionary: spriteNameToImageDictionary, enemyObjectTemplates: enemyObjectTemplates, guidGenerator: guidGenerator); ObjectAction createBulletAction2 = SpawnPhase3Bullet( bulletDirectionInMillidegrees: MathExpression.Multiply(MathExpression.ParentVariable(angleVariable), MathExpression.Constant(-1)), spriteNameToImageDictionary: spriteNameToImageDictionary, enemyObjectTemplates: enemyObjectTemplates, guidGenerator: guidGenerator); IMathExpression shootCooldownInMillis = MathExpression.Constant(20); ObjectAction startCooldownAction = ObjectAction.SetNumericVariable(shootCooldownVariable, shootCooldownInMillis); ObjectAction decrementCooldownAction = ObjectAction.SetNumericVariable(shootCooldownVariable, MathExpression.Subtract(MathExpression.Variable(shootCooldownVariable), MathExpression.ElapsedMillisecondsPerIteration())); ObjectAction createBulletWhenCooldownFinishedAction = ObjectAction.Condition( condition: BooleanExpression.LessThanOrEqualTo(MathExpression.Variable(shootCooldownVariable), MathExpression.Constant(0)), action: ObjectAction.Union(startCooldownAction, createBulletAction1, createBulletAction2)); return(ObjectAction.Union( initializeAngleVariable, updateAngleVariableAction, ObjectActionGenerator.DoOnce(ObjectAction.SetNumericVariable(shootCooldownVariable, MathExpression.Constant(1000))), decrementCooldownAction, createBulletWhenCooldownFinishedAction)); }
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)); }