Beispiel #1
0
    protected virtual void AddEntity(Group collection, Entity entity, int index, IComponent component)
    {
        MapPositionComponent mapPositionComponent = null;

        foreach (var c in entity.GetComponents())
        {
            if (c.GetType() == typeof(MapPositionComponent))
            {
                mapPositionComponent = (MapPositionComponent)c;
            }
        }

        if (mapPositionComponent != null)
        {
            if (lookup.ContainsKey(mapPositionComponent.Position) && lookup[mapPositionComponent.Position] == entity)
            {
                return;
            }

            if (lookup.ContainsKey(mapPositionComponent.Position) && lookup[mapPositionComponent.Position] != entity)
            {
                throw new Exception("the key " + mapPositionComponent + " is not unique. Present on entity: " + entity.creationIndex + " and entity: " + lookup[mapPositionComponent.Position].creationIndex);
            }
            entity.Retain(this);
            lookup[mapPositionComponent.Position] = entity;
        }
    }
Beispiel #2
0
        public void Create()
        {
            _map.SetMap(5, 5, Tile.Grass);
            Assert.AreEqual(Tile.Grass, _map.GetTile(4, 4));

            var pos = new MapPositionComponent()
            {
                Value = new Position(4, 4)
            };

            Assert.AreEqual(Tile.Grass, _map.GetTile(pos));
        }
 public bool Equals(MapPositionComponent other)
 {
     return(x == other.x && y == other.y);
 }
 public int GetDistance(MapPositionComponent otherPosition)
 {
     return(Math.Abs(x - otherPosition.x) + Math.Abs(y - otherPosition.y));
 }