public List<Coordinates> CheckAdjacentSquares(Coordinates Square, Coordinates Parent, Coordinates Destination, List<Coordinates> ClosedList, List<Coordinates> OpenList) { List<Coordinates> WalkableSquares = new List<Coordinates>(); Coordinates CheckingSquare = new Coordinates(Square.X + Coordinates.Step, Square.Y); // East if (IsTileWalkable(CheckingSquare, ClosedList, OpenList) || SamePosition(CheckingSquare, Destination)) { WalkableSquares.Add(new Coordinates(CheckingSquare.X, CheckingSquare.Y, CalculateHeuristic(CheckingSquare, Destination), (G + Parent.G), Parent)); } CheckingSquare = new Coordinates(Square.X - Coordinates.Step, Square.Y); // West if (IsTileWalkable(CheckingSquare, ClosedList, OpenList) || SamePosition(CheckingSquare, Destination)) { WalkableSquares.Add(new Coordinates(CheckingSquare.X, CheckingSquare.Y, CalculateHeuristic(CheckingSquare, Destination), (G + Parent.G), Parent)); } CheckingSquare = new Coordinates(Square.X, Square.Y - Coordinates.Step); // North if (IsTileWalkable(CheckingSquare, ClosedList, OpenList) || SamePosition(CheckingSquare, Destination)) { WalkableSquares.Add(new Coordinates(CheckingSquare.X, CheckingSquare.Y, CalculateHeuristic(CheckingSquare, Destination), (G + Parent.G), Parent)); } CheckingSquare = new Coordinates(Square.X, Square.Y + Coordinates.Step); // South if (IsTileWalkable(CheckingSquare, ClosedList, OpenList) || SamePosition(CheckingSquare, Destination)) { WalkableSquares.Add(new Coordinates(CheckingSquare.X, CheckingSquare.Y, CalculateHeuristic(CheckingSquare, Destination), (G + Parent.G), Parent)); } return WalkableSquares; }
public Creature(string name, Coordinates coordinates, int targetID, int magicstr = 0, int strength = 1, int health = 1, int id = 0, int defense = 0, int experience = 1, int spriteid = 0, List<Loot> loot = null, List<Spell> spell = null) { /* Spöken */ Name = name; Position = coordinates; SpawnPosition = coordinates; MaxHealth = health; Health = health; ID = id; TargetID = targetID; SuperPowerSteps = -1; Visible = true; EntityType = Entity.CreatureEntity; Strength = strength; TimeOfLastAttack = 0; Defense = defense; Experience = experience; MagicStrength = magicstr; if(loot != null) { LootList.AddRange(loot); } if(spell != null) { Spells.AddRange(spell); } SpriteID = spriteid; }
public UI(Texture2D sprite, int id, int entitytype, Coordinates pos, string name = "null", int _SpellID = 0) { Sprite = sprite; ID = id; EntityType = entitytype; Position = pos; Name = name; SpellID = _SpellID; }
public Tile(string name, Coordinates pos, ConsoleColor color, int tileID = 0, bool visible = true) { Name = name; ID = tileID; Position = pos; Color = color; Visible = true; EntityType = Entity.TileEntity; }
public Tile(string name, int spriteID, Coordinates pos, int tileID, bool visible = true, bool walkable = true) { Name = name; ID = tileID; Position = pos; SpriteID = spriteID; Visible = visible; Walkable = walkable; }
public SpriteObject(Texture2D sprite, int id, int entitytype, string name, bool walkthrough = true, bool _MovePlayer = false, Coordinates _MovePos = null) { Sprite = sprite; ID = id; EntityType = entitytype; SpriteName = name; Walkable = walkthrough; MovePlayer = _MovePlayer; RelativeMovePosition = _MovePos; }
public DamageObject(Creature monster, int Damage, int _text_type, int _StartTime, int _EndTime, int id = 0, Coordinates pos = null) { creature = monster; damageDealt = Damage; ID = id; EndTime = _EndTime; StartTime = _StartTime; Position = pos; Text_Type = _text_type; }
public DamageObject(Creature monster, int Damage, bool healing, int _StartTime, int _EndTime, int id = 0, Coordinates pos = null) { creature = monster; damageDealt = Damage; ID = id; EndTime = _EndTime; StartTime = _StartTime; Position = pos; Healing = healing; }
public bool IsTileInList(Coordinates Tile, List<Coordinates> List) { bool isClosed = false; for (int i = 0; i < List.Count; i++) { if (List[i].X == Tile.X && List[i].Y == Tile.Y) { isClosed = true; } } return isClosed; }
public Coordinates GetTileInList(Coordinates Tile, List<Coordinates> List) { Coordinates TileCoordinates = new Coordinates(); for (int i = 0; i < List.Count; i++) { if (List[i].X == Tile.X && List[i].Y == Tile.Y) { TileCoordinates = List[i]; break; } } return TileCoordinates; }
public Animation(int _Duration, double _StartOffsetY, int _Steps, int _StartTime, string _Text = "", int id = 0, Coordinates pos = null) { ID = id; EndTime = _StartTime + _Duration; StartTime = _StartTime; Position = pos; Steps = _Steps; Duration = _Duration; StartOffsetY = _StartOffsetY; Text = _Text; }
public Tile(string name, int spriteID, Coordinates pos, Coordinates drawPos, int tileID, bool visible = true, bool walkable = true, int zorder = 0, bool movePlayer = false, Coordinates movePos = null) { Name = name; ID = tileID; Position = pos; drawPosition = drawPos; SpriteID = spriteID; Visible = visible; Walkable = walkable; EntityType = Entity.TileEntity; Z_order = zorder; MovePlayer = movePlayer; RelativeMovePosition = movePos; }
public Player(string name, Coordinates coordinates, int health = 1, int mana = 1, int level = 1, int id = 0) { /* Spelare */ Name = name; Position = coordinates; SpawnPosition = coordinates; MaxHealth = health; Health = health; ID = id; Visible = true; EntityType = Entity.PlayerEntity; TargetID = -1; EquippedItems = new Equipment(); MaxMana = mana; Mana = mana; Level = level; MagicStrength = 0; }
public Item(string name, string wearslot, Coordinates pos, int spriteid, int id = 0, int strength = 0, int defense = 0, bool visible = true) { Name = name; ID = id; Position = pos; Visible = visible; EntityType = Entity.ItemEntity; SpriteID = spriteid; Strength = strength; Defense = defense; WearSlot = wearslot; if (wearslot == ItemSlot.Bag) { Container = new Backpack(); Container.ID = this.ID; Container.ItemID = spriteid; } Parent = new Backpack(); }
public Item(string name, int realid, string wearslot, Coordinates pos, int spriteid, int id = 0, int strength = 0, int defense = 0, bool visible = true, int wearingplayerid = 0, int zorder = 0) { RealID = realid; Name = name; ID = id; Position = pos; Visible = visible; EntityType = Entity.ItemEntity; SpriteID = spriteid; Strength = strength; Defense = defense; WearSlot = wearslot; WearingPlayerID = wearingplayerid; if (wearslot == ItemSlot.Bag) { Container = new Backpack(); Container.ID = this.ID; Container.ItemID = spriteid; } Z_order = zorder; Parent = new Backpack(); }
public void SetFoodEaten(Coordinates step) { for (int i = 0; i < Food.Count; i++) { if (SamePosition(step, Food[i].Position) && Food[i].Visible) { Food[i].Visible = false; } } }
public int CalculateHeuristic(Coordinates Source, Coordinates Destination) { return (G + (G * (Math.Abs(Source.X - Destination.X) + Math.Abs(Source.Y - Destination.Y)))); // Manhattan-metoden }
public bool SamePosition(Coordinates Source, Coordinates Destination) { return (Source.X == Destination.X && Source.Y == Destination.Y); }
public List<Coordinates> PathTo(Coordinates Target, Coordinates FromCreature) { List<Coordinates> OpenList = new List<Coordinates>(); // Den öppna listan med rutor som vi fortfarande kollar List<Coordinates> ClosedList = new List<Coordinates>(); // Den stängda listan med rutor som vi inte behöver kolla längre Coordinates Parent = FromCreature; // Parent-rutan Coordinates Destination = Target; // Destinationen int tries = 0; bool havePath = false; OpenList.Add(Parent); // Lägg till startpunkten OpenList.AddRange(CheckAdjacentSquares(Parent, Parent, Destination, ClosedList, OpenList)); // Lägg till de rutor runtom som går att gå på i den öppna listan OpenList.Remove(Parent); // Ta bort startpunkten ClosedList.Add(Parent); // Lägg till startpunkten i listan med rutor vi inte behöver kolla while (!havePath) { if (tries == 4 * 200) { break; } Parent = LowestFScore(OpenList); if (bool.Parse(ConfigurationManager.AppSettings["DebugMode"])) { //draw.DrawObject(new Entity("F", new Coordinates(Parent.X, Parent.Y))); // Endast för debugging } OpenList.Remove(Parent); ClosedList.Add(Parent); OpenList.AddRange(CheckAdjacentSquares(Parent, Parent, Destination, ClosedList, OpenList)); if (IsTileInList(Target, ClosedList)) { havePath = true; } if (OpenList.Count == 0 && havePath == false) { break; } tries += 4; } List<Coordinates> path = new List<Coordinates>(); if (havePath) { Destination = GetTileInList(Target, ClosedList); path.Add(Destination); while (Destination.hasParent()) { if (bool.Parse(ConfigurationManager.AppSettings["DebugMode"])) { draw.DrawObject(new Entity("F", new Coordinates(Destination.X, Destination.Y))); // Endast för debugging } Destination = Destination.Parent; path.Add(Destination); } } return path; }
public Coordinates LowestFScore(List<Coordinates> OpenList) { Coordinates lowestF = new Coordinates(); for (int i = 0; i < OpenList.Count; i++) { if (i == 0) { lowestF = OpenList[i]; } else { if (OpenList[i].F < lowestF.F) { lowestF = OpenList[i]; } } } return lowestF; }
public Map(Coordinates WindowSize) { windowSize = WindowSize; }
public int DistanceTo(Coordinates Source, Coordinates Destination) { return (Math.Abs((Source.X - Destination.X) + Math.Abs(Source.Y - Destination.Y))); }
public int DistanceToDiagonal(Coordinates Source, Coordinates Destination) { return (int)Math.Sqrt(Math.Pow((Source.X - Destination.X), 2) + Math.Pow(Source.Y - Destination.Y, 2)); }
public void UnequipItem(Item item, UI equipment, Coordinates target) { item.Slot = null; item.Position = new Coordinates(target.X, target.Y); Players[0].UnequipItem(equipment.Name); }
public void ThrowItemToBag(Item item, Backpack Bag, Coordinates target, UI SourceEquipment = null, Backpack Parent = null) { if (Parent != null) { Parent.RemoveItem(item); } item.Slot = null; item.Position = new Coordinates(target.X, target.Y); Bag.AddItem(item); if (SourceEquipment != null) { Players[0].UnequipItem(SourceEquipment.Name); } }
public bool IsTileWalkable(Coordinates Tile) { bool tileWalkable = true; int TileID = GetTileIDFromTile(Tile); if (TileID != -1) /* TODO: When map is finished, IsTileWalkable() should return false; if TileID == -1 (it should not be possible to walk where there is no sprite)*/ { tileWalkable = GetTileByID(TileID).Walkable; } if (tileWalkable) { tileWalkable = !IsTilePlayer(Tile); } if (tileWalkable) { tileWalkable = !IsTileCreature(Tile); } if (tileWalkable) { tileWalkable = !IsTileFood(Tile); } if (tileWalkable) { tileWalkable = !OutOfBoundaries(Tile); } return tileWalkable; }
public void MoveCreature(Entity creature, Coordinates step) { if (IsTileWalkable(step) && DistanceTo(creature.Position, step) == Coordinates.Step) { creature.Position = new Coordinates(step.X, step.Y); } //else //{ // int EntityType = GetEntityTypeFromTile(step); // if (EntityType == Entity.CreatureEntity) // { // /* TODO: Change Players[0] to a variable ID and add method to attack other players to allow for multiplayer */ // if (creature.EntityType == Entity.PlayerEntity) // { // Creature monster = GetCreatureByID(GetCreatureIDFromTile(step)); // PlayerAttack(Players[0], monster); // } // } // else if (EntityType == Entity.PlayerEntity) // { // if (creature.EntityType == Entity.CreatureEntity) // { // CreatureAttack(GetCreatureByID(creature.ID), Players[0]); // } // } // else if (EntityType == Entity.ItemEntity) // { // /* TODO: Change Players[0] to a variable ID to allow for multiplayer */ // Eat(Players[0], step); // } //} }
public bool OutOfBoundaries(Coordinates Coordinates) { return !(Coordinates.X >= 0 && Coordinates.Y >= 0 && Coordinates.X < windowSize.X && Coordinates.Y < windowSize.Y); }
public bool IsTileWalkable(Coordinates Tile, List<Coordinates> ClosedList, List<Coordinates> OpenList) { return (map.IsTileWalkable(Tile) && !IsTileInList(Tile, ClosedList) && !IsTileInList(Tile, OpenList)); }
public void ThrowItemFromBag(Item item, Coordinates target) { item.Slot = null; item.Position = new Coordinates(target.X, target.Y); item.Parent.RemoveItem(item); }