level 1
xmlc00010
楼主
之前看过论坛中高手制作的A star寻路算法的脚本,并成功运用到了游戏中。但我想进一步改进下算法,加入不同地形的影响因素。
熟悉Astar算法的都知道,这个算法中有3个值,F,G,H。。其中G是起点到当前点的消耗。
一般的算法中,在计算消耗时,每一格的上下左右移动消耗都是10,斜着移动消耗值为14。
而我想将它改进下,根据要走的下一格的地形的不同而得到不同的消耗(例如如果是走向雪地,走一格消耗就是30等等……)
我的想法:
现在的问题就是无法判断一个已知格子周围的地形信息,本人才疏学浅,不知道RPG Maker里是否能判断当前格子周围地形的函数,我感觉只要判断出是哪个图块就行,到时候我就可以根据函数返回的图块来改变G值的计算方式了。希望各位高手不吝赐教,先谢过了!!!
如果高手们有其他的方法能实现我说的功能,同样欢迎!!!
附:我在论坛中找到的A star 寻路算法。
#==============================================================================
class Find_Path
#--------------------------------------------------------------------------
def initialize #初始化
@open_list = []#开启列表
@close_lise = []#关闭列表
end #结束初始化
#--------------------------------------------------------------------------
def fp_passable?(x, y, d) #开始判定通行
if [2, 4, 6, 8].include?(d)
if $game_player.passable?(x, y, d)
return true
else
return false
end
else
case d
when 1
if ($game_player.passable?(x, y, 4) and
$game_player.passable?(x - 1, y, 2)) or
($game_player.passable?(x, y, 2) and
$game_player.passable?(x, y + 1, 4))
return true
else
return false
end
when 3
if ($game_player.passable?(x, y, 6) and
$game_player.passable?(x + 1, y, 2)) or
($game_player.passable?(x, y, 2) and
$game_player.passable?(x, y + 1, 6))
return true
else
return false
end
when 7
if ($game_player.passable?(x, y, 4) and
$game_player.passable?(x - 1, y, 8)) or
($game_player.passable?(x, y, 8) and
$game_player.passable?(x, y - 1, 4))
return true
else
return false
2011年06月25日 03点06分
1
熟悉Astar算法的都知道,这个算法中有3个值,F,G,H。。其中G是起点到当前点的消耗。
一般的算法中,在计算消耗时,每一格的上下左右移动消耗都是10,斜着移动消耗值为14。
而我想将它改进下,根据要走的下一格的地形的不同而得到不同的消耗(例如如果是走向雪地,走一格消耗就是30等等……)
我的想法:
现在的问题就是无法判断一个已知格子周围的地形信息,本人才疏学浅,不知道RPG Maker里是否能判断当前格子周围地形的函数,我感觉只要判断出是哪个图块就行,到时候我就可以根据函数返回的图块来改变G值的计算方式了。希望各位高手不吝赐教,先谢过了!!!
如果高手们有其他的方法能实现我说的功能,同样欢迎!!!
附:我在论坛中找到的A star 寻路算法。
#==============================================================================
class Find_Path
#--------------------------------------------------------------------------
def initialize #初始化
@open_list = []#开启列表
@close_lise = []#关闭列表
end #结束初始化
#--------------------------------------------------------------------------
def fp_passable?(x, y, d) #开始判定通行
if [2, 4, 6, 8].include?(d)
if $game_player.passable?(x, y, d)
return true
else
return false
end
else
case d
when 1
if ($game_player.passable?(x, y, 4) and
$game_player.passable?(x - 1, y, 2)) or
($game_player.passable?(x, y, 2) and
$game_player.passable?(x, y + 1, 4))
return true
else
return false
end
when 3
if ($game_player.passable?(x, y, 6) and
$game_player.passable?(x + 1, y, 2)) or
($game_player.passable?(x, y, 2) and
$game_player.passable?(x, y + 1, 6))
return true
else
return false
end
when 7
if ($game_player.passable?(x, y, 4) and
$game_player.passable?(x - 1, y, 8)) or
($game_player.passable?(x, y, 8) and
$game_player.passable?(x, y - 1, 4))
return true
else
return false