debugged delaunay, problem was in referencing slice of connectors instead of copying

This commit is contained in:
anton.gurov
2019-11-14 18:53:41 +03:00
parent 04da543c30
commit 0f367eaf96
3 changed files with 66 additions and 13 deletions

View File

@ -7,6 +7,7 @@ import (
"lab.zaar.be/thefish/alchemyst-go/engine/mob"
"lab.zaar.be/thefish/alchemyst-go/engine/types"
"lab.zaar.be/thefish/alchemyst-go/util"
"strings"
)
var invalidBlit = errors.New("trying to blit on existing good tile")
@ -59,17 +60,24 @@ func (room *Room) BlitToLevel(l *Level) error {
}
func (room *Room) MoveToCoords(where types.Coords) *Room {
fmt.Printf("\n MOVING room :", room.String())
fmt.Printf("\nmovin room to %v", where)
//update room coords?
room.X = where.X
room.Y = where.Y
//update centers!
room.Center.X += where.X
room.Center.Y += where.Y
room.Center.X = room.Center.X + where.X
room.Center.Y = room.Center.Y + where.Y
//update connector?
for i, _ := range room.Connectors {
room.Connectors[i].X += where.X
room.Connectors[i].Y += where.Y
for i, coords := range room.Connectors {
fmt.Printf("\nupdating coords ", coords)
coords.X = coords.X + where.X
coords.Y = coords.Y + where.Y
fmt.Printf("\nupdated coords ", coords)
room.Connectors[i] = coords
}
fmt.Printf("\nROOM MOVED to %v \n\n", room)
return room
}
@ -90,8 +98,17 @@ func NewRandomRectRoom(rng *util.RNG, w, h int, fillage types.RectFill) Room {
newRoom.Connectors,
types.Coords{rng.Range(1, w - 2), 0},
types.Coords{rng.Range(1, w - 2), h -1},
types.Coords{0, rng.Range(1, h - 2)},
types.Coords{w - 1, rng.Range(1, h - 2)},
types.Coords{0, rng.Range(1, h - 1)},
types.Coords{w - 1, rng.Range(1, h - 1)},
)
return newRoom
}
func (r *Room) String() string {
return strings.Join([]string{
"room: ",
"\t" + fmt.Sprintf(" rect: X: %d, Y: %d, maxX: %d, maxY: %d", r.Rect.X, r.Rect.Y, r.Rect.W + r.X - 1, r.Rect.H + r.Y - 1),
"\t" + fmt.Sprintf(" center:", r.Center.X, r.Center.Y),
"\t" + fmt.Sprintf(" Connectors: %v", r.Connectors),
},"\n") + "\n"
}