prefabs broken
This commit is contained in:
parent
ef2577741f
commit
4b631142f7
@ -69,7 +69,7 @@ func main() {
|
||||
go decodeInput(mainCtx, mw.GetLayer("base"))
|
||||
|
||||
//fixme set up (load / generate) level
|
||||
level, rooms := mapgens.DefaultGen(gamemap.NewLevel(mainCtx, "test", 1))
|
||||
level, rooms := mapgens.DefaultGen(mainCtx, gamemap.NewLevel(mainCtx, "test", 1))
|
||||
State.Level = level
|
||||
|
||||
sidebarWidth := 0
|
||||
|
@ -1,6 +1,7 @@
|
||||
package mapgens
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/types"
|
||||
"lab.zaar.be/thefish/alchemyst-go/util"
|
||||
@ -37,10 +38,15 @@ var fges = map[int]types.RectFill{
|
||||
},
|
||||
}
|
||||
|
||||
func DefaultGen(l *gamemap.Level) (*gamemap.Level, []*gamemap.Room) {
|
||||
func DefaultGen(ctx util.ClientCtx,l *gamemap.Level) (*gamemap.Level, []*gamemap.Room) {
|
||||
|
||||
rng := util.NewRNG()
|
||||
|
||||
//load prefabs
|
||||
//pfLoader := gamemap.NewPrefabLoader(ctx)
|
||||
//pfRooms := pfLoader.PrefabRoomsList()
|
||||
|
||||
|
||||
//fill with walls
|
||||
for i := 0; i < l.W; i ++ {
|
||||
for j := 0; j < l.H; j++ {
|
||||
@ -51,20 +57,27 @@ func DefaultGen(l *gamemap.Level) (*gamemap.Level, []*gamemap.Room) {
|
||||
rooms := make([]*gamemap.Room, 0)
|
||||
|
||||
for i := 0; i < maxrooms; i++ {
|
||||
var failed = false
|
||||
failed := false
|
||||
var fillage types.RectFill
|
||||
fillage = fges[rng.GetWeightedEntity(map[int]int{1: 10, 2: 1})]
|
||||
newRoom := gamemap.NewRandomRectRoom(
|
||||
rng,
|
||||
rng.Range(minRoomSize, maxRoomSize),
|
||||
rng.Range(minRoomSize, maxRoomSize),
|
||||
fillage,
|
||||
)
|
||||
var newRoom *gamemap.Room
|
||||
//if rng.Range(0, 5) > 3 {
|
||||
newRoom = gamemap.NewRandomRectRoom(
|
||||
rng,
|
||||
rng.Range(minRoomSize, maxRoomSize),
|
||||
rng.Range(minRoomSize, maxRoomSize),
|
||||
fillage,
|
||||
)
|
||||
//} else {
|
||||
// prefab
|
||||
// newRoom = &pfRooms[0]
|
||||
//}
|
||||
where := types.Coords{
|
||||
rng.Range(1, l.W -2 - newRoom.W),
|
||||
rng.Range(1, l.H - 2 - newRoom.H),
|
||||
}
|
||||
|
||||
newRoom.MoveToCoords(where)
|
||||
|
||||
for _, otherRoom := range rooms {
|
||||
if otherRoom.Intersects(newRoom.Rect) {
|
||||
@ -77,7 +90,6 @@ func DefaultGen(l *gamemap.Level) (*gamemap.Level, []*gamemap.Room) {
|
||||
rooms = append(rooms, newRoom)
|
||||
}
|
||||
|
||||
newRoom.BlitToLevel(l, where)
|
||||
//addStairs(rooms)
|
||||
//itemize(rooms)
|
||||
}
|
||||
@ -87,7 +99,12 @@ func DefaultGen(l *gamemap.Level) (*gamemap.Level, []*gamemap.Room) {
|
||||
//refine it to minimum spanning tree
|
||||
|
||||
//connect accordingly
|
||||
|
||||
for _, room := range rooms {
|
||||
err := room.BlitToLevel(l)
|
||||
if err != nil {
|
||||
fmt.Printf("err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
for idx, room := range rooms {
|
||||
if idx > 0 {
|
||||
|
@ -2,6 +2,7 @@ package gamemap
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/items"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/mob"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/types"
|
||||
@ -29,14 +30,15 @@ func (r *Room) Put (x, y int, tileFunc interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (room *Room) BlitToLevel(l *Level, where types.Coords) error {
|
||||
func (room *Room) BlitToLevel(l *Level) error {
|
||||
//copy tiles like this:
|
||||
//https://stackoverflow.com/questions/21011023/copy-pointer-values-a-b-in-golang
|
||||
|
||||
for j := 0; j < room.H; j++ {
|
||||
|
||||
for i := 0; i < room.W; i++ {
|
||||
underlyingTile := l.GetTileByXY(i+where.X, j+where.Y)
|
||||
mapCoords := types.Coords{room.X + i, room.Y + j}
|
||||
underlyingTile := l.GetTile(mapCoords)
|
||||
|
||||
tileFunc := room.Geometry[i+j*room.W]
|
||||
|
||||
@ -46,11 +48,17 @@ func (room *Room) BlitToLevel(l *Level, where types.Coords) error {
|
||||
//check underlying tile
|
||||
if underlyingTile == nil ||
|
||||
underlyingTile.Name != "Wall" {
|
||||
fmt.Println("Invalid blit!")
|
||||
return invalidBlit
|
||||
}
|
||||
l.Put(i+where.X, j+where.Y, tileFunc)
|
||||
l.Put(mapCoords.X, mapCoords.Y, tileFunc)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (room *Room) MoveToCoords(where types.Coords) *Room {
|
||||
//update room coords?
|
||||
room.X = where.X
|
||||
room.Y = where.Y
|
||||
@ -62,7 +70,7 @@ func (room *Room) BlitToLevel(l *Level, where types.Coords) error {
|
||||
room.Connectors[i].X += where.X
|
||||
room.Connectors[i].Y += where.Y
|
||||
}
|
||||
return nil
|
||||
return room
|
||||
}
|
||||
|
||||
func NewRandomRectRoom(rng *util.RNG, w, h int, fillage types.RectFill) *Room {
|
||||
|
Loading…
x
Reference in New Issue
Block a user