delaunnay pure impl

This commit is contained in:
thefish 2019-11-15 23:12:49 +03:00
parent cc017e3781
commit 7b4a3c3200
3 changed files with 47 additions and 1 deletions

View File

@ -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

View File

@ -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
}
}

View File

@ -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
}