protected override void LoadContent() { // Create a new simple point light texture to use for the lights this.mLightTexture = LightTextureBuilder.CreatePointLight(this.GraphicsDevice, 1024); // Create some lights and hulls this.CreateLights(mLightTexture, this.mNumLights); this.CreateHulls(this.mNumHorzontalHulls, this.mNumVerticalHulls); }
/// <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); // Load fonts hudFont = Content.Load <SpriteFont>("Fonts/Hud"); // Load overlay textures winOverlay = Content.Load <Texture2D>("Overlays/you_win"); loseOverlay = Content.Load <Texture2D>("Overlays/you_lose"); diedOverlay = Content.Load <Texture2D>("Overlays/you_died"); //Known issue that you get exceptions if you use Media PLayer while connected to your PC //See http://social.msdn.microsoft.com/Forums/en/windowsphone7series/thread/c8a243d2-d360-46b1-96bd-62b1ef268c66 //Which means its impossible to test this from VS. //So we have to catch the exception and throw it away try { MediaPlayer.IsRepeating = true; MediaPlayer.Play(Content.Load <Song>("Sounds/Music")); } catch { } if (World == null) { World = new World(Vector2.Zero); } else { World.Clear(); } loadConvexHulls(); // Create a new simple point light texture to use for the lights this.mLightTexture = LightTextureBuilder.CreatePointLight(this.GraphicsDevice, 200); // Create some lights and hulls CreateLights(mLightTexture); CreateShadowHulls(); exitSign = Content.Load <Texture2D>("Tiles/exit"); Sprite sprite = new Sprite(winOverlay, new Vector2(20, 20), krypton); Sprite sprite2 = new Sprite(exitSign, new Vector2(0, 0), krypton); sprites.Add(sprite); sprites.Add(sprite2); LoadNextLevel(); }
protected override void Initialize() { try { _spriteBatch = new SpriteBatch(GraphicsDevice); Camera = new Camera2D(); Camera.Position = new Vector3(500, 500, 0); /* Camera.Initialize(); * Camera.FocusPosition = new Vector2(0, 0); ; */ _pixel = new Texture2D(GraphicsDevice, 1, 1); _pixel.SetData <Color>(new Color[] { Color.White }); _cache = new Dictionary <string, Texture2D>(); GraphicsDevice.RasterizerState = RasterizerState.CullNone; _krypton = new KryptonEngine(); _krypton.GraphicsDevice = GraphicsDevice; _krypton.mEffect = contentManager.Load <Effect>("KryptonEffect"); _krypton.Initialize(); _krypton.LoadContent(); LightTexture = LightTextureBuilder.CreatePointLight(GraphicsDevice, 1024); //_krypton. // _krypton.AmbientColor = Color.DarkGreen; _krypton.CullMode = CullMode.None; _krypton.SpriteBatchCompatablityEnabled = true; _lightSymbolTexture = contentManager.Load <Texture2D>("light_bulb"); _lightSymbolPixelData = GetPixelData(_lightSymbolTexture); _selectionTexture = contentManager.Load <Texture2D>("selection"); System.Windows.Forms.Application.Idle += delegate { Invalidate(); }; this.MouseMove += new System.Windows.Forms.MouseEventHandler(OnMouseMove); this.MouseDown += new System.Windows.Forms.MouseEventHandler(OnMouseDown); this.MouseUp += new System.Windows.Forms.MouseEventHandler(OnMouseUp); this.MouseClick += new System.Windows.Forms.MouseEventHandler(MapPanel_MouseClick); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } }
public Lighting(Engine engine) : base(engine) { Krypton = new KryptonEngine(engine, @"Krypton\KryptonEffect"); Krypton.Bluriness = 3; Krypton.CullMode = CullMode.None; Krypton.Matrix = Engine.Camera.CameraMatrix; Krypton.SpriteBatchCompatablityEnabled = true; PointLightTexture = LightTextureBuilder.CreatePointLight(Engine.Video.GraphicsDevice, 512); this.DrawOrder = (int)Global.Layers.Lighting; engine.AddComponent(this); }
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), }; }
protected override void LoadContent() { FrameRateCounter = new FrameRateCounter(this, Content.Load <SpriteFont>(@"Fonts\Visitor43"), GamePlayManager.SpriteBatch); GamePlayManager.StartServices(); Components.Add(GamePlayManager.GamePlayComponentManager); GamePlayManager.UiManager.AddUiContainer(new UiContainer(GameEnvironment.ScreenRectangle, new UiControlManager())); Ground = Content.Load <Texture2D>(@"Concrete"); MazeA = Content.Load <Texture2D>(@"MazeA"); MazeB = Content.Load <Texture2D>(@"MazeB"); LightTexture = LightTextureBuilder.CreatePointLight(this.GraphicsDevice, 512); //CreateLights(LightTexture, 20); //CreateHulls(50); _compoundA = LevelFromTexture(MazeA, ref _originA); _compoundB = LevelFromTexture(MazeB, ref _originB); //_compoundB.Position += ConvertUnits.ToSimUnits( MazeBOffset); Player = new Player(new Vector2(100, 100)); KryptonEngine.Lights.Add(Player.Light); }
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); }
public PlayerObject(string name, Vector2 startingPos, AnimatedSprite sprite, Texture2D particleTex) : base(name, startingPos, sprite) { base.Angle = MathHelper.PiOver2; base.Sprite.CollisionRange = 32 * 1.4f; Light2D ambient = new Light2D { Texture = LightTextureBuilder.CreatePointLight(GameEngine.CurrentMap.Krypton.GraphicsDevice, 128), Intensity = 1.0f, Range = 256, Angle = Sprite.Angle, Fov = MathHelper.TwoPi, Color = Color.White, IsOn = true }; ambient.Position = Position; base.lights.Add("Ambient", ambient); ParticleSystem engine = new ParticleSystem(Position); engine.AddEmitter( new Vector2(0.098f, 0.016f), new Vector2(0, -1), new Vector2(0.001f * MathHelper.Pi, 0.001f * MathHelper.Pi), new Vector2(0.85f, 1.05f), new Vector2(120 / 2, 140 / 2), new Vector2(60 / 4, 70 / 4), Color.Yellow, Color.Orange, Color.Red, Color.Crimson, new Vector2(400 / 3, 500 / 3), new Vector2(100 / 3, 120 / 3), 500, Vector2.Zero, particleTex); engine.Emitters[0].StopEmmiting = true; base.particleSystems.Add("Engine", engine); }
void rebuild( ) { _krypton.Lights.Clear( ); _krypton.Hulls.Clear( ); LayerEditor activeLayer = IoC.Model.ActiveLayer; if (activeLayer == null) { return; } activeLayer.OfType <LightEditor>( ).ForEach( light => { var props = (LightProperties)light.ItemProperties; Texture2D texture; if (props.TypeOfLight == TypeOfLight.Point) { texture = LightTextureBuilder.CreatePointLight(_game.GraphicsDevice, props.TextureSize); } else { texture = LightTextureBuilder.CreateConicLight(_game.GraphicsDevice, props.TextureSize, props.FieldOfView); } if (texture == null) { throw new InvalidOperationException(@"Cannot create light of type {0}.".FormatWith(props.TypeOfLight)); } _krypton.Lights.Add(new Light2D { Angle = props.Rotation, Color = props.Color, Intensity = props.Intensity, Fov = props.FieldOfView, Position = props.Position, IsOn = props.IsOn, Range = props.Range, ShadowType = convertShadowType(props.ShadowType), Texture = texture }); }); activeLayer.OfType <RectangularHullEditor>( ).ForEach( light => { var props = (RectangularHullProperties)light.ItemProperties; ShadowHull shadowHull = ShadowHull.CreateRectangle(new Vector2(props.Width, props.Height)); shadowHull.Angle = props.Rotation; shadowHull.Opacity = props.Opacity; shadowHull.Position = props.Position + new Vector2(props.Width / 2, props.Height / 2); shadowHull.Scale = props.Scale; shadowHull.Visible = props.Visible; _krypton.Hulls.Add(shadowHull); }); activeLayer.OfType <CircularHullEditor>( ).ForEach( light => { var props = (CircularHullProperties)light.ItemProperties; ShadowHull shadowHull = ShadowHull.CreateCircle(props.Radius, props.Sides); shadowHull.Opacity = props.Opacity; shadowHull.Position = props.Position; shadowHull.Scale = props.Scale; shadowHull.Visible = props.Visible; _krypton.Hulls.Add(shadowHull); }); activeLayer.OfType <ConvexHullEditor>( ).ForEach( light => { var props = (ConvexHullProperties)light.ItemProperties; Vector2[] worldPoints = props.WorldPoints.ToArray( ); // === DON'T SET THE POSITION!! === ShadowHull shadowHull = ShadowHull.CreateConvex(ref worldPoints); shadowHull.Opacity = props.Opacity; shadowHull.Visible = props.Visible; _krypton.Hulls.Add(shadowHull); }); activeLayer.OfType <PreShapedConvexHullEditor>( ).ForEach( light => { var props = (ConvexHullProperties)light.ItemProperties; Vector2[] worldPoints = props.WorldPoints.ToArray( ); // === DON'T SET THE POSITION!! === ShadowHull shadowHull = ShadowHull.CreateConvex(ref worldPoints); shadowHull.Opacity = props.Opacity; shadowHull.Visible = props.Visible; _krypton.Hulls.Add(shadowHull); }); }
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); }
/// <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); playerImage = Content.Load <Texture2D>("player"); // Create a new simple point light texture to use for the lights this.lightTexture = LightTextureBuilder.CreatePointLight(this.GraphicsDevice, 1024); //Offscreen render PresentationParameters pp = GraphicsDevice.PresentationParameters; renderTarget = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, true, GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24, 0, RenderTargetUsage.PreserveContents); stdFont = Content.Load <SpriteFont>("Font/stdFont"); //for (int x = 0; x < 200; x++) //{ // Sprite spam = new Sprite(playerImage, new Vector2((float)random.NextDouble() * 500 + 700, (float)random.NextDouble() * 500 + 400), true, krypton); // spam.Velocity = new Vector2((float)random.NextDouble() * 1.5f -1 , (float)random.NextDouble() * 1.5f -1); // sprites.Add(spam); // } /* * // 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 //Test code - light spammer }
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); } }