resolve conflicts

This commit is contained in:
anton.gurov
2019-11-05 12:42:05 +03:00
33 changed files with 1004 additions and 360 deletions

View File

@ -8,7 +8,7 @@ import (
//fixme move to config
var mapWidth = 150
var mapHeight = 100
var mapHeight = 90
type Level struct {
@ -17,7 +17,7 @@ type Level struct {
Name string
Branch string
Depth int
Objects []ecs.Entity
Objects *[]ecs.Entity
Tiles []*Tile
}
@ -49,6 +49,7 @@ func (l *Level) Put (x, y int, tileFunc interface{}) {
func NewLevel(ctx util.ClientCtx, branch string, depth int) *Level {
l := &Level{
ctx: ctx,
Name: branch + string(depth),
Depth: depth,
Rect: types.NewRect(0,0, mapWidth, mapHeight),
@ -58,6 +59,12 @@ func NewLevel(ctx util.ClientCtx, branch string, depth int) *Level {
return l
}
func (l *Level) SetAllInvisible() {
for idx, _ := range l.Tiles {
l.Tiles[idx].Visible = false
}
}
type Room struct {
*types.Rect
Center types.Coords

View File

@ -8,10 +8,10 @@ import (
//fixme move to config
var minRoomSize = 3
var maxRoomSize = 22
var maxrooms = 50
var maxrooms = 30
//fixme make closure to stack them
func DefaultGen(l *gamemap.Level) *gamemap.Level {
func DefaultGen(l *gamemap.Level) (*gamemap.Level, []*gamemap.Room) {
rng := util.NewRNG()
@ -56,53 +56,49 @@ func DefaultGen(l *gamemap.Level) *gamemap.Level {
if !failed {
rooms = append(rooms, newRoom)
}
//addStairs(rooms)
//itemize(rooms)
}
fges := map[int]types.RectFill{
1: types.RectFill{
Top: func() *gamemap.Tile { return gamemap.NewWall() },
Bottom: func() *gamemap.Tile { return gamemap.NewWall() },
Left: func() *gamemap.Tile { return gamemap.NewWall() },
Right: func() *gamemap.Tile { return gamemap.NewWall() },
BottomLeft: func() *gamemap.Tile { return gamemap.NewWall() },
BottomRight: func() *gamemap.Tile { return gamemap.NewWall() },
TopLeft: func() *gamemap.Tile { return gamemap.NewWall() },
TopRight: func() *gamemap.Tile { return gamemap.NewWall() },
Body: func() *gamemap.Tile { return gamemap.NewFloor() },
},
2: types.RectFill{
Top: func() *gamemap.Tile { return gamemap.NewWaterTile() },
Bottom: func() *gamemap.Tile { return gamemap.NewWaterTile() },
Left: func() *gamemap.Tile { return gamemap.NewWaterTile() },
Right: func() *gamemap.Tile { return gamemap.NewWaterTile() },
BottomLeft: func() *gamemap.Tile { return gamemap.NewWaterTile() },
BottomRight: func() *gamemap.Tile { return gamemap.NewWaterTile() },
TopLeft: func() *gamemap.Tile { return gamemap.NewWaterTile() },
TopRight: func() *gamemap.Tile { return gamemap.NewWaterTile() },
Body: func() *gamemap.Tile { return gamemap.NewDeepWaterTile() },
},
}
//fillage := types.RectFill{
// Top: func() *gamemap.Tile {return gamemap.NewWall()},
// Bottom: func() *gamemap.Tile {return gamemap.NewWall()},
// Left: func() *gamemap.Tile {return gamemap.NewWall()},
// Right: func() *gamemap.Tile {return gamemap.NewWall()},
// BottomLeft: func() *gamemap.Tile {return gamemap.NewWall()},
// BottomRight: func() *gamemap.Tile {return gamemap.NewWall()},
// TopLeft: func() *gamemap.Tile {return gamemap.NewWall()},
// TopRight: func() *gamemap.Tile {return gamemap.NewWall()},
// Body: func() *gamemap.Tile {return gamemap.NewFloor()},
//}
//fillage := types.RectFill{
// Top: func() *gamemap.Tile {return gamemap.NewWaterTile()},
// Bottom: func() *gamemap.Tile {return gamemap.NewWaterTile()},
// Left: func() *gamemap.Tile {return gamemap.NewWaterTile()},
// Right: func() *gamemap.Tile {return gamemap.NewWaterTile()},
// BottomLeft: func() *gamemap.Tile {return gamemap.NewWaterTile()},
// BottomRight: func() *gamemap.Tile {return gamemap.NewWaterTile()},
// TopLeft: func() *gamemap.Tile {return gamemap.NewWaterTile()},
// TopRight: func() *gamemap.Tile {return gamemap.NewWaterTile()},
// Body: func() *gamemap.Tile {return gamemap.NewDeepWaterTile()},
//}
fillage := types.RectFill{
Top: func() *gamemap.Tile {return gamemap.NewFloor()},
Bottom: func() *gamemap.Tile {return gamemap.NewFloor()},
Left: func() *gamemap.Tile {return gamemap.NewFloor()},
Right: func() *gamemap.Tile {return gamemap.NewFloor()},
BottomLeft: func() *gamemap.Tile {return gamemap.NewFloor()},
BottomRight: func() *gamemap.Tile {return gamemap.NewFloor()},
TopLeft: func() *gamemap.Tile {return gamemap.NewFloor()},
TopRight: func() *gamemap.Tile {return gamemap.NewFloor()},
Body: func() *gamemap.Tile {return gamemap.NewFloor()},
var fillage types.RectFill
for _, room := range rooms {
fillage = fges[rng.GetWeightedEntity(map[int]int{1:10, 2:1})]
room.Blit(fillage, l)
}
for idx, room := range rooms {
room.Blit(fillage, l)
if idx > 0 {
connectRooms(l, room, rooms[idx-1], fillage, rng.Range(0,1))
}
}
return l
return l, rooms
}
func connectRooms (l *gamemap.Level, room, otherRoom *gamemap.Room, fillage types.RectFill, toss int) {

View File

@ -1,69 +1,8 @@
package gamemap
import (
"github.com/gammazero/deque"
"lab.zaar.be/thefish/alchemyst-go/util"
. "lab.zaar.be/thefish/alchemyst-go/engine/types"
)
import blt "lab.zaar.be/thefish/bearlibterminal"
type ColorHolder interface {
GetColor() uint32
}
type cdeque struct {
deque.Deque
}
func (c *cdeque) Next() uint8 {
c.Rotate(1)
return c.Front().(uint8)
}
type DanceColorHolder struct {
A uint8
R *cdeque
G *cdeque
B *cdeque
}
func (chd *DanceColorHolder) GetColor() uint32 {
return blt.ColorFromARGB(
chd.A,
chd.R.Next(),
chd.G.Next(),
chd.B.Next(),
)
}
type PlainColorHolder struct {
A uint8
R uint8
G uint8
B uint8
}
func (chb *PlainColorHolder) GetColor() uint32 {
return blt.ColorFromARGB(
chb.A,
chb.R,
chb.G,
chb.B,
)
}
type TileColorSet struct {
Fg ColorHolder
Bg ColorHolder
DarkFg ColorHolder
DarkBg ColorHolder
}
type Appearance struct {
Char string `json:"char"`
ColorSet *TileColorSet `json:"colorSet"`
}
var crng = util.NewRNG()
type Tile struct {
*Appearance `json:"app"`
@ -78,12 +17,11 @@ type Tile struct {
}
func (t *Tile) GetChar() string {
return t.Char
return t.Glyph.GetGlyph()
}
func (t *Tile) GetRawColor() uint32 {
//if !t.Visible {
if !t.Visible {
if t.Visible {
return t.Appearance.ColorSet.Fg.GetColor()
} else {
return t.Appearance.ColorSet.DarkFg.GetColor()
@ -91,7 +29,6 @@ func (t *Tile) GetRawColor() uint32 {
}
func (t *Tile) GetRawBgColor() uint32 {
//if !t.Visible {
if t.Visible {
return t.Appearance.ColorSet.Bg.GetColor()
} else {
@ -99,38 +36,6 @@ func (t *Tile) GetRawBgColor() uint32 {
}
}
func singleColorRing(colorValue uint8) *cdeque {
c := &cdeque{}
c.PushBack(colorValue)
return c
}
func fillColorRing(colorValue uint8, minGlow, maxGlow, step int) *cdeque {
q := make([]uint8, 0)
color := int(colorValue)
for color < maxGlow {
q = append(q, uint8(color))
color = crng.Range(1, step) + color
}
color = crng.Range(0, step+minGlow)
q = append(q, uint8(color))
//for uint8(color) < uint8(colorValue) {
// q = append(q, uint8(color))
// color = crng.Range(1, step+minGlow)
//}
c := &cdeque{}
toss := crng.Range(0, 1) //Хаха
for _, v := range q {
if toss == 1 {
c.PushBack(uint8(v))
} else {
c.PushFront(uint8(v))
}
}
return c
}
func NewWall() *Tile {
return &Tile{
Name: "Wall",
@ -140,7 +45,7 @@ func NewWall() *Tile {
Explored: false,
MustDraw: false,
Appearance: &Appearance{
Char: "#",
Glyph: &PlainGlyphHolder{"#"},
ColorSet: &TileColorSet{
Fg: &PlainColorHolder{255, 130, 110, 150},
Bg: &PlainColorHolder{255, 172, 170, 173},
@ -160,7 +65,7 @@ func NewFloor() *Tile {
Explored: false,
MustDraw: false,
Appearance: &Appearance{
Char: ".",
Glyph: &PlainGlyphHolder{"."},
ColorSet: &TileColorSet{
Fg: &PlainColorHolder{255, 220, 220, 250},
Bg: &PlainColorHolder{255, 19, 19, 70},
@ -183,17 +88,17 @@ func NewWaterTile() *Tile {
Colordance: true,
Appearance: &Appearance{
Char: " ",
Glyph: &PlainGlyphHolder{" "},
ColorSet: &TileColorSet{
Fg: &PlainColorHolder{255, 220, 220, 250},
Fg: &PlainColorHolder{255, 220, 220, 250},
Bg: &DanceColorHolder{
255,
singleColorRing(19),
fillColorRing(22, 2, 42, 4),
fillColorRing(204, 180, 229, 12),
SingleColorRing(19),
FillColorRing(19, 0, 15, 2),
FillColorRing(127, 120, 176, 12),
},
DarkFg: &PlainColorHolder{255, 30, 20, 50 },
DarkBg: &PlainColorHolder{255, 7, 7, 80},
DarkFg: &PlainColorHolder{255, 30, 20, 50},
DarkBg: &PlainColorHolder{255, 7, 7, 30},
},
},
}
@ -210,18 +115,18 @@ func NewDeepWaterTile() *Tile {
MustDraw: true, //fixme debug
Colordance: true,
Appearance: &Appearance{
Char: " ",
Glyph: &PlainGlyphHolder{" "},
ColorSet: &TileColorSet{
Fg: &PlainColorHolder{255, 220, 220, 250},
Fg: &PlainColorHolder{255, 220, 220, 250},
Bg: &DanceColorHolder{
255,
singleColorRing(5),
fillColorRing(2,0,15,2),
fillColorRing(154, 120, 180, 5),
SingleColorRing(5),
FillColorRing(2, 2, 42, 4),
FillColorRing(154, 150, 229, 12),
},
DarkFg: &PlainColorHolder{255, 30, 20, 50},
DarkBg: &PlainColorHolder{255, 7, 7, 80},
DarkBg: &PlainColorHolder{255, 7, 7, 30},
},
},
}
}
}