prefabs broken

This commit is contained in:
2019-11-11 03:13:37 +03:00
parent ef2577741f
commit 4b631142f7
3 changed files with 40 additions and 15 deletions

View File

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