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))); }
private static ObjectAction Phase2ShootAction( Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary, Dictionary <string, EnemyObjectTemplate> enemyObjectTemplates, GuidGenerator guidGenerator) { string singleBulletSpriteName = guidGenerator.NextGuid(); spriteNameToImageDictionary.Add(singleBulletSpriteName, DTDanmakuImage.BossPhase2EnemyBullet); 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); IMathExpression direction = DTDanmakuMath.GetMovementDirectionInMillidegrees( currentX: MathExpression.XMillis(), currentY: MathExpression.Add(MathExpression.YMillis(), MathExpression.Constant(-60000)), desiredX: MathExpression.PlayerXMillis(), desiredY: MathExpression.PlayerYMillis()); direction = MathExpression.Add( direction, MathExpression.Add( MathExpression.Constant(-30 * 1000), MathExpression.RandomInteger(60 * 1000))); List <ObjectAction.InitialChildNumericVariableInfo> initialNumericVariables = new List <ObjectAction.InitialChildNumericVariableInfo>(); initialNumericVariables.Add( new ObjectAction.InitialChildNumericVariableInfo( name: "direction", value: direction)); initialNumericVariables.Add( new ObjectAction.InitialChildNumericVariableInfo( name: "speed", value: MathExpression.Add(MathExpression.Constant(300), MathExpression.RandomInteger(200)))); ObjectAction spawnBullet = ObjectAction.SpawnChild( childXMillis: MathExpression.XMillis(), childYMillis: MathExpression.Add(MathExpression.YMillis(), MathExpression.Constant(-60000)), childObjectTemplateName: singleBulletTemplateName, childInitialNumericVariables: initialNumericVariables, childInitialBooleanVariables: null); string shootCooldown = guidGenerator.NextGuid(); ObjectAction initializeShootCooldown = ObjectAction.SetNumericVariable( variableName: shootCooldown, variableValue: MathExpression.Constant(50)); 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, spawnBullet)); return(ObjectAction.Union( ObjectActionGenerator.DoOnce(ObjectAction.SetNumericVariable( variableName: shootCooldown, variableValue: MathExpression.Constant(1000))), decrementShootCooldown, shootWhenCooldownIsZero)); }
private static Tuple <ObjectAction, BooleanExpression> MoveToSpecifiedLocations_Helper( long startingXMillis, long startingYMillis, long endingXMillis, long endingYMillis, long speedInPixelsPerSecond, bool shouldStrafe, GuidGenerator guidGenerator) { string variableName = guidGenerator.NextGuid(); string variableName2 = guidGenerator.NextGuid(); long?direction = DTDanmakuMath.GetMovementDirectionInMillidegrees( currentX: startingXMillis, currentY: startingYMillis, desiredX: endingXMillis, desiredY: endingYMillis); if (direction == null) { throw new Exception(); } DTDanmakuMath.Offset offset = DTDanmakuMath.GetOffset( speedInMillipixelsPerMillisecond: speedInPixelsPerSecond, // millipixels/millisecond is equivalent to pixels/second movementDirectionInMillidegrees: direction.Value, elapsedMillisecondsPerIteration: 1000); // Use the 1000 to help prevent rounding issues ObjectAction moveAction = ObjectAction.SetPosition( xMillis: MathExpression.Add(MathExpression.XMillis(), MathExpression.Divide(MathExpression.Multiply(MathExpression.Constant(offset.DeltaXInMillipixels), MathExpression.ElapsedMillisecondsPerIteration()), MathExpression.Constant(1000))), yMillis: MathExpression.Add(MathExpression.YMillis(), MathExpression.Divide(MathExpression.Multiply(MathExpression.Constant(offset.DeltaYInMillipixels), MathExpression.ElapsedMillisecondsPerIteration()), MathExpression.Constant(1000)))); ObjectAction setDirectionAction = shouldStrafe ? ObjectAction.SetFacingDirection(facingDirectionInMillidegrees: MathExpression.Constant(180 * 1000)) : ObjectAction.SetFacingDirection(facingDirectionInMillidegrees: MathExpression.Constant(direction.Value)); IMathExpression deltaX = MathExpression.AbsoluteValue(MathExpression.Subtract(MathExpression.XMillis(), MathExpression.Constant(endingXMillis))); IMathExpression deltaY = MathExpression.AbsoluteValue(MathExpression.Subtract(MathExpression.YMillis(), MathExpression.Constant(endingYMillis))); IMathExpression totalDelta = MathExpression.Add(deltaX, deltaY); ObjectAction setDeltaToVariable = ObjectAction.Union( ObjectAction.SetNumericVariable(variableName: variableName2, variableValue: MathExpression.Variable(variableName)), ObjectAction.SetNumericVariable(variableName: variableName, variableValue: totalDelta)); BooleanExpression reachedDestination = BooleanExpression.And( BooleanExpression.LessThanOrEqualTo( MathExpression.Variable(variableName2), MathExpression.Variable(variableName)), BooleanExpression.And( BooleanExpression.GreaterThanOrEqualTo(MathExpression.Variable(variableName), MathExpression.Constant(0)), BooleanExpression.GreaterThanOrEqualTo(MathExpression.Variable(variableName2), MathExpression.Constant(0)) )); ObjectAction initializeVariables = ObjectAction.Union( ObjectAction.SetNumericVariable(variableName: variableName, variableValue: MathExpression.Constant(-1)), ObjectAction.SetNumericVariable(variableName: variableName2, variableValue: MathExpression.Constant(-1))); return(new Tuple <ObjectAction, BooleanExpression>( ObjectAction.Union( moveAction, setDirectionAction, ObjectAction.ConditionalNextAction( currentAction: initializeVariables, condition: BooleanExpression.True(), nextAction: setDeltaToVariable)), reachedDestination)); }
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(); } }