Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
 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;
 }
Ejemplo n.º 8
0
 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;
 }
Ejemplo n.º 9
0
        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;
        }
Ejemplo n.º 10
0
        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;
        }
Ejemplo n.º 11
0
 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;
 }
Ejemplo n.º 12
0
 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;
 }
Ejemplo n.º 13
0
 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;
 }
Ejemplo n.º 14
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();
 }
Ejemplo n.º 15
0
 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();
 }
Ejemplo n.º 16
0
 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;
         }
     }
 }
Ejemplo n.º 17
0
 public int CalculateHeuristic(Coordinates Source, Coordinates Destination)
 {
     return (G + (G * (Math.Abs(Source.X - Destination.X) + Math.Abs(Source.Y - Destination.Y)))); // Manhattan-metoden
 }
Ejemplo n.º 18
0
 public bool SamePosition(Coordinates Source, Coordinates Destination)
 {
     return (Source.X == Destination.X && Source.Y == Destination.Y);
 }
Ejemplo n.º 19
0
        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;
        }
Ejemplo n.º 20
0
 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;
 }
Ejemplo n.º 21
0
 public Map(Coordinates WindowSize)
 {
     windowSize = WindowSize;
 }
Ejemplo n.º 22
0
 public int DistanceTo(Coordinates Source, Coordinates Destination)
 {
     return (Math.Abs((Source.X - Destination.X) + Math.Abs(Source.Y - Destination.Y)));
 }
Ejemplo n.º 23
0
 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));
 }
Ejemplo n.º 24
0
 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);
 }
Ejemplo n.º 25
0
 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);
     }
 }
Ejemplo n.º 26
0
        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;
        }
Ejemplo n.º 27
0
 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);
     //    }
     //}
 }
Ejemplo n.º 28
0
 public bool OutOfBoundaries(Coordinates Coordinates)
 {
     return !(Coordinates.X >= 0 && Coordinates.Y >= 0 && Coordinates.X < windowSize.X && Coordinates.Y < windowSize.Y);
 }
Ejemplo n.º 29
0
 public bool IsTileWalkable(Coordinates Tile, List<Coordinates> ClosedList, List<Coordinates> OpenList)
 {
     return (map.IsTileWalkable(Tile) && !IsTileInList(Tile, ClosedList) && !IsTileInList(Tile, OpenList));
 }
Ejemplo n.º 30
0
 public void ThrowItemFromBag(Item item, Coordinates target)
 {
     item.Slot = null;
     item.Position = new Coordinates(target.X, target.Y);
     item.Parent.RemoveItem(item);
 }