Skip to content

Commit

Permalink
add sim mode, adjust title music fade
Browse files Browse the repository at this point in the history
  • Loading branch information
liqMix committed Jul 16, 2024
1 parent f85d7a7 commit e9fe6c6
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 39 deletions.
5 changes: 4 additions & 1 deletion internal/game/audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ func NewAudioController() *AudioController {
}
}

func (a *AudioController) PlayTitleTrack() {
a.titleTrack.Play()
}

func (a *AudioController) PlayRoomTracks() {
a.tracksPaused = false
for _, track := range a.tracks {
Expand All @@ -151,7 +155,6 @@ func (a *AudioController) PlayRoomTracks() {
for _, track := range a.backgroundTracks {
track.Play()
}
a.titleTrack.Play()
}

func (a *AudioController) PauseRoomTracks() {
Expand Down
17 changes: 15 additions & 2 deletions internal/game/dude.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (

type Dude struct {
name string
invincible bool
xp int
gold int
profession ProfessionKind
Expand Down Expand Up @@ -612,8 +613,12 @@ func (d *Dude) ApplyDamage(amount int) (int, bool) {
amount = stats.ApplyDefense(amount)
d.stats.currentHp -= amount

if d.stats.currentHp < 0 {
d.stats.currentHp = 0
if d.stats.currentHp <= 0 {
if d.invincible {
d.stats.currentHp = d.stats.totalHp
} else {
d.stats.currentHp = 0
}
}

if d.stats.currentHp == 0 {
Expand Down Expand Up @@ -1064,6 +1069,14 @@ func (d *Dude) TrapDamage(roomLevel int) Activity {
}

func (d *Dude) IsDead() bool {
if d == nil {
return true
}

// Nope, not dead
if d.invincible && d.stats.currentHp <= 0 {
d.stats.currentHp = d.stats.totalHp
}
return d.stats.currentHp <= 0 || d.activity == Ded
}

Expand Down
32 changes: 28 additions & 4 deletions internal/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ type Game struct {
gold int
equipment []*Equipment
autoplay bool
playedTitleSong bool
simMode bool
touchIDs []ebiten.TouchID
releasedTouchIDs []ebiten.TouchID
titleFadeOutTick int
}

const TITLE_FADE_TICK = 60

type GameState interface {
Begin(g *Game)
End(g *Game)
Expand Down Expand Up @@ -152,9 +155,14 @@ func (g *Game) Update() error {
}
}
}
if g.playedTitleSong {
g.audioController.SetStoryPanVol(roomPanVol)
}
g.audioController.SetStoryPanVol(roomPanVol)
}

// Fade out title and fade in game.
if g.titleFadeOutTick > 0 {
g.titleFadeOutTick--
g.audioController.SetTitleTrackVolPercent(float64(g.titleFadeOutTick) / TITLE_FADE_TICK)
g.audioController.SetBackgroundTrackVolPercent(1.0 - float64(g.titleFadeOutTick)/TITLE_FADE_TICK)
}

return nil
Expand Down Expand Up @@ -413,10 +421,16 @@ func (g *Game) Init() {
}

func (g *Game) ToggleAutoplay() {
if g.simMode {
return
}
g.SetAutoplay(!g.autoplay)
}

func (g *Game) SetAutoplay(autoplay bool) {
if g.simMode {
return
}
g.autoplay = autoplay
if g.autoplay {
g.ui.speedPanel.autoplayButton.SetImage("autoplay")
Expand Down Expand Up @@ -482,6 +496,16 @@ func (g *Game) GetAliveDudes() []*Dude {
return dudes
}

func (g *Game) EnableSim() {
g.SetAutoplay(true)
g.simMode = true
}

func (g *Game) DisableSim() {
g.SetAutoplay(false)
g.simMode = false
}

func New() *Game {
return &Game{}
}
19 changes: 3 additions & 16 deletions internal/game/gamebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,9 @@ type GameStateBuild struct {
//
selectedEquipment int
shownBossWarning bool
titleFadeOutTick int
}

func (s *GameStateBuild) Begin(g *Game) {
// Fade out
s.titleFadeOutTick = 0

if !g.playedTitleSong {
s.titleFadeOutTick = AUDIO_FADE_IN_TICK
g.playedTitleSong = true
}

// Add feedback if next floor is boss
if len(g.tower.Stories)%2 == 0 && !s.shownBossWarning {
g.ui.feedback.Msg(FeedbackWarning, "...every 3rd floor is a boss floor... prepare yourself...")
Expand Down Expand Up @@ -322,13 +313,6 @@ func (s *GameStateBuild) End(g *Game) {
g.ToggleEnableUI(false)
}
func (s *GameStateBuild) Update(g *Game) GameState {
if s.titleFadeOutTick >= 0 {
s.titleFadeOutTick--
g.audioController.SetTitleTrackVolPercent(float64(s.titleFadeOutTick) / AUDIO_FADE_IN_TICK)
// Fade in background tracks
g.audioController.SetBackgroundTrackVolPercent(1.0 - float64(s.titleFadeOutTick)/AUDIO_FADE_IN_TICK)
}

// Check if we can fill
if g.gold < s.DudeCost(len(g.dudes)) {
g.ui.dudePanel.fillButton.hidden = true
Expand Down Expand Up @@ -637,6 +621,9 @@ func (s *GameStateBuild) BuyDude(g *Game) bool {
// Random profession ??
profession := WeightedRandomProfessionKind(g.dudes)
dude := NewDude(profession, level)
if g.simMode {
dude.invincible = true
}
g.dudes = append(g.dudes, dude)
g.ui.dudePanel.buyButton.text.SetText(fmt.Sprintf("Hire Dude\n%dgp", s.DudeCost(len(g.dudes))))
g.UpdateInfo()
Expand Down
1 change: 1 addition & 0 deletions internal/game/gamelose.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func (s *GameStateLose) Begin(g *Game) {
g.audioController.PlaySfx("loss", 0.5, 0.0)
}
func (s *GameStateLose) End(g *Game) {
g.titleFadeOutTick = 1
}
func (s *GameStateLose) Update(g *Game) GameState {
s.wobbler += 0.05
Expand Down
42 changes: 26 additions & 16 deletions internal/game/gamepre.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ type GameStatePre struct {
medium ButtonPanel
long ButtonPanel
infinite ButtonPanel
sim ButtonPanel
info *UIText

//
gameLength int
titleVolTick int
gameLength int
}

const AUDIO_FADE_IN_TICK = 60

func (s *GameStatePre) Begin(g *Game) {
g.audioController.PlayTitleTrack()
g.audioController.SetTitleTrackVolPercent(1)

// TODO: Hide UI crap.
g.ui.Hide()

// Always turn off autoplay (maybe???)
g.SetAutoplay(false)
// Turn off sim mode when choosing new game
g.DisableSim()

s.title = NewUIText("Time is your purgatory...", assets.DisplayFont, assets.ColorHeading)
s.title2 = NewUIText("choose wisely.", assets.DisplayFont, assets.ColorHeading)
Expand Down Expand Up @@ -65,6 +66,15 @@ func (s *GameStatePre) Begin(g *Game) {
s.info.SetText("How long can you last?")
}
s.infinite.text.SetText("endless")
s.sim = MakeButtonPanel(assets.DisplayFont, PanelStyleButton)
s.sim.onClick = func() {
s.gameLength = -1
g.EnableSim()
}
s.sim.onHover = func() {
s.info.SetText("Non-interactive mode where your dudes never die and never escape.")
}
s.sim.text.SetText("simulation")

s.info = NewUIText("beep boop", assets.BodyFont, assets.ColorStory)

Expand All @@ -77,29 +87,20 @@ func (s *GameStatePre) Begin(g *Game) {
g.ui.dudeInfoPanel.SetDude(nil)
g.ui.dudePanel.SetDudes(g.dudes)
g.ui.dudeInfoPanel.equipmentDetails.SetEquipment(nil)

// Init audio tick
g.audioController.PlayRoomTracks()
g.audioController.MuteAll()
g.playedTitleSong = false
s.titleVolTick = 0
}

func (s *GameStatePre) End(g *Game) {
g.ui.Reveal()
}
func (s *GameStatePre) Update(g *Game) GameState {
if s.titleVolTick < AUDIO_FADE_IN_TICK {
s.titleVolTick++
g.audioController.SetTitleTrackVolPercent(float64(s.titleVolTick) / AUDIO_FADE_IN_TICK)
}

w, h := float64(g.uiOptions.Width), float64(g.uiOptions.Height)

s.short.Layout(nil, &g.uiOptions)
s.medium.Layout(nil, &g.uiOptions)
s.long.Layout(nil, &g.uiOptions)
s.infinite.Layout(nil, &g.uiOptions)
s.sim.Layout(nil, &g.uiOptions)

panelsWidth := 0.0
panelsWidth += s.short.Width()
Expand Down Expand Up @@ -134,6 +135,10 @@ func (s *GameStatePre) Update(g *Game) GameState {
s.info.Layout(nil, &g.uiOptions)
s.info.SetPosition(w/2-s.info.Width()/2, y)

// Put sim mode below info
y += 32 + 4*g.uiOptions.Scale
s.sim.SetPosition(w/2-s.sim.Width()/2, y)

click := ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft)
if len(g.releasedTouchIDs) > 0 && inpututil.IsTouchJustReleased(g.releasedTouchIDs[0]) {
click = true
Expand All @@ -155,6 +160,10 @@ func (s *GameStatePre) Update(g *Game) GameState {
if click {
s.infinite.Check(mx, my, UICheckClick)
}
} else if s.sim.Check(mx, my, UICheckHover) {
if click {
s.sim.Check(mx, my, UICheckClick)
}
} else {
s.info.SetText("")
}
Expand All @@ -177,4 +186,5 @@ func (s *GameStatePre) Draw(g *Game, screen *ebiten.Image) {
s.medium.Draw(opts)
s.long.Draw(opts)
s.infinite.Draw(opts)
s.sim.Draw(opts)
}
6 changes: 6 additions & 0 deletions internal/game/gamestart.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ type GameStateStart struct {
}

func (s *GameStateStart) Begin(g *Game) {
g.titleFadeOutTick = TITLE_FADE_TICK
g.audioController.PlayRoomTracks()

if s.length == 0 {
s.length = 3
}
Expand All @@ -23,6 +26,9 @@ func (s *GameStateStart) Begin(g *Game) {
for i := 0; i < dudeLimit; i++ {
pk := professions[i%len(professions)]
dude := NewDude(pk, 1)
if g.simMode {
dude.invincible = true
}
s.newDudes = append(s.newDudes, dude)
}

Expand Down
1 change: 1 addition & 0 deletions internal/game/gamewin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func (s *GameStateWin) Begin(g *Game) {
g.audioController.PlaySfx("win", 0.5, 0.0)
}
func (s *GameStateWin) End(g *Game) {
g.titleFadeOutTick = 1
}

func (s *GameStateWin) Update(g *Game) GameState {
Expand Down

0 comments on commit e9fe6c6

Please sign in to comment.