- 累计送礼:
 - 0 个
 
 - 累计收礼:
 - 0 个
 
 TA的每日心情  | 开心 2025-10-18 22:41 | 
|---|
 
  签到天数: 165 天 连续签到: 1 天 [LV.7]常住居民III 
  
管理员 
    
    
        - VIP
 
        - 6 
 
     
    
        - 卡币
 
        - 14829 
 
     
    
        - OK点
 
        - 16 
 
     
    
    - 推广点
 
    - 0 
 
     
	
    - 同能卷
 
    - 0 
 
     
  
	- 积分
 - 17954
 
 
  
 
  
 | 
 
很久没冒泡了,就拿这个来水一贴。 
   以前写的 转盘抽奖 ,觉得不是很好,老早就全部推翻重新写了,但搁在那儿都快忘了。 
今天偶然发现了,正好,加上说明就拿出来水咯。
 〓 说明 〓
1,抽奖物品全部编辑在公共事件里。 
2,游戏中可随时增/减随机的转盘物品。 
3,可随时更改抽奖所消耗的东西(金钱/物品)。 
4, 素材来源=>网络
〓 用法 〓
1,将下面的 脚本 复制到工程 main 前。 
2,将下面的 UI图片 下载后,复制到 Graphics\Pictures 文件夹里。 
3,参照脚本说明,进行操作。 
4,嫌麻烦的同学,可以直接下载下面的范例工程。
 〓 演示截图 〓
〓 UI图片 〓
〓 脚本 〓
RUBY 代码 - #==============================================================================
 - # 〓 转盘抽奖 (Lottery draw) 〓            Author: 芯☆淡茹水
 - #==============================================================================
 - # ■ 说明 ■
 - #--------------------------------------------------------------------------
 - # 1,  该转盘抽奖利用公共事件储存抽奖物品,分为 基本物品(设置项设置) 和
 - #    动态物品(脚本命令添加/删除)两种。
 - #      转盘上能够随机的物品为以上两种相加。
 - #--------------------------------------------------------------------------
 - # 2,  公共事件里编辑 增减物品,增减武器 或 增减防具 。当这个公共事件在物品
 - #    事件里时,里面的这些项目物品都将添加到转盘的随机物品中。
 - #--------------------------------------------------------------------------
 - # 3,  如果总共的随机物品当中有 珍贵物品 时,随机时至少有一件会是 珍贵物品 。
 - #    其它出现 珍贵物品 概率,依照设置项所设置的概率百分比。
 - #--------------------------------------------------------------------------
 - # 4,  进入抽奖场景,而未进行抽奖的,系统将储存当前转盘物品,防止进出抽奖场景
 - #    刷物品。
 - #--------------------------------------------------------------------------
 - # 5,  初始抽奖消耗为 金钱=>100 ,可用脚本命令适时更改。
 - #==============================================================================
 - # ■ 脚本命令 ■
 - #--------------------------------------------------------------------------
 - # 1,开始转盘抽奖 => XdRs_Ld.start_lottery_draw
 - #--------------------------------------------------------------------------
 - # 2,添加公共事件(设置有随机物品)里的所有物品到随机物品 =>
 - #    XdRs_Ld.add_ld_event(event_id, type)
 - #    参数  event_id: 公共事件ID。
 - #          type    : 添加的类型(0:添加到普通物品; 1:添加到珍贵物品)
 - #    例:将 22 号公共事件里编辑的所有物品,添加到普通的随机物品中 =>
 - #        XdRs_Ld.add_ld_event(22, 0)
 - #        将 15 号公共事件里编辑的所有物品,添加到珍贵的随机物品中 =>
 - #        XdRs_Ld.add_ld_event(15, 1)
 - #--------------------------------------------------------------------------
 - # 3,将添加的公共事件里的所有物品从随机物品中删除 =>
 - #    XdRs_Ld.del_ld_event(event_id, type)
 - #    参数同第 2 条。
 - #--------------------------------------------------------------------------
 - # 4,清空所有第 2 条添加的公共事件 => XdRs_Ld.clear_ld_events
 - #--------------------------------------------------------------------------
 - # 5,清除系统所记忆的转盘物品 =>  XdRs_Ld.clear_ld_data
 - #--------------------------------------------------------------------------
 - # 6,更改抽奖所需的消耗品 => XdRs_Ld.change_consume(type, num1, num2)
 - #    参数  type: 消耗类型(0:金钱;1:物品)
 - #          num1: 数值1,消耗类型为 0(金钱)时,写所需的金钱数;
 - #                       消耗类型为 1(物品)时,写物品ID。
 - #          num2: 数值2,消耗类型为 0(金钱)时,省略不写;
 - #                       消耗类型为 1(物品)时,写所需的数量。
 - #    例:设置抽奖消耗金钱 500 => XdRs_Ld.change_consume(0, 500)
 - #        设置抽奖消耗 10 号物品 3 个 => XdRs_Ld.change_consume(1, 10, 3)
 - #==============================================================================
 - #==============================================================================
 - module XdRs_Ld
 - #==============================================================================
 - # ■ 设置项 ■
 - #==============================================================================
 - #--------------------------------------------------------------------------
 - # 游戏分辨率宽。
 - Graphics_Width = 640
 - #--------------------------------------------------------------------------
 - # 游戏分辨率高。
 - Graphics_Height = 480
 - #--------------------------------------------------------------------------
 - # 基本普通抽奖物品的公共事件ID。
 - Base_Ordinary = 10
 - #--------------------------------------------------------------------------
 - # 基本珍贵抽奖物品的公共事件ID。
 - Base_Precious = 11
 - #--------------------------------------------------------------------------
 - # 转盘出现珍贵物品的概率百分比。
 - Precious_Rate = 10
 - #--------------------------------------------------------------------------
 - # 金钱图标名。
 - Gold_Icon = "035-Item04"
 - #--------------------------------------------------------------------------
 - # 得到奖品时播放的动画ID。
 - Award_Anm = 46
 - #--------------------------------------------------------------------------
 - # 指针转动时,播放的SE。
 - Needle_Se = "041-Knock02"
 - #--------------------------------------------------------------------------
 - end
 - #==============================================================================
 - # ■ 脚本正文 ■
 - #==============================================================================
 - module XdRs_Ld
 -   #--------------------------------------------------------------------------
 -   defself.ui_name
 -     return"Ui_LotteryDraw"    #UI图片名
 -   end
 -   #--------------------------------------------------------------------------
 -   # 闪烁灯位置
 -   #--------------------------------------------------------------------------
 -   defself.lamp_place(index)
 -     return[[201,21],[264,70],[289,156],[263,234],[196,283],[101,282],
 -     [31,222],[11,144],[39,67],[103,18]][index]
 -   end
 -   #--------------------------------------------------------------------------
 -   # 物品图标位置
 -   #--------------------------------------------------------------------------
 -   defself.item_place(index)
 -     return[[182,52],[230,92],[250,150],[230,210],[182,248],[120,248],
 -     [68,210],[46,150],[68,92],[120,52]][index]
 -   end
 -   #--------------------------------------------------------------------------
 -   defself.has_ld_items
 -     data = [[Base_Ordinary], [Base_Precious]]
 -     data[0] += $game_system.ld_data[0]
 -     data[1] += $game_system.ld_data[1]
 -     return data.any?{|d| self.type_has_ld_items(d)}
 -   end
 -   #--------------------------------------------------------------------------
 -   defself.type_has_ld_items(data)
 -     return data.any?{|id| self.ld_list(id).size > 0}
 -   end
 -   #--------------------------------------------------------------------------
 -   defself.ld_items
 -     data = []
 -     base = [[Base_Ordinary], [Base_Precious]]
 -     data[0] = self.type_items(0, base) + self.type_items(0, $game_system.ld_data)
 -     data[1] = self.type_items(1, base) + self.type_items(1, $game_system.ld_data)
 -     return data
 -   end
 -   #--------------------------------------------------------------------------
 -   defself.type_items(type, data)
 -     items = []
 -     data[type].size.timesdo |i|
 -       list = self.ld_list(data[type][i])
 -       list.each{|l| items 100
 -   end
 -   #--------------------------------------------------------------------------
 -   defself.can_ld_start
 -     cst = $game_system.consumption_data
 -     return$game_party.gold >= cst[1][0]if cst[0] == "gold"
 -     return$game_party.item_number(cst[1][0]) >= cst[1][1]
 -   end
 -   #--------------------------------------------------------------------------
 -   defself.deductible
 -     cst = $game_system.consumption_data
 -     tp = cst[0]; d = cst[1][0]; n = cst[1][1]
 -     tp == "gold" ? $game_party.lose_gold(d) : $game_party.gain_item(d, -n)
 -   end
 -   #--------------------------------------------------------------------------
 -   defself.start_lottery_draw
 -     unlessself.has_ld_items
 -       $game_temp.message_text = "没有抽奖物品,暂时无法抽奖!"
 -       return
 -     end
 -     $scene = Lottery_Draw.new
 -   end
 -   #--------------------------------------------------------------------------
 -   defself.add_ld_event(event_id, type=0)
 -     returnif type > 1
 -     $game_system.set_ld_events(event_id, "add", type)
 -   end
 -   #--------------------------------------------------------------------------
 -   defself.del_ld_event(event_id, type=0)
 -     returnif type > 1
 -     $game_system.set_ld_events(event_id, "del", type)
 -   end
 -   #--------------------------------------------------------------------------
 -   defself.clear_ld_data
 -     $game_system.save_ld_items([])
 -   end
 -   #--------------------------------------------------------------------------
 -   defself.clear_ld_events
 -     $game_system.clear_all_ld_events
 -   end
 -   #--------------------------------------------------------------------------
 -   defself.change_consume(type, num1, num2=0)
 -     returnif type == 0 && num1  0 ? @count -= 1 : start_twinkle
 -   end
 - end
 - #==============================================================================
 - # 白色转幕
 - #==============================================================================
 - class XdRs_LdCurtain < XdRs_UiBase
 -   #--------------------------------------------------------------------------
 -   def initialize(x, y)
 -     super(x, y, XdRs_Ld.ui_name, Rect.new(495,48,78,128))
 -     self.ox = @rect.width / 2
 -     self.oy = @rect.height
 -     @index = rand10
 -     start_turn
 -   end
 -   #--------------------------------------------------------------------------
 -   def start_turn
 -     @count = 0
 -     self.angle = 360 - (@index * 36 + 18)
 -     @index = (@index+1) % 10
 -   end
 -   #--------------------------------------------------------------------------
 -   def update
 -     super
 -     update_turn
 -   end
 -   #--------------------------------------------------------------------------
 -   def update_turn
 -     returnunlessself.visible
 -     @count < 10 ? @count += 1 : start_turn
 -   end
 - end
 - #==============================================================================
 - # 转针
 - #==============================================================================
 - class XdRs_LdNeedle < XdRs_UiBase
 -   #--------------------------------------------------------------------------
 -   def initialize(x, y)
 -     super(x, y, XdRs_Ld.ui_name, Rect.new(381,48,114,150))
 -     self.ox = @rect.width / 2
 -     self.oy = 93
 -     @index = rand10
 -     @count = @speed = 0
 -     @is_start = false
 -     self.angle = 360 - (@index * 36 + 18)
 -   end
 -   #--------------------------------------------------------------------------
 -   def start
 -     returnif@is_start
 -     add = rand100
 -     @count = (rand(2) == 0 ? add : -add) + 200
 -     @is_start = true
 -   end
 -   #--------------------------------------------------------------------------
 -   def index;        return@index;     end
 -   #--------------------------------------------------------------------------
 -   def in_rotation;  return@is_start;  end
 -   #--------------------------------------------------------------------------
 -   def refresh_angle
 -     play_se(XdRs_Ld::Needle_Se)
 -     @index = (@index+1) % 10
 -     self.angle = 360 - (@index * 36 + 18)
 -     @speed = [(300 - @count) / 50, 1].max
 -   end
 -   #--------------------------------------------------------------------------
 -   def update
 -     super
 -     update_turn
 -   end
 -   #--------------------------------------------------------------------------
 -   def update_turn
 -     returnif !self.visible || !@is_start
 -     @count -= 1if@count > 0
 -     @speed -= 1if@speed > 0
 -     @speed == 0 && refresh_angle
 -     @is_start = falseif@count == 0
 -   end
 - end
 - #==============================================================================
 - # 奖品显示
 - #==============================================================================
 - class XdRs_LdPrize < XdRs_UiBase
 -   #--------------------------------------------------------------------------
 -   def initialize
 -     x = XdRs_Ld::Graphics_Width / 2
 -     y = XdRs_Ld::Graphics_Height / 2
 -     super(x, y, "", Rect.new(0,0,300,300))
 -     self.ox = @drawing_board.ox = 150
 -     self.oy = @drawing_board.oy = 150
 -     show_prize
 -   end
 -   #--------------------------------------------------------------------------
 -   def show_prize(prize=nil)
 -     hide; clear
 -     returnif !prize
 -     play_anm(XdRs_Ld::Award_Anm)
 -     image = XdRs_Ld.ui_name
 -     blt(50, 80, Rect.new(300, 255, 200, 45), image)
 -     blt(125, 140, Rect.new(381, 198, 50, 50), image)
 -     ix = (50 - icon_size) / 2
 -     draw_icon(125+ix, 140+ix, prize.icon_name)
 -     draw_text(0, 200, 300, 24, prize.name, 1)
 -     show
 -   end
 - end
 - #==============================================================================
 - # 抽奖场景
 - #==============================================================================
 - class Lottery_Draw
 -   #--------------------------------------------------------------------------
 -   def main
 -     init_data
 -     create_all
 -     start
 -     Graphics.transition
 -     loopdo
 -       Graphics.update; Input.update; update
 -       breakif$scene != self
 -     end
 -     Graphics.freeze
 -     dispose_all
 -   end
 -   #--------------------------------------------------------------------------
 -   def init_data
 -     @process = 0
 -     @all_items = XdRs_Ld.ld_items
 -   end
 -   #--------------------------------------------------------------------------
 -   def create_all
 -     @lamps = []
 -     x = (XdRs_Ld::Graphics_Width - 300) / 2
 -     y = (XdRs_Ld::Graphics_Height - 300) / 2
 -     cy = y + 304; hx = x + 150; hy = y + 150
 -     rect1 = Rect.new(300,48,81,79); rect2 = Rect.new(300,127,81,79)
 -     @map_bg     = Spriteset_Map.new
 -     @turntable  = XdRs_UiBase.new(x, y, XdRs_Ld.ui_name,Rect.new(0,0,300,300))
 -     @consume    = XdRs_UiBase.new(x, cy, XdRs_Ld.ui_name,Rect.new(300,0,300,48))
 -     @curtain    = XdRs_LdCurtain.new(hx, hy)
 -     @needle     = XdRs_LdNeedle.new(hx, hy)
 -     @button     = XdRs_Button.new(hx, hy, XdRs_Ld.ui_name, rect1, rect2)
 -     @prize_show = XdRs_LdPrize.new
 -     10.times{|i| @lamps  0 ? rand(10) : nil
 -     can_repeat = (@all_items[0] + @all_items[1]).size < 10
 -     while data.size < 10
 -       item = rand_item(is_precious(p_index, data) ? 1 : 0)
 -       item && (can_repeat || !data.include?(item)) && data.push(item)
 -     end
 -     $game_system.save_ld_items(data)
 -     return data
 -   end
 -   #--------------------------------------------------------------------------
 -   def is_precious(index, data)
 -     returnrand(100) < XdRs_Ld::Precious_Rate || index && index == data.size
 -   end
 -   #--------------------------------------------------------------------------
 -   def rand_item(type)
 -     obj = @all_items[type]
 -     return obj[rand(obj.size)]
 -   end
 -   #--------------------------------------------------------------------------
 -   def draw_now_items
 -     @turntable.clear
 -     10.timesdo |i|
 -       nextunless@now_items[i]
 -       place = XdRs_Ld.item_place(i)
 -       x = place[0] - @turntable.icon_size / 2
 -       y = place[1] - @turntable.icon_size / 2
 -       @turntable.draw_icon(x,y,@now_items[i].obj.icon_name)
 -     end
 -   end
 -   #--------------------------------------------------------------------------
 -   def num_text(d)
 -     num1 = d[0] == "gold" ? $game_party.gold : $game_party.item_number(d[1][0])
 -     num2 = d[0] == "gold" ? d[1][0] : d[1][1]
 -     return num2.to_s + "/" + num1.to_s
 -   end
 -   #--------------------------------------------------------------------------
 -   def prize
 -     return@now_items[@needle.index].obj
 -   end
 -   #--------------------------------------------------------------------------
 -   def get_prize
 -     case prize
 -     whenRPG::Item   ;$game_party.gain_item(prize.id, 1)
 -     whenRPG::Weapon ;$game_party.gain_weapon(prize.id, 1)
 -     whenRPG::Armor  ;$game_party.gain_armor(prize.id, 1)
 -     end
 -   end
 -   #--------------------------------------------------------------------------
 -   def update
 -     update_windows
 -     send("process"+@process.to_s)
 -   end
 -   #--------------------------------------------------------------------------
 -   def update_windows
 -     @button.update
 -     @needle.update
 -     @curtain.update
 -     @prize_show.update
 -     @lamps.each{|l| l.update}
 -   end
 -   #--------------------------------------------------------------------------
 -   def process0
 -     Input.trigger?(Input::C) && ready_start
 -     Input.trigger?(Input::B) && return_to_map
 -   end
 -   #--------------------------------------------------------------------------
 -   def process1
 -     !@needle.in_rotation && end_rotation
 -   end
 -   #--------------------------------------------------------------------------
 -   def process2
 -     Input.trigger?(Input::C) && come_again
 -   end
 -   #--------------------------------------------------------------------------
 -   def ready_start
 -     @button.press
 -     if !XdRs_Ld.can_ld_start
 -       $game_system.se_play($data_system.buzzer_se)
 -       return
 -     end
 -     $game_system.se_play($data_system.decision_se)
 -     $game_system.save_ld_items([])
 -     XdRs_Ld.deductible
 -     refresh_demand
 -     @needle.start
 -     @curtain.hide
 -     @lamps.each{|l| l.hide}
 -     @process = 1
 -   end
 -   #--------------------------------------------------------------------------
 -   def end_rotation
 -     @prize_show.show_prize(prize)
 -     get_prize
 -     refresh_demand
 -     refresh_button
 -     @process = 2
 -   end
 -   #--------------------------------------------------------------------------
 -   def come_again
 -     $game_system.se_play($data_system.decision_se)
 -     @prize_show.show_prize
 -     @curtain.show
 -     @lamps.each{|l| l.show}
 -     refresh_items
 -     @process = 0
 -   end
 -   #--------------------------------------------------------------------------
 -   def return_to_map
 -     $game_system.se_play($data_system.cancel_se)
 -     $scene = Scene_Map.new
 -   end
 - end
 - #==============================================================================
 - # end
 - #==============================================================================
 
  复制代码 
〓 范例工程 〓
             本帖来自P1论坛作者芯☆淡茹水,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址: https://rpg.blue/forum.php?mod=viewthread&tid=410955  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。  |   
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
 
		
		
		 
 
 |