#============================================================================== # □ ジャンプ (for VX Ace) #------------------------------------------------------------------------------ # Version : 1_20120504 # by サリサ・タイクーン # http://www.tycoon812.com/rgss/ #============================================================================== #============================================================================== # □ 素材スイッチ #============================================================================== $rgsslab = {} if $rgsslab == nil $rgsslab["ジャンプ"] = true if $rgsslab["ジャンプ"] #============================================================================== # □ カスタマイズポイント #============================================================================== module RGSSLAB end module RGSSLAB::Jump #-------------------------------------------------------------------------- # ○ ジャンプボタン # ジャンプボタンを指定します。 # # ダッシュ実装や他の素材等で、被らないようご注意下さい。 #-------------------------------------------------------------------------- BUTTON = Input::Y #-------------------------------------------------------------------------- # ○ ジャンプパワー # POWERの値の分、ジャンプ移動を行います。 # POWERが0の場合、その場でジャンプするだけとなります。 # # 0よりも下(負の数字)にする事はできません。 # # イベントコマンドのスクリプトで後々操作する事も可能です。 #-------------------------------------------------------------------------- POWER = 2 #-------------------------------------------------------------------------- # ○ ジャンプの効果音 # 音楽(SE)のファイル名を指定します。(拡張子は省略) # # nilにすると、無音設定となります。 # # 存在しないファイルを指定すると、ジャンプボタンを押した途端に # エラーとなり、強制終了の原因となりますので # ご注意下さい。 # # イベントコマンドのスクリプトで後々操作する事も可能です。 #-------------------------------------------------------------------------- SE = "Jump1" #-------------------------------------------------------------------------- # ○ 効果音の音量 # 音量を調整します。 # # イベントコマンドのスクリプトで後々操作する事も可能です。 #-------------------------------------------------------------------------- VOLUME = 100 #-------------------------------------------------------------------------- # ○ 効果音のピッチ # ピッチを調整します。 # # イベントコマンドのスクリプトで後々操作する事も可能です。 #-------------------------------------------------------------------------- PITCH = 100 #-------------------------------------------------------------------------- # ○ ジャンプ禁止タグ # ここで指定した数字は、地形タグで指定された数字以上のものが # ある場合、その地形タグを飛び越す事ができません。 # # 飛び越す際に、禁止タグが1つでも含まれている場合 # ジャンプはできません。 # # イベントコマンドのスクリプトで後々操作する事も可能です。 #-------------------------------------------------------------------------- PROHIBIT_TAG = 2 #-------------------------------------------------------------------------- # ○ ジャンプ禁止スイッチ # このスイッチがオンの場合、ジャンプができなくなります。 #-------------------------------------------------------------------------- PROHIBIT_JUMP_SW = 9 end # カスタマイズポイントは、ここまで #============================================================================== # □ RGSSLAB::Jump [module] #============================================================================== module RGSSLAB::Jump #-------------------------------------------------------------------------- # ○ 素材設定用の定数定義 #-------------------------------------------------------------------------- MATERIAL_NAME = "ジャンプ" VERSION = 1 RELEASE = 20120504 #-------------------------------------------------------------------------- # ○ 操作エラー # error_number : エラー番号 #-------------------------------------------------------------------------- def self.operate_error(error_number) text = "【RGSS研究所:#{MATERIAL_NAME}】" case error_number when 1 msgbox_p text, "ジャンプ禁止タグは、7よりも高くできません。" when 2 msgbox_p text, "ジャンプ禁止タグは、1よりも低くできません。" when 3 msgbox_p text "ジャンプパワーは、0よりも低くできません。" end end end #============================================================================== # ■ Game_System [class] #============================================================================== class Game_System #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :rgsslab058 #-------------------------------------------------------------------------- # ● オブジェクト初期化 [エイリアス] #-------------------------------------------------------------------------- alias jump_initialize initialize def initialize jump_initialize @rgsslab058 = RgssLab_058.new end end #============================================================================== # □ RgssLab_058 [class] #============================================================================== class RgssLab_058 #-------------------------------------------------------------------------- # ○ モジュールの設定 #-------------------------------------------------------------------------- RGSSLAB_058 = RGSSLAB::Jump #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :se attr_accessor :volume attr_accessor :pitch attr_reader :tag attr_reader :power #-------------------------------------------------------------------------- # ○ オブジェクト初期化 #-------------------------------------------------------------------------- def initialize @se = RGSSLAB_058::SE @volume = RGSSLAB_058::VOLUME @pitch = RGSSLAB_058::PITCH @tag = RGSSLAB_058::PROHIBIT_TAG @power = RGSSLAB_058::POWER end #-------------------------------------------------------------------------- # ○ ジャンプ禁止タグの変更 # new_value : 変更する値 #-------------------------------------------------------------------------- def jump_tag=(new_value) if new_value > 8 RGSSLAB_058.operate_error(1) return end if new_value < 1 RGSSLAB_058.operate_error(2) return end @tag = new_value end #-------------------------------------------------------------------------- # ○ ジャンプパワーの変更 # new_value : 変更する値 #-------------------------------------------------------------------------- def jump_power=(new_vlue) if new_value < 0 RGSSLAB_058.operate_error(3) return end @power = new_value end end #============================================================================== # ■ Game_Map [class] #============================================================================== class Game_Map #-------------------------------------------------------------------------- # ● 通常キャラの通行可能判定 [再構築] # x : 横方向 # y : 縦方向 # d : 方向(2,4,6,8) # jump : ジャンプフラグ(ジャンプでない場合は常にfalse) #-------------------------------------------------------------------------- def passable?(x, y, d, jump = false) if jump check_passage_jump(x, y, (1 << (d / 2 - 1)) & 0x0f, d) else check_passage(x, y, (1 << (d / 2 - 1)) & 0x0f) end end #-------------------------------------------------------------------------- # ○ 通行チェック [ジャンプ用] # x : 横方向 # y : 縦方向 # bit : 調べる通行禁止ビット # d : 方向 #-------------------------------------------------------------------------- def check_passage_jump(x, y, bit, d) flag_set = [] all_tiles(x, y).each do |tile_id| flag = tileset.flags[tile_id] next if flag & 0x10 != 0 if flag & bit == 0 if flag == 3598 or flag == 3590 or flag == 3592 flag_set.push(false) next end if flag == 1536 or flag == 3584 flag_set.push(true) next end case d when 2 unless check_passage(x, y + 1, (1 << (d / 2 - 1)) & 0x0f) flag_set.push(false) next end when 4 unless check_passage(x - 1, y, (1 << (d / 2 - 1)) & 0x0f) flag_set.push(false) next end when 6 unless check_passage(x + 1, y, (1 << (d / 2 - 1)) & 0x0f) flag_set.push(false) next end when 8 unless check_passage(x, y - 1, (1 << (d / 2 - 1)) & 0x0f) flag_set.push(false) next end end end if flag & bit == bit flag_set.push(false) next end end if flag_set.include?(false) return false else if flag_set.empty? return false else return true end end end end #============================================================================== # ■ Game_CharacterBase [class] #============================================================================== class Game_CharacterBase #-------------------------------------------------------------------------- # ● マップ通行可能判定 [再構築] # x : 横方向 # y : 縦方向 # d : 方向(2,4,6,8) # jump : ジャンプフラグ(ジャンプでない場合は常にfalse) #-------------------------------------------------------------------------- def map_passable?(x, y, d, jump = false) $game_map.passable?(x, y, d, jump) end end #============================================================================== # ■ Game_Player [class] #============================================================================== class Game_Player < Game_Character #-------------------------------------------------------------------------- # ○ モジュールの設定 #-------------------------------------------------------------------------- RGSSLAB_058 = RGSSLAB::Jump #-------------------------------------------------------------------------- # ● マップ通行可能判定 [オーバーライド][再構築] # x : 横方向 # y : 縦方向 # d : 方向(2,4,6,8) # jump : ジャンプフラグ(ジャンプでない場合は常にfalse) #-------------------------------------------------------------------------- def map_passable?(x, y, d, jump = false) case @vehicle_type when :boat ; $game_map.boat_passable?(x, y) when :ship ; $game_map.ship_passable?(x, y) when :airship ; true else ; super end end #-------------------------------------------------------------------------- # ○ ジャンプ [オーバーライド] # x_plus : X 座標加算値 # y_plus : Y 座標加算値 # direction_value : 方向 #-------------------------------------------------------------------------- def jump(x_plus, y_plus, direction_value = nil) if direction_value == nil super(x_plus, y_plus) return end if x_plus.abs > y_plus.abs set_direction(x_plus < 0 ? 4 : 6) if x_plus != 0 else set_direction(y_plus < 0 ? 8 : 2) if y_plus != 0 end new_x = @x + x_plus new_y = @y + y_plus judge = false unless $game_system.rgsslab058.power == 0 or $game_system.rgsslab058.power == 1 for j in 0...$game_system.rgsslab058.power case direction_value when 2 ; judge = true if $game_map.terrain_tag(new_x, new_y + j) >= $game_system.rgsslab058.tag && !map_passable?(new_x, new_y, direction_value, true) when 4 ; judge = true if $game_map.terrain_tag(new_x + j, new_y) >= $game_system.rgsslab058.tag when 6 ; judge = true if $game_map.terrain_tag(new_x - j, new_y) >= $game_system.rgsslab058.tag when 8 ; judge = true if $game_map.terrain_tag(new_x, new_y + j) >= $game_system.rgsslab058.tag end end end if (x_plus == 0 and y_plus == 0) or map_passable?(new_x, new_y, direction_value, true) && judge == false if $game_system.rgsslab058.se != nil Audio.se_play("Audio/SE/" + $game_system.rgsslab058.se, $game_system.rgsslab058.volume, $game_system.rgsslab058.pitch) end distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round @jump_peak = 10 + distance - @move_speed @jump_count = @jump_peak * 2 @stop_count = 0 straighten @x = new_x @y = new_y end end #-------------------------------------------------------------------------- # ● 方向ボタン入力による移動処理 [再定義] #-------------------------------------------------------------------------- def move_by_input return if !movable? || $game_map.interpreter.running? return if jump_process if $rgsslab["ジャンプ"] if $rgsslab["斜め移動"] unless $game_switches[RGSSLAB_026::SW] case Input.dir8 when 1 ; move_diagonal(4, 2) when 2 ; move_straight(2) when 3 ; move_diagonal(6, 2) when 4 ; move_straight(4) when 6 ; move_straight(6) when 7 ; move_diagonal(4, 8) when 8 ; move_straight(8) when 9 ; move_diagonal(6, 8) end else move_straight(Input.dir4) if Input.dir4 > 0 end else move_straight(Input.dir4) if Input.dir4 > 0 end end #-------------------------------------------------------------------------- # ○ ジャンプ処理 #-------------------------------------------------------------------------- def jump_process if Input.trigger?(RGSSLAB_058::BUTTON) && !$game_switches[RGSSLAB_058::PROHIBIT_JUMP_SW] case direction when 2 jump(0, $game_system.rgsslab058.power, 2) followers.jump(0, $game_system.rgsslab058.power, 2) return true when 4 jump(-$game_system.rgsslab058.power, 0, 4) followers.jump(-$game_system.rgsslab058.power, 0, 4) return true when 6 jump($game_system.rgsslab058.power, 0, 6) followers.jump($game_system.rgsslab058.power, 0, 6) return true when 8 jump(0, -$game_system.rgsslab058.power, 8) followers.jump(0, -$game_system.rgsslab058.power, 8) return true end return false end end end #============================================================================== # ■ Game_Follower [class] #============================================================================== class Game_Follower < Game_Character #-------------------------------------------------------------------------- # ○ モジュールの設定 #-------------------------------------------------------------------------- RGSSLAB_058 = RGSSLAB::Jump #-------------------------------------------------------------------------- # ○ ジャンプ [オーバーライド] # x_plus : X 座標加算値 # y_plus : Y 座標加算値 # direction_value : 方向 #-------------------------------------------------------------------------- def jump(x_plus, y_plus, direction_value = nil) if direction_value == nil super(x_plus, y_plus) return end if x_plus.abs > y_plus.abs set_direction(x_plus < 0 ? 4 : 6) if x_plus != 0 else set_direction(y_plus < 0 ? 8 : 2) if y_plus != 0 end new_x = @x + x_plus new_y = @y + y_plus judge = false unless $game_system.rgsslab058.power == 0 or $game_system.rgsslab058.power == 1 for j in 0...$game_system.rgsslab058.power case direction_value when 2 ; judge = true if $game_map.terrain_tag(new_x, new_y + j) >= $game_system.rgsslab058.tag && !map_passable?(new_x, new_y, direction_value, true) when 4 ; judge = true if $game_map.terrain_tag(new_x + j, new_y) >= $game_system.rgsslab058.tag when 6 ; judge = true if $game_map.terrain_tag(new_x - j, new_y) >= $game_system.rgsslab058.tag when 8 ; judge = true if $game_map.terrain_tag(new_x, new_y + j) >= $game_system.rgsslab058.tag end end end if (x_plus == 0 and y_plus == 0) or map_passable?(new_x, new_y, direction_value, true) && judge == false distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round @jump_peak = 10 + distance - @move_speed @jump_count = @jump_peak * 2 @stop_count = 0 straighten @x = new_x @y = new_y end end end #============================================================================== # ■ Game_Followers [class] #============================================================================== class Game_Followers #-------------------------------------------------------------------------- # ○ ジャンプ #-------------------------------------------------------------------------- def jump(x, y, d) for i in 0...@data.size @data[i].jump(x, y, d) end end end end