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

Project1

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

[RMVA发布] 带有奇怪功能的打字声效

[复制链接]

Lv5.捕梦者 (版主)

梦石
28
星屑
10170
在线时间
4673 小时
注册时间
2011-8-22
帖子
1279

开拓者

跳转到指定楼层
1
发表于 2016-12-14 12:59:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
在某群顺手写的代码,考虑到使用的场合应该不少于是传上来了……

RUBY 代码复制
  1. #===============================================================================
  2. # ■ [VA] 带有奇怪功能的打字声效
  3. #    Cirno
  4. #-------------------------------------------------------------------------------
  5. #    这个脚本能在各种对话中播放打字声效
  6. #    * 在 配置部分 中自定义声效种类、频率
  7. #    * 使用 \S[编号] 在对话途中改变声效
  8. #    * 使用 type_effects("效果1", "效果2", ...) 设置声效特殊效果
  9. #      ① 音量、声调的渐变
  10. #      ② 对话显示速度变化和震动效果
  11. #===============================================================================( e+ K- F5 k$ c4 ^6 W
  12. # 以下是配置部分
  13. #===============================================================================
  14. module Cirno
  15.   module TypingSound
  16.     #--------------------------------------------------------------------------
  17.     # * 默认设置
  18.     #--------------------------------------------------------------------------
  19.     # 脚本启用的开关编号
  20.     ENABLE_SWITCH = 1
  21.  
  22.     # 默认声效,格式为 [名字, 音量, 节奏]
  23.     DEFAULT_SOUND = ["Cursor1", 100, 100]
  24.  
  25.     # 是否用第一行来判断人物
  26.     # true:  按照第一行的名字在NAME_SOUNDS里选择对应的声效
  27.     # false: 按照脸图的文件名和图像编号,在FACE_DEFAULT_SOUNDS和FACE_PATTERN_SOUNDS中选择
  28.     FIRST_LINE_AS_CHARACTER = false
  29.     #--------------------------------------------------------------------------
  30.     # * 声效使用列表
  31.     #--------------------------------------------------------------------------
  32.     SOUND_TABLE = {
  33.     1 => ["Cursor2", 100, 100], # 嘟声
  34.     2 => ["Cursor2", 100, 150], # 尖细的声音
  35.     3 => ["Cursor2", 100, 50],  # 低沉的声音
  36.     60 => ["", 100, 100]        # 文件设置为空的时候表示无音效  
  37.     }
  38.     #--------------------------------------------------------------------------
  39.     # * 文字停顿设置
  40.     #--------------------------------------------------------------------------
  41.     # 遇到这些标点符号的时候停顿更久
  42.     PUNCS = ",.?!" + ",。?!—…~"
  43.  
  44.     # 普通字符的停顿时间
  45.     DEFAULT_CHAR_WAITING = 3      
  46.  
  47.     # 遇到标点符号的停顿时间
  48.     DEFAULT_PUNC_WAITING = 10  
  49.  
  50.     # 显示多少个字播放一次声效
  51.     CHARACTERS_FOR_SOUND = 3
  52.     #--------------------------------------------------------------------------
  53.     # * 第一行名字与声效的关联
  54.     #--------------------------------------------------------------------------
  55.     NAME_SOUNDS = {
  56.       "拉尔夫" => 3
  57.     }
  58.     #--------------------------------------------------------------------------
  59.     # * 脸图与声效的关联
  60.     #--------------------------------------------------------------------------
  61.     FACE_DEFAULT_SOUNDS = {
  62.       "Actor1" => 1  # 当脸图为Actor1,默认使用1号声音
  63.     }
  64.     FACE_PATTERN_SOUNDS = {
  65.       ["Actor1", 3] => 2,  # 当脸图为Actor1中编号3(第一行最后),使用2号声效
  66.       ["Actor1", 7] => 3,  # 当脸图为Actor1中编号7(第二行最后),使用3号声效
  67.     }
  68. #===============================================================================( e+ K- F5 k$ c4 ^6 W
  69. # 以上是配置部分
  70. #===============================================================================
  71.     @@effects = []
  72.  
  73.     def self.sound_path
  74.       "Audio/SE/"
  75.     end
  76.  
  77.     def self.set_effects(*args)
  78.       @@effects = args
  79.     end
  80.  
  81.     def self.reset
  82.       @@char_waiting = DEFAULT_CHAR_WAITING
  83.       @@punc_waiting = DEFAULT_PUNC_WAITING
  84.       @@volume_transition_speed = 0
  85.       @@volume_transition_total = 0
  86.       @@pitch_transition_speed = 0
  87.       @@pitch_transition_total = 0
  88.       @@wait_factor = 1.0
  89.       @@shaking = false
  90.       @@character_counter = -1
  91.       apply_effects
  92.     end
  93.  
  94.     def self.apply_effects
  95.       @@effects.each { |effect|
  96.         if /pitch_v\((.*)\)/ === effect
  97.           @@pitch_transition_total += effect[8..-2].to_f
  98.         end
  99.         if /pitch_t\((.*)\)/ === effect
  100.           @@pitch_transition_speed += effect[8..-2].to_f
  101.         end
  102.         if /volume_v\((.*)\)/ === effect
  103.           @@volume_transition_total += effect[9..-2].to_f
  104.         end
  105.         if /volume_t\((.*)\)/ === effect
  106.           @@volume_transition_speed += effect[9..-2].to_f
  107.         end
  108.         if /speed\((.*)\)/ === effect
  109.           @@wait_factor /= effect[6..-2].to_f
  110.         end
  111.         if /shake/ === effect
  112.           @@shaking = true
  113.         end
  114.       }
  115.       @@effects = []
  116.     end
  117.  
  118.     def self.get_character_wait(c)
  119.       if PUNCS.include?(c)
  120.         w = DEFAULT_PUNC_WAITING
  121.       else
  122.         w = DEFAULT_CHAR_WAITING
  123.       end
  124.       w *= @@wait_factor
  125.       w.to_i
  126.     end
  127.  
  128.     def self.play_sound_array(sound)
  129.       return unless $game_switches[ENABLE_SWITCH]
  130.       @@character_counter += 1
  131.       @@character_counter = 0 if @@character_counter == CHARACTERS_FOR_SOUND
  132.       return if @@character_counter != 0 && !@@shaking
  133.  
  134.       file = sound_path + sound[0]
  135.       volume = sound[1]
  136.       volume += @@volume_transition_total
  137.       @@volume_transition_total += @@volume_transition_speed
  138.       pitch = sound[2]
  139.       pitch += @@pitch_transition_total
  140.       @@pitch_transition_total += @@pitch_transition_speed
  141.       volume = 0 if volume < 0
  142.       Audio.se_play(file, volume, pitch) unless sound[0].empty?
  143.       shake_screen if @@shaking
  144.     end
  145.  
  146.     def self.shake_screen
  147.       $game_map.screen.start_shake(3, 10, 20)
  148.     end
  149.  
  150.     def self.play_default
  151.       play_sound_array(DEFAULT_SOUND)
  152.     end
  153.  
  154.     def self.play_index(i)
  155.       play_sound_array(SOUND_TABLE[i])
  156.     end
  157.  
  158.     def self.play_face(face_name, face_index)
  159.       pattern_key = [face_name, face_index]
  160.       if FACE_PATTERN_SOUNDS.has_key?(pattern_key)
  161.         play_index(FACE_PATTERN_SOUNDS[pattern_key])
  162.       elsif FACE_DEFAULT_SOUNDS.has_key?(face_name)
  163.         play_index(FACE_DEFAULT_SOUNDS[face_name])
  164.       else
  165.         play_default
  166.       end
  167.     end
  168.  
  169.     def self.play_name(name)
  170.       if NAME_SOUNDS.has_key?(name)
  171.         play_index(NAME_SOUNDS[name])
  172.       else
  173.         play_default
  174.       end
  175.     end
  176.   end
  177. end
  178.  
  179. class Game_Interpreter
  180.   def type_effects(*args)
  181.     Cirno::TypingSound.set_effects(*args)
  182.   end
  183. end
  184.  
  185. class Window_Message
  186.   alias cirno_20161212_clear_flags clear_flags
  187.   def clear_flags
  188.     cirno_20161212_clear_flags
  189.     @sound_index = 0
  190.     Cirno::TypingSound.reset
  191.   end
  192.  
  193.   alias cirno_20161212_process_escape_character process_escape_character
  194.   def process_escape_character(code, text, pos)
  195.     cirno_20161212_process_escape_character(code, text, pos)
  196.     case code.upcase
  197.     when 'S'
  198.       @sound_index = obtain_escape_param(text).to_i
  199.     end
  200.   end
  201.  
  202.   def play_typing_sound
  203.     if @sound_index == 0
  204.       if Cirno::TypingSound::FIRST_LINE_AS_CHARACTER
  205.         Cirno::TypingSound.play_name($game_message.texts[0])
  206.       else
  207.         Cirno::TypingSound.play_face($game_message.face_name, $game_message.face_index)
  208.       end
  209.     else
  210.       Cirno::TypingSound.play_index(@sound_index)
  211.     end
  212.   end
  213.  
  214.   alias cirno_20161212_process_normal_character process_normal_character
  215.   def process_normal_character(c, pos)
  216.     play_typing_sound
  217.     cirno_20161212_process_normal_character(c, pos)
  218.   end
  219.  
  220.   def process_character(c, text, pos)
  221.     @current_character = c
  222.     super(c, text, pos)
  223.   end
  224.  
  225.  
  226.   def wait_for_one_character
  227.     update_show_fast
  228.     unless @show_fast || @line_show_fast
  229.       if $game_switches[Cirno::TypingSound::ENABLE_SWITCH]
  230.         w = Cirno::TypingSound.get_character_wait(@current_character)
  231.         w.times { Fiber.yield }
  232.       else
  233.         Fiber.yield
  234.       end
  235.     end
  236.   end
  237. end


使用方法:

在 配置部分 中自定义声效种类、频率
使用 \S[编号] 在对话途中改变声效
使用 type_effects("效果1", "效果2", ...) 设置声效特殊效果
  ① 音量、声调的渐变
  ② 对话显示速度变化和震动效果


样例工程:

TypingEx.7z (1.3 MB, 下载次数: 110)

评分

参与人数 7星屑 +1231 收起 理由
咖喱卡卡 + 45 才看见,给⑨姐姐递糖
越前リョーマ + 66 万年不见的新脚本
浮云半仙 + 15 module cirno
zaiy2863 + 400 module cirno
Arfies + 30 塞糖
VIPArcher + 9 精品文章
迷糊的安安 + 666 好棒!

查看全部评分

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

本版积分规则

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

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

GMT+8, 2024-5-5 01:52

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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