// Spawns 3 bullets (120 degrees apart) private static ObjectAction SpawnSatelliteBullet( Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary, Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates, GuidGenerator guidGenerator) { string singleBulletSpriteName = guidGenerator.NextGuid(); spriteNameToImageDictionary.Add(singleBulletSpriteName, DTDanmakuImage.OrbiterEnemyBullet); 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(120 * 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(240 * 1000)))); ObjectAction spawnSingleBulletAction3 = ObjectAction.SpawnChild( childXMillis: MathExpression.XMillis(), childYMillis: MathExpression.YMillis(), childObjectTemplateName: singleBulletTemplateName, childInitialNumericVariables: initialNumericVariables3, childInitialBooleanVariables: null); EnemyObjectTemplate placeholderTemplate = EnemyObjectTemplate.Placeholder( action: ObjectAction.Union( ObjectAction.SetNumericVariable("random offset", MathExpression.RandomInteger(MathExpression.Constant(360 * 1000))), spawnSingleBulletAction1, spawnSingleBulletAction2, spawnSingleBulletAction3, ObjectAction.Destroy())); string placeholderTemplateName = guidGenerator.NextGuid(); enemyObjectTemplates.Add(placeholderTemplateName, placeholderTemplate); return(ObjectAction.SpawnChild( childXMillis: MathExpression.XMillis(), childYMillis: MathExpression.YMillis(), childObjectTemplateName: placeholderTemplateName, childInitialNumericVariables: null, childInitialBooleanVariables: null)); }
private static ObjectAction GetMoveAction( GuidGenerator guidGenerator) { string variableName = guidGenerator.NextGuid(); ObjectAction initializeVariable = ObjectAction.SetNumericVariable( variableName: variableName, variableValue: MathExpression.Constant(0)); ObjectAction incrementVariable = ObjectAction.SetNumericVariable( variableName: variableName, variableValue: MathExpression.Add(MathExpression.Variable(variableName), MathExpression.ElapsedMillisecondsPerIteration())); ObjectAction initializeAndIncrementVariable = ObjectAction.ConditionalNextAction( currentAction: initializeVariable, condition: BooleanExpression.True(), nextAction: incrementVariable); ObjectAction teleportToInitialLocation = ObjectAction.SetPosition( xMillis: MathExpression.Add(50 * 1000, MathExpression.RandomInteger(900 * 1000)), yMillis: MathExpression.Constant(800 * 1000)); ObjectAction faceTowardsPlayer = ObjectAction.Move( moveToXMillis: MathExpression.PlayerXMillis(), moveToYMillis: MathExpression.Min(MathExpression.PlayerYMillis(), 300 * 1000)); ObjectAction setInitialSpeed = ObjectActionGenerator.DoOnce( ObjectAction.SetSpeed( speedInMillipixelsPerMillisecond: MathExpression.Constant(60))); ObjectAction slowDownSpeed1 = ObjectAction.Condition( condition: BooleanExpression.GreaterThanOrEqualTo( MathExpression.Variable(variableName), 1 * 1000), action: ObjectActionGenerator.DoOnce( ObjectAction.SetSpeed( speedInMillipixelsPerMillisecond: MathExpression.Constant(40)))); ObjectAction slowDownSpeed2 = ObjectAction.Condition( condition: BooleanExpression.GreaterThanOrEqualTo( MathExpression.Variable(variableName), 2 * 1000), action: ObjectActionGenerator.DoOnce( ObjectAction.SetSpeed( speedInMillipixelsPerMillisecond: MathExpression.Constant(20)))); ObjectAction stopMovement = ObjectAction.Condition( condition: BooleanExpression.GreaterThanOrEqualTo( MathExpression.Variable(variableName), 3 * 1000), action: ObjectActionGenerator.DoOnce( ObjectAction.SetSpeed( speedInMillipixelsPerMillisecond: MathExpression.Constant(0)))); BooleanExpression ShouldLeave1 = BooleanExpression.GreaterThanOrEqualTo( MathExpression.Variable(variableName), 10 * 1000); ObjectAction leave1 = ObjectAction.SetPosition( xMillis: MathExpression.XMillis(), yMillis: MathExpression.Add(MathExpression.YMillis(), MathExpression.Multiply(MathExpression.ElapsedMillisecondsPerIteration(), MathExpression.Constant(25)))); ObjectAction leave1ConditionalAction = ObjectAction.Condition( condition: ShouldLeave1, action: leave1); BooleanExpression shouldLeave2 = BooleanExpression.GreaterThanOrEqualTo( MathExpression.Variable(variableName), 11 * 1000); ObjectAction leave2 = ObjectAction.SetPosition( xMillis: MathExpression.XMillis(), yMillis: MathExpression.Add(MathExpression.YMillis(), MathExpression.Multiply(MathExpression.ElapsedMillisecondsPerIteration(), MathExpression.Constant(50)))); ObjectAction leave2ConditionalAction = ObjectAction.ConditionalNextAction( currentAction: leave1ConditionalAction, condition: shouldLeave2, nextAction: leave2); ObjectAction shouldDestroy = ObjectAction.Condition( condition: BooleanExpression.And(shouldLeave2, BooleanExpression.GreaterThanOrEqualTo(MathExpression.YMillis(), 800 * 1000)), action: ObjectAction.Destroy()); return(ObjectAction.ConditionalNextAction( currentAction: teleportToInitialLocation, condition: BooleanExpression.True(), nextAction: ObjectAction.Union(faceTowardsPlayer, initializeAndIncrementVariable, setInitialSpeed, slowDownSpeed1, slowDownSpeed2, stopMovement, leave2ConditionalAction, shouldDestroy))); }
private static ObjectAction SpawnBullet( IMathExpression bulletDirectionInMillidegrees, Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary, Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates, GuidGenerator guidGenerator) { string bulletSpriteName = guidGenerator.NextGuid(); spriteNameToImageDictionary.Add(bulletSpriteName, DTDanmakuImage.BarrageEnemyBullet); 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(100), 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(25000)), childObjectTemplateName: templateName, childInitialNumericVariables: null, childInitialBooleanVariables: null)); }
private static ObjectAction GetMoveAndSetCanShootVariableAction( IMathExpression xMillis, GuidGenerator guidGenerator) { string variableName = guidGenerator.NextGuid(); ObjectAction initializeVariable = ObjectAction.SetNumericVariable( variableName: variableName, variableValue: MathExpression.Constant(0)); ObjectAction incrementVariable = ObjectAction.SetNumericVariable( variableName: variableName, variableValue: MathExpression.Add(MathExpression.Variable(variableName), MathExpression.ElapsedMillisecondsPerIteration())); ObjectAction initializeAndIncrementVariable = ObjectAction.ConditionalNextAction( currentAction: initializeVariable, condition: BooleanExpression.True(), nextAction: incrementVariable); ObjectAction teleportToInitialLocation = ObjectAction.SetPosition( xMillis: xMillis, yMillis: MathExpression.Constant(800 * 1000)); ObjectAction moveDownSpeed1 = ObjectAction.SetPosition( xMillis: MathExpression.XMillis(), yMillis: MathExpression.Subtract(MathExpression.YMillis(), MathExpression.Multiply(MathExpression.Constant(100), MathExpression.ElapsedMillisecondsPerIteration()))); ObjectAction moveDownSpeed2 = ObjectAction.SetPosition( xMillis: MathExpression.XMillis(), yMillis: MathExpression.Subtract(MathExpression.YMillis(), MathExpression.Multiply(MathExpression.Constant(70), MathExpression.ElapsedMillisecondsPerIteration()))); ObjectAction moveDownSpeed3 = ObjectAction.SetPosition( xMillis: MathExpression.XMillis(), yMillis: MathExpression.Subtract(MathExpression.YMillis(), MathExpression.Multiply(MathExpression.Constant(30), MathExpression.ElapsedMillisecondsPerIteration()))); ObjectAction stopMovement = ObjectAction.Union( ObjectActionGenerator.Noop(), ObjectActionGenerator.DoOnce(ObjectAction.SetBooleanVariable("can shoot", BooleanExpression.True()))); ObjectAction moveUpSpeed1 = ObjectAction.Union( ObjectActionGenerator.DoOnce(ObjectAction.SetBooleanVariable("can shoot", BooleanExpression.False())), ObjectAction.SetPosition( xMillis: MathExpression.XMillis(), yMillis: MathExpression.Add(MathExpression.YMillis(), MathExpression.Multiply(MathExpression.Constant(30), MathExpression.ElapsedMillisecondsPerIteration())))); ObjectAction moveUpSpeed2 = ObjectAction.SetPosition( xMillis: MathExpression.XMillis(), yMillis: MathExpression.Add(MathExpression.YMillis(), MathExpression.Multiply(MathExpression.Constant(70), MathExpression.ElapsedMillisecondsPerIteration()))); ObjectAction moveUpSpeed3 = ObjectAction.SetPosition( xMillis: MathExpression.XMillis(), yMillis: MathExpression.Add(MathExpression.YMillis(), MathExpression.Multiply(MathExpression.Constant(100), MathExpression.ElapsedMillisecondsPerIteration()))); ObjectAction destroyAction = ObjectAction.Condition( condition: BooleanExpression.GreaterThanOrEqualTo(MathExpression.YMillis(), MathExpression.Constant(800 * 1000)), action: ObjectAction.Destroy()); return(ObjectAction.Union( ObjectActionGenerator.DoOnce(ObjectAction.SetBooleanVariable("can shoot", BooleanExpression.False())), initializeAndIncrementVariable, ObjectActionGenerator.DoOnce(teleportToInitialLocation), ObjectAction.ConditionalNextAction( currentAction: moveDownSpeed1, condition: BooleanExpression.GreaterThanOrEqualTo(MathExpression.Variable(variableName), MathExpression.Constant(3000)), nextAction: ObjectAction.ConditionalNextAction( currentAction: moveDownSpeed2, condition: BooleanExpression.GreaterThanOrEqualTo(MathExpression.Variable(variableName), MathExpression.Constant(4000)), nextAction: ObjectAction.ConditionalNextAction( currentAction: moveDownSpeed3, condition: BooleanExpression.GreaterThanOrEqualTo(MathExpression.Variable(variableName), MathExpression.Constant(5000)), nextAction: ObjectAction.ConditionalNextAction( currentAction: stopMovement, condition: BooleanExpression.GreaterThanOrEqualTo(MathExpression.Variable(variableName), MathExpression.Constant(12000)), nextAction: ObjectAction.ConditionalNextAction( currentAction: moveUpSpeed1, condition: BooleanExpression.GreaterThanOrEqualTo(MathExpression.Variable(variableName), MathExpression.Constant(13000)), nextAction: ObjectAction.ConditionalNextAction( currentAction: moveUpSpeed2, condition: BooleanExpression.GreaterThanOrEqualTo(MathExpression.Variable(variableName), MathExpression.Constant(14000)), nextAction: ObjectAction.Union(moveUpSpeed3, destroyAction))))))))); }
public static BooleanExpression Or(BooleanExpression b1, BooleanExpression b2, BooleanExpression b3, BooleanExpression b4) { // Note the careful attention to short-circuiting behavior return(BooleanExpression.Or(BooleanExpression.Or(b1, b2, b3), b4)); }
public static BooleanExpression LessThanOrEqualTo(long leftSide, IMathExpression rightSide) { return(BooleanExpression.LessThanOrEqualTo(MathExpression.Constant(leftSide), rightSide)); }
public static BooleanExpression LessThanOrEqualTo(IMathExpression leftSide, long rightSide) { return(BooleanExpression.LessThanOrEqualTo(leftSide, MathExpression.Constant(rightSide))); }