当前位置:首页 » 编程软件 » 寻路脚本思路

寻路脚本思路

发布时间: 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个方向!

这个要用挂机脚本的吧

热点内容
lol服务器人数怎么挤 发布:2025-03-19 01:29:19 浏览:838
兄弟连的php 发布:2025-03-19 01:24:25 浏览:809
自己做脚本可不可以 发布:2025-03-19 01:20:13 浏览:533
33的源码值 发布:2025-03-19 01:13:25 浏览:814
虚荣安卓怎么充值 发布:2025-03-19 01:12:27 浏览:892
如何更改报考密码 发布:2025-03-19 01:08:12 浏览:416
python日期类型 发布:2025-03-19 01:02:28 浏览:415
android飞机大战源码 发布:2025-03-19 00:56:52 浏览:736
javaset方法 发布:2025-03-19 00:44:21 浏览:246
淘宝上传文件夹 发布:2025-03-19 00:36:30 浏览:73