Merge pull request #125 from jwangsadinata/add-scenes-guide

add a guide for making scenes
This commit is contained in:
Michal Štrba 2018-09-05 22:14:50 +02:00 committed by GitHub
commit 14fa4a2aa8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 0 deletions

View File

@ -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

View File

@ -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)
}