=begin RGSS3 ★ 遠景マップ ★ マップの遠景としてマップを使用できるようになります。 ● 仕様 ●========================================================== 遠景マップとして使用するマップのサイズは、 表示先のマップサイズと同程度が好ましいです。 -------------------------------------------------------------------- マップのループ設定は考慮してません。 -------------------------------------------------------------------- 遠景マップに設定されている遠景も表示されます。(通常の遠景に限る) -------------------------------------------------------------------- 遠景マップに配置されたイベントは遠景イベントとして表示されます。 -------------------------------------------------------------------- 遠景イベントの実行内容は無視されます。 -------------------------------------------------------------------- 遠景イベントの自律移動・オプションは有効です。遠景内で動きます。 -------------------------------------------------------------------- 遠景イベントの自律移動は遠景マップの通行判定を考慮します。 -------------------------------------------------------------------- 遠景イベントに複雑なことは期待しないでください。 -------------------------------------------------------------------- マップに通常の遠景が設定されている場合は、そちらが優先されます。 ==================================================================== ver1.00 Last Update : 2012/03/18 03/18 : 新規 ろかん   http://kaisou-ryouiki.sakura.ne.jp/ =end #=========================================== # 設定箇所 #=========================================== module ParallaxMAP # 遠景を表示するMAPリスト #【形式】 # ① => [②, ③], # ① 遠景マップを表示するマップID # ② 遠景として表示するマップID # ③ 遠景のスクロール速度補正 # (0でスクロール無効, 1で等倍速, 遅延させる場合は0.8くらいがいいかも) P_MAP_LIST = { 2 => [1, 0.8], 4 => [6, 0], } end #=========================================== # ここまで #=========================================== $rsi ||= {} $rsi["遠景マップ"] = true class Game_ParallaxMap < Game_Map #-------------------------------------------------------------------------- # ● インクルード ParallaxMAP #-------------------------------------------------------------------------- include ParallaxMAP #-------------------------------------------------------------------------- # ● セットアップ #-------------------------------------------------------------------------- def setup(map_id) @map_id = map_id @map = load_data(sprintf("Data/Map%03d.rvdata2", @map_id)) @tileset_id = @map.tileset_id setup_events setup_parallax set_scroll_speed end #-------------------------------------------------------------------------- # ● イベントのセットアップ #-------------------------------------------------------------------------- def setup_events @events = {} @map.events.each{|i, event| @events[i] = Game_ParallaxEvent.new(@map_id, event) } refresh_tile_events end #-------------------------------------------------------------------------- # ● スクロール速度の設定 #-------------------------------------------------------------------------- def set_scroll_speed @scroll_speed = P_MAP_LIST[$game_map.map_id][1] end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update last_x = @display_x last_y = @display_y @display_x = $game_map.display_x * @scroll_speed @display_y = $game_map.display_y * @scroll_speed update_events update_parallax(last_x, last_y) end #-------------------------------------------------------------------------- # ● イベントの更新 #-------------------------------------------------------------------------- def update_events @events.each_value{|event| event.update} end #-------------------------------------------------------------------------- # ● 遠景の更新 #-------------------------------------------------------------------------- def update_parallax(last_x, last_y) super() @parallax_x += @display_x - last_x @parallax_y += @display_y - last_y end end class Game_ParallaxEvent < Game_Event #-------------------------------------------------------------------------- # ● 通行可能判定 #-------------------------------------------------------------------------- def passable?(x, y, d) x2 = $game_parallax_map.round_x_with_direction(x, d) y2 = $game_parallax_map.round_y_with_direction(y, d) return false unless $game_parallax_map.valid?(x2, y2) return true if @through return false unless map_passable?(x, y, d) return false unless map_passable?(x2, y2, reverse_dir(d)) return false if collide_with_characters?(x2, y2) return true end #-------------------------------------------------------------------------- # ● マップ通行可能判定 #-------------------------------------------------------------------------- def map_passable?(x, y, d) $game_parallax_map.passable?(x, y, d) end #-------------------------------------------------------------------------- # ● キャラクターとの衝突判定 #-------------------------------------------------------------------------- def collide_with_characters?(x, y) collide_with_events?(x, y) end #-------------------------------------------------------------------------- # ● イベントとの衝突判定 #-------------------------------------------------------------------------- def collide_with_events?(x, y) $game_parallax_map.events_xy_nt(x, y).any?{|event| event.normal_priority? || self.is_a?(Game_ParallaxEvent) } end #-------------------------------------------------------------------------- # ● フレーム更新(遠景時) #-------------------------------------------------------------------------- def update update_animation return update_jump if jumping? return update_move if moving? return update_stop end #-------------------------------------------------------------------------- # ● ジャンプ時の更新 #-------------------------------------------------------------------------- def update_jump @jump_count -= 1 @real_x = (@real_x * @jump_count + @x) / (@jump_count + 1.0) @real_y = (@real_y * @jump_count + @y) / (@jump_count + 1.0) update_bush_depth if @jump_count == 0 @real_x = @x = $game_parallax_map.round_x(@x) @real_y = @y = $game_parallax_map.round_y(@y) end end #-------------------------------------------------------------------------- # ● 茂み判定 #-------------------------------------------------------------------------- def bush? $game_parallax_map.bush?(@x, @y) end #-------------------------------------------------------------------------- # ● まっすぐに移動 #-------------------------------------------------------------------------- def move_straight(d, turn_ok = true) @move_succeed = passable?(@x, @y, d) if @move_succeed set_direction(d) @x = $game_parallax_map.round_x_with_direction(@x, d) @y = $game_parallax_map.round_y_with_direction(@y, d) @real_x = $game_parallax_map.x_with_direction(@x, reverse_dir(d)) @real_y = $game_parallax_map.y_with_direction(@y, reverse_dir(d)) increase_steps elsif turn_ok set_direction(d) check_event_trigger_touch_front end end #-------------------------------------------------------------------------- # ● 斜めに移動 #-------------------------------------------------------------------------- def move_diagonal(horz, vert) @move_succeed = diagonal_passable?(x, y, horz, vert) if @move_succeed @x = $game_parallax_map.round_x_with_direction(@x, horz) @y = $game_parallax_map.round_y_with_direction(@y, vert) @real_x = $game_parallax_map.x_with_direction(@x, reverse_dir(horz)) @real_y = $game_parallax_map.y_with_direction(@y, reverse_dir(vert)) increase_steps end set_direction(horz) if @direction == reverse_dir(horz) set_direction(vert) if @direction == reverse_dir(vert) end #-------------------------------------------------------------------------- # ● 画面 X 座標の取得 #-------------------------------------------------------------------------- def screen_x $game_parallax_map.adjust_x(@real_x) * 32 + 16 end #-------------------------------------------------------------------------- # ● 画面 Y 座標の取得 #-------------------------------------------------------------------------- def screen_y $game_parallax_map.adjust_y(@real_y) * 32 + 32 - shift_y - jump_height end #-------------------------------------------------------------------------- # ● 画面の可視領域付近にいるか判定 #-------------------------------------------------------------------------- def near_the_screen?(dx = 12, dy = 8) ax = $game_parallax_map.adjust_x(@real_x) - Graphics.width / 2 / 32 ay = $game_parallax_map.adjust_y(@real_y) - Graphics.height / 2 / 32 ax >= -dx && ax <= dx && ay >= -dy && ay <= dy end end class Sprite_ParallaxCharacter < Sprite_Character #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update update_bitmap update_src_rect update_position update_other end end class Parallax_Tilemap #-------------------------------------------------------------------------- # ● インクルード ParallaxMAP #-------------------------------------------------------------------------- include ParallaxMAP #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize $game_parallax_map = Game_ParallaxMap.new @viewport = Viewport.new @viewport.z = -50 @map_id = 0 @character_sprites = [] create_tilemap create_parallax self.visible = false end #-------------------------------------------------------------------------- # ● 可視状態 #-------------------------------------------------------------------------- def visible @viewport.visible end #-------------------------------------------------------------------------- # ● 可視状態の変更 #-------------------------------------------------------------------------- def visible=(value) @viewport.visible = value end #-------------------------------------------------------------------------- # ● タイルマップの作成 #-------------------------------------------------------------------------- def create_tilemap @tilemap = Tilemap.new(@viewport) end #-------------------------------------------------------------------------- # ● 遠景マップIDの取得 #-------------------------------------------------------------------------- def get_parallax_map_id if P_MAP_LIST.has_key?($game_map.map_id) P_MAP_LIST[$game_map.map_id].first else 0 end end #-------------------------------------------------------------------------- # ● セットアップ #-------------------------------------------------------------------------- def setup map_id = get_parallax_map_id if map_id.zero? self.visible = false else $game_parallax_map.setup(map_id) load_tileset set_parallax refresh_characters self.visible = true end end #-------------------------------------------------------------------------- # ● タイルセットのロード #-------------------------------------------------------------------------- def load_tileset @tilemap.map_data = $game_parallax_map.data @tileset = $game_parallax_map.tileset @tileset.tileset_names.each_with_index{|name, i| @tilemap.bitmaps[i] = Cache.tileset(name) } @tilemap.flags = @tileset.flags end #-------------------------------------------------------------------------- # ● 遠景マップの遠景を設定 #-------------------------------------------------------------------------- def set_parallax @parallax.bitmap = Cache.parallax($game_parallax_map.parallax_name) end #-------------------------------------------------------------------------- # ● キャラクターのリフレッシュ #-------------------------------------------------------------------------- def refresh_characters dispose_characters create_characters end #-------------------------------------------------------------------------- # ● キャラクタースプライトの作成 #-------------------------------------------------------------------------- def create_characters @character_sprites.clear $game_parallax_map.setup_events $game_parallax_map.events.values.each{|event| @character_sprites << Sprite_ParallaxCharacter.new(@viewport, event) } end #-------------------------------------------------------------------------- # ● 遠景の作成 #-------------------------------------------------------------------------- def create_parallax @parallax = Plane.new(@viewport) @parallax.z = -100 end #-------------------------------------------------------------------------- # ● 解放 #-------------------------------------------------------------------------- def dispose dispose_tilemap dispose_characters dispose_parallax end #-------------------------------------------------------------------------- # ● タイルマップの解放 #-------------------------------------------------------------------------- def dispose_tilemap @tilemap.dispose end #-------------------------------------------------------------------------- # ● キャラクタースプライトの解放 #-------------------------------------------------------------------------- def dispose_characters @character_sprites.each{|sprite| sprite.dispose} end #-------------------------------------------------------------------------- # ● 遠景の解放 #-------------------------------------------------------------------------- def dispose_parallax @parallax.dispose end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update(viewport) if self.visible $game_parallax_map.update update_viewports(viewport) update_tilemap update_characters update_parallax end end #-------------------------------------------------------------------------- # ● ビューポートの更新 #-------------------------------------------------------------------------- def update_viewports(viewport) @viewport.tone = viewport.tone @viewport.ox = viewport.ox @viewport.update end #-------------------------------------------------------------------------- # ● タイルマップの更新 #-------------------------------------------------------------------------- def update_tilemap @tilemap.ox = $game_parallax_map.display_x * 32 @tilemap.oy = $game_parallax_map.display_y * 32 @tilemap.update end #-------------------------------------------------------------------------- # ● キャラクタースプライトの更新 #-------------------------------------------------------------------------- def update_characters @character_sprites.each{|sprite| sprite.update} end #-------------------------------------------------------------------------- # ● 遠景の更新 #-------------------------------------------------------------------------- def update_parallax if @parallax.bitmap @parallax.ox = $game_parallax_map.parallax_ox(@parallax.bitmap) @parallax.oy = $game_parallax_map.parallax_oy(@parallax.bitmap) end end end class Spriteset_Map #-------------------------------------------------------------------------- # ● ビューポートの作成 #-------------------------------------------------------------------------- alias _create_viewports_with_parallax_map create_viewports def create_viewports _create_viewports_with_parallax_map @parallax_map = Parallax_Tilemap.new end #-------------------------------------------------------------------------- # ● キャラクタースプライトの作成 #-------------------------------------------------------------------------- alias _create_characters_with_parallax_map create_characters def create_characters _create_characters_with_parallax_map @parallax_map.setup end #-------------------------------------------------------------------------- # ● 解放 #-------------------------------------------------------------------------- alias _dispose_with_parallax_map dispose def dispose _dispose_with_parallax_map dispose_parallax_map end #-------------------------------------------------------------------------- # ● 遠景マップの解放 #-------------------------------------------------------------------------- def dispose_parallax_map @parallax_map.dispose end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- alias _update_with_parallax_map update def update _update_with_parallax_map update_parallax_map end #-------------------------------------------------------------------------- # ● 遠景マップの更新 #-------------------------------------------------------------------------- def update_parallax_map @parallax_map.update(@viewport1) end end