diff --git a/examples/community/scene/README.md b/examples/community/scene/README.md new file mode 100644 index 0000000..9e1efb9 --- /dev/null +++ b/examples/community/scene/README.md @@ -0,0 +1,8 @@ +# Scene + +Created by [Jason Wangsadinata][jwangsadinata]. + +This is just a simple example on how to create scenes in [Pixel][pixel]. + +[jwangsadinata]: https://github.com/jwangsadinata +[pixel]: https://github.com/faiface/pixel diff --git a/examples/community/scene/main.go b/examples/community/scene/main.go new file mode 100644 index 0000000..8fccb43 --- /dev/null +++ b/examples/community/scene/main.go @@ -0,0 +1,60 @@ +package main + +import ( + "github.com/faiface/pixel" + "github.com/faiface/pixel/pixelgl" + "golang.org/x/image/colornames" +) + +type scene int + +const ( + start scene = iota + menu + game + credits + end +) + +func (s *scene) nextScene() { + *s = (*s + 1) % 5 +} + +func run() { + cfg := pixelgl.WindowConfig{ + Title: "Click On The Screen!", + Bounds: pixel.R(0, 0, 1024, 768), + VSync: true, + } + win, err := pixelgl.NewWindow(cfg) + if err != nil { + panic(err) + } + + s := start + + for !win.Closed() { + switch s { + case start: + win.Clear(colornames.Lavender) + case menu: + win.Clear(colornames.Turquoise) + case game: + win.Clear(colornames.Lightyellow) + case credits: + win.Clear(colornames.Lightpink) + case end: + win.Clear(colornames.Sandybrown) + } + + if win.JustPressed(pixelgl.MouseButtonLeft) { + s.nextScene() + } + + win.Update() + } +} + +func main() { + pixelgl.Run(run) +}