upd methods

This commit is contained in:
thefish 2019-10-27 01:30:57 +03:00
parent b8c8a65fa7
commit 0da505b01b
3 changed files with 27 additions and 7 deletions

View File

@ -17,7 +17,6 @@ type Level struct {
Name string Name string
Branch string Branch string
Depth int Depth int
MaxRooms int
Objects []ecs.Entity Objects []ecs.Entity
Tiles [][]*Tile Tiles [][]*Tile
} }
@ -34,7 +33,6 @@ func NewLevel(ctx util.ClientCtx, branch string, depth int) *Level {
l := &Level{ l := &Level{
Name: branch + string(depth), Name: branch + string(depth),
Depth: depth, Depth: depth,
MaxRooms: maxrooms,
Rect: types.NewRect(0,0, mapWidth, mapHeight), Rect: types.NewRect(0,0, mapWidth, mapHeight),
} }

View File

@ -6,9 +6,9 @@ import (
"lab.zaar.be/thefish/alchemyst-go/util" "lab.zaar.be/thefish/alchemyst-go/util"
) )
//fixme move to config //fixme move to config
var maxrooms = 100
var minRoomSize = 3 var minRoomSize = 3
var maxRoomSize = 11 var maxRoomSize = 11
var maxrooms = 100
func DefaultGen(l *gamemap.Level) *gamemap.Level { func DefaultGen(l *gamemap.Level) *gamemap.Level {
@ -23,7 +23,7 @@ func DefaultGen(l *gamemap.Level) *gamemap.Level {
rooms := make([]*gamemap.Room, maxrooms) rooms := make([]*gamemap.Room, maxrooms)
for i := 0; i < l.MaxRooms; i++ { for i := 0; i < maxrooms; i++ {
newRoom := &gamemap.Room{ newRoom := &gamemap.Room{
Rect: types.NewRect( Rect: types.NewRect(
rng.Range(l.X, l.W), rng.Range(l.X, l.W),
@ -92,7 +92,6 @@ func digHTunnel(l *gamemap.Level, x1,x2,y int, fillage types.RectFill) {
} }
} }
func digVTunnel(l *gamemap.Level, y1,y2,x int, fillage types.RectFill) { func digVTunnel(l *gamemap.Level, y1,y2,x int, fillage types.RectFill) {
var start, finish int var start, finish int
if y1 > y2 { if y1 > y2 {

View File

@ -1,9 +1,32 @@
package types package types
import "math"
type Coords struct { type Coords struct {
X, Y int X, Y int
} }
func (c *Coords) Get() (int,int) { func (c *Coords) Get() (int, int) {
return c.X,c.Y return c.X, c.Y
}
func (c *Coords) DistanceTo(o *Coords) float64 {
dx := c.X - o.X
dy := c.X - o.Y
return math.Sqrt(math.Pow(float64(dx), 2) + math.Pow(float64(dy), 2))
}
func (c *Coords) IsAdjacentTo(o *Coords) bool {
var xDiff, yDiff int
if c.X > o.X {
xDiff = c.X - o.X
} else {
xDiff = o.X - c.X
}
if c.Y > o. Y {
yDiff = c.Y - o.Y
} else {
yDiff = o.Y - c.Y
}
return xDiff < 2 && yDiff < 2
} }