vindaca510

V's Prize Wheel Mini-Game v0.5

Oct 7th, 2013
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 17.00 KB | None | 0 0
  1. #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
  2. #                                                                              #
  3. #                          V's  Prize Wheel Mini-Game                          #
  4. #                                 Version  0.5                                 #
  5. #                                                                              #
  6. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  7. #                                Written By:  V                                #
  8. #                         Last Edited: October 8, 2013                         #
  9. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  10. #                                                                              #
  11. #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
  12.  
  13.  
  14. #==============================================================================#
  15. #------------------------------------------------------------------------------#
  16. # ** Disclaimer                                                                #
  17. #------------------------------------------------------------------------------#
  18. #                                                                              #
  19. # This script was intended for Non-commercial use only, if you wish to use     #
  20. # this script in a commercial game please PM me at which ever site you found   #
  21. # this script. Either way please give me credit in your game script as the     #
  22. # writer of this script, and send me a PM abuot the release of the game/demo.  #
  23. #                                                                              #
  24. # Wooden Prize Wheel Image and Wooden Background Image found inside of the     #
  25. # demo was drawn and contributed by Cap'n K'nuckles, and can only be used      #
  26. # on his terms.                                                                #
  27. #                                                                              #
  28. #------------------------------------------------------------------------------#
  29. # ** How To Use                                                                #
  30. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  31. #                                                                              #
  32. # * Set-Up prizes below in the script's customizable area.                     #
  33. #                                                                              #
  34. # * To play the game just use one of the commands from below in an event's     #
  35. #   script call.                                                               #
  36. #                                                                              #
  37. #    When using your own prize wheel.                                          #
  38. # prize_wheel(lable, cost, number_of_sections, prize_wheel, bg_fg, bg_fg_type) #
  39. #       (There is an example in the demo of how to set-up a custom wheel.)     #
  40. #                                                                              #
  41. #    When using default prize wheel.                                           #
  42. #    prize_wheel(lable, cost)                                                  #
  43. #                                                                              #
  44. # * When setting-up the events, the lable and cost will determine which list   #
  45. #   to use the rewards from below.                                             #
  46. #                                                                              #
  47. #                                                                              #
  48. #------------------------------------------------------------------------------#
  49. # ** Description                                                               #
  50. #------------------------------------------------------------------------------#
  51. #                                                                              #
  52. #  v0.1                                                                        #
  53. # ~=~=~=~                                                                      #
  54. #  * This script creates a spin-the-wheel type prize game.                     #
  55. #                                                                              #
  56. #  v0.2                                                                        #
  57. # ~=~=~=~                                                                      #
  58. #  * I added a lable feature to allow multitudes of same cost prize set-ups.   #
  59. #    I also added options to change the background/foreground.                 #
  60. #                                                                              #
  61. #  v0.3                                                                        #
  62. # ~=~=~=~                                                                      #
  63. #  * I added a empty item type for no reward sections.                         #
  64. #                                                                              #
  65. #  v0.4                                                                        #
  66. # ~=~=~=~                                                                      #
  67. #  * I set up a customizable audio area below.                                 #
  68. #                                                                              #
  69. #  v0.5                                                                        #
  70. # ~=~=~=~                                                                      #
  71. #  * I fix a bug wth the audio.                                                #
  72. #                                                                              #
  73. #------------------------------------------------------------------------------#
  74. #==============================================================================#
  75. module V_Prize_Wheel
  76.   module Specs
  77. #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
  78. #                                                                              #
  79. #                           Start Customizable Area.                           #
  80. #                                                                              #
  81. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  82. #                                                                              #
  83. #                      ONLY EDIT AFTER THE EQUALS SYMBOL.                      #
  84. #                                                                              #
  85. #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
  86.    
  87.    
  88.   #============================================================================
  89.   #  Audio
  90.   #============================================================================
  91.    
  92.     BGM = ["Town3", 80, 100]
  93.     Victory_ME = ["Item", 80, 100]
  94.     Failure_ME = ["Gag", 80, 100]
  95.    
  96.   #============================================================================
  97.   #  Prize Set-Up
  98.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  99.   #  ** When seting-up the wheel start with the section at the bottom and go
  100.   #     counter-clockwise. (Look at the prize wheel image inside of the demo's
  101.   #     picture folder and use that along with the below set-up as a guide)
  102.   #    
  103.   #  ** Copy and Paste the below set-up to add different prizes lables
  104.   #     and costs.    
  105.   #    
  106.   #  ** You may also include arrays for random items and ammounts.  
  107.   #    
  108.   #============================================================================
  109.     Prizes = {
  110.      
  111.     #Lable
  112.     "Example" => {  
  113.  
  114.     #Cost      #Items_Type       Items/Amount(if gold)          Section
  115.       5 => [[    "weapon",           [1,2,3,4],                    0         ],
  116.             [    "gold",                  1000,                    1         ],
  117.             [    "item",                     1,                    2         ],
  118.             [    "item",                 [7,8],                    3         ],
  119.             [    "armor",                    1,                    4         ],
  120.             [    "gold",                   200,                    5         ],
  121.             [    "item",                     2,                    6         ],
  122.             [    "item",                     6,                    7         ]
  123.             ], # <--- End Cost
  124.            
  125.     #Cost      #Items_Type       Items/Amount(if gold)          Section
  126.       10 => [[    "weapon",           [1,2,3,4],                   0         ],
  127.             [    "gold",                  1000,                    1         ],
  128.             [    "item",                     1,                    2         ],
  129.             [    "item",                 [7,8],                    3         ],
  130.             [    "armor",                    1,                    4         ],
  131.             [    "gold",                   200,                    5         ],
  132.             [    "item",                     2,                    6         ],
  133.             [    "item",                     6,                    7         ]
  134.             ], # <--- End Cost
  135.            
  136.      }, # <--- End Lable
  137.              
  138.     #Lable
  139.     "Example2" => {  
  140.  
  141.     #Cost      #Items_Type       Items/Amount(if gold)          Section
  142.       5 => [[    "weapon",                   6,                    0         ],
  143.             [    "gold",             [100,400],                    1         ],
  144.             [    "item",                    10,                    2         ],
  145.             [    "item",                     1,                    3         ],
  146.             [    "empty",                    0,                    4         ],
  147.             [    "armor",              [1,2,5],                    5         ]
  148.             ], # <--- End Cost
  149.            
  150.      }, # <--- End Lable
  151.              
  152.              
  153.              
  154. #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
  155. #                                                                              #
  156. #         DO NOT EDIT PAST THIS POINT UNLESS YOU KNOW WHAT YOUR DOING.         #
  157. #                                                                              #
  158. #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189. }
  190. end
  191. end
  192. class Window_PrizeWheel_Choices < Window_Command
  193.   def alignment
  194.     return 1
  195.   end
  196.   def cost?
  197.     $game_system.co <= $game_party.gold
  198.   end
  199.   def make_command_list
  200.     add_command("Spin The Wheel", :start_spin, cost?)
  201.     add_command("Nevermind", :cancel_spin)
  202.   end
  203. end
  204. class Window_PrizeWheel_ChoicesText < Window_Base
  205.   def initialize(x, y, width, height)
  206.     super(x, y, width, height)
  207.     text1 = "Give it a shot?"
  208.     text2 = "Only #{$game_system.co} " + Vocab::currency_unit
  209.     draw_v_text(-10, -30, width, height, text1, 1, 16)
  210.     draw_v_text(-10, -10, width, height, text2, 1, 24)
  211.   end
  212.   def draw_v_text(x, y, width, height, text, alignment, size)
  213.     reset_font_settings
  214.     contents.font.size = size
  215.     contents.draw_text(x, y, width, height, text, alignment)
  216.     reset_font_settings
  217.   end
  218. end
  219. class Window_PrizeWheel_Rewards < Window_Base
  220.   include V_Prize_Wheel::Specs
  221.   def initialize(x, y, width, height)
  222.     super(x, y, width, height)
  223.     @rt = nil
  224.     @ri = nil
  225.     refresh
  226.   end
  227.   def draw_large_icon(icon_index, x, y, enabled = true)
  228.     bitmap = Cache.system("Iconset")
  229.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  230.     icon = Rect.new(x, y, 48, 48)
  231.     contents.stretch_blt(icon, bitmap, rect)    
  232.   end
  233.   def draw_v_text(x, y, width, height, text, alignment, size)
  234.     reset_font_settings
  235.     contents.font.size = size
  236.     contents.draw_text(x, y, width, height, text, alignment)
  237.     reset_font_settings
  238.   end
  239.   def draw_contents
  240.     case
  241.     when @rt < 3
  242.       draw_item_reward
  243.     when @rt == 3
  244.       draw_gold_reward
  245.     when @rt == 4
  246.       draw_lose_reward
  247.     end
  248.   end
  249.   def draw_item_reward
  250.     RPG::ME.new(Victory_ME[0],Victory_ME[1],Victory_ME[2]).play
  251.     draw_v_text(-10, -75, 300, 216, "You've Won A...", 1, 36)
  252.     case @rt
  253.     when 0
  254.       item = $data_weapons[@ri]
  255.       $game_party.gain_item(item, 1)
  256.       draw_v_text(75, 0, 300, 216, item.name, 0, 36)
  257.       draw_large_icon(item.icon_index, 20, 75)
  258.     when 1
  259.       item = $data_armors[@ri]
  260.       $game_party.gain_item(item, 1)
  261.       draw_v_text(75, 0, 300, 216, item.name, 0, 36)
  262.       draw_large_icon(item.icon_index, 20, 75)
  263.     when 2
  264.       item = $data_items[@ri]
  265.       $game_party.gain_item(item, 1)
  266.       draw_v_text(75, 0, 300, 216, item.name, 0, 36)
  267.       draw_large_icon(item.icon_index, 20, 75)
  268.     end
  269.   end
  270.   def draw_gold_reward
  271.     RPG::ME.new(Victory_ME[0],Victory_ME[1],Victory_ME[2]).play
  272.     $game_party.gain_gold(@ri)
  273.     text = @ri.to_s + " " + Vocab::currency_unit
  274.     draw_v_text(-10, -75, 300, 216, "You've Won...", 1, 36)
  275.     draw_v_text(-10, 0, 300, 216, text, 1, 36)
  276.   end
  277.   def draw_lose_reward
  278.     RPG::ME.new(Failure_ME[0],Failure_ME[1],Failure_ME[2]).play
  279.     draw_v_text(-10, -35, 300, 216, "You've Lost!", 1, 36)
  280.   end
  281.   def rr(prize)
  282.     case prize[0]
  283.     when "weapon"
  284.       @rt = 0
  285.     when "armor"
  286.       @rt = 1
  287.     when "item"
  288.       @rt = 2
  289.     when "gold"
  290.       @rt = 3
  291.     when "empty"
  292.       @rt = 4
  293.     end
  294.     if prize[1].is_a?(Array)
  295.       @ri = prize[1][rand(prize.size)]
  296.     else
  297.       @ri = prize[1]
  298.     end
  299.     refresh
  300.   end
  301.   def refresh
  302.     contents.clear
  303.     draw_contents unless @ri == nil
  304.   end
  305. end
  306. class Scene_PrizeWheel < Scene_Base
  307.   include V_Prize_Wheel::Specs
  308.   def initialize
  309.     super
  310.     RPG::BGM.new(BGM[0], BGM[1], BGM[2]).play
  311.     setup_vars
  312.     draw_command_window
  313.     draw_prize_wheel_window
  314.     draw_reward_window
  315.   end
  316.   def setup_vars
  317.     @pwro = 0
  318.     @tico = 0
  319.     @sttico = 0
  320.     @rati = [40,45,50,55,60,65]
  321.     @rastti = [40,45,50,55,60,65]
  322.     @rasp = [50,60,70]
  323.     @sp = @rasp[rand(3)]
  324.     @ti = @rati[rand(6)]
  325.     @stti = @rastti[rand(6)]
  326.     @start = false
  327.     @ssspwp = false
  328.     @regiou = false
  329.   end
  330.   def draw_command_window
  331.     @pwcw = Window_PrizeWheel_Choices.new(194, 200)
  332.     @pwcw.set_handler(:start_spin, method(:start_prize_wheel))
  333.     @pwcw.set_handler(:cancel_spin, method(:cancel_prize_wheel))
  334.     @pwcwtw = Window_PrizeWheel_ChoicesText.new(164, 135, @pwcw.width + 60, 75)
  335.     @pwcwtw.z = @pwcw.z - 1
  336.   end
  337.   def draw_prize_wheel_window
  338.     @pw = Sprite.new
  339.     @pw.bitmap = Cache.picture($game_system.prwhim)
  340.     @pw.x = 281
  341.     @pw.y = 255
  342.     @pw.ox = @pw.width.to_f / 2
  343.     @pw.oy = @pw.height.to_f / 2
  344.     @pwfg = Sprite.new
  345.     @pwfg.bitmap = Cache.picture($game_system.prwhbgfgim)
  346.     @pwfg.z = 50 if $game_system.prwhbgfgimty == "fg"
  347.     @pwfg.z = -50 if $game_system.prwhbgfgimty == "bg"
  348.   end
  349.   def draw_reward_window
  350.     @rw = Window_PrizeWheel_Rewards.new(122, 125, 300, 166)
  351.     @rw.openness = 0
  352.   end
  353.   def update_wheel_spins
  354.     @tico += 1
  355.     if @tico == @ti
  356.       @ssspwp = true
  357.       start = false
  358.     else
  359.       @pw.angle -= @sp
  360.       @pwro -= @sp
  361.     end
  362.   end
  363.   def stop_wheel_spin
  364.     @sttico += 1
  365.     if @sttico < @stti
  366.       @sp -= 1
  367.       @sttico = 0
  368.     end
  369.     if @sp == 0
  370.       cpwa
  371.       @ssspwp = false
  372.     else
  373.       @pw.angle -= @sp
  374.       @pwro -= @sp
  375.     end
  376.   end
  377.   def cpwa
  378.     section = 0
  379.     sections_width = (360 / $game_system.nuofse)
  380.     angle = ((@pwro * -1) + (sections_width / 2)) + 270
  381.     angle -= 360 until angle <= 360
  382.     $game_system.nuofse.times { |i|
  383.       min = (sections_width * i)
  384.       max = ((sections_width * i) + sections_width)
  385.       section = i if angle >= min && angle < max
  386.       }
  387.       p section
  388.     srp(section)
  389.   end
  390.   def srp(section)
  391.     prize = Prizes[$game_system.rl][$game_system.co][section]
  392.     @rw.rr(prize)
  393.     @rw.open
  394.     @regiou = true
  395.   end
  396.   def start_prize_wheel
  397.     $game_party.lose_gold($game_system.co)
  398.     @pwcw.close
  399.     @pwcw.unselect
  400.     @pwcwtw.close
  401.     @start = true
  402.   end
  403.   def cancel_prize_wheel
  404.     @regiou = false
  405.     return_scene
  406.     RPG::BGM.stop
  407.   end
  408.   def update
  409.     super
  410.     cancel_prize_wheel if (Input.trigger?(:C) || Input.trigger?(:B)) && @regiou == true
  411.     update_wheel_spins if @start == true
  412.     stop_wheel_spin if @ssspwp == true
  413.   end
  414. end
  415. class Game_System
  416.   attr_accessor :co
  417.   attr_accessor :rl
  418.   attr_accessor :nuofse
  419.   attr_accessor :prwhim
  420.   attr_accessor :prwhbgfgim
  421.   attr_accessor :prwhbgfgimty
  422.   alias :i0420752452753 :initialize
  423.   def initialize
  424.     @co = 0
  425.     @rl = ""
  426.     @nuofse = 0
  427.     @prwhim = ""
  428.     @prwhbgfgim = ""
  429.     @prwhbgfgimty = ""
  430.     i0420752452753()
  431.   end
  432. end
  433. class Game_Interpreter
  434.   def prize_wheel(lable, cost, number_of_sections = 8, prize_wheel = "prize wheel", bg_fg = "prize wheel fg", image_type = "fg")
  435.     $game_system.rl = lable
  436.     $game_system.co = cost
  437.     $game_system.nuofse = number_of_sections
  438.     $game_system.prwhim = prize_wheel
  439.     $game_system.prwhbgfgim = bg_fg
  440.     $game_system.prwhbgfgimty = image_type
  441.     SceneManager.call(Scene_PrizeWheel)
  442.   end
  443. end
Advertisement
Add Comment
Please, Sign In to add comment