package main import ( "strings" "github.com/nsf/termbox-go" "gogs.bullercodeworks.com/brian/termbox-util" ) type command struct { key string description string } type titleScreen struct { titleArt *termboxUtil.ASCIIArt directions *termboxUtil.ASCIIArt menu *termboxUtil.Menu initialized bool } func (screen *titleScreen) handleKeyPress(event termbox.Event) int { if screen.menu.HandleEvent(event) { if screen.menu.IsDone() { selOpt := screen.menu.GetSelectedOption() if strings.Trim(selOpt.GetText(), " ") == "Exit" { return exitScreenIndex } else if strings.Trim(selOpt.GetText(), " ") == "New Game" { screen.initialized = false return mainScreenIndex } } } return titleScreenIndex } func (screen *titleScreen) performLayout(style style) { if !screen.initialized { var tmplt []string 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, " ") } 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("", []string{ " New Game ", " Exit "}, menuX, menuY, 20, 10, defaultFg, defaultBg, ) // TODO: Check if we have a suspended game screen.menu.EnableVimMode() 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) screen.initialized = true } } func (screen *titleScreen) update() {} func (screen *titleScreen) drawScreen(style style) { screen.titleArt.Draw() screen.menu.Draw() screen.directions.Draw() }