steel-lord/render.go

64 lines
1.7 KiB
Go
Raw Normal View History

2019-06-28 23:38:16 -07:00
package main
import (
"github.com/kettek/goro"
"github.com/kettek/goro/fov"
2019-06-28 23:38:16 -07:00
2019-07-17 20:05:05 -07:00
"steel/interfaces"
2019-06-28 23:38:16 -07:00
)
2019-07-02 23:55:29 -07:00
// DrawAll draws all entities and the gameMap to the screen and flushes it.
2019-07-19 21:08:46 -07:00
func DrawAll(screen *goro.Screen, entities []interfaces.Entity, gameMap interfaces.GameMap, fovMap fov.Map, fovRecompute bool, colors map[string]goro.Color) {
if fovRecompute {
2019-07-19 16:04:18 -07:00
// Draw all the tiles in the game map.
for x := 0; x < gameMap.Width(); x++ {
for y := 0; y < gameMap.Height(); y++ {
visible := fovMap.Visible(x, y)
if visible {
2019-07-19 16:04:18 -07:00
if gameMap.IsBlocked(x, y) {
screen.SetBackground(x, y, colors["lightWall"])
} else {
screen.SetBackground(x, y, colors["lightGround"])
2019-07-17 18:37:24 -07:00
}
2019-07-19 16:04:18 -07:00
gameMap.SetExplored(x, y, true)
} else if gameMap.Explored(x, y) {
if gameMap.IsBlocked(x, y) {
2019-07-17 18:37:24 -07:00
screen.SetBackground(x, y, colors["darkWall"])
} else {
screen.SetBackground(x, y, colors["darkGround"])
}
}
2019-07-02 23:55:29 -07:00
}
}
}
2019-07-17 18:37:24 -07:00
// Draw all the entities in the game map.
for _, entity := range entities {
2019-07-19 16:04:18 -07:00
DrawEntity(screen, entity, fovMap)
2019-07-17 18:37:24 -07:00
}
screen.Flush()
2019-06-28 23:38:16 -07:00
}
2019-06-28 23:38:16 -07:00
// ClearAll clears all entities from the screen.
2019-07-19 16:04:18 -07:00
func ClearAll(screen *goro.Screen, entities []interfaces.Entity, fovMap fov.Map) {
2019-06-28 23:38:16 -07:00
for _, entity := range entities {
2019-07-19 16:04:18 -07:00
ClearEntity(screen, entity, fovMap)
}
2019-06-28 23:38:16 -07:00
}
2019-06-28 23:38:16 -07:00
// DrawEntity draws a given entity to the screen.
2019-07-19 16:04:18 -07:00
func DrawEntity(screen *goro.Screen, e interfaces.Entity, fovMap fov.Map) {
if fovMap.Visible(e.X(), e.Y()) {
2019-07-19 21:08:46 -07:00
screen.SetRune(e.X(), e.Y(), e.Rune())
2019-07-19 16:04:18 -07:00
screen.SetForeground(e.X(), e.Y(), e.Style().Foreground)
}
2019-06-28 23:38:16 -07:00
}
2019-06-28 23:38:16 -07:00
// ClearEntity clears a given entity from the screen.
2019-07-19 16:04:18 -07:00
func ClearEntity(screen *goro.Screen, e interfaces.Entity, fovMap fov.Map) {
if fovMap.Visible(e.X(), e.Y()) {
screen.SetRune(e.X(), e.Y(), ' ')
}
}