compute distance
This commit is contained in:
15
main.go
15
main.go
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"embed"
|
"embed"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
@@ -32,6 +33,7 @@ var (
|
|||||||
type neko struct {
|
type neko struct {
|
||||||
x int
|
x int
|
||||||
y int
|
y int
|
||||||
|
distance int
|
||||||
count int
|
count int
|
||||||
sprite string
|
sprite string
|
||||||
}
|
}
|
||||||
@@ -46,11 +48,24 @@ func (m *neko) Update() error {
|
|||||||
m.count++
|
m.count++
|
||||||
|
|
||||||
//sw, sh := ebiten.ScreenSizeInFullscreen()
|
//sw, sh := ebiten.ScreenSizeInFullscreen()
|
||||||
|
|
||||||
|
// set the window position
|
||||||
ebiten.SetWindowPosition(m.x, m.y)
|
ebiten.SetWindowPosition(m.x, m.y)
|
||||||
|
|
||||||
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
|
||||||
|
if dy < 0 {
|
||||||
|
dy = dy * (-1)
|
||||||
|
}
|
||||||
|
if dx < 0 {
|
||||||
|
dx = dx * (-1)
|
||||||
|
}
|
||||||
|
m.distance = dx + dy
|
||||||
|
fmt.Println(m.distance)
|
||||||
|
|
||||||
r := math.Atan2(float64(y), float64(x))
|
r := math.Atan2(float64(y), float64(x))
|
||||||
tr := 0.0
|
tr := 0.0
|
||||||
if r <= 0 {
|
if r <= 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user