steel-lord/render.go
2019-07-02 23:55:29 -07:00

41 lines
1.1 KiB
Go

package main
import (
"github.com/kettek/goro"
"steel/entity"
"steel/mapping"
)
// 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) {
// Draw all the tiles within the game map.
for x, column := range gameMap.Tiles {
for y, tile := range column {
if tile.BlockSight {
screen.SetBackground(x, y, colors["darkWall"])
} else {
screen.SetBackground(x, y, colors["darkGround"])
}
}
}
// Draw all the entities.
for _, entity := range entities {
DrawEntity(screen, entity)
}
screen.Flush()
}
// ClearAll clears all entities from the screen.
func ClearAll(screen *goro.Screen, entities[]*entity.Entity) {
for _, entity := range entities {
ClearEntity(screen, entity)
}
}
// DrawEntity draws a given entity to the screen.
func DrawEntity(screen *goro.Screen, e*entity.Entity) {
screen.DrawRune(e.X, e.Y, e.Rune, e.Style)
}
// ClearEntity clears a given entity from the screen.
func ClearEntity(screen *goro.Screen, e*entity.Entity) {
screen.DrawRune(e.X, e.Y, ' ', goro.Style{})
}