#============================================================================== # ■ XP-RGSS-70 マップビュー [main] by Claimh #------------------------------------------------------------------------------ # [再定義] Scene_Map#update #============================================================================== #============================================================================== # ■ Sprite_MapViewBack : ミニマップ用背景スプライト #============================================================================== class Sprite_MapViewBack < Sprite #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(viewport, w, h, mini) super(viewport) self.bitmap = Bitmap.new(w, h) self.bitmap.fill_rect(0, 0, w, h, Color.new(0,0,0)) self.z = 0 self.visible = mini self.opacity = MapView::M_MAP_BACK_OP end end #============================================================================== # ■ Sprite_MapViewCharacter : キャラクタースプライト #============================================================================== class Sprite_MapViewCharacter < Sprite OPP = 12 #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(viewport, zoom, mini, character=nil) @character = character @opp = OPP @mini = mini @time = @m_idx = @_blink_count = 0 super(viewport) if @mini self.bitmap = Bitmap.new(32, 32) else b = RPG::Cache.character(@character.character_name, @character.character_hue) self.bitmap = Bitmap.new(b.width / 4, b.height / 4) self.bush_depth = @character.bush_depth end self.ox = @c_ox = self.oy = @c_oy = 0 self.zoom_x = self.zoom_y = zoom self.z = 100 refresh update_blink end #-------------------------------------------------------------------------- # ● 位置情報(x) #-------------------------------------------------------------------------- def p_x return (@character.nil? ? $game_player.x : @character.x) * 32 end #-------------------------------------------------------------------------- # ● 位置情報(y) #-------------------------------------------------------------------------- def p_y return (@character.nil? ? $game_player.y : @character.y) * 32 end #-------------------------------------------------------------------------- # ● 位置情報(ox) #-------------------------------------------------------------------------- def ox=(x) super(@c_ox + x) end #-------------------------------------------------------------------------- # ● 位置情報(oy) #-------------------------------------------------------------------------- def oy=(y) super(@c_oy + y) end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh self.bitmap.clear @mini ? draw_point : draw_char end #-------------------------------------------------------------------------- # ● キャラクター描画 #-------------------------------------------------------------------------- def draw_point self.bitmap.fill_rect(Rect.new(0,0,32,32), MapView::M_MAP_CH_CLR) end #-------------------------------------------------------------------------- # ● キャラクター描画 #-------------------------------------------------------------------------- def draw_char @c_pt = @mini ? @character.pattern : @m_idx @c_dr = @mini ? @character.direction : 2 b = RPG::Cache.character(@character.character_name, @character.character_hue) cw = b.width / 4 ch = b.height / 4 sx = @c_pt * cw sy = (@c_dr - 2) / 2 * ch self.bitmap.blt(0, 0, b, Rect.new(sx, sy, cw, ch)) @c_ox = (cw - 32) / 2 @c_oy = (ch > 48) ? (ch / 2) : (ch - 32) end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update @mini ? update_mini : update_full end #-------------------------------------------------------------------------- # ● フレーム更新(ミニマップ用) #-------------------------------------------------------------------------- def update_mini self.opacity -= @opp if self.opacity <= 0 @opp = -OPP elsif self.opacity >= 255 @opp = OPP end end #-------------------------------------------------------------------------- # ● フレーム更新(フルビュー用) #-------------------------------------------------------------------------- def update_full update_blink @time += 1 if @time == 16 @m_idx = (@m_idx + 1) % 4 @time = 0 refresh end # if @c_pt != @character.pattern or @c_dr != @character.direction # refresh # end end #-------------------------------------------------------------------------- # ● フレーム更新(blink) #-------------------------------------------------------------------------- def update_blink @_blink_count = (@_blink_count + 1) % 32 if @_blink_count < 16 alpha = (16 - @_blink_count) * 6 else alpha = (@_blink_count - 16) * 6 end self.color.set(255, 255, 255, alpha) end end #============================================================================== # ■ MapViewMas : タイルセット&イベント情報管理クラス(1マス) #============================================================================== class MapViewMas attr_reader :layer attr_reader :tile_id attr_reader :ev def initialize(layer=0, tile_id=0, ev=nil) @layer = layer; @tile_id = tile_id; @ev = ev end end #============================================================================== # ■ MapViewPriority : タイルセット&イベント情報管理クラス #============================================================================== class MapViewPriority PRI_MAX = 6 + 3 # タイルセット*6 + イベント*2 def initialize(w,h) @data = Table.new(w, h, PRI_MAX) @last_id = 0 @array = [] end def set(x, y, pri, mas) if @data[x, y, pri] == 0 or @data[x, y, pri].nil? @last_id += 1 @data[x, y, pri] = @last_id end @array[@data[x, y, pri]] = [] if @array[@data[x, y, pri]].nil? @array[@data[x, y, pri]].push(mas) end def get(x, y, pri) return [] if @array[@data[x, y, pri]].nil? return @array[@data[x, y, pri]] end end #============================================================================== # ■ MapViewAutotile : オートタイル位置 #============================================================================== class MapViewAutotilePos attr_reader :x attr_reader :y attr_reader :l def initialize(x, y, l) @x = x; @y = y; @l = l end end #============================================================================== # ■ MapViewAutotile : オートタイルアニメーション情報 #============================================================================== class MapViewAutotile attr_reader :pos attr_reader :anime_i def initialize(w,h,l) @pos = [] @anime_i = Table.new(w, h, l) end def set_point(x, y, l) @pos.push(MapViewAutotilePos.new(x, y, l)) @anime_i[x, y, l] = 0 end def next_i(x, y, l, koma) @anime_i[x, y, l] = (@anime_i[x, y, l] + 1) % koma end end #============================================================================== # ■ Sprite_MapView : タイルセット、イベント、プレイヤー表示クラス #============================================================================== class Sprite_MapView #-------------------------------------------------------------------------- #【仕様!】 # 負荷を抑えるための制限事項(主にミニマップ) # ・イベント、タイル毎のスプライトは作らない(=z軸は正確に配置されない) # ・イベント表示は更新しない # ・ミニマップ時はオートタイルの更新はしない # ・プレイヤーは最上位に表示 #-------------------------------------------------------------------------- #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(mapview) @map_id = mapview.map_id @time = 0 @mini = mapview.mini @auto_tile = (!@mini and MapView::F_MAP_AT) # ミニマップでは無効 # mapデータ読み込み @map = load_data(sprintf("Data/Map%03d.rxdata", @map_id)) # マップイベントのデータを設定 @events = [] for i in @map.events.keys.sort ev = Game_Event.new(@map_id, @map.events[i]) next unless ev.enable_mapview?(@mini) @events.push(ev) end @events.sort {|a, b| a.screen_z(RPG::Cache.character(a.character_name, a.character_hue).height / 4) - b.screen_z(RPG::Cache.character(b.character_name, b.character_hue).height / 4)} # タイルセットデータ @tileset = $data_tilesets[@map.tileset_id] # オートタイルデータ @at = MapViewAutotile.new(@map.width, @map.height, 3) if @mini vx = 640 - mapview.rect.x - mapview.rect.width vy = 480 - mapview.rect.y - mapview.rect.height zw = @map.width * 32.0 * MapView::M_MAP_ZOOM zh = @map.height * 32.0 * MapView::M_MAP_ZOOM case MapView::M_MAP_FIT when 1 mapview.rect.y = 480 - zh - vy if mapview.rect.height > zh when 3 mapview.rect.x = 640 - zw - vx if mapview.rect.width > zw mapview.rect.y = 480 - zh - vy if mapview.rect.height > zh when 7 when 9 mapview.rect.x = 640 - zw - vx if mapview.rect.width > zw end end # マップデータ作成 @data = MapViewPriority.new(@map.width, @map.height) make_mapdata ############################################################################ @viewport = Viewport.new(mapview.rect) @viewport.z = mapview.z # 表示スプライト(タイルセット+イベントの転送先) @viewsprite = Sprite.new(@viewport) @viewsprite.bitmap = Bitmap.new(r_w, r_h) @viewsprite.opacity = mapview.opacity @viewsprite.z = 10 # 位置補正 if !@mini and MapView::F_MAP_ZOOM == 0 ajust_zoom else self.zoom = @mini ? MapView::M_MAP_ZOOM : MapView::F_MAP_ZOOM end ajust_pos unless @mini # マップ描画 draw_map # カレントマップのときは現在位置表示 @player = nil if @map_id == $game_map.map_id @player = Sprite_MapViewCharacter.new(@viewport, @zoom, mapview.mini, $game_player) @player.z = @mini ? 1000 : 10 end @back = Sprite_MapViewBack.new(@viewport, z_w, z_h, @mini) update_filter end #-------------------------------------------------------------------------- # ● ズーム倍率変更(アスペクト比固定) #-------------------------------------------------------------------------- def zoom=(z) @zoom = z @player.zoom_x = @player.zoom_y = z unless @player.nil? @viewsprite.zoom_x = @viewsprite.zoom_y = z end #-------------------------------------------------------------------------- # ● 位置補正処理 #-------------------------------------------------------------------------- def ajust_pos zw = z_w; zh = z_h; vw = v_w; vh = v_h @viewsprite.x = zw < vw ? (vw - zw) / 2 : 0 @viewsprite.y = zh < vh ? (vh - zh) / 2 : 0 end #-------------------------------------------------------------------------- # ● 画面に合わせたズーム倍率を決める #-------------------------------------------------------------------------- def ajust_zoom x_zoom = (v_w * 1.0) / r_w y_zoom = (v_h * 1.0) / r_h self.zoom = x_zoom < y_zoom ? x_zoom : y_zoom end #-------------------------------------------------------------------------- # ● ビューポート矩形 #-------------------------------------------------------------------------- def v_w; return (@viewport.rect.width * 1.0); end def v_h; return (@viewport.rect.height * 1.0); end #-------------------------------------------------------------------------- # ● リアル矩形 #-------------------------------------------------------------------------- def r_w; return (@map.width * 32.0); end def r_h; return (@map.height * 32.0); end #-------------------------------------------------------------------------- # ● ズーム矩形 #-------------------------------------------------------------------------- def z_w; return (r_w * 1.0 * @zoom); end def z_h; return (r_h * 1.0 * @zoom); end #-------------------------------------------------------------------------- # ● 解放 #-------------------------------------------------------------------------- def dispose @viewsprite.bitmap.dispose unless @viewsprite.bitmap.nil? @viewsprite.dispose @player.dispose unless @player.nil? @back.dispose @viewport.dispose @map = @data = @events = @at = nil end #-------------------------------------------------------------------------- # ● 表示 #-------------------------------------------------------------------------- def visible=(f) @viewsprite.visible = f @player.visible = f unless @player.nil? @back.visible = f end #---------------------------------------------------------------------------- # ● リフレッシュ #---------------------------------------------------------------------------- def refresh @viewsprite.bitmap.clear @events = [] for i in @map.events.keys.sort ev = Game_Event.new(@map_id, @map.events[i]) next unless ev.enable_mapview?(@mini) @events.push(ev) end @events.sort {|a, b| a.screen_z(RPG::Cache.character(a.character_name, a.character_hue).height / 4) - b.screen_z(RPG::Cache.character(b.character_name, b.character_hue).height / 4)} @data = MapViewPriority.new(@map.width, @map.height) make_mapdata draw_map update_filter end #---------------------------------------------------------------------------- # ● Priority毎のマップデータ生成 #---------------------------------------------------------------------------- def make_mapdata # タイルマップ for i in 0..2 for yi in 0...@map.height for xi in 0...@map.width tile_id = @map.data[xi, yi, i] next if tile_id == 0 pri = $data_tilesets[@map.tileset_id].priorities[tile_id] @data.set(xi,yi,pri,MapViewMas.new(i, tile_id)) case tile_id when 0x30...0x180 # オートタイル at_name = @tileset.autotile_names[(tile_id / 0x30) - 1] next if at_name == "" cache_b = RPG::Cache.autotile(at_name) next if (cache_b.width / 96) < 2 # アニメーションなし @at.set_point(xi, yi, i) end end end end # イベント for ev in @events if ev.always_on_top pri = 8 elsif ev.tile_id == 0 b = RPG::Cache.character(ev.character_name, ev.character_hue) if (b.height / 4) > 32 # 高さが32超える @data.set(ev.x, ev.y, 7, MapViewMas.new(0, ev.tile_id, ev)) end pri = 6 else pri = $data_tilesets[@map.tileset_id].priorities[ev.tile_id] end @data.set(ev.x, ev.y, pri, MapViewMas.new(0, ev.tile_id, ev)) end end #---------------------------------------------------------------------------- # ● マップ描画 #---------------------------------------------------------------------------- PRI_MAP = [0,6,1,7,2,3,4,5,8] def draw_map for pri in PRI_MAP for yi in 0...@map.height for xi in 0...@map.width data = @data.get(xi, yi, pri) for d in data draw_point(xi, yi, d, pri) end end end end end #---------------------------------------------------------------------------- # ● オートタイル部分の再描画 #---------------------------------------------------------------------------- def refresh_autotile tmp_pos = [] # オートタイルを含むマスを消去 for pos in @at.pos tile_id = @map.data[pos.x, pos.y, pos.l] at_name = @tileset.autotile_names[(tile_id / 0x30) - 1] next if at_name == "" cache_b = RPG::Cache.autotile(at_name) koma = cache_b.width / 96 # コマ数 next if koma < 2 # アニメーションなし時は削除不要 # 次のアニメーションへ @at.next_i(pos.x, pos.y, pos.l, koma) rect = Rect.new(pos.x*32, pos.y*32, 32, 32) @viewsprite.bitmap.fill_rect(rect, Color.new(0, 0, 0, 0)) tmp_pos.push(MapViewAutotilePos.new(pos.x, pos.y, pos.l)) end # オートタイルのあるマスだけ再描画 for pos in tmp_pos for pri in PRI_MAP data = @data.get(pos.x, pos.y, pri) for d in data draw_point(pos.x, pos.y, d, pri) end end end end #---------------------------------------------------------------------------- # ● マス目の描画 #---------------------------------------------------------------------------- def draw_point(xi, yi, data, pri) case data.tile_id when 0x00 unless data.ev.nil? case pri when 6; draw_ev_character_btm(data.ev) when 7; draw_ev_character_top(data.ev) when 8; draw_ev_character(data.ev) end end when 0x01...0x30 # 透明 when 0x30...0x180 # オートタイル draw_autotile((data.tile_id/0x30)-1, data.tile_id%0x30, xi*32, yi*32, @at.anime_i[xi,yi,data.layer]) else # タイルセット draw_tileset(data.tile_id-384, xi*32, yi*32) end end #---------------------------------------------------------------------------- # ● オートタイル描画 # autotile_index : オートタイルIndex # ptn_id : パターンID # x : 描画位置X # y : 描画位置Y #---------------------------------------------------------------------------- def draw_autotile(autotile_index, ptn_id, x, y, anime_i=0) autotile_name = @tileset.autotile_names[autotile_index] return if autotile_name == "" draw_autotile_ptn(RPG::Cache.autotile(autotile_name), ptn_id, x, y, anime_i) end #---------------------------------------------------------------------------- # ● オートタイルパターン描画 #---------------------------------------------------------------------------- AT_A = 0x00; AT_B = 0x01; AT_C = 0x02 AT_D7 = 0x03; AT_D8 = 0x04; AT_D9 = 0x05 AT_D4 = 0x06; AT_D5 = 0x07; AT_D6 = 0x08 AT_D1 = 0x09; AT_D2 = 0x0A; AT_D3 = 0x0B def draw_autotile_ptn(cache_b, ptn_id, x, y, anime_i=0) case ptn_id when 0x00; draw_autotile_all(cache_b, AT_D5, x, y, anime_i) when 0x01; draw_autotile_h2(cache_b, [AT_C, AT_D5], 0, x, y, anime_i) draw_autotile_h(cache_b, AT_D5, 1, x, y, anime_i) when 0x02; draw_autotile_h2(cache_b, [AT_D5, AT_C], 0, x, y, anime_i) draw_autotile_h(cache_b, AT_D5, 1, x, y, anime_i) when 0x03; draw_autotile_h(cache_b, AT_C , 0, x, y, anime_i) draw_autotile_h(cache_b, AT_D5, 1, x, y, anime_i) when 0x04; draw_autotile_h(cache_b, AT_D5, 0, x, y, anime_i) draw_autotile_h2(cache_b, [AT_D5, AT_C], 1, x, y, anime_i) when 0x05; draw_autotile_4(cache_b, [AT_C, AT_D5, AT_D5, AT_C], x, y, anime_i) when 0x06; draw_autotile_v(cache_b, AT_D5, 0, x, y, anime_i) draw_autotile_v(cache_b, AT_C , 1, x, y, anime_i) when 0x07; draw_autotile_h(cache_b, AT_C , 0, x, y, anime_i) draw_autotile_h2(cache_b, [AT_D5, AT_C], 1, x, y, anime_i) when 0x08; draw_autotile_h(cache_b, AT_D5, 0, x, y, anime_i) draw_autotile_h2(cache_b, [AT_C, AT_D5], 1, x, y, anime_i) when 0x09; draw_autotile_v(cache_b, AT_C , 0, x, y, anime_i) draw_autotile_v(cache_b, AT_D5, 1, x, y, anime_i) when 0x0A; draw_autotile_4(cache_b, [AT_D5, AT_C , AT_C , AT_D5], x, y, anime_i) when 0x0B; draw_autotile_h(cache_b, AT_C , 0, x, y, anime_i) draw_autotile_h2(cache_b, [AT_C , AT_D5], 1, x, y, anime_i) when 0x0C; draw_autotile_h(cache_b, AT_D5, 0, x, y, anime_i) draw_autotile_h(cache_b, AT_C , 1, x, y, anime_i) when 0x0D; draw_autotile_h2(cache_b, [AT_C , AT_D5], 0, x, y, anime_i) draw_autotile_h(cache_b, AT_C , 1, x, y, anime_i) when 0x0E; draw_autotile_h2(cache_b, [AT_D5, AT_C ], 0, x, y, anime_i) draw_autotile_h(cache_b, AT_C , 1, x, y, anime_i) when 0x0F; draw_autotile_all(cache_b, AT_C, x, y, anime_i) when 0x10; draw_autotile_all(cache_b, AT_D4, x, y, anime_i) when 0x11; draw_autotile_h2(cache_b, [AT_D4, AT_C ], 0, x, y, anime_i) draw_autotile_h(cache_b, AT_D4, 1, x, y, anime_i) when 0x12; draw_autotile_h(cache_b, AT_D4, 0, x, y, anime_i) draw_autotile_h2(cache_b, [AT_D4, AT_C ], 1, x, y, anime_i) when 0x13; draw_autotile_v(cache_b, AT_D4, 0, x, y, anime_i) draw_autotile_v(cache_b, AT_C , 1, x, y, anime_i) when 0x14; draw_autotile_all(cache_b, AT_D8, x, y, anime_i) when 0x15; draw_autotile_h(cache_b, AT_D8, 0, x, y, anime_i) draw_autotile_h2(cache_b, [AT_D8, AT_C ], 1, x, y, anime_i) when 0x16; draw_autotile_h(cache_b, AT_D8, 0, x, y, anime_i) draw_autotile_h2(cache_b, [AT_C , AT_D8], 1, x, y, anime_i) when 0x17; draw_autotile_h(cache_b, AT_D8, 0, x, y, anime_i) draw_autotile_h(cache_b, AT_C , 1, x, y, anime_i) when 0x18; draw_autotile_all(cache_b, AT_D6, x, y, anime_i) when 0x19; draw_autotile_h(cache_b, AT_D6, 0, x, y, anime_i) draw_autotile_h2(cache_b, [AT_C , AT_D6], 1, x, y, anime_i) when 0x1A; draw_autotile_h2(cache_b, [AT_C , AT_D6], 0, x, y, anime_i) draw_autotile_h(cache_b, AT_D6, 1, x, y, anime_i) when 0x1B; draw_autotile_v(cache_b, AT_C , 0, x, y, anime_i) draw_autotile_v(cache_b, AT_D6, 1, x, y, anime_i) when 0x1C; draw_autotile_all(cache_b, AT_D2, x, y, anime_i) when 0x1D; draw_autotile_h2(cache_b, [AT_C , AT_D2], 0, x, y, anime_i) draw_autotile_h(cache_b, AT_D2, 1, x, y, anime_i) when 0x1E; draw_autotile_h2(cache_b, [AT_D2, AT_C ], 0, x, y, anime_i) draw_autotile_h(cache_b, AT_D2, 1, x, y, anime_i) when 0x1F; draw_autotile_h(cache_b, AT_C , 0, x, y, anime_i) draw_autotile_h(cache_b, AT_D2, 1, x, y, anime_i) when 0x20; draw_autotile_v(cache_b, AT_D4, 0, x, y, anime_i) draw_autotile_v(cache_b, AT_D6, 1, x, y, anime_i) when 0x21; draw_autotile_h(cache_b, AT_D8, 0, x, y, anime_i) draw_autotile_h(cache_b, AT_D2, 1, x, y, anime_i) when 0x22; draw_autotile_all(cache_b, AT_D7, x, y, anime_i) when 0x23; draw_autotile_h(cache_b, AT_D7, 0, x, y, anime_i) draw_autotile_h2(cache_b, [AT_D7, AT_C ], 1, x, y, anime_i) when 0x24; draw_autotile_all(cache_b, AT_D9, x, y, anime_i) when 0x25; draw_autotile_h(cache_b, AT_D9, 0, x, y, anime_i) draw_autotile_h2(cache_b, [AT_C , AT_D9], 1, x, y, anime_i) when 0x26; draw_autotile_all(cache_b, AT_D3, x, y, anime_i) when 0x27; draw_autotile_h2(cache_b, [AT_C , AT_D3], 0, x, y, anime_i) draw_autotile_h(cache_b, AT_D3, 1, x, y, anime_i) when 0x28; draw_autotile_all(cache_b, AT_D1, x, y, anime_i) when 0x29; draw_autotile_h2(cache_b, [AT_D1, AT_C ], 0, x, y, anime_i) draw_autotile_h(cache_b, AT_D1, 1, x, y, anime_i) when 0x2A; draw_autotile_v(cache_b, AT_D7, 0, x, y, anime_i) draw_autotile_v(cache_b, AT_D9, 1, x, y, anime_i) when 0x2B; draw_autotile_h(cache_b, AT_D7, 0, x, y, anime_i) draw_autotile_h(cache_b, AT_D1, 1, x, y, anime_i) when 0x2C; draw_autotile_v(cache_b, AT_D1, 0, x, y, anime_i) draw_autotile_v(cache_b, AT_D3, 1, x, y, anime_i) when 0x2D; draw_autotile_h(cache_b, AT_D9, 0, x, y, anime_i) draw_autotile_h(cache_b, AT_D3, 1, x, y, anime_i) when 0x2E; draw_autotile_4(cache_b, [AT_D7, AT_D9, AT_D1, AT_D3], x, y, anime_i) when 0x2F; draw_autotile_all(cache_b, AT_A , x, y, anime_i) else; p "err: autotile", sprintf("%#x", ptn_id), x, y, anime_i end end #---------------------------------------------------------------------------- # ● オートタイルパターン描画 (同一パターン転送) #---------------------------------------------------------------------------- def draw_autotile_all(cache_b, ptn, x, y, anime_i=0) xx = (ptn % 3) * 32 + (anime_i * 96) yy = (ptn / 3) * 32 src_rect = Rect.new(xx, yy, 32, 32) @viewsprite.bitmap.blt(x, y, cache_b, src_rect) end #---------------------------------------------------------------------------- # ● オートタイルパターン描画 (2分割パターン転送) # _h : 水平 2分割パターンの転送 # _v : 垂直 2分割パターンの転送 #---------------------------------------------------------------------------- def draw_autotile_h(cache_b, ptn, ii, x, y, anime_i=0) yi = ii * 16 xx = ((ptn % 3) * 32) + (anime_i * 96) yy = ((ptn / 3) * 32) src_rect = Rect.new(xx, yy+yi, 32, 16) @viewsprite.bitmap.blt(x, y+yi, cache_b, src_rect) end def draw_autotile_v(cache_b, ptn, ii, x, y, anime_i=0) xi = ii * 16 xx = ((ptn % 3) * 32) + (anime_i * 96) yy = ((ptn / 3) * 32) src_rect = Rect.new(xx+xi, yy, 16, 32) @viewsprite.bitmap.blt(x+xi, y, cache_b, src_rect) end #---------------------------------------------------------------------------- # ● オートタイルパターン描画 (4分割*2パターン転送) # _h2 : 水平 4分割*2パターンの転送 # _v2 : 垂直 4分割*2パターンの転送 #---------------------------------------------------------------------------- def draw_autotile_h2(cache_b, ptn, ii, x, y, anime_i=0) yi = ii * 16 for i in 0..1 xi = (i % 2) * 16 xx = ((ptn[i] % 3) * 32) + (anime_i * 96) yy = ((ptn[i] / 3) * 32) src_rect = Rect.new(xx+xi, yy+yi, 16, 16) @viewsprite.bitmap.blt(x+xi, y+yi, cache_b, src_rect) end end def draw_autotile_v2(cache_b, ptn, ii, x, y, anime_i=0) xi = ii * 16 for i in 0..1 yi = (i / 2) * 16 xx = ((ptn[i] % 3) * 32) + (anime_i * 96) yy = ((ptn[i] / 3) * 32) src_rect = Rect.new(xx+xi, yy+yi, 16, 16) @viewsprite.bitmap.blt(x+xi, y+yi, cache_b, src_rect) end end #---------------------------------------------------------------------------- # ● オートタイルパターン描画 (4分割*4パターン転送) #---------------------------------------------------------------------------- def draw_autotile_4(cache_b, ptn, x, y, anime_i=0) for i in 0..3 xi = (i % 2) * 16 yi = (i / 2) * 16 xx = ((ptn[i] % 3) * 32) + (anime_i * 96) yy = ((ptn[i] / 3) * 32) src_rect = Rect.new(xx+xi, yy+yi, 16, 16) @viewsprite.bitmap.blt(x+xi, y+yi, cache_b, src_rect) end end #---------------------------------------------------------------------------- # ● タイルセット描画 # pri : プライオリティ # index : タイルセットIndex # x : 描画位置X # y : 描画位置Y #---------------------------------------------------------------------------- def draw_tileset(index, x, y) cache_b = RPG::Cache.tileset(@tileset.tileset_name) xx = (index % 8) * 32 yy = (index / 8) * 32 src_rect = Rect.new(xx, yy, 32, 32) @viewsprite.bitmap.blt(x, y, cache_b, src_rect) end #---------------------------------------------------------------------------- # ● イベントキャラクター描画 #---------------------------------------------------------------------------- def draw_ev_character(ev) b = RPG::Cache.character(ev.character_name, ev.character_hue) cw = b.width / 4 ch = b.height / 4 sx = ev.pattern * cw sy = (ev.direction - 2) / 2 * ch w = (cw - 32) / 2 h = ch - 32 src_rect = Rect.new(sx, sy, cw, ch) @viewsprite.bitmap.blt(ev.x*32-w, ev.y*32-h, b, src_rect, ev.opacity) end #---------------------------------------------------------------------------- # ● イベントキャラクター描画(下 32px) #---------------------------------------------------------------------------- def draw_ev_character_btm(ev) b = RPG::Cache.character(ev.character_name, ev.character_hue) cw = b.width / 4 ch = b.height / 4 sx = ev.pattern * cw sy = (ev.direction - 2) / 2 * ch w = (cw - 32) / 2 src_rect = Rect.new(sx, sy+(ch-32), cw, 32) @viewsprite.bitmap.blt(ev.x*32-w, ev.y*32, b, src_rect, ev.opacity) end #---------------------------------------------------------------------------- # ● イベントキャラクター描画(上) #---------------------------------------------------------------------------- def draw_ev_character_top(ev) b = RPG::Cache.character(ev.character_name, ev.character_hue) cw = b.width / 4 ch = b.height / 4 sx = ev.pattern * cw sy = (ev.direction - 2) / 2 * ch w = (cw - 32) / 2 h = ch - 32 src_rect = Rect.new(sx, sy, cw, ch-32) @viewsprite.bitmap.blt(ev.x*32-w, ev.y*32-h, b, src_rect, ev.opacity) end #---------------------------------------------------------------------------- # ● フレーム更新 #---------------------------------------------------------------------------- def update update_filter if @mini @player.update unless @player.nil? update_autotile if @auto_tile end #---------------------------------------------------------------------------- # ● オートタイルのアニメーション #---------------------------------------------------------------------------- def update_autotile @time += 1 if @time == 16 refresh_autotile @time = 0 end end #---------------------------------------------------------------------------- # ● マップのピックアップ位置の補正 #---------------------------------------------------------------------------- def cur_pos_x return ((@map_id == $game_map.map_id) ? $game_player.x : (@map.width / 2).truncate) end def cur_pos_y return ((@map_id == $game_map.map_id) ? $game_player.y : (@map.height / 2).truncate) end #---------------------------------------------------------------------------- # ● マップのピックアップ位置の補正 #---------------------------------------------------------------------------- def update_filter c_x = (v_w / 2 - 16.0) / @zoom c_y = (v_h / 2 - 16.0) / @zoom max_x = r_w - v_w / @zoom max_y = r_h - v_h / @zoom p_x = cur_pos_x * 32 p_y = cur_pos_y * 32 @viewsprite.ox = [0, [p_x - c_x, max_x].min].max @viewsprite.oy = [0, [p_y - c_y, max_y].min].max # キャラクター位置更新 unless @player.nil? @player.x = @viewsprite.x + p_x * @zoom @player.y = @viewsprite.y + p_y * @zoom @player.ox = @viewsprite.ox @player.oy = @viewsprite.oy end end #-------------------------------------------------------------------------- # ● フルビュー化 #-------------------------------------------------------------------------- def full if MapView::F_MAP_ZOOM != 0 if @zoom == MapView::F_MAP_ZOOM ajust_zoom else self.zoom = MapView::F_MAP_ZOOM end ajust_pos update_filter end end #-------------------------------------------------------------------------- # ● ズームイン #-------------------------------------------------------------------------- def zoomin org_zoom = @zoom new_zoom = [0.1, org_zoom - 0.02].max self.zoom = new_zoom if MapView::F_MAP_ZOOM > new_zoom and (z_w <= v_w and z_h <= v_h) self.zoom = org_zoom return false # 画面より小さくなるときは無視 end ajust_pos update_filter return (org_zoom != @zoom) end #-------------------------------------------------------------------------- # ● ズームアウト #-------------------------------------------------------------------------- def zoomout org_zoom = @zoom self.zoom = [1.0, @zoom + 0.02].min ajust_pos update_filter return (org_zoom != @zoom) end end #============================================================================== # ■ Sprite_MapViewName : フルビュー用マップ名表示ウィンドウ #============================================================================== class Window_MapViewName < Window_Base #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(map_id) n = MapView::F_MAP_RECT_N m = MapView::F_MAP_RECT_M w = MapView::F_MAP_RECT_W h = MapView::F_MAP_RECT_H case MapView::F_MAP_FIT when 1; rect = Rect.new( n, 480-h-m, w, h) when 3; rect = Rect.new(640-w-n, 480-h-m, w, h) when 7; rect = Rect.new( n, m, w, h) when 9; rect = Rect.new(640-w-n, m, w, h) else; rect = Rect.new(640-w-n, 480-h-m, w, h) end super(rect.x, rect.y, rect.width, rect.height) self.contents = Bitmap.new(width - 32, height - 32) self.back_opacity = 128 @map_id = map_id < 0 ? $game_map.map_id : map_id @mapInfo = load_data(sprintf("Data/MapInfos.rxdata")) refresh end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh self.contents.clear self.contents.draw_text(0, 0, self.contents.width, 32, MapView.map_name(@mapInfo, @map_id)) end end #============================================================================== # ■ Sprite_MapViewName : フルビュー用マップ名表示スプライト #============================================================================== class Sprite_MapViewName < Sprite #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(map_id) b = RPG::Cache.windowskin(MapView::F_MAP_NAME_BG) n = MapView::F_MAP_RECT_N m = MapView::F_MAP_RECT_M case MapView::F_MAP_FIT when 1; rect = Rect.new( n, 480-b.height-m, b.width, b.height) when 3; rect = Rect.new(640-b.width-n, 480-b.height-m, b.width, b.height) when 7; rect = Rect.new( n, m, b.width, b.height) when 9; rect = Rect.new(640-b.width-n, m, b.width, b.height) else; rect = Rect.new(640-b.width-n, 480-b.height-m, b.width, b.height) end @viewport = Viewport.new(rect) @viewport.z = 200 super(@viewport) self.bitmap = Bitmap.new(b.width, b.height) @map_id = map_id < 0 ? $game_map.map_id : map_id @mapInfo = load_data(sprintf("Data/MapInfos.rxdata")) refresh end #-------------------------------------------------------------------------- # ● オブジェクト開放 #-------------------------------------------------------------------------- def dispose super @viewport.dispose end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh self.bitmap.clear b = RPG::Cache.windowskin(MapView::F_MAP_NAME_BG) self.bitmap.blt(0,0,b,Rect.new(0,0,b.width,b.height)) self.bitmap.draw_text(16, 0, self.bitmap.width, 32, MapView.map_name(@mapInfo, @map_id)) end end if MapView::USE_MINIMAP #============================================================================== # ■ Game_System #============================================================================== class Game_System attr_accessor :miniview # ミニマップ表示状態(EV) attr_accessor :miniview_usr # ミニマップ表示状態(User操作) #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- alias init_mapview initialize def initialize init_mapview @miniview = @miniview_usr = true end end #============================================================================== # ■ Interpreter #============================================================================== class Interpreter #-------------------------------------------------------------------------- # ● ミニマップの表示ON/OFF #-------------------------------------------------------------------------- def minimap(flag) return true unless $scene.is_a?(Scene_Map) $scene.spriteset.minimap(flag) return true end #-------------------------------------------------------------------------- # ● ミニマップの再描画 #-------------------------------------------------------------------------- def refresh_minimap return true unless $scene.is_a?(Scene_Map) $scene.spriteset.refresh_minimap return true end end #============================================================================== # ■ Scene_Map #============================================================================== class Scene_Map attr_reader :spriteset end #============================================================================== # ■ Spriteset_Map #============================================================================== class Spriteset_Map #-------------------------------------------------------------------------- # ● ミニマップの表示ON/OFF(user状態も上書き) #-------------------------------------------------------------------------- def minimap(flag) return if @mapview.nil? @mapview.visible = $game_system.miniview = $game_system.miniview_usr = flag end #-------------------------------------------------------------------------- # ● ミニマップの表示ON/OFF(user操作, EVロックされている場合は無視) #-------------------------------------------------------------------------- def mapview_user return false if @mapview.nil? return false unless $game_system.miniview @mapview.visible = $game_system.miniview_usr = !$game_system.miniview_usr return true end #-------------------------------------------------------------------------- # ● ミニマップの再描画 #-------------------------------------------------------------------------- def refresh_minimap return if @mapview.nil? @mapview.refresh end #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- alias init_mapview initialize def initialize init_mapview v = (MapView.mc_visible? and $game_system.miniview and $game_system.miniview_usr) @mapview = v ? Sprite_MapView.new(MapViewMini.new) : nil end #-------------------------------------------------------------------------- # ● 解放 #-------------------------------------------------------------------------- alias dispose_mapview dispose def dispose dispose_mapview @mapview.dispose unless @mapview.nil? end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- alias update_mapview update def update update_mapview @mapview.update unless @mapview.nil? end end end # if MapView::USE_MINIMAP if MapView::USE_M_MAP_DIRECT or MapView::USE_F_MAP_DIRECT #============================================================================== # ■ Game_Temp #============================================================================== class Game_Temp #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :mapview_calling # マップビュー 呼び出しフラグ #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- alias init_mapview initialize def initialize init_mapview @mapview_calling = false end end #============================================================================== # ■ Scene_Map #============================================================================== class Scene_Map #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update # ループ loop do # マップ、インタプリタ、プレイヤーの順に更新 # (この更新順序は、イベントを実行する条件が満たされているときに # プレイヤーに一瞬移動する機会を与えないなどの理由で重要) $game_map.update $game_system.map_interpreter.update $game_player.update # システム (タイマー)、画面を更新 $game_system.update $game_screen.update # プレイヤーの場所移動中でなければループを中断 unless $game_temp.player_transferring break end # 場所移動を実行 transfer_player # トランジション処理中の場合、ループを中断 if $game_temp.transition_processing break end end # スプライトセットを更新 @spriteset.update # メッセージウィンドウを更新 @message_window.update # ゲームオーバーの場合 if $game_temp.gameover # ゲームオーバー画面に切り替え $scene = Scene_Gameover.new return end # タイトル画面に戻す場合 if $game_temp.to_title # タイトル画面に切り替え $scene = Scene_Title.new return end # トランジション処理中の場合 if $game_temp.transition_processing # トランジション処理中フラグをクリア $game_temp.transition_processing = false # トランジション実行 if $game_temp.transition_name == "" Graphics.transition(20) else Graphics.transition(40, "Graphics/Transitions/" + $game_temp.transition_name) end end # メッセージウィンドウ表示中の場合 if $game_temp.message_window_showing return end return if update_mapview # MapView切り替え検出(この行だけ追加) # エンカウント カウントが 0 で、エンカウントリストが空ではない場合 if $game_player.encounter_count == 0 and $game_map.encounter_list != [] # イベント実行中かエンカウント禁止中でなければ unless $game_system.map_interpreter.running? or $game_system.encounter_disabled # トループを決定 n = rand($game_map.encounter_list.size) troop_id = $game_map.encounter_list[n] # トループが有効なら if $data_troops[troop_id] != nil # バトル呼び出しフラグをセット $game_temp.battle_calling = true $game_temp.battle_troop_id = troop_id $game_temp.battle_can_escape = true $game_temp.battle_can_lose = false $game_temp.battle_proc = nil end end end # B ボタンが押された場合 if Input.trigger?(Input::B) # イベント実行中かメニュー禁止中でなければ unless $game_system.map_interpreter.running? or $game_system.menu_disabled # メニュー呼び出しフラグと SE 演奏フラグをセット $game_temp.menu_calling = true $game_temp.menu_beep = true end end # デバッグモードが ON かつ F9 キーが押されている場合 if $DEBUG and Input.press?(Input::F9) # デバッグ呼び出しフラグをセット $game_temp.debug_calling = true end # プレイヤーの移動中ではない場合 unless $game_player.moving? # 各種画面の呼び出しを実行 if $game_temp.battle_calling call_battle elsif $game_temp.shop_calling call_shop elsif $game_temp.name_calling call_name elsif $game_temp.menu_calling call_menu elsif $game_temp.save_calling call_save elsif $game_temp.debug_calling call_debug end end end #-------------------------------------------------------------------------- # ● フレーム更新(MapView用) #-------------------------------------------------------------------------- def update_mapview return false if $game_system.map_interpreter.running? # ミニマップ切り替え if MapView::USE_MINIMAP and MapView::USE_M_MAP_DIRECT and Input.trigger?(MapView::M_MAP_D_KEY) if MapView.fc_visible? and $game_system.miniview and @spriteset.mapview_user $game_system.se_play($data_system.decision_se) else $game_system.se_play($data_system.buzzer_se) end end # フルビュー切り替え if MapView::USE_F_MAP_DIRECT and Input.trigger?(MapView::F_MAP_D_KEY) $game_temp.mapview_calling = true return false elsif $game_temp.mapview_calling and !$game_player.moving? $game_temp.mapview_calling = false if MapView.fc_visible? $game_system.se_play($data_system.decision_se) $scene = Scene_MapView.new $scene.direct return true # シーン切り替えさせる else $game_system.se_play($data_system.buzzer_se) return false end end return false end end end # if MapView::USE_M_MAP_DIRECT or MapView::USE_F_MAP_DIRECT #============================================================================== # ■ Scene_MapView : フルビュー用シーンクラス #============================================================================== class Scene_MapView #-------------------------------------------------------------------------- # ● メイン処理 #-------------------------------------------------------------------------- def initialize(index=-1, map_id=-1) @menu_index = index @map_id = map_id @direct = false end #-------------------------------------------------------------------------- # ● 直接呼び出し #-------------------------------------------------------------------------- def direct @direct = true end #-------------------------------------------------------------------------- # ● メイン処理 #-------------------------------------------------------------------------- def main start # 開始処理 Graphics.transition # トランジション実行 loop do Graphics.update # ゲーム画面を更新 Input.update # 入力情報を更新 update # フレーム更新 break if $scene != self # 画面が切り替わったらループを中断 end Graphics.update Graphics.freeze # トランジション準備 terminate # 終了処理 end #-------------------------------------------------------------------------- # ● 開始処理 #-------------------------------------------------------------------------- def start @sprite = Sprite_MapView.new(MapViewFull.new(@map_id)) if MapView::F_MAP_NAME @name = MapView.map_name_class(@map_id) end end #-------------------------------------------------------------------------- # ● 終了処理 #-------------------------------------------------------------------------- def terminate @name.dispose @sprite.dispose end #---------------------------------------------------------------------------- # ● フレーム更新 #---------------------------------------------------------------------------- def update @sprite.update if Input.repeat?(Input::B) $game_system.se_play($data_system.cancel_se) next_scene elsif Input.repeat?(Input::C) $game_system.se_play($data_system.decision_se) MapView::F_MAP_CHG_FL ? @sprite.full : next_scene elsif @direct and Input.trigger?(MapView::F_MAP_D_KEY) $game_system.se_play($data_system.decision_se) next_scene elsif MapView::F_MAP_ZOOM_IO and Input::repeat?(Input::UP) @sprite.zoomin #$game_system.se_play(@sprite.zoomin ? $data_system.cursor_se : $data_system.buzzer_se) elsif MapView::F_MAP_ZOOM_IO and Input::repeat?(Input::DOWN) @sprite.zoomout #$game_system.se_play(@sprite.zoomout ? $data_system.cursor_se : $data_system.buzzer_se) end end #---------------------------------------------------------------------------- # ● 次のシーン #---------------------------------------------------------------------------- def next_scene $scene = (@menu_index < 0) ? Scene_Map.new : Scene_Menu.new(@menu_index) end end