part 2 4/8

This commit is contained in:
Joel M. Southall 2019-06-28 23:38:16 -07:00
parent ace6a7d811
commit 8fceb614a7
3 changed files with 38 additions and 3 deletions

13
main.go
View File

@ -20,13 +20,20 @@ func main() {
// Our initial variables.
player := entity.NewEntity(screen.Columns/2, screen.Rows/2, '@', goro.Style{Foreground: goro.ColorWhite})
npc := entity.NewEntity(screen.Columns/2-5, screen. Rows/2, '@', goro.Style{Foreground: goro.ColorYellow})
entities := []*entity.Entity{
player,
npc,
}
// The game loop.
for {
// Draw screen.
screen.DrawRune(player.X, player.Y, player.Rune, player.Style)
screen.Flush()
screen.DrawRune(player.X, player.Y, ' ', goro.Style{})
DrawAll(screen, entities)
ClearAll(screen, entities)
// Handle events.
switch event := screen.WaitEvent().(type) {
case goro.EventKey:

28
render.go Normal file
View File

@ -0,0 +1,28 @@
package main
import (
"github.com/kettek/goro"
"steel/entity"
)
// DrawAll draws all entities to the screen and flushes it.
func DrawAll(screen *goro.Screen, entities[]*entity.Entity) {
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{})
}

BIN
steel Executable file

Binary file not shown.