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

Project1

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

[原创发布] 纯脚本陷阱系统

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
45 小时
注册时间
2011-6-6
帖子
70
跳转到指定楼层
1
发表于 2011-7-7 20:40:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 160445706 于 2011-7-7 21:18 编辑

应该不用说了吧
使用方法:国际惯例,替代原脚本

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

本版积分规则

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

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

GMT+8, 2024-4-29 23:51

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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