赞 | 4 |
VIP | 211 |
好人卡 | 175 |
积分 | 7 |
经验 | 48096 |
最后登录 | 2014-1-9 |
在线时间 | 1327 小时 |
Lv2.观梦者 (?????)
- 梦石
- 0
- 星屑
- 728
- 在线时间
- 1327 小时
- 注册时间
- 2011-7-18
- 帖子
- 3184
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 各种压力的猫君 于 2012-1-29 02:04 编辑
移植自XP脚本 Leyeshot2.1线形视野系统,做暗杀类游戏的葵花宝典! By 流川枫- #encoding:utf-8
- #==============================================================================
- # [PS0]线形视野系统
- # Linetype_Eyeshot
- #------------------------------------------------------------------------------
- # 非常强大、高效率的NPC视野系统
- #==============================================================================
- # [更新记录]
- # - 2012.01.29 By 各种压力的猫君
- # * 移植至RGSS3,遵循PS0协议
- # - 2008.11.03 By LCF(流川枫 QQ:350773875)
- # * 蓝本(LCF_Leyeshot XP 2.1)
- #------------------------------------------------------------------------------
- # [使用方法]
- # - 将本脚本插入到MAIN以上
- # - 当NPC看到主角时,会打开自身的独立开关D
- #------------------------------------------------------------------------------
- # [使用说明]
- # - 在需要开启视野系统的NPC身上执行以下脚本至少一次即可
- # 以下内容纯移植原脚本,下一版加入简化输入功能。
- # - $game_map.events[@event_id].le_seeing = true/false
- # 该值为true表示该NPC视野开启,否则未开启,默认为false。
- # - $game_map.events[@event_id].le_clairv = true/false
- # 该值为true表示该NPC视野不扫描视线障碍,否则扫描,默认为false。
- # - $game_map.events[@event_id].le_show = true/false
- # 该值为true表示显示该NPC的视线,否则不显示,默认为false。
- # - $game_map.events[@event_id].le_side = true/false
- # 该值为true表示该NPC可以看到侧面一格内的人,否则由斜率决定,默认为true。
- # - $game_map.events[@event_id].le_circle = true/false
- # 该值为true表示该NPC为环绕视野,否则不能看见自己的身后,默认为false。
- # - $game_map.events[@event_id].le_deepness = 深度值
- # 该值代表视野的能见度,默认为7。
- # - $game_map.events[@event_id].le_slope = 斜率值
- # 该值代表视野的斜率,默认为1.0。
- # - $game_map.events[@event_id].le_color = 颜色值
- # 该值代表视线显示的颜色,默认为0xf0。
- #==============================================================================
- $_PS0 = {} if $_PS0 == nil
- $_PS0["Linetype_Eyeshot"] = 20120129
- #==============================================================================
- # [PS0] 通用配置模块
- #==============================================================================
- module PS0
- module Linetype_Eyeshot
-
- # 初始版本,仅移植为Ace可用版本。功能待添加。
-
- end
- end
- #==============================================================================
- # ■ Game_Event
- #==============================================================================
- class Game_Event < Game_Character
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_accessor :le_seeing # 视野系统开关
- attr_accessor :le_clairv # 视野透视开关
- attr_accessor :le_show # 视线显示开关
- attr_accessor :le_side # 侧面可视开关
- attr_accessor :le_circle # 视野环绕开关
- attr_accessor :le_deepness # 视野深度
- attr_accessor :le_slope # 视野斜率
- attr_accessor :le_color # 显示颜色
- #--------------------------------------------------------------------------
- # ● 初始化对象
- # event : RPG::Event
- #--------------------------------------------------------------------------
- alias original_initialize initialize
- def initialize(map_id, event)
- original_initialize(map_id, event)
- @le_seeing = false
- @le_clairv = false
- @le_show = false
- @le_side = true
- @le_circle = false
- @le_deepness = 7
- @le_slope = 1.0
- @le_color = 0xf0
- @trace = Table.new(@le_deepness,2)
- @trace[0,0] = -1
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- alias original_update update
- def update
- if @le_seeing
- @trace.resize(@le_deepness,2) if @trace.xsize != @le_deepness
- original_switch = $game_self_switches[[$game_map.map_id, @id, "D"]]
- self.see
- $game_map.need_refresh = true if original_switch != $game_self_switches[[$game_map.map_id, @id, "D"]]
- end
- original_update
- end
- #--------------------------------------------------------------------------
- # ● 视野检测
- #--------------------------------------------------------------------------
- def see
- $game_self_switches[[$game_map.map_id, @id, "D"]] = false
- if ($game_player.x-@x).abs<@le_deepness and ($game_player.y-@y).abs<@le_deepness
- difference_x = $game_player.x - @x
- difference_y = $game_player.y - @y
- case @direction
- when 2
- return if @le_circle != true and $game_player.y < @y
- unless @le_side and (difference_y == 0 and difference_x.abs == 1)
- return if (difference_y/(difference_x+0.0)).abs < @le_slope
- end
- when 4
- return if @le_circle != true and $game_player.x > @x
- unless @le_side and difference_y.abs == 1 and difference_x == 0
- return if (difference_x/(difference_y+0.0)).abs < @le_slope
- end
- when 6
- return if @le_circle != true and $game_player.x < @x
- unless @le_side and difference_y.abs == 1 and difference_x == 0
- return if (difference_x/(difference_y+0.0)).abs < @le_slope
- end
- else
- return if @le_circle != true and $game_player.y > @y
- unless @le_side and difference_y == 0 and difference_x.abs == 1
- return if (difference_y/(difference_x+0.0)).abs < @le_slope
- end
- end
- $game_self_switches[[$game_map.map_id, @id, "D"]] = scan_line
- end
- end
- #--------------------------------------------------------------------------
- # ● 视线检测
- #--------------------------------------------------------------------------
- def scan_line
- difference_x = $game_player.x - @x
- difference_y = $game_player.y - @y
- direction_x = (difference_x > 0 ? 1 : -1)
- direction_y = (difference_y > 0 ? 1 : -1)
- i = 0
- if difference_x.abs > difference_y.abs
- while difference_x.abs > i+1
- i+=1
- x = @x+i*direction_x
- if direction_y>0
- y = @y+i*difference_y/(difference_x+0.0)*direction_y*direction_x+0.5
- else
- y = @y-i*difference_y/(difference_x+0.0)*direction_y*direction_x+0.5
- end
- x = x.floor
- y = y.floor
- if @le_clairv != true
- unless (direction_x > 0 ? passable?(x-1,y,6) : passable?(x+1,y,4))
- @trace[i-1,0] = -1
- return false
- end
- end
- if @le_show
- @trace[i-1,0] = x
- @trace[i-1,1] = y
- $scene.spriteset.tilemap.flash_data[x,y] = @le_color
- end
- end
- else
- while difference_y.abs > i+1
- i+=1
- y = @y+i*direction_y
- if direction_x>0
- x = @x+i*difference_x/(difference_y+0.0)*direction_x*direction_y+0.5
- else
- x = @x-i*difference_x/(difference_y+0.0)*direction_x*direction_y+0.5
- end
- x = x.floor
- y = y.floor
- if @le_clairv != true
- unless (direction_y > 0 ? passable?(x,y-1,2) : passable?(x,y+1,8))
- @trace[i-1,0] = -1
- return false
- end
- end
- if @le_show
- @trace[i-1,0] = x
- @trace[i-1,1] = y
- SceneManager.scene.spriteset.tilemap.flash_data[x,y] = @le_color
- end
- end
- end
- return true
- end
- #--------------------------------------------------------------------------
- # ● 清楚痕迹
- #--------------------------------------------------------------------------
- def clear
- for i in 0 .. @trace.xsize-1
- break if @trace[i,0] == -1
- SceneManager.scene.spriteset.tilemap.flash_data[@trace[i,0],@trace[i,1]] = 0
- end
- @trace[0,0] = -1
- end
- end
- #==============================================================================
- # ■ Spriteset_Map
- #==============================================================================
- class Spriteset_Map
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :tilemap
- #--------------------------------------------------------------------------
- # ● 初始化对象
- #--------------------------------------------------------------------------
- alias original_ini initialize
- def initialize
- original_ini
- @tilemap.flash_data=Table.new(@tilemap.map_data.xsize,@tilemap.map_data.ysize)
- end
- end
- #==============================================================================
- # ■ Scene_Map
- #==============================================================================
- class Scene_Map
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :spriteset
- end
- #==============================================================================
- # ■ Game_Map
- #==============================================================================
- class Game_Map
- alias original_update update
- #--------------------------------------------------------------------------
- # ● 更新画面
- # main : 事件解释器更新的标志
- #--------------------------------------------------------------------------
- def update(main = false)
- # 清除视线痕迹
- for event in @events.values
- event.clear
- end
- original_update(main = false)
- end
- end
- #==============================================================================
- # [PS0] End of Script
- #==============================================================================
复制代码 这次移植很简单 = = 中途走了弯路所以拖了半天……
范例暂不提供,请浏览原版的旧发布页:
http://www.66rpg.com/htm/news1185.htm
想测试效果的话,随便弄个范例地图,建个NPC,用事件脚本- $game_map.events[@event_id].le_seeing = true
- $game_map.events[@event_id].le_show = true
复制代码 就能看到效果了。
|
评分
-
查看全部评分
|