2019-06-27 20:29:15 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/kettek/goro"
|
2019-07-17 01:30:15 -07:00
|
|
|
"github.com/kettek/goro-game/entity"
|
|
|
|
"github.com/kettek/goro-game/mapping"
|
|
|
|
"github.com/kettek/goro/fov"
|
2019-07-16 18:52:08 -07:00
|
|
|
"log"
|
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!
|
2019-07-12 23:01:35 -07:00
|
|
|
if err := goro.InitEbiten(); err != nil {
|
2019-06-27 20:29:15 -07:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2019-07-17 01:30:15 -07:00
|
|
|
|
2019-06-27 20:29:15 -07:00
|
|
|
goro.Run(func(screen *goro.Screen) {
|
|
|
|
// Screen configuration.
|
|
|
|
screen.SetTitle("Steel Lord")
|
2019-07-12 23:01:35 -07:00
|
|
|
screen.SetSize(80, 40)
|
2019-06-27 20:29:15 -07:00
|
|
|
|
2019-07-16 18:52:08 -07:00
|
|
|
// Randomize our seed so the map is randomized per run.
|
|
|
|
goro.SetSeed(goro.RandomSeed())
|
|
|
|
|
2019-06-27 20:29:15 -07:00
|
|
|
// Our initial variables.
|
2019-07-12 23:01:35 -07:00
|
|
|
mapWidth, mapHeight := 80, 40
|
2019-07-16 18:52:08 -07:00
|
|
|
maxRooms, roomMinSize, roomMaxSize := 30, 6, 10
|
2019-07-02 23:55:29 -07:00
|
|
|
|
2019-07-17 01:30:15 -07:00
|
|
|
fovRadius := 10
|
|
|
|
fovRecompute := true
|
|
|
|
|
2019-07-02 23:55:29 -07:00
|
|
|
colors := map[string]goro.Color{
|
2019-07-17 01:30:15 -07:00
|
|
|
"darkWall": goro.Color{R: 25, G: 25, B: 25, A: 255},
|
|
|
|
"darkGround": goro.Color{R: 100, G: 100, B: 100, A: 255},
|
|
|
|
"lightWall": goro.Color{R: 50, G: 50, B: 50, A: 255},
|
|
|
|
"lightGround": goro.Color{R: 150, G: 150, B: 150, A: 255},
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2019-07-02 23:55:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gameMap := mapping.GameMap{
|
|
|
|
Width: mapWidth,
|
|
|
|
Height: mapHeight,
|
|
|
|
}
|
|
|
|
|
|
|
|
gameMap.Initialize()
|
2019-07-17 01:30:15 -07:00
|
|
|
|
|
|
|
gameMap.MakeMap(maxRooms, roomMinSize, roomMaxSize, player)
|
2019-07-02 23:55:29 -07:00
|
|
|
|
2019-07-17 01:30:15 -07:00
|
|
|
fovMap := InitializeFoV(&gameMap)
|
2019-06-28 23:38:16 -07:00
|
|
|
|
2019-06-27 20:29:15 -07:00
|
|
|
for {
|
2019-07-17 01:30:15 -07:00
|
|
|
|
|
|
|
if fovRecompute {
|
|
|
|
RecomputeFoV(fovMap, player.X, player.Y, fovRadius, fov.Light{})
|
|
|
|
}
|
|
|
|
|
2019-06-27 20:29:15 -07:00
|
|
|
// Draw screen.
|
2019-07-17 01:30:15 -07:00
|
|
|
DrawAll(screen, entities, gameMap, fovMap, fovRecompute, colors)
|
|
|
|
|
|
|
|
fovRecompute = false
|
|
|
|
|
2019-06-28 23:38:16 -07:00
|
|
|
ClearAll(screen, entities)
|
2019-07-17 01:30:15 -07:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|