steel-lord/main.go
2019-07-16 18:52:08 -07:00

71 lines
1.5 KiB
Go

package main
import (
"github.com/kettek/goro"
"log"
"steel/entity"
"steel/mapping"
)
func main() {
// Initialize goro!
if err := goro.InitEbiten(); err != nil {
log.Fatal(err)
}
goro.Run(func(screen *goro.Screen) {
// Screen configuration.
screen.SetTitle("Steel Lord")
screen.SetSize(80, 40)
// Randomize our seed so the map is randomized per run.
goro.SetSeed(goro.RandomSeed())
// Our initial variables.
mapWidth, mapHeight := 80, 40
maxRooms, roomMinSize, roomMaxSize := 30, 6, 10
colors := map[string]goro.Color{
"darkWall": goro.ColorGray,
"darkGround": goro.ColorGreen,
}
gameMap := mapping.GameMap{
Width: mapWidth,
Height: mapHeight,
}
gameMap.Initialize()
player := entity.NewEntity(screen.Columns/2, screen.Rows/2+5, '@', 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,
}
gameMap.MakeMap(maxRooms, roomMinSize, roomMaxSize, player)
for {
// Draw screen.
DrawAll(screen, entities, gameMap, colors)
ClearAll(screen, entities)
// Handle events.
switch event := screen.WaitEvent().(type) {
case goro.EventKey:
switch action := handleKeyEvent(event).(type) {
case ActionMove:
if !gameMap.IsBlocked(player.X+action.X, player.Y+action.Y) {
player.Move(action.X, action.Y)
}
case ActionQuit:
goro.Quit()
}
case goro.EventQuit:
return
}
}
})
}