Project1

标题: 全键盘密码锁脚本第一次必错怎么破? [打印本页]

作者: Forever火    时间: 2014-9-3 12:35
标题: 全键盘密码锁脚本第一次必错怎么破?
本帖最后由 Forever火 于 2014-9-4 16:12 编辑

RT,测试时第一次必错不知道为毛,按Z键进去必错,空格没事,求各位大大看看
RUBY 代码复制
  1. #===============================================================================
  2. # +++ MOG - Chain Commands (v1.4) +++
  3. #===============================================================================
  4. # By Moghunter
  5. # [url]http://www.atelier-rgss.com[/url]
  6. #===============================================================================
  7. # 拓展 By 火灰
  8. # (位于 [url]https://rpg.blue[/url])
  9. # 添加了全键盘的支持
  10. #===============================================================================
  11. # Sistema de sequência de botões para ativar switchs.
  12. #
  13. # Serão necessárias as seguintes imagens. (Graphics/System)
  14. #
  15. # Chain_Cursor.png
  16. # Chain_Command.png
  17. # Chain_Layout.png
  18. # Chain_Timer_Layout.png
  19. # Chain_Timer_Meter.png
  20. #
  21. #===============================================================================
  22. #
  23. # Para ativar o script use o comando abaixo.  (*Call Script)
  24. #
  25. # chain_commands(ID)
  26. #
  27. # ID - Id da switch.
  28. #
  29. #===============================================================================
  30. #==============================================================================
  31. # ● Histórico (Version History)
  32. #==============================================================================
  33. # v 1.4 - Correção do crash aleatório.
  34. # v 1.3 - Melhoria no sistema de dispose
  35. # v 1.2 - Melhoria na codificação e correção de alguns glitches.
  36. # v 1.1 - Animação de fade ao sair da cena de chain.
  37. #       - Opção de definir a prioridade da hud na tela.
  38. #==============================================================================
  39. module MOG_CHAIN_COMMANDS
  40.   #============================================================================
  41.   # CHAIN_COMMAND = { SWITCH_ID => [COMMAND] }
  42.   #
  43.   # SWITCH_ID = ID da switch
  44.   # COMMANDS = Defina aqui a sequência de botões.
  45.   #            (Para fazer a sequência use os comandos abaixo)
  46.   #
  47.   # "Down" ,"Up" ,"Left" ,"Right" ,"Shift" ,以及所有其他的英文字母键
  48.   #
  49.   # Exemplo de utilização
  50.   #
  51.   # CHAIN_SWITCH_COMMAND = {
  52.   # 25=>["Down","D","S","Right"],
  53.   # 59=>["Down","Up","Left","Right","Shift","D","S","A","Z","X","Q","W"],
  54.   # 80=>["Shift","D"]
  55.   # }
  56.   #============================================================================
  57.   CHAIN_SWITCH_COMMAND = {
  58.     1 => ["D","O","O","R"],
  59.     12 => ("A".."Z").to_a + %w{Shift Right Left Down Up},
  60.     5  => ["X","Right","Left","Z","Z"],
  61.     7  => ["X","X","X","X","X"],
  62.     6  => ["Left","Right","Left","Right","Left","Right","Q","Z","Up","A","S",
  63.            "Down","D","Z","Right","Up","Up","Z","W","Left","Down","D","A","W"],
  64.     8  => ["Up","Down","Left","Right","Z"],
  65.     9  => ["L","E","F","T"],
  66.     10 => ["R","I","G","H","T"]
  67.   }
  68.   #Duração para colocar os comandos. (A duração é multiplicado pela quantidade
  69.   #de comandos) *60 = 1 sec
  70.   #上面的连击链代表成功输入这些按键后会开启相应的开关
  71.   CHAIN_INPUT_DURATION = 80
  72.   #Som ao acertar.
  73.   CHAIN_RIGHT_SE = "Chime1"
  74.   #Som ao errar.
  75.   CHAIN_WRONG_SE = "Buzzer1"
  76.   #Switch que ativa o modo automático.
  77.   CHAIN_AUTOMATIC_MODE_SWITCH_ID = 20
  78.   #Definição da prioridade da hud na tela
  79.   CHAIN_HUD_Z = 300
  80.   KEYS = {}
  81.   ("A".."Z").each_with_index{|k, i| KEYS[k] = i + 0x41}
  82.   KEYS["SHIFT"] = 0x10; KEYS["LEFT"]  = 0x25; KEYS["RIGHT"] = 0x27
  83.   KEYS["DOWN"]  = 0x28; KEYS["UP"]    = 0x26
  84. end
  85. #===============================================================================
  86. # ■ Chain Commands
  87. #===============================================================================
  88. class Chain_Commands
  89.   include MOG_CHAIN_COMMANDS
  90.   #--------------------------------------------------------------------------
  91.   # ● Initialize
  92.   #--------------------------------------------------------------------------
  93.   def initialize
  94.     @action_id = $game_temp.chain_switch_id
  95.     @chain_command = CHAIN_SWITCH_COMMAND[@action_id]
  96.     @chain_command = ["?"] if @chain_command == nil
  97.     duration = [[CHAIN_INPUT_DURATION, 1].max, 9999].min
  98.     @timer_max = duration * @chain_command.size
  99.     @timer = @timer_max
  100.     @slide_time = [[60 / duration, 10].max, 60].min
  101.     @change_time = 0
  102.     @auto = $game_switches[CHAIN_AUTOMATIC_MODE_SWITCH_ID]
  103.     @com
  104.   end
  105.   #--------------------------------------------------------------------------
  106.   # ● Main
  107.   #--------------------------------------------------------------------------
  108.   def main
  109.     dispose
  110.     @background_sprite = Sprite.new
  111.     @background_sprite.bitmap = SceneManager.background_bitmap2
  112.     create_chain_command
  113.     create_cusrsor
  114.     create_layout
  115.     create_meter
  116.     create_text
  117.     create_number
  118.     Graphics.transition
  119.     loop do
  120.       Graphics.update
  121.       Input.update
  122.       update
  123.       break if SceneManager.scene != self
  124.     end
  125.     dispose
  126.   end
  127.   #--------------------------------------------------------------------------
  128.   # ● Create Cursor
  129.   #--------------------------------------------------------------------------
  130.   def create_cusrsor
  131.     @fy_time = 0
  132.     @fy = 0
  133.     @com_index = 0
  134.     @cursor = Sprite.new
  135.     @cursor.bitmap = Cache.system("Chain_Cursor")
  136.     @cursor.z = 4 + CHAIN_HUD_Z
  137.     @cursor_space = ((@bitmap_cw + 5) * @chain_command.size) / 2
  138.     if @chain_command.size <= 20
  139.       @cursor.x = (544 / 2) - @cursor_space + @cursor_space * @com_index
  140.     else
  141.       @cursor.x = (544 / 2)
  142.     end
  143.     @cursor.y = (416 / 2) + 30
  144.   end
  145.   #--------------------------------------------------------------------------
  146.   # ● Create Chain Command
  147.   #--------------------------------------------------------------------------
  148.   def create_chain_command
  149.     @image = Cache.system("Chain_Command")
  150.     width_max = ((@image.width / 32) + 5) * @chain_command.size
  151.     @bitmap = Bitmap.new(width_max,@image.height * 2)
  152.     @bitmap_cw = @image.width / 32
  153.     @bitmap_ch = @image.height
  154.     index = 0
  155.     for i in @chain_command
  156.       command_list_check(i)
  157.       bitmap_src_rect = Rect.new([url=home.php?mod=space&uid=10462]@Com[/url] * @bitmap_cw, 0, @bitmap_cw, @bitmap_ch)
  158.       if index == 0
  159.         @bitmap.blt(index * (@bitmap_cw + 5) , 0, @image, bitmap_src_rect)
  160.       else
  161.         @bitmap.blt(index * (@bitmap_cw + 5) , @bitmap_ch, @image,
  162.         bitmap_src_rect)
  163.       end
  164.       index += 1
  165.     end
  166.     @sprite = Sprite.new
  167.     @sprite.bitmap = @bitmap
  168.     if @chain_command.size <= 15
  169.       @sprite.x = (544 / 2) - ((@bitmap_cw + 5) * @chain_command.size) / 2
  170.       @new_x = 0
  171.     else
  172.       @sprite.x = (544 / 2)
  173.       @new_x = @sprite.x
  174.     end
  175.     @sprite.y = (416 / 2) + 30  - @bitmap_ch  - 15
  176.     @sprite.z = 3 + CHAIN_HUD_Z
  177.     @sprite.zoom_x = 1.5
  178.     @sprite.zoom_y = 1.5
  179.   end
  180.   #--------------------------------------------------------------------------
  181.   # * create_layout
  182.   #--------------------------------------------------------------------------
  183.   def create_layout
  184.     @back = Plane.new
  185.     @back.bitmap = Cache.system("Chain_Layout")
  186.     @back.z = 0
  187.     @layout = Sprite.new
  188.     @layout.bitmap = Cache.system("Chain_Timer_Layout")
  189.     @layout.z = 1 + CHAIN_HUD_Z
  190.     @layout.x = 160
  191.     @layout.y = 150
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # * create_meter
  195.   #--------------------------------------------------------------------------
  196.   def create_meter
  197.     @meter_flow = 0
  198.     @meter_image = Cache.system("Chain_Timer_Meter")
  199.     @meter_bitmap = Bitmap.new(@meter_image.width,@meter_image.height)
  200.     @meter_range = @meter_image.width / 3
  201.     @meter_width = @meter_range * @timer / @timer_max
  202.     @meter_height = @meter_image.height
  203.     @meter_src_rect = Rect.new(@meter_range, 0, @meter_width, @meter_height)
  204.     @meter_bitmap.blt(0,0, @meter_image, @meter_src_rect)
  205.     @meter_sprite = Sprite.new
  206.     @meter_sprite.bitmap = @meter_bitmap
  207.     @meter_sprite.z = 2 + CHAIN_HUD_Z
  208.     @meter_sprite.x = 220
  209.     @meter_sprite.y = 159
  210.     update_flow
  211.   end
  212.   #--------------------------------------------------------------------------
  213.   # ● Create Text
  214.   #--------------------------------------------------------------------------
  215.   def create_text
  216.     @text = Sprite.new
  217.     @text.bitmap = Bitmap.new(200,32)
  218.     @text.z = 2 + CHAIN_HUD_Z
  219.     @text.bitmap.font.name = "Georgia"
  220.     @text.bitmap.font.size = 25
  221.     @text.bitmap.font.bold = true
  222.     @text.bitmap.font.italic = true
  223.     @text.bitmap.font.color.set(255, 255, 255,220)
  224.     @text.x = 230
  225.     @text.y = 100
  226.   end
  227.   #--------------------------------------------------------------------------
  228.   # ● Create Number
  229.   #--------------------------------------------------------------------------
  230.   def create_number
  231.     @combo = 0
  232.     @number = Sprite.new
  233.     @number.bitmap = Bitmap.new(200,64)
  234.     @number.z = 2 + CHAIN_HUD_Z
  235.     @number.bitmap.font.name = "Arial"
  236.     @number.bitmap.font.size = 24
  237.     @number.bitmap.font.bold = true
  238.     @number.bitmap.font.color.set(0, 255, 255,200)
  239.     @number.bitmap.draw_text(0, 0, 200, 32, "Ready",1)
  240.     @number.x = 30
  241.     @number.y = 100
  242.   end
  243.   #--------------------------------------------------------------------------
  244.   # ● Pre Dispose
  245.   #--------------------------------------------------------------------------
  246.   def exit
  247.     loop do
  248.       Graphics.update
  249.       @sprite.x += 5
  250.       @layout.x -= 5
  251.       @meter_sprite.x -= 5
  252.       @text.x -= 2
  253.       @text.opacity -= 5
  254.       @sprite.opacity -= 5
  255.       @layout.opacity -= 5
  256.       @meter_sprite.opacity -= 5
  257.       @number.opacity -= 5
  258.       @back.opacity -= 5
  259.       @cursor.visible = false
  260.       break if @sprite.opacity == 0
  261.     end
  262.     SceneManager.call(Scene_Map)
  263.   end
  264.   #--------------------------------------------------------------------------
  265.   # ● Dispose
  266.   #--------------------------------------------------------------------------
  267.   def dispose
  268.     return if @layout == nil
  269.     Graphics.freeze
  270.     @background_sprite.bitmap.dispose
  271.     @background_sprite.dispose
  272.     @bitmap.dispose
  273.     @sprite.bitmap.dispose
  274.     @sprite.dispose
  275.     @cursor.bitmap.dispose
  276.     @cursor.dispose
  277.     @meter_image.dispose
  278.     @meter_bitmap.dispose
  279.     @meter_sprite.bitmap.dispose
  280.     @meter_sprite.dispose
  281.     @layout.bitmap.dispose
  282.     @layout.dispose
  283.     @layout = nil
  284.     @back.bitmap.dispose
  285.     @back.dispose
  286.     @text.bitmap.dispose
  287.     @text.dispose
  288.     @number.bitmap.dispose
  289.     @number.dispose
  290.     @image.dispose
  291.   end
  292.   #--------------------------------------------------------------------------
  293.   # ● Update
  294.   #--------------------------------------------------------------------------
  295.   def update
  296.     update_command
  297.     update_cursor_slide
  298.     update_flow
  299.     update_change_time
  300.   end
  301.   #--------------------------------------------------------------------------
  302.   # ● Change_Time
  303.   #--------------------------------------------------------------------------
  304.   def update_change_time
  305.     return unless @auto
  306.     @change_time += 1
  307.     check_command(-1) if @change_time >= CHAIN_INPUT_DURATION - 1
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # ● Update Flow
  311.   #--------------------------------------------------------------------------
  312.   def update_flow
  313.     @timer -= 1
  314.     @meter_sprite.bitmap.clear
  315.     @meter_width = @meter_range * @timer / @timer_max
  316.     @meter_src_rect = Rect.new(@meter_flow, 0, @meter_width, @meter_height)
  317.     @meter_bitmap.blt(0,0, @meter_image, @meter_src_rect)
  318.     @meter_flow += 20
  319.     @meter_flow = 0 if @meter_flow >= @meter_image.width - @meter_range
  320.     wrong_command if @timer == 0 and @auto == false
  321.   end
  322.   #--------------------------------------------------------------------------
  323.   # ● Update Command
  324.   #--------------------------------------------------------------------------
  325.   def update_command
  326.     return if @auto
  327.     KEYS.each{|key,value| check_command(key) if Kboard.trigger?(value)}
  328.   end
  329.   #--------------------------------------------------------------------------
  330.   # ● command_list_check
  331.   #--------------------------------------------------------------------------
  332.   def command_list_check(command)
  333.     command.upcase!
  334.     [url=home.php?mod=space&uid=10462]@Com[/url] = ("A".."Z").to_a.index(command)
  335.     @com ||= 26 + (_ = %w{SHIFT RIGHT LEFT DOWN UP}.index(command)) ? _ : 5
  336.   end
  337.   #--------------------------------------------------------------------------
  338.   # ● check_command
  339.   #--------------------------------------------------------------------------
  340.   def check_command(com)
  341.     index = 0
  342.     if com != -1
  343.       right_input = false
  344.       for i in @chain_command
  345.         if index == @com_index
  346.           right_input = true if @chain_command[index] == com
  347.         end
  348.         index += 1
  349.       end
  350.     else
  351.       @change_time = 0
  352.       right_input = true
  353.     end
  354.     if right_input
  355.       refresh_number
  356.       next_command
  357.     else
  358.       wrong_command
  359.     end
  360.   end
  361.   #--------------------------------------------------------------------------
  362.   # ● Next Command
  363.   #--------------------------------------------------------------------------
  364.   def next_command
  365.     @com_index += 1
  366.     Audio.se_play("Audio/SE/" + CHAIN_RIGHT_SE, 100, 100)
  367.     if @com_index == @chain_command.size
  368.       $game_switches[@action_id] = true
  369.       exit
  370.       $game_map.need_refresh = true
  371.     end
  372.     refresh_command
  373.     refresh_text(0)
  374.   end
  375.   #--------------------------------------------------------------------------
  376.   # ● wrong_command
  377.   #--------------------------------------------------------------------------
  378.   def wrong_command
  379.     Audio.se_play("Audio/SE/" + CHAIN_WRONG_SE, 100, 100)
  380.     refresh_text(1)
  381.     exit
  382.     $game_player.jump(0,0)
  383.   end
  384.   #--------------------------------------------------------------------------
  385.   # ● Refresh Command
  386.   #--------------------------------------------------------------------------
  387.   def refresh_command
  388.     @sprite.bitmap.clear
  389.     index = 0
  390.     for i in @chain_command
  391.       command_list_check(i)
  392.       bitmap_src_rect = Rect.new(@com * @bitmap_cw, 0, @bitmap_cw, @bitmap_ch)
  393.       if @com_index == index
  394.         @bitmap.blt(index * (@bitmap_cw + 5) , 0, @image, bitmap_src_rect)
  395.       else
  396.         @bitmap.blt(index * (@bitmap_cw + 5) , @bitmap_ch,
  397.         @image, bitmap_src_rect)
  398.       end
  399.       index += 1
  400.     end
  401.     if @chain_command.size > 15
  402.       @new_x = (544 / 2) - ((@bitmap_cw + 5) * @com_index)
  403.     else
  404.       @cursor.x = (544 / 2) - @cursor_space + ((@bitmap_cw + 5) * @com_index)
  405.     end
  406.   end
  407.   #--------------------------------------------------------------------------
  408.   # ● Refresh Text
  409.   #--------------------------------------------------------------------------
  410.   def refresh_text(type)
  411.     @text.bitmap.clear
  412.     if type == 0
  413.       if @com_index == @chain_command.size
  414.         @text.bitmap.font.color.set(55, 255, 55,220)
  415.         @text.bitmap.draw_text(0, 0, 200, 32, "Perfect!",1)
  416.       else
  417.         @text.bitmap.font.color.set(55, 155, 255,220)
  418.         @text.bitmap.draw_text(0, 0, 200, 32, "Success!",1)
  419.       end
  420.     else
  421.       @text.bitmap.font.color.set(255, 155, 55,220)
  422.       if @timer == 0
  423.         @text.bitmap.draw_text(0, 0, 200, 32, "Time Limit!",1)
  424.       else
  425.         @text.bitmap.draw_text(0, 0, 200, 32, "Fail!",1)
  426.       end
  427.     end
  428.     @text.x = 230
  429.     @text.opacity = 255
  430.   end
  431.   #--------------------------------------------------------------------------
  432.   # ● Refresh Number
  433.   #--------------------------------------------------------------------------
  434.   def refresh_number
  435.     @combo += 1
  436.     @number.bitmap.clear
  437.     @number.bitmap.font.size = 34
  438.     @number.bitmap.draw_text(0, 0, 200, 32, @combo.to_s,1)
  439.     @number.opacity = 255
  440.     @number.zoom_x = 2
  441.     @number.zoom_y = 2
  442.   end
  443.   #--------------------------------------------------------------------------
  444.   # ● Update Cursor Slide
  445.   #--------------------------------------------------------------------------
  446.   def update_cursor_slide
  447.     @sprite.zoom_x -= 0.1 if @sprite.zoom_x > 1
  448.     @sprite.zoom_y -= 0.1 if @sprite.zoom_y > 1
  449.     @text.x -= 2 if @text.x > 210
  450.     @text.opacity -= 5 if @text.opacity > 0
  451.     @sprite.x -= @slide_time if @sprite.x > @new_x and @chain_command.size > 15
  452.     if @number.zoom_x > 1
  453.       @number.zoom_x -= 0.1
  454.       @number.zoom_y -= 0.1
  455.     end
  456.     if @fy_time > 15
  457.       @fy += 1
  458.     elsif @fy_time > 0
  459.       @fy -= 1
  460.     else
  461.       @fy = 0
  462.       @fy_time = 30
  463.     end
  464.     @fy_time -= 1
  465.     @cursor.oy = @fy
  466.   end
  467. end
  468. #==============================================================================
  469. # ■ Game Temp
  470. #==============================================================================
  471. class Game_Temp
  472.   attr_accessor :chain_switch_id
  473.   #--------------------------------------------------------------------------
  474.   # ● Initialize
  475.   #--------------------------------------------------------------------------
  476.   alias mog_chain_commands_initialize initialize
  477.   def initialize
  478.     @chain_switch_id = 0
  479.     mog_chain_commands_initialize
  480.   end
  481. end
  482. #==============================================================================
  483. # ■ Game_Interpreter
  484. #==============================================================================
  485. class Game_Interpreter
  486.   #--------------------------------------------------------------------------
  487.   # ● Chain Commands
  488.   #--------------------------------------------------------------------------
  489.   def chain_commands(switch_id = 0)
  490.     return if switch_id <= 0
  491.     $game_temp.chain_switch_id = switch_id
  492.     SceneManager.call(Chain_Commands)
  493.     wait(1)
  494.   end
  495. end
  496. #===============================================================================
  497. # ■ SceneManager
  498. #===============================================================================
  499. class << SceneManager
  500.   @background_bitmap2 = nil
  501.   #--------------------------------------------------------------------------
  502.   # ● Snapshot For Background2
  503.   #--------------------------------------------------------------------------
  504.   def snapshot_for_background2
  505.     @background_bitmap2.dispose if @background_bitmap2
  506.     @background_bitmap2 = Graphics.snap_to_bitmap
  507.   end
  508.   #--------------------------------------------------------------------------
  509.   # ● Background Bitmap2
  510.   #--------------------------------------------------------------------------
  511.   def background_bitmap2
  512.     @background_bitmap2
  513.   end
  514. end
  515. #===============================================================================
  516. # ■ Scene Map
  517. #===============================================================================
  518. class Scene_Map < Scene_Base
  519.   #--------------------------------------------------------------------------
  520.   # ● Terminate
  521.   #--------------------------------------------------------------------------
  522.   alias mog_chain_commands_terminate terminate
  523.   def terminate
  524.     SceneManager.snapshot_for_background2
  525.     mog_chain_commands_terminate
  526.   end
  527. end
  528. $mog_rgss3_chain_commands = true
  529. #============================================================================
  530. # ■ Keyboard Script
  531. #----------------------------------------------------------------------------
  532. #    By: 灼眼的夏娜
  533. #  整理: 火灰
  534. #----------------------------------------------------------------------------
  535. # 本脚本来自 rm.66RPG.com,使用和转载请保留此信息
  536. #==============================================================================
  537. module Kboard
  538.   module_function
  539.   @R_Key_Hash = {}
  540.   @R_Key_Repeat = {}
  541.   GetKeyState = Win32API.new("user32","GetAsyncKeyState",['I'],'I')
  542.   def press?(rkey)
  543.     return GetKeyState.call(rkey) != 0
  544.   end
  545.   def repeat?(rkey)
  546.     result = GetKeyState.call(rkey)
  547.     if result != 0
  548.       if @R_Key_Repeat[rkey].nil?
  549.         @R_Key_Repeat[rkey] = 0
  550.         return true
  551.       end
  552.       @R_Key_Repeat[rkey] += 1
  553.     else
  554.       @R_Key_Repeat[rkey] = nil
  555.       @R_Key_Hash[rkey] = 0
  556.     end
  557.     if !@R_Key_Repeat[rkey].nil? and @R_Key_Repeat[rkey] > 4
  558.       @R_Key_Repeat[rkey] = 0
  559.       return true
  560.     else
  561.       return false
  562.     end
  563.   end
  564.   def trigger?(rkey)
  565.     result = GetKeyState.call(rkey)
  566.     if @R_Key_Hash[rkey] == 1 and result != 0
  567.       return false
  568.     end
  569.     if result != 0
  570.       @R_Key_Hash[rkey] = 1
  571.       return true
  572.     else
  573.       @R_Key_Hash[rkey] = 0
  574.       return false
  575.     end
  576.   end
  577. end


  

Project6.zip

1.52 MB, 下载次数: 103

范例


作者: Forever火    时间: 2014-9-3 17:57
下载12次怎么没人吱声?
作者: Forever火    时间: 2014-9-3 19:21
@VIPArcher  余烬说要是报bug了就靠你了




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1