Object Follow Mouse Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
teadrinker
Posts: 1639
Joined: 29 Mar 2015, 09:41
Contact:

Re: Object Follow Mouse

05 Sep 2019, 07:41

For me it works great! :)
TheDewd wrote: It's not easy for me modify.
If you still have any qustions, feel free to ask.
User avatar
TheDewd
Posts: 1391
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Object Follow Mouse

06 Sep 2019, 14:26

teadrinker wrote:
05 Sep 2019, 07:41
For me it works great! :)
TheDewd wrote: It's not easy for me modify.
If you still have any qustions, feel free to ask.

Thanks! I figured out how to re-write your code in a style that is easier for me to read/debug, removing the function binds, etc.

Code: Select all

#SingleInstance, Force
SetBatchLines, -1
CoordMode, Mouse, Screen

ImageFrame := 1

Gui, +LastFound -Caption -Border +AlwaysOnTop +HWNDhNeko +E0x20
Gui, Margin, 0, 0
Gui, Color, EEAA99
Gui, Add, Picture, x0 y0 w32 h32 BackgroundTrans vPic, img\still.png
WinSet, TransColor, EEAA99
Gui, Show, w32 h32 NA, Neko
SetTimer, MouseCheck, 250
return

MouseCheck:
	WinGetPos, WinX, WinY, WinW, WinH, ahk_id %hNeko%
	MouseGetPos, MouseX, MouseY

	X := Floor(MouseX - (WinX + (WinW / 2)))
	Y := Floor(MouseY - (WinY + (WinH / 2)))
	Distance := ((X ** 2 + Y ** 2) ** 0.5)

	Sin := (Y / Distance)
	Cos := (X / Distance)

	;cDir := (X = 0 && Y = 0 ? 0 : Sin < -0.365 ? (Cos < -0.365 ? "NW" : Cos > 0.365 ? "NE" : "N") : Sin > 0.365 ? (Cos < -0.365 ? "SW" : Cos > 0.365 ? "SE" : "S") : (Cos < 0 ? "W" : "E"))

	If (X = 0 && Y = 0) {
		Direction := 0
		GuiControl, %hNeko%:, Pic, img\still.png
		ImageFrame := 1
	} Else {
		If (Sin < -0.365) {
			If (Cos < -0.365) {
				Direction := "NW"
				GuiControl, %hNeko%:, Pic, img\nwrun%ImageFrame%.png
			} Else If (Cos > 0.365) {
				Direction := "NE"
				GuiControl, %hNeko%:, Pic, img\nerun%ImageFrame%.png
			} Else {
				Direction := "N"
				GuiControl, %hNeko%:, Pic, img\nrun%ImageFrame%.png
			}
		} Else If (Sin > 0.365) {
			If (Cos < -0.365) {
				Direction := "SW"
				GuiControl, %hNeko%:, Pic, img\swrun%ImageFrame%.png
			} Else If (Cos > 0.365) {
				Direction := "SE"
				GuiControl, %hNeko%:, Pic, img\serun%ImageFrame%.png
			} Else {
				Direction := "S"
				GuiControl, %hNeko%:, Pic, img\srun%ImageFrame%.png
			}
		} Else {
			If (Cos < 0) {
				Direction := "W"
				GuiControl, %hNeko%:, Pic, img\wrun%ImageFrame%.png
			} Else If (Cos > 0) {
				Direction := "E"
				GuiControl, %hNeko%:, Pic, img\erun%ImageFrame%.png
			}
		}

		ImageFrame := (ImageFrame = 1 ? 2 : 1)
	}

	If (Distance <= 16) {
		MoveX := MouseX - (WinW / 2)
		MoveY := MouseY - (WinH / 2)
	} Else {
		StepX := Abs(X * 16 / Distance)
		StepY := Abs(Y * 16 / Distance)
		MoveX := (WinX + StepX * (X > 0 ? 1 : -1))
		MoveY := (WinY + StepY * (Y > 0 ? 1 : -1))
	}

	Gui, Show, x%MoveX% y%MoveY% w32 h32 NA, Neko
return

Esc::
	ExitApp
return
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], euras, Rohwedder and 271 guests