114 lines
2.3 KiB
Go
114 lines
2.3 KiB
Go
package system
|
|
|
|
import (
|
|
"log"
|
|
"time"
|
|
|
|
"code.rocketnine.space/tslocum/gas-station-sim/asset"
|
|
"github.com/hajimehoshi/ebiten/v2/audio"
|
|
|
|
"code.rocketnine.space/tslocum/gas-station-sim/world"
|
|
"code.rocketnine.space/tslocum/gohan"
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
)
|
|
|
|
type speakPhrase int
|
|
|
|
const (
|
|
phraseUnknown speakPhrase = iota
|
|
phraseEight
|
|
phraseTwenty
|
|
phraseOnPump
|
|
)
|
|
|
|
type Customer struct {
|
|
}
|
|
|
|
const CashTime = world.TPS * 5.25
|
|
|
|
func (r *Customer) Update(_ gohan.Entity) error {
|
|
if !world.TutorialIntroFinished {
|
|
return nil
|
|
}
|
|
|
|
world.CustomerGenderMale = false
|
|
|
|
const SpeakTime = world.TPS * 3.5
|
|
|
|
if world.CustomerTicks == 0 {
|
|
world.CustomerGenderMale = world.Rand.Intn(2) == 0
|
|
|
|
asset.SoundChime.Rewind()
|
|
//asset.SoundChime.Play()
|
|
// TODO
|
|
} else if world.CustomerTicks == SpeakTime {
|
|
//go r.Speak(phraseTwenty, phraseOnPump, phraseEight)
|
|
}
|
|
world.CustomerTicks++
|
|
return nil
|
|
}
|
|
|
|
func (r *Customer) Draw(_ gohan.Entity, screen *ebiten.Image) error {
|
|
if !world.TutorialIntroFinished {
|
|
return nil
|
|
}
|
|
|
|
const waitTime = world.TPS * 2.5
|
|
const fadeInEnd = world.TPS * 3
|
|
|
|
if world.CustomerTicks > waitTime {
|
|
scale := 1.0
|
|
if world.CustomerTicks < fadeInEnd {
|
|
scale = float64(world.CustomerTicks-waitTime) / float64(fadeInEnd-waitTime)
|
|
}
|
|
|
|
customerImg := asset.ImageCustomerFrontMale
|
|
if !world.CustomerGenderMale {
|
|
customerImg = asset.ImageCustomerFrontFemale
|
|
}
|
|
|
|
op := &ebiten.DrawImageOptions{}
|
|
op.GeoM.Translate(128, 16)
|
|
op.ColorM.Scale(1, 1, 1, scale)
|
|
screen.DrawImage(customerImg, op)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (r *Customer) Speak(phrase ...speakPhrase) {
|
|
var sound *audio.Player
|
|
var waitTime time.Duration
|
|
for _, p := range phrase {
|
|
switch p {
|
|
case phraseEight:
|
|
if world.CustomerGenderMale {
|
|
sound = asset.SoundEightMale
|
|
} else {
|
|
sound = asset.SoundEightFemale
|
|
}
|
|
waitTime = 600 * time.Millisecond
|
|
case phraseTwenty:
|
|
if world.CustomerGenderMale {
|
|
sound = asset.SoundTwentyMale
|
|
} else {
|
|
sound = asset.SoundTwentyFemale
|
|
}
|
|
waitTime = 600 * time.Millisecond
|
|
case phraseOnPump:
|
|
if world.CustomerGenderMale {
|
|
sound = asset.SoundOnPumpMale
|
|
} else {
|
|
sound = asset.SoundOnPumpFemale
|
|
}
|
|
waitTime = 650 * time.Millisecond
|
|
default:
|
|
log.Printf("warning: unknown phrase %d", phrase)
|
|
return
|
|
}
|
|
sound.Rewind()
|
|
sound.Play()
|
|
|
|
time.Sleep(waitTime)
|
|
}
|
|
}
|