#◆◇◆◇◆ コードブレイカー ver 1.01 ◇◆◇◆◇ # 全マスタースクリプト共通スクリプト # 開発者用・高速数字描写機構 ver 1.11 以降必須 # サポート掲示板 http://www2.ezbbs.net/21/minto-aaa/ # by みんと =begin ■ 更新履歴 ○ ver 1.01(2011/09/30) 単体で動かなかったミスを修正 ○ ver 1.00(2011/08/19) 公開 ■ 説明 ミニゲーム「コードブレイカー」が遊べるようになります。 コードブレイカーを実行するにはイベントコマンドのスクリプトで $scene = Scene_CodeBeakar.new(ante, type) と入力してください。 anteは1プレイに使うコイン(ゴールドではありません)の枚数、 typeは景品のパターンタイプです。 $scene = Scene_CodeBeakar.new(100, 0)なら、 1プレイ100コインで、景品タイプ0番と言う事になります。 なお、コインそのものの入手は別途イベントを組む必要があります。 例 指定した変数をコインの枚数に加算したい場合 $game_party.gain_coin($game_variables[id]) となります。 数値入力の処理などを使ってコインを買うイベントを組むと良いでしょう。 コインそのものは $game_party.coin で取得が可能です。 ● 基本ルール コードブレイカーはパネルに隠された1〜9までの数値を当てるゲームです。 正解までの回数が少ないほど景品は豪華にした方がよいでしょう。 概ね、正解までにかかるトライ回数は人にもよりますが4〜5回です。 記号のH(ヒット)はその列に当たりが存在し、 なお且つ位置もあっている事を意味し、 B(ブロー)はその列に当たりはあるが、位置が違う事を意味します。 ● 基本操作 Cボタン(Cキー)・・・パネルを進ませる Bボタン(Xキー)・・・パネルを戻す Aボタン(Zキー)・・・マーキング ● デバッグ機能 テストプレイ中の場合、 F9を押す事で正解が表示されます。 景品の設定などはソース内部を参照してください。 =end #============================================================================== # ☆ MINTO #------------------------------------------------------------------------------ # 様々なフラグを扱うメインモジュールです。 #============================================================================== module MINTO # コードブレイカーを有効化 ( true で有効 / false で無効 ) RGSS["コードブレイカー"] = true end # コードブレイカーが有効な場合に以降の処理を実行する if MINTO::RGSS["コードブレイカー"] == true then #============================================================================== # ☆ カスタマイズ #------------------------------------------------------------------------------ # 機能のカスタマイズをここで行います。 #============================================================================== class Scene_CodeBeakar #-------------------------------------------------------------------------- # ● キーガイドの表記タイプ( "ゲームパッド" / "キーボード" ) #-------------------------------------------------------------------------- def self.key_guide return "キーボード" end #-------------------------------------------------------------------------- # ● サウンドエフェクトの演奏 # title : サウンドエフェクトのタイトル #-------------------------------------------------------------------------- def sound_call(title) # タイトルに応じて分岐 case title when "チェック" # 実際のサウンド(SE)を演奏(フルパス) Audio.se_play("Audio/SE/020-Teleport03") when "大当たり" # 実際のサウンド(ME)を演奏(フルパス) Audio.me_play("Audio/ME/009-Fanfare03") when "当たり" # 実際のサウンド(ME)を演奏(フルパス) Audio.me_play("Audio/ME/007-Fanfare01") when "失敗" # 実際のサウンド(ME)を演奏(フルパス) Audio.me_play("Audio/ME/012-Gag01") end end #-------------------------------------------------------------------------- # ● 挑戦回数の設定 #-------------------------------------------------------------------------- def set_challenge_count # 景品タイプに応じて分岐 case @present_type # 景品パターン1 when 0 # トライ回数をセット @try = 4 # 景品パターン2 when 1 # トライ回数をセット @try = 9 end @ori_try = @try end #-------------------------------------------------------------------------- # ● 景品の処理 # type : 0(景品表示), 1(景品獲得) #-------------------------------------------------------------------------- def present_effect(type) # 景品タイプに応じて分岐 case @present_type # 景品パターン1 when 0 # 実行内容に応じて分岐 case type # 景品表示 when 0 # トライ回数に応じて分岐 case (@ori_try - @try) when 0 return "お楽しみセット&30000コイン" when 1 return "ランダムドリンク&5000コイン" when 2 return "100コイン" when 3 return "10コイン" else return "はずれ" end # 景品獲得(実際の処理) when 1 # 実際の処理をスクリプトソースで入力してください。 # コインを増やしたい場合 $game_party.gain_coin(枚数) # アイテムを増やしたい場合 $game_party.gain_item(id, 個数) # 武器を増やしたい場合 $game_party.gain_weapon(id, 個数) # 防具を増やしたい場合 $game_party.gain_armor(id, 個数) # スクリプトに知識のある方は、必要に応じて処理を追加してください。 # トライ回数に応じて分岐 case (@ori_try - @try) when 0 $game_party.gain_item(1, 1) $game_party.gain_item(1, 2) $game_party.gain_item(1, 3) $game_party.gain_coin(30000) when 1 id = 14 + rand(10) $game_party.gain_item(id, 1) $game_party.gain_coin(5000) when 2 $game_party.gain_coin(100) when 3 $game_party.gain_coin(10) end end # 景品パターン2 when 1 # 実行内容に応じて分岐 case type # 景品表示 when 0 # トライ回数に応じて分岐 case (@ori_try - @try) when 0 return "お楽しみセット&300000コイン" when 1 return "ランダムドリンク3個&50000コイン" when 2 return "1000コイン" when 3 return "250コイン" when 4 return "100コイン" when 5 return "50コイン" when 6 return "40コイン" when 7 return "30コイン" when 8 return "20コイン" else return "はずれ" end # 景品獲得(実際の処理) when 1 # トライ回数に応じて分岐 case (@ori_try - @try) when 0 $game_party.gain_item(1, 1) $game_party.gain_item(1, 2) $game_party.gain_item(1, 3) $game_party.gain_coin(300000) when 1 3.times do id = 14 + rand(10) $game_party.gain_item(id, 1) end $game_party.gain_coin(50000) when 2 $game_party.gain_coin(1000) when 3 $game_party.gain_coin(250) when 4 $game_party.gain_coin(100) when 5 $game_party.gain_coin(50) when 6 $game_party.gain_coin(40) when 7 $game_party.gain_coin(30) when 8 $game_party.gain_coin(20) end end end end end #============================================================================== # ☆ SEPass #------------------------------------------------------------------------------ # 指定されたSEを実際のSEに変換して演奏するモジュールです。 #============================================================================== module SEPass #-------------------------------------------------------------------------- # ● SEの演奏 # title : SEタイトル #-------------------------------------------------------------------------- def self.call(title) case title when "決定" $game_system.se_play($data_system.decision_se) when "キャンセル" $game_system.se_play($data_system.cancel_se) when "ブザー" $game_system.se_play($data_system.buzzer_se) when "ショップ" $game_system.se_play($data_system.shop_se) end end end #============================================================================== # ■ Array #------------------------------------------------------------------------------ #  配列全般を扱う組み込みクラスです。 #============================================================================== class Array #-------------------------------------------------------------------------- # ● 要素のシャッフル #-------------------------------------------------------------------------- def shuffle # データを複製 data = self.dup # 要素をランダムに並び替える data.each_index do |i| j = rand(i+1) data[i], data[j] = data[j], data[i] end return data end #-------------------------------------------------------------------------- # ● 要素のシャッフル(破壊的) #-------------------------------------------------------------------------- def shuffle! # 要素をランダムに並び替える self.each_index do |i| j = rand(i+1) self[i], self[j] = self[j], self[i] end end end #============================================================================== # ■ Bitmap #------------------------------------------------------------------------------ #  画像そのものを扱う組み込みクラスです。 #============================================================================== class Bitmap #-------------------------------------------------------------------------- # ● キーアイコンの描写 # x : 描写先 X 座標 # y : 描写先 Y 座標 # key : 描写キー #-------------------------------------------------------------------------- def draw_key(x, y, key) # キーアイコンを読み込む icon = RPG::Cache.picture("Keys") # キーに応じて分岐 case key when "A" then rect = Rect.new(24 * 0, 24 * 0, 24, 24) when "B" then rect = Rect.new(24 * 1, 24 * 0, 24, 24) when "C" then rect = Rect.new(24 * 2, 24 * 0, 24, 24) when "X" then rect = Rect.new(24 * 0, 24 * 1, 24, 24) when "Y" then rect = Rect.new(24 * 1, 24 * 1, 24, 24) when "Z" then rect = Rect.new(24 * 2, 24 * 1, 24, 24) when "L" then rect = Rect.new(24 * 0, 24 * 2, 24, 24) when "R" then rect = Rect.new(24 * 1, 24 * 2, 24, 24) end # キーボード表記の場合 if Scene_CodeBeakar.key_guide == "キーボード" then # 転送座標をずらす rect.x += 24 * 3 end # 描写範囲を消す self.rect_clear(x, y, 24, 24) # アイコンを描写 self.blt(x, y, icon, rect) end #-------------------------------------------------------------------------- # ● 指定範囲のクリア #-------------------------------------------------------------------------- def rect_clear(x, y, width, height) # 対象の範囲を消す rect = Rect.new(x, y, width, height) self.fill_rect(rect, Color.new(0, 0, 0, 0)) end end #============================================================================== # ■ Numeric #------------------------------------------------------------------------------ #  数値全般を扱う組み込みクラスです。 #============================================================================== class Numeric #-------------------------------------------------------------------------- # ● 最大値の設定 # max : 求められた最大の数値 #-------------------------------------------------------------------------- def to_max(min, max) if self > max return max elsif self < min return min else return self end end #-------------------------------------------------------------------------- # ● 最大値の設定 # max : 求められた最大の数値 #-------------------------------------------------------------------------- def to_m(max) if self > max return max else return self end end #-------------------------------------------------------------------------- # ● 最小値の設定 # min : 求められた最小の数値 #-------------------------------------------------------------------------- def to_min(min) if self < min return min else return self end end end #============================================================================== # ■ Window #------------------------------------------------------------------------------ #  ゲーム内の全てのウィンドウのスーパークラスです。 # 内部的には複数のスプライトで構成されています。 #============================================================================== class Window #-------------------------------------------------------------------------- # ● ウィンドウのセンタリング #-------------------------------------------------------------------------- def centering # ウィンドウを画面の中央に配置する self.x = (640 - self.width) / 2 self.y = (480 - self.height) / 2 end end #============================================================================== # ■ Mint_Picture_Number #------------------------------------------------------------------------------ #  ピクチャー数字のスプライト表示を扱うクラスです。 # このクラスは数値の高速再描写に特化したクラスとなっています。 #============================================================================== class Mint_Picture_Number #-------------------------------------------------------------------------- # ● セットテキスト # number : 求められた数値 # collar : 求められたカラーインデックス #-------------------------------------------------------------------------- def set_text(number, collar = 0, align = 1) # 求められた文字を一文字ずつ配列にする text = number.to_s.split(//) # クリア行数 clear_index = text.size == 1 ? 1 : 0 # X座標を調整する x_size = @index - text.size # 求められた行数分繰り返す for i in 0...@index # クリア行数が0で求められた数字が0か、 # 元の数字が存在しなければなら次へ if clear_index == 0 and text[i].to_i == 0 or text[i] == nil @sprite[i].visible = false next end # スプライトを可視状態にする @sprite[i].visible = true # 描写範囲を取得 rect = Rect.new(text[i].to_i * @width, collar * @height, @width, @height) # アライメントに応じて分岐 case align when 0 # X座標を調整する(左寄せ) @sprite[i].x = @x.to_i + (i * @width) else # X座標を調整する(右寄せ) @sprite[i].x = @x.to_i + (i * @width) + (x_size * @width) end # 条件をクリアしていれば、クリア行数に1を加算 clear_index += 1 # 条件をクリアしていれば描写 @sprite[i].src_rect = rect end end end #============================================================================== # ■ CodeBreakar_Key #------------------------------------------------------------------------------ #  コードブレイカーのキーを管理するクラスです。 #============================================================================== class CodeBreakar_Key #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :key # 正解キー attr_accessor :hit # 的中の配列 attr_accessor :blow # かすりの配列 attr_accessor :play # 入力中のキー配列 #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize reset end #-------------------------------------------------------------------------- # ● キーの初期化 #-------------------------------------------------------------------------- def reset @key = [1, 2, 3, 4, 5, 6, 7, 8, 9].shuffle @hit = [0, 0, 0, 0, 0, 0] @blow = [0, 0, 0, 0, 0, 0] @play = [1, 1, 1, 1, 1, 1, 1, 1, 1] end #-------------------------------------------------------------------------- # ● 的中の取得 #-------------------------------------------------------------------------- def get_hit @hit = [0, 0, 0, 0, 0, 0] # 横1列目の判定 for i in [1, 2, 3] do # 入力キーと同一の場合 if @key[i - 1] == @play[i - 1] # 的中 @hit[0] += 1 end end # 横2列目の判定 for i in [4, 5, 6] do # 入力キーと同一の場合 if @key[i - 1] == @play[i - 1] # 的中 @hit[1] += 1 end end # 横3列目の判定 for i in [7, 8, 9] do # 入力キーと同一の場合 if @key[i - 1] == @play[i - 1] # 的中 @hit[2] += 1 end end # 縦1列目の判定 for i in [1, 4, 7] do # 入力キーと同一の場合 if @key[i - 1] == @play[i - 1] # 的中 @hit[3] += 1 end end # 縦2列目の判定 for i in [2, 5, 8] do # 入力キーと同一の場合 if @key[i - 1] == @play[i - 1] # 的中 @hit[4] += 1 end end # 縦3列目の判定 for i in [3, 6, 9] do # 入力キーと同一の場合 if @key[i - 1] == @play[i - 1] # 的中 @hit[5] += 1 end end end #-------------------------------------------------------------------------- # ● かすりの取得 #-------------------------------------------------------------------------- def get_blow @blow = [0, 0, 0, 0, 0, 0] # 横1列目の判定 for i in [1, 2, 3] do # 正解キーを一元化 answer = [@key[0], @key[1], @key[2]] # 正解キーを含んでいる場合 if answer.include?(@play[i - 1]) # かすり @blow[0] += 1 end end # 横2列目の判定 for i in [4, 5, 6] do # 正解キーを一元化 answer = [@key[3], @key[4], @key[5]] # 正解キーを含んでいる場合 if answer.include?(@play[i - 1]) # かすり @blow[1] += 1 end end # 横3列目の判定 for i in [7, 8, 9] do # 正解キーを一元化 answer = [@key[6], @key[7], @key[8]] # 正解キーを含んでいる場合 if answer.include?(@play[i - 1]) # かすり @blow[2] += 1 end end # 縦1列目の判定 for i in [1, 4, 7] do # 正解キーを一元化 answer = [@key[0], @key[3], @key[6]] # 正解キーを含んでいる場合 if answer.include?(@play[i - 1]) # かすり @blow[3] += 1 end end # 縦2列目の判定 for i in [2, 5, 8] do # 正解キーを一元化 answer = [@key[1], @key[4], @key[7]] # 正解キーを含んでいる場合 if answer.include?(@play[i - 1]) # かすり @blow[4] += 1 end end # 縦3列目の判定 for i in [3, 6, 9] do # 正解キーを一元化 answer = [@key[2], @key[5], @key[8]] # 正解キーを含んでいる場合 if answer.include?(@play[i - 1]) # かすり @blow[5] += 1 end end # ヒット分を減算 for i in 0...6 do @blow[i] -= @hit[i] end end #-------------------------------------------------------------------------- # ● 正解判定 #-------------------------------------------------------------------------- def bingo? return (@key == @play) end end #============================================================================== # ■ Game_Party #------------------------------------------------------------------------------ #  パーティを扱うクラスです。ゴールドやアイテムなどの情報が含まれます。このク # ラスのインスタンスは $game_party で参照されます。 #============================================================================== class Game_Party #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :coin # コイン #-------------------------------------------------------------------------- # ■ コインの増加 (減少) #-------------------------------------------------------------------------- def gain_coin(n) unless @coin.is_a?(Numeric) @coin = 0 end @coin = (@coin + n).to_max(0, 999999) end #-------------------------------------------------------------------------- # ■ コインの減少 #-------------------------------------------------------------------------- def lose_coin(n) # 数値を逆転して gain_coin を呼ぶ gain_coin(-n) end end #============================================================================== # ■ Window_Coin #------------------------------------------------------------------------------ #  カジノ画面でコインを表示するウィンドウです。 #============================================================================== class Window_Coin < Window_Base #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize super(64, 24, 256, 56) self.contents = Bitmap.new(width - 32, height - 32) self.opacity = 0 gwx = self.x + 24 gwy = self.y + 28 @gold = Mint_Picture_Number.new(gwx, gwy, 6, 999, 24, "string03") @last_gold = $game_party.coin.to_i @last_gold2 = $game_party.coin.to_i @last_gold3 = 0 @wait = 0 @gold.set_text(@last_gold, 0, 0) end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh # 更新フレームを初期化 @wait = 21 # 最終ゴールドを更新 @last_gold = @last_gold2.to_i end #-------------------------------------------------------------------------- # ● アクティブリフレッシュ #-------------------------------------------------------------------------- def active_refresh # 現在ゴールドと最終ゴールドが異なる場合 if $game_party.coin != @last_gold2 # 最終ゴールドと、現在ゴールドとの差を求める gap = @last_gold - $game_party.coin.to_i # 差分の絶対値が20超の場合 if gap.abs > 20 # 更新フレームが21の場合 if @wait == 21 # 差分を20で割った余りを引く @last_gold2 -= gap % 20 # 差分がマイナスの場合 if gap < 0 # 最終ゴールド3に最終ゴールドを代入 @last_gold3 = @last_gold.abs end end end # 最終ゴールドと現在ゴールドの差を求める gap = (@last_gold - $game_party.coin) # 最終ゴールド3が設定されている場合 if @last_gold3 != 0 # 最終ゴールド2が最終ゴールド3以上になるまで繰り返す while @last_gold3 > @last_gold2 @last_gold2 -= gap / [gap.abs, 20].min end # 最終ゴールド3を初期化 @last_gold3 = 0 end # 差分を差分の絶対値で割った数で最終ゴールドを引く @last_gold2 -= gap / [gap.abs, 20].min # ゴールドの最終値を描写 @gold.set_text(@last_gold2, 0, 0) else # 最終ゴールドに現在ゴールドを設定 @last_gold = $game_party.coin.abs @last_gold2 = $game_party.coin.abs # 現在ゴールドを描写 @gold.set_text($game_party.coin.abs, 0, 0) end end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update # 更新フレームが設定されている場合 if @wait > 0 # アクティブリフレッシュ active_refresh # 更新カウントを減らす @wait -= 1 end end #-------------------------------------------------------------------------- # ● 解放 #-------------------------------------------------------------------------- def dispose # ゴールドを解放 @gold.dispose @gold = nil super end end #============================================================================== # ■ Window_CodeBeakar #------------------------------------------------------------------------------ #  コードブレイカー画面の数値を表示するウィンドウです。 #============================================================================== class Window_CodeBeakar < Window_Selectable #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :key # コードデータ #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize super(4, 132, 320, 320) self.contents = Bitmap.new(width - 32, height - 32) self.opacity = 0 self.index = 0 self.active = false self.windowskin = RPG::Cache.windowskin("002-BlackBlue") @item_max = 9 @column_max = 3 @last_index = 0 @key = CodeBreakar_Key.new # ビットマップ読み込み @bitmap = RPG::Cache.picture("Code_Number") # スプライトを作成 @sprite = Sprite.new @sprite.x = 22 @sprite.y = 98 @sprite.z = 100 @sprite.bitmap = RPG::Cache.picture("Code_Guide") @sprite.src_rect.set(0, 28, 256, 28) @sprites = [] @filter_sprites = [] for i in 0...9 @sprites[i] = Sprite.new @sprites[i].x = 22 + i * 28 @sprites[i].y = 98 @sprites[i].z = 100 @sprites[i].bitmap = RPG::Cache.picture("Code_Guide") @sprites[i].src_rect.set(i * 28, 28, 28, 28) @filter_sprites[i] = Sprite.new @filter_sprites[i].x = self.x + 16 @filter_sprites[i].y = self.y + 16 @filter_sprites[i].z = 999 @filter_sprites[i].bitmap = Bitmap.new(88, 88) @filter_sprites[i].visible = false end @keys = [] refresh update end #-------------------------------------------------------------------------- # ● 解放 #-------------------------------------------------------------------------- def dispose @bitmap.dispose @sprite.bitmap.dispose @sprite.dispose for i in 0...9 @sprites[i].dispose @filter_sprites[i].bitmap.dispose @filter_sprites[i].dispose end super end #-------------------------------------------------------------------------- # ● リセット #-------------------------------------------------------------------------- def reset # キーを初期化 @key.reset # キーを再描写 refresh # ウィンドウをアクティブにする self.active = true end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh self.contents.clear for i in 0...9 do draw_code_key(i) end end #-------------------------------------------------------------------------- # ● フィルターの描写 #-------------------------------------------------------------------------- def draw_filter index = self.index # カーソルの座標を計算 x = index % @column_max * 88 y = index / @column_max * 88 @filter_sprites[index].x = self.x + 20 + x @filter_sprites[index].y = self.y + 19 + y # フィルター描写 color = Color.new(192, 0, 255, 160) @filter_sprites[index].bitmap.fill_rect(0, 0, 76, 74, color) # 表示反転 @filter_sprites[index].visible = (not @filter_sprites[index].visible) end #-------------------------------------------------------------------------- # ● キーの描写 #-------------------------------------------------------------------------- def draw_code_key(index) # カーソルの座標を計算 x = index % @column_max * 88 y = index / @column_max * 88 # 対象の範囲を消す self.contents.rect_clear(x, y, 88, 88) # 描写範囲作成 rect = Rect.new((@key.play[index] - 1) * 88, 0, 88, 88) self.contents.blt(x, y, @bitmap, rect) @keys.clear for i in @key.play do unless @keys.include?(i) @keys.push(i) end end for i in 0...9 @sprites[i].src_rect.set(i * 28, 28, 28, 28) end for k in @keys do @sprites[k - 1].src_rect.set(((k - 1) * 28), 0, 28, 28) end end #-------------------------------------------------------------------------- # ● キー加算 #-------------------------------------------------------------------------- def key_gain @key.play[self.index] += 1 @key.play[self.index] %= 10 @key.play[self.index] = @key.play[self.index].to_min(1) draw_code_key(self.index) end #-------------------------------------------------------------------------- # ● キー減算 #-------------------------------------------------------------------------- def key_lose @key.play[self.index] -= 1 if @key.play[self.index].zero? @key.play[self.index] = 9 end draw_code_key(self.index) end #-------------------------------------------------------------------------- # ● カーソルの矩形更新 #-------------------------------------------------------------------------- def update_cursor_rect # ウィンドウがアクティブでない、 # もしくはカーソル位置が 0 未満の場合 if self.active == false or @index < 0 self.cursor_rect.empty return end # カーソルの座標を計算 x = @index % @column_max * 88 y = @index / @column_max * 88 # カーソルの矩形を更新 self.cursor_rect.set(x + 4, y + 4, 76, 74) end end #============================================================================== # ■ Scene_CodeBeakar #------------------------------------------------------------------------------ #  コードブレイカーの処理を行うクラスです。 #============================================================================== class Scene_CodeBeakar #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reader :spriteset # スプライトセット #-------------------------------------------------------------------------- # ● オブジェクト初期化 # ante : 消費コイン # type : 景品のタイプ #-------------------------------------------------------------------------- def initialize(ante = 10, type = 0) $game_party.coin ||= 0 @ante = ante @blink_count = 0 @blink_turn = -1 @present_type = type @total_result = [] # 挑戦回数のセット set_challenge_count end #-------------------------------------------------------------------------- # ● メイン処理 #-------------------------------------------------------------------------- def main # トランジション準備 Graphics.freeze # メインウィンドウを作成 @main_window = Window_CodeBeakar.new # コインウィンドウを作成 @coin_window = Window_Coin.new # シーンスプライトを作成 @scene_sprite = RPG::Sprite.new # 壁紙表示 @scene_sprite.bitmap = RPG::Cache.picture("Code_Back") # スプライトを作成 @sprite = Sprite.new # スプライトの座標を定義 @sprite.x = 16 @sprite.y = 24 @sprite.z = 9999 # スプライトのビットマップを作成 @sprite.bitmap = Bitmap.new(640, 480) # テキスト表示 @sprite.bitmap.draw_key(328 + (64 * 0), 24, "R") @sprite.bitmap.draw_key(324 + (64 * 2), 24, "Z") @sprite.bitmap.draw_key(300 + (64 * 4), 24, "L") @sprite.bitmap.font.size = 16 @sprite.bitmap.font.color = Color.new(224, 224, 0) @sprite.bitmap.draw_text(76, 0, 64, 24, "×" + @ante.to_s) # チェック演出用スプライトを作成 @check_sprite = Sprite.new @check_sprite.y = 160 @check_sprite.z = 9999 @check_sprite.bitmap = RPG::Cache.picture("Code_Brealar_Check") @check_sprite.visible = false # トランジション実行 Graphics.transition(20) # 極端な処理落ちを防止する Graphics.frame_reset # メインループ main_loop end #-------------------------------------------------------------------------- # ● メインループ #-------------------------------------------------------------------------- def main_loop # 画面が切り替わるまで繰り返す while self == $scene # 基本情報を更新 update_graphic # フレーム更新 update end # トランジション準備 Graphics.freeze # ウィンドウを解放 @main_window.dispose @coin_window.dispose #スプライトを解放 @scene_sprite.bitmap.dispose @scene_sprite.dispose @scene_sprite = nil @sprite.bitmap.dispose @sprite.dispose @sprite = nil @check_sprite.bitmap.dispose @check_sprite.dispose @check_sprite = nil end #-------------------------------------------------------------------------- # ● 転送矩形のセット # code : 識別コード #-------------------------------------------------------------------------- def check_set_rect(code) case code when "チェック" # チェックSEの演奏 sound_call("チェック") @check_sprite.src_rect.set(0, 160 * 0, 640, 160) when "ビンゴ" if (@ori_try - @try) <= 1 # 正解MEの演奏(大当たり) sound_call("大当たり") else # 正解MEの演奏(通常当たり) sound_call("当たり") end @check_sprite.src_rect.set(0, 160 * 1, 640, 160) when "ルーズ" # 失敗MEの演奏 sound_call("失敗") @check_sprite.src_rect.set(0, 160 * 2, 640, 160) end end #-------------------------------------------------------------------------- # ● チェック演出の開始 # code : 識別コード #-------------------------------------------------------------------------- def start_check_effect(code) # 識別コード記憶 @code = code # 転送矩形セット check_set_rect(code) @check_sprite.x = 640 @check_sprite.visible = true @speed = 640 / 10 @wait = 40 # メインウィンドウを非アクティブにする @main_window.active = false end #-------------------------------------------------------------------------- # ● チェック判定 #-------------------------------------------------------------------------- def code_check # ヒット算出 @main_window.key.get_hit # ブロー算出 @main_window.key.get_blow # ターンリザルトの表示 draw_turn_result # トータルリザルト記憶 key = @main_window.key.play hit = @main_window.key.hit blow = @main_window.key.blow @total_result[@ori_try - (@try - 1)] = [key, hit, blow] # 完全一致の場合 if @main_window.key.bingo? # 正解演出 start_check_effect("ビンゴ") # 景品獲得 present_effect(1) # コインを再描写 @coin_window.refresh # ゲーム終了 @game_end = true # 残り挑戦回数を減らす @try -= 1 else # 残り挑戦回数を減らす @try -= 1 # 挑戦回数が0になった場合 if @try.zero? # 次の景品の表示 draw_present # 正解表示 @main_window.key.play = @main_window.key.key # ヒット算出 @main_window.key.get_hit # ブロー算出 @main_window.key.get_blow # ターンリザルトの表示 draw_turn_result # キー再描写 @main_window.refresh # 失敗演出 start_check_effect("ルーズ") # ゲーム終了 @game_end = true end end # トータルリザルト描写 draw_total_result # 完全一致でない場合 unless @main_window.key.bingo? # 次の景品の表示 draw_present end end #-------------------------------------------------------------------------- # ● ターンリザルトの表示 #-------------------------------------------------------------------------- def draw_turn_result @sprite.bitmap.rect_clear(0, 160, 320, 320) @sprite.bitmap.font.size = 20 # ヒットの表示 for i in 0...@main_window.key.hit.size # 座標セット case i # 横列 when 0..2 x = 275 y = 160 + (i * 88) # 縦列 when 3..5 x = 40 + ((i - 3) * 88) y = 390 end text = @main_window.key.hit[i].to_s @sprite.bitmap.font.color = Color.new(255, 128, 0) @sprite.bitmap.draw_text(x, y, 32, 24, text) end # ブローの表示 for i in 0...@main_window.key.blow.size # 座標セット case i # 横列 when 0..2 x = 275 + 24 y = 160 + (i * 88) # 縦列 when 3..5 x = 40 + ((i - 3) * 88) y = 390 + 24 end text = @main_window.key.blow[i].to_s @sprite.bitmap.font.color = Color.new(0, 255, 0) @sprite.bitmap.draw_text(x, y, 32, 24, text) end end #-------------------------------------------------------------------------- # ● トータルリザルトの表示 #-------------------------------------------------------------------------- def draw_total_result @sprite.bitmap.font.size = 10 # キーの表示 for i in 0...@total_result[@ori_try - @try][0].size index = @ori_try - @try - 1 # 座標セット x = 350 + ((i % 3) * 12) + ((index % 3) * 88) y = 120 + ((i / 3) * 12) + ((index / 3) * 88) text = @total_result[@ori_try - @try][0][i].to_s @sprite.bitmap.font.color = Color.new(224, 224, 255) @sprite.bitmap.draw_text(x, y, 32, 24, text) end # ヒットの表示 for i in 0...@total_result[@ori_try - @try][1].size index = @ori_try - @try - 1 # 座標セット case i # 横列 when 0..2 x = 390 + ((index % 3) * 88) y = 120 + (i * 13) + ((index / 3) * 88) # 縦列 when 3..5 x = 348 + ((i - 3) * 13) + ((index % 3) * 88) y = 158 + ((index / 3) * 88) end text = @total_result[@ori_try - @try][1][i].to_s @sprite.bitmap.font.color = Color.new(255, 128, 0) @sprite.bitmap.draw_text(x, y, 32, 24, text) end # ブローの表示 for i in 0...@total_result[@ori_try - @try][2].size index = @ori_try - @try - 1 # 座標セット case i # 横列 when 0..2 x = 390 + ((index % 3) * 88) + 10 y = 120 + (i * 13) + ((index / 3) * 88) # 縦列 when 3..5 x = 348 + ((i - 3) * 13) + ((index % 3) * 88) y = 158 + ((index / 3) * 88) + 10 end text = @total_result[@ori_try - @try][2][i].to_s @sprite.bitmap.font.color = Color.new(0, 255, 0) @sprite.bitmap.draw_text(x, y, 32, 24, text) end end #-------------------------------------------------------------------------- # ● リザルトフィルターの表示 #-------------------------------------------------------------------------- def draw_result_filter # 回数が9でない場合 if @ori_try != 9 for i in @ori_try...9 x = 342 + ((i % 3) * 88) y = 122 + ((i / 3) * 88) @sprite.bitmap.fill_rect(x, y, 66, 68, Color.new(0, 128, 0, 160)) end end end #-------------------------------------------------------------------------- # ● 景品表示 #-------------------------------------------------------------------------- def draw_present @sprite.bitmap.font.size = 22 @sprite.bitmap.font.color = Color.new(255, 255, 255) # 描写範囲のクリア @sprite.bitmap.rect_clear(314, 410, 290, 50) # 景品の表示 @sprite.bitmap.draw_text(314, 410, 290, 24, present_effect(0), 1) end #-------------------------------------------------------------------------- # ● フレーム更新(基本画面) #-------------------------------------------------------------------------- def update_graphic # ゲーム画面を更新 Graphics.update # 入力情報を更新 Input.update end #-------------------------------------------------------------------------- # ● フレーム更新(チェック演出) #-------------------------------------------------------------------------- def update_check_effect # スプライトの座標がプラスの場合 if @check_sprite.x >= 1 # 座標をマイナス @check_sprite.x -= @speed # ウェイト中の場合 elsif @wait >= 1 # ウェイトカウントを減らす @wait -= 1 # ゲームが終了している場合 elsif @game_end # 点滅カウントを更新 @blink_count += 1 # 最大までカウントが進んだ場合 if @blink_count == 32 # カウント初期化 @blink_count = 0 # ターン反転 @blink_turn *= -1 end @check_sprite.opacity += (5 * @blink_turn) # 開始処理を更新 update_start # 退出の場合 else # 座標をマイナス @check_sprite.x -= @speed # 画面外に出た場合 if @check_sprite.x <= -640 # スプライトを非表示にする @check_sprite.visible = false # メインウィンドウをアクティブにする @main_window.active = true # チェック判定を行う場合 if @code == "チェック" # チェック判定 code_check end end end end #-------------------------------------------------------------------------- # ● フレーム更新(開始処理) #-------------------------------------------------------------------------- def update_start # L ボタンが押された場合 if Input.trigger?(Input::L) # SEを演奏 SEPass.call("キャンセル") # マップ画面に切り替え $scene = Scene_Map.new end # R ボタンが押された場合 if Input.trigger?(Input::R) # コイン不足の場合 if $game_party.coin < @ante # SEを演奏 SEPass.call("ブザー") # メソッドを返す return end # ゲーム開始 @game_end = false # リザルトをクリア @sprite.bitmap.rect_clear(0, 120, 640, 330) # 挑戦回数初期化 @try = @ori_try # 景品の表示 draw_present # スプライトを非表示にする @check_sprite.visible = false # リザルトフィルター表示 draw_result_filter # メインウィンドウをリセット @main_window.reset # SEを演奏 SEPass.call("ショップ") # コイン減算 $game_party.lose_coin(@ante) # コインを再描写 @coin_window.refresh end end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update # ウィンドウを更新 @main_window.update @coin_window.update # デバッグモードが ON かつ F9 キーが押されている場合 if $DEBUG and Input.press?(Input::F9) # 正解の表示 p @main_window.key.key end # チェック演出中の場合 if @check_sprite.visible # チェック演出の更新 update_check_effect # メソッドを返す return end # メインウィンドウがアクティブでない場合 unless @main_window.active # ゲーム開始中でない場合 unless @check_sprite.visible # 開始処理を更新 update_start end else # A ボタンが押された場合 if Input.trigger?(Input::A) # SEを演奏 SEPass.call("決定") # ロックフィルター表示 @main_window.draw_filter end # B ボタンが押された場合 if Input.trigger?(Input::B) # SEを演奏 SEPass.call("決定") # キー減算 @main_window.key_lose end # C ボタンが押された場合 if Input.trigger?(Input::C) # SEを演奏 SEPass.call("決定") # キー加算 @main_window.key_gain end # Z ボタンが押された場合 if Input.trigger?(Input::Z) # SEを演奏 SEPass.call("決定") # チェック演出 start_check_effect("チェック") end end end end end