49
main.go
49
main.go
@@ -16,12 +16,14 @@ import (
|
|||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/audio"
|
"github.com/hajimehoshi/ebiten/v2/audio"
|
||||||
"github.com/hajimehoshi/ebiten/v2/audio/wav"
|
"github.com/hajimehoshi/ebiten/v2/audio/wav"
|
||||||
|
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
||||||
|
|
||||||
"crg.eti.br/go/config"
|
"crg.eti.br/go/config"
|
||||||
_ "crg.eti.br/go/config/ini"
|
_ "crg.eti.br/go/config/ini"
|
||||||
)
|
)
|
||||||
|
|
||||||
type neko struct {
|
type neko struct {
|
||||||
|
waiting bool
|
||||||
x int
|
x int
|
||||||
y int
|
y int
|
||||||
distance int
|
distance int
|
||||||
@@ -68,33 +70,44 @@ func playsound(sound []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *neko) Update() error {
|
func (m *neko) Update() error {
|
||||||
mx, my := ebiten.CursorPosition()
|
|
||||||
|
|
||||||
m.count++
|
m.count++
|
||||||
if m.state == 10 && m.count == m.min {
|
if m.state == 10 && m.count == m.min {
|
||||||
playsound(mSound["idle3"])
|
playsound(mSound["idle3"])
|
||||||
}
|
}
|
||||||
|
|
||||||
// sw, sh := ebiten.ScreenSizeInFullscreen()
|
|
||||||
|
|
||||||
// set the window position
|
|
||||||
ebiten.SetWindowPosition(m.x, m.y)
|
ebiten.SetWindowPosition(m.x, m.y)
|
||||||
|
|
||||||
|
mx, my := ebiten.CursorPosition()
|
||||||
x := mx - (height / 2)
|
x := mx - (height / 2)
|
||||||
y := my - (width / 2)
|
y := my - (width / 2)
|
||||||
|
|
||||||
// get distance from sprite to mouse
|
|
||||||
dy, dx := y, x
|
dy, dx := y, x
|
||||||
if dy < 0 {
|
if dy < 0 {
|
||||||
dy *= -1
|
dy = -dy
|
||||||
}
|
}
|
||||||
|
|
||||||
if dx < 0 {
|
if dx < 0 {
|
||||||
dx *= -1
|
dx = -dx
|
||||||
}
|
}
|
||||||
|
|
||||||
m.distance = dx + dy
|
m.distance = dx + dy
|
||||||
if m.distance < width {
|
if m.distance < width || m.waiting {
|
||||||
|
m.stayIdle()
|
||||||
|
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
|
||||||
|
m.waiting = !m.waiting
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.state >= 13 {
|
||||||
|
playsound(mSound["awake"])
|
||||||
|
}
|
||||||
|
m.state = 0
|
||||||
|
m.min = 8
|
||||||
|
m.max = 16
|
||||||
|
m.catchCursor(x, y)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *neko) stayIdle() {
|
||||||
// idle state
|
// idle state
|
||||||
switch m.state {
|
switch m.state {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -118,17 +131,9 @@ func (m *neko) Update() error {
|
|||||||
default:
|
default:
|
||||||
m.sprite = "sleep"
|
m.sprite = "sleep"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
func (m *neko) catchCursor(x, y int) {
|
||||||
}
|
|
||||||
|
|
||||||
if m.state >= 13 {
|
|
||||||
playsound(mSound["awake"])
|
|
||||||
}
|
|
||||||
m.state = 0
|
|
||||||
m.min = 8
|
|
||||||
m.max = 16
|
|
||||||
|
|
||||||
tr := 0.0
|
tr := 0.0
|
||||||
// get mouse direction
|
// get mouse direction
|
||||||
r := math.Atan2(float64(y), float64(x))
|
r := math.Atan2(float64(y), float64(x))
|
||||||
@@ -179,8 +184,6 @@ func (m *neko) Update() error {
|
|||||||
case a < 247 && a > 202:
|
case a < 247 && a > 202:
|
||||||
m.sprite = "upleft"
|
m.sprite = "upleft"
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *neko) Draw(screen *ebiten.Image) {
|
func (m *neko) Draw(screen *ebiten.Image) {
|
||||||
|
|||||||
Reference in New Issue
Block a user