#============================================================================== # ■ Game_System #------------------------------------------------------------------------------ #  システム周りのデータを扱うクラスです。BGM などの管理も行います。このクラス # のインスタンスは $game_system で参照されます。 #============================================================================== class Game_System def self.title # ゲームタイトル取得 win = Win32API.new("kernel32", "GetPrivateProfileString", %w(p p p p i p), "i") title = "\0" * 255 win.call("Game", "Title", "Not title", title, 255, ".\\Game.ini") title.gsub!(/\0/){} return title.utf8 end end #============================================================================== # ■ Numset #------------------------------------------------------------------------------ #  定数全般のモジュールです。 #============================================================================== module Numset # ウィンドウハンドル取得 win = Win32API.new("user32", "FindWindow", %w(p p), "i") WINDOW_HANDLE = win.call("RGSS Player", Game_System.title) c = Win32API.new("user32", "GetDoubleClickTime", v, "i") time = win.call() DOUBLE_TIME = Graphics.frame_rate * time / 1000 SWAP = Win32API.new("user32", "SwapMouseButton", "i", "i") SYSTEM = Win32API.new("user32", "GetSystemMetrics", "i", "i") end #============================================================================== # ■ Sprite #------------------------------------------------------------------------------ #  スプライトは、ゲーム画面上にキャラクター等を表示するための基本概念です。 #============================================================================== class Sprite < Object #-------------------------------------------------------------------------- # ● 公開インスタンス変数追加 #-------------------------------------------------------------------------- attr_accessor :drag # ドラッグ可能か #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- alias :base_initialize :initialize def initialize(viewport = nil, drag = false) base_initialize(viewport) @drag_ok = drag @drag = false @position = nil end #-------------------------------------------------------------------------- # ● ビットマップクリック確認 #-------------------------------------------------------------------------- def click?(double = false) # スプライトの座標を確認 x_max = self.x + self.bitmap.rect.width y_max = self.y + self.bitmap.rect.height # スプライトに乗っているか判定 if @mouse_x >= self.x and @mouse_x <= x_max if @mouse_y >= self.y and @mouse_y <= y_max color = self.bitmap.get_pixel(@mouse_x - self.x, @mouse_y - self.y) # 透明であれば無視する if color.alpha != 0 if double return Mouse.double_click? else return Mouse.click? end end end end return false end #-------------------------------------------------------------------------- # ● ビットマップドラッグ確認 #-------------------------------------------------------------------------- def drag? # スプライトの座標を確認 x_max = self.x + self.bitmap.width y_max = self.y + self.bitmap.height # スプライトに乗っているか判定 if @mouse_x >= self.x and @mouse_x <= x_max if @mouse_y >= self.y and @mouse_y <= y_max color = self.bitmap.get_pixel(@mouse_x - self.x, @mouse_y - self.y) # 透明であれば無視する if color.alpha != 0 if @drag_ok if Mouse.click? @position = [@mouse_x - self.x, @mouse_y - self.y] return true else return Input.press?(Mouse.swap? ? Input::MOUSE_R : Input::MOUSE_L) end end end end end @position = nil return false end alias :base_update :update def update base_update @mouse_x = Mouse.mouse_point[0] @mouse_y = Mouse.mouse_point[1] # ドラッグ時はスプライトの座標も更新 if @drag self.x = mouse_x - @position[0] self.y = mouse_y - @position[1] end end end #============================================================================== # ■ Mouse #------------------------------------------------------------------------------ #  マウス専用のモジュールです。 #  ただしキー自由取得も組み込まないとクリックが確認できません。 #============================================================================== module Mouse #-------------------------------------------------------------------------- # ● 懲りずに定数宣言 #-------------------------------------------------------------------------- MOUSE = [Win32API.new("user32", "ScreenToClient", %w(i, p), "i"), Win32API.new("user32", "GetCursorPos", "p", "i")] #-------------------------------------------------------------------------- # ● クリック確認 #-------------------------------------------------------------------------- def self.click? if self.swap? if Input.trigger?(Input::MOUSE_R) @count = Graphics.frame_count return true else return false end else if Input.trigger?(Input::MOUSE_L) @count = Graphics.frame_count return true else return false end end end #-------------------------------------------------------------------------- # ● ダブルクリック確認 #-------------------------------------------------------------------------- def self.double_click? old_count = @count if self.click? return ((@count - old_count) <= Numset::DOUBLE_TIME) else return false end end #-------------------------------------------------------------------------- # ● マウス座標の確認 #-------------------------------------------------------------------------- def self.mouse_point return [@mouse_x, @mouse_y] end #-------------------------------------------------------------------------- # ● 左右入れ替え #-------------------------------------------------------------------------- def self.swap set = Numset::SWAP.call(SYSTEM.call(23)) end #-------------------------------------------------------------------------- # ● 左右入れ替え? #-------------------------------------------------------------------------- def self.swap? return (SYSTEM.call(23) == 1 ? true : false) end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def self.update # マウス座標を更新 long = [0, 0].pack("i2") MOUSE[1].call(long) MOUSE[0].call(Numset::WINDOW_HANDLE, long) long = long.unpack("i2") @mouse_x = long[0] @mouse_y = long[1] end end