Project1
标题:
关于八方向脚本的问题
[打印本页]
作者:
Clh
时间:
2018-3-3 21:40
标题:
关于八方向脚本的问题
#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#==============================================================================
#==============================================================================
#
# XP版八方向移动及遇到障碍自动转向脚本整合 by 7408,使用和转载请保留此信息
# 效果:实现手感加强的八方向移动,遇到障碍自动绕开
# 使用:将此脚本插入到Main前即可,面对事件不进行自动转向,
# 对于个别需要自动转向的事件,在该事件的第一页
# 第一行写一句注释"not_npc"(不含引号),
# 如不需要自动转向功能请删掉354行到593行的内容(就是保留最后一个end)
#
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# ● 画面更新
#--------------------------------------------------------------------------
def update
# 本地变量记录移动信息
last_moving = moving?
# 移动中、事件执行中、强制移动路线中、
# 信息窗口一个也不显示的时候
unless moving? or $game_system.map_interpreter.running? or
@move_route_forcing or $game_temp.message_window_showing
# 如果方向键被按下、主角就朝那个方向移动
case Input.dir8
when 1
move_lower_left
when 2
move_down
when 3
move_lower_right
when 4
move_left
when 6
move_right
when 7
move_upper_left
when 8
move_up
when 9
move_upper_right
end
end
# 本地变量记忆坐标
last_real_x = @real_x
last_real_y = @real_y
super
# 角色向下移动、画面上的位置在中央下方的情况下
if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
# 画面向下卷动
$game_map.scroll_down(@real_y - last_real_y)
end
# 角色向左移动、画面上的位置在中央左方的情况下
if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
# 画面向左卷动
$game_map.scroll_left(last_real_x - @real_x)
end
# 角色向右移动、画面上的位置在中央右方的情况下
if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
# 画面向右卷动
$game_map.scroll_right(@real_x - last_real_x)
end
# 角色向上移动、画面上的位置在中央上方的情况下
if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
# 画面向上卷动
$game_map.scroll_up(last_real_y - @real_y)
end
# 不在移动中的情况下
unless moving?
# 上次主角移动中的情况
if last_moving
# 与同位置的事件接触就判定为事件启动
result = check_event_trigger_here([1,2])
# 没有可以启动的事件的情况下
if result == false
# 调试模式为 ON 并且按下 CTRL 键的情况下除外
unless $DEBUG and Input.press?(Input::CTRL)
# 遇敌计数下降
if @encounter_count > 0
@encounter_count -= 1
end
end
end
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 判定为同位置以及正面的事件启动
check_event_trigger_here([0])
check_event_trigger_there([0,1,2])
end
end
end
end
class Game_Character
#--------------------------------------------------------------------------
# ● 向左下移动
#--------------------------------------------------------------------------
def move_lower_left
# 没有固定面向的场合
unless @direction_fix
# 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
@direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
end
# 下→左、左→下 的通道可以通行的情况下
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) and
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
# 更新坐标
@x -= 1
@y += 1
# 增加步数
increase_steps
# 下→左能够通行的情况下
elsif (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4))
# 向下移动后向左移动
move_down
move_left
# 左→下能够通行的情况下
elsif (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
# 向左移动后向下移动
move_left
move_down
# 如果移动的对象是角色且非强制移动
elsif self.is_a?(Game_Player) and not @move_route_forcing
# 面向左时
if @direction = 4
# 左方可以通行时
if passable?(@x, @y, 4)
# 向左移动
move_left
# 不能通行时
else
# 左面接触事件启动
result = check_event_trigger_touch(@x-1, @y)
# 没有事件的情况下
unless result
# 向下移动
move_down
end
end
# 不面向左时
else
# 下方可以通行时
if passable?(@x, @y, 2)
# 向下移动
move_down
# 不能通行时
else
# 下面接触事件启动
result = check_event_trigger_touch(@x, @y+1)
# 没有事件的情况下
unless result
# 向左移动
move_left
end
end
end
end
end
#--------------------------------------------------------------------------
# ● 向右下移动
#--------------------------------------------------------------------------
def move_lower_right
# 没有固定面向的场合
unless @direction_fix
# 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
@direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
end
# 下→右、右→下 的通道可以通行的情况下
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
# 更新坐标
@x += 1
@y += 1
# 增加步数
increase_steps
# 下→右能够通行的情况下
elsif (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6))
# 向下移动后向右移动
move_down
move_right
# 右→下能够通行的情况下
elsif (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
# 向右移动后向下移动
move_right
move_down
# 如果移动的对象是角色且非强制移动
elsif self.is_a?(Game_Player) and not @move_route_forcing
# 面向右时
if @direction = 6
# 右方可以通行时
if passable?(@x, @y, 6)
# 向右移动
move_right
# 不能通行时
else
# 右面接触事件启动
result = check_event_trigger_touch(@x+1, @y)
# 没有事件的情况下
unless result
# 向下移动
move_down
end
end
# 不面向右时
else
# 下方可以通行时
if passable?(@x, @y, 2)
# 向下移动
move_down
# 不能通行时
else
# 下面接触事件启动
result = check_event_trigger_touch(@x, @y+1)
# 没有事件的情况下
unless result
# 向右移动
move_right
end
end
end
end
end
#--------------------------------------------------------------------------
# ● 向左上移动
#--------------------------------------------------------------------------
def move_upper_left
# 没有固定面向的场合
unless @direction_fix
# 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
@direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
end
# 上→左、左→上 的通道可以通行的情况下
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
# 更新坐标
@x -= 1
@y -= 1
# 增加步数
increase_steps
# 上→左能够通行的情况下
elsif (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4))
# 向上移动后向左移动
move_up
move_left
# 左→上能够通行的情况下
elsif (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
# 向左移动后向上移动
move_left
move_up
# 如果移动的对象是角色且非强制移动
elsif self.is_a?(Game_Player) and not @move_route_forcing
# 面向左时
if @direction = 4
# 左方可以通行时
if passable?(@x, @y, 4)
# 向左移动
move_left
# 不能通行时
else
# 左面接触事件启动
result = check_event_trigger_touch(@x-1, @y)
# 没有事件的情况下
unless result
# 向上移动
move_up
end
end
# 不面向左时
else
# 上方可以通行时
if passable?(@x, @y, 8)
# 向上移动
move_up
# 不能通行时
else
# 上面接触事件启动
result = check_event_trigger_touch(@x, @y-1)
# 没有事件的情况下
unless result
# 向左移动
move_left
end
end
end
end
end
#--------------------------------------------------------------------------
# ● 向右上移动
#--------------------------------------------------------------------------
def move_upper_right
# 没有固定面向的场合
unless @direction_fix
# 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
@direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
end
# 上→右、右→上 的通道可以通行的情况下
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
# 更新坐标
@x += 1
@y -= 1
# 增加步数
increase_steps
# 上→右能够通行的情况下
elsif (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6))
# 向上移动后向右移动
move_up
move_right
# 右→上能够通行的情况下
elsif (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
# 向右移动后向上移动
move_right
move_up
# 如果移动的对象是角色且非强制移动
elsif self.is_a?(Game_Player) and not @move_route_forcing
# 面向右时
if @direction = 6
# 右方可以通行时
if passable?(@x, @y, 6)
# 向右移动
move_right
# 不能通行时
else
# 右面接触事件启动
result = check_event_trigger_touch(@x+1, @y)
# 没有事件的情况下
unless result
# 向上移动
move_up
end
end
# 不面向右时
else
# 上方可以通行时
if passable?(@x, @y, 8)
# 向上移动
move_up
# 不能通行时
else
# 上面接触事件启动
result = check_event_trigger_touch(@x, @y-1)
# 没有事件的情况下
unless result
# 向右移动
move_right
end
end
end
end
end
end
复制代码
我这个萌新又来求问了,是这样的,我用了这个八方向的脚本(里面原有的自动绕路被我删了),很完美的实现了八方向移动,但是我觉得在斜向移动的同时还是以原来的正向角色图形很别扭。
就说说我的请求吧,假设角色行走图的名字为“QAQ.png”,哪位大佬帮我设定当斜向的同时把角色图形更改为“QAQ
_X
.png”,正向时再改回来,并且要求不与人物跟随、近大远小脚本冲突,万分感谢哦……
作者:
灯笼菜刀王
时间:
2018-3-6 18:33
你的这个是"伪"八方向, 斜向移动只是把原本按一下方向移动一次, 变成按一下方向移动两次~
根据脚本原理,你把自动绕路删了的话,某些情况下可是会出现类似象棋中别马脚一样的现象哦
, 不要自动绕路的话,建议画地图都用横平竖直的大路,不要在路上设置不可通行的零碎障碍物~~
如果要实现更换行走图, 有两种方法, 1是把它变成"真"八方向, 也就是给4个斜向定义direction= 1,3,7,9. 然后到Sprite_Character里追加4个角色矩形的计算.
用这个方法可以保证"转向自然","无懈可击"~~ 缺点是,你要给所有NPC都准备8方向
2是偷懒法,只给主角用8反向, 思路:加个开关, 用它来判断是正常操作还是斜向操作, 然后移动操作里追加这个开关的打开和关闭. 然后用这个开关来判断, 当Character是主角的时候,开关关闭使用XXX行走图,开关打开使用XXX2行走图.
用这个方法可以一定程度上实现"不会正向斜移动", 然而缺点是, 一些接触式的事件可能会有囧情况~~ 比如斜着进门之类的, 不想出现这些BUG, 设置这些事件同样要考虑到这个开关问题. 考研细心
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1