赞 | 0 |
VIP | 23 |
好人卡 | 30 |
积分 | 0 |
经验 | 85978 |
最后登录 | 2017-6-19 |
在线时间 | 1165 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 38
- 在线时间
- 1165 小时
- 注册时间
- 2012-3-16
- 帖子
- 5336
|
覆盖原来的路标脚本~
我是抄的我会说吗...- #===============================================================================
- # 路牌提示系统 v1.02 by 沉影不器
- #------------------------------------------------------------------------------
- # 功能说明:
- # 仿《黑暗圣剑传说2 序章》(柳柳)的介绍里提到的效果写的,据说是空之轨迹里的效果
- # 原游戏的实现方式是公共事件播放动画, 以下引用原描述:
- # "方便玩家的路牌设计, 当靠近路牌的时候, 路牌就会指引玩家的方向"
- #------------------------------------------------------------------------------
- # 使用说明(详见范例工程):
- # ① 制作路牌皮肤文件, 包含三个文件(64×64的窗体和两个箭头标志)
- # ② 在地图上创建路牌事件, 并在事件中用注释写上指路内容, 允许多项
- # ③ 指路内容格式为(忽略空格): 方向代号 = 该方向所指向的名称
- # 其中方向代号为: 2 4 6 8 (下 左 右 上)
- # 例: 2 = 悦来客栈 显示"↓ 悦来客栈"
- # ④ 创建与路牌事件同名的区域, 表示玩家进入该区域时激活相应路牌
- #------------------------------------------------------------------------------
- # 更新历史:
- # 2008-09-09 v1.00 原始版
- # 2008-10-19 v1.01 增加场所跳转时路牌的显示控制
- # 2010-10-05 v1.02 修复路牌正在显示时无法存档的错误
- #==============================================================================
- # □ Spriteset_Roadsign
- #==============================================================================
- class Spriteset_Roadsign
- #--------------------------------------------------------------------------
- # ○ 参数设定
- #--------------------------------------------------------------------------
- # 窗体最小宽度
- WIDTH_MIN = 96
- # 窗体显示时间
- SHOW_TIME = 60
-
- # 字体
- FONT = "宋体"
- # 字体大小
- FONT_SIZE = 14
- # 字体阴影
- FONT_SHADOW = false
- # 字体颜色
- FONT_COLOR = Color.new(0,0,0)
-
- # 路标皮肤
- SIGN_SKIN = "Roadsign"
- # 皮肤厚度(边框)
- SKIN_SIZE = 8
- # 路标不透明度
- SIGN_OPACITY = 192
-
- # 路标箭头坐标微调
- X_ADJ = 0
- Y_ADJ = 0
- #--------------------------------------------------------------------------
- # ○ 初始化对象
- # event : 事件
- #--------------------------------------------------------------------------
- def initialize(event)
- @event = event
- # 显示控制符
- [url=home.php?mod=space&uid=32215]@show[/url] = true
- # 显示时间计数
- @show_count = 0
- # 相对定位
- @x_plus = 0
- @y_plus = 0
- # 描绘内容
- @texts = get_texts
- # 主'窗体'
- @base_sprite = Sprite.new
- @base_sprite.z = 999
- @base_sprite.opacity = 0
- # 大小和尺寸
- set_size
- get_pos
- reset_pos
- # 描绘皮肤
- draw_skin
- refresh
- end
- #--------------------------------------------------------------------------
- # ○ 释放
- #--------------------------------------------------------------------------
- def dispose
- @base_sprite.bitmap.dispose
- @base_sprite.dispose
- @arrow_sprite.bitmap.dispose
- @arrow_sprite.dispose
- # 还原事件
- $game_map.events.each_value{|event| event.roadsign = "" if event == @event}
- end
- #--------------------------------------------------------------------------
- # ○ 是否释放
- #--------------------------------------------------------------------------
- def disposed?
- return @base_sprite.disposed?
- end
- #--------------------------------------------------------------------------
- # ○ 更新画面
- #--------------------------------------------------------------------------
- def update
- # 跟随路标
- reset_pos
- # 显示期
- if @show_count > 0
- @show_count -= 1
- return
- end
- # 开始显示期
- if @base_sprite.opacity >= 255
- @show_count = SHOW_TIME
- @show = false
- end
- # 显示中或隐藏中
- if @show
- @base_sprite.opacity += 8 if @base_sprite.opacity < 255
- else
- @base_sprite.opacity -= 8 if @base_sprite.opacity > 0
- end
- @arrow_sprite.opacity = @base_sprite.opacity
- # 自释放
- self.dispose if !@show and @base_sprite.opacity <= 0
- end
- #--------------------------------------------------------------------------
- # ○ 获取描绘文本
- #--------------------------------------------------------------------------
- def get_texts
- down = @event.read_roadsign("2")
- left = @event.read_roadsign("4")
- right = @event.read_roadsign("6")
- up = @event.read_roadsign("8")
- texts = []
- texts.push("↓ " + down) if down != ""
- texts.push("← " + left) if left != ""
- texts.push("→ " + right) if right != ""
- texts.push("↑ " + up) if up != ""
- return texts
- end
- #--------------------------------------------------------------------------
- # ○ 创建位图
- #--------------------------------------------------------------------------
- def create_bitmap(width, height)
- @base_sprite.bitmap = Bitmap.new(width, height)
- # 字体设定
- @base_sprite.bitmap.font = Font.new(FONT, FONT_SIZE)
- @base_sprite.bitmap.font.shadow = FONT_SHADOW
- @base_sprite.bitmap.font.color = FONT_COLOR
- end
- #--------------------------------------------------------------------------
- # ○ 设定尺寸
- #--------------------------------------------------------------------------
- def set_size
- # 最小宽度
- width = WIDTH_MIN
- # 测试宽度的临时位图
- test_bitmap = Bitmap.new(1, 1)
- test_bitmap.font = Font.new(FONT, FONT_SIZE)
- for text in @texts
- c_width = test_bitmap.text_size(text).width
- width = c_width if c_width > width
- end
- height = @texts.size * line_height
- create_bitmap(width+SKIN_SIZE*2, height+SKIN_SIZE*2)
- # 释放临时位图
- test_bitmap.dispose
- end
- #--------------------------------------------------------------------------
- # ○ 获取坐标
- #--------------------------------------------------------------------------
- def get_pos
- x = @event.screen_x - width/2
- if @event.screen_y > height
- y = @event.screen_y - height - 32
- # 箭头类型标志
- up = true
- else
- y = @event.screen_y
- # 箭头类型标志
- up = false
- end
- # 相对定位
- @x_plus = x - @event.screen_x
- @y_plus = y - @event.screen_y
- set_arrow_sprite(up)
- end
- #--------------------------------------------------------------------------
- # ○ 重设坐标
- #--------------------------------------------------------------------------
- def reset_pos
- # 相对定位
- @base_sprite.x = @event.screen_x + @x_plus
- @base_sprite.y = @event.screen_y + @y_plus
- @arrow_sprite.x = @event.screen_x - 16 + X_ADJ
- @arrow_sprite.y = @event.screen_y - 32 + Y_ADJ
- end
- #--------------------------------------------------------------------------
- # ○ 设定箭头
- #--------------------------------------------------------------------------
- def set_arrow_sprite(up = true)
- @arrow_sprite = Sprite.new
- @arrow_sprite.opacity = 0
- # 上下两套箭头
- case up
- when true
- bitmap = Cache.system(SIGN_SKIN + "_arrow_up")
- rect = Rect.new(0, 0, bitmap.width, bitmap.height)
- @arrow_sprite.bitmap = Bitmap.new(rect.width, rect.height)
- @arrow_sprite.bitmap.blt(0, 0, bitmap, rect, SIGN_OPACITY)
- when false
- bitmap = Cache.system(SIGN_SKIN + "_arrow_down")
- rect = Rect.new(0, 0, bitmap.width, bitmap.height)
- @arrow_sprite.bitmap = Bitmap.new(rect.width, rect.height)
- @arrow_sprite.bitmap.blt(0, 0, bitmap, rect, SIGN_OPACITY)
- end
- bitmap.dispose
- end
- #--------------------------------------------------------------------------
- # ○ 获取宽度
- #--------------------------------------------------------------------------
- def width
- return @base_sprite.width
- end
- #--------------------------------------------------------------------------
- # ○ 获取高度
- #--------------------------------------------------------------------------
- def height
- return @base_sprite.height
- end
- #--------------------------------------------------------------------------
- # ○ 获取行高
- #--------------------------------------------------------------------------
- def line_height
- return FONT_SIZE + 2
- end
- #--------------------------------------------------------------------------
- # ○ 描绘皮肤
- #--------------------------------------------------------------------------
- def draw_skin
- # 皮肤文件
- skin = Cache.system(SIGN_SKIN)
- @base_sprite.bitmap.clear
- # 描绘角
- src_rect = Rect.new(0,0,16,16)
- @base_sprite.bitmap.blt(0, 0, skin, src_rect, SIGN_OPACITY)
- src_rect = Rect.new(48,0,16,16)
- @base_sprite.bitmap.blt(width-16, 0, skin, src_rect, SIGN_OPACITY)
- src_rect = Rect.new(0,48,16,16)
- @base_sprite.bitmap.blt(0, height-16, skin, src_rect, SIGN_OPACITY)
- src_rect = Rect.new(48,48,16,16)
- @base_sprite.bitmap.blt(width-16, height-16, skin, src_rect, SIGN_OPACITY)
- # 描绘边
- dest_rect = Rect.new(16,0,width-32,16)
- src_rect = Rect.new(16,0,32,16)
- @base_sprite.bitmap.stretch_blt(dest_rect, skin, src_rect, SIGN_OPACITY)
- dest_rect = Rect.new(16,height-16,width-32,16)
- src_rect = Rect.new(16,48,32,16)
- @base_sprite.bitmap.stretch_blt(dest_rect, skin, src_rect, SIGN_OPACITY)
- dest_rect = Rect.new(0,16,16,height-32)
- src_rect = Rect.new(0,16,16,32)
- @base_sprite.bitmap.stretch_blt(dest_rect, skin, src_rect, SIGN_OPACITY)
- dest_rect = Rect.new(width-16,16,16,height-32)
- src_rect = Rect.new(48,16,16,32)
- @base_sprite.bitmap.stretch_blt(dest_rect, skin, src_rect, SIGN_OPACITY)
- # 描绘底
- dest_rect = Rect.new(16,16,width-32,height-32)
- src_rect = Rect.new(16,16,32,32)
- @base_sprite.bitmap.stretch_blt(dest_rect, skin, src_rect, SIGN_OPACITY)
- # 释放皮肤文件
- skin.dispose
- end
- #--------------------------------------------------------------------------
- # ○ 刷新
- #--------------------------------------------------------------------------
- def refresh
- # 逐行
- for i in [email protected]
- rect = Rect.new(SKIN_SIZE, i*line_height+SKIN_SIZE, @base_sprite.width, line_height)
- text = @texts[i]
- @base_sprite.bitmap.draw_text(rect, text)
- end
- end
- end
- #==============================================================================
- # ■ Game_Event
- #==============================================================================
- class Game_Event < Game_Character
- #--------------------------------------------------------------------------
- # ◎ 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :id # 事件 ID
- attr_reader :name # 事件名称
- attr_accessor :roadsign # 路标标志
- #--------------------------------------------------------------------------
- # ◎ 初始化对像
- # map_id : 地图 ID
- # event : 事件 (RPG::Event)
- #--------------------------------------------------------------------------
- def initialize(map_id, event)
- super()
- @map_id = map_id
- @event = event
- @id = @event.id
- @erased = false
- @starting = false
- @through = true
- # 事件名称
- @name = @event.name
- # 路标
- @roadsign = ''
- moveto(@event.x, @event.y) # 向初期位置移动
- refresh
- end
- #-------------------------------------------------------------------------
- # ○ 读取路标指定字段
- # section : 字段名
- # ignore_caps : 忽略大小写(仅字段名)
- #-------------------------------------------------------------------------
- def read_roadsign(section, ignore_caps = false)
- result = ''
- # 忽略大小写时,全部转大写
- section.upcase! if ignore_caps
- # 转symbol方便比较
- s = section.to_sym
- @roadsign.each_line{|line|
- temp = line.split(/=/)
- # 去掉干扰字符
- temp.each {|i| i.strip!}
- temp[0].upcase! if ignore_caps
- if temp[0].to_sym == s
- unless temp[1] == nil
- result = temp[1]
- end
- # 如果希望同名字段值覆盖前面的字段,去掉下一行
- break
- end
- }
- return result
- end
- end
- #==============================================================================
- # ■ Game_Player
- #==============================================================================
- class Game_Player < Game_Character
- #--------------------------------------------------------------------------
- # ◎ 刷新画面
- #--------------------------------------------------------------------------
- def update
- last_real_x = @real_x
- last_real_y = @real_y
- last_moving = moving?
- move_by_input
- super
- update_scroll(last_real_x, last_real_y)
- update_vehicle
- update_nonmoving(last_moving)
- # 路标窗体刷新
- unless @roadsign_sprite == nil or @roadsign_sprite.disposed?
- @roadsign_sprite.update
- end
- end
- #--------------------------------------------------------------------------
- # ◎ 增加步数
- #--------------------------------------------------------------------------
- def increase_steps
- super
- return if @move_route_forcing
- return if in_vehicle?
- $game_party.increase_steps
- $game_party.on_player_walk
- # 路标操作
- setup_roadsign_spriteset
- end
- #--------------------------------------------------------------------------
- # ○ 显示路标
- #--------------------------------------------------------------------------
- def setup_roadsign_spriteset
- name = roadsign_name
- return if name == "" or name == @old_name
- @old_name = name
- event = get_event(name)
- return if event == nil
- roadsign_event = setup_roadsign_event(event)
- return if roadsign_event == nil
- # 生成路标窗体
- if @roadsign_sprite == nil or @roadsign_sprite.disposed?
- @roadsign_sprite = Spriteset_Roadsign.new(roadsign_event)
- end
- end
- #--------------------------------------------------------------------------
- # ○ 设置路标
- # event : 事件(Game_Map内部)
- #--------------------------------------------------------------------------
- def setup_roadsign_event(event)
- return if event.list == nil
- for line in event.list
- if line.code == 108 or 408
- unless line.parameters.empty?
- event.roadsign += line.parameters.to_s + "\r\n"
- end
- end
- end
- return event
- end
- #--------------------------------------------------------------------------
- # ○ 查找路标名称
- #--------------------------------------------------------------------------
- def roadsign_name
- for area in $data_areas.values
- return area.name if $game_player.in_area?(area)
- end
- @old_name = ""
- return @old_name
- end
- #--------------------------------------------------------------------------
- # ○ 获取事件
- # event_name : 事件名 $game_map.events.values
- #--------------------------------------------------------------------------
- def get_event(event_name)
- $game_map.events.each_value {|event| event.refresh;
- return event if event.name == event_name}
- return nil
- end
- #--------------------------------------------------------------------------
- # ○ 释放路标
- #--------------------------------------------------------------------------
- def dispose_roadsign
- if @roadsign_sprite
- @roadsign_sprite.dispose
- @roadsign_sprite = nil
- end
- end
- end
- #==============================================================================
- # ■ Scene_Map
- #==============================================================================
- class Scene_Map < Scene_Base
- #--------------------------------------------------------------------------
- # ◎ 结束处理
- #--------------------------------------------------------------------------
- def terminate
- super
- if $scene.is_a?(Scene_Battle) # 正在切换战斗画面的情况下
- @spriteset.dispose_characters # 为了生成背景隐藏角色
- end
- snapshot_for_background
- @spriteset.dispose
- @message_window.dispose
- if $scene.is_a?(Scene_Battle) # 正在切换战斗画面的情况下
- perform_battle_transition # 执行战斗前变换
- end
- # 释放路标
- $game_player.dispose_roadsign
- end
- end
复制代码 |
评分
-
查看全部评分
|