add a guide for making scenes
This commit introduces a way to work with scenes by introducing a scene type and a function to move between it.
This commit is contained in:
parent
7cff3ce3ae
commit
72e07a2c06
|
@ -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
|
|
@ -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)
|
||||||
|
}
|
Loading…
Reference in New Issue