Inheritance: ILight2D
Exemplo n.º 1
0
        public AbstractLight()
        {
            Light = new Light2D();

            // [Default Values]
            Range = 400;
        }
Exemplo n.º 2
0
        public Light()
        {
            mLight2D = new Light2D();

            // [Default Values]
            Range = 400;
        }
Exemplo n.º 3
0
        public Light(Engine engine)
            : base(engine)
        {
            light = new Light2D();

              light.Texture = Engine.Lighting.PointLightTexture;

              Engine.Lighting.Krypton.Lights.Add(light);

              Engine.AddComponent(this);
        }
Exemplo n.º 4
0
        public TorchEntity(GameWorld GameWorld, Vector2 Position)
            : base(GameWorld)
        {
            Texture2D LightTexture = LightTextureBuilder.CreatePointLight(GeneralManager.GDevice, 512);
            TorchLight = new Light2D()
            {

                Texture = LightTexture,
                Range = (float)(0.5f),
                Color = new Color(1f, 0.5f, 0.1f, 1f),
                Intensity = 1f,
                Angle = MathHelper.TwoPi * (float)1,
                X = 2 * (Position.X + GameWorld.TileWidth/2) / GeneralManager.ScreenX - 1,
                Y = 1 - 2 * (Position.Y + GameWorld.TileHeight/2) / GeneralManager.ScreenY,
            };
            GameWorld.LightSystem.Lights.Add(TorchLight);
        }
Exemplo n.º 5
0
        protected Light(LightType lightType)
        {
            LightType = lightType;

            Texture2D LightTexture = LightTextureBuilder.CreatePointLight(Renderer.GD, 512);

            KryptonLight = new Light2D()
            {
                Texture = LightTexture,
                Range = (float)(1.5f),
                Color = new Color(0.8f, 0.8f, 0.8f, 1f),
                Intensity = 1f,
                Angle = MathHelper.TwoPi * 0.5f,
                X = (float)(0),
                Y = (float)(0),
            };
        }
Exemplo n.º 6
0
        public override void OnMouseClick(Map map, Layer layer, Camera2D camera, Vector2 position, string selectedTileName)
        {
            bool add = true;

            foreach (Light2D light in MainForm.MapPanel.Krpyton.Lights)
            {
                var mouse = (new Vector2(camera.Position.X, camera.Position.Y) + position).ToPoint();

                for (int i = 0; i < MainForm.MapPanel._lightSymbolPixelData.Length; i++)
                {
                    int x = i % MainForm.MapPanel._lightSymbolTexture.Width;
                    int y = i / MainForm.MapPanel._lightSymbolTexture.Width;
                 //   System.Windows.Forms.MessageBox.Show(mouse.ToString() + " , " + x + (int)light.Position.X + " " + y + (int)light.Position.Y);
                    if (new Rectangle(x + (int)light.Position.X, y + (int)light.Position.Y, 16, 16).Contains(mouse))
                    {
                        add = false;
                        ((MainForm)MainForm.ActiveForm).OpenProperties(light);
                        MainForm.MapPanel.SelectedLight = light;
                    }
                }
            }

            if (add)
            {
                var light = new Light2D()
                {
                    Position = new Vector2(camera.Position.X + position.X, camera.Position.Y + position.Y),
                    Color = Color.White,
                    Texture = MapPanel.LightTexture,
                    Range = 100,
                    IsOn = true,
                    Intensity = 1.5f,
                    ShadowType = ShadowType.Occluded
                };

                MainForm.MapPanel.Krpyton.Lights.Add(light);
                ((MainForm)MainForm.ActiveForm).OpenProperties(light);
                MainForm.MapPanel.SelectedLight = light;
            }
        }
Exemplo n.º 7
0
        public void LoadContent(GraphicsDevice graphics)
        {
            Light = LightTextureBuilder.CreatePointLight(graphics, 512);

            this.Sun = new Light2D()
            {
                Texture = Light,
                Range = 300000f,
                Color = new Color(150, 150, 150),
                //Intensity = (float)(this.mRandom.NextDouble() * 0.25 + 0.75),
                Intensity = 2222f,
                Angle = MathHelper.TwoPi * 1f,
                X = 0,
                Y = -1000f,

            };

            krypton.Lights.Add(this.Sun);

            //this.CreateLights(Light, this.mNumLights);
            //this.CreateHulls(this.mNumHorzontalHulls, this.mNumVerticalHulls);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Draws shadows from the light's position outward
        /// </summary>
        /// <param name="helper">A render helper for drawing shadows</param>
        /// <param name="hulls">The shadow hulls used to draw shadows</param>
        public void Draw(KryptonRenderHelper helper, List <ShadowHull> hulls)
        {
            // Draw the light only if it's on
            if (!this.mIsOn)
            {
                return;
            }

            // Make sure we only render the following hulls
            helper.ShadowHullVertices.Clear();
            helper.ShadowHullIndicies.Clear();

            // Loop through each hull
            foreach (ShadowHull hull in hulls)
            {
                //if(hull.Bounds.Intersects(this.Bounds))
                // Add the hulls to the buffer only if they are within the light's range
                if (hull.Visible && Light2D.IsInRange(hull.Position - this.Position, hull.MaxRadius * Math.Max(hull.Scale.X, hull.Scale.Y) + this.Range))
                {
                    helper.BufferAddShadowHull(hull);
                }
            }

            var shadowEffect = helper.Effect.Techniques["PointLight_Shadow_Fast"];

            helper.Effect.CurrentTechnique = shadowEffect;
            // Set the effect parameters
            helper.Effect.Parameters["LightPosition"].SetValue(this.mPosition);
            helper.Effect.Parameters["Texture0"].SetValue(this.mTexture);
            helper.Effect.Parameters["LightIntensityFactor"].SetValue(1 / (this.mIntensity * this.mIntensity));

            shadowEffect.Passes["ShadowStencil"].Apply();
            helper.BufferDraw();

            shadowEffect.Passes["Light"].Apply();
            helper.DrawClippedFov(this.mPosition, this.mAngle, this.mRange * 2, this.mColor, this.mFov);
        }
Exemplo n.º 9
0
        private Light2D CreateLights(Texture2D texture)
        {
            byte r = (byte)(255);
            byte g = (byte)(100);
            byte b = (byte)(200);

            var light = new Light2D()
            {
                Texture = texture,
                Range = (float)(70),
                Color = new Color(r, g, b),
                //Intensity = (float)(this.mRandom.NextDouble() * 0.25 + 0.75),
                Intensity = 1.0f,
                Angle = (float)Math.PI / 2,
                X = _position.X,
                Y = _position.Y

            };
            light.ShadowType = ShadowType.Illuminated;
            krypton.Lights.Add(light);
            return light;
        }
Exemplo n.º 10
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            map = Content.Load<Map>("desert");

            // Create a new simple point light texture to use for the lights
            this.lightTexture = LightTextureBuilder.CreatePointLight(this.GraphicsDevice, 512);

            // Load sprites
            playerImage = Content.Load<Texture2D>("player");
            gemImage = Content.Load<Texture2D>("gem");

            //Test Sprite
            testSprite = new Sprite(playerImage, new Vector2(100, -100), krypton);
            testSprite.Position = new Vector2(200, 20);
            testSprite.Velocity = new Vector2(0.2f, 0f);

            //Dont add it cuase
            sprites.Add(testSprite);

            //Create player
            player = new Player(Vector2.Zero,testSprite);
            // Load the player resources
            Animation playerAnimation = new Animation();
            Texture2D playerTexture = Content.Load<Texture2D>("shipAnimation");
            playerAnimation.Initialize(playerTexture, Vector2.Zero, 115, 69, 8, 45, Color.White, 1f, true, this.GraphicsDevice);
            player.Position = new Vector2(200, 200);
            //player.Velocity = new Vector2(0f, 0f);

            testSprite2 = new Sprite(playerImage, new Vector2(100, -100), krypton);
            testSprite2.Position = new Vector2(100, 20);
            testSprite2.Velocity = new Vector2(0f, 0.1f);
            sprites.Add(testSprite2);

            // Create a light we can control
            torch = new Light2D()
            {
                Texture = this.lightTexture,
                X = 0,
                Y = 0,
                Range = 600,
                Intensity = 0.5f,
                Color = Color.White,
                ShadowType = ShadowType.Illuminated,
                Fov = MathHelper.PiOver2 * (float)(0.5)
            };

            this.krypton.Lights.Add(this.torch);

            /*
            // Make some random lights!
            for (int i = 0; i < 9; i++)
            {
                byte r = (byte)(this.random.Next(255 - 32) + 32);
                byte g = (byte)(this.random.Next(255 - 32) + 32);
                byte b = (byte)(this.random.Next(255 - 32) + 32);

                Light2D light = new Light2D()
                {
                    Texture = lightTexture,
                    Range = (float)(this.random.NextDouble() * 200 + 100),
                    Color = new Color(r, g, b),
                    //Intensity = (float)(this.mRandom.NextDouble() * 0.25 + 0.75),
                    Intensity = 0.8f,
                    Angle = MathHelper.TwoPi * (float)this.random.NextDouble(),
                    X = (float)(this.random.NextDouble() * 500),
                    Y = (float)(this.random.NextDouble() * 500),
                };

                // Here we set the light's field of view
                if (i % 2 == 0)
                {
                    light.Fov = MathHelper.PiOver2 * (float)(this.random.NextDouble() * 0.75 + 0.25);
                }

                this.krypton.Lights.Add(light);
            }
             */

            /*
            int x = 10;
            int y = 10;
            float w = 1000;
            float h = 1000;

            // Make lines of lines of hulls!
            for (int j = 0; j < y; j++)
            {
                // Make lines of hulls!
                for (int i = 0; i < x; i++)
                {
                    var posX = (((i + 0.5f) * w) / x) - w / 2 + (j % 2 == 0 ? w / x / 2 : 0);
                    var posY = (((j + 0.5f) * h) / y) - h / 2; // +(i % 2 == 0 ? h / y / 4 : 0);

                    var hull = ShadowHull.CreateRectangle(Vector2.One * 10f);
                    hull.Position.X = posX;
                    hull.Position.Y = posY;
                    hull.Scale.X = (float)(this.random.NextDouble() * 2.75f + 0.25f);
                    hull.Scale.Y = (float)(this.random.NextDouble() * 2.75f + 0.25f);

                    krypton.Hulls.Add(hull);
                }
            }
            */ //Test lights
        }
Exemplo n.º 11
0
        public void Intialise(List<Platform> platforms,List<Sprite> sprites,KryptonEngine krypton,ContentManager content,GraphicsDevice graphicsDevice, ScreenDebuger screenDebuger, Level level)
        {
            if (EntityType == "Player")
            {
                Texture2D playerImage = content.Load<Texture2D>("player");
                Sprite testSprite = new Sprite(playerImage, new Vector2(0,0), false, krypton);
                Player aPlayer = new Player(new Vector2(EntityBounds.X, EntityBounds.Y), testSprite,screenDebuger,content,graphicsDevice,level);
                level.setPlayer(aPlayer);
            }

            if (EntityType == "Hazard")
            {

            }

            if (EntityType == "Platform")
            {
                TileCollision tileCollision = TileCollision.Platform;
                if (Properties["CollisionType"] == "Platform") {tileCollision = TileCollision.Platform;}
                if (Properties["CollisionType"] == "Passable") { tileCollision = TileCollision.Passable; }
                if (Properties["CollisionType"] == "Impassable") { tileCollision = TileCollision.Impassable; }
                Platform platform = new Platform(EntityBounds, tileCollision, Convert.ToBoolean(Properties["IsShadowCaster"]), krypton);
                platforms.Add(platform);
            }

            if (EntityType == "Light")
            {
                Color color = new Color();
                color.R = (byte)Convert.ToInt32(Properties["R"]);
                color.G = (byte)Convert.ToInt32(Properties["G"]);
                color.B = (byte)Convert.ToInt32(Properties["B"]);
                color.A = 255;

                /*
                    X = EntityBounds.X,
                    Y = EntityBounds.Y,
                    Range = (float)Convert.ToInt32(Properties["Range"]),
                    Intensity = (float)Convert.ToDouble(Properties["Intensity"]),
                    Color = color,
                    ShadowType = ShadowType.Illuminated,
                    Fov = MathHelper.PiOver2 * (float) (0.5)
                 * */

                    Light2D light = new Light2D
                    {
                        Texture = LightTextureBuilder.CreatePointLight(graphicsDevice, 1024),
                        X = EntityBounds.X,
                        Y = EntityBounds.Y,
                        Range = (float)Convert.ToInt32(Properties["Range"]),
                        Intensity = (float)Convert.ToDouble(Properties["Intensity"]),
                        Color = color,
                        ShadowType = ShadowType.Illuminated,
                        Fov = MathHelper.PiOver2 * (float)Convert.ToDouble(Properties["Fov"])
                    };

                //Optional Properties
                    if(Properties.ContainsKey("Flicker")){ light.Flicker = (bool)Convert.ToBoolean(Properties["Flicker"]);}

                    krypton.Lights.Add(light);
            }
        }
Exemplo n.º 12
0
        public override void Dispose(bool disposing)
        {
            Engine.Lighting.Krypton.Lights.Remove(light);
              light = null;

              base.Dispose(disposing);
        }
Exemplo n.º 13
0
        public PlayerShip(Game game, Vector2 position)
        {
            Game = game;
            _soundBank = Game.Services.GetService<SoundBank[]>();
            _world = Game.Services.GetService<World>();
            krypton = Game.Services.GetService<KryptonEngine>();

            thrustLR = _soundBank[0].GetCue("thrust01");
            thrustLR.Play();
            thrustLR.Pause();

            thrustUD = _soundBank[0].GetCue("thrust01");
            thrustUD.Play();
            thrustUD.Pause();

            Position = position;
            _particleRenderer = Game.Services.GetService<SpriteBatchRenderer>();
            //_textures = Game.Services.GetService<Textures>();

            //Loadcontentstuff
            _shiptxture = Game.Content.Load<Texture2D>("player_ship");
            _turretTxture = Game.Content.Load<Texture2D>(".\\guns\\turret01");
            _centreVect = new Vector2(_shiptxture.Width / 2, _shiptxture.Height / 2);

            ProximityBox = new Rectangle(0, 0, _shiptxture.Width+Globals.PhysBuffer, _shiptxture.Height + Globals.PhysBuffer);

            //make ship fixture in for farseer
            box = BodyFactory.CreateCircle(_world, ConvertUnits.ToSimUnits(_shiptxture.Width / 2), 7.0f);
            box.BodyType = BodyType.Dynamic;
            box.Restitution = 0.5f;
            box.Friction = 0.2f;
            box.FixedRotation = true;
            box.LinearDamping = 0.4f;
            box.Position = ConvertUnits.ToSimUnits(Position.X + _centreVect.X, Position.Y + _centreVect.Y);
            box.UserData = "player";

            //box.OnCollision += Collide;
            box.OnSeparation += Collide;

            //make light in krypton
            var mLightTexture = LightTextureBuilder.CreateConicLight(Game.GraphicsDevice, 256, 2.0f);
            light = CreateLights(mLightTexture,400);
            var mLightTexture2 = LightTextureBuilder.CreatePointLight(Game.GraphicsDevice, 64);
            light2 = CreateLights(mLightTexture2,200);

            //set up thruster particle
            _thrustparticle = Game.Content.Load<ParticleEffect>(".\\mercury\\thruster");
            _thrustparticle.LoadContent(Game.Content);
            _thrusterEmitter = (ConeEmitter)_thrustparticle[0];
            //_thrusterEmitter.Initialise();
            _thrusterEmitter.ParticleTexture = Game.Content.Load<Texture2D>(".\\mercury\\Particle004");
            _thrustparticle.Initialise();
            _particleRenderer.LoadContent(Game.Content);

            //_centerVect = new Vector2(_shiptxture.Width / 2,_shiptxture.Width / 2);
            currentWeapon = new Gun(Game, true, BulletsStats.Plasma01);
        }
Exemplo n.º 14
0
        protected override void Draw()
        {
            Camera.Update();

            if (LightsEnabled)
            {
               _krypton.Matrix = Camera.View;
                this._krypton.LightMapPrepare();
            }

            GraphicsDevice.Clear(new Color(240,240,240));

            _spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, Camera.View);

            foreach (var layer in Map.Layers.Where(p => p.Order <= ActiveLayer.Order).OrderBy(p => p.Order))
            {
                DrawLayer(layer);
            }

            _spriteBatch.End();

            if (LightsEnabled)
                this._krypton.Draw();

            _spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, Camera.View);

            ActiveTool.Draw(_spriteBatch, Camera, _currentMousePosition, _pixel);

            if (!mouseDown && _movingLight != null)
                _movingLight = null;

            foreach (Light2D light in _krypton.Lights)
            {
                if (light == SelectedLight)
                    _spriteBatch.Draw(_selectionTexture, light.Position + new Vector2(1, -1), Color.White);

                _spriteBatch.Draw(_lightSymbolTexture, light.Position/* - new Vector2(_lightSymbolTexture.Width / 2, _lightSymbolTexture.Height / 2)*/, Color.White);
            }

            _spriteBatch.End();
        }
Exemplo n.º 15
0
 private void CreateLights(Texture2D texture, int count)
 {
     // Make some random lights!
     for (int i = 0; i < count; i++)
     {
         Light2D light = new Light2D()
         {
             Texture = texture,
             Range = (float)(40),
             Intensity = float.MaxValue,
             X = (float)(this.mRandom.NextDouble() * 50 - 25),
             Y = (float)(this.mRandom.NextDouble() * 50 - 25),
         };
         this.krypton.Lights.Add(light);
     }
 }
Exemplo n.º 16
0
        private Light2D CreateLights(Texture2D texture,int range)
        {
            byte r = (byte) (255);
            byte g = (byte) (255);
            byte b = (byte) (255);

            var light = new Light2D()
                        {
                            Texture = texture,
                            Range = (float) (range),
                            Color = new Color(r, g, b),
                            //Intensity = (float)(this.mRandom.NextDouble() * 0.25 + 0.75),
                            Intensity = 1.0f,
                            Angle = (float) Math.PI/2,
                            X =  Position.X,
                            Y = Position.Y

                        };

            /* Here we set the light's field of view
            if (i % 2 == 0)
            {
                light.Fov = MathHelper.PiOver2 * (float)(this.mRandom.NextDouble() * 0.75 + 0.25);
            }*/
            light.ShadowType = ShadowType.Occluded;
            krypton.Lights.Add(light);
            return light;
        }
Exemplo n.º 17
0
        public void CreateLights(Texture2D texture)
        {
            // Make some random lights!
            for (int i = 0; i < 1; i++)
            {
                Light2D light = new Light2D()
                {
                    Texture = texture,
                    Range = (float)(50),
                    Color = new Color(255, 255, 255),
                    //Intensity = (float)(this.mRandom.NextDouble() * 0.25 + 0.75),
                    Intensity = 0.8f,
                    Angle = MathHelper.TwoPi * (float)0,
                    X = (float)(10),
                    Y = (float)(-10),
                };

                // Here we set the light's field of view
                if (i % 2 == 0)
                {
                    light.Fov = MathHelper.PiOver2 * (float)(1);
                }

                light.ShadowType = ShadowType.Illuminated;

                this.krypton.Lights.Add(light);
            }
        }
Exemplo n.º 18
0
        protected override void LoadContent()
        {
            // Create a new simple point light texture to use for the lights
            this.mLightTexture = LightTextureBuilder.CreatePointLight(this.GraphicsDevice, 512);

            // Create some lights and hulls
            this.CreateLights(mLightTexture, this.mNumLights);
            this.CreateHulls(this.mNumHorzontalHulls, this.mNumVerticalHulls);

            // Create a light we can control
            this.mLight2D = new Light2D()
            {
                Texture = this.mLightTexture,
                X = 0,
                Y = 0,
                Range = 25,
                Color = Color.Multiply(Color.CornflowerBlue, 2.0f),
                ShadowType = ShadowType.Occluded
            };

            this.krypton.Lights.Add(this.mLight2D);
        }
Exemplo n.º 19
0
 public bool InLight(World w, Light2D light)
 {
     List<float> fractions = new List<float>();
     for (float i = -24f; i <= 24f; i += 24f)
     {
         Vector2 start = light.Position * MainGame.PIXEL_TO_METER;
         Vector2 end = torso.Position + Vector2.UnitY * i * MainGame.PIXEL_TO_METER - start;
         end.Normalize();
         end *= (light.Range - 32) * MainGame.PIXEL_TO_METER;
         end += start;
         fractions.Clear();
         float foundFr = (end - start).Length();
         w.RayCast((f, p, n, fr) =>
             {
                 this.p = p;
                 if (f.Body.UserData == this)
                     foundFr = fr;
                 if (f.Body.UserData == "hasshadow" || f.UserData == "hasshadow" || f.Body.UserData == this)
                 {
                     fractions.Add(fr);
                     return fr;
                 }
                 else
                     return -1;
             }, start, end);
         fractions.Sort();
         if (fractions.Count > 0 && fractions[0] == foundFr)
             return true;
     }
     return false;
 }
Exemplo n.º 20
0
        public void Intialise(KryptonEngine krypton, ContentManager content, GraphicsDevice graphicsDevice,ScreenDebuger screenDebuger, List<Sprite> sprites)
        {
            this.content = content;
            this.krypton = krypton;
            this.sprites = sprites;
            this.screenDebuger = screenDebuger;
            placeHolder = content.Load<Texture2D>("PlaceHolder");
            interestingLight = content.Load<Texture2D>("player");
            platforms = new List<Platform>();

            //Texture2D playerImage = content.Load<Texture2D>("playerDraft");
            //Sprite testSprite = new Sprite(playerImage, new Vector2(0,0), false, krypton);
            //player = new Player(new Vector2(100, 100), testSprite);

            foreach (var layer in TileLayers)
            {
                for (int y = 0; y < layer.Height; y++)
                {
                    for (int x = 0; x < layer.Width; x++)
                    {
                        Tile tile = layer.Tiles[y * layer.Width + x];
                        if (tile.Exists)
                        {
                            tile.Intialise(new Vector2(x, y), content);
                        }
                    }
                }
            }

            foreach (var layer in EntityLayers)
            {
                foreach (Entity entity in layer.Entities)
                {
                    entity.Intialise(platforms, sprites, krypton, content, graphicsDevice,screenDebuger , this);
                }
            }

            // Create a light we can control
            torch = new Light2D()
            {
                Texture = LightTextureBuilder.CreatePointLight(graphicsDevice, 1024),
                X = 0,
                Y = 0,
                Range = 800,
                Intensity = 0.6f,
                Color = Color.White,
                ShadowType = ShadowType.Illuminated,
                Fov = MathHelper.PiOver2 * (float)(0.3)
            };
            krypton.Lights.Add(torch);

            torchGlow = new Light2D()
            {
                Texture = LightTextureBuilder.CreatePointLight(graphicsDevice, 1024),
                X = 0,
                Y = 0,
                Range = 700,
                Intensity = 0.25f,
                Color = Color.White,
                ShadowType = ShadowType.Solid,
                //Fov = MathHelper.PiOver2 * (float)(0.5)
            };
            krypton.Lights.Add(torchGlow);
        }
Exemplo n.º 21
0
        private void Load(Game game, string name)
        {
            // Load tiles for world type
            textures = new Dictionary<string, Texture2D>();
            string[] files = Directory.GetFiles("Content\\tiles");
            for (int i = 0; i < files.Length; i++)
            {
                string s = files[i].Replace(".xnb", "").Split('\\')[files[i].Split('\\').Length - 1];
                textures.Add(s, game.Content.Load<Texture2D>("tiles\\" + s));
            }

            XmlSerializer ser = new XmlSerializer(typeof(LevelData));
            LevelData level;
            using (XmlReader reader = XmlReader.Create("Content\\levels\\" + name + ".xml"))
            {
                level = (LevelData)ser.Deserialize(reader);
            }

            this.size = level.size;
            foreach (TileInformation t in level.tiles)
                this.tiles.Add(new Tile(t.texture, new Vector2(t.X, t.Y), t.Scale, t.Rotation, t.Layer, t.Effect));
            foreach (StaticBodyInformation sb in level.staticBodies)
            {
                StaticBody body = new StaticBody(sb.Points);
                body.CreateBody(world, globalLighting);
                this.collisionMap.Add(body);
            }
            foreach (ObjectInformation obj in level.objects)
            {
            //				Console.WriteLine(typeof(Box).AssemblyQualifiedName.ToArray());
                object[] parameters = new object[obj.ParameterValues == null ? 3 : (obj.ParameterValues.Count() + 3)];
                parameters[0] = world;
                parameters[1] = obj.Index;
                parameters[2] = obj.Position;
                for (int i = 3; i < parameters.Length; i++)
                    parameters[i] = obj.ParameterValues[i - 3];
                GameObject converted = Activator.CreateInstance(Type.GetType(obj.Type), parameters) as GameObject;
                converted.Scripts = new List<Script>();
                foreach (ScriptInformation s in obj.Scripts)
                    converted.Scripts.Add(new Script(s.Name, s.InitDelay, s.LoopCount, s.LoopDelay, s.TriggerName, s.Params));
                this.objects.Add(converted);
            }
            foreach (CameraBoxInformation cam in level.cameras)
                this.objects.Add(new CameraBox(cam.Target, cam.Bounds, cam.Priority));
            foreach (TriggerInformation trigger in level.triggers)
                this.triggers.Add(new Trigger(trigger.Bounds, trigger.Name, trigger.ObjID, trigger.WhenTrigger));

            targetLight = new Color(level.R, level.G, level.B);
            globalLighting.AmbientColor = new Color(0, 0, 0);

            //---- Temp ----
            Texture2D lightTexture = LightTextureBuilder.CreatePointLight(game.GraphicsDevice, 512);
            Light2D globalLight = new Light2D()
            {
                Texture = lightTexture,
                Range = 1600,
                Color = Color.White,
                Intensity = 1f,
                X = level.size.X / 2,
                Y = 600,
                Fov = MathHelper.TwoPi
            };
            globalLighting.Lights.Add(globalLight);
            // -------------
        }
Exemplo n.º 22
0
        /// <summary>
        /// Draws shadows from the light's position outward
        /// </summary>
        /// <param name="helper">A render helper for drawing shadows</param>
        /// <param name="hulls">The shadow hulls used to draw shadows</param>
        public void Draw(KryptonRenderHelper helper, List <ShadowHull> hulls)
        {
            // Draw the light only if it's on
            if (!this.mIsOn)
            {
                return;
            }

            // Make sure we only render the following hulls
            helper.ShadowHullVertices.Clear();
            helper.ShadowHullIndicies.Clear();

            // Loop through each hull
            foreach (ShadowHull hull in hulls)
            {
                //if(hull.Bounds.Intersects(this.Bounds))
                // Add the hulls to the buffer only if they are within the light's range
                if (hull.Visible && Light2D.IsInRange(hull.Position - this.Position, hull.MaxRadius * Math.Max(hull.Scale.X, hull.Scale.Y) + this.Range))
                {
                    helper.BufferAddShadowHull(hull);
                }
            }

            // Set the effect and parameters
            helper.Effect.Parameters["LightPosition"].SetValue(this.mPosition);
            helper.Effect.Parameters["Texture0"].SetValue(this.mTexture);
            helper.Effect.Parameters["LightIntensityFactor"].SetValue(1 / (this.mIntensity * this.mIntensity));


            switch (this.mShadowType)
            {
            case (ShadowType.Solid):
                helper.Effect.CurrentTechnique = helper.Effect.Techniques["PointLight_Shadow_Solid"];
                break;

            case (ShadowType.Illuminated):
                helper.Effect.CurrentTechnique = helper.Effect.Techniques["PointLight_Shadow_Illuminated"];
                break;

            case (ShadowType.Occluded):
                helper.Effect.CurrentTechnique = helper.Effect.Techniques["PointLight_Shadow_Occluded"];
                break;

            default:
                throw new NotImplementedException("Shadow Type does not exist: " + this.mShadowType);
            }

            foreach (var pass in helper.Effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                helper.BufferDraw();
            }

            helper.Effect.CurrentTechnique = helper.Effect.Techniques["PointLight_Light"];
            foreach (var pass in helper.Effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                helper.DrawClippedFov(this.mPosition, this.mAngle, this.mRange * 2, this.mColor, this.mFov);
            }

            helper.Effect.CurrentTechnique = helper.Effect.Techniques["ClearTarget_Alpha"];
            foreach (var pass in helper.Effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                helper.GraphicsDevice.DrawUserPrimitives <VertexPositionTexture>(PrimitiveType.TriangleStrip, KryptonRenderHelper.UnitQuad, 0, 2);
            }
        }
Exemplo n.º 23
0
        private void InitLightSystem()
        {
            LightSystem.AmbientColor = new Color(0, 0, 0, 0.5f);

            Texture2D LightTexture = LightTextureBuilder.CreatePointLight(GeneralManager.GDevice, 512);

            PlayerLight = new Light2D()
            {
                Texture = LightTexture,
                Range = (float)(0.5f),
                Color = new Color(0.8f, 0.8f, 0.8f, 1f),
                Intensity = 1f,
                Angle = MathHelper.TwoPi * 2f,
                X = (float)(0),
                Y = (float)(0),
            };
            SunLight = new Light2D()
            {
                Texture = LightTexture,
                Range = (float)(1500f),
                Color = new Color(0.9f, 0.9f, 0.9f, 1f),
                Intensity = 1f,
                Angle = MathHelper.TwoPi * (float)1,
                X = (float)(0),
                Y = (float)(100),
            };
            LightSystem.Lights.Add(PlayerLight);
            LightSystem.Lights.Add(SunLight);
        }
Exemplo n.º 24
0
        private void CreateLights(Texture2D texture, int count)
        {
            // Make some random lights!
            for (int i = 0; i < count; i++)
            {
                byte r = (byte)(this.mRandom.Next(255 - 64) + 64);
                byte g = (byte)(this.mRandom.Next(255 - 64) + 64);
                byte b = (byte)(this.mRandom.Next(255 - 64) + 64);

                Light2D light = new Light2D()
                {
                    Texture = texture,
                    Range = (float)(this.mRandom.NextDouble() * 5 + 5),
                    Color = new Color(r,g,b),
                    //Intensity = (float)(this.mRandom.NextDouble() * 0.25 + 0.75),
                    Intensity = 1f,
                    Angle = MathHelper.TwoPi * (float)this.mRandom.NextDouble(),
                    X = (float)(this.mRandom.NextDouble() * 50 - 25),
                    Y = (float)(this.mRandom.NextDouble() * 50 - 25),
                };

                // Here we set the light's field of view
                if (i % 2 == 0)
                {
                    light.Fov = MathHelper.PiOver2 * (float)(this.mRandom.NextDouble() * 0.75 + 0.25);
                }

                this.krypton.Lights.Add(light);
            }
        }
Exemplo n.º 25
0
        private void CreateLights(Texture2D texture)
        {
            byte r = (byte) (255);
                byte g = (byte) (255);
                byte b = (byte) (255);

                light = new Light2D()
                                    {
                                        Texture = texture,
                                        Range = (float) (1000),
                                        Color = new Color(r, g, b),
                                        //Intensity = (float)(this.mRandom.NextDouble() * 0.25 + 0.75),
                                        Intensity = 1f,
                                        Angle = (float)Math.PI/2,
                                        X = (float)300,
                                        Y = (float)300,
                                        //ShadowType = ShadowType.Occluded,
                                    };

                /* Here we set the light's field of view
                if (i % 2 == 0)
                {
                    light.Fov = MathHelper.PiOver2 * (float)(this.mRandom.NextDouble() * 0.75 + 0.25);
                }*/
               light.ShadowType = ShadowType.Occluded;
                krypton.Lights.Add(light);
        }