old connections working

This commit is contained in:
2019-11-11 02:29:01 +03:00
parent 931971ba8f
commit ef2577741f
4 changed files with 24 additions and 13 deletions

View File

@ -82,26 +82,33 @@ func DefaultGen(l *gamemap.Level) (*gamemap.Level, []*gamemap.Room) {
//itemize(rooms)
}
//build delannay graph from room center
//refine it to minimum spanning tree
//connect accordingly
for idx, room := range rooms {
if idx > 0 {
connectRooms(l, room, rooms[idx-1], fillage, rng.Range(0, 1))
connectRooms(l, room, rooms[idx-1], rng.Range(0, 1))
}
}
return l, rooms
}
func connectRooms(l *gamemap.Level, room, otherRoom *gamemap.Room, fillage types.RectFill, toss int) {
func connectRooms(l *gamemap.Level, room, otherRoom *gamemap.Room, toss int) {
if toss == 0 {
digHTunnel(l, room.Center.X, otherRoom.Center.X, room.Center.Y, fillage)
digVTunnel(l, room.Center.Y, otherRoom.Center.Y, otherRoom.Center.X, fillage)
digHTunnel(l, room.Center.X, otherRoom.Center.X, room.Center.Y)
digVTunnel(l, room.Center.Y, otherRoom.Center.Y, otherRoom.Center.X)
} else {
digVTunnel(l, room.Center.Y, otherRoom.Center.Y, room.Center.Y, fillage)
digHTunnel(l, room.Center.X, otherRoom.Center.X, otherRoom.Center.Y, fillage)
digVTunnel(l, room.Center.Y, otherRoom.Center.Y, room.Center.Y)
digHTunnel(l, room.Center.X, otherRoom.Center.X, otherRoom.Center.Y)
}
}
func digHTunnel(l *gamemap.Level, x1, x2, y int, fillage types.RectFill) {
func digHTunnel(l *gamemap.Level, x1, x2, y int) {
var start, finish int
if x1 < x2 {
start = x1
@ -112,13 +119,13 @@ func digHTunnel(l *gamemap.Level, x1, x2, y int, fillage types.RectFill) {
}
for i := start; i <= finish; i++ {
if l.InBounds(types.Coords{i, y}) {
l.SetTileByXY(i, y, fillage.Body.(func() *gamemap.Tile)())
l.SetTileByXY(i, y, gamemap.NewFloor())
//l.Tiles[i][y] = gamemap.NewFloor()
}
}
}
func digVTunnel(l *gamemap.Level, y1, y2, x int, fillage types.RectFill) {
func digVTunnel(l *gamemap.Level, y1, y2, x int) {
var start, finish int
if y1 < y2 {
start = y1
@ -129,7 +136,7 @@ func digVTunnel(l *gamemap.Level, y1, y2, x int, fillage types.RectFill) {
}
for i := start; i <= finish; i++ {
if l.InBounds(types.Coords{x, i}) {
l.SetTileByXY(x, i, fillage.Body.(func() *gamemap.Tile)())
l.SetTileByXY(x, i, gamemap.NewFloor())
}
}
}