fix: implement sqrt(2) on diagonals
Refactors the x/y to float64 and rounds on draw. Fixes: #20
This commit is contained in:
32
main.go
32
main.go
@@ -24,8 +24,8 @@ import (
|
|||||||
|
|
||||||
type neko struct {
|
type neko struct {
|
||||||
waiting bool
|
waiting bool
|
||||||
x int
|
x float64
|
||||||
y int
|
y float64
|
||||||
distance int
|
distance int
|
||||||
count int
|
count int
|
||||||
min int
|
min int
|
||||||
@@ -37,7 +37,7 @@ type neko struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Speed int `cfg:"speed" cfgDefault:"2" cfgHelper:"The speed of the cat."`
|
Speed float64 `cfg:"speed" cfgDefault:"2.0" cfgHelper:"The speed of the cat."`
|
||||||
Scale float64 `cfg:"scale" cfgDefault:"2.0" cfgHelper:"The scale of the cat."`
|
Scale float64 `cfg:"scale" cfgDefault:"2.0" cfgHelper:"The scale of the cat."`
|
||||||
Quiet bool `cfg:"quiet" cfgDefault:"false" cfgHelper:"Disable sound."`
|
Quiet bool `cfg:"quiet" cfgDefault:"false" cfgHelper:"Disable sound."`
|
||||||
MousePassthrough bool `cfg:"mousepassthrough" cfgDefault:"false" cfgHelper:"Enable mouse passthrough."`
|
MousePassthrough bool `cfg:"mousepassthrough" cfgDefault:"false" cfgHelper:"Enable mouse passthrough."`
|
||||||
@@ -86,9 +86,9 @@ func (m *neko) Update() error {
|
|||||||
}
|
}
|
||||||
// Prevents neko from being stuck on the side of the screen
|
// Prevents neko from being stuck on the side of the screen
|
||||||
// or randomly travelling to another monitor
|
// or randomly travelling to another monitor
|
||||||
m.x = max(0, min(m.x, monitorWidth))
|
m.x = max(0, min(m.x, float64(monitorWidth)))
|
||||||
m.y = max(0, min(m.y, monitorHeight))
|
m.y = max(0, min(m.y, float64(monitorHeight)))
|
||||||
ebiten.SetWindowPosition(m.x, m.y)
|
ebiten.SetWindowPosition(int(math.Round(m.x)), int(math.Round(m.y)))
|
||||||
|
|
||||||
mx, my := ebiten.CursorPosition()
|
mx, my := ebiten.CursorPosition()
|
||||||
x := mx - (height / 2)
|
x := mx - (height / 2)
|
||||||
@@ -161,23 +161,23 @@ func (m *neko) catchCursor(x, y int) {
|
|||||||
case a <= 292.5 && a > 247.5: // up
|
case a <= 292.5 && a > 247.5: // up
|
||||||
m.y -= cfg.Speed
|
m.y -= cfg.Speed
|
||||||
case a <= 337.5 && a > 292.5: // up right
|
case a <= 337.5 && a > 292.5: // up right
|
||||||
m.x += cfg.Speed
|
m.x += cfg.Speed / math.Sqrt2
|
||||||
m.y -= cfg.Speed
|
m.y -= cfg.Speed / math.Sqrt2
|
||||||
case a <= 22.5 || a > 337.5: // right
|
case a <= 22.5 || a > 337.5: // right
|
||||||
m.x += cfg.Speed
|
m.x += cfg.Speed
|
||||||
case a <= 67.5 && a > 22.5: // down right
|
case a <= 67.5 && a > 22.5: // down right
|
||||||
m.x += cfg.Speed
|
m.x += cfg.Speed / math.Sqrt2
|
||||||
m.y += cfg.Speed
|
m.y += cfg.Speed / math.Sqrt2
|
||||||
case a <= 112.5 && a > 67.5: // down
|
case a <= 112.5 && a > 67.5: // down
|
||||||
m.y += cfg.Speed
|
m.y += cfg.Speed
|
||||||
case a <= 157.5 && a > 112.5: // down left
|
case a <= 157.5 && a > 112.5: // down left
|
||||||
m.x -= cfg.Speed
|
m.x -= cfg.Speed / math.Sqrt2
|
||||||
m.y += cfg.Speed
|
m.y += cfg.Speed / math.Sqrt2
|
||||||
case a <= 202.5 && a > 157.5: // left
|
case a <= 202.5 && a > 157.5: // left
|
||||||
m.x -= cfg.Speed
|
m.x -= cfg.Speed
|
||||||
case a <= 247.5 && a > 202.5: // up left
|
case a <= 247.5 && a > 202.5: // up left
|
||||||
m.x -= cfg.Speed
|
m.x -= cfg.Speed / math.Sqrt2
|
||||||
m.y -= cfg.Speed
|
m.y -= cfg.Speed / math.Sqrt2
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
@@ -280,8 +280,8 @@ func main() {
|
|||||||
audio.CurrentContext().NewPlayerFromBytes([]byte{}).Play()
|
audio.CurrentContext().NewPlayerFromBytes([]byte{}).Play()
|
||||||
|
|
||||||
n := &neko{
|
n := &neko{
|
||||||
x: monitorWidth / 2,
|
x: float64(monitorWidth / 2),
|
||||||
y: monitorHeight / 2,
|
y: float64(monitorHeight / 2),
|
||||||
min: 8,
|
min: 8,
|
||||||
max: 16,
|
max: 16,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user