From abab62ce1112d9073b1ab30dea24ae3c06031a54 Mon Sep 17 00:00:00 2001 From: Cesar Gimenes Date: Sun, 19 Sep 2021 19:33:59 -0300 Subject: [PATCH] compute distance --- main.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 336d319..152111e 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "bytes" "embed" _ "embed" + "fmt" "image" _ "image/png" "io/fs" @@ -30,10 +31,11 @@ var ( ) type neko struct { - x int - y int - count int - sprite string + x int + y int + distance int + count int + sprite string } func (m *neko) Layout(outsideWidth, outsideHeight int) (int, int) { @@ -46,11 +48,24 @@ func (m *neko) Update() error { m.count++ //sw, sh := ebiten.ScreenSizeInFullscreen() + + // set the window position ebiten.SetWindowPosition(m.x, m.y) x := mx - (height / 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)) tr := 0.0 if r <= 0 {