compute distance

This commit is contained in:
Cesar Gimenes
2021-09-19 19:33:59 -03:00
parent 342e14f76a
commit abab62ce11

23
main.go
View File

@@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"embed" "embed"
_ "embed" _ "embed"
"fmt"
"image" "image"
_ "image/png" _ "image/png"
"io/fs" "io/fs"
@@ -30,10 +31,11 @@ var (
) )
type neko struct { type neko struct {
x int x int
y int y int
count int distance int
sprite string count int
sprite string
} }
func (m *neko) Layout(outsideWidth, outsideHeight int) (int, int) { func (m *neko) Layout(outsideWidth, outsideHeight int) (int, int) {
@@ -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 {