protected override void Initialize() { var displaySize = this.graphics.GraphicsDevice.DisplayMode.TitleSafeArea; this.graphics.PreferredBackBufferHeight = displaySize.Height - 100; this.graphics.PreferredBackBufferWidth = displaySize.Width; this.graphics.ApplyChanges(); const int minX = 0; var maxX = this.graphics.PreferredBackBufferWidth; const int minY = 0; var maxY = this.graphics.PreferredBackBufferHeight; this.moveSystem = new MoveSystem(this.graphics, Scene.EntityCount, Scene.PositionComponents, Scene.VelocityComponents); this.velocityModifierSystem = new VelocityModifierSystem(Scene.EntityCount, Scene.VelocityModifierCount, Scene.PositionComponents, Scene.VelocityConstraintComponents, Scene.VelocityComponents, Scene.SizeComponents, Scene.VelocityModifierComponents); var random = new Random(); for (int i = 0; i < Scene.EntityCount; i++) { var position = new PositionComponent(); position.Value = new Vector2(random.Next(minX, maxX), random.Next(minY, maxY)); Scene.PositionComponents[i] = position; var entityTypePredicate = i >= Constants.DotCount; var velMin = MathF.Select(Constants.Dot.MinVelocity, Constants.Bubble.MinVelocity, entityTypePredicate); var velMax = MathF.Select(Constants.Dot.MaxVelocity, Constants.Bubble.MaxVelocity, entityTypePredicate); Scene.VelocityConstraintComponents[i] = new VelocityConstraintComponent(velMin, velMax); var velocity = new VelocityComponent(); velocity.Value = random.NextVelocity(velMin, velMax); Scene.VelocityComponents[i] = velocity; var velocityModifierValue = (float)random.NextDouble() * (Constants.Bubble.MaxModifier - Constants.Bubble.MinModifier) + Constants.Bubble.MinModifier; var scaleMax = MathF.Select(Constants.Bubble.MinModifier, Constants.Bubble.MaxModifier, velocityModifierValue >= 0.0f); var bubbleAlpha = (byte)(int)(128 * (velocityModifierValue / scaleMax)); var bubbleColorR = MathB.Select(0, byte.MaxValue, velocityModifierValue < 0.0f); var bubbleColorG = MathB.Select(0, byte.MaxValue, velocityModifierValue >= 0.0f); var dotColors = new byte[3]; random.NextBytes(dotColors); var colorR = MathB.Select(dotColors[0], bubbleColorR, entityTypePredicate); var colorG = MathB.Select(dotColors[1], bubbleColorG, entityTypePredicate); var colorB = MathB.Select(dotColors[2], byte.MinValue, entityTypePredicate); var alpha = MathB.Select(byte.MaxValue, bubbleAlpha, entityTypePredicate); var index = Math.Select(Constants.Sprites.Dot, Constants.Sprites.Bubble, entityTypePredicate); Scene.SpriteComponents[i] = new SpriteComponent(colorR, colorG, colorB, alpha, index); if (entityTypePredicate) { var modifierIndex = i - Constants.DotCount; Scene.SizeComponents[modifierIndex] = new SizeComponent(64); Scene.VelocityModifierComponents[modifierIndex] = new VelocityModifierComponent(velocityModifierValue); } } base.Initialize(); }