Ejemplo n.º 1
0
        public static Vector2G GetCoord(Vector2G gridCoord, Vector3 position)
        {
            int cx = (int)Math.Floor(position.X / Size) - (gridCoord.X * WorldGrid.CellBreadth);
            int cy = (int)Math.Floor(position.Z / Size) - (gridCoord.Y * WorldGrid.CellBreadth);

            Debug.Assert(cx.InRange(-WorldGrid.CellBreadth, WorldGrid.CellBreadth) && cy.InRange(-WorldGrid.CellBreadth, WorldGrid.CellBreadth));

            return(new Vector2G(cx, cy));
        }
Ejemplo n.º 2
0
 public WorldGrid(Vector2G coordinates)
 {
     gridCoordinates = coordinates;
     for (int x = 0; x < CellBreadth; x++)
     {
         for (int y = 0; y < CellBreadth; y++)
         {
             cells.Add(new Vector2G(x, y), new WorldCell());
         }
     }
 }
Ejemplo n.º 3
0
        public void RelocateActor(Actor actor, Vector3 newPosition)
        {
            Vector2G curCellCoordinates = WorldCell.GetCoord(gridCoordinates, actor.Position.Offset);
            Vector2G newCellCoordinates = WorldCell.GetCoord(gridCoordinates, newPosition);

            if (curCellCoordinates != newCellCoordinates)
            {
                if (!cells.TryGetValue(curCellCoordinates, out WorldCell curCell))
                {
                    return;
                }

                if (!cells.TryGetValue(newCellCoordinates, out WorldCell newCell))
                {
                    return;
                }

                curCell.RemoveActor(actor);
                newCell.AddActor(actor);
            }
        }