steel-lord/main.go

107 lines
2.5 KiB
Go
Raw Permalink Normal View History

2019-06-27 20:29:15 -07:00
package main
import (
2019-07-24 21:04:21 -07:00
"fmt"
2019-07-16 18:52:08 -07:00
"log"
2019-06-28 16:37:33 -07:00
"steel/entity"
2019-07-17 20:05:05 -07:00
"steel/interfaces"
2019-07-02 23:55:29 -07:00
"steel/mapping"
2019-07-17 18:37:24 -07:00
"github.com/kettek/goro"
"github.com/kettek/goro/fov"
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)
}
2019-06-27 20:29:15 -07:00
goro.Run(func(screen *goro.Screen) {
// Screen configuration.
screen.SetTitle("Steel Lord")
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.
mapWidth, mapHeight := 80, 40
2019-07-16 18:52:08 -07:00
maxRooms, roomMinSize, roomMaxSize := 30, 6, 10
maxMonstersPerRoom := 3
gameState := PlayerTurnState
2019-07-02 23:55:29 -07:00
fovRadius := 10
fovRecompute := true
2019-07-02 23:55:29 -07:00
colors := map[string]goro.Color{
2019-07-17 18:37:24 -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(0, 0, '@', goro.Style{Foreground: goro.ColorWhite}, "Player", entity.BlockMovement)
2019-07-17 20:05:05 -07:00
entities := []interfaces.Entity{
player,
2019-07-02 23:55:29 -07:00
}
2019-07-19 21:08:46 -07:00
gameMap := mapping.NewGameMap(mapWidth, mapHeight)
2019-07-17 18:37:24 -07:00
gameMap.MakeMap(maxRooms, roomMinSize, roomMaxSize, &entities, maxMonstersPerRoom)
2019-07-02 23:55:29 -07:00
2019-07-19 21:08:46 -07:00
fovMap := InitializeFoV(gameMap)
2019-06-28 23:38:16 -07:00
2019-06-27 20:29:15 -07:00
for {
if fovRecompute {
2019-07-17 20:05:05 -07:00
RecomputeFov(fovMap, player.X(), player.Y(), fovRadius, fov.Light{})
}
2019-06-27 20:29:15 -07:00
// Draw screen.
DrawAll(screen, entities, gameMap, fovMap, fovRecompute, colors)
fovRecompute = false
2019-07-19 21:08:46 -07:00
ClearAll(screen, entities, fovMap)
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:
if gameState == PlayerTurnState {
x := player.X() + action.X
y := player.Y() + action.Y
if !gameMap.IsBlocked(x, y) {
otherEntity := entity.FindEntityAtLocation(entities, x, y, entity.BlockMovement, entity.BlockMovement)
if otherEntity != nil {
2019-07-24 21:04:21 -07:00
fmt.Printf("You lick the %s in the shins, much to its enjoyment!\n", otherEntity.Name())
} else {
player.Move(action.X, action.Y)
fovRecompute = true
}
}
2019-07-24 21:04:21 -07:00
gameState = NPCTurnState
2019-07-02 23:55:29 -07:00
}
2019-07-24 21:04:21 -07:00
case ActionQuit:
goro.Quit()
2019-06-27 20:29:15 -07:00
}
case goro.EventQuit:
return
}
// Handle entity updates.
if gameState == NPCTurnState {
for i, e := range entities {
if i > 0 {
2019-07-24 21:04:21 -07:00
fmt.Printf("The %s punders.\n", e.Name())
}
}
gameState = PlayerTurnState
}
2019-06-27 20:29:15 -07:00
}
})
}