#============================================================================== # ★ Circle_Move ver1.0 by USK #------------------------------------------------------------------------------ # ・キャラクターを円弧を描くように移動させます。 #============================================================================== =begin イベントコマンドのスクリプトで circle_move((イベントID),(x移動マス),(y移動マス),(フレーム数),(回転方向)) と記入して使います。 例:circle_move(1,4,-3,180,false) (イベントID)には円弧移動をする対象のイベントIDが入ります。 対象がプレイヤーの場合-1を、イベント自身の場合は0を記入してください。 (x移動マス),(y移動マス)には対象が現在座標からx,y方向に何マス移動するかを 記入します。x方向は右が+、y方向は下が+になります。 (フレーム数)には目標まで何フレームかけて移動するかを記入します。 (回転方向)には、時計回りに弧を描く場合はtrue、反時計回りの場合はfalseと記入 してください。 移動ルートの設定のスクリプトで circle_move((x移動マス),(y移動マス),(フレーム数),(回転方向)) と記入すると設定の対象が円弧移動します。 circle_move(1, 4,-4,180,true) circle_move(1, 4, 4,180,true) circle_move(1,-4, 4,180,true) circle_move(1,-4,-4,180,true) のように記入すると円周上を一周することができます。 =end #============================================================================== # ■ Game_CharacterBase #============================================================================== class Game_CharacterBase #-------------------------------------------------------------------------- # ● 非公開メンバ変数の初期化 #-------------------------------------------------------------------------- alias :usk_cm_init_private_members :init_private_members def init_private_members @cx = [] @cy = [] usk_cm_init_private_members end #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def cx @cx[-1] || @x end #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def cy @cy[-1] || @y end #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def circle_move(dx, dy, div = 240, clockwise = true) pi = Math::PI / (div * 2) _cx = self.cx _cy = self.cy div.times do |i| j = i + 1 if ((dx < 0 && dy < 0) || (dx > 0 && dy > 0)) != clockwise @cx << _cx - dx * (Math.cos(pi * j) - 1) @cy << _cy + dy * Math.sin(pi * j) else @cx << _cx + dx * Math.sin(pi * j) @cy << _cy - dy * (Math.cos(pi * j) - 1) end end end #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def cm_direction_set d = direction dx = @cx[1] - @cx[0] dy = @cy[1] - @cy[0] if dx > 0 if dy > 0 d = dx > dy ? 6 : 2 else d = dx > -dy ? 6 : 8 end else if dy > 0 d = dx > -dy ? 2 : 4 else d = dx > dy ? 8 : 4 end end set_direction(d) end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- alias :usk_cm_update :update def update usk_cm_update process_circle_move end #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def process_circle_move if @cx.empty? return false elsif @cx.size == 1 @x = @real_x = @cx.shift.round @y = @real_y = @cy.shift.round else cm_direction_set @real_x = @cx.shift @real_y = @cy.shift end increase_steps true end end #============================================================================== # ■ Game_Player #============================================================================== class Game_Player #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def circle_move(dx, dy, div = 240, clockwise = true) super followers.each {|f| f.circle_move(dx, dy, div, clockwise)} end #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def process_circle_move center(@real_x, @real_y) if super end #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def route_preceding_character_x @cx end #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def route_preceding_character_y @cy end end #============================================================================== # ■ Game_Follower #============================================================================== class Game_Follower #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def cx $game_player.cx end #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def cy $game_player.cy end #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def circle_move(dx, dy, div = 240, clockwise = true) if @cx.empty? @cx += route_preceding_character_x @cy += route_preceding_character_y else i = $game_player.route_preceding_character_x.size - 1 - div @cx += $game_player.route_preceding_character_x[i, div] @cy += $game_player.route_preceding_character_y[i, div] end end #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def route_preceding_character_x ret = [] dx = @preceding_character.x - @x if dx > 0 x = @x + distance_per_frame while @preceding_character.x > x ret << x x += distance_per_frame end elsif dx < 0 x = @x - distance_per_frame while @preceding_character.x < x ret << x x -= distance_per_frame end else ret += [@x] * (256 / 2 ** real_move_speed - 1) end ret << @preceding_character.x ret += @preceding_character.route_preceding_character_x end #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def route_preceding_character_y ret = [] dy = @preceding_character.y - @y if dy > 0 y = @y + distance_per_frame while @preceding_character.y > y ret << y y += distance_per_frame end elsif dy < 0 y = @y - distance_per_frame while @preceding_character.y < y ret << y y -= distance_per_frame end else ret += [@y] * (256 / 2 ** real_move_speed - 1) end ret << @preceding_character.y ret += @preceding_character.route_preceding_character_y end end #============================================================================== # ■ Game_Interpreter #============================================================================== class Game_Interpreter #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def circle_move(event_id, dx, dy, div = 240, clockwise = true) get_character(event_id).circle_move(dx, dy, div, clockwise) end end