slight refactor, gofmt

This commit is contained in:
2019-10-26 23:32:32 +03:00
parent 32c598f9e0
commit ec9d3d9a73
20 changed files with 303 additions and 239 deletions

View File

@ -1,5 +1,3 @@
package ecs
type Entity struct {
ID int
}
type Entity int

View File

@ -85,4 +85,4 @@ func (f *FieldOfVision) RayCast(playerX, playerY int, gameMap *gamemap.Map) {
func Round(f float64) float64 {
return math.Floor(f + .5)
}
}

View File

@ -1,14 +1,60 @@
package gamemap
import "lab.zaar.be/thefish/alchemyst-go/engine/ecs"
import (
"lab.zaar.be/thefish/alchemyst-go/engine/ecs"
"lab.zaar.be/thefish/alchemyst-go/util"
)
var maxrooms = 100
var mapWidth = 150
var mapHeight = 100
type Level struct {
Name string
Branch string
Depth int
Name string
Branch string
Depth int
MaxRooms int
Width int
Height int
Objects []ecs.Entity
Tiles [][]*Tile
}
Width int
Height int
Objects []ecs.Entity
Tiles [][]*Tile
}
func NewLevel(ctx util.ClientCtx, branch string, depth int) *Level {
l := &Level{
Name: branch + string(depth),
Depth: depth,
MaxRooms: maxrooms,
Width: mapWidth,
Height: mapHeight,
}
l.Tiles = make([][]*Tile, l.Width)
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++ {
}
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 {
}
}

View File

@ -4,12 +4,12 @@ type mapGen interface {
generate(l *Level) *Level
}
type defaultGen struct {}
type defaultGen struct{}
func (d defaultGen) generate(l *Level) *Level {
l.Tiles, rooms = addRooms(l)
l. Tiles = connectRooms(rooms)
l.Tiles = connectRooms(rooms)
l.Objects = populate(rooms)
return l
@ -17,4 +17,4 @@ func (d defaultGen) generate(l *Level) *Level {
func addRooms(l *Level) {
}
}

View File

@ -10,15 +10,15 @@ type ColorHolder struct {
}
type TileColorSet struct {
Fg func() uint32
Bg func() uint32
DarkFg func() uint32
DarkBg func() uint32
Fg func() uint32
Bg func() uint32
DarkFg func() uint32
DarkBg func() uint32
current *ColorHolder
}
type Appearance struct {
Char string
Char string
ColorSet *TileColorSet
}
@ -34,30 +34,29 @@ func colordance(colorValue uint8, minGlow, maxGlow, step int) uint8 {
type Tile struct {
*Appearance
Name string
Name string
Description string
BlocksPass bool
BlocksPass bool
BlocksSight bool
Explored bool
MustDraw bool
Explored bool
MustDraw bool
}
func NewWall() *Tile {
return &Tile{
Name: "Wall",
Name: "Wall",
Description: "A dull rock wall",
BlocksPass: true,
BlocksPass: true,
BlocksSight: true,
Explored: false,
MustDraw: false,
Explored: false,
MustDraw: false,
Appearance: &Appearance{
Char: "#",
ColorSet: &TileColorSet{
Fg: func() uint32 {return blt.ColorFromARGB(255, 130,110,150)},
Bg: func() uint32 {return blt.ColorFromARGB(255, 172,170,173)},
DarkFg: func() uint32 {return blt.ColorFromARGB(255, 20,20,68)},
DarkBg: func() uint32 {return blt.ColorFromARGB(255, 7,7,30)},
Fg: func() uint32 { return blt.ColorFromARGB(255, 130, 110, 150) },
Bg: func() uint32 { return blt.ColorFromARGB(255, 172, 170, 173) },
DarkFg: func() uint32 { return blt.ColorFromARGB(255, 20, 20, 68) },
DarkBg: func() uint32 { return blt.ColorFromARGB(255, 7, 7, 30) },
},
},
}
@ -65,79 +64,78 @@ func NewWall() *Tile {
func NewFloor() *Tile {
return &Tile{
Name: "Floor",
Name: "Floor",
Description: "Dusty rock floor",
BlocksPass: false,
BlocksPass: false,
BlocksSight: false,
Explored: false,
MustDraw: false,
Explored: false,
MustDraw: false,
Appearance: &Appearance{
Char: ".",
ColorSet: &TileColorSet{
Fg: func() uint32 {return blt.ColorFromARGB(255, 220,220,250)},
Bg: func() uint32 {return blt.ColorFromARGB(255, 19,19,70)},
DarkFg: func() uint32 {return blt.ColorFromARGB(255, 30,20,50)},
DarkBg: func() uint32 {return blt.ColorFromARGB(255, 7,7,30)},
Fg: func() uint32 { return blt.ColorFromARGB(255, 220, 220, 250) },
Bg: func() uint32 { return blt.ColorFromARGB(255, 19, 19, 70) },
DarkFg: func() uint32 { return blt.ColorFromARGB(255, 30, 20, 50) },
DarkBg: func() uint32 { return blt.ColorFromARGB(255, 7, 7, 30) },
},
},
}
}
func NewWaterTile() *Tile {
ch := &ColorHolder{19,19,70}
return &Tile {
Name: "Water",
ch := &ColorHolder{19, 19, 70}
return &Tile{
Name: "Water",
Description: "Murky water",
BlocksPass: false,
BlocksPass: false,
BlocksSight: false,
Explored: false,
MustDraw: true, //fixme debug
Explored: false,
MustDraw: true, //fixme debug
Appearance: &Appearance{
Char: ".",
ColorSet: &TileColorSet{
current: ch,
Fg: func() uint32 {return blt.ColorFromARGB(255, 220,220,250)},
Fg: func() uint32 { return blt.ColorFromARGB(255, 220, 220, 250) },
Bg: func() uint32 {
return blt.ColorFromARGB(
255,
ch.R,
colordance(ch.G, 2, 42, 4 ),
colordance(ch.B, 180,229,12),
colordance(ch.G, 2, 42, 4),
colordance(ch.B, 180, 229, 12),
)
},
DarkFg: func() uint32 {return blt.ColorFromARGB(255, 30,20,50)},
DarkBg: func() uint32 {return blt.ColorFromARGB(255, 7,7,30)},
DarkFg: func() uint32 { return blt.ColorFromARGB(255, 30, 20, 50) },
DarkBg: func() uint32 { return blt.ColorFromARGB(255, 7, 7, 30) },
},
},
}
}
func NewDeepWaterTile() *Tile {
ch := &ColorHolder{5,2,154}
return &Tile {
Name: "Deep Water",
ch := &ColorHolder{5, 2, 154}
return &Tile{
Name: "Deep Water",
Description: "Deep water",
BlocksPass: false,
BlocksPass: false,
BlocksSight: false,
Explored: false,
MustDraw: true, //fixme debug
Explored: false,
MustDraw: true, //fixme debug
Appearance: &Appearance{
Char: " ",
ColorSet: &TileColorSet{
current: ch,
Fg: func() uint32 {return blt.ColorFromARGB(255, 220,220,250)},
Fg: func() uint32 { return blt.ColorFromARGB(255, 220, 220, 250) },
Bg: func() uint32 {
return blt.ColorFromARGB(
255,
ch.R,
colordance(ch.G, 0, 15, 2 ),
colordance(ch.B, 120,180,5),
colordance(ch.G, 0, 15, 2),
colordance(ch.B, 120, 180, 5),
)
},
DarkFg: func() uint32 {return blt.ColorFromARGB(255, 30,20,50)},
DarkBg: func() uint32 {return blt.ColorFromARGB(255, 7,7,30)},
DarkFg: func() uint32 { return blt.ColorFromARGB(255, 30, 20, 50) },
DarkBg: func() uint32 { return blt.ColorFromARGB(255, 7, 7, 30) },
},
},
}
}

View File

@ -1,5 +1,5 @@
package gamemap
type Coords struct {
x,y int
x, y int
}

9
engine/types/ifaces.go Normal file
View File

@ -0,0 +1,9 @@
package types
type Renderable interface {
Render()
}
type Putable interface {
Put(x, y int, symbol interface{})
}

47
engine/types/rect.go Normal file
View File

@ -0,0 +1,47 @@
package types
type Rect struct {
X, Y, W, H int
}
type RectFill struct {
Top, Bottom, Left, Right, TopLeft, TopRight, BottomLeft, BottomRight, Body interface{}
}
func NewRect(x, y, w, h int) *Rect {
return &Rect{x, y, w, h}
}
func (r *Rect) RenderToLayer(fillage RectFill, layer Putable) {
if fillage.Body != "" {
for i := r.X + 1; i < r.X+r.W; i++ {
for j := r.Y + 1; j < r.Y+r.H; j++ {
layer.Put(i, j, fillage.Body)
//lii.Put(i, j, "X");
}
}
}
for i := r.X + 1; i < r.X+r.W; i++ {
layer.Put(i, r.Y, fillage.Top)
//lii.Put(i, Y-1, "Q");
layer.Put(i, r.Y+r.H, fillage.Bottom)
//lii.Put(i, Y+H, "H");
}
for j := r.Y + 1; j < r.Y+r.H; j++ {
layer.Put(r.X, j, fillage.Left)
//lii.Put(X-1, j, "U");
layer.Put(r.X+r.W, j, fillage.Right)
//lii.Put(X+W, j, "M");
}
layer.Put(r.X, r.Y, fillage.TopLeft)
//lii.Put(X-1, Y-1, "T");
layer.Put(r.X, r.Y+r.H, fillage.BottomLeft)
//lii.Put(X-1, Y+H, "q");
layer.Put(r.X+r.W, r.Y, fillage.TopRight)
//lii.Put(X+W, Y-1, "L");
layer.Put(r.X+r.W, r.Y+r.H, fillage.BottomRight)
}