public Pathfinder(TileLayer layer) { levelWidth = layer.Width(); levelHeight = layer.Height(); this.layer = layer; InitializeSearchNodes(layer); }
public EntityManager(TileLayer layer, StreamReader sr, ContentManager content) : this(layer) { do { Entity e; sr.ReadLine(); string tag = sr.ReadLine(); sr.ReadLine(); string group = sr.ReadLine(); sr.ReadLine(); Point pos = Utility.ParsePoint(sr.ReadLine()); sr.ReadLine(); string type = sr.ReadLine(); sr.ReadLine(); e = new Entity(tag, group, layer, pos, EntityInfo.FromFile(type), content); Add(e); } while (sr.ReadLine() != null); }
public Entity(string tag, string group, TileLayer layer, Point position, EntityInfo info, ContentManager content) { if (!init) { initializeBehaviors(); init = true; } Tag = tag; Group = group; Health = new StatBar(info.health); this.speed = info.speed; this.skill = info.skill; this.inventory = new Inventory(5, this); this.layer = layer; this.position = position; texture = content.Load <Texture2D>("Sprites/" + info.texture); iconTexture = content.Load <Texture2D>("UI/" + info.icon); healthbarTexture = content.Load <Texture2D>("UI/" + info.healthbar); animation = new FrameAnimation(2, 32, 32, 0, 0); animation.FramesPerSecond = 2; foreach (string item in info.items) { Item i = Item.FromFile(item, Group); inventory.Add(i); if (i is Weapon) { weapon = i as Weapon; } } if (behaviors.ContainsKey(info.behavior)) { Behavior += behaviors[info.behavior]; } }
public Cursor(TileLayer layer, Texture2D texture, Texture2D arrowTexture, Texture2D overlayTexture, TimeSpan moveTime, Point? location, string group) { this.layer = layer; this.texture = texture; this.arrowTexture = arrowTexture; this.overlayTexture = overlayTexture; this.moveTime = moveTime; if (location.HasValue) this.location = location.Value; Group = group; AddProcess(new Buttons[] { Buttons.A }, new Process(onSelect)); AddProcess(new Buttons[] { Buttons.X }, new Process(onTab)); AddProcess(new Buttons[] { Buttons.B }, new Process(onExit)); AddProcess(new Buttons[] { Buttons.Y }, new Process(onOpen)); }
public Cursor(TileLayer layer, Texture2D texture, Texture2D arrowTexture, Texture2D overlayTexture, TimeSpan moveTime, Point?location, string group) { this.layer = layer; this.texture = texture; this.arrowTexture = arrowTexture; this.overlayTexture = overlayTexture; this.moveTime = moveTime; if (location.HasValue) { this.location = location.Value; } Group = group; AddProcess(new Buttons[] { Buttons.A }, new Process(onSelect)); AddProcess(new Buttons[] { Buttons.X }, new Process(onTab)); AddProcess(new Buttons[] { Buttons.B }, new Process(onExit)); AddProcess(new Buttons[] { Buttons.Y }, new Process(onOpen)); }
public Entity( string tag, string group, string behavior, double health, int speed, int skill, TileLayer layer, Point position, Texture2D texture, Texture2D iconTexture, Texture2D healthbarTexture) { if (!init) { initializeBehaviors(); init = true; } Tag = tag; Group = group; Health = new StatBar(health); this.speed = speed; this.skill = skill; this.inventory = new Inventory(5, this); this.layer = layer; this.position = position; this.texture = texture; this.iconTexture = iconTexture; this.healthbarTexture = healthbarTexture; animation = new FrameAnimation(2, 32, 32, 0, 0); animation.FramesPerSecond = 2; if (behaviors.ContainsKey(behavior)) { Behavior += behaviors[behavior]; } }
public EntityManager(TileLayer layer) { this.layer = layer; groups.Add("Player"); }
public Cursor(TileLayer layer, Texture2D texture, Texture2D arrowTexture, Texture2D overlayTexture, Point?location, string group) : this(layer, texture, arrowTexture, overlayTexture, TimeSpan.FromSeconds(0.1), location, group) { }
public static TileLayer FromFile(ContentManager content, string filename) { TileLayer layer; using (StreamReader sr = new StreamReader("Content/Levels/" + filename)) { int width = -1, height = -1; if (sr.ReadLine().Equals("[Width]")) width = int.Parse(sr.ReadLine()); if (sr.ReadLine().Equals("[Height]")) height = int.Parse(sr.ReadLine()); if (width == -1 || height == -1) throw new ArgumentException("File format incorrect."); layer = new TileLayer(width, height); string textureFilename = "", layoutFilename = ""; if (sr.ReadLine().Equals("[Texture]")) textureFilename = sr.ReadLine(); if (sr.ReadLine().Equals("[Layout]")) layoutFilename = sr.ReadLine(); if (string.IsNullOrEmpty(textureFilename) || string.IsNullOrEmpty(layoutFilename)) throw new ArgumentException("File format incorrect."); layer.LoadContent(content, textureFilename, "Maps/" + layoutFilename); if (sr.ReadLine().Equals("[Blocked Tiles]")) { string next; List<Int32> tiles = new List<Int32>(); while ((next = sr.ReadLine()) != "[Slow Tiles]" && next != null) { tiles.Add(Int32.Parse(next)); } layer.SetBlockedTiles(tiles.ToArray()); tiles.Clear(); if (next == "[Slow Tiles]") { while ((next = sr.ReadLine()) != "[Cover Tiles]" && next != null) { tiles.Add(Int32.Parse(next)); } layer.SetSlowTiles(tiles.ToArray()); tiles.Clear(); } if (next == "[Cover Tiles]") { while ((next = sr.ReadLine()) != "[Castle Tiles]" && next != null) { tiles.Add(Int32.Parse(next)); } layer.SetCoverTiles(tiles.ToArray()); tiles.Clear(); } if (next == "[Castle Tiles]") { while ((next = sr.ReadLine()) != "[Entities]") { tiles.Add(Int32.Parse(next)); } layer.SetCastleTiles(tiles.ToArray()); tiles.Clear(); } } else { throw new ArgumentException("Improper file format."); } layer.Entities = new EntityManager(layer, sr, content); sr.Close(); } return layer; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { ScreenHelper.Initialize(GraphicsDevice, graphics); ScreenHelper.Camera = new Camera(new Vector2(ScreenHelper.Viewport.Width, ScreenHelper.Viewport.Height), null); // 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 layer = TileLayer.FromFile(Content, "layer.txt"); layer.Entities.BloodTexture = Content.Load<Texture2D>("Sprites/Blood"); layer.Entities.HealingTexture = Content.Load<Texture2D>("Sprites/Healing"); Texture2D cursorTexture = Content.Load<Texture2D>("UI/Cursor_1"); Texture2D arrowTexture = Content.Load<Texture2D>("UI/Arrows"); Texture2D overlayTexture = Content.Load<Texture2D>("UI/Tile Overlays"); Texture2D rogue = Content.Load<Texture2D>("Sprites/Rogue"); Texture2D knight = Content.Load<Texture2D>("Sprites/Knight"); Texture2D priest = Content.Load<Texture2D>("Sprites/Priest"); Texture2D iconTexture = Content.Load<Texture2D>("UI/Phase Icons"); Texture2D healthbarTexture = Content.Load<Texture2D>("UI/Health Bar"); SpriteFont font = Content.Load<SpriteFont>("Fonts/Font1"); ScreenHelper.Font = font; cursor = new Cursor(layer, cursorTexture, arrowTexture, overlayTexture, TimeSpan.FromSeconds(0.1), new Point(20, 20), "Player"); entity = new Entity("", "Enemy", "Healer", 20, 5, 1, layer, new Point(15, 17), priest, iconTexture, healthbarTexture); Weapon w = new Weapon("Healing", "Enemy", 3.0, 1, 1, true); entity.Items.Add(w); entity.EquippedWeapon = w; layer.Entities.Add(entity); entity = new Entity("", "Enemy", "Default", 20, 5, 3, layer, new Point(22, 20), knight, iconTexture, healthbarTexture); entity.EquippedWeapon = Item.FromFile("Sword.txt", "Enemy") as Weapon; layer.Entities.Add(entity); entity = new Entity("", "Enemy", "Default", 20, 5, 3, layer, new Point(15, 16), knight, iconTexture, healthbarTexture); entity.EquippedWeapon = new Weapon("Sword", "Enemy", 2.0, 1, 1); layer.Entities.Add(entity); layer.Pathfind = new Pathfinder(layer); }
public void InitializeSearchNodes(TileLayer layer) { searchNodes = new SearchNode[levelWidth, levelHeight]; for (int x = 0; x < levelWidth; ++x) { for (int y = 0; y < levelHeight; ++y) { SearchNode node = new SearchNode(); node.Position = new Point(x, y); node.Passable = layer.IsPassable(x, y); if (node.Passable) { node.Neighbors = new SearchNode[4]; searchNodes[x, y] = node; } } } for (int x = 0; x < levelWidth; ++x) { for (int y = 0; y < levelHeight; ++y) { SearchNode node = searchNodes[x, y]; if (node == null || !node.Passable) continue; Point[] neighbors = new Point[] { new Point(x, y - 1), new Point(x, y + 1), new Point(x - 1, y), new Point(x + 1, y) }; for (int i = 0; i < neighbors.Length; ++i) { Point position = neighbors[i]; if (position.X < 0 || position.X >= levelWidth || position.Y < 0 || position.Y >= levelHeight) continue; SearchNode neighbor = searchNodes[position.X, position.Y]; if (neighbor == null || !neighbor.Passable) continue; node.Neighbors[i] = neighbor; } } } }
public Entity( string tag, string group, string behavior, double health, int speed, int skill, TileLayer layer, Point position, Texture2D texture, Texture2D iconTexture, Texture2D healthbarTexture) { if (!init) { initializeBehaviors(); init = true; } Tag = tag; Group = group; Health = new StatBar(health); this.speed = speed; this.skill = skill; this.inventory = new Inventory(5, this); this.layer = layer; this.position = position; this.texture = texture; this.iconTexture = iconTexture; this.healthbarTexture = healthbarTexture; animation = new FrameAnimation(2, 32, 32, 0, 0); animation.FramesPerSecond = 2; if (behaviors.ContainsKey(behavior)) Behavior += behaviors[behavior]; }
public Entity(string tag, string group, TileLayer layer, Point position, EntityInfo info, ContentManager content) { if (!init) { initializeBehaviors(); init = true; } Tag = tag; Group = group; Health = new StatBar(info.health); this.speed = info.speed; this.skill = info.skill; this.inventory = new Inventory(5, this); this.layer = layer; this.position = position; texture = content.Load<Texture2D>("Sprites/" + info.texture); iconTexture = content.Load<Texture2D>("UI/" + info.icon); healthbarTexture = content.Load<Texture2D>("UI/" + info.healthbar); animation = new FrameAnimation(2, 32, 32, 0, 0); animation.FramesPerSecond = 2; foreach (string item in info.items) { Item i = Item.FromFile(item, Group); inventory.Add(i); if (i is Weapon) weapon = i as Weapon; } if (behaviors.ContainsKey(info.behavior)) Behavior += behaviors[info.behavior]; }
public Cursor(TileLayer layer, Texture2D texture, Texture2D arrowTexture, Texture2D overlayTexture, Point? location, string group) : this(layer, texture, arrowTexture, overlayTexture, TimeSpan.FromSeconds(0.1), location, group) { }
public void InitializeSearchNodes(TileLayer layer) { searchNodes = new SearchNode[levelWidth, levelHeight]; for (int x = 0; x < levelWidth; ++x) { for (int y = 0; y < levelHeight; ++y) { SearchNode node = new SearchNode(); node.Position = new Point(x, y); node.Passable = layer.IsPassable(x, y); if (node.Passable) { node.Neighbors = new SearchNode[4]; searchNodes[x, y] = node; } } } for (int x = 0; x < levelWidth; ++x) { for (int y = 0; y < levelHeight; ++y) { SearchNode node = searchNodes[x, y]; if (node == null || !node.Passable) { continue; } Point[] neighbors = new Point[] { new Point(x, y - 1), new Point(x, y + 1), new Point(x - 1, y), new Point(x + 1, y) }; for (int i = 0; i < neighbors.Length; ++i) { Point position = neighbors[i]; if (position.X < 0 || position.X >= levelWidth || position.Y < 0 || position.Y >= levelHeight) { continue; } SearchNode neighbor = searchNodes[position.X, position.Y]; if (neighbor == null || !neighbor.Passable) { continue; } node.Neighbors[i] = neighbor; } } } }
public static TileLayer FromFile(ContentManager content, string filename) { TileLayer layer; using (StreamReader sr = new StreamReader("Content/Levels/" + filename)) { int width = -1, height = -1; if (sr.ReadLine().Equals("[Width]")) { width = int.Parse(sr.ReadLine()); } if (sr.ReadLine().Equals("[Height]")) { height = int.Parse(sr.ReadLine()); } if (width == -1 || height == -1) { throw new ArgumentException("File format incorrect."); } layer = new TileLayer(width, height); string textureFilename = "", layoutFilename = ""; if (sr.ReadLine().Equals("[Texture]")) { textureFilename = sr.ReadLine(); } if (sr.ReadLine().Equals("[Layout]")) { layoutFilename = sr.ReadLine(); } if (string.IsNullOrEmpty(textureFilename) || string.IsNullOrEmpty(layoutFilename)) { throw new ArgumentException("File format incorrect."); } layer.LoadContent(content, textureFilename, "Maps/" + layoutFilename); if (sr.ReadLine().Equals("[Blocked Tiles]")) { string next; List <Int32> tiles = new List <Int32>(); while ((next = sr.ReadLine()) != "[Slow Tiles]" && next != null) { tiles.Add(Int32.Parse(next)); } layer.SetBlockedTiles(tiles.ToArray()); tiles.Clear(); if (next == "[Slow Tiles]") { while ((next = sr.ReadLine()) != "[Cover Tiles]" && next != null) { tiles.Add(Int32.Parse(next)); } layer.SetSlowTiles(tiles.ToArray()); tiles.Clear(); } if (next == "[Cover Tiles]") { while ((next = sr.ReadLine()) != "[Castle Tiles]" && next != null) { tiles.Add(Int32.Parse(next)); } layer.SetCoverTiles(tiles.ToArray()); tiles.Clear(); } if (next == "[Castle Tiles]") { while ((next = sr.ReadLine()) != "[Entities]") { tiles.Add(Int32.Parse(next)); } layer.SetCastleTiles(tiles.ToArray()); tiles.Clear(); } } else { throw new ArgumentException("Improper file format."); } layer.Entities = new EntityManager(layer, sr, content); sr.Close(); } return(layer); }