ミニゲーム:スロットマシーン in VXA



どこにでもありそうなスロットマシーンのスクリプトです。

SceneManager.call(Scene_Slot)
にてゲーム開始。

ミニゲーム用共通処理モジュール in VXAが必要です。

ゲーム内部で使用する画像は
Graphics/Pictures
にインポートしてください。

変更点
2013:06:16
・所持金ベット方式と変数ベット方式を選択可能に

#==============================================================================
# ミニゲーム:スロットマシーン in VX Ace By 貪藻矢射妥←
#------------------------------------------------------------------------------
# いわゆるどこにでもありがちなスロットマシーンのスクリプト。
# 
# SceneManager.call(Scene_Slot)
# にてゲームを開始できます。
# 
# 外部カスタマイズポイントについて
# シーンをスロットに移す前に以下を設定することでスロットマシーンの難易度などを
# 変更することが可能です。(設定しなくともプレイは可能です。)
# 
# EX)
# $game_system.get_rate = [3, 1]
#  →大当たり/当たり時の掛け金基本倍率
# $game_system.slot_opt = 2
#  →1列/複数列の選択を可能にするかどうか
#    (0:真ん中1列のみ, 1:3列, 2:3列+斜め)
# $game_system.get_rate_line = [1.1, 0.6, 0.3]
#  →複数列選択可能時の賭け金倍率
# $game_system.slot_wait = 3
#  →スロットマシーンの絵柄が変わるまでの時間
# 
# ※ちなみに、普通のカスタマイズポイントにしてないのは、数種類のスロットマシーン
#  を設定したい際にスクリプトをコピペして使用しなくてもいいようにとの配慮です。
#==============================================================================
# 変更履歴
# 2013:06:16
# ・所持金ベット方式と変数ベット方式を選択可能に

module SLOT
  include BM
  # スロットの絵柄
  CARD_ROOT="slot_set_vxa"
  # スロット一枚のサイズ
  TR_WIDTH  = 64
  TR_HEIGHT = 77
  # 外側部分の画像
  PIC_ROOT="slot_pic"
  # 一枚のサイズ
  SP_WIDTH  = 75
  SP_HEIGHT = 35
  # ベット方式
  SLOT_BET_TYPE = MINI_GAME::MG_BET_TYPE_COIN
  
  #--------------------------------------------------------------------------
  # スロットセッティング
  #--------------------------------------------------------------------------
  def set_slot
    $sl_pic = []
    for i in 0...10
      $sl_pic[i] = Rect.new(i * TR_WIDTH, 0, TR_WIDTH, TR_HEIGHT)
    end
    
    $game_pic = []
    for i in 0...5
      $game_pic[i] = Rect.new(0, i * SP_HEIGHT, SP_WIDTH, SP_HEIGHT)
    end
  end
  
  # 賭け金基本レート(スロットの絵柄の数-1分設定)
  SL_RATE = [5.0 ,4.5 ,4.0 ,3.5 ,3.0 ,2.5 ,2.0 ,1.5 ,1.0]
  
  # スロットを終える時に外部カスタマイズポイントをnilに戻すか?
  SLOT_END_FLAG = true
end

class Game_System
  #--------------------------------------------------------------------------
  # ● 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_accessor :get_rate                 # 賭け金倍率
  attr_accessor :slot_opt                 # ラインセレクト
  attr_accessor :get_rate_line            # ラインによる賭け金倍率
  attr_accessor :slot_wait                # スロットの回転ウェイト
end

class Scene_Slot < Scene_Minigame_Base
  include SLOT
  include MINI_GAME
  #--------------------------------------------------------------------------
  # ● 上下の描画倍率
  #--------------------------------------------------------------------------
  def draw_rate
    60
  end
  #--------------------------------------------------------------------------
  # ● 上の段の描画位置
  #--------------------------------------------------------------------------
  def set_y1
    35
  end
  #--------------------------------------------------------------------------
  # ● 真ん中の段の描画位置
  #--------------------------------------------------------------------------
  def set_y2
    set_y1 + (TR_HEIGHT * draw_rate / 100.0).to_i + 10
  end
  #--------------------------------------------------------------------------
  # ● 下の段の描画位置
  #--------------------------------------------------------------------------
  def set_y3
    set_y2 + TR_HEIGHT + 10
  end
  #--------------------------------------------------------------------------
  # ● スロットマシーン初期化
  #--------------------------------------------------------------------------
  def slot_init(flg = true)
    @slot_flg = false
    @three_flg = false
    @stop_flg = [false, false, false]
    @bet_gold = 0
    @index = 0
    @slot = [[9, 9, 9], [9, 9, 9], [9, 9, 9]]
    set_slot
    if flg == true
      draw_slot
      draw_sl_pics
    end
  end
  #--------------------------------------------------------------------------
  # ● スロットマシーンの外側部分描画
  # opacity : 透明度のリスト
  #--------------------------------------------------------------------------
  def draw_sl_pics(opacity = [160, 160, 160, 160, 160])
    @slot_window2.contents.clear
    
    y_list = [set_y2 + TR_HEIGHT / 2 - SP_HEIGHT / 2,
              set_y1, 
              set_y3 + (TR_HEIGHT * draw_rate / 100.0).to_i - SP_HEIGHT,
              set_y1 - SP_HEIGHT > 0 ? set_y1 - SP_HEIGHT : 0, 
              set_y3 + (TR_HEIGHT * draw_rate / 100.0).to_i]
    
    for i in 0...$game_system.slot_opt * 2 + 1
      dest_src = Rect.new(10, y_list[i], SP_WIDTH, SP_HEIGHT)
      @slot_window2.contents.stretch_blt(dest_src, Cache.picture(PIC_ROOT), 
                                         $game_pic[i], opacity[i])
    end
    
    for i in 0...3
      fil_rect = Rect.new(20 + SP_WIDTH, y_list[i] + SP_HEIGHT / 2, 248, 2)
      @slot_window2.contents.fill_rect(fil_rect, Color.new(196, 196, 128, 200))
    end
  end
  #--------------------------------------------------------------------------
  # ● グラフィックの描画
  # 
  # card    : 表示カード
  # x       : 表示x座標
  # y       : 表示y座標
  # height  : 表示高さ倍率
  # set     : 上下カット(0:カットなし, 1:下カット, 2:上カット)
  # opacity : 透明度
  #--------------------------------------------------------------------------
  def draw_card(card, x, y, height = 100, set = 0, opacity = MAX8BIT)
    case set
    when 0
      src_rect = card.dup
    when 1
      src_rect = Rect.new(card.x, card.y + 16, card.width, card.height - 16)
    when 2
      src_rect = Rect.new(card.x, card.y, card.width, card.height - 16)
    end
    
    @slot_window.contents.stretch_blt(Rect.new(x, y, TR_WIDTH, TR_HEIGHT * height / 100), 
                                      Cache.picture(CARD_ROOT), 
                                      src_rect, opacity)
  end
  #--------------------------------------------------------------------------
  # ● スロットマシーンの絵柄表示
  #--------------------------------------------------------------------------
  def draw_slot
    @slot_window.contents.clear
    
    draw_card($sl_pic[@slot[0][0]],   0 + 124 - 17, set_y1, draw_rate, 1)
    draw_card($sl_pic[@slot[1][0]],  80 + 124 - 17, set_y1, draw_rate, 1)
    draw_card($sl_pic[@slot[2][0]], 160 + 124 - 17, set_y1, draw_rate, 1)
    
    draw_card($sl_pic[@slot[0][1]],   0 + 124 - 17, set_y2)
    draw_card($sl_pic[@slot[1][1]],  80 + 124 - 17, set_y2)
    draw_card($sl_pic[@slot[2][1]], 160 + 124 - 17, set_y2)
    
    draw_card($sl_pic[@slot[0][2]],   0 + 124 - 17, set_y3, draw_rate, 2)
    draw_card($sl_pic[@slot[1][2]],  80 + 124 - 17, set_y3, draw_rate, 2)
    draw_card($sl_pic[@slot[2][2]], 160 + 124 - 17, set_y3, draw_rate, 2)
  end
  #--------------------------------------------------------------------------
  # ● スロット絵柄
  #--------------------------------------------------------------------------
  def change_slot(id)
    if @card[id] == $game_system.slot_wait
      @slot[id].delete_at(0)
      #@slot[id].push(0)
      @slot[id].push(rand(9))
      @card[id] = 0
    end
    @card[id] += 1
  end
  #--------------------------------------------------------------------------
  # ● スロットマシーン結果判定
  #--------------------------------------------------------------------------
  def judg_slot
    total_rate = 0
    opa_list = [160, 160, 160, 160, 160]
    
    if @slot[0][1] == @slot[1][1] && @slot[1][1] == @slot[2][1]
      total_rate += Integer($game_system.get_rate_line[$game_system.slot_opt] * 
                            $game_system.get_rate[0] * SL_RATE[@slot[0][1]])
      opa_list[0] = MAX8BIT
      draw_sl_pics(opa_list)
    end
    if @slot[0][1] == @slot[1][1] || @slot[1][1] == @slot[2][1]
      total_rate += Integer($game_system.get_rate_line[$game_system.slot_opt] * 
                            $game_system.get_rate[1] * SL_RATE[@slot[1][1]])
      opa_list[0] = MAX8BIT
      draw_sl_pics(opa_list)
    end
    if $game_system.slot_opt >= 1
      if @slot[0][0] == @slot[1][0] && @slot[1][0] == @slot[2][0]
        total_rate += Integer($game_system.get_rate_line[$game_system.slot_opt] * 
                              $game_system.get_rate[0] * SL_RATE[@slot[0][0]])
      opa_list[1] = MAX8BIT
      draw_sl_pics(opa_list)
      end
      if @slot[0][2] == @slot[1][2] && @slot[1][2] == @slot[2][2]
        total_rate += Integer($game_system.get_rate_line[$game_system.slot_opt] * 
                              $game_system.get_rate[0] * SL_RATE[@slot[0][2]])
      opa_list[2] = MAX8BIT
      draw_sl_pics(opa_list)
      end
      if @slot[0][0] == @slot[1][0] || @slot[1][0] == @slot[2][0]
        total_rate += Integer($game_system.get_rate_line[$game_system.slot_opt] * 
                              $game_system.get_rate[1] * SL_RATE[@slot[0][0]])
      opa_list[1] = MAX8BIT
      draw_sl_pics(opa_list)
      end
      if @slot[0][2] == @slot[1][2] || @slot[1][2] == @slot[2][2]
        total_rate += Integer($game_system.get_rate_line[$game_system.slot_opt] * 
                              $game_system.get_rate[1] * SL_RATE[@slot[0][2]])
      opa_list[2] = MAX8BIT
      draw_sl_pics(opa_list)
      end
    end
    if $game_system.slot_opt == 2
      if @slot[0][0] == @slot[1][1] && @slot[1][1] == @slot[2][2]
        total_rate += Integer($game_system.get_rate_line[$game_system.slot_opt] * 
                              $game_system.get_rate[0] * SL_RATE[@slot[1][1]])
      opa_list[3] = MAX8BIT
      draw_sl_pics(opa_list)
      end
      if @slot[0][2] == @slot[1][1] && @slot[1][1] == @slot[2][0]
        total_rate += Integer($game_system.get_rate_line[$game_system.slot_opt] * 
                              $game_system.get_rate[0] * SL_RATE[@slot[1][1]])
      opa_list[4] = MAX8BIT
      draw_sl_pics(opa_list)
      end
    end
    if total_rate == 0
      total_rate = -1
    end
    gets_gold = total_rate * @bet_gold
    if gets_gold > MAX_GOLD
      gets_gold = MAX_GOLD
    end
    
    if gets_gold > 0
      get_lost_gold_coin(gets_gold, MG_GOLDCOIN_GET, SLOT_BET_TYPE)
      text = GET_GOLD[SLOT_BET_TYPE] + gets_gold.to_s
      @info_window.refresh(text)
      if gets_gold > @bet_gold * $game_system.get_rate[0] * ($game_system.slot_opt + 1)
        JACK_POT_ME4.play
      else
        JACK_POT_ME6.play
      end
    else
      get_lost_gold_coin(@bet_gold, MG_GOLDCOIN_LOST, SLOT_BET_TYPE)
      text = LOST_GOLD[SLOT_BET_TYPE] + @bet_gold.to_s
      @info_window.refresh(text)
      LOOSE_ME.play
    end
    
    @bet_gold = 0
    @bet_window.refresh(@bet_gold)
    @gold_window.refresh
  end
  
  #--------------------------------------------------------------------------
  # ● 開始処理
  #--------------------------------------------------------------------------
  def start
    super
    create_minigame_window(SLOT_BET_TYPE)
    
    # スロットマシンメインウィンドウ
    @slot_window  = Window_Base.new(0, 48, 384, 272 + 8)
    @slot_window2 = Window_Base.new(0, 48, 384, 272 + 8)
    
    @slot_window2.windowskin = nil
    
    # スロットマシン初期化
    @card = [0, 0, 0]
    
    # 外部カスタマイズポイントの設定(未設定の場合)
    if $game_system.get_rate == nil
      $game_system.get_rate = [2.5, 1.5]
    end
    if $game_system.slot_opt == nil
      $game_system.slot_opt = 0
    end
    if $game_system.get_rate_line == nil
      $game_system.get_rate_line = [1, 0.8, 0.6]
    end
    if $game_system.slot_wait == nil
      $game_system.slot_wait = 6
    end
    
    set_keyhelp1
    
    slot_init
    @bet_window.refresh(@bet_gold)
    @title_window.refresh("スロットマシーン")
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新(基本)
  #--------------------------------------------------------------------------
  def update_basic
    super
    if @slot_flg == true
      if @three_flg == false
        @slot = [[rand(9), rand(9), rand(9)], 
                 [rand(9), rand(9), rand(9)], 
                 [rand(9), rand(9), rand(9)]]
        @three_flg = true
      end
    end
      
    if @three_flg == true
      for id in 0..2
        if @stop_flg[id] == false
          change_slot(id)
        end
      end
      draw_slot
    end
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    super
    if @slot_window.active
      update_main
    end
    if @value_window.active
      update_value
    end
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新 (メインウィンドウがアクティブの場合)
  #--------------------------------------------------------------------------
  def update_main
    # B ボタンが押された場合
    if Input.trigger?(:B)
      # キャンセル SE を演奏
      Sound.play_cancel
      #$game_system.windowskin_name = WINDOW_SKIN_ROOT
      if SLOT_END_FLAG
        $game_system.get_rate = nil
        $game_system.slot_opt = nil
        $game_system.get_rate_line = nil
        $game_system.slot_wait = nil
      end
      return_scene
      return
    end
    # A ボタンが押された場合
    if Input.trigger?(:A)
      # 決定 SE を演奏
      Sound.play_ok
      # 念の為
      draw_slot
      draw_sl_pics
      value_window_activate
      
      @value_window.number = @bet_gold
      
      @slot_window.deactivate
      set_keyhelp3
      return
    end
    # C ボタンが押された場合
    if Input.trigger?(:C)
      if @bet_gold == 0
        # エラー SE を演奏
        ERROR_SE.play
        #@info_window.contents.clear
        text =  "まずは" + MG_ERR_BET_ZERO[SLOT_BET_TYPE]
        @info_window.refresh(text)
      else
        # 決定 SE を演奏
        Sound.play_ok
        @info_window.refresh("")
        if !@slot_flg
          @slot_flg = true
          set_keyhelp2
        elsif @slot_flg
          if !@stop_flg[0]
            @stop_flg[0] = true
          elsif !@stop_flg[1]
            @stop_flg[1] = true
          elsif !@stop_flg[2]
            @stop_flg[2] = true
          end
        end
        if @stop_flg[2]
          judg_slot
          slot_init(false)
          set_keyhelp1
        end
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新 (バリューウィンドウがアクティブの場合)
  #--------------------------------------------------------------------------
  def update_value
    # C ボタンが押された場合
    if Input.trigger?(:C)
      if (MG_BET_TYPE_GOLD == SLOT_BET_TYPE && @bet_gold > $game_party.gold) ||
        (MG_BET_TYPE_COIN == SLOT_BET_TYPE && @bet_gold > $game_variables[MG_COIN_INDEX])
        # エラー SE を演奏
        ERROR_SE.play
        @info_window.refresh(MG_ERR_BET_UPPER[SLOT_BET_TYPE])
      elsif @bet_gold == 0
        # エラー SE を演奏
        ERROR_SE.play
        @info_window.refresh(MG_ERR_BET_ZERO[SLOT_BET_TYPE])
      else
        # 決定 SE を演奏
        Sound.play_ok
        @info_window.refresh("")
        value_window_deactivate
        @slot_window.activate
        @bet_window.refresh(@bet_gold)
        set_keyhelp1
      end
      return
    end
    # B ボタンが押された場合
    if Input.trigger?(:B)
      # キャンセル SE を演奏
      Sound.play_cancel
      value_window_deactivate
      @slot_window.activate
      set_keyhelp1
      return
    end
    @bet_gold = @value_window.number
  end
  
  #--------------------------------------------------------------------------
  # ○ キーヘルプを設定
  #--------------------------------------------------------------------------
  def set_keyhelp1
    @bottomkeyhelp_window.clear
    @bottomkeyhelp_window.set_bottom_help({"B"=>"キャンセル", 
                                           "A"=>"コインベット", 
                                           "C"=>"ゲームスタート"})
  end
  #--------------------------------------------------------------------------
  # ○ キーヘルプを設定 2
  #--------------------------------------------------------------------------
  def set_keyhelp2
    @bottomkeyhelp_window.clear
    @bottomkeyhelp_window.set_bottom_help({"C"=>"ストップ", 
                                           "B"=>"キャンセル"})
  end
  #--------------------------------------------------------------------------
  # ○ キーヘルプを設定 3
  #--------------------------------------------------------------------------
  def set_keyhelp3
    @bottomkeyhelp_window.clear
    @bottomkeyhelp_window.set_bottom_help({"矢印"=>"ベット", 
                                           "C"   =>"決定", 
                                           "B"   =>"キャンセル"})
  end
end
こぉんな感じになります。 使用画像はこちらにありマス カスタマイズポイントの設定
外部カスタマイズポイント
変数 設定例 説明
$game_system.get_rate [3, 1] 大当たり/当たり時の掛け金基本倍率
$game_system.slot_opt 2 1列/複数列の選択を可能にするかどうか
(0:真ん中1列のみ, 1:3列, 2:3列+斜め)
$game_system.get_rate_line [1.1, 0.6, 0.3] 複数列選択可能時の賭け金倍率
$game_system.slot_wait 3 スロットマシーンの絵柄が変わるまでの時間
内部カスタマイズポイント(一部省略)
変数 設定例 説明
SL_RATE [5.0 ,4.5 ,4.0 ,3.5 ,3.0 ,2.5 ,2.0 ,1.5 ,1.0] 賭け金基本レート(スロットの絵柄の数-1分設定)
MAX_DIG 7 入力金額最高桁数
SLOT_END_FLAG true スロットを終える時に外部カスタマイズポイントをnilに戻すか?

戻る