got to 3/6 of part 4, but failed to build
This commit is contained in:
parent
643bcfbf41
commit
8bbf6c4ff5
23
fov.go
Normal file
23
fov.go
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"steel/mapping"
|
||||||
|
"github.com/kettek/goro/fov"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InitializeFoV(g *mapping.GameMap) fov.Map {
|
||||||
|
fovMap := fov.NewMap(g.Width, g.Height, fov.AlgorithmBBQ)
|
||||||
|
|
||||||
|
for x := range g.Tiles {
|
||||||
|
for y, tile := range g.Tiles[x] {
|
||||||
|
fovMap.SetBlocksMovement(x, y, tile.BlockMovement)
|
||||||
|
fovMap.SetBlocksLight(x, y, tile.BlockSight)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fovMap
|
||||||
|
}
|
||||||
|
|
||||||
|
func RecomputeFov(fovMap fov.Map, centerX, centerY int, radius int, fov.Light) {
|
||||||
|
fovMap.Recompute(centerX, centerY, radius, light)
|
||||||
|
}
|
1
go.mod
1
go.mod
|
@ -4,5 +4,6 @@ go 1.12
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/kettek/goro v0.0.0-20190716230418-ed743d8603f6
|
github.com/kettek/goro v0.0.0-20190716230418-ed743d8603f6
|
||||||
|
github.com/kettek/goro-game v0.0.0-20190715002527-c93e962913d4
|
||||||
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb // indirect
|
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb // indirect
|
||||||
)
|
)
|
||||||
|
|
3
go.sum
3
go.sum
|
@ -34,10 +34,13 @@ github.com/kettek/goro v0.0.0-20190713012210-db6dc3381a1e h1:8UPf9Di15NxRSHdPi0Z
|
||||||
github.com/kettek/goro v0.0.0-20190713012210-db6dc3381a1e/go.mod h1:fO57DVF4MXRm+AOQWrFN0CFCbihOO36HUn42vjr00fU=
|
github.com/kettek/goro v0.0.0-20190713012210-db6dc3381a1e/go.mod h1:fO57DVF4MXRm+AOQWrFN0CFCbihOO36HUn42vjr00fU=
|
||||||
github.com/kettek/goro v0.0.0-20190713012409-1029522674ba h1:HFhcgGAbvE1IhToLKr6IDfI7B2isbYY2yzB6rxV/mwQ=
|
github.com/kettek/goro v0.0.0-20190713012409-1029522674ba h1:HFhcgGAbvE1IhToLKr6IDfI7B2isbYY2yzB6rxV/mwQ=
|
||||||
github.com/kettek/goro v0.0.0-20190713012409-1029522674ba/go.mod h1:fO57DVF4MXRm+AOQWrFN0CFCbihOO36HUn42vjr00fU=
|
github.com/kettek/goro v0.0.0-20190713012409-1029522674ba/go.mod h1:fO57DVF4MXRm+AOQWrFN0CFCbihOO36HUn42vjr00fU=
|
||||||
|
github.com/kettek/goro v0.0.0-20190714065548-99acc2c2dfc6/go.mod h1:fO57DVF4MXRm+AOQWrFN0CFCbihOO36HUn42vjr00fU=
|
||||||
github.com/kettek/goro v0.0.0-20190716001741-2ca1aaeebd5b h1:CMDJNDNpm6/ThhLQDxUSR475u49Bu5W4dVaVMxBCk0Q=
|
github.com/kettek/goro v0.0.0-20190716001741-2ca1aaeebd5b h1:CMDJNDNpm6/ThhLQDxUSR475u49Bu5W4dVaVMxBCk0Q=
|
||||||
github.com/kettek/goro v0.0.0-20190716001741-2ca1aaeebd5b/go.mod h1:fO57DVF4MXRm+AOQWrFN0CFCbihOO36HUn42vjr00fU=
|
github.com/kettek/goro v0.0.0-20190716001741-2ca1aaeebd5b/go.mod h1:fO57DVF4MXRm+AOQWrFN0CFCbihOO36HUn42vjr00fU=
|
||||||
github.com/kettek/goro v0.0.0-20190716230418-ed743d8603f6 h1:+0W0fQIvYWnyS/tHViIQJjUBZ4Cm+8Bl6XZTR8jjrwU=
|
github.com/kettek/goro v0.0.0-20190716230418-ed743d8603f6 h1:+0W0fQIvYWnyS/tHViIQJjUBZ4Cm+8Bl6XZTR8jjrwU=
|
||||||
github.com/kettek/goro v0.0.0-20190716230418-ed743d8603f6/go.mod h1:fO57DVF4MXRm+AOQWrFN0CFCbihOO36HUn42vjr00fU=
|
github.com/kettek/goro v0.0.0-20190716230418-ed743d8603f6/go.mod h1:fO57DVF4MXRm+AOQWrFN0CFCbihOO36HUn42vjr00fU=
|
||||||
|
github.com/kettek/goro-game v0.0.0-20190715002527-c93e962913d4 h1:lKD8ikzpJJNDFrEr4IOutR1xPrrAm4XSvw4+jqXzquQ=
|
||||||
|
github.com/kettek/goro-game v0.0.0-20190715002527-c93e962913d4/go.mod h1:I19bCZN5DV5IpzeLR2WHbxnXEwsLnfms3ZszaTjoJUo=
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
|
|
41
main.go
41
main.go
|
@ -2,8 +2,10 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/kettek/goro"
|
"github.com/kettek/goro"
|
||||||
|
"github.com/kettek/goro-game/entity"
|
||||||
|
"github.com/kettek/goro-game/mapping"
|
||||||
|
"github.com/kettek/goro/fov"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"steel/entity"
|
"steel/entity"
|
||||||
"steel/mapping"
|
"steel/mapping"
|
||||||
)
|
)
|
||||||
|
@ -13,6 +15,7 @@ func main() {
|
||||||
if err := goro.InitEbiten(); err != nil {
|
if err := goro.InitEbiten(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
goro.Run(func(screen *goro.Screen) {
|
goro.Run(func(screen *goro.Screen) {
|
||||||
// Screen configuration.
|
// Screen configuration.
|
||||||
screen.SetTitle("Steel Lord")
|
screen.SetTitle("Steel Lord")
|
||||||
|
@ -25,18 +28,16 @@ func main() {
|
||||||
mapWidth, mapHeight := 80, 40
|
mapWidth, mapHeight := 80, 40
|
||||||
maxRooms, roomMinSize, roomMaxSize := 30, 6, 10
|
maxRooms, roomMinSize, roomMaxSize := 30, 6, 10
|
||||||
|
|
||||||
|
fovRadius := 10
|
||||||
|
fovRecompute := true
|
||||||
|
|
||||||
colors := map[string]goro.Color{
|
colors := map[string]goro.Color{
|
||||||
"darkWall": goro.ColorGray,
|
"darkWall": goro.Color{R: 25, G: 25, B: 25, A: 255},
|
||||||
"darkGround": goro.ColorGreen,
|
"darkGround": goro.Color{R: 100, G: 100, B: 100, A: 255},
|
||||||
|
"lightWall": goro.Color{R: 50, G: 50, B: 50, A: 255},
|
||||||
|
"lightGround": goro.Color{R: 150, G: 150, B: 150, A: 255},
|
||||||
}
|
}
|
||||||
|
|
||||||
gameMap := mapping.GameMap{
|
|
||||||
Width: mapWidth,
|
|
||||||
Height: mapHeight,
|
|
||||||
}
|
|
||||||
|
|
||||||
gameMap.Initialize()
|
|
||||||
|
|
||||||
player := entity.NewEntity(screen.Columns/2, screen.Rows/2+5, '@', goro.Style{Foreground: goro.ColorWhite})
|
player := entity.NewEntity(screen.Columns/2, screen.Rows/2+5, '@', goro.Style{Foreground: goro.ColorWhite})
|
||||||
npc := entity.NewEntity(screen.Columns/2-5, screen. Rows/2, '@', goro.Style{Foreground: goro.ColorYellow})
|
npc := entity.NewEntity(screen.Columns/2-5, screen. Rows/2, '@', goro.Style{Foreground: goro.ColorYellow})
|
||||||
|
|
||||||
|
@ -45,12 +46,30 @@ func main() {
|
||||||
npc,
|
npc,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gameMap := mapping.GameMap{
|
||||||
|
Width: mapWidth,
|
||||||
|
Height: mapHeight,
|
||||||
|
}
|
||||||
|
|
||||||
|
gameMap.Initialize()
|
||||||
|
|
||||||
gameMap.MakeMap(maxRooms, roomMinSize, roomMaxSize, player)
|
gameMap.MakeMap(maxRooms, roomMinSize, roomMaxSize, player)
|
||||||
|
|
||||||
|
fovMap := InitializeFoV(&gameMap)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|
||||||
|
if fovRecompute {
|
||||||
|
RecomputeFoV(fovMap, player.X, player.Y, fovRadius, fov.Light{})
|
||||||
|
}
|
||||||
|
|
||||||
// Draw screen.
|
// Draw screen.
|
||||||
DrawAll(screen, entities, gameMap, colors)
|
DrawAll(screen, entities, gameMap, fovMap, fovRecompute, colors)
|
||||||
|
|
||||||
|
fovRecompute = false
|
||||||
|
|
||||||
ClearAll(screen, entities)
|
ClearAll(screen, entities)
|
||||||
|
|
||||||
// Handle events.
|
// Handle events.
|
||||||
switch event := screen.WaitEvent().(type) {
|
switch event := screen.WaitEvent().(type) {
|
||||||
case goro.EventKey:
|
case goro.EventKey:
|
||||||
|
|
27
render.go
27
render.go
|
@ -2,15 +2,27 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/kettek/goro"
|
"github.com/kettek/goro"
|
||||||
|
"github.com/kettek/goro/fov"
|
||||||
|
|
||||||
"steel/entity"
|
"steel/entity"
|
||||||
"steel/mapping"
|
"steel/mapping"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DrawAll draws all entities and the gameMap to the screen and flushes it.
|
// DrawAll draws all entities and the gameMap to the screen and flushes it.
|
||||||
func DrawAll(screen *goro.Screen, entities[]*entity.Entity, gameMap mapping.GameMap, colors map[string]goro.Color) {
|
func DrawAll(screen *goro.Screen, entities []*entity.Entity, gameMap mapping.GameMap, fovMap fov.Map, fovRecompute bool, colors map[string]goro.Color) {
|
||||||
// Draw all the tiles within the game map.
|
if fovRecompute {
|
||||||
|
// Draw all the riles in the game map.
|
||||||
for x, column := range gameMap.Tiles {
|
for x, column := range gameMap.Tiles {
|
||||||
for y, tile := range column {
|
for y, tile := range column {
|
||||||
|
visible := fovMap.Visible(x, y)
|
||||||
|
|
||||||
|
if visible {
|
||||||
|
if tile.BlockSight {
|
||||||
|
screen.SetBackground(x, y, colors["lightWall"])
|
||||||
|
} else {
|
||||||
|
screen.SetBackground(x, y, colors["lightGround"])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if tile.BlockSight {
|
if tile.BlockSight {
|
||||||
screen.SetBackground(x, y, colors["darkWall"])
|
screen.SetBackground(x, y, colors["darkWall"])
|
||||||
} else {
|
} else {
|
||||||
|
@ -18,24 +30,29 @@ func DrawAll(screen *goro.Screen, entities[]*entity.Entity, gameMap mapping.Game
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Draw all the entities.
|
}
|
||||||
for _, entity := range entities {
|
}
|
||||||
|
|
||||||
|
// Draw all the entities in the game map.
|
||||||
|
for_, entity := range entities {
|
||||||
DrawEntity(screen, entity)
|
DrawEntity(screen, entity)
|
||||||
}
|
}
|
||||||
screen.Flush()
|
screen.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearAll clears all entities from the screen.
|
// ClearAll clears all entities from the screen.
|
||||||
func ClearAll(screen *goro.Screen, entities[]*entity.Entity) {
|
func ClearAll(screen *goro.Screen, entities[]*entity.Entity) {
|
||||||
for _, entity := range entities {
|
for _, entity := range entities {
|
||||||
ClearEntity(screen, entity)
|
ClearEntity(screen, entity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DrawEntity draws a given entity to the screen.
|
// DrawEntity draws a given entity to the screen.
|
||||||
func DrawEntity(screen *goro.Screen, e *entity.Entity) {
|
func DrawEntity(screen *goro.Screen, e *entity.Entity) {
|
||||||
screen.DrawRune(e.X, e.Y, e.Rune, e.Style)
|
screen.DrawRune(e.X, e.Y, e.Rune, e.Style)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearEntity clears a given entity from the screen.
|
// ClearEntity clears a given entity from the screen.
|
||||||
func ClearEntity(screen *goro.Screen, e *entity.Entity) {
|
func ClearEntity(screen *goro.Screen, e *entity.Entity) {
|
||||||
screen.DrawRune(e.X, e.Y, ' ', goro.Style{})
|
screen.SetRune(e.X, e.Y, ' ')
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user