updates
This commit is contained in:
5
engine/ecs/entity.go
Normal file
5
engine/ecs/entity.go
Normal file
@ -0,0 +1,5 @@
|
||||
package ecs
|
||||
|
||||
type Entity struct {
|
||||
ID int
|
||||
}
|
88
engine/fov/fov.go
Normal file
88
engine/fov/fov.go
Normal file
@ -0,0 +1,88 @@
|
||||
package fov
|
||||
|
||||
import (
|
||||
"github.com/jcerise/gogue/gamemap"
|
||||
"math"
|
||||
)
|
||||
|
||||
type FieldOfVision struct {
|
||||
cosTable map[int]float64
|
||||
sinTable map[int]float64
|
||||
torchRadius int
|
||||
}
|
||||
|
||||
func (f *FieldOfVision) Initialize() {
|
||||
|
||||
f.cosTable = make(map[int]float64)
|
||||
f.sinTable = make(map[int]float64)
|
||||
|
||||
for i := 0; i < 360; i++ {
|
||||
ax := math.Sin(float64(i) / (float64(180) / math.Pi))
|
||||
ay := math.Cos(float64(i) / (float64(180) / math.Pi))
|
||||
|
||||
f.sinTable[i] = ax
|
||||
f.cosTable[i] = ay
|
||||
}
|
||||
}
|
||||
|
||||
func (f *FieldOfVision) SetTorchRadius(radius int) {
|
||||
if radius > 1 {
|
||||
f.torchRadius = radius
|
||||
}
|
||||
}
|
||||
|
||||
func (f *FieldOfVision) SetAllInvisible(gameMap *gamemap.Map) {
|
||||
for x := 0; x < gameMap.Width; x++ {
|
||||
for y := 0; y < gameMap.Height; y++ {
|
||||
gameMap.Tiles[x][y].Visible = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (f *FieldOfVision) RayCast(playerX, playerY int, gameMap *gamemap.Map) {
|
||||
// Cast out rays each degree in a 360 circle from the player. If a ray passes over a floor (does not block sight)
|
||||
// tile, keep going, up to the maximum torch radius (view radius) of the player. If the ray intersects a wall
|
||||
// (blocks sight), stop, as the player will not be able to see past that. Every visible tile will get the Visible
|
||||
// and Explored properties set to true.
|
||||
|
||||
for i := 0; i < 360; i++ {
|
||||
|
||||
ax := f.sinTable[i]
|
||||
ay := f.cosTable[i]
|
||||
|
||||
x := float64(playerX)
|
||||
y := float64(playerY)
|
||||
|
||||
// Mark the players current position as explored
|
||||
tile := gameMap.Tiles[playerX][playerY]
|
||||
tile.Explored = true
|
||||
tile.Visible = true
|
||||
|
||||
for j := 0; j < f.torchRadius; j++ {
|
||||
x -= ax
|
||||
y -= ay
|
||||
|
||||
roundedX := int(Round(x))
|
||||
roundedY := int(Round(y))
|
||||
|
||||
if x < 0 || x > float64(gameMap.Width-1) || y < 0 || y > float64(gameMap.Height-1) {
|
||||
// If the ray is cast outside of the gamemap, stop
|
||||
break
|
||||
}
|
||||
|
||||
tile := gameMap.Tiles[roundedX][roundedY]
|
||||
|
||||
tile.Explored = true
|
||||
tile.Visible = true
|
||||
|
||||
if gameMap.Tiles[roundedX][roundedY].BlocksSight == true {
|
||||
// The ray hit a wall, go no further
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Round(f float64) float64 {
|
||||
return math.Floor(f + .5)
|
||||
}
|
14
engine/gamemap/level.go
Normal file
14
engine/gamemap/level.go
Normal file
@ -0,0 +1,14 @@
|
||||
package gamemap
|
||||
|
||||
import "lab.zaar.be/thefish/alchemyst-go/engine/ecs"
|
||||
|
||||
type Level struct {
|
||||
Name string
|
||||
Branch string
|
||||
Depth int
|
||||
MaxRooms int
|
||||
Width int
|
||||
Height int
|
||||
Objects []ecs.Entity
|
||||
Tiles [][]*Tile
|
||||
}
|
20
engine/gamemap/mapgen.go
Normal file
20
engine/gamemap/mapgen.go
Normal file
@ -0,0 +1,20 @@
|
||||
package gamemap
|
||||
|
||||
type mapGen interface {
|
||||
generate(l *Level) *Level
|
||||
}
|
||||
|
||||
type defaultGen struct {}
|
||||
|
||||
func (d defaultGen) generate(l *Level) *Level {
|
||||
|
||||
l.Tiles, rooms = addRooms(l)
|
||||
l. Tiles = connectRooms(rooms)
|
||||
l.Objects = populate(rooms)
|
||||
|
||||
return l
|
||||
}
|
||||
|
||||
func addRooms(l *Level) {
|
||||
|
||||
}
|
143
engine/gamemap/tile.go
Normal file
143
engine/gamemap/tile.go
Normal file
@ -0,0 +1,143 @@
|
||||
package gamemap
|
||||
|
||||
import "lab.zaar.be/thefish/alchemyst-go/util"
|
||||
import blt "lab.zaar.be/thefish/bearlibterminal"
|
||||
|
||||
type ColorHolder struct {
|
||||
R uint8
|
||||
G uint8
|
||||
B uint8
|
||||
}
|
||||
|
||||
type TileColorSet struct {
|
||||
Fg func() uint32
|
||||
Bg func() uint32
|
||||
DarkFg func() uint32
|
||||
DarkBg func() uint32
|
||||
current *ColorHolder
|
||||
}
|
||||
|
||||
type Appearance struct {
|
||||
Char string
|
||||
ColorSet *TileColorSet
|
||||
}
|
||||
|
||||
var crng = util.NewRNG()
|
||||
|
||||
func colordance(colorValue uint8, minGlow, maxGlow, step int) uint8 {
|
||||
color := crng.Range(0, step) + int(colorValue)
|
||||
if color > maxGlow {
|
||||
color = crng.Range(0, step) + minGlow
|
||||
}
|
||||
return uint8(color)
|
||||
}
|
||||
|
||||
type Tile struct {
|
||||
*Appearance
|
||||
Name string
|
||||
Description string
|
||||
BlocksPass bool
|
||||
BlocksSight bool
|
||||
Explored bool
|
||||
MustDraw bool
|
||||
}
|
||||
|
||||
|
||||
func NewWall() *Tile {
|
||||
return &Tile{
|
||||
Name: "Wall",
|
||||
Description: "A dull rock wall",
|
||||
BlocksPass: true,
|
||||
BlocksSight: true,
|
||||
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)},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func NewFloor() *Tile {
|
||||
return &Tile{
|
||||
Name: "Floor",
|
||||
Description: "Dusty rock floor",
|
||||
BlocksPass: false,
|
||||
BlocksSight: 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)},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func NewWaterTile() *Tile {
|
||||
ch := &ColorHolder{19,19,70}
|
||||
return &Tile {
|
||||
Name: "Water",
|
||||
Description: "Murky water",
|
||||
BlocksPass: false,
|
||||
BlocksSight: false,
|
||||
Explored: false,
|
||||
MustDraw: true, //fixme debug
|
||||
Appearance: &Appearance{
|
||||
Char: ".",
|
||||
ColorSet: &TileColorSet{
|
||||
current: ch,
|
||||
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),
|
||||
)
|
||||
},
|
||||
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",
|
||||
Description: "Deep water",
|
||||
BlocksPass: false,
|
||||
BlocksSight: false,
|
||||
Explored: false,
|
||||
MustDraw: true, //fixme debug
|
||||
Appearance: &Appearance{
|
||||
Char: " ",
|
||||
ColorSet: &TileColorSet{
|
||||
current: ch,
|
||||
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),
|
||||
)
|
||||
},
|
||||
DarkFg: func() uint32 {return blt.ColorFromARGB(255, 30,20,50)},
|
||||
DarkBg: func() uint32 {return blt.ColorFromARGB(255, 7,7,30)},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
5
engine/gamemap/types.go
Normal file
5
engine/gamemap/types.go
Normal file
@ -0,0 +1,5 @@
|
||||
package gamemap
|
||||
|
||||
type Coords struct {
|
||||
x,y int
|
||||
}
|
Reference in New Issue
Block a user