parent
66e1fc7c77
commit
e18fa170f1
Binary file not shown.
@ -0,0 +1,23 @@
|
||||
//go:build !js || !wasm
|
||||
// +build !js !wasm
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"code.rocketnine.space/tslocum/gas-station-sim/world"
|
||||
)
|
||||
|
||||
func parseFlags() {
|
||||
var (
|
||||
skipIntro bool
|
||||
)
|
||||
flag.BoolVar(&world.Fullscreen, "fullscreen", true, "run in fullscreen mode")
|
||||
flag.BoolVar(&skipIntro, "skip-intro", false, "skip intro screen")
|
||||
flag.Parse()
|
||||
|
||||
if skipIntro {
|
||||
world.GameStarted = true
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"code.rocketnine.space/tslocum/gas-station-sim/world"
|
||||
)
|
||||
|
||||
func parseFlags() {
|
||||
world.DisableEsc = true
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"code.rocketnine.space/tslocum/gas-station-sim/asset"
|
||||
"code.rocketnine.space/tslocum/gas-station-sim/world"
|
||||
"code.rocketnine.space/tslocum/gohan"
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
||||
)
|
||||
|
||||
type NewEmployee struct {
|
||||
confirmTicks int
|
||||
}
|
||||
|
||||
func (r *NewEmployee) Update(_ gohan.Entity) error {
|
||||
if !world.GameStarted {
|
||||
return nil
|
||||
}
|
||||
|
||||
if r.confirmTicks != 0 {
|
||||
r.confirmTicks--
|
||||
|
||||
if r.confirmTicks == world.TPS*2.25 {
|
||||
asset.SoundHelloAndWelcome.Play()
|
||||
} else if r.confirmTicks == 0 {
|
||||
world.Name = world.NameInput
|
||||
world.NameInput = ""
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func (r *NewEmployee) Draw(_ gohan.Entity, screen *ebiten.Image) error {
|
||||
return nil
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
|
||||
"code.rocketnine.space/tslocum/gas-station-sim/world"
|
||||
"code.rocketnine.space/tslocum/gohan"
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||
)
|
||||
|
||||
type RenderUI struct {
|
||||
img *ebiten.Image
|
||||
}
|
||||
|
||||
func (r *RenderUI) Update(_ gohan.Entity) error {
|
||||
if r.img == nil {
|
||||
r.img = ebiten.NewImage(world.ScreenWidth, world.ScreenHeight)
|
||||
}
|
||||
|
||||
if !world.GameStarted {
|
||||
return nil
|
||||
}
|
||||
if world.Name == "" {
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RenderUI) Draw(_ gohan.Entity, screen *ebiten.Image) error {
|
||||
if !world.GameStarted {
|
||||
return nil
|
||||
}
|
||||
|
||||
if world.Name == "" {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RenderUI) drawText(screen *ebiten.Image, scale int, x int, y int, fill bool, text string) {
|
||||
const (
|
||||
paddingW = 6
|
||||
paddingH = 4
|
||||
)
|
||||
|
||||
l := len(text)
|
||||
textW, textH := 6*l+paddingW, 12+paddingH
|
||||
|
||||
rect := image.Rect(x, y, x+textW*scale, y+textH*scale)
|
||||
screen.SubImage(rect).(*ebiten.Image).Fill(color.White)
|
||||
screen.SubImage(rect.Inset(1)).(*ebiten.Image).Fill(color.Black)
|
||||
|
||||
r.img.Clear()
|
||||
ebitenutil.DebugPrintAt(r.img, text, 2+x/scale, y/scale)
|
||||
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
op.GeoM.Scale(float64(scale), float64(scale))
|
||||
//op.ColorM.ChangeHSV(0, 0, 0.8)
|
||||
screen.DrawImage(r.img, op)
|
||||
}
|
Loading…
Reference in new issue