Fixed the problem! Fov works now
This commit is contained in:
parent
8bbf6c4ff5
commit
eea1fa9388
7
fov.go
7
fov.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"steel/mapping"
|
"steel/mapping"
|
||||||
|
|
||||||
"github.com/kettek/goro/fov"
|
"github.com/kettek/goro/fov"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,10 +15,10 @@ func InitializeFoV(g *mapping.GameMap) fov.Map {
|
||||||
fovMap.SetBlocksLight(x, y, tile.BlockSight)
|
fovMap.SetBlocksLight(x, y, tile.BlockSight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fovMap
|
return fovMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func RecomputeFov(fovMap fov.Map, centerX, centerY int, radius int, fov.Light) {
|
func RecomputeFov(fovMap fov.Map, centerX, centerY int, radius int, fovLight fov.Light) {
|
||||||
fovMap.Recompute(centerX, centerY, radius, light)
|
fovMap.Recompute(centerX, centerY, radius, fovLight)
|
||||||
}
|
}
|
||||||
|
|
22
main.go
22
main.go
|
@ -1,13 +1,12 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"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"
|
||||||
|
|
||||||
|
"github.com/kettek/goro"
|
||||||
|
"github.com/kettek/goro/fov"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -32,14 +31,14 @@ func main() {
|
||||||
fovRecompute := true
|
fovRecompute := true
|
||||||
|
|
||||||
colors := map[string]goro.Color{
|
colors := map[string]goro.Color{
|
||||||
"darkWall": goro.Color{R: 25, G: 25, B: 25, A: 255},
|
"darkWall": goro.Color{R: 25, G: 25, B: 25, A: 255},
|
||||||
"darkGround": goro.Color{R: 100, G: 100, B: 100, A: 255},
|
"darkGround": goro.Color{R: 100, G: 100, B: 100, A: 255},
|
||||||
"lightWall": goro.Color{R: 50, G: 50, B: 50, A: 255},
|
"lightWall": goro.Color{R: 50, G: 50, B: 50, A: 255},
|
||||||
"lightGround": goro.Color{R: 150, G: 150, B: 150, A: 255},
|
"lightGround": goro.Color{R: 150, G: 150, B: 150, A: 255},
|
||||||
}
|
}
|
||||||
|
|
||||||
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})
|
||||||
|
|
||||||
entities := []*entity.Entity{
|
entities := []*entity.Entity{
|
||||||
player,
|
player,
|
||||||
|
@ -47,12 +46,12 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
gameMap := mapping.GameMap{
|
gameMap := mapping.GameMap{
|
||||||
Width: mapWidth,
|
Width: mapWidth,
|
||||||
Height: mapHeight,
|
Height: mapHeight,
|
||||||
}
|
}
|
||||||
|
|
||||||
gameMap.Initialize()
|
gameMap.Initialize()
|
||||||
|
|
||||||
gameMap.MakeMap(maxRooms, roomMinSize, roomMaxSize, player)
|
gameMap.MakeMap(maxRooms, roomMinSize, roomMaxSize, player)
|
||||||
|
|
||||||
fovMap := InitializeFoV(&gameMap)
|
fovMap := InitializeFoV(&gameMap)
|
||||||
|
@ -60,7 +59,7 @@ func main() {
|
||||||
for {
|
for {
|
||||||
|
|
||||||
if fovRecompute {
|
if fovRecompute {
|
||||||
RecomputeFoV(fovMap, player.X, player.Y, fovRadius, fov.Light{})
|
RecomputeFov(fovMap, player.X, player.Y, fovRadius, fov.Light{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw screen.
|
// Draw screen.
|
||||||
|
@ -77,6 +76,7 @@ func main() {
|
||||||
case ActionMove:
|
case ActionMove:
|
||||||
if !gameMap.IsBlocked(player.X+action.X, player.Y+action.Y) {
|
if !gameMap.IsBlocked(player.X+action.X, player.Y+action.Y) {
|
||||||
player.Move(action.X, action.Y)
|
player.Move(action.X, action.Y)
|
||||||
|
fovRecompute = true
|
||||||
}
|
}
|
||||||
case ActionQuit:
|
case ActionQuit:
|
||||||
goro.Quit()
|
goro.Quit()
|
||||||
|
|
26
render.go
26
render.go
|
@ -21,29 +21,29 @@ func DrawAll(screen *goro.Screen, entities []*entity.Entity, gameMap mapping.Gam
|
||||||
screen.SetBackground(x, y, colors["lightWall"])
|
screen.SetBackground(x, y, colors["lightWall"])
|
||||||
} else {
|
} else {
|
||||||
screen.SetBackground(x, y, colors["lightGround"])
|
screen.SetBackground(x, y, colors["lightGround"])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if tile.BlockSight {
|
if tile.BlockSight {
|
||||||
screen.SetBackground(x, y, colors["darkWall"])
|
screen.SetBackground(x, y, colors["darkWall"])
|
||||||
} else {
|
} else {
|
||||||
screen.SetBackground(x, y, colors["darkGround"])
|
screen.SetBackground(x, y, colors["darkGround"])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Draw all the entities in the game map.
|
// Draw all the entities in the game map.
|
||||||
for_, entity := range entities {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user