public bool MoveEntity(Entity e, Direction d) { if (entities.Move(e, entities.GetPosition(e) + d)) { return(true); } return(false); }
public void TestMove() { var itemsAdded = new List <MySpatialMapItem>(); var sm = new LayeredSpatialMap <MySpatialMapItem>(5); for (int i = 0; i < 5; i++) { var item = new MySpatialMapItem(i); itemsAdded.Add(item); sm.Add(item, (1, 2)); } var lastItem = new MySpatialMapItem(3); itemsAdded.Add(lastItem); sm.Add(lastItem, (5, 6)); bool result = sm.Move(lastItem, 1, 2); Assert.AreEqual(false, result); // Blocked by first 5 adds and they no layers support multiple items result = sm.Move(lastItem, (2, 3)); // At 2, 3 we now have item on layer 3 Assert.AreEqual(true, result); List <MySpatialMapItem> itemsMoved = sm.Move((1, 2), (2, 3)).ToList(); Assert.AreEqual(4, itemsMoved.Count); // All original items minus 1 because that one was blocked itemsMoved = sm.Move((2, 3), (1, 2), ~sm.LayerMasker.Mask(2)).ToList(); Assert.AreEqual(3, itemsMoved.Count); // lastItem from above masked out by layer sm = new LayeredSpatialMap <MySpatialMapItem>(5, 1); for (int i = 0; i < itemsAdded.Count - 1; i++) // All but that last item so we add at diff pos { sm.Add(itemsAdded[i], (1, 2)); } sm.Add(lastItem, (2, 3)); // We should have added all but the one that was layer 0 itemsMoved = sm.Move(1, 2, 2, 3).ToList(); Assert.AreEqual(3, itemsMoved.Count); itemsMoved = sm.Move(2, 3, 1, 2, ~sm.LayerMasker.Mask(2)).ToList(); Assert.AreEqual(2, itemsMoved.Count); List <MySpatialMapItem> itemsLeft = sm.GetItems((2, 3)).ToList(); Assert.AreEqual(2, itemsLeft.Count); bool found = false; foreach (var item in itemsLeft) { found = found || item == itemsAdded[2]; } Assert.AreEqual(true, found); }
internal bool AttemptEntityMove(IGameObject gameObject, Coord newPosition) => _entities.Move(gameObject, newPosition);