gopher-battle/screen_title.go

93 lines
3.1 KiB
Go
Raw Normal View History

2016-01-06 18:24:08 +00:00
package main
import (
2016-01-09 04:56:46 +00:00
"strings"
2016-01-06 18:24:08 +00:00
"github.com/nsf/termbox-go"
"gogs.bullercodeworks.com/brian/termbox-util"
)
type command struct {
key string
description string
}
type titleScreen struct {
titleArt *termboxUtil.ASCIIArt
2016-01-09 04:56:46 +00:00
directions *termboxUtil.ASCIIArt
2016-01-06 18:24:08 +00:00
menu *termboxUtil.Menu
initialized bool
}
2016-01-07 04:04:42 +00:00
func (screen *titleScreen) handleKeyPress(event termbox.Event) int {
if screen.menu.HandleEvent(event) {
2016-01-06 18:24:08 +00:00
if screen.menu.IsDone() {
selOpt := screen.menu.GetSelectedOption()
2016-01-09 04:56:46 +00:00
if strings.Trim(selOpt.GetText(), " ") == "Exit" {
2016-01-06 18:24:08 +00:00
return exitScreenIndex
2016-01-09 04:56:46 +00:00
} else if strings.Trim(selOpt.GetText(), " ") == "New Game" {
2016-01-06 18:24:08 +00:00
screen.initialized = false
return mainScreenIndex
}
}
}
return titleScreenIndex
}
func (screen *titleScreen) performLayout(style style) {
if !screen.initialized {
var tmplt []string
2016-01-08 21:44:35 +00:00
if ScreenWidth >= 87 {
tmplt = append(tmplt, " ________ .__ __________ __ __ .__ ")
tmplt = append(tmplt, " / _____/ ____ ______ | |__ ___________ \\______ _____ _/ |__/ |_| | ____ ")
tmplt = append(tmplt, "/ \\ ___ / _ \\\\____ \\| | \\_/ __ \\_ __ \\ | | _\\__ \\\\ __\\ __| | _/ __ \\ ")
tmplt = append(tmplt, "\\ \\_\\ ( <_> | |_> | Y \\ ___/| | \\/ | | \\/ __ \\| | | | | |_\\ ___/ ")
tmplt = append(tmplt, " \\______ /\\____/| __/|___| /\\___ |__| |______ (____ |__| |__| |____/\\___ >")
tmplt = append(tmplt, " \\/ |__| \\/ \\/ \\/ \\/ \\/ ")
} else {
tmplt = append(tmplt, " ")
tmplt = append(tmplt, " ")
tmplt = append(tmplt, " Gopher Battle ")
tmplt = append(tmplt, " ")
tmplt = append(tmplt, " ")
tmplt = append(tmplt, " ")
}
2016-01-06 18:24:08 +00:00
defaultFg := style.defaultFg
defaultBg := style.defaultBg
screen.titleArt = termboxUtil.CreateASCIIArt(tmplt, 0, 0, defaultFg, defaultBg)
w, h := termbox.Size()
screen.titleArt.Align(termboxUtil.AlignCenter, w)
menuX := w/2 - 10
menuY := h/2 - 5
screen.menu = termboxUtil.CreateMenu("",
2016-01-09 04:56:46 +00:00
[]string{
" New Game ",
" Exit "},
2016-01-06 18:24:08 +00:00
menuX, menuY, 20, 10, defaultFg, defaultBg,
)
// TODO: Check if we have a suspended game
screen.menu.EnableVimMode()
2016-01-09 04:56:46 +00:00
var directions []string
directions = append(directions, " Directions: ")
directions = append(directions, " Up/Down adjust Speed ")
directions = append(directions, " Left/Right adjust Angle ")
directions = append(directions, " Space to Fire ")
directions = append(directions, " W,A,S,D also work ")
screen.directions = termboxUtil.CreateASCIIArt(directions, 0, menuX+10, defaultFg, defaultBg)
screen.directions.Align(termboxUtil.AlignCenter, w)
2016-01-06 18:24:08 +00:00
screen.initialized = true
}
}
func (screen *titleScreen) update() {}
func (screen *titleScreen) drawScreen(style style) {
screen.titleArt.Draw()
screen.menu.Draw()
2016-01-09 04:56:46 +00:00
screen.directions.Draw()
2016-01-06 18:24:08 +00:00
}