From ef2577741f88a4c0ed19a865f217b92bb8334e80 Mon Sep 17 00:00:00 2001 From: thefish Date: Mon, 11 Nov 2019 02:29:01 +0300 Subject: [PATCH] old connections working --- engine/gamemap/mapgens/default.go | 27 +++++++++++++++++---------- engine/gamemap/room.go | 6 +++++- engine/gamemap/tile.go | 2 +- go.mod | 2 +- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/engine/gamemap/mapgens/default.go b/engine/gamemap/mapgens/default.go index 62eca14..c1bf985 100644 --- a/engine/gamemap/mapgens/default.go +++ b/engine/gamemap/mapgens/default.go @@ -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()) } } } diff --git a/engine/gamemap/room.go b/engine/gamemap/room.go index 4471d96..ed6ff4d 100644 --- a/engine/gamemap/room.go +++ b/engine/gamemap/room.go @@ -44,7 +44,7 @@ func (room *Room) BlitToLevel(l *Level, where types.Coords) error { continue } //check underlying tile - if underlyingTile != nil || + if underlyingTile == nil || underlyingTile.Name != "Wall" { return invalidBlit } @@ -54,6 +54,9 @@ func (room *Room) BlitToLevel(l *Level, where types.Coords) error { //update room coords? room.X = where.X room.Y = where.Y + //update centers! + room.Center.X += where.X + room.Center.Y += where.Y //update connector? for i, _ := range room.Connectors { room.Connectors[i].X += where.X @@ -71,6 +74,7 @@ func NewRandomRectRoom(rng *util.RNG, w, h int, fillage types.RectFill) *Room { h, ), Center: types.Coords{w / 2, h /2 }, + Geometry: make([]func()*Tile, w*h), } newRoom.Blit(fillage, newRoom) //add connectors diff --git a/engine/gamemap/tile.go b/engine/gamemap/tile.go index 0f3f3b8..6a910f5 100644 --- a/engine/gamemap/tile.go +++ b/engine/gamemap/tile.go @@ -39,7 +39,7 @@ func NewWall() *Tile { return &Tile{ Name: "Wall", Description: "A dull rock wall", - BlocksPass: true, + BlocksPass: false, BlocksSight: true, Explored: false, MustDraw: false, diff --git a/go.mod b/go.mod index 3d74214..d6957dc 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/rs/zerolog v1.15.0 golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136 // indirect golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 // indirect - golang.org/x/tools v0.0.0-20191109212701-97ad0ed33101 // indirect + golang.org/x/tools v0.0.0-20191109212701-97ad0ed33101 gonum.org/v1/gonum v0.6.0 // indirect lab.zaar.be/thefish/bearlibterminal v0.0.0-20191018101635-dd37bbc90d77 )