查看: 4633|回复: 2

[原创发布] 仿梦幻卷屏效果[八方向]

[复制链接]
梦石
0
星屑
1556
在线时间
626 小时
注册时间
2010-8-5
回帖
317
发表于 2014-9-6 23:53:48 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
https://rpg.blue/thread-198307-1-1.html  这是懒虫起床 以前的帖子。。。我稍微修改了下,[稍微。。]是八方向实现效果

  1. $速度 = 4#值越大卷屏越快
复制代码
——脚本1

  1. #==============================================================================
  2. # ■ Game_Player
  3. #------------------------------------------------------------------------------
  4. # 处理主角的类。事件启动的判定、以及地图的滚动等功能。
  5. # 本类的实例请参考 $game_player。
  6. #十一弦修改
  7. #==============================================================================

  8. class Game_Player < Game_Character
  9.   #--------------------------------------------------------------------------
  10.   # ● 恒量
  11.   #--------------------------------------------------------------------------
  12.   CENTER_X = (320 - 16) * 4   # 画面中央的 X 坐标 * 4
  13.   CENTER_Y = (240 - 16) * 4   # 画面中央的 Y 坐标 * 4
  14.   #--------------------------------------------------------------------------
  15.   # ● 可以通行判定
  16.   #     x : X 坐标
  17.   #     y : Y 坐标
  18.   #     d : 方向 (0,2,4,6,8)  ※ 0 = 全方向不能通行的情况判定 (跳跃用)
  19.   #--------------------------------------------------------------------------
  20.   def passable?(x, y, d)
  21.     # 求得新的坐标
  22.     new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  23.     new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  24.     # 坐标在地图外的情况下
  25.     unless $game_map.valid?(new_x, new_y)
  26.       # 不能通行
  27.       return false
  28.     end
  29.     # 调试模式为 ON 并且 按下 CTRL 键的情况下
  30.     if $DEBUG and Input.press?(Input::CTRL)
  31.       # 可以通行
  32.       return true
  33.     end
  34.     super
  35.   end
  36.   #--------------------------------------------------------------------------
  37.   # ● 获取角色名称
  38.   #--------------------------------------------------------------------------
  39.   def name
  40.     return $game_party.actors[0].name
  41.   end
  42.   #--------------------------------------------------------------------------
  43.   # ● 像通到画面中央一样的设置地图的显示位置
  44.   #--------------------------------------------------------------------------
  45.   def center(x, y)
  46.     max_x = ($game_map.width - 20) * 128
  47.     max_y = ($game_map.height - 15) * 128
  48.     $game_map.display_x = [0, [x * 128 - CENTER_X, max_x].min].max
  49.     $game_map.display_y = [0, [y * 128 - CENTER_Y, max_y].min].max
  50.   end
  51.   #--------------------------------------------------------------------------
  52.   # ● 向指定的位置移动
  53.   #     x : X 座標
  54.   #     y : Y 座標
  55.   #--------------------------------------------------------------------------
  56.   def moveto(x, y)
  57.     super
  58.     # 自连接
  59.     center(x, y)
  60.     # 生成遇敌计数
  61.     make_encounter_count
  62.   end
  63.   #--------------------------------------------------------------------------
  64.   # ● 增加步数
  65.   #--------------------------------------------------------------------------
  66.   def increase_steps
  67.     super
  68.     # 不是强制移动路线的场合
  69.     unless @move_route_forcing
  70.       # 增加步数
  71.       $game_party.increase_steps
  72.       # 步数是偶数的情况下
  73.       if $game_party.steps % 2 == 0
  74.         # 检查连续伤害
  75.         $game_party.check_map_slip_damage
  76.       end
  77.     end
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # ● 获取遇敌计数
  81.   #--------------------------------------------------------------------------
  82.   def encounter_count
  83.     return @encounter_count
  84.   end
  85.   #--------------------------------------------------------------------------
  86.   # ● 生成遇敌计数
  87.   #--------------------------------------------------------------------------
  88.   def make_encounter_count
  89.     # 两种颜色震动的图像
  90.     if $game_map.map_id != 0
  91.       n = $game_map.encounter_step
  92.       @encounter_count = rand(n) + rand(n) + 1
  93.     end
  94.   end
  95.   #--------------------------------------------------------------------------
  96.   # ● 刷新
  97.   #--------------------------------------------------------------------------
  98.   def refresh
  99.     # 同伴人数为 0 的情况下
  100.     if $game_party.actors.size == 0
  101.       # 清除角色的文件名及对像
  102.       @character_name = ""
  103.       @character_hue = 0
  104.       # 分支结束
  105.       return
  106.     end
  107.     # 获取带头的角色
  108.     actor = $game_party.actors[0]
  109.     # 设置角色的文件名及对像
  110.     @character_name = actor.character_name
  111.     @character_hue = actor.character_hue
  112.     # 初始化不透明度和合成方式子
  113.     @opacity = 255
  114.     @blend_type = 0
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # ● 同位置的事件启动判定
  118.   #--------------------------------------------------------------------------
  119.   def check_event_trigger_here(triggers)
  120.     result = false
  121.     # 事件执行中的情况下
  122.     if $game_system.map_interpreter.running?
  123.       return result
  124.     end
  125.     # 全部事件的循环
  126.     for event in $game_map.events.values
  127.       # 事件坐标与目标一致的情况下
  128.       if event.x == @x and event.y == @y and triggers.include?(event.trigger)
  129.         # 跳跃中以外的情况下、启动判定是同位置的事件
  130.         if not event.jumping? and event.over_trigger?
  131.           event.start
  132.           result = true
  133.         end
  134.       end
  135.     end
  136.     return result
  137.   end
  138.   #--------------------------------------------------------------------------
  139.   # ● 正面事件的启动判定
  140.   #--------------------------------------------------------------------------
  141.   def check_event_trigger_there(triggers)
  142.     result = false
  143.     # 事件执行中的情况下
  144.     if $game_system.map_interpreter.running?
  145.       return result
  146.     end
  147.     # 计算正面坐标
  148.     new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  149.     new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  150.     # 全部事件的循环
  151.     for event in $game_map.events.values
  152.       # 事件坐标与目标一致的情况下
  153.       if event.x == new_x and event.y == new_y and
  154.          triggers.include?(event.trigger)
  155.         # 跳跃中以外的情况下、启动判定是正面的事件
  156.         if not event.jumping? and not event.over_trigger?
  157.           event.start
  158.           result = true
  159.         end
  160.       end
  161.     end
  162.     # 找不到符合条件的事件的情况下
  163.     if result == false
  164.       # 正面的元件是计数器的情况下
  165.       if $game_map.counter?(new_x, new_y)
  166.         # 计算 1 元件里侧的坐标
  167.         new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  168.         new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  169.         # 全事件的循环
  170.         for event in $game_map.events.values
  171.           # 事件坐标与目标一致的情况下
  172.           if event.x == new_x and event.y == new_y and
  173.              triggers.include?(event.trigger)
  174.             # 跳跃中以外的情况下、启动判定是正面的事件
  175.             if not event.jumping? and not event.over_trigger?
  176.               event.start
  177.               result = true
  178.             end
  179.           end
  180.         end
  181.       end
  182.     end
  183.     return result
  184.   end
  185.   #--------------------------------------------------------------------------
  186.   # ● 接触事件启动判定
  187.   #--------------------------------------------------------------------------
  188.   def check_event_trigger_touch(x, y)
  189.     result = false
  190.     # 事件执行中的情况下
  191.     if $game_system.map_interpreter.running?
  192.       return result
  193.     end
  194.     # 全事件的循环
  195.     for event in $game_map.events.values
  196.       # 事件坐标与目标一致的情况下
  197.       if event.x == x and event.y == y and [1,2].include?(event.trigger)
  198.         # 跳跃中以外的情况下、启动判定是正面的事件
  199.         if not event.jumping? and not event.over_trigger?
  200.           event.start
  201.           result = true
  202.         end
  203.       end
  204.     end
  205.     return result
  206.   end
  207.   #--------------------------------------------------------------------------
  208.   # ● 画面更新
  209.   #--------------------------------------------------------------------------
  210.   def update
  211.     # 本地变量记录移动信息
  212.     last_moving = moving?
  213.     # 移动中、事件执行中、强制移动路线中、
  214.     # 信息窗口一个也不显示的时候
  215.     unless moving? or $game_system.map_interpreter.running? or
  216.       @move_route_forcing or $game_temp.message_window_showing
  217.       # 判断主角行走图方向数量
  218.       case Input.dir8
  219.       when 2
  220.         move_down
  221.                 @fangxiang = false
  222.       when 4
  223.         move_left
  224.                 @fangxiang = false
  225.       when 6
  226.         move_right
  227.                 @fangxiang = false
  228.       when 8
  229.         move_up
  230.                 @fangxiang = false
  231.       when 1
  232.         move_lower_left
  233.                 @fangxiang = false
  234.       when 3
  235.         move_lower_right
  236.                 @fangxiang = false
  237.       when 7
  238.         move_upper_left
  239.                 @fangxiang = false
  240.       when 9
  241.         move_upper_right
  242.                 @fangxiang = false
  243.     else
  244.       @fangxiang = true
  245.       end
  246.     end
  247.     # 本地变量记忆坐标
  248.     last_real_x = @real_x
  249.     last_real_y = @real_y
  250.     super
  251.     # 角色向下移动、画面上的位置在中央下方的情况下
  252.     if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y + 300
  253.       # 画面向下卷动
  254.       $game_map.scroll_down(@real_y - last_real_y)
  255.      else
  256.     if @fangxiang == true and @real_y - $game_map.display_y > CENTER_Y
  257.       $game_map.scroll_down($速度)
  258.     end
  259.     end
  260.     # 角色向左移动、画面上的位置在中央左方的情况下
  261.     if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X - 300
  262.       # 画面向左卷动
  263.       $game_map.scroll_left(last_real_x - @real_x)
  264.      else
  265.     if @fangxiang == true and  @real_x - $game_map.display_x < CENTER_X
  266.       $game_map.scroll_left($速度)
  267.     end
  268.     end
  269.     # 角色向右移动、画面上的位置在中央右方的情况下
  270.     if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X + 300
  271.       # 画面向右卷动
  272.       $game_map.scroll_right(@real_x - last_real_x)
  273.      else
  274.     if @fangxiang == true and @real_x - $game_map.display_x > CENTER_X
  275.       $game_map.scroll_right($速度)
  276.     end
  277.     end
  278.     # 角色向上移动、画面上的位置在中央上方的情况下
  279.     if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y - 300
  280.       # 画面向上卷动
  281.       $game_map.scroll_up(last_real_y - @real_y)
  282.      else
  283.     if @fangxiang == true and @real_y - $game_map.display_y < CENTER_Y
  284.       $game_map.scroll_up($速度)
  285.     end
  286.     end
  287.    
  288.     # 不在移动中的情况下
  289.     unless moving?
  290.       # 上次主角移动中的情况
  291.       if last_moving
  292.         # 与同位置的事件接触就判定为事件启动
  293.         result = check_event_trigger_here([1,2])
  294.         # 没有可以启动的事件的情况下
  295.         if result == false
  296.           # 调试模式为 ON 并且按下 CTRL 键的情况下除外
  297.           unless $DEBUG and Input.press?(Input::CTRL)
  298.             # 遇敌计数下降
  299.             if @encounter_count > 0
  300.               @encounter_count -= 1
  301.             end
  302.           end
  303.         end
  304.       end
  305.       # 按下 C 键的情况下
  306.       if Input.trigger?(Input::C)
  307.         # 判定为同位置以及正面的事件启动
  308.         check_event_trigger_here([0])
  309.         check_event_trigger_there([0,1,2])
  310.       end
  311.     end
  312.   end
  313. end

复制代码
梦石
0
星屑
8026
在线时间
1051 小时
注册时间
2012-4-3
回帖
1270

开拓者

发表于 2014-9-8 03:13:42 来自手机 | 显示全部楼层
深夜里,来踩一脚吧。
回复

使用道具 举报

梦石
0
星屑
631
在线时间
0 小时
注册时间
2015-8-31
回帖
1
发表于 2015-8-31 12:57:16 | 显示全部楼层
111111111111
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部