public static bool BlockExistsAt(this IEnumerable <IBlock> blocks, RelativePoint point) { foreach (var i in blocks) { if (i.Position.X == point.X && i.Position.Y == point.Y) { return(true); } } return(false); }
public static bool FitsInRegion(this IEnumerable <IBlock> blocks, IEnumerable <IBlock> world, int x, int y) { var relPoint = new RelativePoint(x, y); foreach (var i in blocks) { if (world.BlockExistsAt(i.Position.AddTo(relPoint))) { return(false); } } return(true); }
public static RelativePoint LowestBlock(this IEnumerable <IBlock> blocks) { var pos = new RelativePoint(); foreach (var i in blocks) { if (i.Position.X > pos.X) { pos = new RelativePoint(i.Position.X, pos.Y); } if (i.Position.Y > pos.Y) { pos = new RelativePoint(pos.X, i.Position.Y); } } return(pos); }
public static IEnumerable <IBlock> BuildWorld(this IEnumerable <Module> mods, int maxX, int maxY) { var blocks = new List <IBlock>(); foreach (var i in mods) { var blks = i.GetBlocks(); var lowest = blks.LowestBlock(); var regX = int.MaxValue; var regY = int.MaxValue; for (var x = 0; x < maxX - lowest.X; x++) { for (var y = 0; y < maxY - lowest.Y; y++) { if (blks.FitsInRegion(blocks, x, y)) { regX = x; regY = y; x = maxX; // break out of the loop y = maxY; } } } var relPoint = new RelativePoint(regX, regY); foreach (var j in blks) { blocks.Add(j.Clone(relPoint)); } } return(blocks); }
public Portal(RelativePoint pos, BlockType id, PortalDirection rotation, int curId, int targetId) : this(pos, id, new PortalInfo(curId, targetId, rotation)) { }
public Switch(RelativePoint pos, BlockType id, int switchId) { this.Position = pos; this.Id = id; this.SwitchId = switchId; }
public IBlock Clone(RelativePoint newPos) => new Switch(this.Position.AddTo(newPos), this.Id, this.SwitchId);
public IBlock Clone(RelativePoint newPos) => new Regular(this.Position.AddTo(newPos), this.Id);
public Regular(RelativePoint pos, BlockType id) { this.Position = pos; this.Id = id; }
public RelativePoint AddTo(RelativePoint other) => new RelativePoint(other.X + this.X, other.Y + this.Y);
public IBlock Clone(RelativePoint newPos) => new Portal(this.Position.AddTo(newPos), this.Id, this.PortalInfo);
public Portal(RelativePoint pos, BlockType id, PortalInfo portalInfo) { this.Position = pos; this.Id = id; this.PortalInfo = portalInfo; }