From 7b4a3c3200eaa7acec10bea25bb5b539219feb30 Mon Sep 17 00:00:00 2001 From: thefish Date: Fri, 15 Nov 2019 23:12:49 +0300 Subject: [PATCH] delaunnay pure impl --- cmd/game/main.go | 1 + engine/gamemap/mapgens/delaunay_mst_ext.go | 2 +- engine/gamemap/mapgens/delaunay_pure.go | 45 ++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 engine/gamemap/mapgens/delaunay_pure.go diff --git a/cmd/game/main.go b/cmd/game/main.go index 78987cb..5a612b0 100644 --- a/cmd/game/main.go +++ b/cmd/game/main.go @@ -74,6 +74,7 @@ func main() { //level, rooms := _default.DefaultGen(mainCtx, gamemap.NewLevel(mainCtx, "test", 1)) //level, rooms := mapgens.DelaunayMstGen(mainCtx, gamemap.NewLevel(mainCtx, "test", 1)) level, rooms := mapgens.DelaunayMstExtGen(mainCtx, gamemap.NewLevel(mainCtx, "test", 1)) + //level, rooms := mapgens.DelaunayPureGen(mainCtx, gamemap.NewLevel(mainCtx, "test", 1)) State.Level = level sidebarWidth := 0 diff --git a/engine/gamemap/mapgens/delaunay_mst_ext.go b/engine/gamemap/mapgens/delaunay_mst_ext.go index 8545087..f997f92 100644 --- a/engine/gamemap/mapgens/delaunay_mst_ext.go +++ b/engine/gamemap/mapgens/delaunay_mst_ext.go @@ -40,7 +40,7 @@ func DelaunayMstExtGen(ctx appctx.ClientCtx, l *gamemap.Level) (*gamemap.Level, MedianStraight(rng, l, rooms, centers, edge) outlyingCorridors = append(outlyingCorridors, edge) outlyingCorrCount++ - if outlyingCorrCount > 5 { + if outlyingCorrCount > 8 { break } } diff --git a/engine/gamemap/mapgens/delaunay_pure.go b/engine/gamemap/mapgens/delaunay_pure.go new file mode 100644 index 0000000..e6eb652 --- /dev/null +++ b/engine/gamemap/mapgens/delaunay_pure.go @@ -0,0 +1,45 @@ +package mapgens + +import ( + "context" + "fmt" + "lab.zaar.be/thefish/alchemyst-go/engine/gamemap" + "lab.zaar.be/thefish/alchemyst-go/engine/types" + "lab.zaar.be/thefish/alchemyst-go/util" + "lab.zaar.be/thefish/alchemyst-go/util/delaunay" +) + +func DelaunayPureGen(ctx context.Context, l *gamemap.Level) (*gamemap.Level, []gamemap.Room) { + + rng := util.NewRNG() + + //fill with walls + for i := 0; i < l.W; i ++ { + for j := 0; j < l.H; j++ { + l.SetTileByXY(i, j, gamemap.NewWall()) + } + } + rooms := GetRandomRoomList(ctx, rng, l, maxrooms, minRoomSize, maxRoomSize) + + + for _, room := range rooms { + err := room.BlitToLevel(l) + if err != nil { + fmt.Printf("err: %v", err) + } + } + + centers := make([]types.Coords, 0) + for _, room := range rooms { + centers = append(centers, room.Center) + } + edges := delaunay.GetTriangles(centers, l.W, l.H) + for _, edge := range edges { + MedianStraight(rng, l, rooms, centers, edge) + } + + return l, rooms +} + + +