public SS_Station(int seed, SS_StationType stationType, Color tint, int numberOfPods) { Seed = seed; random = new SS_Random(Seed); Sprite = new SS_Texture(Size, Size, Color.clear); if (stationType == SS_StationType.Cool) { CreateRing(random.Range(0.85f, 1.0f), random.Range(1, 4), true, random.NextColor(), false); CreateRing(random.Range(0.5f, 0.75f), random.Range(1, 4), true, random.NextColor(), true); // Draw lights for (int i = 0; i < LightPoints.Count; i++) { CreateFlare(Sprite, LightPoints[i], 16, true, Color.white); } int podCount = random.RangeEven(2, 8); int podWidth = random.RangeEven(24, 32); int podHeight = random.RangeEven(12, 24); int podDistance = random.RangeEven(64, Size / 2 - 32); CreatePods(podCount, podWidth, podHeight, 8, podDistance, 1.0, Color.grey); CreatePods(podCount, podWidth, podHeight, 8, podDistance, 0.75, Color.grey); Color[] flareColors = SS_Utilities.GenerateColorWheelColors(Seed, 3); CreateFlare(Sprite, new SS_Point(Sprite.Center.x, Sprite.Center.y), 128, true, flareColors[0]); CreateFlare(Sprite, new SS_Point(Sprite.Center.x, Sprite.Center.y), 64, true, flareColors[1]); CreateFlare(Sprite, new SS_Point(Sprite.Center.x, Sprite.Center.y), 32, true, flareColors[2]); } else if (stationType == SS_StationType.Pod) { int podCount = numberOfPods; int podSize = 64; int step = 360 / podCount; int bridgeWidth = random.RangeEven(8, 16); // Setup pod positions List <SS_Point> podPositions = new List <SS_Point>(); for (int a = 0; a < 359; a += step) { int x = Sprite.Center.x + (int)(Mathf.Cos(a * Mathf.Deg2Rad) * 96); int y = Sprite.Center.y + (int)(Mathf.Sin(a * Mathf.Deg2Rad) * 96); podPositions.Add(new SS_Point(x, y)); } for (int i = 0; i < podPositions.Count; i++) { SS_Texture tmpBridgeTexture = new SS_Texture(Size, Size, Color.clear); List <SS_Point> points = new List <SS_Point>(); int px1 = podPositions[i].x + (int)(Mathf.Cos((i * step - 90) * Mathf.Deg2Rad) * bridgeWidth); int py1 = podPositions[i].y + (int)(Mathf.Sin((i * step - 90) * Mathf.Deg2Rad) * bridgeWidth); int px2 = podPositions[i].x + (int)(Mathf.Cos((i * step + 90) * Mathf.Deg2Rad) * bridgeWidth); int py2 = podPositions[i].y + (int)(Mathf.Sin((i * step + 90) * Mathf.Deg2Rad) * bridgeWidth); int cx1 = Sprite.Center.x + (int)(Mathf.Cos((i * step - 90) * Mathf.Deg2Rad) * bridgeWidth); int cy1 = Sprite.Center.y + (int)(Mathf.Sin((i * step - 90) * Mathf.Deg2Rad) * bridgeWidth); int cx2 = Sprite.Center.x + (int)(Mathf.Cos((i * step + 90) * Mathf.Deg2Rad) * bridgeWidth); int cy2 = Sprite.Center.y + (int)(Mathf.Sin((i * step + 90) * Mathf.Deg2Rad) * bridgeWidth); points.Add(new SS_Point(cx1, cy1)); points.Add(new SS_Point(px1, py1)); points.Add(new SS_Point(px2, py2)); points.Add(new SS_Point(cx2, cy2)); SS_Drawing.PolygonFill(tmpBridgeTexture, points.ToArray(), SS_StellarSprite.FillColor, SS_StellarSprite.FillColor); SS_Drawing.MergeColors(Sprite, tmpBridgeTexture, 0, 0); } int numPoints = random.RangeEven(6, 10); for (int i = 0; i < podPositions.Count; i++) { float angleStep = 360.0f / numPoints; List <SS_Point> controlPoints = new List <SS_Point>(); for (float angle = 0; angle < 360f; angle += angleStep) { int px = (int)(podPositions[i].x + (Mathf.Cos(angle * Mathf.Deg2Rad) * (podSize * 0.5))); int py = (int)(podPositions[i].y + (Mathf.Sin(angle * Mathf.Deg2Rad) * (podSize * 0.5))); controlPoints.Add(new SS_Point(px, py)); } SS_Texture tmpPodTexture = new SS_Texture(Size, Size, Color.clear); SS_Drawing.PolygonFill(tmpPodTexture, controlPoints.ToArray(), SS_StellarSprite.OutlineColor, SS_StellarSprite.FillColor); SS_Drawing.MergeColors(Sprite, tmpPodTexture, 0, 0); List <SS_Point> controlPoints2 = new List <SS_Point>(); for (float angle = 0; angle < 360f; angle += angleStep) { int px = (int)(podPositions[i].x + (Mathf.Cos(angle * Mathf.Deg2Rad) * (podSize * 0.4))); int py = (int)(podPositions[i].y + (Mathf.Sin(angle * Mathf.Deg2Rad) * (podSize * 0.4))); controlPoints2.Add(new SS_Point(px, py)); LightPoints.Add(new SS_Point(px, py)); } SS_Texture tmpPodTexture2 = new SS_Texture(Size, Size, Color.clear); SS_Drawing.PolygonFill(tmpPodTexture2, controlPoints2.ToArray(), SS_StellarSprite.OutlineColor, SS_StellarSprite.FillColor); SS_Drawing.MergeColors(Sprite, tmpPodTexture2, 0, 0); } int hubSize = random.RangeEven(64, 128); int numHubPoints = random.RangeEven(6, 10); float hubAngleSteps = 360.0f / numHubPoints; List <SS_Point> hubPoints = new List <SS_Point>(); for (float angle = 0; angle < 360f; angle += hubAngleSteps) { int px = (int)(Sprite.Center.x + (Mathf.Cos(angle * Mathf.Deg2Rad) * (hubSize * 0.5))); int py = (int)(Sprite.Center.y + (Mathf.Sin(angle * Mathf.Deg2Rad) * (hubSize * 0.5))); hubPoints.Add(new SS_Point(px, py)); } SS_Texture tmpHub = new SS_Texture(Size, Size, Color.clear); SS_Drawing.PolygonFill(tmpHub, hubPoints.ToArray(), SS_StellarSprite.OutlineColor, SS_StellarSprite.FillColor); SS_Drawing.MergeColors(Sprite, tmpHub, 0, 0); List <SS_Point> hubPoints2 = new List <SS_Point>(); for (float angle = 0; angle < 360f; angle += hubAngleSteps) { int px = (int)(Sprite.Center.x + (Mathf.Cos(angle * Mathf.Deg2Rad) * (hubSize * 0.4))); int py = (int)(Sprite.Center.y + (Mathf.Sin(angle * Mathf.Deg2Rad) * (hubSize * 0.4))); hubPoints2.Add(new SS_Point(px, py)); } SS_Texture tmpHub2 = new SS_Texture(Size, Size, Color.clear); SS_Drawing.PolygonFill(tmpHub2, hubPoints2.ToArray(), SS_StellarSprite.OutlineColor, SS_StellarSprite.FillColor); SS_Drawing.MergeColors(Sprite, tmpHub2, 0, 0); SS_Drawing.Outline(Sprite, Color.black); Texturize(Sprite, Color.magenta, tint, false, true); SS_StellarSprite.ShadeEdge(Sprite); SS_StellarSprite.Mirror(Sprite, SS_Mirror.TopRight); foreach (SS_Point p in podPositions) { CreateFlare(Sprite, p, 32, false, Color.white); } foreach (SS_Point p in LightPoints) { CreateFlare(Sprite, p, 16, true, Color.white); } CreateFlare(Sprite, Sprite.Center, hubSize, false, Color.white); } }
private void CreateBody(SS_Texture targetTexture, SS_ShipBody body, int length, int smoothCount, bool highlights) { // Temporary texture SS_Texture tmpTexture = new SS_Texture(Size, Size, Color.clear); // Determine type of body to generate if (body == SS_ShipBody.Human) { // Data points for body edge List <SS_Point> topPoints = new List <SS_Point>(); List <SS_Point> bottomPoints = new List <SS_Point>(); // Noise generator Perlin perlin = new Perlin(BodyDetail, 2, 0.5, 8, Seed, QualityMode.Medium); // Calculated step points int step = length / GetRandomBodyStep(length); for (int xCnt = 0; xCnt <= length; xCnt += step) { // Get some funky noise value float noise = (float)perlin.GetValue(xCnt, 0, 0); noise = (noise + 3.0f) * 0.25f; // Convert to 0 to 1 noise = Mathf.Clamp(noise, 0.05f, 1f); int x = Sprite.Center.x - (length / 2) + xCnt; if (x > Size - 1) { x = Size - 1; } int y = (int)(noise * (Size / 4)); topPoints.Add(new SS_Point(x, Sprite.Center.y + y)); } // Fix first and last points so they are less ugly than a random tip and butt. topPoints[0] = new SS_Point(topPoints[0].x, Sprite.Center.y + 4); topPoints[topPoints.Count - 1] = new SS_Point(topPoints[topPoints.Count - 1].x, Sprite.Center.y + 2); // Loop through all the points and smooth them out a bit for (int j = 0; j < smoothCount; j++) { for (int i = 0; i < topPoints.Count - 1; i++) { float y = (topPoints[i].y + topPoints[i + 1].y) / 2f; y = Mathf.Ceil(y); topPoints[i] = new SS_Point(topPoints[i].x, (int)y); } } // Duplicate top points to bottom points but inverse the Y position for (int i = 0; i < topPoints.Count; i++) { SS_Point p = topPoints[i]; p.y = Size - p.y - 1; bottomPoints.Add(p); } // Draw the body outline - use lines since they seem to be more symmetric (pixel placement) than my polygon drawing... not sure why. SS_Drawing.LineStrip(tmpTexture, topPoints.ToArray(), SS_StellarSprite.OutlineColor); SS_Drawing.LineStrip(tmpTexture, bottomPoints.ToArray(), SS_StellarSprite.OutlineColor); // Connect both sizes of lines SS_Drawing.Line(tmpTexture, topPoints[0].x, topPoints[0].y, topPoints[0].x, (Size - topPoints[0].y), SS_StellarSprite.OutlineColor); SS_Drawing.Line(tmpTexture, topPoints[topPoints.Count - 1].x, topPoints[topPoints.Count - 1].y, topPoints[topPoints.Count - 1].x, (Size - topPoints[topPoints.Count - 1].y), SS_StellarSprite.OutlineColor); // Fill with magenta SS_Drawing.FloodFillArea(tmpTexture, Sprite.Center, SS_StellarSprite.FillColor); // Inner detail (same shape as body, but slightly smaller) for (int i = 0; i < topPoints.Count; i++) { topPoints[i] = SS_Point.Scale(topPoints[i], Sprite.Center, 0.5f, 0.25f); } for (int i = 0; i < bottomPoints.Count; i++) { bottomPoints[i] = SS_Point.Scale(bottomPoints[i], Sprite.Center, 0.5f, 0.25f); } // Draw the body outline - use lines since they seem to be more symmetric (pixel placement) than my polygon drawing... not sure why. SS_Drawing.LineStrip(tmpTexture, topPoints.ToArray(), SS_StellarSprite.OutlineColor); SS_Drawing.LineStrip(tmpTexture, bottomPoints.ToArray(), SS_StellarSprite.OutlineColor); // Connect both sizes of lines SS_Drawing.Line(tmpTexture, topPoints[0].x, topPoints[0].y, topPoints[0].x, (Size - topPoints[0].y), SS_StellarSprite.OutlineColor); SS_Drawing.Line(tmpTexture, topPoints[topPoints.Count - 1].x, topPoints[topPoints.Count - 1].y, topPoints[topPoints.Count - 1].x, (Size - topPoints[topPoints.Count - 1].y), SS_StellarSprite.OutlineColor); // Texturize and shade if (!DebugDrawing) { Texturize(tmpTexture, SS_StellarSprite.FillColor, ColorBase, highlights, true); SS_StellarSprite.ShadeEdge(tmpTexture); } SS_Drawing.MergeColors(targetTexture, tmpTexture, 0, 0); } else if (body == SS_ShipBody.Alien) { float bodyAngleSteps = 360.0f / 32; List <SS_Point> bodyPoints = new List <SS_Point>(); for (float angle = 0; angle < 360f; angle += bodyAngleSteps) { int px = (int)((Size / 2) + (Mathf.Cos(angle * Mathf.Deg2Rad) * (BodyLength * 0.5))); int py = (int)((Size / 2) + (Mathf.Sin(angle * Mathf.Deg2Rad) * (BodyLength * 0.5))); bodyPoints.Add(new SS_Point(px, py)); } SS_Drawing.PolygonFill(tmpTexture, bodyPoints.ToArray(), SS_StellarSprite.OutlineColor, SS_StellarSprite.FillColor); if (!DebugDrawing) { Texturize(tmpTexture, SS_StellarSprite.FillColor, ColorBase, false, true); } Color ringColor = random.NextColor(); int ringMin = random.RangeEven(12, 18); int ringMax = random.RangeEven(18, 24); for (int y = 0; y < Size; y++) { for (int x = 0; x < Size; x++) { int dist = SS_Point.Distance(new SS_Point(x, y), Sprite.Center); if (dist >= ringMin && dist <= ringMax) { tmpTexture.SetPixel(x, y, tmpTexture.GetPixel(x, y) * ringColor); } } } if (random.NextBool()) { CreateFlare(tmpTexture, Sprite.Center, 48, true, random.NextColor()); } if (random.NextBool()) { CreateFlare(tmpTexture, Sprite.Center, 24, true, Color.white); } if (!DebugDrawing) { SS_StellarSprite.ShadeEdge(tmpTexture); } SS_Drawing.MergeColors(targetTexture, tmpTexture, 0, 0); } }