neonblack

QTE Minigame Set v1.0b

Aug 22nd, 2013
134
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##-----------------------------------------------------------------------------
  2. ## QTE Minigames v1.0b
  3. ## Created by Neon Black
  4. ##
  5. ## For both commercial and non-commercial use as long as credit is given to
  6. ## Neon Black and any additional authors.  Licensed under Creative Commons
  7. ## CC BY 3.0 - http://creativecommons.org/licenses/by/3.0/.
  8. ##----------------------------------------------------------------------------##
  9.                                                                               ##
  10. ##----------------------------------------------------------------------------##
  11. ##    Revision Info:
  12. ## v1.0b - 8.22.2013
  13. ##  Small updates to options
  14. ## v1.0 - 8.18.2013
  15. ##  Wrote and debugged main script
  16. ##----------------------------------------------------------------------------##
  17.                                                                               ##
  18. $imported ||= {}                                                              ##
  19. $imported["QTE_Minigames"] = 1.0                                              ##
  20.                                                                               ##
  21. ##----------------------------------------------------------------------------##
  22. ##    Instructions:
  23. ## Place this script in the script editor below "Materials" and above "Main".
  24. ## This script adds 4 minigames that can be played by typing out a simple
  25. ## script call.  Each of the 4 script calls has 3 options that can be changed
  26. ## to make the game harder or easier.
  27. ##
  28. ##------
  29. ## MashQTE.play  -or-  MashQTE.play(presses, time, button)
  30. ##  - Play a button mashing minigame.  This minigame requires the player to
  31. ##    press a single button as fast as they can to satisfy a number of button
  32. ##    presses before time runs out.  The 3 options are as follows:
  33. ##
  34. ##    presses - The number of times the button must be pressed before the
  35. ##              minigame is won.
  36. ##    time - The amount of time, in frames, that the player has to finish the
  37. ##           minigame.  60 frames = 1 second.
  38. ##    button - The button the player must press for the minigame.  Examples of
  39. ##             valid buttons include :C, :X, :LEFT, etc.
  40. ##
  41. ## Examples:
  42. ##    MashQTE.play(15, 120, :A)
  43. ##    MashQTE.play(50)
  44. ##
  45. ##------
  46. ## TriggerQTE.play  -or-  TriggerQTE.play(match, time)
  47. ##  - Play a button matching minigame.  The player must match all buttons as
  48. ##    quickly as possible to win the minigame.  There are two options as
  49. ##    follows:
  50. ##
  51. ##    match - The number of buttons the player must match.  The pattern is
  52. ##            randomly generated.
  53. ##    time - The amount of time, in frames, the player has to match the
  54. ##           pattern.  60 frames = 1 second.
  55. ##
  56. ## Examples:
  57. ##    TriggerQTE.play(6, 180)
  58. ##    TriggerQTE.play(4)
  59. ##
  60. ##------
  61. ## MatchQTE.play  -or-  MatchQTE.play(match, time)
  62. ##  - Play a minigame where the player must press each button as the indicator
  63. ##    hovers over it.  The player is given a short period of time before the
  64. ##    game starts and then must press the pattern as the indicator hovers over
  65. ##    each part of the pattern.  This is similar to the Trigger minigame.
  66. ##    There are 2 options as follows:
  67. ##
  68. ##    match - The number of buttons the player must match.
  69. ##    time - The time in frames to complete the minigame.
  70. ##
  71. ## Examples:
  72. ##    MatchQTE.play(8, 330)
  73. ##    MatchQTE.play(5)
  74. ##
  75. ##------
  76. ## TargetQTE.play  -or-  TargetQTE.play(zoom, time, speed)
  77. ##  - Play a minigame where the player must press a button when the indicator
  78. ##    is in a certain target region.  The indicator will scroll back and forth
  79. ##    until time runs out or the player wins the minigame.  There are 3 options
  80. ##    as follows:
  81. ##
  82. ##    zoom - The zoom of the bar.  As a general rule of thumb the minimum value
  83. ##           for this should be 1.0.  Making this value higher will cause the
  84. ##           target area to be larger.
  85. ##    time - The time in frames to win the minigame.
  86. ##    speed - The amount of pixels the indicator moves every frame.  Higher
  87. ##            numbers move faster and as such are harder to win.
  88. ##
  89. ## Examples:
  90. ##    TargetQTE.play(1.5, 90, 7)
  91. ##    TargetQTE.play(1.0, 150)
  92. ##----------------------------------------------------------------------------##
  93.                                                                               ##
  94. module CPMinigame ## Do not touch this line                                   ##
  95. ##----------------------------------------------------------------------------##
  96. ##    Config:
  97. ## The config options are below.  You can set these depending on the flavour of
  98. ## your game.  Each option is explained in a bit more detail above it.
  99. ##
  100. ##------
  101. #     Common Settings:
  102. #
  103. # Choose if you would like the background blurred and if you would like the
  104. # background dimmed.
  105. BlurBack = true
  106. DimBack  = true
  107.  
  108. # The color to dim the background to if a dimming background is enabled.
  109. # [Red, Green, Blue, Opacity]
  110. DimSetting = [16, 16, 16, 128]
  111.  
  112. # This is the switch used to indicate if the minigame was won or lost.  The
  113. # switch will turn on when the game is won and off when the game is lost.
  114. GameSwitch = 41
  115.  
  116. # This is the variable that stores the number of correct button presses made
  117. # during a minigame.  This can be used to reward the player for partial
  118. # completion of the minigame or anything else you can think to use it for.
  119. GameVariable = 41
  120.  
  121. # This is the background color for all bars used in the minigames.  Remember
  122. # that colors use [Red, Green, Blue, Opacity].
  123. BarBackColor = [0, 0, 0, 64]
  124.  
  125. #------
  126. #     Mash Button Minigame Settings:
  127. #
  128. # This is the background image for the minigame.
  129. ButtonImages = "MiniGameButtons"
  130.  
  131. # These are the default presses, time, and button for the minigame.  See the
  132. # instructions section of this minigame for further explaination.
  133. DefMPresses = 20
  134. DefMTime    = 240
  135. DefMButton  = :C
  136.  
  137. # These are the graphics used by the minigame.  The first is the background
  138. # image and the second is a foreground image.  They are layered on top of each
  139. # other.
  140. MBackImage = "MenuBackItem"
  141. MashImage  = "MiniGameMashText"
  142.  
  143. # These settings are for the button that appears to the left of the minigame
  144. # HUD.  Offset is the X offset in pixels of the tap icon over the button icon.
  145. MashOffset = 10
  146. ButtonZoom = 2.0
  147.  
  148. # This is the color of the bar that fills up as the player taps the button.
  149. # [Red, Green, Blue, Opacity]
  150. MashBarColor = [128, 197, 118]
  151.  
  152. # These are the success and failure sound effects for the minigame.
  153. # ["Filename", Volume, Pitch]
  154. MashSuccess  = ["Chime2", 80, 115]
  155. MashFailure  = ["Stare", 80, 95]
  156.  
  157. #------
  158. #     Trigger Minigame Settings:
  159. #
  160. # These are the default settings of the minigame.  See instructions above for
  161. # further explaination.
  162. DefTMatch   = 5
  163. DefTTime    = 150
  164.  
  165. # These are the buttons that can be mixed into the pattern.  Allowed buttons
  166. # include :A, :B, :C, :X, :Y, :Z, :LEFT, :RIGHT, :UP, and :DOWN.
  167. DefTButtons = [:LEFT, :RIGHT, :UP, :DOWN]
  168.  
  169. # This is the image used for the background.  It is stretched to fit the time
  170. # and buttons.
  171. TBackImage = "MenuBackItem"
  172.  
  173. # This is the color of the bar for the time of the minigame.
  174. # [Red, Green, Blue, Opacity]
  175. TriggerBarColor   = [245, 198, 75]
  176.  
  177. # These are the sound effects used by the minigame.  ButtonGood and ButtonBad
  178. # are used to indicate if the player has pressed a matching button or not.
  179. # ["Filename", Volume, Pitch]
  180. TriggerButtonGood = ["Switch1", 70, 130]
  181. TriggerButtonBad  = ["Cancel1", 75, 85]
  182. TriggerSuccess    = ["Chime2", 80, 115]
  183. TriggerFailure    = ["Stare", 80, 95]
  184.  
  185. # This setting determines what happens when an incorrect button is pressed.
  186. # This can be one of 3 values.
  187. # 1 = Do nothing.
  188. # 2 = Restart minigame.
  189. # 3 = Fail the minigame.
  190. # 4 = Custom.  Meant for scripters.  Search for "##~Bookmark1" to edit.
  191. TriggerWrong = 3
  192.  
  193. #------
  194. #     Matching Minigame Settings:
  195. #
  196. # These are the default settings of the minigame.  See instructions above for
  197. # further explaination.
  198. DefSMatch   = 4
  199. DefSTime    = 204
  200.  
  201. # These are the buttons that can be mixed into the pattern.  Allowed buttons
  202. # include :A, :B, :C, :X, :Y, :Z, :LEFT, :RIGHT, :UP, and :DOWN.
  203. DefSButtons = [:LEFT, :RIGHT, :UP, :DOWN]
  204.  
  205. # This is the image to be used as the menu back.  It is stretched to fit all
  206. # the buttons to be pressed.
  207. SBackImage     = "MenuBackItem"
  208.  
  209. # This value is the X offset of the pointer that appears above the button to be
  210. # pressed.
  211. SPointerOffset = 0
  212.  
  213. # This is the color of the bar for the time of the minigame.
  214. # [Red, Green, Blue, Opacity]
  215. MatchBarColor   = [192, 15, 45]
  216.  
  217. # These are the sound effects used by the minigame.  ButtonGood and ButtonBad
  218. # are used to indicate if the player has pressed a matching button or not.
  219. # ["Filename", Volume, Pitch]
  220. MatchButtonGood = ["Switch1", 70, 130]
  221. MatchButtonBad  = ["Cancel1", 75, 85]
  222. MatchSuccess    = ["Chime2", 80, 115]
  223. MatchFailure    = ["Stare", 80, 95]
  224.  
  225. # This settings determines what happens when an incorrect button is pressed.
  226. # This can be one of 3 values.
  227. # 1 = Do nothing.
  228. # 2 = Mark the button wrong.
  229. # 3 = Fail the minigame.
  230. # 4 = Custom.  Meant for scripters.  Search for "##~Bookmark3" to edit.
  231. MatchWrong = 3
  232.  
  233. #------
  234. #     Target Minigame Settings:
  235. #
  236. # These are the default settings of the minigame.  See instructions above for
  237. # futher explaination.
  238. DefXZoom  = 1.5
  239. DefXTime  = 120
  240. DefXSpeed = 7
  241.  
  242. # These are the main images used by the script.  The back image holds the text
  243. # and counter, the bar image is the target bar.
  244. XBackImage   = "MenuBackItem"
  245. XBarImage    = "MiniGameTarget"
  246. TargetImage  = "MiniGameTargetText"
  247. TargetSlider = "MiniGameTargetSlider"
  248.  
  249. # The Y offset of the slider.
  250. SliderOffset = 4
  251.  
  252. # The button that must be pressed for the minigame.
  253. TargetButton = :C
  254.  
  255. # The area of the bar that can be used to win the minigame.  This value must
  256. # be a decimal.  A value of 1.0 would be the entire bar while 0.0 would be none
  257. # of the bar.  If the target area is 20% of the bar, the value you put here
  258. # would be 0.2.
  259. TargetArea   = 0.15
  260.  
  261. # The sound effects used by the minigame.
  262. # ["Filename", Volume, Pitch]
  263. TargetButtonBad = ["Cancel2", 85, 125]
  264. TargetSuccess   = ["Chime2", 80, 115]
  265. TargetFailure   = ["Stare", 80, 95]
  266.  
  267. # This setting determines what happens when an incorrect button is pressed.
  268. # This can be one of 3 values.
  269. # 1 = Restart minigame.
  270. # 2 = Fail minigame.
  271. # 3 = Custom.  Meant for scripters.  Search for "##~Bookmark2" to edit.
  272. TargetWrong = 2
  273. ##----------------------------------------------------------------------------##
  274.                                                                               ##
  275.                                                                               ##
  276. ##----------------------------------------------------------------------------##
  277. ## The following lines are the actual core code of the script.  While you are
  278. ## certainly invited to look, modifying it may result in undesirable results.
  279. ## Modify at your own risk!
  280. ###----------------------------------------------------------------------------
  281.  
  282.  
  283. end
  284.  
  285. ## The common class for all minigames.  All other games are built off this.
  286. class Scene_CPMinigame < Scene_Base
  287.   include CPMinigame  ## Include the above module in this class.
  288.  
  289.   ButtonIndex ={ ## A hash containing the spritesheet setup.
  290.     :UPLEFT => 0, :UP => 1, :UPRIGHT => 2, :L => 3, :R => 4, :ARROW => 5,
  291.     :TAP => 6, :LEFT => 7, :CENTER => 8, :RIGHT => 9, :X => 10, :Y => 11,
  292.     :Z => 12, :GOOD => 13, :DOWNLEFT => 14, :DOWN => 15, :DOWNRIGHT => 16,
  293.     :A => 17, :B => 18, :C => 19, :BAD => 20}
  294.  
  295.   @@background_image = nil
  296.  
  297.   def self.get_background_image ## Gets a custom background image.
  298.     @@background_image = Graphics.snap_to_bitmap
  299.     @@background_image.blur if BlurBack
  300.   end
  301.  
  302.   def start
  303.     super  ## The basic common start and post stats with a wait command.
  304.     create_background
  305.     create_game_sprites
  306.   end
  307.  
  308.   def post_start
  309.     super
  310.     wait(5)
  311.   end
  312.  
  313.   def terminate
  314.     super  ## The basic terminate which auto disposes for me.
  315.     dispose_background
  316.     dispose_game_sprites
  317.   end
  318.  
  319.   def create_background  ## Background create and dispose.
  320.     @background_sprite = Sprite.new
  321.     @background_sprite.bitmap = @@background_image
  322.     @background_sprite.color.set(*DimSetting) if DimBack
  323.   end
  324.  
  325.   def dispose_background
  326.     @background_sprite.dispose
  327.   end
  328.  
  329.   ## Gets a button image from the spritesheet and returns a bitmap with only
  330.   ## the selected image on it.  Used by all minigames except the slider.
  331.   def get_button_image(button)
  332.     button_bitmap = Cache.system(ButtonImages)
  333.     bitmap = Bitmap.new(button_bitmap.width / 7, button_bitmap.height / 3)
  334.     return bitmap unless ButtonIndex.include?(button)
  335.     index = ButtonIndex[button]
  336.     rect = Rect.new(index % 7 * bitmap.width, index / 7 * bitmap.height,
  337.                     bitmap.width, bitmap.height)
  338.     bitmap.blt(0, 0, button_bitmap, rect)
  339.     return bitmap
  340.   end
  341.  
  342.   ## Success and failure main methods.  These set the switch and wait after the
  343.   ## game has been won before sending the player to the previous scene.
  344.   def minigame_success
  345.     set_complete_variable
  346.     $game_switches[GameSwitch] = true
  347.     wait(40)
  348.     return_scene
  349.   end
  350.  
  351.   def minigame_failure
  352.     set_complete_variable
  353.     $game_switches[GameSwitch] = false
  354.     wait(40)
  355.     return_scene
  356.   end
  357.  
  358.   def set_complete_variable
  359.   end
  360.  
  361.   def wait(duration = 20)  ## An added wait command to allow me to pause things.
  362.     duration.times { update_basic }
  363.   end
  364. end
  365.  
  366. ##------
  367. ## Button Mash Minigame
  368. ##------
  369. class MashQTE < Scene_CPMinigame
  370.   @@prepared_valuesM = []
  371.  
  372.   ## Sets up the first bits of the game before starting it.  Same in all
  373.   ## 4 minigames.
  374.   def self.play(presses = DefMPresses, time = DefMTime, button = DefMButton)
  375.     get_background_image
  376.     @@prepared_valuesM = [presses, time, button]
  377.     SceneManager.call(MashQTE)
  378.     Fiber.yield
  379.   end
  380.  
  381.   ## Minigame creation process.
  382.   def create_game_sprites
  383.     create_back_sprite
  384.     create_tap_bar
  385.     create_button_sprite
  386.     create_tap_sprite
  387.     create_number_sprites
  388.   end
  389.  
  390.   def create_back_sprite
  391.     @menu_back = Sprite.new(@viewport)
  392.     bit1 = Cache.system(MBackImage)
  393.     bit2 = Cache.system(MashImage)
  394.     wd, ht = bit1.width, [bit1.height, bit2.height].max
  395.     @menu_back.bitmap = Bitmap.new(wd, ht)
  396.     @menu_back.ox, @menu_back.oy = @menu_back.width / 2, @menu_back.height / 2
  397.     @menu_back.x, @menu_back.y = Graphics.width / 2, Graphics.height / 2 - 4
  398.     @menu_back.bitmap.blt(0, (ht - bit1.height) / 2, bit1, bit1.rect)
  399.     @menu_back.bitmap.blt(0, (ht - bit2.height) / 2, bit2, bit2.rect)
  400.   end
  401.  
  402.   def create_tap_bar
  403.     @tap_bar = Sprite.new(@viewport)
  404.     @tap_bar.bitmap = Bitmap.new(@menu_back.width, @menu_back.height + 8)
  405.     @tap_bar.ox, @tap_bar.oy = @menu_back.ox, @menu_back.oy
  406.     @tap_bar.x, @tap_bar.y = @menu_back.x, @menu_back.y
  407.     @tapped_times = [0, 0, @@prepared_valuesM[0]]
  408.     c3 = Color.new(*BarBackColor)
  409.     @tap_bar.bitmap.fill_rect(0, @tap_bar.height - 8, @tap_bar.width, 8, c3)
  410.   end
  411.  
  412.   def create_button_sprite
  413.     z = ButtonZoom
  414.     @button_sprite = Sprite.new(@viewport)
  415.     @button_sprite.bitmap = get_button_image(@@prepared_valuesM[2])
  416.     @button_sprite.ox = @button_sprite.width / 2
  417.     @button_sprite.oy = @button_sprite.height / 2
  418.     @button_sprite.x = @menu_back.x - @menu_back.ox - (@button_sprite.ox * z)
  419.     @button_sprite.y = @menu_back.y + 4
  420.     @button_sprite.zoom_x = @button_sprite.zoom_y = z
  421.   end
  422.  
  423.   def create_tap_sprite
  424.     @tap_sprite = Sprite.new(@viewport)
  425.     @tap_sprite.bitmap = get_button_image(:TAP)
  426.     @tap_sprite.ox = @tap_sprite.width / 2
  427.     @tap_sprite.oy = @tap_sprite.height
  428.     @tap_sprite.x = @button_sprite.x + MashOffset
  429.     z = ButtonZoom
  430.     @tap_sprite.zoom_x = @tap_sprite.zoom_y = z
  431.     @tap_sprite.y = @button_sprite.y - 8 * @tap_sprite.zoom_x
  432.     @tap_sprite.z = 50
  433.     @tap_counter = 0
  434.   end
  435.  
  436.   def create_number_sprites
  437.     @number_sprite = Sprite.new(@viewport)
  438.     @number_sprite.bitmap = Bitmap.new(@menu_back.width, @menu_back.height)
  439.     @number_sprite.ox, @number_sprite.oy = @menu_back.ox, @menu_back.oy
  440.     @number_sprite.x, @number_sprite.y = @menu_back.x, @menu_back.y
  441.     @timer_value = @@prepared_valuesM[1]
  442.     value = ((@timer_value + 5) / 6).to_f / 10
  443.     @number_sprite.bitmap.draw_text(@number_sprite.bitmap.rect, "#{value} ", 2)
  444.   end
  445.  
  446.   def update
  447.     super  ## Main gameplay process.  Nothing too interesting from here on.
  448.     update_tap_sprite
  449.     update_timer_sprite
  450.     update_tap_count
  451.   end
  452.  
  453.   def update_tap_sprite
  454.     @tap_counter += 1
  455.     if @tap_counter % 32 == 0
  456.       @tap_sprite.y = @button_sprite.y - 8 * @tap_sprite.zoom_x
  457.     elsif (@tap_counter + 16) % 32 == 0
  458.       @tap_sprite.y = @button_sprite.y
  459.     end
  460.   end
  461.  
  462.   def update_timer_sprite
  463.     @timer_value -= 1
  464.     value = ((@timer_value + 5) / 6).to_f / 10
  465.     @number_sprite.bitmap.clear
  466.     @number_sprite.bitmap.draw_text(@number_sprite.bitmap.rect, "#{value} ", 2)
  467.     return minigame_failure if value <= 0.0
  468.   end
  469.  
  470.   def update_tap_count
  471.     if Input.trigger?(@@prepared_valuesM[2])
  472.       @tapped_times[1] += 1
  473.     end
  474.     if @tapped_times[0] != @tapped_times[1]
  475.       @tapped_times[0] = @tapped_times[1]
  476.       @tap_bar.bitmap.clear
  477.       c1 = Color.new(*MashBarColor)
  478.       w = (@tap_bar.width - 2) * (@tapped_times[1].to_f / @tapped_times[2])
  479.       c3 = Color.new(*BarBackColor)
  480.       @tap_bar.bitmap.fill_rect(0, @tap_bar.height - 8, @tap_bar.width, 8, c3)
  481.       @tap_bar.bitmap.fill_rect(1, @tap_bar.height - 7, w, 6, c1)
  482.     end
  483.     if @tapped_times[1] >= @tapped_times[2]
  484.       minigame_success
  485.     end
  486.   end
  487.  
  488.   def dispose_game_sprites
  489.     @menu_back.dispose
  490.     @tap_bar.dispose
  491.     @button_sprite.dispose
  492.     @tap_sprite.dispose
  493.     @number_sprite.dispose
  494.   end
  495.  
  496.   def minigame_success
  497.     RPG::SE.new(*MashSuccess).play
  498.     super
  499.   end
  500.  
  501.   def minigame_failure
  502.     RPG::SE.new(*MashFailure).play
  503.     super
  504.   end
  505.  
  506.   def set_complete_variable
  507.     super
  508.     $game_variables[GameVariable] = @tapped_times[1]
  509.   end
  510. end
  511.  
  512. ##------
  513. ## Trigger Button Minigame.
  514. ##------
  515. class TriggerQTE < Scene_CPMinigame
  516.   @@prepared_valuesT = []
  517.  
  518.   def self.play(match = DefTMatch, time = DefTTime, buttons = DefTButtons)
  519.     get_background_image
  520.     @@prepared_valuesT = [match, time, buttons]
  521.     SceneManager.call(TriggerQTE)
  522.     Fiber.yield
  523.   end
  524.  
  525.   def create_game_sprites
  526.     create_qte_pattern
  527.     create_menu_sprite
  528.     create_menu_top
  529.     create_time_bar
  530.     create_number_sprites
  531.   end
  532.  
  533.   def create_menu_sprite
  534.     temp = get_button_image(:A)
  535.     wd = temp.width * (@pattern.size + 2)
  536.     bit0 = Cache.system(TBackImage)
  537.     @menu_back = Sprite.new(@viewport)
  538.     @menu_back.bitmap = Bitmap.new(wd, [bit0.height, temp.height].max)
  539.     rect = Rect.new(0, (@menu_back.height - bit0.height) / 2, wd, bit0.height)
  540.     @menu_back.bitmap.stretch_blt(rect, bit0, bit0.rect)
  541.     @top_edge = (@menu_back.height - temp.height) / 2
  542.     @pattern.each_with_index do |s,i|
  543.       bit = get_button_image(s)
  544.       @menu_back.bitmap.blt(bit.width * i, @top_edge, bit, bit.rect)
  545.     end
  546.     @menu_back.ox, @menu_back.oy = @menu_back.width / 2, @menu_back.height / 2
  547.     @menu_back.x, @menu_back.y = Graphics.width / 2, Graphics.height / 2 - 4
  548.   end
  549.  
  550.   def create_menu_top
  551.     @correct = 0
  552.     @menu_top = Sprite.new(@viewport)
  553.     @menu_top.bitmap = Bitmap.new(@menu_back.width, @menu_back.height)
  554.     @menu_top.z = 50
  555.     @menu_top.ox, @menu_top.oy = @menu_back.ox, @menu_back.oy
  556.     @menu_top.x, @menu_top.y = @menu_back.x, @menu_back.y
  557.   end
  558.  
  559.   def create_time_bar
  560.     @time_bar = Sprite.new(@viewport)
  561.     @time_bar.bitmap = Bitmap.new(@menu_back.width, @menu_back.height + 8)
  562.     @time_bar.ox, @time_bar.oy = @menu_back.ox, @menu_back.oy
  563.     @time_bar.x, @time_bar.y = @menu_back.x, @menu_back.y
  564.     c3 = Color.new(*BarBackColor)
  565.     @time_bar.bitmap.fill_rect(0, @time_bar.height - 8, @time_bar.width, 8, c3)
  566.     c1 = Color.new(*TriggerBarColor)
  567.     @time_bar.bitmap.fill_rect(1, @time_bar.height - 7, @time_bar.width, 6, c1)
  568.   end
  569.  
  570.   def create_number_sprites
  571.     @number_sprite = Sprite.new(@viewport)
  572.     @number_sprite.bitmap = Bitmap.new(@menu_back.width, @menu_back.height)
  573.     @number_sprite.ox, @number_sprite.oy = @menu_back.ox, @menu_back.oy
  574.     @number_sprite.x, @number_sprite.y = @menu_back.x, @menu_back.y
  575.     @timer_value = @@prepared_valuesT[1]
  576.     value = ((@timer_value + 5) / 6).to_f / 10
  577.     @number_sprite.bitmap.draw_text(@number_sprite.bitmap.rect, "#{value} ", 2)
  578.     @number_sprite.bitmap.draw_text(@number_sprite.bitmap.rect, "#{value} ", 2)
  579.   end
  580.  
  581.   def create_qte_pattern
  582.     @pattern = []
  583.     @@prepared_valuesT[0].times do
  584.       @pattern.push(@@prepared_valuesT[2][rand(@@prepared_valuesT[2].size)])
  585.     end
  586.   end
  587.  
  588.   def update
  589.     super
  590.     update_timer_sprite
  591.     update_trigger_count
  592.   end
  593.  
  594.   def update_timer_sprite
  595.     @timer_value -= 1
  596.     value = ((@timer_value + 5) / 6).to_f / 10
  597.     @number_sprite.bitmap.clear
  598.     @number_sprite.bitmap.draw_text(@number_sprite.bitmap.rect, "#{value} ", 2)
  599.     w = (@time_bar.width - 2) * (@timer_value.to_f / @@prepared_valuesT[1])
  600.     c1 = Color.new(*TriggerBarColor)
  601.     c3 = Color.new(*BarBackColor)
  602.     @time_bar.bitmap.fill_rect(0, @time_bar.height - 8, @time_bar.width, 8, c3)
  603.     @time_bar.bitmap.fill_rect(1, @time_bar.height - 7, w, 6, c1)
  604.     return minigame_failure if value <= 0.0
  605.   end
  606.  
  607.   def update_trigger_count
  608.     full = [:LEFT, :RIGHT, :UP, :DOWN, :A, :B, :C, :X, :Y, :Z, :L, :R]
  609.     full.each do |s|
  610.       if Input.trigger?(s)
  611.         if s == @pattern[@correct]
  612.           on_trigger_right
  613.         else
  614.           on_trigger_wrong
  615.         end
  616.         break
  617.       end
  618.     end
  619.   end
  620.  
  621.   def on_trigger_right
  622.     bit = get_button_image(:GOOD)
  623.     @menu_top.bitmap.blt(bit.width * @correct, @top_edge, bit, bit.rect)
  624.     @correct += 1
  625.     return minigame_success if @correct >= @pattern.size
  626.     RPG::SE.new(*TriggerButtonGood).play
  627.   end
  628.  
  629.   def on_trigger_wrong
  630.     case TriggerWrong
  631.     when 1
  632.       RPG::SE.new(*TriggerButtonBad).play
  633.     when 2
  634.       RPG::SE.new(*TriggerButtonBad).play
  635.       @correct = 0
  636.       @menu_top.bitmap.clear
  637.     when 3
  638.       bit = get_button_image(:BAD)
  639.       @menu_top.bitmap.blt(bit.width * @correct, @top_edge, bit, bit.rect)
  640.       minigame_failure
  641.     when 4
  642.       return custom_trigger_wrong
  643.     end
  644.   end
  645.  
  646.   def custom_trigger_wrong
  647.     ##~Bookmark1
  648.     ## This section is meant for custom code for when the player gets an
  649.     ## object wrong from the trigger.  Maker sure TriggerWrong is set to 4
  650.     ## for this section to occur.
  651.   end
  652.  
  653.   def dispose_game_sprites
  654.     @menu_back.dispose
  655.     @menu_top.dispose
  656.     @time_bar.dispose
  657.     @number_sprite.dispose
  658.   end
  659.  
  660.   def minigame_success
  661.     RPG::SE.new(*TriggerSuccess).play
  662.     super
  663.   end
  664.  
  665.   def minigame_failure
  666.     RPG::SE.new(*TriggerFailure).play
  667.     super
  668.   end
  669.  
  670.   def set_complete_variable
  671.     super
  672.     $game_variables[GameVariable] = @correct
  673.   end
  674. end
  675.  
  676. ##------
  677. ## Button Match Minigame
  678. ##------
  679. class MatchQTE < Scene_CPMinigame
  680.   @@prepared_valuesS = []
  681.  
  682.   def self.play(match = DefSMatch, time = DefSTime, buttons = DefSButtons)
  683.     get_background_image
  684.     @@prepared_valuesS = [match, time, buttons]
  685.     SceneManager.call(MatchQTE)
  686.     Fiber.yield
  687.   end
  688.  
  689.   def create_game_sprites
  690.     create_qte_pattern
  691.     create_menu_sprite
  692.     create_menu_top
  693.     create_pointer
  694.     create_time_bar
  695.   end
  696.  
  697.   def create_menu_sprite
  698.     temp = get_button_image(:A)
  699.     wd = temp.width * (@pattern.size + 2)
  700.     bit0 = Cache.system(SBackImage)
  701.     @menu_back = Sprite.new(@viewport)
  702.     @menu_back.bitmap = Bitmap.new(wd, [bit0.height, temp.height].max)
  703.     rect = Rect.new(0, (@menu_back.height - bit0.height) / 2, wd, bit0.height)
  704.     @menu_back.bitmap.stretch_blt(rect, bit0, bit0.rect)
  705.     @top_edge = (@menu_back.height - temp.height) / 2
  706.     @pattern.each_with_index do |s,i|
  707.       bit = get_button_image(s)
  708.       @menu_back.bitmap.blt(bit.width * (i + 1), @top_edge, bit, bit.rect)
  709.     end
  710.     @menu_back.ox, @menu_back.oy = @menu_back.width / 2, @menu_back.height / 2
  711.     @menu_back.x, @menu_back.y = Graphics.width / 2, Graphics.height / 2 - 4
  712.   end
  713.  
  714.   def create_menu_top
  715.     @menu_top = Sprite.new(@viewport)
  716.     @menu_top.bitmap = Bitmap.new(@menu_back.width, @menu_back.height)
  717.     @menu_top.z = 50
  718.     @menu_top.ox, @menu_top.oy = @menu_back.ox, @menu_back.oy
  719.     @menu_top.x, @menu_top.y = @menu_back.x, @menu_back.y
  720.   end
  721.  
  722.   def create_pointer
  723.     @pointer = Sprite.new(@viewport)
  724.     @pointer.bitmap = get_button_image(:ARROW)
  725.     @pointer.ox = @menu_back.ox - SPointerOffset
  726.     @pointer.oy = @menu_back.oy + @pointer.height
  727.     @pointer.x, @pointer.y = @menu_back.x, @menu_back.y
  728.   end
  729.  
  730.   def create_time_bar
  731.     @time_bar = Sprite.new(@viewport)
  732.     @time_bar.bitmap = Bitmap.new(@menu_back.width, @menu_back.height + 8)
  733.     @time_bar.ox, @time_bar.oy = @menu_back.ox, @menu_back.oy
  734.     @time_bar.x, @time_bar.y = @menu_back.x, @menu_back.y
  735.     @timer_value = 0
  736.     c3 = Color.new(*BarBackColor)
  737.     @time_bar.bitmap.fill_rect(0, @time_bar.height - 8, @time_bar.width, 8, c3)
  738.   end
  739.  
  740.   def create_qte_pattern
  741.     @pattern = []; @matches = []
  742.     @@prepared_valuesS[0].times do
  743.       @pattern.push(@@prepared_valuesS[2][rand(@@prepared_valuesS[2].size)])
  744.     end
  745.   end
  746.  
  747.   def update
  748.     super
  749.     update_timer_sprite
  750.     update_match_count
  751.   end
  752.  
  753.   def update_timer_sprite
  754.     @timer_value += 1
  755.     w = (@time_bar.width - 2) * (@timer_value.to_f / @@prepared_valuesS[1])
  756.     c1 = Color.new(*MatchBarColor)
  757.     c3 = Color.new(*BarBackColor)
  758.     @time_bar.bitmap.fill_rect(0, @time_bar.height - 8, @time_bar.width, 8, c3)
  759.     @time_bar.bitmap.fill_rect(1, @time_bar.height - 7, w, 6, c1)
  760.     @pos = @timer_value / (@@prepared_valuesS[1] / (@@prepared_valuesS[0] + 2))
  761.     @pos = [@pos, @@prepared_valuesS[0] + 1].min
  762.     return check_minigame_value if @timer_value >= @@prepared_valuesS[1]
  763.     @pointer.x = @menu_back.x + (@pos * @pointer.width)
  764.     check_last_pos
  765.   end
  766.  
  767.   def update_match_count
  768.     return if @pos == 0 || @pattern[@pos - 1].nil? || !@matches[@pos - 1].nil?
  769.     full = [:LEFT, :RIGHT, :UP, :DOWN, :A, :B, :C, :X, :Y, :Z, :L, :R]
  770.     full.each do |s|
  771.       if Input.trigger?(s)
  772.         @matches[@pos - 1] = s
  773.         if s == @pattern[@pos - 1]
  774.           on_trigger_right
  775.         else
  776.           on_trigger_wrong
  777.         end
  778.         break
  779.       end
  780.     end
  781.   end
  782.  
  783.   def check_last_pos
  784.     return if @pos < 2 || !@matches[@pos - 2].nil?
  785.     @matches[@pos - 2] = false
  786.     on_trigger_wrong(@pos - 1) unless MatchWrong == 1
  787.   end
  788.  
  789.   def on_trigger_right
  790.     RPG::SE.new(*MatchButtonGood).play
  791.     bit = get_button_image(:GOOD)
  792.     @menu_top.bitmap.blt(bit.width * @pos, @top_edge, bit, bit.rect)
  793.   end
  794.  
  795.   def on_trigger_wrong(pos = @pos)
  796.     case MatchWrong
  797.     when 1
  798.       RPG::SE.new(*TriggerButtonBad).play
  799.       ## Nothing is done.
  800.     when 2
  801.       fill_in_wrong_trigger(pos)
  802.     when 3
  803.       bit = get_button_image(:BAD)
  804.       @menu_top.bitmap.blt(bit.width * pos, @top_edge, bit, bit.rect)
  805.       minigame_failure
  806.     when 4
  807.       return custom_trigger_wrong
  808.     end
  809.   end
  810.  
  811.   def custom_trigger_wrong
  812.     ##~Bookmark3
  813.     ## This section is meant for custom code for when the player gets an
  814.     ## object wrong from the trigger.  Maker sure MatchWrong is set to 3
  815.     ## for this section to occur.
  816.   end
  817.  
  818.   def fill_in_wrong_trigger(pos = @pos)
  819.     RPG::SE.new(*MatchButtonBad).play
  820.     bit = get_button_image(:BAD)
  821.     @menu_top.bitmap.blt(bit.width * pos, @top_edge, bit, bit.rect)
  822.   end
  823.  
  824.   def check_minigame_value
  825.     @pattern.each_with_index do |s,i|
  826.        return minigame_failure if @matches[i] != s
  827.     end
  828.     return minigame_success
  829.   end
  830.  
  831.   def dispose_game_sprites
  832.     @menu_back.dispose
  833.     @menu_top.dispose
  834.     @time_bar.dispose
  835.     @pointer.dispose
  836.   end
  837.  
  838.   def minigame_success
  839.     RPG::SE.new(*MatchSuccess).play
  840.     super
  841.   end
  842.  
  843.   def minigame_failure
  844.     RPG::SE.new(*MatchFailure).play
  845.     super
  846.   end
  847.  
  848.   def set_complete_variable
  849.     super
  850.     var = 0
  851.     @pattern.each_with_index { |s,i| var += 1 if s == @matches[i] }
  852.     $game_variables[GameVariable] = var
  853.   end
  854. end
  855.  
  856. class ThermonuclearWar < Scene_CPMinigame
  857.   def self.play  ## Type in ThermonuclearWar.play
  858.     get_background_image
  859.     SceneManager.call(ThermonuclearWar)
  860.     Fiber.yield
  861.   end
  862.  
  863.   def create_game_sprites
  864.     black = Color.new(0, 0, 0)
  865.     @blackness = Sprite.new(@viewport)
  866.     @blackness.bitmap = Bitmap.new(Graphics.width, Graphics.height)
  867.     @blackness.bitmap.fill_rect(0, 0, Graphics.width, Graphics.height, black)
  868.     @blackness.bitmap.font.color = Color.new(255, 255, 255)
  869.     @blackness.visible = false
  870.   end
  871.  
  872.   def update
  873.     super
  874.     wait(45)
  875.     RPG::BGS.stop
  876.     RPG::BGM.stop
  877.     @blackness.visible = true
  878.     rect = @blackness.bitmap.rect
  879.     @blackness.bitmap.fill_rect(rect, Color.new(0, 0, 0))
  880.     @blackness.bitmap.draw_text(rect, "Shall we play a game?", 1)
  881.     wait(180)
  882.     @blackness.bitmap.fill_rect(rect, Color.new(0, 0, 0))
  883.     @blackness.bitmap.draw_text(rect, "How about a game of Thermonuclear War?", 1)
  884.     wait(180)
  885.     @blackness.bitmap.fill_rect(rect, Color.new(0, 0, 0))
  886.     @blackness.bitmap.draw_text(rect, "The only winning move is not to play.", 1)
  887.     wait(180)
  888.     exit
  889.   end
  890.  
  891.   def minigame_success
  892.     RPG::SE.new(*MatchSuccess).play
  893.     super
  894.   end
  895.  
  896.   def minigame_failure
  897.     RPG::SE.new(*MatchFailure).play
  898.     super
  899.   end
  900.  
  901.   def set_complete_variable
  902.     super
  903.     var = 0
  904.     @pattern.each_with_index { |s,i| var += 1 if s == @matches[i] }
  905.     $game_variables[GameVariable] = var
  906.   end
  907. end
  908.  
  909. ##------
  910. ## Target Slider Minigame
  911. ##------
  912. class TargetQTE < Scene_CPMinigame
  913.   @@prepared_valuesX = []
  914.  
  915.   def self.play(zoom = DefXZoom, time = DefXTime, speed = DefXSpeed)
  916.     get_background_image
  917.     @@prepared_valuesX = [zoom, time, speed]
  918.     SceneManager.call(TargetQTE)
  919.     Fiber.yield
  920.   end
  921.  
  922.   def create_game_sprites
  923.     create_menu_sprite
  924.     create_slider_sprite
  925.     create_number_sprites
  926.   end
  927.  
  928.   def create_menu_sprite
  929.     @menu_back = Sprite.new(@viewport)
  930.     bit0 = Cache.system(XBackImage)
  931.     bit1 = Cache.system(XBarImage)
  932.     bit2 = Cache.system(TargetImage)
  933.     mh = [bit0.height, bit2.height].max
  934.     offx = bit1.height + ((mh - bit0.height) / 2)
  935.     @menu_back.bitmap = Bitmap.new(bit1.width, bit1.height + mh)
  936.     rect1 = Rect.new(0, offx, bit1.width, bit0.height)
  937.     @menu_back.bitmap.stretch_blt(rect1, bit0, bit0.rect)
  938.     @menu_back.bitmap.blt(0, offx, bit2, bit2.rect)
  939.     sx = (bit1.width * @@prepared_valuesX[0] - bit1.width) / 2
  940.     sw = bit1.width - sx * 2
  941.     rect3 = Rect.new(0, 0, bit1.width, bit1.height)
  942.     rect4 = Rect.new(sx, 0, sw, bit1.height)
  943.     @menu_back.bitmap.stretch_blt(rect3, bit1, rect4)
  944.     @hi_section = (bit1.width / 2) / @@prepared_valuesX[2]
  945.     @lo_section = -@hi_section
  946.     @menu_back.ox, @menu_back.oy = @menu_back.width / 2, @menu_back.height / 2
  947.     @menu_back.x, @menu_back.y = Graphics.width / 2, Graphics.height / 2
  948.   end
  949.  
  950.   def create_slider_sprite
  951.     @slider = Sprite.new(@viewport)
  952.     @slider.bitmap = Cache.system(TargetSlider)
  953.     @slider.z = 50
  954.     @slider.ox = @slider.width / 2
  955.     @slider.oy = @menu_back.oy + @slider.height - SliderOffset
  956.     @slider.x = @menu_back.x + @lo_section * @@prepared_valuesX[2]
  957.     @slider.y = @menu_back.y
  958.     @pos = @lo_section
  959.   end
  960.  
  961.   def create_number_sprites
  962.     @number_sprite = Sprite.new(@viewport)
  963.     bit = Cache.system(XBarImage)
  964.     @number_sprite.bitmap = Bitmap.new(@menu_back.width,
  965.                                        @menu_back.height - bit.height)
  966.     @number_sprite.ox = @menu_back.ox
  967.     @number_sprite.x, @number_sprite.y = @menu_back.x, @menu_back.y
  968.     @timer_value = @@prepared_valuesX[1]
  969.     value = ((@timer_value + 5) / 6).to_f / 10
  970.     @number_sprite.bitmap.draw_text(@number_sprite.bitmap.rect, "#{value} ", 2)
  971.     @number_sprite.bitmap.draw_text(@number_sprite.bitmap.rect, "#{value} ", 2)
  972.   end
  973.  
  974.   def update
  975.     super
  976.     update_slider_sprite
  977.     update_timer_sprite
  978.     update_tap_count
  979.   end
  980.  
  981.   def update_slider_sprite
  982.     if @pos == @lo_section
  983.       @dir = 1
  984.     elsif @pos == @hi_section
  985.       @dir = -1
  986.     end
  987.     @pos += @dir
  988.     @slider.x = @menu_back.x + @pos * @@prepared_valuesX[2]
  989.   end
  990.  
  991.   def update_timer_sprite
  992.     @timer_value -= 1
  993.     value = ((@timer_value + 5) / 6).to_f / 10
  994.     @number_sprite.bitmap.clear
  995.     @number_sprite.bitmap.draw_text(@number_sprite.bitmap.rect, "#{value} ", 2)
  996.     return minigame_failure if value <= 0.0
  997.   end
  998.  
  999.   def update_tap_count
  1000.     if Input.trigger?(TargetButton)
  1001.       spot = (@pos * @@prepared_valuesX[2]).abs
  1002.       area = (@menu_back.width * @@prepared_valuesX[0] * TargetArea) / 2
  1003.       if area >= spot
  1004.         return minigame_success
  1005.       else
  1006.         return on_target_wrong
  1007.       end
  1008.     end
  1009.   end
  1010.  
  1011.   def on_target_wrong
  1012.     case TargetWrong
  1013.     when 1
  1014.       RPG::SE.new(*TargetButtonBad).play
  1015.       @pos = @lo_section
  1016.     when 2
  1017.       minigame_failure
  1018.     when 3
  1019.       return custom_target_wrong
  1020.     end
  1021.   end
  1022.  
  1023.   def custom_target_wrong
  1024.     ##~Bookmark2
  1025.     ## This section is meant for custom code for when the player targets
  1026.     ## a bad position on the slider bar.  Maker sure TargetWrong is set to 3
  1027.     ## for this section to occur.
  1028.   end
  1029.  
  1030.   def dispose_game_sprites
  1031.     @menu_back.dispose
  1032.     @slider.dispose
  1033.     @number_sprite.dispose
  1034.   end
  1035.  
  1036.   def minigame_success
  1037.     RPG::SE.new(*TargetSuccess).play
  1038.     super
  1039.   end
  1040.  
  1041.   def minigame_failure
  1042.     RPG::SE.new(*TargetFailure).play
  1043.     super
  1044.   end
  1045.  
  1046.   def set_complete_variable
  1047.     super
  1048.     ## Nothing....  Nothing is here....
  1049.   end
  1050. end
  1051.  
  1052.  
  1053. ##-----------------------------------------------------------------------------
  1054. ##  End of script.
  1055. ##-----------------------------------------------------------------------------
RAW Paste Data