Add animated gopher
This commit is contained in:
parent
c9cf7b73b4
commit
d53f8150ef
BIN
gopher-anim.CI8
Normal file
BIN
gopher-anim.CI8
Normal file
Binary file not shown.
BIN
gopher-anim.png
Normal file
BIN
gopher-anim.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 45 KiB |
36
main.go
36
main.go
@ -1,18 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
|
||||
"github.com/clktmr/n64/drivers/cartfs"
|
||||
"github.com/clktmr/n64/drivers/controller"
|
||||
"github.com/clktmr/n64/drivers/display"
|
||||
"github.com/clktmr/n64/drivers/draw"
|
||||
"github.com/clktmr/n64/fonts/gomono12"
|
||||
_ "github.com/clktmr/n64/machine"
|
||||
"github.com/clktmr/n64/rcp/serial/joybus"
|
||||
"github.com/clktmr/n64/rcp/texture"
|
||||
"github.com/clktmr/n64/rcp/video"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed gopher-anim.CI8
|
||||
_tutorialFiles embed.FS
|
||||
tutorialFiles cartfs.FS = cartfs.Embed(_tutorialFiles)
|
||||
)
|
||||
|
||||
var face = gomono12.NewFace()
|
||||
var background = &image.Uniform{color.RGBA{0x7f, 0x7f, 0xaf, 0x0}}
|
||||
|
||||
@ -32,6 +42,17 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
gopherFile, err := tutorialFiles.Open("gopher-anim.CI8")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
gopherTexture, err := texture.Load(gopherFile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
gopherRect := image.Rect(0, 0, 128, 128)
|
||||
blows := 0
|
||||
|
||||
for {
|
||||
fb := display.Swap() // Blocks until next VBlank
|
||||
input := <-controllers
|
||||
@ -43,8 +64,23 @@ func main() {
|
||||
|
||||
text := fmt.Appendln(nil, "N⁶⁴ - Get N or Get Out ♫")
|
||||
text = fmt.Appendln(text, input[0].Down())
|
||||
text = fmt.Appendf(text, "blows: %v/8\n", blows)
|
||||
pt = draw.DrawText(fb, textarea, face, pt, image.Black, nil, text)
|
||||
|
||||
gopherFrame := image.Point{}
|
||||
if blows < 8 {
|
||||
if input[0].Pressed()&joybus.ButtonA != 0 {
|
||||
blows++
|
||||
}
|
||||
if input[0].Down()&joybus.ButtonA != 0 {
|
||||
gopherFrame.X += 128 // blowing gopher
|
||||
}
|
||||
} else {
|
||||
gopherFrame.X += 256 // happy gopher
|
||||
}
|
||||
|
||||
draw.Over.Draw(fb, gopherRect.Add(pt), gopherTexture, gopherFrame)
|
||||
|
||||
draw.Flush() // Blocks until everything is drawn
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user