=begin ▼ 乗り物擬似3D化 イベント立体表示 ver. 2.1 RPGツクールVXAce用スクリプト 制作 : 木星ペンギン URL : http://woodpenguin.blog.fc2.com/ ------------------------------------------------------------------------------ 概要 □ イベントや乗り物を疑似3Dで表示します。 □ 本スクリプトは、乗り物疑似3D化スクリプトのオプションです。 =end #////////////////////////////////////////////////////////////////////////////// # # 設定項目なし # #////////////////////////////////////////////////////////////////////////////// module WdTk @material << :Veh3D_OP4 end #============================================================================== # ■ Game_CharacterBase #============================================================================== class Game_CharacterBase #-------------------------------------------------------------------------- # ● 立体表示するかどうか #-------------------------------------------------------------------------- def solid? @solid && $game_player.in_vehicle end #-------------------------------------------------------------------------- # ● 立体表示の向きの取得 #-------------------------------------------------------------------------- def direction if solid? && (@auto_turn == 0 || (@auto_turn == 2 && !@direction_fix)) case $game_player.vehicle.angle_dir when 2 reverse_dir(@direction) when 4 case @direction when 2; 4 when 4; 8 when 6; 2 when 8; 6 end when 6 case @direction when 2; 6 when 4; 2 when 6; 8 when 8; 4 end when 8 @direction end else @direction end end #-------------------------------------------------------------------------- # ● 立体表示の不透明度の取得 #-------------------------------------------------------------------------- def solid_opacity(y) (y - 160) * @opacity / 6 end end #============================================================================== # ■ Game_Player #============================================================================== class Game_Player #-------------------------------------------------------------------------- # ◯ マップイベントの起動 #-------------------------------------------------------------------------- alias _wdtk_veh3d_op4_start_map_event start_map_event def start_map_event(x, y, triggers, normal) if @in_vehicle altitude = vehicle.altitude altitude *= vehicle.view_zoom if WdTk.include?(:Veh3D_OP2) $game_map.events_xy(x, y).each do |event| if event.trigger_in?(triggers) && event.normal_priority? == normal && event.collide_altitude?(altitude) event.start end end else _wdtk_veh3d_op4_start_map_event(x, y, triggers, normal) end end #-------------------------------------------------------------------------- # ☆ 接触(重なり)によるイベント起動判定 #-------------------------------------------------------------------------- def check_touch_event #return false if in_airship? check_event_trigger_here([1,2]) $game_map.setup_starting_event end #-------------------------------------------------------------------------- # ☆ 決定ボタンによるイベント起動判定 #-------------------------------------------------------------------------- def check_action_event #return false if in_airship? check_event_trigger_here([0]) return true if $game_map.setup_starting_event check_event_trigger_there([0,1,2]) $game_map.setup_starting_event end end #============================================================================== # ■ Game_Vehicle #============================================================================== class Game_Vehicle #-------------------------------------------------------------------------- # ● 定数 #-------------------------------------------------------------------------- NON_POS = [0, -32, 0, 1.0] #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- alias _wdtk_veh3d_op4_initialize initialize def initialize(type) _wdtk_veh3d_op4_initialize(type) @solid = param(:solid) != false @auto_turn = param(:auto_turn) != false ? 0 : 1 end #-------------------------------------------------------------------------- # ☆ 通行可能判定 #-------------------------------------------------------------------------- def vehicle_passable?(x2, y2) return false unless $game_map.valid?(x2, y2) return true if @through || debug_through? return false unless map_passable?(x2, y2, 0) if collide_with_events?(x2, y2) $game_player.check_event_trigger_touch(x2, y2) stop if $game_map.any_event_starting? return false end return false if !flight? && collide_with_vehicles?(x2, y2) return true end #-------------------------------------------------------------------------- # ☆ イベントとの衝突判定 #-------------------------------------------------------------------------- def collide_with_events?(x, y) $game_map.events_xy_nt(x, y).any? do |ev| ev.normal_priority? && ev.collide_altitude?(@altitude) end end #-------------------------------------------------------------------------- # ● 乗り物との衝突判定 #-------------------------------------------------------------------------- def collide_with_vehicles?(x, y) $game_map.vehicles.any? {|v| v != self && v.pos_nt?(x, y) } end #-------------------------------------------------------------------------- # ◯ 上昇の処理 #-------------------------------------------------------------------------- alias _wdtk_veh3d_op4_process_up process_up def process_up last_altitude = @altitude _wdtk_veh3d_op4_process_up x2 = $game_map.round_x(@x.round) y2 = $game_map.round_y(@y.round) if collide_with_events?(x2, y2) $game_player.check_event_trigger_touch(x2, y2) stop if $game_map.any_event_starting? @altitude = last_altitude elsif $game_player.check_touch_event if $game_map.interpreter.event_id == @touch_event_id $game_map.interpreter.clear else @touch_event_id = $game_map.interpreter.event_id end elsif !$game_map.interpreter.running? @touch_event_id = 0 end end #-------------------------------------------------------------------------- # ◯ 下降の処理 #-------------------------------------------------------------------------- alias _wdtk_veh3d_op4_process_down process_down def process_down last_altitude = @altitude _wdtk_veh3d_op4_process_down x2 = $game_map.round_x(@x.round) y2 = $game_map.round_y(@y.round) if collide_with_events?(x2, y2) $game_player.check_event_trigger_touch(x2, y2) stop if $game_map.any_event_starting? @altitude = last_altitude elsif $game_player.check_touch_event if $game_map.interpreter.event_id == @touch_event_id $game_map.interpreter.clear else @touch_event_id = $game_map.interpreter.event_id end elsif !$game_map.interpreter.running? @touch_event_id = 0 end end #-------------------------------------------------------------------------- # ● 座標からイベントのラジアン取得 #-------------------------------------------------------------------------- def event_radian if @angle < 90 sx = @angle / 90.0 elsif @angle < 270 sx = (180 - @angle) / 90.0 else sx = (@angle - 360) / 90.0 end sy = ((@angle - 180).abs - 90) / 90.0 base = @angle / 180 * PI base + (atan2(sx, sy) - base) * 2 end #-------------------------------------------------------------------------- # ● イベントの位置計算 #-------------------------------------------------------------------------- def event_position(x, y) vzoom = WdTk.include?(:Veh3D_OP2) ? view_zoom : 1.0 mzoom = WdTk.include?(:Veh3D_OP3) ? WdTk::Veh3D::OP3::MapZoom : 1.0 sx = (@real_x - x) / vzoom * mzoom sy = (y - @real_y) / vzoom * mzoom if sx != 0 || sy != 0 ox = hypot(sx, sy) * sin(@angle * PI / 180 + atan2(-sx, -sy)) * 32 oy = hypot(sx, sy) * cos(@angle * PI / 180 + atan2(sx, sy)) * 32 else ox = oy = 0 end return NON_POS if ox.abs > Graphics.width / 2 ay = origin_y(oy + Graphics.height / 2 + snap_distance - 4) return NON_POS if ay == 0 zoom = adjust_zoom(ay - 160) ax = Graphics.width / 2 + ox * zoom az = 100 + oy / 3 return [ax, ay, az, zoom * mzoom / vzoom] end #-------------------------------------------------------------------------- # ● 立体表示位置の取得 #-------------------------------------------------------------------------- def solid_position x = $game_map.adjust_x(@real_x + 0.5) y = $game_map.adjust_y(@real_y + 0.5) $game_player.vehicle.event_position(x, y) end def solid_position x = $game_map.round_x(@real_x) y = $game_map.round_y(@real_y) $game_player.vehicle.event_position(x, y) end #-------------------------------------------------------------------------- # ● 立体表示の高さ取得 #-------------------------------------------------------------------------- def solid_altitude param(:anc_altitude) || [@altitude, 10].max end #-------------------------------------------------------------------------- # ● 拡大率の取得 #-------------------------------------------------------------------------- def solid_zoom (param(:solid_zoom) || 50) / 100.0 end end #============================================================================== # ■ Game_Event #============================================================================== class Game_Event #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reader :touch_altitude # 接触高度 attr_reader :solid_zoom # 拡大率 #-------------------------------------------------------------------------- # ● 高さでの衝突判定(フォロワーを含む) #-------------------------------------------------------------------------- def collide_altitude?(altitude) altitude.between?(@altitude, @altitude + @touch_altitude) end #-------------------------------------------------------------------------- # ● 立体表示位置の取得 #-------------------------------------------------------------------------- def solid_position x = $game_map.adjust_x(@real_x + 0.5) y = $game_map.adjust_y(@real_y + 0.5) $game_player.vehicle.event_position(x, y) end def solid_position x = $game_map.round_x(@real_x) y = $game_map.round_y(@real_y) $game_player.vehicle.event_position(x, y) end #-------------------------------------------------------------------------- # ◯ 画面の可視領域付近にいるか判定 #-------------------------------------------------------------------------- alias _wdtk_veh3d_op4_near_the_screen? near_the_screen? def near_the_screen?(dx = 12, dy = 8) $game_player.in_vehicle || _wdtk_veh3d_op4_near_the_screen?(dx, dy) end #-------------------------------------------------------------------------- # ◯ イベントページの設定をクリア #-------------------------------------------------------------------------- alias _wdtk_veh3d_op4_clear_page_settings clear_page_settings def clear_page_settings _wdtk_veh3d_op4_clear_page_settings clear_veh3d_op4 end #-------------------------------------------------------------------------- # ◯ イベントページの設定をセットアップ #-------------------------------------------------------------------------- alias _wdtk_veh3d_op4_setup_page_settings setup_page_settings def setup_page_settings _wdtk_veh3d_op4_setup_page_settings clear_veh3d_op4 get_command_escapes end #-------------------------------------------------------------------------- # ● イベント内容から設定をセットアップ #-------------------------------------------------------------------------- def get_command_escapes @list.each do |cmd| case cmd.code when 108,408 comment_escape_data(cmd.parameters[0]) else return end end end #-------------------------------------------------------------------------- # ● 注釈の内容取得 #-------------------------------------------------------------------------- def comment_escape_data(comment) case comment when /立体表示/ @solid = true when /高さ\s*[::]\s*(\d+)/ @solid = true @altitude = $1.to_i when /接触高度\s*[::]\s*(\d+)/ @touch_altitude = $1.to_i when /自動向き変更\s*[::]\s*(on|off)/i @auto_turn = $1 =~ /on/i ? 0 : 1 when /拡大率\s*[::]\s*(\d+)/i @solid_zoom = $1.to_f / 100 end end #-------------------------------------------------------------------------- # ● イベント立体表示の設定をクリア #-------------------------------------------------------------------------- def clear_veh3d_op4 @solid = false @altitude = 10 @touch_altitude = 9 @auto_turn = 2 @solid_zoom = 0.5 end #-------------------------------------------------------------------------- # ● 立体表示の高さ取得 #-------------------------------------------------------------------------- def solid_altitude @altitude end end #============================================================================== # ■ Sprite_Character #============================================================================== class Sprite_Character #-------------------------------------------------------------------------- # ● ビューポートの設定 #-------------------------------------------------------------------------- def viewport=(viewport) super @shadow_sprite.viewport = viewport if @shadow_sprite end #-------------------------------------------------------------------------- # ◯ 位置の更新 #-------------------------------------------------------------------------- alias _wdtk_veh3d_op4_update_position update_position def update_position if @character.solid? @solid_x, @solid_y, self.z, zoom = @character.solid_position self.x = @solid_x self.y = @solid_y - (@character.solid_altitude - 14) * zoom / 1.25 self.zoom_x = self.zoom_y = zoom * @character.solid_zoom else _wdtk_veh3d_op4_update_position end end #-------------------------------------------------------------------------- # ◯ その他の更新 #-------------------------------------------------------------------------- alias _wdtk_veh3d_op4_update_other update_other def update_other _wdtk_veh3d_op4_update_other self.opacity = @character.solid_opacity(@solid_y) if @solid_y end #-------------------------------------------------------------------------- # ◯ 影の更新 #-------------------------------------------------------------------------- alias _wdtk_veh3d_op4_update_shadow update_shadow def update_shadow if @solid_x altitude = @character.solid_altitude if @solid_y > 0 && altitude > 10 start_shadow unless @shadow_sprite opacity = 255 * (90 - altitude / 2) / 90 zoom = self.zoom_x * (200 - altitude) / 180.0 zoom = zoom * self.width / @shadow_sprite.width @shadow_sprite.x = @solid_x @shadow_sprite.y = @solid_y + 3 * zoom @shadow_sprite.z = self.z @shadow_sprite.opacity = opacity * self.opacity / 255 @shadow_sprite.zoom_x = @shadow_sprite.zoom_y = zoom end else _wdtk_veh3d_op4_update_shadow end end end #============================================================================== # ■ Spriteset_Vehicle #============================================================================== class Spriteset_Vehicle #-------------------------------------------------------------------------- # ◯ キャラクタースプライトの作成 #-------------------------------------------------------------------------- alias _wdtk_veh3d_op4_create_characters create_characters def create_characters _wdtk_veh3d_op4_create_characters if WdTk.include?(:Veh3D_OP2) && !WdTk::Veh3D::OP2::ShowEvent $game_map.events.values.each do |event| @character_sprites.push(Sprite_Character.new(@veh_viewport0, event)) end end @character_sprites.each do |sprite| sprite.viewport = @veh_viewport0 if sprite.character.solid? end end end