public static void Render( List <EnemyObject> enemyObjects, EnemyObjectType enemyObjectType, TranslatedDTDanmakuDisplay display, Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary) { foreach (EnemyObject enemyObj in enemyObjects) { if (enemyObj.IsDestroyed) { continue; } if (enemyObj.ObjectType != enemyObjectType) { continue; } if (enemyObj.SpriteName == null) { continue; } DTDanmakuImage image = spriteNameToImageDictionary[enemyObj.SpriteName]; long width = display.GetWidth(image); long height = display.GetHeight(image); int x = (int)(enemyObj.XMillis / 1000 - width / 2); int y = (int)(700 - enemyObj.YMillis / 1000 - height / 2); display.DrawImageRotatedClockwise(image, x, y, (int)enemyObj.FacingDirectionInMillidegrees); } }
public void DrawImageRotatedCounterclockwise(DTDanmakuImage image, int x, int y, int milliDegrees) { Surface surface = this.GetSurface(image); surface.RotationCenter = OriginAlignment.Center; surface.RotationAngle = milliDegrees / 1000.0 * 2.0 * Math.PI / 360.0; // Unclear why the "- 1" is necessary, but it seems to make the image render better. surface.Draw(x - 1, y); }
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)); }
public long GetHeight(DTDanmakuImage image) { return(this.GetSurface(image: image).DisplayHeight); }
public long GetWidth(DTDanmakuImage image) { return(this.GetSurface(image: image).DisplayWidth); }
public void DrawImage(DTDanmakuImage image, int x, int y) { this.DrawImageRotatedCounterclockwise(image: image, x: x, y: y, milliDegrees: 0); }
private Surface GetSurface(DTDanmakuImage image) { return(this.imageToSurfaceMapping[image]); }
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)); }
public long GetHeight(DTDanmakuImage image) { return(this.display.GetAssets().GetHeight(image: image)); }
public void DrawImageRotatedCounterclockwise(DTDanmakuImage image, int x, int y, int milliDegrees) { this.display.GetAssets().DrawImageRotatedCounterclockwise(image, x + this.xOffset, y + this.yOffset, milliDegrees); }
public void DrawImage(DTDanmakuImage image, int x, int y) { this.display.GetAssets().DrawImage(image, x + this.xOffset, y + this.yOffset); }