-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
94 lines (76 loc) · 2.2 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"fmt"
"image"
"image/color"
"log"
"time"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/joelschutz/stagehand"
)
const (
screenWidth = 640
screenHeight = 480
)
type State int
type BaseScene struct {
bounds image.Rectangle
count State
sm *stagehand.SceneManager[State]
}
func (s *BaseScene) Layout(w, h int) (int, int) {
s.bounds = image.Rect(0, 0, w, h)
return w, h
}
func (s *BaseScene) Load(st State, sm stagehand.SceneController[State]) {
s.count = st
s.sm = sm.(*stagehand.SceneManager[State])
}
func (s *BaseScene) Unload() State {
return s.count
}
type FirstScene struct {
BaseScene
}
func (s *FirstScene) Update() error {
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
s.count++
}
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) {
s.sm.SwitchWithTransition(&SecondScene{}, stagehand.NewTicksTimedSlideTransition[State](stagehand.LeftToRight, time.Second*time.Duration(s.count)))
}
return nil
}
func (s *FirstScene) Draw(screen *ebiten.Image) {
screen.Fill(color.RGBA{255, 0, 0, 255}) // Fill Red
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Count: %v, WindowSize: %s", s.count, s.bounds.Max), s.bounds.Dx()/2, s.bounds.Dy()/2)
}
type SecondScene struct {
BaseScene
}
func (s *SecondScene) Update() error {
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
s.count--
}
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) {
s.sm.SwitchWithTransition(&FirstScene{}, stagehand.NewDurationTimedSlideTransition[State](stagehand.RightToLeft, time.Second*time.Duration(s.count)))
}
return nil
}
func (s *SecondScene) Draw(screen *ebiten.Image) {
screen.Fill(color.RGBA{0, 0, 255, 255}) // Fill Blue
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Count: %v, WindowSize: %s", s.count, s.bounds.Max), s.bounds.Dx()/2, s.bounds.Dy()/2)
}
func main() {
ebiten.SetWindowSize(screenWidth, screenHeight)
ebiten.SetWindowTitle("My Game")
ebiten.SetWindowResizable(true)
state := State(3)
s := &FirstScene{}
sm := stagehand.NewSceneManager[State](s, state)
if err := ebiten.RunGame(sm); err != nil {
log.Fatal(err)
}
}