Set initial name input to something random

This commit is contained in:
Trevor Slocum 2023-02-17 13:40:05 -08:00
parent e18fa170f1
commit 46c9a1e300
8 changed files with 244 additions and 9 deletions

View File

@ -18,6 +18,6 @@ func parseFlags() {
flag.Parse()
if skipIntro {
world.GameStarted = true
world.StartGame()
}
}

View File

@ -90,7 +90,7 @@ func (g *Game) handleTransition() error {
world.GameStarting--
if world.GameStarting == 0 {
world.GameStarted = true
world.StartGame()
}
}
return nil

1
go.mod
View File

@ -11,7 +11,6 @@ require (
github.com/ebitengine/purego v0.1.1 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
github.com/hajimehoshi/file2byteslice v1.0.0 // indirect
github.com/hajimehoshi/go-mp3 v0.3.3 // indirect
github.com/hajimehoshi/oto/v2 v2.3.1 // indirect
github.com/jezek/xgb v1.1.0 // indirect
github.com/jfreymuth/oggvorbis v1.0.4 // indirect

1
go.sum
View File

@ -13,7 +13,6 @@ github.com/hajimehoshi/ebiten/v2 v2.4.16/go.mod h1:BZcqCU4XHmScUi+lsKexocWcf4off
github.com/hajimehoshi/file2byteslice v0.0.0-20210813153925-5340248a8f41/go.mod h1:CqqAHp7Dk/AqQiwuhV1yT2334qbA/tFWQW0MD2dGqUE=
github.com/hajimehoshi/file2byteslice v1.0.0 h1:ljd5KTennqyJ4vG9i/5jS8MD1prof97vlH5JOdtw3WU=
github.com/hajimehoshi/file2byteslice v1.0.0/go.mod h1:CqqAHp7Dk/AqQiwuhV1yT2334qbA/tFWQW0MD2dGqUE=
github.com/hajimehoshi/go-mp3 v0.3.3 h1:cWnfRdpye2m9ElSoVqneYRcpt/l3ijttgjMeQh+r+FE=
github.com/hajimehoshi/go-mp3 v0.3.3/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=
github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
github.com/hajimehoshi/oto/v2 v2.3.1 h1:qrLKpNus2UfD674oxckKjNJmesp9hMh7u7QCrStB3Rc=

View File

@ -10,6 +10,7 @@ import (
type NewEmployee struct {
confirmTicks int
keys []ebiten.Key
}
func (r *NewEmployee) Update(_ gohan.Entity) error {
@ -30,12 +31,24 @@ func (r *NewEmployee) Update(_ gohan.Entity) error {
}
if world.Name == "" {
if world.NameInput == "" {
world.NameInput = "Test"
}
if inpututil.IsKeyJustPressed(ebiten.KeyEnter) || inpututil.IsKeyJustPressed(ebiten.KeyKPEnter) {
r.confirmTicks = world.TPS * 2.75
return nil
}
if inpututil.IsKeyJustPressed(ebiten.KeyBackspace) && len(world.NameInput) > 0 {
world.NameInput = world.NameInput[:len(world.NameInput)-1]
}
r.keys = inpututil.AppendPressedKeys(r.keys[:0])
for _, key := range r.keys {
if key >= ebiten.KeyA && key <= ebiten.KeyZ && inpututil.IsKeyJustPressed(key) {
char := 'a'
if ebiten.IsKeyPressed(ebiten.KeyShift) {
char = 'A'
}
world.NameInput += string(char + rune(key))
}
}
}
return nil

View File

@ -39,7 +39,7 @@ func (r *RenderUI) Draw(_ gohan.Entity, screen *ebiten.Image) error {
if world.Ticks > 6 {
r.drawText(screen, 2, 32, 64, true, "What is your name?")
if world.Ticks > 8 {
r.drawText(screen, 2, 64, 128, true, fmt.Sprintf("%s", world.NameInput))
r.drawText(screen, 2, 64, 128, true, fmt.Sprintf("%s_", world.NameInput))
}
}
}

207
world/names.go Normal file
View File

@ -0,0 +1,207 @@
package world
import "strings"
const allNames = `Trevor
Liam
Noah
Oliver
Elijah
James
William
Benjamin
Lucas
Henry
Theodore
Jack
Levi
Alexander
Jackson
Mateo
Daniel
Michael
Mason
Sebastian
Ethan
Logan
Owen
Samuel
Jacob
Asher
Aiden
John
Joseph
Wyatt
David
Leo
Luke
Julian
Hudson
Grayson
Matthew
Ezra
Gabriel
Carter
Isaac
Jayden
Luca
Anthony
Dylan
Lincoln
Thomas
Maverick
Elias
Josiah
Charles
Caleb
Christopher
Ezekiel
Miles
Jaxon
Isaiah
Andrew
Joshua
Nathan
Nolan
Adrian
Cameron
Santiago
Eli
Aaron
Ryan
Angel
Cooper
Waylon
Easton
Kai
Christian
Landon
Colton
Roman
Axel
Brooks
Jonathan
Robert
Jameson
Ian
Everett
Greyson
Wesley
Jeremiah
Hunter
Leonardo
Jordan
Jose
Bennett
Silas
Nicholas
Parker
Beau
Weston
Austin
Connor
Carson
Dominic
Xavier
Olivia
Emma
Charlotte
Amelia
Ava
Sophia
Isabella
Mia
Evelyn
Harper
Luna
Camila
Gianna
Elizabeth
Eleanor
Ella
Abigail
Sofia
Avery
Scarlett
Emily
Aria
Penelope
Chloe
Layla
Mila
Nora
Hazel
Madison
Ellie
Lily
Nova
Isla
Grace
Violet
Aurora
Riley
Zoey
Willow
Emilia
Stella
Zoe
Victoria
Hannah
Addison
Leah
Lucy
Eliana
Ivy
Everly
Lillian
Paisley
Elena
Naomi
Maya
Natalie
Kinsley
Delilah
Claire
Audrey
Aaliyah
Ruby
Brooklyn
Alice
Aubrey
Autumn
Leilani
Savannah
Valentina
Kennedy
Madelyn
Josephine
Bella
Skylar
Genesis
Sophie
Hailey
Sadie
Natalia
Quinn
Caroline
Allison
Gabriella
Anna
Serenity
Nevaeh
Cora
Ariana
Emery
Lydia
Jade
Sarah
Eva
Adeline
Madeline
Piper
Rylee
Athena
Peyton
Everleigh`
var Names = strings.Split(allNames, "\n")

View File

@ -1,5 +1,10 @@
package world
import (
"math/rand"
"time"
)
const (
ScreenWidth = 426
ScreenHeight = 240
@ -19,3 +24,15 @@ var (
DisableEsc bool
)
var Rand = rand.New(rand.NewSource(time.Now().UnixNano()))
func RandomName() string {
return Names[Rand.Intn(len(Names))]
}
func StartGame() {
Name = ""
NameInput = RandomName()
GameStarted = true
}