steel-lord/render.go

59 lines
1.5 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
"steel/entity"
2019-07-02 23:55:29 -07:00
"steel/mapping"
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.
func DrawAll(screen *goro.Screen, entities []*entity.Entity, gameMap mapping.GameMap, fovMap fov.Map, fovRecompute bool, colors map[string]goro.Color) {
if fovRecompute {
// Draw all the riles in the game map.
for x, column := range gameMap.Tiles {
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"])
2019-07-17 18:37:24 -07:00
}
} else {
2019-07-17 18:37:24 -07:00
if tile.BlockSight {
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 {
DrawEntity(screen, entity)
}
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-17 18:37:24 -07:00
func ClearAll(screen *goro.Screen, entities []*entity.Entity) {
2019-06-28 23:38:16 -07:00
for _, entity := range entities {
2019-07-17 18:37:24 -07:00
ClearEntity(screen, entity)
}
2019-06-28 23:38:16 -07:00
}
2019-06-28 23:38:16 -07:00
// DrawEntity draws a given entity to the screen.
func DrawEntity(screen *goro.Screen, e *entity.Entity) {
2019-06-28 23:38:16 -07:00
screen.DrawRune(e.X, e.Y, e.Rune, e.Style)
}
2019-06-28 23:38:16 -07:00
// ClearEntity clears a given entity from the screen.
func ClearEntity(screen *goro.Screen, e *entity.Entity) {
screen.SetRune(e.X, e.Y, ' ')
}