示例#1
1
        public Point GetDestination(Point destination, FixedObject destObject, Hero hero)
        {
            var cell = Map.PointToCell(destination);
            var obj = Game.Map.GetObjectFromCell(cell);

            var largeObjectOuter = obj as LargeObjectOuterAbstract;

            if(largeObjectOuter == null)
                return destination;

            var startingPoint = new Point(cell.X - largeObjectOuter.PlaceInObject.X, cell.Y - largeObjectOuter.PlaceInObject.Y);

            var innerObject = largeObjectOuter.InnerObject as Wickiup;
            var totDist = Int32.MaxValue;
            Point p = null;
            var heroPos = Map.PointToCell(hero.Position);

            for (int i = 0; i < (int)innerObject.Size.Width + 2; i++ )
            {
                for (int j = 0; j < (int) innerObject.Size.Height + 2; j++)
                {
                    if (i > 0 && i < (int) innerObject.Size.Width + 1 && j > 0 && j < (int) innerObject.Size.Height + 1)
                        continue;

                    var curPoint = new Point(i - 1, j - 1);
                    bool isPassable;

                    if (j == 0 || j == (int) innerObject.Size.Height + 1)
                    {
                        isPassable = innerObject.HorizontalBorder[i, j == 0 ? 0 : 1];
                    }
                    else
                    {
                        isPassable = innerObject.VerticalBorder[j - 1, i == 0 ? 0 : 1];
                    }

                    if (!isPassable)
                        continue;

                    int totdistX = Math.Abs(heroPos.X - startingPoint.X - curPoint.X);
                    int totdistY = Math.Abs(heroPos.Y - startingPoint.Y - curPoint.Y);

                    var curtotDist = totdistX*totdistX + totdistY*totdistY;

                    if (curtotDist < totDist)
                    {
                        totDist = curtotDist;
                        p = curPoint;
                    }
                }
            }

            var newCenterPoint = Map.CellToPoint(new Point(startingPoint.X + p.X, startingPoint.Y + p.Y));
            var x = newCenterPoint.X + Map.CELL_MEASURE / 2 + (p.X > -1 && p.X < innerObject.Size.Width ? 0 :  p.X == -1 ? Map.CELL_MEASURE / 2 + 2 : -Map.CELL_MEASURE / 2 - 2);
            var y = newCenterPoint.Y + Map.CELL_MEASURE / 2 + (p.Y > -1 && p.Y < innerObject.Size.Height ? 0 : p.Y == -1 ? Map.CELL_MEASURE / 2 + 2 : -Map.CELL_MEASURE / 2 - 2);

            innerPoint = startingPoint;

            return new Point(x, y);
        }
示例#2
0
 //adding fixed objects
 public void CreateAndAddFixedObjectToMap(FixedObject fixedObject, double left, double top)
 {
     Canvas.SetLeft(fixedObject.Image, left);
     Canvas.SetTop(fixedObject.Image, top);
     _gameArea.Children.Add(fixedObject.Image);
     _fixedObjects.Add(fixedObject);
 }
示例#3
0
    static public FixedObject CreatePrototype(string _objType, float _moveCost = 1f, int w = 1, int h = 1)
    {
        FixedObject obj = new FixedObject();

        obj.objectType   = _objType;
        obj.movementCost = _moveCost;
        obj.width        = w;
        obj.height       = h;

        return(obj);
    }
示例#4
0
    protected void CreateFixedObjectPrototypes()
    {
        fixedObjPrototypes = new Dictionary <string, FixedObject> ();

        // Temp function
        // Will later be replaced by reading from data file
        FixedObject wallPrototype = FixedObject.CreatePrototype(
            "Wall",     // Object identifier
            0,          // Movement cost - (higher numbers mean slower movement, and 0 means this object is impassable)
            1,          // Width
            1           // Height
            );

        fixedObjPrototypes.Add("Wall", wallPrototype);
    }
示例#5
0
            public TestMap(int sizeX, int sizeY, bool addObjects)
            {
                _localMap = new FixedObject[sizeX, sizeY];

                if (addObjects)
                {
                    for (int i = 0; i < _localMap.GetLength(0); i++)
                    {
                        for (int j = 0; j < _localMap.GetLength(1); j++)
                        {
                            _localMap[i, j] = new FixedObject();
                        }
                    }
                }
            }
示例#6
0
    // Returns a bool to identify if the assignment of the object to the tile is successful
    public bool SetFixedObject(FixedObject objInstance)
    {
        if (objInstance == null)
        {
            // Uninstall any object already fixed to tile
            fixedObject = null;
            return(true);
        }

        if (fixedObject != null)
        {
            Debug.LogError("Assigning a fixed object on a tile that already has one.");
            return(false);
        }

        fixedObject = objInstance;
        return(true);
    }
示例#7
0
    static protected FixedObject InstallObject(FixedObject proto, Tile tile)
    {
        FixedObject obj = new FixedObject();

        obj.objectType   = proto.objectType;
        obj.movementCost = proto.movementCost;
        obj.width        = proto.width;
        obj.height       = proto.height;

        obj.tile = tile;

        if (tile.SetFixedObject(obj) == false)
        {
            // In the event that the assignment failed (possibly due to another object already inhabiting that tile)
            // Do NOT return newly instantiated object (it will be garbage collected)
            return(null);
        }

        return(obj);
    }
示例#8
0
 public Point GetDestination(Point destination, FixedObject destObject, Hero hero)
 {
     return destination;
 }
示例#9
0
 public Point GetDestination(Point destination, FixedObject destObject, Hero hero)
 {
     return(destination);
 }
示例#10
0
        public bool IsCollidingWithFixedObject(List <FixedObject> fixedObjects, Point newPosition, out FixedObject colidedObject)
        //checks collixion with fixed objects and outputs the spesific object it collided with gives null if there is no collision

        {
            foreach (FixedObject fixedObject in fixedObjects)
            {
                bool isColliding = AreImagesColliding(Image, newPosition.Top, newPosition.Left, fixedObject.Image);
                if (isColliding)
                {
                    colidedObject = fixedObject;
                    return(true);
                }
            }
            colidedObject = null;
            return(false);
        }
示例#11
0
        public Point GetDestination(Point destination, FixedObject destObject, Hero hero)
        {
            var cell = Map.PointToCell(destination);
            var obj  = Game.Map.GetObjectFromCell(cell);

            var largeObjectOuter = obj as LargeObjectOuterAbstract;

            if (largeObjectOuter == null)
            {
                return(destination);
            }

            var startingPoint = new Point(cell.X - largeObjectOuter.PlaceInObject.X, cell.Y - largeObjectOuter.PlaceInObject.Y);

            var   innerObject = largeObjectOuter.InnerObject as Wickiup;
            var   totDist     = Int32.MaxValue;
            Point p           = null;
            var   heroPos     = Map.PointToCell(hero.Position);

            for (int i = 0; i < (int)innerObject.Size.Width + 2; i++)
            {
                for (int j = 0; j < (int)innerObject.Size.Height + 2; j++)
                {
                    if (i > 0 && i < (int)innerObject.Size.Width + 1 && j > 0 && j < (int)innerObject.Size.Height + 1)
                    {
                        continue;
                    }

                    var  curPoint = new Point(i - 1, j - 1);
                    bool isPassable;

                    if (j == 0 || j == (int)innerObject.Size.Height + 1)
                    {
                        isPassable = innerObject.HorizontalBorder[i, j == 0 ? 0 : 1];
                    }
                    else
                    {
                        isPassable = innerObject.VerticalBorder[j - 1, i == 0 ? 0 : 1];
                    }

                    if (!isPassable)
                    {
                        continue;
                    }

                    int totdistX = Math.Abs(heroPos.X - startingPoint.X - curPoint.X);
                    int totdistY = Math.Abs(heroPos.Y - startingPoint.Y - curPoint.Y);

                    var curtotDist = totdistX * totdistX + totdistY * totdistY;

                    if (curtotDist < totDist)
                    {
                        totDist = curtotDist;
                        p       = curPoint;
                    }
                }
            }

            var newCenterPoint = Map.CellToPoint(new Point(startingPoint.X + p.X, startingPoint.Y + p.Y));
            var x = newCenterPoint.X + Map.CellMeasure / 2 + (p.X > -1 && p.X < innerObject.Size.Width ? 0 :  p.X == -1 ? Map.CellMeasure / 2 + 2 : -Map.CellMeasure / 2 - 2);
            var y = newCenterPoint.Y + Map.CellMeasure / 2 + (p.Y > -1 && p.Y < innerObject.Size.Height ? 0 : p.Y == -1 ? Map.CellMeasure / 2 + 2 : -Map.CellMeasure / 2 - 2);

            innerPoint = startingPoint;

            return(new Point(x, y));
        }