コード例 #1
0
ファイル: ParticleSmoke.cs プロジェクト: ngaspar/PlanetsXNA
 public void updateSmokeParticles(NoiseGenerator noise, float newX, float newY)
 {
     for (int i = 0; i < smoke.Length; i++)
     {
         if (smoke[i] != null)
         {
             if (smoke[i].currentAlpha > smoke[i].minAlpha)
             {
                 smoke[i].currentAlpha -= 0.01f;
                 smoke[i].x += smoke[i].moveX;
                 smoke[i].y += smoke[i].moveY;
                 smoke[i].angle += smoke[i].rotation;
                 if (smoke[i].expanding)
                 {
                     if (smoke[i].currentSize < smoke[i].maxSize)
                     {
                         smoke[i].currentSize ++;
                     }
                 }
                 else if (smoke[i].currentSize > smoke[i].minSize)
                 {
                     smoke[i].currentSize --;
                 }
             }
             else if (smoke[i].looping)
             {
                 float alpha = maxAlpha - (float)noise.random.NextDouble();
                 smoke[i] = new Particle(newX + noise.random.Next(-2, 3), newY + noise.random.Next(-2, 3), 0, 0, (float)(maxSize - i), 1f, maxSize, (alpha / ((float)i + 1)), 0f, 0f, (float)(noise.random.Next(-1, 2) * 0.1f), true, false, true);
             }
         }
     }
 }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: ngaspar/Planets
        public MainForm()
        {
            InitializeComponent();
            this.BringToFront();

            seed = (int)System.DateTime.Now.Ticks;
            noise = new NoiseGenerator(seed);

            this.Top = 0;
            this.Left = 0;
            this.Width = Screen.PrimaryScreen.Bounds.Width;
            this.Height = Screen.PrimaryScreen.Bounds.Height;

            popups = new List<Popup>();

            gfx = new GFXEngine(this, this.Width, this.Height);
            gfx.totalAreaWidth = STARSYSTEM_SIZE * STARSYSTEM_SCALE;
            gfx.totalAreaHeight = STARSYSTEM_SIZE * STARSYSTEM_SCALE;
            gfx.generateBackground(noise);
            gfx.drawWindows = true;

            player = new Player();
            player.currentPlanet = 0;
            player.currentStarSystem = 0;

            inputTimer = new System.Windows.Forms.Timer();
            inputTimer.Interval = 50;
            inputTimer.Tick += new EventHandler(processKeys);
            inputTimer.Start();

            loadStuff();
        }
コード例 #3
0
ファイル: testForm.cs プロジェクト: ngaspar/Planets
        public testForm()
        {
            InitializeComponent();

            noise = new NoiseGenerator((int)DateTime.Now.Ticks);

            planetGfx = panel1.CreateGraphics();
            surfaceGfx = panel2.CreateGraphics();

            imageAttributes = new ImageAttributes();
            imageAttributes.SetColorKey(Color.FromArgb(255, 0, 255), Color.FromArgb(255, 0, 255));
        }
コード例 #4
0
ファイル: ParticleSmoke.cs プロジェクト: ngaspar/PlanetsXNA
        public void newSmokeParticles(NoiseGenerator noise, float newX, float newY, int number, float maxSize, float maxAlpha)
        {
            this.maxSize = maxSize;
            this.maxAlpha = maxAlpha;

            smoke = new Particle[number];
            for (int i = 0; i < number; i++)
            {
                float alpha = maxAlpha - (float)noise.random.NextDouble();
                smoke[i] = new Particle(newX + noise.random.Next(-2, 3), newY + noise.random.Next(-2, 3), 0, 0, (float)(maxSize - i), 1f, maxSize, (alpha / ((float)i + 1)), 0f, 0f, (float)(noise.random.Next(-1, 2) * 0.1f), true, false, true);
            }
        }
コード例 #5
0
ファイル: GFXEngine.cs プロジェクト: ngaspar/Planets
 public void generateBackground(NoiseGenerator noise)
 {
     background2 = new Bitmap(viewAreaWidth * 2, viewAreaHeight * 2);
     Graphics g = Graphics.FromImage(background2);
     g.Clear(Color.Black);
     int stars = noise.random.Next(100, 201);
     for (int i = 0; i < stars; i++)
     {
         int rgb = noise.random.Next(50, 251);
         int size = noise.random.Next(3, 7);
         g.FillEllipse(new SolidBrush(Color.FromArgb(rgb, rgb, rgb)), noise.random.Next(0, viewAreaWidth * 2), noise.random.Next(0, viewAreaHeight * 2), size, size);
     }
 }
コード例 #6
0
ファイル: Planet.cs プロジェクト: ngaspar/PlanetsXNA
        public void generate(NoiseGenerator noise, GraphicsDevice device, int seed)
        {
            radius = 100;
            int scale = noise.random.Next(1, 5);
            width = (radius * 2) / scale;
            height = (radius * 2) / scale;

            planetRadius = (float)((noise.random.NextDouble() * 100000) / scale);

            mass = (float)(noise.random.NextDouble() * 20);
            massRadix = noise.random.Next(24, 70) / scale;

            minTemp = noise.random.Next(-80, 20);
            maxTemp = noise.random.Next(minTemp, minTemp + 80);

            orgRes = noise.random.Next(0, 11);
            indRes = noise.random.Next(0, 11);
            atmosphere = noise.random.Next(0, 11);

            technology = atmosphere > 5 ? noise.random.Next(0, 6) : 0;

            frequency = ((noise.random.NextDouble() * 0.1));
            persistence = ((noise.random.NextDouble() * 1.0) + 0.5) / 2;
            octaves = ((noise.random.NextDouble() * 16) + 4) / 2;
            amplitude = ((noise.random.NextDouble() * 1.1) + 1) / 2;

            heightMap = noise.generateHeightMap(radius * 4, radius * 4, frequency, persistence, octaves, amplitude);

            r1 = (float)(noise.random.NextDouble() * 0.2) + 0.2f;
            g1 = (float)(noise.random.NextDouble() * 0.2) + 0.2f;
            b1 = (float)(noise.random.NextDouble() * 0.2) + 0.2f;

            r2 = (float)(noise.random.NextDouble() * 0.2) + r1;
            g2 = (float)(noise.random.NextDouble() * 0.2) + g1;
            b2 = (float)(noise.random.NextDouble() * 0.2) + b1;

            r3 = (float)(noise.random.NextDouble() * 0.2) + r2;
            g3 = (float)(noise.random.NextDouble() * 0.2) + g2;
            b3 = (float)(noise.random.NextDouble() * 0.2) + b2;

            r4 = (float)(noise.random.NextDouble() * 0.2) + r3;
            g4 = (float)(noise.random.NextDouble() * 0.2) + g3;
            b4 = (float)(noise.random.NextDouble() * 0.2) + b3;

            r5 = (float)(noise.random.NextDouble() * 0.2) + r4;
            g5 = (float)(noise.random.NextDouble() * 0.2) + g4;
            b5 = (float)(noise.random.NextDouble() * 0.2) + b4;

            surface = new Texture2D(device, radius * 4, radius * 4);

            maxHeight = 0;

            circle = new Texture2D(device, radius * 2 + 1, radius * 2 + 1);

            //now draw the circle, same as the surface texture
            Color[] noisyColors = new Color[circle.Width * circle.Height];
            Vector3 rgb = new Vector3();
            int[] center = new int[2];
            int[] point = new int[2];
            center[0] = radius;
            center[1] = radius;
            for (int i = 0; i < radius; i++)
            {
                for (float angle = 0; angle < 360; angle += 0.27f)
                {
                    if (i == radius - 1)
                    {
                        point = noise.getCircleCoordinate(center, i - 1, angle);
                        noisyColors[(point[0] / scale) + (point[1] / scale) * circle.Width] = new Color(new Vector3(0.10f, 0.10f, 0.10f));
                        point = noise.getCircleCoordinate(center, i, angle);
                        noisyColors[(point[0] / scale) + (point[1] / scale) * circle.Width] = new Color(new Vector3(0.05f, 0.05f, 0.05f));
                        point = noise.getCircleCoordinate(center, i + 1, angle);
                        noisyColors[(point[0] / scale) + (point[1] / scale) * circle.Width] = new Color(new Vector3(0.025f, 0.025f, 0.025f));
                    }
                    else
                    {
                        point = noise.getCircleCoordinate(center, i, angle);
                        rgb = getColorFromHeight(heightMap[point[0], point[1]]);
                        noisyColors[(point[0] / scale) + (point[1] / scale) * circle.Width] = new Color(new Vector3((rgb.X - (float)(i * 0.005) > 0 ? rgb.X - (float)(i * 0.005) : 0), (rgb.Y - (float)(i * 0.005) > 0 ? rgb.Y - (float)(i * 0.005) : 0), (rgb.Z - (float)(i * 0.005) > 0 ? rgb.Z - (float)(i * 0.005) : 0)));
                    }
                }
            }

            circle = new Texture2D(device, circle.Width, circle.Height, false, SurfaceFormat.Color);
            circle.SetData(noisyColors);
        }
コード例 #7
0
ファイル: Main.cs プロジェクト: ngaspar/PlanetsXNA
        protected override void Initialize()
        {
            graphics.PreferredBackBufferWidth = resX; // GraphicsDevice.DisplayMode.Width;
            graphics.PreferredBackBufferHeight = resY; // GraphicsDevice.DisplayMode.Height;
            graphics.IsFullScreen = fullscreen;
            graphics.ApplyChanges();
            Window.Title = "Planets";

            seed = (int)DateTime.Now.Ticks;
            noise = new NoiseGenerator(seed);

            quadrantWidth = 3000;
            quadrantHeight = 3000;

            //totalPlanets = noise.random.Next(10, 21);
            //totalShips = 1000;

            loader = new Loader(this);

            base.Initialize();
        }
コード例 #8
0
ファイル: Planet.cs プロジェクト: ngaspar/Planets
        public void generate(NoiseGenerator noise, int seed)
        {
            radius = 100;
            int scale = noise.random.Next(1, 5);
            width = (radius * 2) / scale;
            height = (radius * 2) / scale;

            planetRadius = (float)((noise.random.NextDouble() * 100000) / scale);

            mass = (float)(noise.random.NextDouble() * 20);
            massRadix = noise.random.Next(24, 70) / scale;

            minTemp = noise.random.Next(-80, 20);
            maxTemp = noise.random.Next(minTemp, minTemp + 80);

            orgRes = noise.random.Next(0, 11);
            indRes = noise.random.Next(0, 11);
            atmosphere = noise.random.Next(0, 11);

            technology = atmosphere > 5 ? noise.random.Next(0, 6) : 0;

            frequency = ((noise.random.NextDouble() * 0.1));
            persistence = ((noise.random.NextDouble() * 1.0) + 0.5) / 2;
            octaves = ((noise.random.NextDouble() * 16) + 4) / 2;
            amplitude = ((noise.random.NextDouble() * 1.1) + 1) / 2;

            heightMap = noise.generateHeightMap(radius * 4, radius * 4, frequency, persistence, octaves, amplitude);

            r1 = noise.random.Next(25, 100);
            g1 = noise.random.Next(25, 100);
            b1 = noise.random.Next(25, 100);

            r2 = noise.random.Next(r1, r1 + 25);
            g2 = noise.random.Next(g1, g1 + 25);
            b2 = noise.random.Next(g1, g1 + 25);

            r3 = noise.random.Next(r2, r2 + 25);
            g3 = noise.random.Next(g2, g2 + 25);
            b3 = noise.random.Next(g2, g2 + 25);

            r4 = noise.random.Next(r3, r3 + 25);
            g4 = noise.random.Next(g3, g3 + 25);
            b4 = noise.random.Next(g3, g3 + 25);

            r5 = noise.random.Next(r4, r4 + 25);
            g5 = noise.random.Next(g4, g4 + 25);
            b5 = noise.random.Next(g4, g4 + 25);

            surface = new Bitmap(radius * 4, radius * 4);

            maxHeight = 0;

            circle = new Bitmap(radius * 2 + 1, radius * 2 + 1);

            //fill with the transparent color first
            for (int x = 0; x < circle.Width; x++)
            {
                for (int y = 0; y < circle.Height; y++)
                {
                    Color c = Color.FromArgb(255, 0, 255);
                    circle.SetPixel(x, y, c);
                }
            }

            //now draw the circle, same as the surface texture
            int[] rgb = new int[3];
            int[] center = new int[2];
            int[] point = new int[2];
            center[0] = radius;
            center[1] = radius;
            for (int i = 0; i < radius; i++)
            {
                for (float angle = 0; angle < 360; angle += 0.27f)
                {
                    if (i == radius - 1)
                    {
                        point = noise.getCircleCoordinate(center, i - 1, angle);
                        circle.SetPixel(point[0] / scale, point[1] / scale, Color.FromArgb(20, 20, 20));
                        point = noise.getCircleCoordinate(center, i, angle);
                        circle.SetPixel(point[0] / scale, point[1] / scale, Color.FromArgb(15, 15, 15));
                        point = noise.getCircleCoordinate(center, i + 1, angle);
                        circle.SetPixel(point[0] / scale, point[1] / scale, Color.FromArgb(5, 5, 5));
                    }
                    else
                    {
                        point = noise.getCircleCoordinate(center, i, angle);
                        rgb = getColorFromHeight(heightMap[point[0], point[1]]);
                        circle.SetPixel(point[0]/scale, point[1]/scale, Color.FromArgb((rgb[0] - (int)(i) > 0 ? rgb[0] - (int)(i) : 0), (rgb[1] - (int)(i) > 0 ? rgb[1] - (int)(i) : 0), (rgb[2] - (int)(i) > 0 ? rgb[2] - (int)(i) : 0)));
                    }
                }
            }
        }