Example #1
0
        public SS_Ship(int seed, SS_ShipType shipType, float bodyDetail, int bodyLength, float wingDetail, Color[] colors, float colorDetail)
        {
            Seed = seed;

            ColorBase      = colors[0];
            ColorHighlight = colors[1];
            ColorEngine    = colors[2];

            BodyDetail  = bodyDetail;
            BodyLength  = bodyLength;
            WingDetail  = wingDetail;
            ColorDetail = colorDetail;

            Sprite = new SS_Texture(Size, Size, Color.clear);

            random = new SS_Random(Seed);

            // generate ship based on type
            if (shipType == SS_ShipType.Fighter)
            {
                CreateWing(Sprite, Color.grey, random.NextBool());
                CreateBody(Sprite, SS_ShipBody.Human, bodyLength, random.Range(0, 4), random.NextBool());
                CreateEngine(Sprite, random.Range(1, 6));
                CreateTank(Sprite, random.Range(1, 6), Color.grey, random.NextBool());
                CreateWing(Sprite, Color.grey, random.NextBool());
                CreateCockpit(Sprite, Color.cyan);
            }
            else if (shipType == SS_ShipType.Fighter2)
            {
                CreateWing(Sprite, Color.grey, random.NextBool());
                CreateWing(Sprite, Color.grey, random.NextBool());
                CreateBody(Sprite, SS_ShipBody.Human, bodyLength, random.Range(0, 4), random.NextBool());
                CreateEngine(Sprite, random.Range(1, 4));
                CreateTank(Sprite, random.Range(1, 4), Color.grey, random.NextBool());
                CreateWing(Sprite, Color.grey, random.NextBool());
                CreateWing(Sprite, Color.grey, random.NextBool());
                CreateCockpit(Sprite, Color.cyan);
            }
            else if (shipType == SS_ShipType.Hauler)
            {
                CreateBody(Sprite, SS_ShipBody.Human, bodyLength, random.Range(0, 4), random.NextBool());
                CreateEngine(Sprite, random.Range(1, 4));
                CreateTank(Sprite, 2, Color.grey, random.NextBool());
                CreateCockpit(Sprite, Color.cyan);
            }
            else if (shipType == SS_ShipType.Saucer)
            {
                BodyLength = 48;

                //CreateWing(Sprite, Color.grey, random.NextBool());
                CreateBody(Sprite, SS_ShipBody.Alien, bodyLength, random.Range(0, 4), random.NextBool());
                //CreateTank(Sprite, 1, Color.grey, random.NextBool());
                //CreateWing(Sprite, Color.grey, random.NextBool());
            }
        }
Example #2
0
        void CreateRing(float scale, int sectionsPerQuarter, bool details, Color detailColor, bool lights)
        {
            //  Only draws top right quarter, the rest is mirrored
            List <SS_Point> DetailPoints = new List <SS_Point>();

            SS_Texture tmpTexture = new SS_Texture(Size, Size, Color.clear);

            int innerRadius = (int)((Size / 8) * scale);
            int outerRadius = (int)(((Size / 2) - 4) * scale);

            List <SS_Point> innerPoints = new List <SS_Point>();
            List <SS_Point> outerPoints = new List <SS_Point>();

            int step = 90 / sectionsPerQuarter;

            for (int a = 0; a <= 90; a += step)
            {
                int innerX = Sprite.Center.x + (int)(Mathf.Cos(a * Mathf.Deg2Rad) * innerRadius);
                int innerY = Sprite.Center.y + (int)(Mathf.Sin(a * Mathf.Deg2Rad) * innerRadius);

                innerPoints.Add(new SS_Point(innerX, innerY));

                int outerX = Sprite.Center.x + (int)(Mathf.Cos(a * Mathf.Deg2Rad) * outerRadius);
                int outerY = Sprite.Center.y + (int)(Mathf.Sin(a * Mathf.Deg2Rad) * outerRadius);

                outerPoints.Add(new SS_Point(outerX, outerY));

                if (lights)
                {
                    LightPoints.Add(new SS_Point(outerX, outerY));
                    LightPoints.Add(new SS_Point(Size - outerX, outerY));
                    LightPoints.Add(new SS_Point(Size - outerX, Size - outerY));
                    LightPoints.Add(new SS_Point(outerX, Size - outerY));
                }
            }

            // Determine centroids (detail points) for each ring section
            for (int i = 0; i < innerPoints.Count - 1; i++)
            {
                SS_Point[] points = new SS_Point[4];

                int j  = i;
                int j2 = i + 1;
                if (i == innerPoints.Count - 1)
                {
                    j2 = 0;
                }

                points[0] = innerPoints[j];
                points[1] = outerPoints[j];
                points[2] = outerPoints[j2];
                points[3] = innerPoints[j2];

                SS_Point centroid = SS_Utilities.Centroid(points);

                if (random.NextBool())
                {
                    DetailPoints.Add(centroid);
                }
            }

            List <SS_Point> ringPoints = new List <SS_Point>();

            for (int i = 0; i < innerPoints.Count; i++)
            {
                ringPoints.Add(innerPoints[i]);
            }

            for (int i = outerPoints.Count - 1; i >= 0; i--)
            {
                ringPoints.Add(outerPoints[i]);
            }

            SS_Drawing.PolygonFill(tmpTexture, ringPoints.ToArray(), SS_StellarSprite.OutlineColor, SS_StellarSprite.FillColor);

            // Add borders between sectons
            float colorVal      = 0;// random.Range(0.25f, 1f);
            Color sectionBorder = new Color(colorVal, colorVal, colorVal);

            for (int i = 0; i < innerPoints.Count; i++)
            {
                SS_Drawing.Line(tmpTexture, innerPoints[i].x, innerPoints[i].y, outerPoints[i].x, outerPoints[i].y, sectionBorder);
            }

            if (details)
            {
                for (int i = 0; i < DetailPoints.Count; i++)
                {
                    SS_Drawing.EllipseFill(tmpTexture, DetailPoints[i].x, DetailPoints[i].y, 8, 8, 12, SS_StellarSprite.OutlineColor, detailColor);
                }
            }

            // Texture the section
            Texturize(tmpTexture, SS_StellarSprite.FillColor, Color.grey, false, true);

            SS_StellarSprite.ShadeEdge(tmpTexture);
            SS_StellarSprite.Mirror(tmpTexture, SS_Mirror.TopRight);

            SS_Drawing.MergeColors(Sprite, tmpTexture, 0, 0);
        }
Example #3
0
        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);
            }
        }