public void CreateTile(string type, string layer, float x, float y) { Type t = GameActor.GetGameActorType(type); if (t == null) { throw new Exception("Object of type " + type + " not found in assembly."); } int xi = (int)x; int yi = (int)y; GameActor ga; if (t.IsSubclassOf(typeof(DynamicTile))) { ga = (GameActor)Activator.CreateInstance(t, new Vector2I(xi, yi)); } else if (t.IsSubclassOf(typeof(Tile))) { ga = (GameActor)Activator.CreateInstance(t); } else { throw new Exception("Object of type " + t + " is not subclass of Tile."); } m_atlas.Add(new GameActorPosition(ga, new Vector2(xi, yi), Layer(layer))); }
internal static GameActorPosition GetNearest(int x, int y, string type, IAtlas atlas) { Type t = GameActor.GetGameActorType(type); for (int i = 1; i < 20; i++) { IEnumerable <Vector2I> vonNeumannNeighborhood = Neighborhoods.VonNeumannNeighborhood(new Vector2I(x, y), i); foreach (var xy in vonNeumannNeighborhood) { foreach (GameActorPosition gameActorPosition in atlas.ActorsAt((Vector2)xy)) { if (gameActorPosition.Actor.GetType() == t) { return(gameActorPosition); } } } } return(null); }