示例#1
0
        private void makelife() //Well do this once for the whole planet.
        {
            Random rnd = new Random(OuterSpace.thisPlanet.uSeed);

            // Adjust our biopercentage so it//s a value between 0 and 100, to make voidsequent stuff eaiser.
            int lifepercentage;

            lifepercentage = Convert.ToInt32(MathFunctions.scaleValue(OuterSpace.thisPlanet.BioDensity, 255, 0, 100, 0));

            //Temporary for debugging
            lifepercentage = 50;
            //Temporary for debugging

            bool gasplanet = false;

            if (OuterSpace.thisPlanet.PClass == "J")
            {
                gasplanet = true;
            }

            for (int x = 0; x < OuterSpace.thisPlanet.PlanetMaps.BigMapX; x++)
            {
                for (int y = 0; y < OuterSpace.thisPlanet.PlanetMaps.BigMapY; y++)
                {
                    OuterSpace.thisPlanet.lifemap[x, y] = new lifeforms(map[x, y].color, gasplanet, lifepercentage);
                    //if OuterSpace.thisPlanet.lifemap(x, y).type > 0
                    //OuterSpace.debugfile.output("X: " + Convert.ToString(x) + " Y: " + Convert.ToString(y) + " " + _
                    //Convert.ToString(map(x, y).color) + " " + OuterSpace.thisPlanet.lifemap(x, y).FetchDesc(true, false) _
                    //+ " " + OuterSpace.thisPlanet.lifemap(x, y).FetchDesc(false, true) + " " + OuterSpace.thisPlanet.lifemap(x, y).FetchDesc(false, false))
                    //} if
                }
            }
        }
示例#2
0
        private void drawStars()
        {
            int   xPos;
            int   yPos;
            Point starScreen = new Point();

            for (xPos = 0; xPos <= 250; xPos++)
            {
                for (yPos = 0; yPos <= 250; yPos++)
                {
                    if (OuterSpace.theVerse.HasStar(xPos, yPos))
                    {
                        CStar star = null;
                        OuterSpace.theVerse.GetStarAtLocation(xPos, yPos, ref star);
                        starScreen.X = (int)MathFunctions.scaleValue(xPos, 250, 0, mapArea[1].X, mapArea[0].X);
                        starScreen.Y = (int)MathFunctions.scaleValue(250 - yPos, 250, 0, mapArea[1].Y, mapArea[0].Y);
                        // Invert the yPos cause the screen corrdinates are top 0, bottom max.
                        OuterSpace.backstars.Draw(starScreen.X, starScreen.Y, OuterSpace.backstars.sourceFrame[OuterSpace.theVerse.GetTempType(star.SpectralClass)], 0,
                                                  Color.FromArgb(100 + (int)(rnd.NextDouble() * 150) + 1, 255, 255, 255));
                    }
                }
            }

            starScreen.X = (int)MathFunctions.scaleValue(OuterSpace.XCor, 250, 0, mapArea[1].X, mapArea[0].X);
            starScreen.Y = (int)MathFunctions.scaleValue(250 - OuterSpace.YCor, 250, 0, mapArea[1].Y, mapArea[0].Y);

            OuterSpace.smallship.Draw(starScreen.X - 8, starScreen.Y - 5, OuterSpace.smallship.sourceFrame[0],
                                      OuterSpace.playership.theta, Color.FromArgb(90, 255, 255, 255));
        }
示例#3
0
        private void drawmouse_onmap()
        {
            int mouseframe = 0;

            if (mousexpos < 654 & mousexpos > 122)
            {
                if (mouseypos > 148 & mouseypos < 416)
                {
                    if (!OuterSpace.mnu.showmenu)
                    {
                        OuterSpace.textfont.DrawText(100, 100, Color.White, "Latitude: " + Convert.ToString((int)MathFunctions.scaleValue(mouseypos, 416, 148, OuterSpace.thisPlanet.PlanetMaps.BigMapY / 2, -OuterSpace.thisPlanet.PlanetMaps.BigMapY / 2)));
                        OuterSpace.textfont.DrawText(100, 120, Color.White, "Longitude: " + Convert.ToString(-(int)MathFunctions.scaleValue(mousexpos, 654, 122, OuterSpace.thisPlanet.PlanetMaps.BigMapX / 2, -OuterSpace.thisPlanet.PlanetMaps.BigMapX / 2)));
                        OuterSpace.textfont.DrawText(100, 140, Color.White, "MouseX: " + Convert.ToString(mousexpos));
                        OuterSpace.textfont.DrawText(100, 160, Color.White, "MouseY: " + Convert.ToString(mouseypos));

                        // Set up to land at specified coordinates.
                        if (CheckButton("Left", true))
                        {
                            // Once the user clicks..
                            // Scale the mouse pointer position to a relative Terrian Vehicle position.
                            // 654, 122, 416 and 148 represent the dimensions of the map displayed on the screen.
                            OuterSpace.TV.X = -(int)MathFunctions.scaleValue(mousexpos, 654, 122, OuterSpace.thisPlanet.PlanetMaps.BigMapX / 2, -OuterSpace.thisPlanet.PlanetMaps.BigMapX / 2);
                            // Invert the passed in Y value, because DirectX 3d vectors has +Y going up, and 2D screen vectors have +Y going DOWN.
                            OuterSpace.TV.Y = (int)MathFunctions.scaleValue(mouseypos, 416, 148, OuterSpace.thisPlanet.PlanetMaps.BigMapY / 2, -OuterSpace.thisPlanet.PlanetMaps.BigMapY / 2);

                            // Assign the ship's position to a spot that matches our object map dimensions
                            OuterSpace.playership.X = OuterSpace.TV.X + 3.0F;
                            OuterSpace.playership.Y = OuterSpace.TV.Y + 3.0F;

                            // Pass our selected corrdinates into scan new terrian, forcing it to load.
                            OuterSpace.TV.updateterrian((int)OuterSpace.TV.X, (int)OuterSpace.TV.Y, true, true);

                            //Set the ships position in planetside world

                            OuterSpace.theGameState.AddState(OuterSpace.GameStates.Landed);
                            OuterSpace.mnu.items[49] = "Launch";
                        }
                    }

                    if (rnd.NextDouble() < 0.5f)
                    {
                        mouseframe = 2;
                    }
                    else
                    {
                        mouseframe = 1;
                    }
                }
            }

            OuterSpace.pointer.Draw(mousexpos, mouseypos, OuterSpace.pointer.sourceFrame[mouseframe], 0, Color.White);
        }
示例#4
0
        private void handleMouse()
        {
            Point pointingAt   = new Point();
            Point resizeCenter = new Point();
            Point newMapArea   = new Point();

            resizeCenter.Y = (int)mapArea[1].Y + resizeButton.sourceFrame[0].Height / 2;
            resizeCenter.X = (int)mapArea[0].X + resizeButton.sourceFrame[0].Width / 2;

            if (OuterSpace.userinput.mousexpos > mapArea[0].X & OuterSpace.userinput.mouseypos < mapArea[1].Y)
            {
                pointingAt.X = (int)MathFunctions.scaleValue(OuterSpace.userinput.mousexpos, mapArea[1].X, mapArea[0].X, 250, 0);
                pointingAt.Y = (int)MathFunctions.scaleValue(mapArea[1].Y - OuterSpace.userinput.mouseypos, mapArea[1].Y, mapArea[0].Y, 250, 0);
                OuterSpace.textfont.DrawText(OuterSpace.userinput.mousexpos - 60, OuterSpace.userinput.mouseypos - 8, Color.LimeGreen, "X:" + pointingAt.X.ToString("0.0"));
                OuterSpace.textfont.DrawText(OuterSpace.userinput.mousexpos - 60, OuterSpace.userinput.mouseypos + 8, Color.LimeGreen, "Y:" + pointingAt.Y.ToString("0.0"));
            }

            pointingAt.X = OuterSpace.userinput.mousexpos;
            pointingAt.Y = OuterSpace.userinput.mouseypos;

            if (MathFunctions.findDistance(resizeCenter, pointingAt) > resizeButton.sourceFrame[0].Width / 2)
            {
                resizeButtonColor = Color.FromArgb(75, 255, 255, 255);
            }
            else
            {
                resizeButtonColor = Color.White;
                if (OuterSpace.userinput.CheckButton("Left", false))
                {
                    resizing = true;
                }
            }

            if (resizing)
            {
                if (OuterSpace.userinput.CheckButton("Left", false))
                {
                    newMapArea.X = mapArea[0].X + OuterSpace.userinput.mousexpos - resizeCenter.X;
                    newMapArea.Y = mapArea[1].Y + OuterSpace.userinput.mouseypos - resizeCenter.Y;
                    resizeMap(newMapArea);
                    return;
                }
                else
                {
                    resizing = false;
                }
            }
        }
示例#5
0
        public void getColors() //A broken texture mapping method. It's documentation, I have on my haddrive.
        {
            for (int i = 0; i < maxtriangles; i++)
            {
                triangles[i].A.texcor = (float)((Math.Asin(normalize(triangles[i].A).X) / Math.PI + 0.5) * 4) - (int)((Math.Asin(normalize(triangles[i].A).X) / Math.PI + 0.5) * 4);
                triangles[i].B.texcor = (float)((Math.Asin(normalize(triangles[i].B).X) / Math.PI + 0.5) * 4) - (int)((Math.Asin(normalize(triangles[i].B).X) / Math.PI + 0.5) * 4);
                triangles[i].C.texcor = (float)((Math.Asin(normalize(triangles[i].C).X) / Math.PI + 0.5) * 4) - (int)((Math.Asin(normalize(triangles[i].C).X) / Math.PI + 0.5) * 4);

                triangles[i].A.color = MathFunctions.scaleValue(triangles[i].A.elevation, maxElev, minElev, 1, 0);
                triangles[i].B.color = MathFunctions.scaleValue(triangles[i].B.elevation, maxElev, minElev, 1, 0);
                triangles[i].C.color = MathFunctions.scaleValue(triangles[i].C.elevation, maxElev, minElev, 1, 0);

                triangles[i].A.normal = (new Vector3(triangles[i].A.X / triangles[i].A.elevation,
                                                     triangles[i].A.Y / triangles[i].A.elevation,
                                                     triangles[i].A.Z / triangles[i].A.elevation));
                triangles[i].B.normal = (new Vector3(triangles[i].B.X / triangles[i].B.elevation,
                                                     triangles[i].B.Y / triangles[i].B.elevation,
                                                     triangles[i].B.Z / triangles[i].B.elevation));
                triangles[i].C.normal = (new Vector3(triangles[i].C.X / triangles[i].C.elevation,
                                                     triangles[i].C.Y / triangles[i].C.elevation,
                                                     triangles[i].C.Z / triangles[i].C.elevation));
            }
        }
示例#6
0
        private void maperize(int Maxtraingles)
        {
            Single sumcount;
            Single cellsum;

            //int lastnotnull;
            vertex_structure[] allpoints = new vertex_structure[61440];
            int i, iY, iX;
            int tX;
            int ty;
            int txmid;
            int tymid;
            int txmidc;
            int tymidc;
            int deresoluter = 4; // Factor that we want to deresolute the master map by to get the mini-map.
            /////// Initialize the arrays
            int mapsizex = 140 * deresoluter - 1;
            int mapsizey = 70 * deresoluter - 1;

            Single maxXvert = 70.71051F;
            Single maxYvert = 35.35536F;

            for (i = 0; i < 61439; i++)
            {
                allpoints[i].color = 0.0F;
            }

            for (iY = 0; iY < mapsizey; iY++)
            {
                for (iX = 0; iX < mapsizex; iX++)
                {
                    map[iX, iY].color     = 0.0F;
                    map[iX, iY].elevation = 0; //Well use the elevation member of the vertex_structure as a counter,
                    // count the number of vertecies that have been added to this array element.
                }
            }

            iX = 0;

            // Stuff all vertcies into a one dimensional array
            for (i = 0; i < maxtriangles; i++)
            {
                allpoints[iX]     = triangles[i].A;
                allpoints[iX + 1] = triangles[i].B;
                allpoints[iX + 2] = triangles[i].C;
                iX = iX + 3;
            }

            // Figure out the position of the current verticie on our map, and pop it//s elevation into that index.
            // Summing for each vertex popped into each element of the map array and using a counter to count how many
            // we've popped in there. Later well average the elevation of the midpoint by dividing by that counter.
            // First for/} loop, do all points of each triangle.
            // Second for/} Loop, do all the midpoints on each triangle.
            for (i = 0; i < (maxtriangles * 3); i++)
            {
                ///// //Scaled from 0 to 1 and multiplied by the appropriate dimension of the map array, and take Convert.ToInt32
                tX = Convert.ToInt32(MathFunctions.scaleValue(allpoints[i].X, maxXvert, -maxXvert, 1.0F, 0.0F) * mapsizex);
                ty = Convert.ToInt32(MathFunctions.scaleValue(allpoints[i].Y, maxYvert, -maxYvert, 1.0F, 0.0F) * mapsizey);
                ///// sum the total value in each position.
                map[tX, ty].color = map[tX, ty].color + allpoints[i].color;
                ///// number of verticies that are in this element.
                map[tX, ty].elevation = map[tX, ty].elevation + 1;
            }

            for (i = 0; i < (maxtriangles * 3); i += 3)
            {
                ///// //Scaled from 0 to 1 and multiplied by the appropriate dimension of the map array, and take Convert.ToInt32
                tX     = Convert.ToInt32(MathFunctions.scaleValue((allpoints[i].X + allpoints[i + 1].X) / 2, maxXvert, -maxXvert, 1, 0) * mapsizex);
                ty     = Convert.ToInt32(MathFunctions.scaleValue((allpoints[i].Y + allpoints[i + 1].Y) / 2, maxYvert, -maxYvert, 1, 0) * mapsizey);
                txmid  = Convert.ToInt32(MathFunctions.scaleValue((allpoints[i + 1].X + allpoints[i + 2].X) / 2, maxXvert, -maxXvert, 1, 0) * mapsizex);
                tymid  = Convert.ToInt32(MathFunctions.scaleValue((allpoints[i + 1].Y + allpoints[i + 2].Y) / 2, maxYvert, -maxYvert, 1, 0) * mapsizey);
                txmidc = Convert.ToInt32(MathFunctions.scaleValue((allpoints[i].X + allpoints[i + 2].X) / 2, maxXvert, -maxXvert, 1, 0) * mapsizex);
                tymidc = Convert.ToInt32(MathFunctions.scaleValue((allpoints[i].Y + allpoints[i + 2].Y) / 2, maxYvert, -maxYvert, 1, 0) * mapsizey);

                ///// sum the total value in each position.
                map[tX, ty].color         = map[tX, ty].color + (allpoints[i].color + allpoints[i + 1].color) / 2;
                map[txmid, tymid].color   = map[txmid, tymid].color + (allpoints[i + 1].color + allpoints[i + 2].color) / 2;
                map[txmidc, tymidc].color = map[txmidc, tymidc].color + (allpoints[i].color + allpoints[i + 2].color) / 2;
                ///// number of verticies that are in this element.
                map[tX, ty].elevation         = map[tX, ty].elevation + 1;
                map[txmid, tymid].elevation   = map[txmid, tymid].elevation + 1;
                map[txmidc, tymidc].elevation = map[txmidc, tymidc].elevation + 1;
            }

            ////// Center the map and figure out the color of each elevation point.
            for (iY = 0; iY < mapsizey; iY++)
            {
                for (iX = 0; iX < mapsizex; iX++)
                {
                    ////centering
                    map[iX, iY].X = iX - mapsizex / 2;
                    map[iX, iY].Y = iY - mapsizey / 2;
                    map[iX, iY].Z = 0.0F;

                    if (map[iX, iY].color > 0.0)
                    {
                        // if more  one vertex has been stuffed into this element, average them.
                        map[iX, iY].color = map[iX, iY].color / map[iX, iY].elevation;
                    }
                }
            }

            ///// Fill in all the empty cells (in the middle of two filled cells) with the average of the adjacent filled cells.
            ///// Fill in the blanks basically.

            int left, right;

            for (iY = 0; iY < mapsizey; iY++)
            {
                iX = 1;

                while (iX < mapsizex + 1)
                {
                    cellsum  = 0.0F;
                    sumcount = 0.0F;

                    if (map[iX, iY].color == 0.0)
                    {
                        left  = iX;
                        right = iX;

                        // move to the right until we reach a filled cell or the "edge"
                        do
                        {
                            right++;
                        }while (map[right + 1, iY].color == 0.0 || right != mapsizex);

                        // move to the left....
                        do
                        {
                            left--;
                        } while (map[left - 1, iY].color == 0.0 || left != 1);

                        // put the filled cell into the total, sum count.
                        if (left > 0 && map[left - 1, iY].color != 0.0)
                        {
                            cellsum  = cellsum + map[left - 1, iY].color; //Sum up the elevation.
                            sumcount = sumcount + 1.0F;                   //Add 1 to the number of filled cells in this loop pass.
                        }

                        // put the filled cell into the total, sum count.
                        if (right < mapsizex + 1 && map[right + 1, iY].color != 0.0)
                        {
                            cellsum  = cellsum + map[right + 1, iY].color;
                            sumcount = sumcount + 1.0F;
                        }

                        cellsum = cellsum / sumcount;

                        // fill in the empty cells.
                        if (left == 1)
                        {
                            left = 0;
                        }

                        for (i = left; i < right; i++)
                        {
                            map[i, iY].color = cellsum;
                        }

                        cellsum  = 0.0F;
                        sumcount = 0;
                    }
                    iX++;
                }
            }

            ////////////
            Single texcor = 0.0F;
            int    flipper = 1;

            // To re-cycle through the texture map backwards once we reach the }.
            // Changes our dirrection.
            Random rnd = new Random(OuterSpace.thisPlanet.uSeed);

            for (iX = 0; iX < mapsizex; iX++)
            {
                texcor = (float)texcor + 0.01F * flipper + (float)rnd.NextDouble() / 200F;
                for (iY = 0; iY < mapsizey; iY++)
                {
                    map[iX, iY].texcor = texcor;
                    if (texcor > 1)
                    {
                        map[iX, iY].texcor = 1;
                        texcor             = 0;
                        flipper            = flipper * -1;
                    }
                }
            }

            i = 0;
            for (iY = 0; iY < mapsizey; iY += deresoluter)
            {
                for (iX = 0; iX < mapsizex + 1; iX += deresoluter)
                {
                    // Use the points organized in a deresoluter dimensional array to make a list of quads.
                    triangles[i].A     = map[iX, iY + deresoluter];
                    triangles[i].B     = map[iX, iY];
                    triangles[i].C     = map[iX + deresoluter, iY + deresoluter];
                    triangles[i + 1].A = map[iX, iY];
                    triangles[i + 1].B = map[iX + deresoluter, iY];
                    triangles[i + 1].C = map[iX + deresoluter, iY + deresoluter];
                    i += 2;
                }
            }
            maxtriangles = i;

            for (i = 0; i < maxtriangles; i++)
            {
                triangles[i].A.normal = new Vector3(0.0F, 0.0F, -1.0F);
                triangles[i].B.normal = new Vector3(0.0F, 0.0F, -1.0F);
                triangles[i].C.normal = new Vector3(0.0F, 0.0F, -1.0F);
            }

            OuterSpace.thisPlanet.PlanetMaps = new PlanetMap(mapsizex, mapsizey);

            //3-10-06 ...

            // Resize our life and mineral maps to represent the size of our terrian map,
            // and make the life and minerals.

            OuterSpace.thisPlanet.mineralmap = null;
            OuterSpace.thisPlanet.mineralmap = new bool[mapsizex, mapsizey];
            if (OuterSpace.thisPlanet.MinDensity > 0)
            {
                makeminerals();
            }

            //Redim OuterSpace.thisPlanet.lifemap[mapsizex, mapsizey];
            OuterSpace.thisPlanet.lifemap = null;
            OuterSpace.thisPlanet.lifemap = new lifeforms[mapsizex, mapsizey];

            makelife();
        }
示例#7
0
        private void drawScaleLines()
        {
            int x;
            int x1;
            int y;
            int y1;

            //Draw the scale lines.
            //Verticle first, then horizontal.
            aLine.Width       = 1;
            aLineVectors[0].X = mapArea[0].X;
            aLineVectors[0].Y = mapArea[0].Y;
            aLineVectors[1].Y = mapArea[1].Y;
            aLineVectors[1].X = mapArea[0].X;
            aLine.Draw(aLineVectors, Color.White);

            aLineVectors[0].Y = mapArea[1].Y;
            aLineVectors[1].X = mapArea[1].X;
            aLine.Draw(aLineVectors, Color.White);

            // Draw the horozontal hash marks
            for (y = 0; y <= 249; y += 50)
            {
                aLineVectors[0].X = mapArea[0].X;
                aLineVectors[0].Y = MathFunctions.scaleValue(y, 250, 0, mapArea[1].Y, mapArea[0].Y);
                aLineVectors[1].Y = aLineVectors[0].Y;
                aLineVectors[1].X = mapArea[0].X + 20;
                aLine.Draw(aLineVectors, Color.Red);

                // Biggers ones every 50
                for (y1 = 0; y1 <= 50; y1 += 10)
                {
                    aLineVectors[0].X = mapArea[0].X;
                    aLineVectors[0].Y = MathFunctions.scaleValue(y + y1, 250, 0, mapArea[1].Y, mapArea[0].Y);
                    aLineVectors[1].Y = aLineVectors[0].Y;
                    aLineVectors[1].X = mapArea[0].X + 9;
                    aLine.Draw(aLineVectors, Color.White);
                    //Smaller ones every 10
                }
            }

            // Draw the verticle hash marks
            for (x = 0; x <= 249; x += 50)
            {
                aLineVectors[0].Y = mapArea[1].Y;
                aLineVectors[0].X = MathFunctions.scaleValue(x, 250, 0, mapArea[1].X, mapArea[0].X);
                aLineVectors[1].Y = mapArea[1].Y - 20;
                aLineVectors[1].X = aLineVectors[0].X;
                aLine.Draw(aLineVectors, Color.Red);

                for (x1 = 0; x1 <= 50; x1 += 10)
                {
                    aLineVectors[0].Y = mapArea[1].Y;
                    aLineVectors[0].X = MathFunctions.scaleValue(x + x1, 250, 0, mapArea[1].X, mapArea[0].X);
                    aLineVectors[1].Y = mapArea[1].Y - 9;
                    aLineVectors[1].X = aLineVectors[0].X;
                    aLine.Draw(aLineVectors, Color.White);
                }
            }

            resizeButton.Draw(mapArea[0].X, mapArea[1].Y, resizeButton.sourceFrame[0], 0, resizeButtonColor);
        }