我正在为2D游戏编写宏。字符的坐标以(x,y)为单位。游戏中有一些障碍,所以我需要以一种让角色在游戏中移动的方式来编程。
所以我写了一个程序,读取游戏的x和y坐标的记忆。然后,我编写了一个函数,将字符移动到所需的位置。逻辑是:如果x坐标小于所需位置,则保持向右移动,反之亦然。然后,如果y坐标小于所期望的位置,则继续向上移动,反之亦然。
然而,由于障碍,我必须手动给出坐标移动到。例如,如果我在(1,1),并告诉角色移动到(5,5),可能会有一个障碍在(3,1)和字符将被卡住。所以我告诉它先移到(1,3),然后移到(5,3),然后(5,5)。
我只是搞不懂怎么按顺序告诉角色移动。在我移动到(1,3)之后,移动到(5,3),然后(5,5)。
这就是我所拥有的:
f1::
WinGetTitle, ai, A
curX := ReadMemory(0x10F6A7D0, ai)
curY := ReadMemory(0x10F6A7D4, ai)
MoveTo(21,13)
if(curX == 21 && curY == 13){
MoveTo(21,28)
}
return
q::
Pause
return
ReadMemory(MADDRESS,PROGRAM)
{
winget, pid, PID, %PROGRAM%
VarSetCapacity(MVALUE,4,0)
ProcessHandle := DllCall("OpenProcess", "Int", 24, "Char", 0, "UInt", pid, "UInt")
DllCall("ReadProcessMemory","UInt",ProcessHandle,"UInt",MADDRESS,"Str",MVALUE,"UInt",4,"UInt *",0)
Loop 4
result += *(&MVALUE + A_Index-1) << 8*(A_Index-1)
return, result
}
MoveTo(targetX,targetY)
{
xadd = 0x10F6A7D0
yadd = 0x10F6A7D4
WinGetTitle, ai, A
Loop{
curX:= ReadMemory(xadd,ai)
curY:= ReadMemory(yadd,ai)
if(curX < targetX){
ControlSend,, {Right}, %ai%
}
else if(curX > targetX){
ControlSend,, {Left}, %ai%
}
else if(curY < targetY){
ControlSend,, {Down}, %ai%
}
else if(curY > targetY){
ControlSend,, {Up}, %ai%
}
Sleep, 30发布于 2014-09-14 00:30:50
所以我解决了我的问题。我只需在MoveTo函数中做一个while循环,并在到达位置后终止它。
MoveTo(targetX,targetY)
{
xadd = 0x10F6A7D0
yadd = 0x10F6A7D4
WinGetTitle, ai, A
isThere := 1
while(isThere = 1){
curX:= ReadMemory(xadd,ai)
curY:= ReadMemory(yadd,ai)
if(curX < targetX){
ControlSend,, {Right}, %ai%
}
else if(curX > targetX){
ControlSend,, {Left}, %ai%
}
else if(curY < targetY){
ControlSend,, {Down}, %ai%
}
else if(curY > targetY){
ControlSend,, {Up}, %ai%
}
if(curX = targetX && curY = targetY){
isThere = 0
}
Sleep, 30https://stackoverflow.com/questions/25825018
复制相似问题