Project1
标题:
伪·像素移动的问题...
[打印本页]
作者:
Wind2010
时间:
2011-2-27 11:58
标题:
伪·像素移动的问题...
class Game_Character
def x
return @x.round
end
def y
return @y.round
end
#def passable?(x,y,d)
#return true
#end
def screen_x
shizi = (@real_x - $game_map.display_x + 3) / 4 + 16
return shizi.floor
end
def screen_y
y = (@real_y - $game_map.display_y + 3) / 4 + 32
if @jump_count >= @jump_peak
n = @jump_count - @jump_peak
else
n = @jump_peak - @jump_count
end
shizi = y - (@jump_peak * @jump_peak - n * n) / 2
return shizi.floor
end
def move_down(turn_enabled = true)
if turn_enabled
turn_down
end
for i in 1..@move_speed
if passable?(@x, @y, 2)
turn_down
@y += (1/32.0000000)
increase_steps
else
check_event_trigger_touch(@x, @y+1)
end
end
end
def move_left(turn_enabled = true)
if turn_enabled
turn_left
end
for i in 1..@move_speed
if passable?(@x, @y, 4)
turn_left
@x -= (1/32.0000000)
increase_steps
else
check_event_trigger_touch(@x-1, @y)
end
end
end
def move_right(turn_enabled = true)
if turn_enabled
turn_right
end
for i in 1..@move_speed
if passable?(@x, @y, 6)
turn_right
@x += (1/32.0000000)
increase_steps
else
check_event_trigger_touch(@x+1, @y)
end
end
end
def move_up(turn_enabled = true)
if turn_enabled
turn_up
end
for i in 1..@move_speed
if passable?(@x, @y, 8)
turn_up
@y -= (1/32.0000000)
increase_steps
else
check_event_trigger_touch(@x, @y-1)
end
end
end
end
复制代码
这是我自己写的一段脚本,但是测试时发现主角/事件不能走到x为0的位置...这个原因是什么? dsu_plus_rewardpost_czw
作者:
忧雪の伤
时间:
2011-2-27 12:10
# ▼▲▼ No78. Xムーブ ▼▲▼
#
# update 2007/12/18
#
#==============================================================================
# --- プレイヤー移動速度設定 ---
#==============================================================================
module XMoveSmoother
#--------------------------------------------------------------------------
# オブジェクト初期化
#--------------------------------------------------------------------------
def initialize
super
xmove_reset
end
#--------------------------------------------------------------------------
# ずれリセット
#--------------------------------------------------------------------------
def xmove_reset
@xf = 0
@yf = 0
end
#--------------------------------------------------------------------------
# 接触イベントの判定 と 歩数カウント
#--------------------------------------------------------------------------
def check_event_touch_here_x
if @xf == 0
increase_steps
return check_event_trigger_here([1,2])
end
return false
end
def check_event_touch_here_y
if @yf == 0
increase_steps
return check_event_trigger_here([1,2])
end
return false
end
#--------------------------------------------------------------------------
# 通行可能?[拡張版]
#--------------------------------------------------------------------------
def passablex?(x, y, d)
# ずれ補正のみ による移動可
case d
when 2
return true if @yf < 0
when 4
return true if @xf > 0
when 6
return true if @xf < 0
when 8
return true if @yf > 0
end
# 通常の通行可能判定
result = passable?(x, y, d)
# ぶれによる追加判定
unless (@xf == 0 and @yf == 0)
case d
when 2, 8
nx = @xf > 0 ? 1 : (@xf < 0 ? -1 : 0)
ny = d == 2 ? 1 : -1
nd = @xf > 0 ? 6 : (@xf < 0 ? 4 : 0)
result &= passable?(x + nx, y, d)
result &= passable?(x, y + ny, nd)
when 4, 6
nx = d == 6 ? 1 : -1
ny = @yf > 0 ? 1 : (@yf < 0 ? -1 : 0)
nd = @yf > 0 ? 2 : (@yf < 0 ? 8 : 0)
result &= passable?(x + nx, y, nd)
result &= passable?(x, y + ny, d)
end
end
# 結果
return result
end
#--------------------------------------------------------------------------
# 下に移動
#--------------------------------------------------------------------------
def move_down(turn_enabled = true)
# 移動指定されているなら本来どおり or 移動速度4でない場合
return super if @move_route_forcing or @move_speed != 4
# 下を向く
if turn_enabled
turn_down
end
# 通行可能な場合
if passablex?(@x, @y, 2)
# ぶれを更新
@yf += 1
if @yf >= 3
@yf = -2
@y += 1
end
# 接触判定
check_event_touch_here_y
# 通行不可能な場合
else
# 接触イベントの起動判定
if check_event_trigger_touch(@x, @y+1)
turn_down
xmove_reset
return
end
# ぬるり
if turn_enabled and @yf == 0 and passable?(@x, @y, 2)
if @xf >= 1 and (not passable?(@x+1, @y, 2) or not passable?(@x, @y+1, 6))
@xf -= 1
check_event_touch_here_x
elsif @xf <= -1 and (not passable?(@x-1, @y, 2) or not passable?(@x, @y+1, 4))
@xf += 1
check_event_touch_here_x
end
end
end
end
#--------------------------------------------------------------------------
# 左に移動
#--------------------------------------------------------------------------
def move_left(turn_enabled = true)
# 移動指定されているなら本来どおり or 移動速度4でない場合
return super if @move_route_forcing or @move_speed != 4
# 左を向く
if turn_enabled
turn_left
end
# 通行可能な場合
if passablex?(@x, @y, 4)
# ぶれを更新
@xf -= 1
if @xf <= -3
@xf = 2
@x -= 1
end
# 接触判定
check_event_touch_here_x
# 通行不可能な場合
else
# 接触イベントの起動判定
if check_event_trigger_touch(@x-1, @y)
turn_left
xmove_reset
return
end
# ぬるり
if @xf == 0 and turn_enabled and passable?(@x, @y, 4)
if @yf >= 1 and (not passable?(@x, @y+1, 4) or not passable?(@x-1, @y, 2))
@yf -= 1
check_event_touch_here_y
elsif @yf <= -1 and (not passable?(@x, @y-1, 4) or not passable?(@x-1, @y, 8))
@yf += 1
check_event_touch_here_y
end
end
end
end
#--------------------------------------------------------------------------
# 右に移動
#--------------------------------------------------------------------------
def move_right(turn_enabled = true)
# 移動指定されているなら本来どおり or 移動速度4でない場合
return super if @move_route_forcing or @move_speed != 4
# 右を向く
if turn_enabled
turn_right
end
# 通行可能な場合
if passablex?(@x, @y, 6)
# ぶれを更新
@xf += 1
if @xf >= 3
@xf = -2
@x += 1
end
# 接触判定
check_event_touch_here_x
# 通行不可能な場合
else
# 接触イベントの起動判定
if check_event_trigger_touch(@x+1, @y)
turn_right
xmove_reset
return
end
# ぬるり
if turn_enabled and @xf == 0 and passable?(@x, @y, 6)
if @yf >= 1 and (not passable?(@x, @y+1, 6) or not passable?(@x+1, @y, 2))
@yf -= 1
check_event_touch_here_y
elsif @yf <= -1 and (not passable?(@x, @y-1, 6) or not passable?(@x+1, @y, 8))
@yf += 1
check_event_touch_here_y
end
end
end
end
#--------------------------------------------------------------------------
# 上に移動
#--------------------------------------------------------------------------
def move_up(turn_enabled = true)
# 移動指定されているなら本来どおり or 移動速度4でない場合
return super if @move_route_forcing or @move_speed != 4
# 上を向く
if turn_enabled
turn_up
end
# 通行可能な場合
if passablex?(@x, @y, 8)
# ぶれを更新
@yf -= 1
if @yf <= -3
@yf = 2
@y -= 1
end
# 接触判定
check_event_touch_here_y
# 通行不可能な場合
else
# 接触イベントの起動判定
if check_event_trigger_touch(@x, @y-1)
turn_up
xmove_reset
return
end
# ぬるり
if turn_enabled and @yf == 0 and passable?(@x, @y, 8)
if @xf >= 1 and (not passable?(@x+1, @y, 8) or not passable?(@x, @y-1, 6))
@xf -= 1
check_event_touch_here_x
elsif @xf <= -1 and (not passable?(@x-1, @y, 8) or not passable?(@x, @y-1, 4))
@xf += 1
check_event_touch_here_x
end
end
end
end
#--------------------------------------------------------------------------
# 左下に移動
#--------------------------------------------------------------------------
def move_lower_left
# 移動指定されているなら本来どおり or 移動速度4でない場合
return super if @move_route_forcing or @move_speed != 4
# 左を向く
turn_left
move_down(false)
move_left(false)
end
#--------------------------------------------------------------------------
# 右下に移動
#--------------------------------------------------------------------------
def move_lower_right
# 移動指定されているなら本来どおり or 移動速度4でない場合
return super if @move_route_forcing or @move_speed != 4
# 下を向く
turn_down
move_down(false)
move_right(false)
end
#--------------------------------------------------------------------------
# 左上に移動
#--------------------------------------------------------------------------
def move_upper_left
# 移動指定されているなら本来どおり or 移動速度4でない場合
return super if @move_route_forcing or @move_speed != 4
# 上を向く
turn_up
move_up(false)
move_left(false)
end
#--------------------------------------------------------------------------
# 右上に移動
#--------------------------------------------------------------------------
def move_upper_right
# 移動指定されているなら本来どおり or 移動速度4でない場合
return super if @move_route_forcing or @move_speed != 4
# 右を向く
turn_right
move_up(false)
move_right(false)
end
#--------------------------------------------------------------------------
# 座標の瞬時更新
#--------------------------------------------------------------------------
def refresh_position
@real_x = @x * 128 + (@xf * 25.6).to_i
@real_y = @y * 128 + (@yf * 25.6).to_i
end
#--------------------------------------------------------------------------
# 移動中判定 [オーバーライド]
#--------------------------------------------------------------------------
def moving?
# イベント実行中の場合
return super if $game_system.map_interpreter.running?
return super if @move_route_forcing
@xf = 0 if @xf == nil
@yf = 0 if @yf == nil
# 論理座標と実座標が違っていれば移動中
return (@real_x != @x * 128 + (@xf * 25.6).to_i or
@real_y != @y * 128 + (@yf * 25.6).to_i )
end
#--------------------------------------------------------------------------
# ○ フレーム更新 (移動) [オーバーライド]
#--------------------------------------------------------------------------
def update_move
# 移動指定されているなら本来どおり or 移動速度4でない場合
if $game_system.map_interpreter.running? or
@move_route_forcing or @move_speed != 4
xmove_reset
super
else
super
# 表示位置を更新
refresh_position
end
end
#--------------------------------------------------------------------------
# 歩数増加
#--------------------------------------------------------------------------
def increase_steps
super
# イベント実行中の場合
return if $game_system.map_interpreter.running?
# デバッグモードが ON かつ CTRL キーが押されている場合を除き
unless $DEBUG and Input.press?(Input::CTRL)
# エンカウント カウントダウン
if @encounter_count > 0
@encounter_count -= 1
if $game_map.bush?(self.x, self.y)
@encounter_extra += 80
end
end
end
end
#--------------------------------------------------------------------------
# 移動ルートの強制
#--------------------------------------------------------------------------
def force_move_route(move_route)
xmove_reset
super
end
end
class Game_Player < Game_Character
include XMoveSmoother
end
复制代码
作者:
wbsy8241
时间:
2011-2-27 18:00
往左或往上 坐标达到 1.0 以下时
判断下一步(-1) 坐标为负数 不可通行
作者:
沙漠点灰
时间:
2011-3-11 16:56
这种问题认真分析还是很容易的,
假设现在主角坐标为[1,2],在你的脚本里面就为[1.0,2.0],再假设现在往左走,
判断[1.0.to_i-1,2.0.to_i]是否可通行(我用的是.to_i,),也就是[0,2]坐标,发现可通行,就移动到大概
[0.97,2.0],再次判断:[0.97.to_i-1,2.0.to_i],也就是[-1,2],在范围外,返回false,通行不能。
所以,不应该用to_i或者floor,应用ceil,当然,这仅仅是解决了这个小bug,还有更大的问题——
假设主角坐标[1.5,3.0],地图[1.0,2.0]不能通行,而[2.0,2.0]可以通行,现在主角向上移动,是动,还是不动?
目前,得到了:若主角卡在两个坐标之间,那两个坐标只要有一个不可通行,则不可通行,不过
又有问题了——
假设地图上[1.0,2.0]和[3.0,2.0]不可通行,而[2.0,2.0]可通行,要想主角从中间走过去,
以上面的“结论”,主角的x坐标必须为2.0,不然不能过,不过...你也知道....刚刚为2.0是较为困难的,很容易
1.9,2.1之类的.....又有大问题....
到这,只有建议:若主角卡在两个坐标之间,那两个坐标只要有一个可通行,“自动转弯”,校正其
x或y坐标到 n.0
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1