#============================================================================== # RGSS2_SRPG2拡張 ランダム座標セット # 2012/01/19公開 # C Winter (http://ccwinter.blog.fc2.com/) #============================================================================== #============================================================================== # ■ コマンド #============================================================================== module TSRPG module Commands module_function #-------------------------------------------------------------------------- # ● ユニット配置可能なランダム座標の取得 # ax, ay : 判定を行う領域の左端・上端 # bx, by : 判定を行う領域の右端・下端 # n : 配置可能な座標が無かった場合、範囲を各方向1マス拡張して再判定する # その再判定を行う回数 未入力なら0回 # flag : nの再判定をしても最終的に配置可能な座標が無かった場合、 # trueなら[ax,ay]を返しfalseならnilを返す 未入力ならtrue #-------------------------------------------------------------------------- def make_random_pos(ax, ay, bx, by, n = 0, flag = true) return $game_srpg.make_random_pos(ax, ay, bx, by, n, flag) end #-------------------------------------------------------------------------- # ● イベントをランダム座標に移動させて敵ユニットにする # ax, ay : 判定を行う領域の左端・上端 # bx, by : 判定を行う領域の右端・下端 #-------------------------------------------------------------------------- def set_move_enemy(event_id, enemy_id, ax, ay, bx, by, n = 0, flag = true) pos = $game_srpg.make_random_pos(ax, ay, bx, by, n, flag) $game_srpg.add_move_enemy(event_id, enemy_id, pos[0], pos[1]) end end end #============================================================================== # ■ Game_Interpreter #============================================================================== class Game_Interpreter include TSRPG::Commands end #============================================================================== # ■ Game_Srpg #============================================================================== class Game_Srpg < Game_Map def make_random_pos(ax, ay, bx, by, n = 0, flag = true) pos = make_random_pos_2(ax, ay, bx, by, n) if pos == [] return [ax, ay] if flag == true return nil if flag == false end return pos[rand(pos.size)] end def make_random_pos_2(ax, ay, bx, by, n) x, y = 0 pos = [] for x in ax .. bx for y in ay .. by # 通行可能なタイルである ユニットが存在していない if tile_passable?(x, y) and alive_unit_xy(x, y) == nil pos.push([x, y]) #配置可能座標と判断して結果に加える end end end pos = make_random_pos_2(ax-1,ay-1,bx+1,by+1,n-1) if pos == [] and n > 0 return pos end #-------------------------------------------------------------------------- # ○ エネミーユニットの追加 #-------------------------------------------------------------------------- def add_move_enemy(event_id, enemy_id, x, y) event = @events[event_id] # イベントを取得 event.moveto(x, y) unless event.enemy_flag # まだ出現していない場合 set_unit_appear_pos(event) # 出現位置を補正 @enemy_list.push(event) # エネミーリストに追加 end event.set_enemy(enemy_id) # イベントをエネミーユニットとしてセット make_unique_names # エネミーユニットのユニークネームを作成 update_alive_unit_count # 生存ユニット数をカウント end end