- 注册时间
- 2004-10-29
- 最后登录
- 2006-4-22
⑤进阶
- 积分
- 568
|
谁知道加到哪里?小弟感激不尽!!!
效果:可以实现八方向键行走并且解除系统默认的行走限制。
代码:
# ドット単位移動人柱バージョン
#==============================================================================
# ■ Game_Player
#------------------------------------------------------------------------------
# プレイヤーを扱うクラスです。イベントの起動判定や、マップのスクロールなどの
# 機能を持っています。このクラスのインスタンスは $game_player で参照されます。
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# ● 公開インスタンス変数
#--------------------------------------------------------------------------
attr_accessor :revise_x # X座標補正値
attr_accessor :revise_y # Y座標補正値
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
def initialize
@revise_x = 0
@revise_y = 0
super
end
def moving?
if @move_route_forcing
super
else
return (@x != (@real_x / 128.0).round or @y != (@real_y / 128.0).round)
end
end
#--------------------------------------------------------------------------
# ● 下に移動
#--------------------------------------------------------------------------
def move_down_p
# 下を向く
turn_down
# 下に移動
distance = 2 ** @move_speed
down1(@x, @y, distance)
end
def down1(x, y, distance)
return false unless down2(x, y, distance)
if @revise_x < -32
return false unless down2(x - 1, y, distance)
elsif @revise_x > 32
return false unless down2(x + 1, y, distance)
end
@revise_y += distance
return true
end
def down2(x, y, distance)
if @revise_y + distance > 0
unless passable?(x, y, 2)
@revise_y = 0
@event = check_event_trigger_touch(x, y+1)
return false
end
end
return true
end
#--------------------------------------------------------------------------
# ● 左に移動
#--------------------------------------------------------------------------
def move_left_p
# 左を向く
turn_left
distance = 2 ** @move_speed
left1(@x, @y, distance)
end
def left1(x, y, distance)
return false unless left2(x, y, distance)
if @revise_y < -48
return false unless left2(x, y - 1, distance)
elsif @revise_y > 0
return false unless left2(x, y + 1, distance)
end
@revise_x -= distance
return true
end
def left2(x, y, distance)
if @revise_x - distance < -32
unless passable?(x, y, 4)
@revise_x = -32
@event = check_event_trigger_touch(x-1, y)
return false
end
end
return true
end
#--------------------------------------------------------------------------
# ● 右に移動
#--------------------------------------------------------------------------
def move_right_p
# 右を向く
turn_right
distance = 2 ** @move_speed
right1(@x, @y, distance)
end
def right1(x, y, distance)
return false unless right2(x, y, distance)
if @revise_y < -48
return false unless right2(x, y, distance)
elsif @revise_y > 0
return false unless right2(x, y + 1, distance)
end
@revise_x += distance
return true
end
def right2(x, y, distance)
if @revise_x + distance > 32
unless passable?(x, y, 6)
@revise_x = 32
@event = check_event_trigger_touch(x+1, y)
return false
end
end
return true
end
#--------------------------------------------------------------------------
# ● 上に移動
#--------------------------------------------------------------------------
def move_up_p
# 上を向く
turn_up
# 下に移動
distance = 2 ** @move_speed
up1(@x, @y, distance)
end
def up1(x, y, distance)
return false unless up2(x, y, distance)
if @revise_x < -32
return false unless up2(x - 1, y, distance)
elsif @revise_x > 32
return false unless up2(x + 1, y, distance)
end
@revise_y -= distance
return true
end
def up2(x, y, distance)
if @revise_y - distance < -48
unless passable?(x, y, 8)
@revise_y = -48
@event = check_event_trigger_touch(x, y-1)
return false
end
end
return true
end
#--------------------------------------------------------------------------
# ● 左下に移動
#--------------------------------------------------------------------------
def move_lower_left_p
# 向き固定でない場合
unless @direction_fix
# 右向きだった場合は左を、上向きだった場合は下を向く
@direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
end
# 左下に移動
distance = (2 ** @move_speed) / Math.sqrt(2)
turn_left unless down1(@x, @y, distance)
turn_down if @event
turn_down unless left1(@x, @y, distance) unless @event
turn_left if @event
end
#--------------------------------------------------------------------------
# ● 右下に移動
#--------------------------------------------------------------------------
def move_lower_right_p
# 向き固定でない場合
unless @direction_fix
# 左向きだった場合は右を、上向きだった場合は下を向く
@direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
end
# 右下に移動
distance = (2 ** @move_speed) / Math.sqrt(2)
turn_right unless down1(@x, @y, distance)
turn_down if @event
turn_down unless right1(@x, @y, distance) unless @event
turn_right if @event
end
#--------------------------------------------------------------------------
# ● 左上に移動
#--------------------------------------------------------------------------
def move_upper_left_p
# 向き固定でない場合
unless @direction_fix
# 右向きだった場合は左を、下向きだった場合は上を向く
@direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
end
# 左下に移動
distance = (2 ** @move_speed) / Math.sqrt(2)
turn_left unless up1(@x, @y, distance)
turn_up if @event
turn_up unless left1(@x, @y, distance) unless @event
turn_left if @event
end
#--------------------------------------------------------------------------
# ● 右上に移動
#--------------------------------------------------------------------------
def move_upper_right_p
# 向き固定でない場合
unless @direction_fix
# 左向きだった場合は右を、下向きだった場合は上を向く
@direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
end
# 右下に移動
distance = (2 ** @move_speed) / Math.sqrt(2)
turn_right unless up1(@x, @y, distance)
turn_up if @event
turn_up unless right1(@x, @y, distance) unless @event
turn_right if @event
end
#--------------------------------------------------------------------------
# ● 座標修正
#--------------------------------------------------------------------------
def move_on
if @y < (@real_y / 128.0).round
@y += 1
@revise_y -= 128
increase_steps
end
if @x > (@real_x / 128.0).round
@x -= 1
@revise_x += 128
increase_steps
end
if @x < (@real_x / 128.0).round
@x += 1
@revise_x -= 128
increase_steps
end
if @y > (@real_y / 128.0).round
@y -= 1
@revise_y += 128
increase_steps
end
end
#--------------------------------------------------------------------------
# ● アニメーションアップデート
#--------------------------------------------------------------------------
def anime_update
# 移動時アニメが ON の場合
if @walk_anime
# アニメカウントを 1.5 増やす
@anime_count += 1.5
# 移動時アニメが OFF で、停止時アニメが ON の場合
elsif @step_anime
# アニメカウントを 1 増やす
@anime_count += 1
end
# アニメカウントが最大値を超えた場合
# ※最大値は、基本値 18 から移動速度 * 1 を引いた値
if @anime_count > 18 - @move_speed * 2
# 停止時アニメが OFF かつ 停止中の場合
if not @step_anime and @stop_count > 0
# パターンをオリジナルに戻す
@pattern = @original_pattern
# 停止時アニメが ON または 移動中の場合
else
# パターンを更新
@pattern = (@pattern + 1) % 4
end
# アニメカウントをクリア
@anime_count = 0
end
end
#--------------------------------------------------------------------------
# ● 正面のイベント起動判定
#--------------------------------------------------------------------------
# オリジナルのイベントを改名
alias :check_event_trigger_there_original :check_event_trigger_there
def check_event_trigger_there(triggers)
result = check_event_trigger_there_original(triggers)
unless result
if @direction == 2 or @direction == 8
if @revise_x < -32
@x -= 1
result = check_event_trigger_there_original(triggers)
@x += 1
elsif @revise_x > 32
@x += 1
result = check_event_trigger_there_original(triggers)
@x -= 1
end
elsif @direction == 4 or @direction == 6
if @revise_y < -48
@y -= 1
result = check_event_trigger_there_original(triggers)
@y += 1
elsif @revise_y > 0
@y += 1
result = check_event_trigger_there_original(triggers)
@y -= 1
end
end
end
return result
end
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
def update
if @revise_x == nil and @revise_y == nil
@revise_x = 0
@revise_y = 0
end
if @move_route_forcing
# ローカル変数に移動中かどうかを記憶
last_moving = moving?
# ローカル変数に座標を記憶
last_real_x = @real_x
last_real_y = @real_y
# 座標がずれている場合
if @revise_x != 0 or @revise_y != 0
distance1 = 2 ** @move_speed
distance2= Math.sqrt(@revise_x ** 2 + @revise_y ** 2)
if distance1 > distance2
@real_x = (@real_x - @revise_x).round
@real_y = (@real_y - @revise_y).round
@revise_x = 0
@revise_y = 0
anime_update
else
@revise_x -= distance1 * @revise_x / distance2
@revise_y -= distance1 * @revise_y / distance2
# 移動処理
@real_x -= distance1 * @revise_x / distance2
@real_y -= distance1 * @revise_y / distance2
anime_update
end
else
super
end
else
# 移動中、イベント実行中、移動ルート強制中、
# メッセージウィンドウ表示中のいずれでもない場合
unless moving? or $game_system.map_interpreter.running? or
@move_route_forcing or $game_temp.message_window_showing
#ダッシュ機能。エンターキーが押されている間、移動速度を変更する。
if Input.press?(Input::C)
if @move_speed != 5
@move_speed = 5
end
else
if @move_speed != 4
@move_speed = 4
end
end
@event = false
# 方向ボタンが押されていれば、その方向へプレイヤーを移動
case Input.dir8
when 1
move_lower_left_p
when 2
move_down_p
when 3
move_lower_right_p
when 4
move_left_p
when 6
move_right_p
when 7
move_upper_left_p
when 8
move_up_p
when 9
move_upper_right_p
end
end
# ローカル変数に座標を記憶
last_real_x = @real_x
last_real_y = @real_y
# 移動処理
@real_x = @x * 128 + @revise_x
@real_y = @y * 128 + @revise_y
# ローカル変数に移動中かどうかを記憶
last_moving = moving?
move_on
if (last_real_x != @real_x or last_real_y != @real_y)
anime_update
else
@pattern = 0
end
end
# キャラクターが下に移動し、かつ画面上の位置が中央より下の場合
if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
# マップを下にスクロール
$game_map.scroll_down(@real_y - last_real_y)
end
# キャラクターが左に移動し、かつ画面上の位置が中央より左の場合
if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
# マップを左にスクロール
$game_map.scroll_left(last_real_x - @real_x)
end
# キャラクターが右に移動し、かつ画面上の位置が中央より右の場合
if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
# マップを右にスクロール
$game_map.scroll_right(@real_x - last_real_x)
end
# キャラクターが上に移動し、かつ画面上の位置が中央より上の場合
if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
# マップを上にスクロール
$game_map.scroll_up(last_real_y - @real_y)
end
# 移動中ではない場合
unless moving?
# 前回プレイヤーが移動中だった場合
if last_moving
# 同位置のイベントとの接触によるイベント起動判定
result = check_event_trigger_here([1,2])
# 起動したイベントがない場合
if result == false
# デバッグモードが ON かつ CTRL キーが押されている場合を除き
unless $DEBUG and Input.press?(Input::CTRL)
# エンカウント カウントダウン
if @encounter_count > 0
@encounter_count -= 1
end
end
end
end
# C ボタンが押された場合
if Input.trigger?(Input::C)
# 同位置および正面のイベント起動判定
check_event_trigger_here([0])
check_event_trigger_there([0,1,2])
end
end
end
end
|
|