public void ChangePosition(GridPoint oldPos, GridPoint newPos)
 {
     if (_positions.Contains(oldPos))
     {
         _positions.Remove(oldPos);
         _positions.Add(newPos);
     }
 }
        public static HashSet<GridPoint> CreateCircle(GridPoint center, int radius, bool filled = false)
        {
            var points = new HashSet<GridPoint>();
            points.Add(new GridPoint(center.X + radius, center.Y));
            points.Add(new GridPoint(center.X - radius, center.Y));
            points.Add(new GridPoint(center.X, center.Y + radius));
            points.Add(new GridPoint(center.X, center.Y - radius));
            if (filled)
                for (var i = center.X - radius + 1; i < center.X + radius; i++)
                    points.Add(new GridPoint(i, center.Y));

            var x = 0;
            var y = radius;
            var ddfX = 1;
            var ddfY = -2*radius;
            var f = 1 - radius;

            while (x < y)
            {
                if (f >= 0)
                {
                    y -= 1;
                    ddfY += 2;
                    f += ddfY;
                }
                x += 1;
                ddfX += 2;
                f += ddfX;

                points.Add(new GridPoint(center.X + x, center.Y + y));
                points.Add(new GridPoint(center.X - x, center.Y + y));
                if (filled)
                    for (var i = center.X - x + 1; i < center.X + x; i++)
                        points.Add(new GridPoint(i, center.Y + y));
                points.Add(new GridPoint(center.X + x, center.Y - y));
                points.Add(new GridPoint(center.X - x, center.Y - y));
                if (filled)
                    for (var i = center.X - x + 1; i < center.X + x; i++)
                        points.Add(new GridPoint(i, center.Y - y));
                points.Add(new GridPoint(center.X + y, center.Y + x));
                points.Add(new GridPoint(center.X - y, center.Y + x));
                if (filled)
                    for (var i = center.X - y + 1; i < center.X + y; i++)
                        points.Add(new GridPoint(i, center.Y + x));
                points.Add(new GridPoint(center.X + y, center.Y - x));
                points.Add(new GridPoint(center.X - y, center.Y - x));
                if (filled)
                    for (var i = center.X - y + 1; i < center.X + y; i++)
                        points.Add(new GridPoint(i, center.Y - x));
            }
            return points;
        }
 public void MoveEntity(Entity entity, GridPoint oldPos, GridPoint newPos, bool checkPassable = true)
 {
     var canMove = true;
     if (checkPassable == true)
     {
         if (CanPassThroughSquare(entity, newPos) == false)
             canMove = false;
     }
     if (canMove == true)
     {
         var pos = entity.Component<IPosition>();
         pos.ChangePosition(oldPos, newPos);
         GameState.DrawMap();
     }
 }
 private GridPoint GetBuildCoords()
 {
     _buildPos = _buildPos.Add(_buildDelta);
     return _buildPos;
 }
 public GridPoint Add(GridPoint point)
 {
     return new GridPoint(X + point.X, Y + point.Y);
 }
Esempio n. 6
0
 public void ChangePosition(GridPoint oldPos, GridPoint newPos)
 {
     Coords = newPos;
 }
Esempio n. 7
0
 public Position(GridPoint coords)
 {
     Coords = coords;
 }
Esempio n. 8
0
 public Position(int x, int y)
 {
     Coords = new GridPoint(x, y);
 }
Esempio n. 9
0
 public Position()
 {
     Coords = new GridPoint(0, 0);
 }
 public void ChangePosition(GridPoint oldPos, GridPoint newPos)
 {
     _xOffset = _basePosition.X - newPos.X;
     _yOffset = _basePosition.Y - newPos.Y;
 }
 public RelativePosition(GridPoint basePosition, int xOffset, int yOffset)
 {
     _basePosition = basePosition;
     _xOffset = xOffset;
     _yOffset = yOffset;
 }
Esempio n. 12
0
 private bool CanPassThroughSquare(Entity traveler, GridPoint pos)
 {
     var obstacles = from entity in _obstacles
         where entity.Component<IPosition>().IsAtPosition(pos.X, pos.Y) && CanPass(traveler, entity) == false
         select entity;
     return !obstacles.Any();
 }
Esempio n. 13
0
        // Not finished yet
        private void GetMovementPath(Entity entity, GridPoint destination)
        {
            /*
            var mob = entity.GetComponent<Mob>();
            var pos = entity.GetComponent<Position>();

            var blockedEntityCoords = from blocker in _obstacles
                                      let obstacle = blocker.GetComponent<Obstacle>()
                                      where CanPass(mob, obstacle) == false
                                      select blocker.GetComponent<Position>();

            //var blockedTileCoords = Singleton<GameState>.Instance.GetBlockedTileCoords(mob.MovementTypes);

            //var blockedCoords = blockedEntityCoords.Union(blockedTileCoords);
            */
            throw new NotImplementedException();
        }
        private void StartWindow(string name, int x, int y, int width, int height, Color color, int buffer)
        {
            _name = name;
            _position = new GridPoint(x, y);
            _size = new GridPoint(width, height);
            _buffer = buffer;
            _graphic.Color = color;

            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    _positions.AddPosition(i + x, j + y);
                    if (i > buffer && i < width - buffer && j > buffer && j < width - buffer)
                    {
                        // Note that these are relative to the window, not the whole screen!
                        _freeSpots.Add(new GridPoint(i, j));
                    }
                }
            }
        }