Exemplo n.º 1
0
        public static CollisionLayer FromFile(string filename)
        {
            CollisionLayer     layer;
            bool               readingLayout = false;
            List <List <int> > tempLayout    = new List <List <int> >();

            using (StreamReader reader = new StreamReader(filename))
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine().Trim();

                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    if (line.Contains("[Layout]"))
                    {
                        readingLayout = true;
                    }
                    else if (readingLayout)
                    {
                        List <int> row   = new List <int>();
                        string[]   cells = line.Split(' ');
                        foreach (string c in cells)
                        {
                            if (!string.IsNullOrEmpty(c))
                            {
                                row.Add(int.Parse(c));
                            }
                        }
                        tempLayout.Add(row);
                    }
                }
            }

            int width  = tempLayout[0].Count;
            int height = tempLayout.Count;

            layer = new CollisionLayer(height, width);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    layer.SetCellIndex(x, y, tempLayout[y][x]);
                }
            }

            return(layer);
        }
Exemplo n.º 2
0
        public static void CreateLights(Texture2D texture, KryptonEngine krypton, CollisionLayer map)
        {
            //make random lights
            for (int i = 0; i < lightCount; i++)
            {
                if (RandomLightColorOn)
                {
                    byte r = (byte)(rand.Next(randomLightColorRedScale - 64) + 64);
                    byte g = (byte)(rand.Next(randomLightColorGreenScale - 64) + 64);
                    byte b = (byte)(rand.Next(randomLightColorBlueScale - 64) + 64);
                    lightColor = new Color(r, g, b);
                }
                if (RandomLightIntensityOn)
                {
                    lightIntensity = (float)(rand.NextDouble() * randomLightIntensityMin + randomLightIntensityMax);
                }
                Light2D light = new Light2D()
                {
                    Texture   = texture,
                    Range     = (float)(rand.NextDouble() * (randomLightRangeMax - randomLightRangeMin) + randomLightRangeMin),
                    Color     = lightColor,
                    Intensity = lightIntensity,
                    Angle     = MathHelper.TwoPi * (float)rand.NextDouble(),
                    X         = (float)(rand.NextDouble() * map.WidthInPixels),
                    Y         = (float)(rand.NextDouble() * map.HeightInPixels)
                };

                //here we set the light's field of view
                if (i % 2 == 0)
                {
                    if (RandomLightFovOn)
                    {
                        light.Fov = MathHelper.PiOver2 * (float)(rand.NextDouble() * 0.75 + 0.25);
                    }
                    else
                    {
                        light.Fov = lightFov;
                    }
                }

                krypton.Lights.Add(light);
            }
        }
        public static void CreateLights(PenumbraComponent penumbra, CollisionLayer map)
        {
            //make random lights
            for (int i = 0; i < lightCount; i++)
            {
                if (RandomLightColorOn)
                {
                    byte r = (byte)(rand.Next(randomLightColorRedScale - 64) + 64);
                    byte g = (byte)(rand.Next(randomLightColorGreenScale - 64) + 64);
                    byte b = (byte)(rand.Next(randomLightColorBlueScale - 64) + 64);
                    lightColor = new Color(r, g, b);
                }
                if (RandomLightIntensityOn)
                {
                    lightIntensity = (float)(rand.NextDouble() * randomLightIntensityMin + randomLightIntensityMax);
                }
                SpotLight light = new SpotLight()
                {
                    Radius    = (float)(rand.NextDouble() * (randomLightRangeMax - randomLightRangeMin) + randomLightRangeMin),
                    Color     = lightColor,
                    Intensity = lightIntensity,
                    Rotation  = MathHelper.TwoPi * (float)rand.NextDouble(),
                    Position  = new Vector2
                                (
                        (float)(rand.NextDouble() * map.WidthInPixels),
                        (float)(rand.NextDouble() * map.HeightInPixels)
                                )
                };

                //here we set the light's field of view
                if (i % 2 == 0)
                {
                    //if (RandomLightFovOn)
                    //light.Fov = MathHelper.PiOver2 * (float)(rand.NextDouble() * 0.75 + 0.25);
                    //else
                    //light.Fov = lightFov;
                }

                penumbra.Lights.Add(light);
            }
        }