Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using xTile;
- using xTile.Display;
- using xTile.ObjectModel;
- using Krypton;
- using Krypton.Lights;
- namespace RenaissanceAdventure.level
- {
- public class TestChambers:TiAPI.Component.tileGameLevel
- {
- KryptonEngine krypton;
- private Texture2D mLightTexture;
- Light2D playerLight;
- public TestChambers(Map map,Game1 instance)
- {
- TileMap = map;
- DisplayWidth = TileMap.DisplayWidth;
- DisplayHeight = TileMap.DisplayHeight;
- this.krypton = new KryptonEngine(instance, "KryptonEffect");
- }
- public override void LoadContent(Microsoft.Xna.Framework.Content.ContentManager Content,GraphicsDevice device)
- {
- ID = "TestChambers";
- BackColor = Color.Black;
- levelHeading = Content.Load<Texture2D>("sprites\\gui\\levelHeader\\TestChamber");
- usesLighting = true;
- base.LoadContent(Content);
- BGMCue = "Cue_PuzzleGame";
- GameObjects.Add(Game1.player);
- // Create a new simple point light texture to use for the lights
- this.mLightTexture = LightTextureBuilder.CreatePointLight(device, 512);
- // Create some lights
- playerLight = new Light2D()
- {
- Texture = mLightTexture,
- Range = 96,
- Color = new Color(255, 255, 255),
- Intensity = 0.5f,
- Angle = MathHelper.TwoPi * 0,
- X = 100,
- Y = -100,
- };
- krypton.AmbientColor = new Color(48, 48, 48, 255);
- }
- public override void InitalizeGFX()
- {
- this.krypton.Initialize();
- base.InitalizeGFX();
- }
- void addLight(Color c, Vector2 position, int range)
- {
- Light2D lt = new Light2D()
- {
- Texture = mLightTexture,
- Range = range,
- Color = c,
- Intensity = 1.0f,
- Angle = MathHelper.TwoPi * 0,
- X = position.X,
- Y = position.Y,
- };
- krypton.Lights.Add(lt);
- }
- public override void InitalizeLogic()
- {
- krypton.Lights.Clear();
- krypton.Lights.Add(playerLight);
- SolidRectangles.Clear(); actionTiles.Clear();
- foreach (xTile.Layers.Layer current in TileMap.Layers)
- {
- if (current.Id == "lightingLayer")
- {
- PropertyValue r = 0;
- PropertyValue g = 0;
- PropertyValue b = 0;
- PropertyValue range = 0;
- int xx = 0, yy = 0;
- do
- {
- for (xx = 0; xx < current.LayerWidth; xx++)
- {
- if (current.Tiles[xx, yy] != null)
- {
- current.Tiles[xx, yy].Properties.TryGetValue("r", out r);
- current.Tiles[xx, yy].Properties.TryGetValue("g", out g);
- current.Tiles[xx, yy].Properties.TryGetValue("b", out b);
- current.Tiles[xx, yy].Properties.TryGetValue("range", out range);
- if (r == null)
- {
- r = 255;
- }
- if (g == null)
- {
- g = 255;
- }
- if (b == null)
- {
- b = 255;
- }
- if (range == null)
- {
- range = 32;
- }
- addLight(new Color(r, g, b), new Vector2(xx*8, -yy*8), range);
- }
- }
- yy++;
- } while (yy < current.LayerHeight);
- }
- PropertyValue Logic = 0;
- PropertyValue solid = 0;
- PropertyValue action = "";
- PropertyValue pseudo = 0;
- PropertyValue spawnpoint = "";
- PropertyValue Entity = "";
- current.Properties.TryGetValue("Logic", out Logic);
- current.Properties.TryGetValue("solid", out solid);
- if (solid == null)
- {
- solid = 0;
- }
- if (Logic == null)
- {
- Logic = 0;
- }
- if (Logic == 1)
- {
- int spx = 0, spy = 0;
- int xx = 0, yy = 0;
- do
- {
- for (xx = 0; xx < current.LayerWidth; xx++)
- {
- if (current.Tiles[xx, yy] != null)
- {
- current.Tiles[xx, yy].Properties.TryGetValue("SpawnPlayer", out pseudo);
- current.Tiles[xx, yy].Properties.TryGetValue("action", out action);
- current.Tiles[xx, yy].Properties.TryGetValue("spawnpoint", out spawnpoint);
- current.Tiles[xx, yy].Properties.TryGetValue("Entity", out Entity);
- }
- if (action == null)
- {
- action = "";
- }
- if (pseudo == null)
- {
- pseudo = 0;
- }
- if (pseudo == 1)
- {
- spx = xx * current.TileWidth;
- spy = yy * current.TileHeight;
- pseudo = 0;
- }
- if (spawnpoint == null)
- {
- spawnpoint = "";
- }
- if (spawnpoint == Game1.player.LastLevelID && Game1.player.LastLevelID != this.ID && !string.IsNullOrEmpty(Game1.player.LastLevelID))
- {
- spx = xx * current.TileWidth;
- spy = yy * current.TileHeight;
- spawnpoint = "";
- //Game1.player.Position = new Vector2(xx * current.TileWidth, yy * current.TileHeight);
- }
- if (Entity == null)
- {
- Entity = "";
- }
- if (Entity == "SoundEntity")
- {
- //this.GameObjects.Add(new Objects.Entity.TestSoundEntity(new Vector2(xx * current.TileHeight, yy * current.TileHeight)));
- Entity = "";
- }
- if (action != "")
- {
- if (action.ToString().StartsWith("Health."))
- {
- actionTiles.Add(new TiAPI.Component.ActionTile(action, new Rectangle(xx * current.TileWidth, yy * current.TileHeight, current.TileWidth, current.TileHeight), Color.Red));
- }
- else
- {
- actionTiles.Add(new TiAPI.Component.ActionTile(action, new Rectangle(xx * current.TileWidth, yy * current.TileHeight, current.TileWidth, current.TileHeight)));
- }
- action = null;
- }
- }
- yy++;
- } while (yy < current.LayerHeight);
- Game1.player.Position = new Vector2(spx, spy);
- }
- if (solid == 1)
- {
- int xsx, ysy = 0;
- do
- {
- for (xsx = 0; xsx < current.LayerWidth; xsx++)
- {
- if (current.Tiles[xsx, ysy] != null)
- {
- SolidRectangles.Add(new Rectangle(xsx * current.TileWidth, ysy * current.TileHeight, current.TileWidth, current.TileHeight));
- }
- }
- ysy++;
- } while (ysy < current.LayerHeight);
- }
- }
- }
- public override void Update(GameTime gt,xTile.Dimensions.Location vportLoc)
- {
- LightCount = krypton.Lights.Count;
- base.Update(gt, vportLoc);
- }
- /// <summary>
- /// Overridden class of tileGameLevel
- /// </summary>
- /// <param name="device">The XTile DisplayDevice</param>
- /// <param name="viewport">XTile's Camera</param>
- /// <param name="offset">View Offset</param>
- /// <param name="wrap">Wrap around, true if no walls.</param>
- /// <param name="spritebatch"></param>
- /// <param name="ViewportLoc">Viewport location (probably overkill)</param>
- public override void Draw(IDisplayDevice device, xTile.Dimensions.Rectangle viewport, xTile.Dimensions.Location offset, bool wrap, SpriteBatch spritebatch, xTile.Dimensions.Location ViewportLoc)
- {
- playerLight.IsOn = true;
- this.playerLight.Position = new Vector2(Game1.player.Position.X, -Game1.player.Position.Y);
- Matrix world = Matrix.CreateWorld(new Vector3(0, 0, 0), Vector3.Forward, Vector3.Up);
- Matrix view = Matrix.CreateTranslation(new Vector3(-ViewportLoc.X-viewport.Width/2, ViewportLoc.Y+viewport.Height/2, 0));
- Matrix projection = Matrix.CreateOrthographic(viewport.Width, viewport.Height, 0, 0);
- // Assign the matrix and pre-render the light map.
- // Make sure not to change the position of any lights or shadow hulls after this call, as it won't take effect till the next frame!
- this.krypton.Matrix = world*view*projection;
- this.krypton.Bluriness = 0;
- this.krypton.LightMapPrepare();
- // ----- DRAW STUFF HERE ----- //
- // By drawing here, you ensure that your scene is properly lit by krypton.
- spritebatch.Begin();
- spritebatch.Draw(Game1.backgroundColor, new Rectangle(0, 0, viewport.Width, viewport.Height), Color.White);
- spritebatch.End();
- base.Draw(device, viewport, offset, wrap, spritebatch, ViewportLoc);
- // Drawing after KryptonEngine.Draw will cause you objects to be drawn on top of the light map (can be useful, fyi)
- // ----- DRAW STUFF HERE ----- //
- this.krypton.Draw(null);
- base.DrawHeading(device, viewport, offset, wrap, spritebatch, ViewportLoc);
- if (Game1.ShowBounds)
- {
- foreach (Rectangle item in SolidRectangles)
- {
- if (item.Intersects(new Rectangle(viewport.X, viewport.Y, viewport.Width, viewport.Height)))
- {
- spritebatch.Begin();
- spritebatch.Draw(Game1.bounds, new Rectangle(-ViewportLoc.X + item.X, -ViewportLoc.Y + item.Y, item.Width, item.Height), Color.Black);
- spritebatch.End();
- }
- }
- foreach (TiAPI.Component.ActionTile item in actionTiles)
- {
- item.draw(spritebatch, ViewportLoc);
- }
- foreach (Krypton.Lights.Light2D item in krypton.Lights)
- {
- spritebatch.Begin();
- spritebatch.Draw(Game1.bounds, new Rectangle(-ViewportLoc.X + (int)item.X - (int)item.Bounds.Width / 2, -ViewportLoc.Y - (int)item.Y - (int)item.Bounds.Height / 2, (int)item.Bounds.Width, (int)item.Bounds.Height), item.Color);
- spritebatch.End();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement