precomputed shade algo, viewport basic render
This commit is contained in:
85
engine/fov/precomputed_shade/precomputed_shade_test.go
Normal file
85
engine/fov/precomputed_shade/precomputed_shade_test.go
Normal file
@ -0,0 +1,85 @@
|
||||
package precomputed_shade
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/types"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPsDistance(t *testing.T) {
|
||||
iterCoords := types.Coords{0, 0}
|
||||
|
||||
fmt.Printf("\n dto: \t %v", iterCoords.DistanceTo(types.Coords{0, 1}))
|
||||
fmt.Printf("\n dto: \t %v", iterCoords.DistanceTo(types.Coords{0, 5}))
|
||||
fmt.Printf("\n dto: \t %v", iterCoords.DistanceTo(types.Coords{3, 3}))
|
||||
fmt.Printf("\n dto: \t %v", iterCoords.DistanceTo(types.Coords{100, 0}))
|
||||
}
|
||||
|
||||
func TestPrecompShade(t *testing.T) {
|
||||
ppFov := NewPrecomputedShade(15)
|
||||
_ = ppFov
|
||||
t.Log("ok")
|
||||
|
||||
//level := gamemap.NewLevel(util.ClientCtx{}, "test", 1)
|
||||
|
||||
level := &gamemap.Level{
|
||||
Name: "test1",
|
||||
Depth: 1,
|
||||
Rect: types.NewRect(0, 0, 20, 20),
|
||||
}
|
||||
|
||||
level.Tiles = make([][]*gamemap.Tile, level.W)
|
||||
for i := range level.Tiles {
|
||||
level.Tiles[i] = make([]*gamemap.Tile, level.H)
|
||||
}
|
||||
|
||||
var tile func() (*gamemap.Tile)
|
||||
|
||||
for x := 0; x < level.W; x++ {
|
||||
for y := 0; y < level.H; y++ {
|
||||
if x == 0 || y == 0 || x == (level.W-1) || y == (level.H-1) {
|
||||
tile = gamemap.NewWall
|
||||
} else {
|
||||
tile = gamemap.NewFloor
|
||||
}
|
||||
level.Tiles[x][y] = tile()
|
||||
}
|
||||
}
|
||||
|
||||
playerCoords := types.Coords{10, 10}
|
||||
|
||||
level.Tiles[8][12] = gamemap.NewWall()
|
||||
level.Tiles[10][8] = gamemap.NewWall()
|
||||
|
||||
level.Tiles[7][9] = gamemap.NewWall()
|
||||
level.Tiles[7][11] = gamemap.NewWall()
|
||||
level.Tiles[5][10] = gamemap.NewWall()
|
||||
|
||||
level.Tiles[10][11] = gamemap.NewWall()
|
||||
level.Tiles[11][10] = gamemap.NewWall()
|
||||
|
||||
ppFov.ComputeFov(level, playerCoords, 15)
|
||||
|
||||
fmt.Printf("\n\n")
|
||||
|
||||
var render = func(x, y int) string {
|
||||
if playerCoords.X == x && playerCoords.Y == y {
|
||||
return "@"
|
||||
}
|
||||
result := level.Tiles[x][y].Char
|
||||
if !level.Tiles[x][y].Visible {
|
||||
result = "?"
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
for y := 0; y < level.H; y++ {
|
||||
for x := 0; x < level.W; x++ {
|
||||
|
||||
fmt.Printf("%s", render(x, y))
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user