part 2 4/8
This commit is contained in:
parent
ace6a7d811
commit
8fceb614a7
13
main.go
13
main.go
|
@ -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
28
render.go
Normal 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{})
|
||||
}
|
Loading…
Reference in New Issue
Block a user