當前位置:首頁 » 編程軟體 » 尋路腳本思路

尋路腳本思路

發布時間: 2022-08-23 04:26:12

1. 網路游戲中自動尋路是如何實現的

坐標點標記軌跡

2. 求自己製作游戲自動尋路的腳本教程!求高手!

沒有相當的編程知識的話,可以用按鍵精靈錄制腳本,即記錄後再重現你的操作,這是我想到最簡單的方法了。
詳情參考:http://wenku..com/link?url=_

3. 按鍵精靈怎麼自動尋路

自動尋路腳本的製作有幾個關鍵點:

1. 由於現在的網游大多是3D的,當前視角可能是變化的,因此,你必須要確保或設置游戲的視角不變。

2. 屏幕上的坐標點與人物的坐標點要找到對應關系,因為屏幕是不變的,而人物坐標是變化的。有些網遊人物在同一屏幕(即人物不超出當前屏幕范圍,屏幕畫面不變),這種情況則直接使用屏幕坐標就可以了,只要保證人物不會超出屏幕范圍。

4. RMXP尋路演算法

#==============================================================================
# ■ Find_Path
#------------------------------------------------------------------------------
# 尋路演算法--完整滑鼠系統(四方向)專用版
# By whbm
#==============================================================================
class Find_Path
#--------------------------------------------------------------------------
def initialize #初始化
@open_list = []
@close_lise = []
@path = []
end #結束初始化
#--------------------------------------------------------------------------
def fp_passable?(x, y, d, tr_x = -2, tr_y = -2) #開始判定通行
return false if (tr_x == @unable_xa or
tr_x == @unable_xb or
tr_y == @unable_ya or
tr_y == @unable_yb)
if $game_player.passable?(x, y, d)
return true
else
return false
end
end #結束判定通行
#--------------------------------------------------------------------------
def get_g(now_point) #開始計算G值
d = now_point[2]
return 0 if d == 5
father_point = get_father_point(now_point)
g = father_point[3] + 10
return g
end #結束計算G值
#--------------------------------------------------------------------------
def get_h(now_point) #開始計算H值
now_x = now_point[0]
now_y = now_point[1]
#print @trg_x,now_x,@trg_y,now_y
h = (@trg_x - now_x).abs + (@trg_y - now_y).abs
return h * 10
end #結束計算H值
#--------------------------------------------------------------------------
def get_f(now_point) #開始計算F值
f = now_point[3] + now_point[4]
return f
end #結束計算F值
#--------------------------------------------------------------------------
def get_point(x, y) #取已知坐標點
if @open_list.size != 0
@open_list.each do |point|
if point[0] == x and point[1] == y
return point
break
end
end
end
if @close_list.size != 0
@close_list.each do |point|
if point[0] == x and point[1] == y
return point
break
end
end
end
end #結束取已知坐標點
#--------------------------------------------------------------------------
def get_father_point(now_point) #取已知點的父節點
d = now_point[2]
return now_point if d == 5
x = now_point[0] + (d == 6 ? 1 : (d == 4 ? -1 : 0))
y = now_point[1] + (d == 2 ? 1 : (d == 8 ? -1 : 0))
return get_point(x, y)
end #結束取已知點的父節點
#--------------------------------------------------------------------------
def new_point(x, y, d) #開始建立新節點
#print x,y,d
point = [x, y, d]
point.push get_g(point)
point.push get_h(point)
point.push get_f(point)
return point
end #結束建立新節點
#--------------------------------------------------------------------------
def get_direction(self_x, self_y, trg_x, trg_y)
if trg_x > self_x
if trg_y - self_y > - ( trg_x - self_x ) and
trg_y - self_y < ( trg_x - self_x )
return 6
end
if trg_y - self_y > ( trg_x - self_x )
return 2
end
if trg_y - self_y < - ( trg_x - self_x )
return 8
end
end
if trg_x < self_x
if trg_y - self_y > - ( self_x - trg_x ) and
trg_y - self_y < ( self_x - trg_x )
return 4
end
if trg_y - self_y > ( self_x - trg_x )
return 2
end
if trg_y - self_y < - ( self_x - trg_x )
return 8
end
end
end
#--------------------------------------------------------------------------
def get_d_x_y(x, y, d)
d_x = x + (d == 6 ? 1 : (d == 4 ? -1 : 0))
d_y = y + (d == 2 ? 1 : (d == 8 ? -1 : 0))
return d_x, d_y
end
#--------------------------------------------------------------------------
def find_short_path_other(self_x, self_y, trg_x, trg_y,
real_self_x, real_self_y, real_trg_x, real_trg_y)
@self_x = self_x
@self_y = self_y
@now_x = self_x
@now_y = self_y
@trg_x = trg_x
@trg_y = trg_y
@path = []
direction = get_direction(real_self_x, real_self_y, real_trg_x, real_trg_y)
@now_trg_x, @now_trg_y = get_d_x_y(@self_x, @self_y, direction)
while fp_passable?(@now_x, @now_y, direction)
@path.push direction
@now_x = @now_trg_x
@now_y = @now_trg_y
@now_trg_x, @now_trg_y = get_d_x_y(@now_x, @now_y, direction)
end
return @path
end
#--------------------------------------------------------------------------
def find_short_path(self_x, self_y, trg_x, trg_y,
real_self_x, real_self_y, real_trg_x, real_trg_y) #開始搜索路徑

return find_short_path_other(self_x, self_y, trg_x, trg_y,
real_self_x, real_self_y, real_trg_x, real_trg_y) if not
(fp_passable?(trg_x, trg_y + 1, 8) or
fp_passable?(trg_x + 1, trg_y, 4) or
fp_passable?(trg_x - 1, trg_y, 6) or
fp_passable?(trg_x, trg_y - 1, 2)) and @goal_type != 1

#根據屏幕限定搜索麵積..加速
@unable_xa = $game_map.display_x / 128 - 1
@unable_ya = $game_map.display_y / 128 - 1
@unable_xb = $game_map.display_x / 128 + 20
@unable_yb = $game_map.display_y / 128 + 20

@self_x = self_x
@self_y = self_y
@now_x = self_x
@now_y = self_y
@trg_x = trg_x
@trg_y = trg_y
@open_list = []
@close_list = []
#准備搜索
#print @self_x,@self_y
@now_point = new_point(@self_x, @self_y, 5) #令起始點為當前點
@open_list.push @now_point #將當前點加入關閉列表
#開始搜索
begin
loop do
check_trg = check_around_point(@now_point)
if check_trg == true
@path = get_path
break
end
@now_point = get_lowest_f_point
if @now_point == [] or @now_point == nil
@path = []
break
end
end
rescue Hangup
retry
end
return @path
end #結束搜索路徑
#--------------------------------------------------------------------------
def find_player_short_path(trg_x, trg_y,
real_trg_x, real_trg_y) #尋找角色的最短路徑
self_x = $game_player.x
self_y = $game_player.y
real_self_x = $game_player.screen_x
real_self_y = $game_player.screen_y
@goal_type, event = $game_map.check_event_custom_exist(real_trg_x, real_trg_y)
if @goal_type == 1
trg_x = event.x
trg_y = event.y
end
return find_short_path(self_x, self_y, trg_x, trg_y,
real_self_x, real_self_y, real_trg_x, real_trg_y)
end #結束角色的尋找路徑
#--------------------------------------------------------------------------
def get_path #取得最終的路徑
path = []
now_point = @open_list[@open_list.size - 1]
path.push(10 - now_point[2])
last_point = now_point
loop do
now_point = get_father_point(now_point)
break if now_point[2] == 5
path.push(10 - now_point[2])
end
return path.reverse
end #結束取得最終的路徑
#--------------------------------------------------------------------------
def get_lowest_f_point #開始取得最低F值的點
if @open_list == []
return []
end
last_lowest_f_point = @open_list[0]
@open_list.each do |point|
last_lowest_f_point = point if point[5] < last_lowest_f_point[5]
end
return last_lowest_f_point
end #結束取得最低F值點
#--------------------------------------------------------------------------
def check_around_point(point) #開始檢查已知點的八方節點
for d in [2, 4, 6, 8]
x = point[0] + (d == 6 ? 1 : (d == 4 ? -1 : 0))
y = point[1] + (d == 2 ? 1 : (d == 8 ? -1 : 0))
if in_close_list?(x, y) #在關閉列表中
next
elsif in_open_list?(x, y) #在開啟列表中
get_new_g_point = new_point(x, y, 10 - d)
get_last_g_point = get_point(x, y)
if get_new_g_point[3] >= get_last_g_point[3]
next
else
#如果改變父節點是新G值更小則確定改變
@open_list[@open_list.index(get_last_g_point)] = get_new_g_point
end
else
if fp_passable?(point[0], point[1], d, x, y)
# 如果不在開啟列表中、且不在關閉列表中、且通行則添加它到新八周節點
@open_list.push new_point(x, y, 10 - d)
#如果將目標點添加到了開啟列表中就返回true
return true if x == @trg_x and y == @trg_y
return true if @goal_type == 1 and ([1, -1].include?(x - @trg_x) and y - @trg_y == 0) or ([1, -1].include?(y - @trg_y) and x - @trg_x == 0)
end
end
end
#此刻沒有找到目標點並將當前點加入關閉列表並在開啟列表中刪除
@close_list.push point
@open_list.delete(point)
#此刻沒找到目標點並返回false
return false
end #結束計算已知點的八方節點
#--------------------------------------------------------------------------
def in_open_list?(x, y) #開始檢查謀點是否在開啟列表中
@open_list.each do |point|
return true if point[0] == x and point[1] == y
end
return false
end #結束檢查謀點是否在開啟列表中
#--------------------------------------------------------------------------
def in_close_list?(x, y) #開始檢查謀點是否在關閉列表中
@close_list.each do |point|
return true if point[0] == x and point[1] == y
end
return false
end #結束檢查謀點是否在關閉列表中
#--------------------------------------------------------------------------
end

5. 按鍵精靈初學者,嘗試性寫了一款點擊任務自動尋路的腳本。求高手看下我的邏輯思路能幫忙改正。

你試試系統自帶的找圖功能,直接一個大循環裡面幾個判斷就行。這樣簡單而且效率不低

6. 星際爭霸2的尋路演算法思路是怎樣的

首先地圖整體開始前,會用多層可達矩陣演算法,算出路徑關鍵點
2,創建關鍵節點可達矩陣
3,再每個兵當前位置對關鍵節點進行路徑計算
這樣可以最小化資源佔用就可以完成路徑計算了,高數的離散數學,挺容易解的

7. 製作游戲輔助:用按鍵精靈如何確定人物朝向

按鍵學院實戰班前段時間沸沸揚揚的講解著自動尋路教程。今天,咱也來跟大家分享分享,實戰班自動尋路思路之——確定人物朝向(箭頭的方向角度)。

不少網路游戲已經支持自動尋路,玩家只需要設定終點後,游戲人物即可自動尋路,但是碰到某些未自帶自動尋路功能的游戲,就呵呵呵了……

院刊今天跟大家分享兩款熱門游戲的人物朝向判定~~知道了人物朝向,再知道目標的朝向,不就知道怎麼自動尋路了嘛~

按鍵學院實戰班的07老師整理了自動尋路的三要素,給大家分享:

自動尋路一般需要確定三個要素:

確定路線

確定朝向

確定位置


確定了人物位置和物品位置,再確定了人物的朝向,與目標路線。將人物轉向目標就可以用腳本實現自動尋路的功能。

劍靈模式的地圖的尋路:游戲畫面右上角有小地圖,地圖中灰白色箭頭代表人物。


斜率:已知A、B點坐標,求直線AB的斜率。

斜率公式k=(y1-y2)/(x1-x2),即兩個坐標縱坐標之差,除以兩個坐標橫坐標之差。

正切函數:正切函數是直角三角形中,對邊與鄰邊的比值。

在上圖中,即tanα=b/a=(y2-y1)/(x2-x1)。在按鍵精靈中為Tan函數。

通過公式對比,我們可以知道,直線AB的斜率,即角α的正切值

角度:已知角α的正切值,我們可以通過反三角函數公式,來計算這個角度的值。

α=arctan(k)。在按鍵精靈中為Atn函數。

反三角函數:即相對應的正弦、餘弦、正切、餘切為x的角。


如何實現箭頭角度計算:

從上面的三角函數知識拓展中,我們知道,要計算一個角度,可以通過計算該角度的正切值,再通過反三角函數來求這個角度。

那麼,在按鍵精靈的代碼中如何實現呢?

思路:

1.通過找圖找色命令,找到箭頭頂部A的坐標,以及箭頭底部中間B的坐標。

2.構建直角三角形。確定箭頭的指向的角度α。

3.通過斜率/正切函數,來計算角度α的正切值。

4.通過反三角函數,來得出角α的角度值。


代碼實現:

『在劍靈右上角的小地圖里找色/找圖,箭頭坐標存儲在(x1,y1),箭尾坐標存儲在(x2,y2)

FindColor1200,0,1920,300,"箭頭顏色",x1,y1

Ifx1>0Andy1>0Then

EndIf

FindColor1200,0,1920,300,"箭尾顏色",x2,y2

Ifx1>0Andy1>0Then

EndIf


'計算斜率/正切值

斜率=(y1-y2)/(x1-x2)


'計算角度

角度=Atn(斜率)

當然,自動尋路並不是單一的方式,不同游戲的地圖不同,尋路的方式不同。但是運用到的數學知識和思路是共同的。當然,有些特定的地圖有更便捷的方式,例如最終幻想14的地圖。下一期的院刊,再跟大家分享另一些不同的地圖的尋路方式~~

8. 按鍵精靈游戲尋路不用打開地圖就尋路過去這種腳本要怎麼做

這個技術我會使用。調用游戲中,已經經過編譯的,sub 走路。例子:call 0x********

9. 游戲自動尋路躲避障礙物思路,8個方向!

這個要用掛機腳本的吧

熱點內容
java遍歷二維數組 發布:2025-03-18 03:36:01 瀏覽:410
銳捷源碼 發布:2025-03-18 03:26:55 瀏覽:436
訴訟中止裁定後可否解壓 發布:2025-03-18 03:24:51 瀏覽:128
sqlserver全文搜索 發布:2025-03-18 03:23:58 瀏覽:715
u盤裡面文件夾沒有了 發布:2025-03-18 03:22:19 瀏覽:229
華為p系列手機哪個配置好 發布:2025-03-18 03:20:13 瀏覽:621
易語言連接access資料庫 發布:2025-03-18 03:12:48 瀏覽:661
苗木源碼 發布:2025-03-18 03:12:38 瀏覽:747
oracle卸載資料庫 發布:2025-03-18 03:05:15 瀏覽:46
編譯時生成固件怎麼辦 發布:2025-03-18 03:04:30 瀏覽:707