basic mapgen
This commit is contained in:
@ -2,59 +2,51 @@ package gamemap
|
||||
|
||||
import (
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/ecs"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/types"
|
||||
"lab.zaar.be/thefish/alchemyst-go/util"
|
||||
)
|
||||
|
||||
var maxrooms = 100
|
||||
//fixme move to config
|
||||
var mapWidth = 150
|
||||
var mapHeight = 100
|
||||
|
||||
|
||||
type Level struct {
|
||||
*types.Rect
|
||||
ctx util.ClientCtx
|
||||
Name string
|
||||
Branch string
|
||||
Depth int
|
||||
MaxRooms int
|
||||
Width int
|
||||
Height int
|
||||
Objects []ecs.Entity
|
||||
Tiles [][]*Tile
|
||||
}
|
||||
|
||||
func (l *Level) Put (x, y int, tileFunc interface{}) {
|
||||
tf := tileFunc.(func() *Tile)()
|
||||
if tf == nil {
|
||||
l.ctx.Logger().Fatal().Msgf("Got non-tile type to put into level: %v", tf)
|
||||
}
|
||||
l.Tiles[x][y] = tf
|
||||
}
|
||||
|
||||
func NewLevel(ctx util.ClientCtx, branch string, depth int) *Level {
|
||||
l := &Level{
|
||||
Name: branch + string(depth),
|
||||
Depth: depth,
|
||||
MaxRooms: maxrooms,
|
||||
Width: mapWidth,
|
||||
Height: mapHeight,
|
||||
Rect: types.NewRect(0,0, mapWidth, mapHeight),
|
||||
}
|
||||
|
||||
l.Tiles = make([][]*Tile, l.Width)
|
||||
l.Tiles = make([][]*Tile, l.W)
|
||||
for i := range l.Tiles {
|
||||
l.Tiles[i] = make([]*Tile, l.Height)
|
||||
}
|
||||
|
||||
return l
|
||||
}
|
||||
|
||||
func Generate(l *Level) (l *Level) {
|
||||
|
||||
for i := 0; i < l.MaxRooms; i++ {
|
||||
|
||||
l.Tiles[i] = make([]*Tile, l.H)
|
||||
}
|
||||
|
||||
return l
|
||||
}
|
||||
|
||||
type Room struct {
|
||||
x, y, w, h int
|
||||
}
|
||||
|
||||
func (self *Room) intersects(other *Room) bool {
|
||||
if self.x <= (other.x+other.w) &&
|
||||
(self.x+self.w) >= other.x &&
|
||||
self.y <= (other.y+other.h) &&
|
||||
(self.y+self.h) >= other.y {
|
||||
|
||||
}
|
||||
}
|
||||
*types.Rect
|
||||
Center *types.Coords
|
||||
}
|
Reference in New Issue
Block a user