设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3564|回复: 2
打印 上一主题 下一主题

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

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1546
在线时间
625 小时
注册时间
2010-8-5
帖子
451
跳转到指定楼层
1
发表于 2014-9-6 23:53:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

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

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

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

Lv4.逐梦者

梦石
0
星屑
7921
在线时间
1049 小时
注册时间
2012-4-3
帖子
1271

开拓者

2
发表于 2014-9-8 03:13:42 手机端发表。 | 只看该作者
深夜里,来踩一脚吧。
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
631
在线时间
0 小时
注册时间
2015-8-31
帖子
1
3
发表于 2015-8-31 12:57:16 | 只看该作者
111111111111
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-28 17:55

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表