steel-lord/main.go

71 lines
1.4 KiB
Go
Raw Normal View History

2019-06-27 20:29:15 -07:00
package main
import (
"log"
"github.com/kettek/goro"
2019-06-28 16:37:33 -07:00
"steel/entity"
2019-07-02 23:55:29 -07:00
"steel/mapping"
2019-06-27 20:29:15 -07:00
)
func main() {
// Initialize goro!
if err := goro.InitEbiten(); err != nil {
2019-06-27 20:29:15 -07:00
log.Fatal(err)
}
goro.Run(func(screen *goro.Screen) {
// Screen configuration.
screen.SetTitle("Steel Lord")
screen.SetSize(80, 40)
2019-06-27 20:29:15 -07:00
// Our initial variables.
mapWidth, mapHeight := 80, 40
2019-07-02 23:55:29 -07:00
colors := map[string]goro.Color{
"darkWall": goro.ColorGray,
"darkGround": goro.ColorGreen,
2019-07-02 23:55:29 -07:00
}
gameMap := mapping.GameMap{
Width: mapWidth,
Height: mapHeight,
}
gameMap.Initialize()
2019-07-12 13:46:26 -07:00
gameMap.MakeMap()
player := entity.NewEntity(screen.Columns/2, screen.Rows/2+5, '@', goro.Style{Foreground: goro.ColorWhite})
2019-06-28 23:38:16 -07:00
npc := entity.NewEntity(screen.Columns/2-5, screen. Rows/2, '@', goro.Style{Foreground: goro.ColorYellow})
entities := []*entity.Entity{
player,
npc,
}
2019-06-27 20:29:15 -07:00
// The game loop.
for {
// Draw screen.
2019-07-02 23:55:29 -07:00
DrawAll(screen, entities, gameMap, colors)
2019-06-28 23:38:16 -07:00
ClearAll(screen, entities)
2019-06-27 20:29:15 -07:00
// Handle events.
switch event := screen.WaitEvent().(type) {
case goro.EventKey:
switch action := handleKeyEvent(event).(type) {
case ActionMove:
2019-07-02 23:55:29 -07:00
if !gameMap.IsBlocked(player.X+action.X, player.Y+action.Y) {
player.Move(action.X, action.Y)
}
2019-06-27 20:29:15 -07:00
case ActionQuit:
goro.Quit()
}
case goro.EventQuit:
return
}
}
})
}