added manager, scene, and first examples
This commit is contained in:
68
examples/splashmenu/menu.go
Normal file
68
examples/splashmenu/menu.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package splashmenu
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"log"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
|
||||
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
||||
"github.com/hajimehoshi/ebiten/v2/text"
|
||||
"golang.org/x/image/font"
|
||||
"golang.org/x/image/font/opentype"
|
||||
)
|
||||
|
||||
var (
|
||||
menuFont font.Face
|
||||
)
|
||||
|
||||
func init() {
|
||||
tt, err := opentype.Parse(fonts.PressStart2P_ttf)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
const dpi = 72
|
||||
menuFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
|
||||
Size: 12,
|
||||
DPI: dpi,
|
||||
Hinting: font.HintingVertical,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
type Menu struct {
|
||||
bgcolor color.RGBA
|
||||
completed bool
|
||||
}
|
||||
|
||||
func NewMenu() Menu {
|
||||
return Menu{
|
||||
bgcolor: color.RGBA{0x33, 0x33, 0x99, 0xFF},
|
||||
completed: false,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Menu) Draw(screen *ebiten.Image) {
|
||||
screen.Fill(m.bgcolor)
|
||||
text.Draw(screen, "menu", menuFont, 40, 40, color.White)
|
||||
}
|
||||
|
||||
func (m *Menu) Update() error {
|
||||
|
||||
var keysPressed []ebiten.Key
|
||||
keysPressed = inpututil.AppendPressedKeys(keysPressed[:0])
|
||||
for _, k := range keysPressed {
|
||||
if k == ebiten.KeyEnter {
|
||||
m.completed = true
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Menu) Completed() bool {
|
||||
return m.completed
|
||||
}
|
||||
69
examples/splashmenu/splash.go
Normal file
69
examples/splashmenu/splash.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package splashmenu
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"log"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
|
||||
"github.com/hajimehoshi/ebiten/v2/text"
|
||||
"golang.org/x/image/font"
|
||||
"golang.org/x/image/font/opentype"
|
||||
)
|
||||
|
||||
var (
|
||||
splashFont font.Face
|
||||
)
|
||||
|
||||
func init() {
|
||||
tt, err := opentype.Parse(fonts.PressStart2P_ttf)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
const dpi = 72
|
||||
splashFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
|
||||
Size: 12,
|
||||
DPI: dpi,
|
||||
Hinting: font.HintingVertical,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
type Splash struct {
|
||||
bgcolor color.RGBA
|
||||
completed bool
|
||||
increment int
|
||||
}
|
||||
|
||||
func NewSplash() Splash {
|
||||
return Splash{
|
||||
bgcolor: color.RGBA{0xFF, 0xFF, 0xFF, 0xFF},
|
||||
completed: false,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Splash) Draw(screen *ebiten.Image) {
|
||||
screen.Fill(s.bgcolor)
|
||||
text.Draw(screen, "splash", splashFont, 40, 40, color.White)
|
||||
}
|
||||
|
||||
func (s *Splash) Update() error {
|
||||
s.increment++
|
||||
|
||||
s.bgcolor.R = (s.bgcolor.R - 2) % 0xFF
|
||||
s.bgcolor.G = (s.bgcolor.G - 2) % 0xFF
|
||||
s.bgcolor.B = (s.bgcolor.B - 2) % 0xFF
|
||||
|
||||
if s.bgcolor.R == 0x00 {
|
||||
s.completed = true
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Splash) Completed() bool {
|
||||
return s.completed
|
||||
}
|
||||
Reference in New Issue
Block a user