Skip to content

Commit eef3250

Browse files
author
Joel Schutz
committed
Simplify director example
1 parent 76bc96b commit eef3250

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

examples/director/main.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ const (
2424
)
2525

2626
type BaseScene struct {
27-
bounds image.Rectangle
28-
count State
29-
Condition State
30-
sm *stagehand.SceneDirector[State]
27+
bounds image.Rectangle
28+
count State
29+
active bool
30+
sm *stagehand.SceneDirector[State]
3131
}
3232

3333
func (s *BaseScene) Layout(w, h int) (int, int) {
@@ -37,10 +37,12 @@ func (s *BaseScene) Layout(w, h int) (int, int) {
3737

3838
func (s *BaseScene) Load(st State, sm stagehand.SceneController[State]) {
3939
s.count = st
40+
s.active = true
4041
s.sm = sm.(*stagehand.SceneDirector[State])
4142
}
4243

4344
func (s *BaseScene) Unload() State {
45+
s.active = false
4446
return s.count
4547
}
4648

@@ -52,15 +54,15 @@ func (s *FirstScene) Update() error {
5254
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
5355
s.count++
5456
}
55-
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) && s.count == s.Condition {
57+
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) && s.active {
5658
s.sm.ProcessTrigger(Trigger)
5759
}
5860
return nil
5961
}
6062

6163
func (s *FirstScene) Draw(screen *ebiten.Image) {
6264
screen.Fill(color.RGBA{255, 0, 0, 255}) // Fill Red
63-
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Count: %v, WindowSize: %s\nCan Switch? %v", s.count, s.bounds.Max, s.count == s.Condition), s.bounds.Dx()/2, s.bounds.Dy()/2)
65+
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Count: %v, WindowSize: %s\nActive? %v", s.count, s.bounds.Max, s.active), s.bounds.Dx()/2, s.bounds.Dy()/2)
6466
}
6567

6668
type SecondScene struct {
@@ -71,15 +73,15 @@ func (s *SecondScene) Update() error {
7173
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
7274
s.count--
7375
}
74-
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) && s.count <= s.Condition {
76+
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) && s.active {
7577
s.sm.ProcessTrigger(Trigger)
7678
}
7779
return nil
7880
}
7981

8082
func (s *SecondScene) Draw(screen *ebiten.Image) {
8183
screen.Fill(color.RGBA{0, 0, 255, 255}) // Fill Blue
82-
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Count: %v, WindowSize: %s\nCan Switch? %v", s.count, s.bounds.Max, s.count <= s.Condition), s.bounds.Dx()/2, s.bounds.Dy()/2)
84+
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Count: %v, WindowSize: %s\nActive? %v", s.count, s.bounds.Max, s.active), s.bounds.Dx()/2, s.bounds.Dy()/2)
8385
}
8486

8587
type ThirdScene struct {
@@ -90,15 +92,15 @@ func (s *ThirdScene) Update() error {
9092
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
9193
s.count++
9294
}
93-
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) && s.count >= s.Condition {
95+
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) && s.active {
9496
s.sm.ProcessTrigger(Trigger)
9597
}
9698
return nil
9799
}
98100

99101
func (s *ThirdScene) Draw(screen *ebiten.Image) {
100102
screen.Fill(color.RGBA{0, 255, 0, 255}) // Fill Green
101-
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Count: %v, WindowSize: %s\nCan Switch? %v", s.count, s.bounds.Max, s.count >= s.Condition), s.bounds.Dx()/2, s.bounds.Dy()/2)
103+
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Count: %v, WindowSize: %s\nActive? %v", s.count, s.bounds.Max, s.active), s.bounds.Dx()/2, s.bounds.Dy()/2)
102104
}
103105

104106
func main() {
@@ -108,9 +110,9 @@ func main() {
108110

109111
state := State(10)
110112

111-
s1 := &FirstScene{BaseScene{Condition: 10}}
112-
s2 := &SecondScene{BaseScene{Condition: 5}}
113-
s3 := &ThirdScene{BaseScene{Condition: 15}}
113+
s1 := &FirstScene{}
114+
s2 := &SecondScene{}
115+
s3 := &ThirdScene{}
114116
trans := stagehand.NewSlideTransition[State](stagehand.BottomToTop, 0.02)
115117
trans2 := stagehand.NewSlideTransition[State](stagehand.TopToBottom, 0.02)
116118
trans3 := stagehand.NewSlideTransition[State](stagehand.LeftToRight, 0.02)

0 commit comments

Comments
 (0)