搜索附件  

〓 转盘抽奖 〓: d1.gif

 

〓 转盘抽奖 〓:
很久没冒泡了,就拿这个来水一贴。

   以前写的 转盘抽奖 ,觉得不是很好,老早就全部推翻重新写了,但搁在那儿都快忘了。
今天偶然发现了,正好,加上说明就拿出来水咯。

〓 说明 〓
1,抽奖物品全部编辑在公共事件里。
2,游戏中可随时增/减随机的转盘物品。
3,可随时更改抽奖所消耗的东西(金钱/物品)。
4,素材来源=>网络

〓 用法 〓
1,将下面的 脚本 复制到工程 main 前。
2,将下面的 UI图片 下载后,复制到 Graphics\Pictures 文件夹里。
3,参照脚本说明,进行操作。
4,嫌麻烦的同学,可以直接下载下面的范例工程。

〓 演示截图 〓



〓 UI图片 〓



〓 脚本 〓
RUBY 代码
  1. #==============================================================================
  2. # 〓 转盘抽奖 (Lottery draw) 〓            Author: 芯☆淡茹水
  3. #==============================================================================
  4. # ■ 说明 ■
  5. #--------------------------------------------------------------------------
  6. # 1,  该转盘抽奖利用公共事件储存抽奖物品,分为 基本物品(设置项设置) 和
  7. #    动态物品(脚本命令添加/删除)两种。
  8. #      转盘上能够随机的物品为以上两种相加。
  9. #--------------------------------------------------------------------------
  10. # 2,  公共事件里编辑 增减物品,增减武器 或 增减防具 。当这个公共事件在物品
  11. #    事件里时,里面的这些项目物品都将添加到转盘的随机物品中。
  12. #--------------------------------------------------------------------------
  13. # 3,  如果总共的随机物品当中有 珍贵物品 时,随机时至少有一件会是 珍贵物品 。
  14. #    其它出现 珍贵物品 概率,依照设置项所设置的概率百分比。
  15. #--------------------------------------------------------------------------
  16. # 4,  进入抽奖场景,而未进行抽奖的,系统将储存当前转盘物品,防止进出抽奖场景
  17. #    刷物品。
  18. #--------------------------------------------------------------------------
  19. # 5,  初始抽奖消耗为 金钱=>100 ,可用脚本命令适时更改。
  20. #==============================================================================
  21. # ■ 脚本命令 ■
  22. #--------------------------------------------------------------------------
  23. # 1,开始转盘抽奖 => XdRs_Ld.start_lottery_draw
  24. #--------------------------------------------------------------------------
  25. # 2,添加公共事件(设置有随机物品)里的所有物品到随机物品 =>
  26. #    XdRs_Ld.add_ld_event(event_id, type)
  27. #    参数  event_id: 公共事件ID。
  28. #          type    : 添加的类型(0:添加到普通物品; 1:添加到珍贵物品)
  29. #    例:将 22 号公共事件里编辑的所有物品,添加到普通的随机物品中 =>
  30. #        XdRs_Ld.add_ld_event(22, 0)
  31. #        将 15 号公共事件里编辑的所有物品,添加到珍贵的随机物品中 =>
  32. #        XdRs_Ld.add_ld_event(15, 1)
  33. #--------------------------------------------------------------------------
  34. # 3,将添加的公共事件里的所有物品从随机物品中删除 =>
  35. #    XdRs_Ld.del_ld_event(event_id, type)
  36. #    参数同第 2 条。
  37. #--------------------------------------------------------------------------
  38. # 4,清空所有第 2 条添加的公共事件 => XdRs_Ld.clear_ld_events
  39. #--------------------------------------------------------------------------
  40. # 5,清除系统所记忆的转盘物品 =>  XdRs_Ld.clear_ld_data
  41. #--------------------------------------------------------------------------
  42. # 6,更改抽奖所需的消耗品 => XdRs_Ld.change_consume(type, num1, num2)
  43. #    参数  type: 消耗类型(0:金钱;1:物品)
  44. #          num1: 数值1,消耗类型为 0(金钱)时,写所需的金钱数;
  45. #                       消耗类型为 1(物品)时,写物品ID。
  46. #          num2: 数值2,消耗类型为 0(金钱)时,省略不写;
  47. #                       消耗类型为 1(物品)时,写所需的数量。
  48. #    例:设置抽奖消耗金钱 500 => XdRs_Ld.change_consume(0, 500)
  49. #        设置抽奖消耗 10 号物品 3 个 => XdRs_Ld.change_consume(1, 10, 3)
  50. #==============================================================================
  51. #==============================================================================
  52. module XdRs_Ld
  53. #==============================================================================
  54. # ■ 设置项 ■
  55. #==============================================================================
  56. #--------------------------------------------------------------------------
  57. # 游戏分辨率宽。
  58. Graphics_Width = 640
  59. #--------------------------------------------------------------------------
  60. # 游戏分辨率高。
  61. Graphics_Height = 480
  62. #--------------------------------------------------------------------------
  63. # 基本普通抽奖物品的公共事件ID。
  64. Base_Ordinary = 10
  65. #--------------------------------------------------------------------------
  66. # 基本珍贵抽奖物品的公共事件ID。
  67. Base_Precious = 11
  68. #--------------------------------------------------------------------------
  69. # 转盘出现珍贵物品的概率百分比。
  70. Precious_Rate = 10
  71. #--------------------------------------------------------------------------
  72. # 金钱图标名。
  73. Gold_Icon = "035-Item04"
  74. #--------------------------------------------------------------------------
  75. # 得到奖品时播放的动画ID。
  76. Award_Anm = 46
  77. #--------------------------------------------------------------------------
  78. # 指针转动时,播放的SE。
  79. Needle_Se = "041-Knock02"
  80. #--------------------------------------------------------------------------
  81. end
  82. #==============================================================================
  83. # ■ 脚本正文 ■
  84. #==============================================================================
  85. module XdRs_Ld
  86.   #--------------------------------------------------------------------------
  87.   defself.ui_name
  88.     return"Ui_LotteryDraw"    #UI图片名
  89.   end
  90.   #--------------------------------------------------------------------------
  91.   # 闪烁灯位置
  92.   #--------------------------------------------------------------------------
  93.   defself.lamp_place(index)
  94.     return[[201,21],[264,70],[289,156],[263,234],[196,283],[101,282],
  95.     [31,222],[11,144],[39,67],[103,18]][index]
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # 物品图标位置
  99.   #--------------------------------------------------------------------------
  100.   defself.item_place(index)
  101.     return[[182,52],[230,92],[250,150],[230,210],[182,248],[120,248],
  102.     [68,210],[46,150],[68,92],[120,52]][index]
  103.   end
  104.   #--------------------------------------------------------------------------
  105.   defself.has_ld_items
  106.     data = [[Base_Ordinary], [Base_Precious]]
  107.     data[0] += $game_system.ld_data[0]
  108.     data[1] += $game_system.ld_data[1]
  109.     return data.any?{|d| self.type_has_ld_items(d)}
  110.   end
  111.   #--------------------------------------------------------------------------
  112.   defself.type_has_ld_items(data)
  113.     return data.any?{|id| self.ld_list(id).size > 0}
  114.   end
  115.   #--------------------------------------------------------------------------
  116.   defself.ld_items
  117.     data = []
  118.     base = [[Base_Ordinary], [Base_Precious]]
  119.     data[0] = self.type_items(0, base) + self.type_items(0, $game_system.ld_data)
  120.     data[1] = self.type_items(1, base) + self.type_items(1, $game_system.ld_data)
  121.     return data
  122.   end
  123.   #--------------------------------------------------------------------------
  124.   defself.type_items(type, data)
  125.     items = []
  126.     data[type].size.timesdo |i|
  127.       list = self.ld_list(data[type][i])
  128.       list.each{|l| items 100
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   defself.can_ld_start
  132.     cst = $game_system.consumption_data
  133.     return$game_party.gold >= cst[1][0]if cst[0] == "gold"
  134.     return$game_party.item_number(cst[1][0]) >= cst[1][1]
  135.   end
  136.   #--------------------------------------------------------------------------
  137.   defself.deductible
  138.     cst = $game_system.consumption_data
  139.     tp = cst[0]; d = cst[1][0]; n = cst[1][1]
  140.     tp == "gold" ? $game_party.lose_gold(d) : $game_party.gain_item(d, -n)
  141.   end
  142.   #--------------------------------------------------------------------------
  143.   defself.start_lottery_draw
  144.     unlessself.has_ld_items
  145.       $game_temp.message_text = "没有抽奖物品,暂时无法抽奖!"
  146.       return
  147.     end
  148.     $scene = Lottery_Draw.new
  149.   end
  150.   #--------------------------------------------------------------------------
  151.   defself.add_ld_event(event_id, type=0)
  152.     returnif type > 1
  153.     $game_system.set_ld_events(event_id, "add", type)
  154.   end
  155.   #--------------------------------------------------------------------------
  156.   defself.del_ld_event(event_id, type=0)
  157.     returnif type > 1
  158.     $game_system.set_ld_events(event_id, "del", type)
  159.   end
  160.   #--------------------------------------------------------------------------
  161.   defself.clear_ld_data
  162.     $game_system.save_ld_items([])
  163.   end
  164.   #--------------------------------------------------------------------------
  165.   defself.clear_ld_events
  166.     $game_system.clear_all_ld_events
  167.   end
  168.   #--------------------------------------------------------------------------
  169.   defself.change_consume(type, num1, num2=0)
  170.     returnif type == 0 && num1  0 ? @count -= 1 : start_twinkle
  171.   end
  172. end
  173. #==============================================================================
  174. # 白色转幕
  175. #==============================================================================
  176. class XdRs_LdCurtain < XdRs_UiBase
  177.   #--------------------------------------------------------------------------
  178.   def initialize(x, y)
  179.     super(x, y, XdRs_Ld.ui_name, Rect.new(495,48,78,128))
  180.     self.ox = @rect.width / 2
  181.     self.oy = @rect.height
  182.     @index = rand10
  183.     start_turn
  184.   end
  185.   #--------------------------------------------------------------------------
  186.   def start_turn
  187.     @count = 0
  188.     self.angle = 360 - (@index * 36 + 18)
  189.     @index = (@index+1) % 10
  190.   end
  191.   #--------------------------------------------------------------------------
  192.   def update
  193.     super
  194.     update_turn
  195.   end
  196.   #--------------------------------------------------------------------------
  197.   def update_turn
  198.     returnunlessself.visible
  199.     @count < 10 ? @count += 1 : start_turn
  200.   end
  201. end
  202. #==============================================================================
  203. # 转针
  204. #==============================================================================
  205. class XdRs_LdNeedle < XdRs_UiBase
  206.   #--------------------------------------------------------------------------
  207.   def initialize(x, y)
  208.     super(x, y, XdRs_Ld.ui_name, Rect.new(381,48,114,150))
  209.     self.ox = @rect.width / 2
  210.     self.oy = 93
  211.     @index = rand10
  212.     @count = @speed = 0
  213.     @is_start = false
  214.     self.angle = 360 - (@index * 36 + 18)
  215.   end
  216.   #--------------------------------------------------------------------------
  217.   def start
  218.     returnif@is_start
  219.     add = rand100
  220.     @count = (rand(2) == 0 ? add : -add) + 200
  221.     @is_start = true
  222.   end
  223.   #--------------------------------------------------------------------------
  224.   def index;        return@index;     end
  225.   #--------------------------------------------------------------------------
  226.   def in_rotation;  return@is_start;  end
  227.   #--------------------------------------------------------------------------
  228.   def refresh_angle
  229.     play_se(XdRs_Ld::Needle_Se)
  230.     @index = (@index+1) % 10
  231.     self.angle = 360 - (@index * 36 + 18)
  232.     @speed = [(300 - @count) / 50, 1].max
  233.   end
  234.   #--------------------------------------------------------------------------
  235.   def update
  236.     super
  237.     update_turn
  238.   end
  239.   #--------------------------------------------------------------------------
  240.   def update_turn
  241.     returnif !self.visible || !@is_start
  242.     @count -= 1if@count > 0
  243.     @speed -= 1if@speed > 0
  244.     @speed == 0 && refresh_angle
  245.     @is_start = falseif@count == 0
  246.   end
  247. end
  248. #==============================================================================
  249. # 奖品显示
  250. #==============================================================================
  251. class XdRs_LdPrize < XdRs_UiBase
  252.   #--------------------------------------------------------------------------
  253.   def initialize
  254.     x = XdRs_Ld::Graphics_Width / 2
  255.     y = XdRs_Ld::Graphics_Height / 2
  256.     super(x, y, "", Rect.new(0,0,300,300))
  257.     self.ox = @drawing_board.ox = 150
  258.     self.oy = @drawing_board.oy = 150
  259.     show_prize
  260.   end
  261.   #--------------------------------------------------------------------------
  262.   def show_prize(prize=nil)
  263.     hide; clear
  264.     returnif !prize
  265.     play_anm(XdRs_Ld::Award_Anm)
  266.     image = XdRs_Ld.ui_name
  267.     blt(50, 80, Rect.new(300, 255, 200, 45), image)
  268.     blt(125, 140, Rect.new(381, 198, 50, 50), image)
  269.     ix = (50 - icon_size) / 2
  270.     draw_icon(125+ix, 140+ix, prize.icon_name)
  271.     draw_text(0, 200, 300, 24, prize.name, 1)
  272.     show
  273.   end
  274. end
  275. #==============================================================================
  276. # 抽奖场景
  277. #==============================================================================
  278. class Lottery_Draw
  279.   #--------------------------------------------------------------------------
  280.   def main
  281.     init_data
  282.     create_all
  283.     start
  284.     Graphics.transition
  285.     loopdo
  286.       Graphics.update; Input.update; update
  287.       breakif$scene != self
  288.     end
  289.     Graphics.freeze
  290.     dispose_all
  291.   end
  292.   #--------------------------------------------------------------------------
  293.   def init_data
  294.     @process = 0
  295.     @all_items = XdRs_Ld.ld_items
  296.   end
  297.   #--------------------------------------------------------------------------
  298.   def create_all
  299.     @lamps = []
  300.     x = (XdRs_Ld::Graphics_Width - 300) / 2
  301.     y = (XdRs_Ld::Graphics_Height - 300) / 2
  302.     cy = y + 304; hx = x + 150; hy = y + 150
  303.     rect1 = Rect.new(300,48,81,79); rect2 = Rect.new(300,127,81,79)
  304.     @map_bg     = Spriteset_Map.new
  305.     @turntable  = XdRs_UiBase.new(x, y, XdRs_Ld.ui_name,Rect.new(0,0,300,300))
  306.     @consume    = XdRs_UiBase.new(x, cy, XdRs_Ld.ui_name,Rect.new(300,0,300,48))
  307.     @curtain    = XdRs_LdCurtain.new(hx, hy)
  308.     @needle     = XdRs_LdNeedle.new(hx, hy)
  309.     @button     = XdRs_Button.new(hx, hy, XdRs_Ld.ui_name, rect1, rect2)
  310.     @prize_show = XdRs_LdPrize.new
  311.     10.times{|i| @lamps  0 ? rand(10) : nil
  312.     can_repeat = (@all_items[0] + @all_items[1]).size < 10
  313.     while data.size < 10
  314.       item = rand_item(is_precious(p_index, data) ? 1 : 0)
  315.       item && (can_repeat || !data.include?(item)) && data.push(item)
  316.     end
  317.     $game_system.save_ld_items(data)
  318.     return data
  319.   end
  320.   #--------------------------------------------------------------------------
  321.   def is_precious(index, data)
  322.     returnrand(100) < XdRs_Ld::Precious_Rate || index && index == data.size
  323.   end
  324.   #--------------------------------------------------------------------------
  325.   def rand_item(type)
  326.     obj = @all_items[type]
  327.     return obj[rand(obj.size)]
  328.   end
  329.   #--------------------------------------------------------------------------
  330.   def draw_now_items
  331.     @turntable.clear
  332.     10.timesdo |i|
  333.       nextunless@now_items[i]
  334.       place = XdRs_Ld.item_place(i)
  335.       x = place[0] - @turntable.icon_size / 2
  336.       y = place[1] - @turntable.icon_size / 2
  337.       @turntable.draw_icon(x,y,@now_items[i].obj.icon_name)
  338.     end
  339.   end
  340.   #--------------------------------------------------------------------------
  341.   def num_text(d)
  342.     num1 = d[0] == "gold" ? $game_party.gold : $game_party.item_number(d[1][0])
  343.     num2 = d[0] == "gold" ? d[1][0] : d[1][1]
  344.     return num2.to_s + "/" + num1.to_s
  345.   end
  346.   #--------------------------------------------------------------------------
  347.   def prize
  348.     return@now_items[@needle.index].obj
  349.   end
  350.   #--------------------------------------------------------------------------
  351.   def get_prize
  352.     case prize
  353.     whenRPG::Item   ;$game_party.gain_item(prize.id, 1)
  354.     whenRPG::Weapon ;$game_party.gain_weapon(prize.id, 1)
  355.     whenRPG::Armor  ;$game_party.gain_armor(prize.id, 1)
  356.     end
  357.   end
  358.   #--------------------------------------------------------------------------
  359.   def update
  360.     update_windows
  361.     send("process"+@process.to_s)
  362.   end
  363.   #--------------------------------------------------------------------------
  364.   def update_windows
  365.     @button.update
  366.     @needle.update
  367.     @curtain.update
  368.     @prize_show.update
  369.     @lamps.each{|l| l.update}
  370.   end
  371.   #--------------------------------------------------------------------------
  372.   def process0
  373.     Input.trigger?(Input::C) && ready_start
  374.     Input.trigger?(Input::B) && return_to_map
  375.   end
  376.   #--------------------------------------------------------------------------
  377.   def process1
  378.     !@needle.in_rotation && end_rotation
  379.   end
  380.   #--------------------------------------------------------------------------
  381.   def process2
  382.     Input.trigger?(Input::C) && come_again
  383.   end
  384.   #--------------------------------------------------------------------------
  385.   def ready_start
  386.     @button.press
  387.     if !XdRs_Ld.can_ld_start
  388.       $game_system.se_play($data_system.buzzer_se)
  389.       return
  390.     end
  391.     $game_system.se_play($data_system.decision_se)
  392.     $game_system.save_ld_items([])
  393.     XdRs_Ld.deductible
  394.     refresh_demand
  395.     @needle.start
  396.     @curtain.hide
  397.     @lamps.each{|l| l.hide}
  398.     @process = 1
  399.   end
  400.   #--------------------------------------------------------------------------
  401.   def end_rotation
  402.     @prize_show.show_prize(prize)
  403.     get_prize
  404.     refresh_demand
  405.     refresh_button
  406.     @process = 2
  407.   end
  408.   #--------------------------------------------------------------------------
  409.   def come_again
  410.     $game_system.se_play($data_system.decision_se)
  411.     @prize_show.show_prize
  412.     @curtain.show
  413.     @lamps.each{|l| l.show}
  414.     refresh_items
  415.     @process = 0
  416.   end
  417.   #--------------------------------------------------------------------------
  418.   def return_to_map
  419.     $game_system.se_play($data_system.cancel_se)
  420.     $scene = Scene_Map.new
  421.   end
  422. end
  423. #==============================================================================
  424. # end
  425. #==============================================================================
复制代码


〓 范例工程 〓


             本帖来自P1论坛作者芯☆淡茹水,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=410955  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
〓 转盘抽奖 〓: d1.gif
关闭

幸运抽奖

社区每日抽奖来袭,快来试试你是欧皇还是非酋~

立即查看

Loading...

QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

GMT+8, 2025-7-2 00:15 , Processed in 0.101794 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

返回顶部