Game_Character 3
#============================================
# ¡ Game_Character (•ªŠ„’è‹` 3)
#----------------------------------------------
# @ƒLƒƒƒ‰ƒNƒ^[‚ðˆµ‚¤ƒNƒ‰ƒX‚Å‚·B‚±‚̃Nƒ‰ƒX‚Í Game_Player ƒNƒ‰ƒX‚Æ Game_Event
# ƒNƒ‰ƒX‚̃X[ƒp[ƒNƒ‰ƒX‚Æ‚µ‚Äg—p‚³‚ê‚Ü‚·B
#============================================
class Game_Character
#------------------------------------------
# œ ‰º‚Ɉړ®
# turn_enabled : ‚»‚Ìê‚Å‚ÌŒü‚«•ÏX‚ð‹–‰Â‚·‚éƒtƒ‰ƒO
#------------------------------------------
def move_down(turn_enabled = true)
# ‰º‚ðŒü‚
if turn_enabled
turn_down
end
# ’Ês‰Â”‚Èê‡
if passable?(@x, @y, 2)
# ‰º‚ðŒü‚
turn_down
# À•W‚ðXV
@y += 1
# •à”‘‰Á
increase_steps
# ’Ês•s‰Â”‚Èê‡
else
# ÚGƒCƒxƒ“ƒg‚Ì‹N“®”»’è
check_event_trigger_touch(@x, @y+1)
end
end
#------------------------------------------
# œ ¶‚Ɉړ®
# turn_enabled : ‚»‚Ìê‚Å‚ÌŒü‚«•ÏX‚ð‹–‰Â‚·‚éƒtƒ‰ƒO
#------------------------------------------
def move_left(turn_enabled = true)
# ¶‚ðŒü‚
if turn_enabled
turn_left
end
# ’Ês‰Â”‚Èê‡
if passable?(@x, @y, 4)
# ¶‚ðŒü‚
turn_left
# À•W‚ðXV
@x -= 1
# •à”‘‰Á
increase_steps
# ’Ês•s‰Â”‚Èê‡
else
# ÚGƒCƒxƒ“ƒg‚Ì‹N“®”»’è
check_event_trigger_touch(@x-1, @y)
end
end
#------------------------------------------
# œ ‰E‚Ɉړ®
# turn_enabled : ‚»‚Ìê‚Å‚ÌŒü‚«•ÏX‚ð‹–‰Â‚·‚éƒtƒ‰ƒO
#------------------------------------------
def move_right(turn_enabled = true)
# ‰E‚ðŒü‚
if turn_enabled
turn_right
end
# ’Ês‰Â”‚Èê‡
if passable?(@x, @y, 6)
# ‰E‚ðŒü‚
turn_right
# À•W‚ðXV
@x += 1
# •à”‘‰Á
increase_steps
# ’Ês•s‰Â”‚Èê‡
else
# ÚGƒCƒxƒ“ƒg‚Ì‹N“®”»’è
check_event_trigger_touch(@x+1, @y)
end
end
#------------------------------------------
# œ ã‚Ɉړ®
# turn_enabled : ‚»‚Ìê‚Å‚ÌŒü‚«•ÏX‚ð‹–‰Â‚·‚éƒtƒ‰ƒO
#------------------------------------------
def move_up(turn_enabled = true)
# ã‚ðŒü‚
if turn_enabled
turn_up
end
# ’Ês‰Â”‚Èê‡
if passable?(@x, @y, 8)
# ã‚ðŒü‚
turn_up
# À•W‚ðXV
@y -= 1
# •à”‘‰Á
increase_steps
# ’Ês•s‰Â”‚Èê‡
else
# ÚGƒCƒxƒ“ƒg‚Ì‹N“®”»’è
check_event_trigger_touch(@x, @y-1)
end
end
#------------------------------------------
# œ ¶‰º‚Ɉړ®
#------------------------------------------
def move_lower_left
# Œü‚«ŒÅ’è‚Å‚È‚¢ê‡
unless @direction_fix
# ‰EŒü‚«‚¾‚Á‚½ê‡‚Ͷ‚ðAãŒü‚«‚¾‚Á‚½ê‡‚͉º‚ðŒü‚
@direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
end
# ‰º¨¶A¶¨‰º ‚Ì‚Ç‚¿‚ç‚©‚̃R[ƒX‚ª’Ês‰Â”‚Èê‡
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
# À•W‚ðXV
@x -= 1
@y += 1
# •à”‘‰Á
increase_steps
end
end
#------------------------------------------
# œ ‰E‰º‚Ɉړ®
#------------------------------------------
def move_lower_right
# Œü‚«ŒÅ’è‚Å‚È‚¢ê‡
unless @direction_fix
# ¶Œü‚«‚¾‚Á‚½ê‡‚͉E‚ðAãŒü‚«‚¾‚Á‚½ê‡‚͉º‚ðŒü‚
@direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
end
# ‰º¨‰EA‰E¨‰º ‚Ì‚Ç‚¿‚ç‚©‚̃R[ƒX‚ª’Ês‰Â”‚Èê‡
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
# À•W‚ðXV
@x += 1
@y += 1
# •à”‘‰Á
increase_steps
end
end
#------------------------------------------
# œ ¶ã‚Ɉړ®
#------------------------------------------
def move_upper_left
# Œü‚«ŒÅ’è‚Å‚È‚¢ê‡
unless @direction_fix
# ‰EŒü‚«‚¾‚Á‚½ê‡‚Ͷ‚ðA‰ºŒü‚«‚¾‚Á‚½ê‡‚Íã‚ðŒü‚
@direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
end
# 㨶A¶¨ã ‚Ì‚Ç‚¿‚ç‚©‚̃R[ƒX‚ª’Ês‰Â”‚Èê‡
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
# À•W‚ðXV
@x -= 1
@y -= 1
# •à”‘‰Á
increase_steps
end
end
#------------------------------------------
# œ ‰Eã‚Ɉړ®
#------------------------------------------
def move_upper_right
# Œü‚«ŒÅ’è‚Å‚È‚¢ê‡
unless @direction_fix
# ¶Œü‚«‚¾‚Á‚½ê‡‚͉E‚ðA‰ºŒü‚«‚¾‚Á‚½ê‡‚Íã‚ðŒü‚
@direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
end
# 㨉EA‰E¨ã ‚Ì‚Ç‚¿‚ç‚©‚̃R[ƒX‚ª’Ês‰Â”‚Èê‡
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
# À•W‚ðXV
@x += 1
@y -= 1
# •à”‘‰Á
increase_steps
end
end
#------------------------------------------
# œ ƒ‰ƒ“ƒ_ƒ€‚Ɉړ®
#------------------------------------------
def move_random
case rand(4)
when 0 # ‰º‚Ɉړ®
move_down(false)
when 1 # ¶‚Ɉړ®
move_left(false)
when 2 # ‰E‚Ɉړ®
move_right(false)
when 3 # ã‚Ɉړ®
move_up(false)
end
end
#------------------------------------------
# œ ƒvƒŒƒCƒ„[‚ɋ߂Â
#------------------------------------------
def move_toward_player
# ƒvƒŒƒCƒ„[‚ÌÀ•W‚Æ‚Ì·‚ð‹‚ß‚é
sx = @x - $game_player.x
sy = @y - $game_player.y
# À•W‚ª“™‚µ‚¢ê‡
if sx == 0 and sy == 0
return
end
# ·‚Ìâ‘Î’l‚ð‹‚ß‚é
abs_sx = sx.abs
abs_sy = sy.abs
# ‰¡‚Ì‹——£‚Æc‚Ì‹——£‚ª“™‚µ‚¢ê‡
if abs_sx == abs_sy
# ƒ‰ƒ“ƒ_ƒ€‚Å‚Ç‚¿‚ç‚©‚ð 1 ‘‚â‚·
rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
end
# ‰¡‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
if abs_sx > abs_sy
# ¶‰E•ûŒü‚ð—D悵AƒvƒŒƒCƒ„[‚Ì‚¢‚é‚Ù‚¤‚ÖˆÚ“®
sx > 0 ? move_left : move_right
if not moving? and sy != 0
sy > 0 ? move_up : move_down
end
# c‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
else
# ㉺•ûŒü‚ð—D悵AƒvƒŒƒCƒ„[‚Ì‚¢‚é‚Ù‚¤‚ÖˆÚ“®
sy > 0 ? move_up : move_down
if not moving? and sx != 0
sx > 0 ? move_left : move_right
end
end
end
#------------------------------------------
# œ ƒvƒŒƒCƒ„[‚©‚牓‚´‚©‚é
#------------------------------------------
def move_away_from_player
# ƒvƒŒƒCƒ„[‚ÌÀ•W‚Æ‚Ì·‚ð‹‚ß‚é
sx = @x - $game_player.x
sy = @y - $game_player.y
# À•W‚ª“™‚µ‚¢ê‡
if sx == 0 and sy == 0
return
end
# ·‚Ìâ‘Î’l‚ð‹‚ß‚é
abs_sx = sx.abs
abs_sy = sy.abs
# ‰¡‚Ì‹——£‚Æc‚Ì‹——£‚ª“™‚µ‚¢ê‡
if abs_sx == abs_sy
# ƒ‰ƒ“ƒ_ƒ€‚Å‚Ç‚¿‚ç‚©‚ð 1 ‘‚â‚·
rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
end
# ‰¡‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
if abs_sx > abs_sy
# ¶‰E•ûŒü‚ð—D悵AƒvƒŒƒCƒ„[‚Ì‚¢‚È‚¢‚Ù‚¤‚ÖˆÚ“®
sx > 0 ? move_right : move_left
if not moving? and sy != 0
sy > 0 ? move_down : move_up
end
# c‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
else
# ㉺•ûŒü‚ð—D悵AƒvƒŒƒCƒ„[‚Ì‚¢‚È‚¢‚Ù‚¤‚ÖˆÚ“®
sy > 0 ? move_down : move_up
if not moving? and sx != 0
sx > 0 ? move_right : move_left
end
end
end
#------------------------------------------
# œ ˆê•à‘Oi
#------------------------------------------
def move_forward
case @direction
when 2
move_down(false)
when 4
move_left(false)
when 6
move_right(false)
when 8
move_up(false)
end
end
#------------------------------------------
# œ ˆê•àŒã‘Þ
#------------------------------------------
def move_backward
# Œü‚«ŒÅ’è‚Ìó‘Ô‚ð‹L‰¯
last_direction_fix = @direction_fix
# ‹§“I‚ÉŒü‚«ŒÅ’è
@direction_fix = true
# Œü‚«‚Å•ªŠò
case @direction
when 2 # ‰º
move_up(false)
when 4 # ¶
move_right(false)
when 6 # ‰E
move_left(false)
when 8 # ã
move_down(false)
end
# Œü‚«ŒÅ’è‚Ìó‘Ô‚ðŒ³‚É–ß‚·
@direction_fix = last_direction_fix
end
#------------------------------------------
# œ ƒWƒƒƒ“ƒv
# x_plus : X À•W‰ÁZ’l
# y_plus : Y À•W‰ÁZ’l
#------------------------------------------
def jump(x_plus, y_plus)
# ‰ÁZ’l‚ª (0,0) ‚Å‚Í‚È‚¢ê‡
if x_plus != 0 or y_plus != 0
# ‰¡‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
if x_plus.abs > y_plus.abs
# ¶‰E‚Ç‚¿‚ç‚©‚ÉŒü‚«•ÏX
x_plus < 0 ? turn_left : turn_right
# c‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢‚©“™‚µ‚¢ê‡
else
# ㉺‚Ç‚¿‚ç‚©‚ÉŒü‚«•ÏX
y_plus < 0 ? turn_up : turn_down
end
end
# V‚µ‚¢À•W‚ðŒvZ
new_x = @x + x_plus
new_y = @y + y_plus
# ‰ÁZ’l‚ª (0,0) ‚Ìꇂ©AƒWƒƒƒ“ƒv悪’Ês‰Â”‚Èê‡
if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
# p¨‚ð‹¸³
straighten
# À•W‚ðXV
@x = new_x
@y = new_y
# ‹——£‚ðŒvZ
distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
# ƒWƒƒƒ“ƒvƒJƒEƒ“ƒg‚ðÝ’è
@jump_peak = 10 + distance - @move_speed
@jump_count = @jump_peak * 2
# ’â~ƒJƒEƒ“ƒg‚ðƒNƒŠƒA
@stop_count = 0
end
end
#------------------------------------------
# œ ‰º‚ðŒü‚
#------------------------------------------
def turn_down
unless @direction_fix
@direction = 2
@stop_count = 0
end
end
#------------------------------------------
# œ ¶‚ðŒü‚
#------------------------------------------
def turn_left
unless @direction_fix
@direction = 4
@stop_count = 0
end
end
#------------------------------------------
# œ ‰E‚ðŒü‚
#------------------------------------------
def turn_right
unless @direction_fix
@direction = 6
@stop_count = 0
end
end
#------------------------------------------
# œ ã‚ðŒü‚
#------------------------------------------
def turn_up
unless @direction_fix
@direction = 8
@stop_count = 0
end
end
#------------------------------------------
# œ ‰E‚É 90 “x‰ñ“]
#------------------------------------------
def turn_right_90
case @direction
when 2
turn_left
when 4
turn_up
when 6
turn_down
when 8
turn_right
end
end
#------------------------------------------
# œ ¶‚É 90 “x‰ñ“]
#------------------------------------------
def turn_left_90
case @direction
when 2
turn_right
when 4
turn_down
when 6
turn_up
when 8
turn_left
end
end
#------------------------------------------
# œ 180 “x‰ñ“]
#------------------------------------------
def turn_180
case @direction
when 2
turn_up
when 4
turn_right
when 6
turn_left
when 8
turn_down
end
end
#------------------------------------------
# œ ‰E‚©¶‚É 90 “x‰ñ“]
#------------------------------------------
def turn_right_or_left_90
if rand(2) == 0
turn_right_90
else
turn_left_90
end
end
#------------------------------------------
# œ ƒ‰ƒ“ƒ_ƒ€‚É•ûŒü“]Š·
#------------------------------------------
def turn_random
case rand(4)
when 0
turn_up
when 1
turn_right
when 2
turn_left
when 3
turn_down
end
end
#------------------------------------------
# œ ƒvƒŒƒCƒ„[‚Ì•û‚ðŒü‚
#------------------------------------------
def turn_toward_player
# ƒvƒŒƒCƒ„[‚ÌÀ•W‚Æ‚Ì·‚ð‹‚ß‚é
sx = @x - $game_player.x
sy = @y - $game_player.y
# À•W‚ª“™‚µ‚¢ê‡
if sx == 0 and sy == 0
return
end
# ‰¡‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
if sx.abs > sy.abs
# ¶‰E•ûŒü‚ŃvƒŒƒCƒ„[‚Ì‚¢‚é‚Ù‚¤‚ðŒü‚
sx > 0 ? turn_left : turn_right
# c‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
else
# ㉺•ûŒü‚ŃvƒŒƒCƒ„[‚Ì‚¢‚é‚Ù‚¤‚ðŒü‚
sy > 0 ? turn_up : turn_down
end
end
#------------------------------------------
# œ ƒvƒŒƒCƒ„[‚Ì‹t‚ðŒü‚
#------------------------------------------
def turn_away_from_player
# ƒvƒŒƒCƒ„[‚ÌÀ•W‚Æ‚Ì·‚ð‹‚ß‚é
sx = @x - $game_player.x
sy = @y - $game_player.y
# À•W‚ª“™‚µ‚¢ê‡
if sx == 0 and sy == 0
return
end
# ‰¡‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
if sx.abs > sy.abs
# ¶‰E•ûŒü‚ŃvƒŒƒCƒ„[‚Ì‚¢‚È‚¢‚Ù‚¤‚ðŒü‚
sx > 0 ? turn_right : turn_left
# c‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
else
# ㉺•ûŒü‚ŃvƒŒƒCƒ„[‚Ì‚¢‚È‚¢‚Ù‚¤‚ðŒü‚
sy > 0 ? turn_down : turn_up
end
end
end
# ¡ Game_Character (•ªŠ„’è‹` 3)
#----------------------------------------------
# @ƒLƒƒƒ‰ƒNƒ^[‚ðˆµ‚¤ƒNƒ‰ƒX‚Å‚·B‚±‚̃Nƒ‰ƒX‚Í Game_Player ƒNƒ‰ƒX‚Æ Game_Event
# ƒNƒ‰ƒX‚̃X[ƒp[ƒNƒ‰ƒX‚Æ‚µ‚Äg—p‚³‚ê‚Ü‚·B
#============================================
class Game_Character
#------------------------------------------
# œ ‰º‚Ɉړ®
# turn_enabled : ‚»‚Ìê‚Å‚ÌŒü‚«•ÏX‚ð‹–‰Â‚·‚éƒtƒ‰ƒO
#------------------------------------------
def move_down(turn_enabled = true)
# ‰º‚ðŒü‚
if turn_enabled
turn_down
end
# ’Ês‰Â”‚Èê‡
if passable?(@x, @y, 2)
# ‰º‚ðŒü‚
turn_down
# À•W‚ðXV
@y += 1
# •à”‘‰Á
increase_steps
# ’Ês•s‰Â”‚Èê‡
else
# ÚGƒCƒxƒ“ƒg‚Ì‹N“®”»’è
check_event_trigger_touch(@x, @y+1)
end
end
#------------------------------------------
# œ ¶‚Ɉړ®
# turn_enabled : ‚»‚Ìê‚Å‚ÌŒü‚«•ÏX‚ð‹–‰Â‚·‚éƒtƒ‰ƒO
#------------------------------------------
def move_left(turn_enabled = true)
# ¶‚ðŒü‚
if turn_enabled
turn_left
end
# ’Ês‰Â”‚Èê‡
if passable?(@x, @y, 4)
# ¶‚ðŒü‚
turn_left
# À•W‚ðXV
@x -= 1
# •à”‘‰Á
increase_steps
# ’Ês•s‰Â”‚Èê‡
else
# ÚGƒCƒxƒ“ƒg‚Ì‹N“®”»’è
check_event_trigger_touch(@x-1, @y)
end
end
#------------------------------------------
# œ ‰E‚Ɉړ®
# turn_enabled : ‚»‚Ìê‚Å‚ÌŒü‚«•ÏX‚ð‹–‰Â‚·‚éƒtƒ‰ƒO
#------------------------------------------
def move_right(turn_enabled = true)
# ‰E‚ðŒü‚
if turn_enabled
turn_right
end
# ’Ês‰Â”‚Èê‡
if passable?(@x, @y, 6)
# ‰E‚ðŒü‚
turn_right
# À•W‚ðXV
@x += 1
# •à”‘‰Á
increase_steps
# ’Ês•s‰Â”‚Èê‡
else
# ÚGƒCƒxƒ“ƒg‚Ì‹N“®”»’è
check_event_trigger_touch(@x+1, @y)
end
end
#------------------------------------------
# œ ã‚Ɉړ®
# turn_enabled : ‚»‚Ìê‚Å‚ÌŒü‚«•ÏX‚ð‹–‰Â‚·‚éƒtƒ‰ƒO
#------------------------------------------
def move_up(turn_enabled = true)
# ã‚ðŒü‚
if turn_enabled
turn_up
end
# ’Ês‰Â”‚Èê‡
if passable?(@x, @y, 8)
# ã‚ðŒü‚
turn_up
# À•W‚ðXV
@y -= 1
# •à”‘‰Á
increase_steps
# ’Ês•s‰Â”‚Èê‡
else
# ÚGƒCƒxƒ“ƒg‚Ì‹N“®”»’è
check_event_trigger_touch(@x, @y-1)
end
end
#------------------------------------------
# œ ¶‰º‚Ɉړ®
#------------------------------------------
def move_lower_left
# Œü‚«ŒÅ’è‚Å‚È‚¢ê‡
unless @direction_fix
# ‰EŒü‚«‚¾‚Á‚½ê‡‚Ͷ‚ðAãŒü‚«‚¾‚Á‚½ê‡‚͉º‚ðŒü‚
@direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
end
# ‰º¨¶A¶¨‰º ‚Ì‚Ç‚¿‚ç‚©‚̃R[ƒX‚ª’Ês‰Â”‚Èê‡
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
# À•W‚ðXV
@x -= 1
@y += 1
# •à”‘‰Á
increase_steps
end
end
#------------------------------------------
# œ ‰E‰º‚Ɉړ®
#------------------------------------------
def move_lower_right
# Œü‚«ŒÅ’è‚Å‚È‚¢ê‡
unless @direction_fix
# ¶Œü‚«‚¾‚Á‚½ê‡‚͉E‚ðAãŒü‚«‚¾‚Á‚½ê‡‚͉º‚ðŒü‚
@direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
end
# ‰º¨‰EA‰E¨‰º ‚Ì‚Ç‚¿‚ç‚©‚̃R[ƒX‚ª’Ês‰Â”‚Èê‡
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
# À•W‚ðXV
@x += 1
@y += 1
# •à”‘‰Á
increase_steps
end
end
#------------------------------------------
# œ ¶ã‚Ɉړ®
#------------------------------------------
def move_upper_left
# Œü‚«ŒÅ’è‚Å‚È‚¢ê‡
unless @direction_fix
# ‰EŒü‚«‚¾‚Á‚½ê‡‚Ͷ‚ðA‰ºŒü‚«‚¾‚Á‚½ê‡‚Íã‚ðŒü‚
@direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
end
# 㨶A¶¨ã ‚Ì‚Ç‚¿‚ç‚©‚̃R[ƒX‚ª’Ês‰Â”‚Èê‡
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
# À•W‚ðXV
@x -= 1
@y -= 1
# •à”‘‰Á
increase_steps
end
end
#------------------------------------------
# œ ‰Eã‚Ɉړ®
#------------------------------------------
def move_upper_right
# Œü‚«ŒÅ’è‚Å‚È‚¢ê‡
unless @direction_fix
# ¶Œü‚«‚¾‚Á‚½ê‡‚͉E‚ðA‰ºŒü‚«‚¾‚Á‚½ê‡‚Íã‚ðŒü‚
@direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
end
# 㨉EA‰E¨ã ‚Ì‚Ç‚¿‚ç‚©‚̃R[ƒX‚ª’Ês‰Â”‚Èê‡
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
# À•W‚ðXV
@x += 1
@y -= 1
# •à”‘‰Á
increase_steps
end
end
#------------------------------------------
# œ ƒ‰ƒ“ƒ_ƒ€‚Ɉړ®
#------------------------------------------
def move_random
case rand(4)
when 0 # ‰º‚Ɉړ®
move_down(false)
when 1 # ¶‚Ɉړ®
move_left(false)
when 2 # ‰E‚Ɉړ®
move_right(false)
when 3 # ã‚Ɉړ®
move_up(false)
end
end
#------------------------------------------
# œ ƒvƒŒƒCƒ„[‚ɋ߂Â
#------------------------------------------
def move_toward_player
# ƒvƒŒƒCƒ„[‚ÌÀ•W‚Æ‚Ì·‚ð‹‚ß‚é
sx = @x - $game_player.x
sy = @y - $game_player.y
# À•W‚ª“™‚µ‚¢ê‡
if sx == 0 and sy == 0
return
end
# ·‚Ìâ‘Î’l‚ð‹‚ß‚é
abs_sx = sx.abs
abs_sy = sy.abs
# ‰¡‚Ì‹——£‚Æc‚Ì‹——£‚ª“™‚µ‚¢ê‡
if abs_sx == abs_sy
# ƒ‰ƒ“ƒ_ƒ€‚Å‚Ç‚¿‚ç‚©‚ð 1 ‘‚â‚·
rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
end
# ‰¡‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
if abs_sx > abs_sy
# ¶‰E•ûŒü‚ð—D悵AƒvƒŒƒCƒ„[‚Ì‚¢‚é‚Ù‚¤‚ÖˆÚ“®
sx > 0 ? move_left : move_right
if not moving? and sy != 0
sy > 0 ? move_up : move_down
end
# c‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
else
# ㉺•ûŒü‚ð—D悵AƒvƒŒƒCƒ„[‚Ì‚¢‚é‚Ù‚¤‚ÖˆÚ“®
sy > 0 ? move_up : move_down
if not moving? and sx != 0
sx > 0 ? move_left : move_right
end
end
end
#------------------------------------------
# œ ƒvƒŒƒCƒ„[‚©‚牓‚´‚©‚é
#------------------------------------------
def move_away_from_player
# ƒvƒŒƒCƒ„[‚ÌÀ•W‚Æ‚Ì·‚ð‹‚ß‚é
sx = @x - $game_player.x
sy = @y - $game_player.y
# À•W‚ª“™‚µ‚¢ê‡
if sx == 0 and sy == 0
return
end
# ·‚Ìâ‘Î’l‚ð‹‚ß‚é
abs_sx = sx.abs
abs_sy = sy.abs
# ‰¡‚Ì‹——£‚Æc‚Ì‹——£‚ª“™‚µ‚¢ê‡
if abs_sx == abs_sy
# ƒ‰ƒ“ƒ_ƒ€‚Å‚Ç‚¿‚ç‚©‚ð 1 ‘‚â‚·
rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
end
# ‰¡‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
if abs_sx > abs_sy
# ¶‰E•ûŒü‚ð—D悵AƒvƒŒƒCƒ„[‚Ì‚¢‚È‚¢‚Ù‚¤‚ÖˆÚ“®
sx > 0 ? move_right : move_left
if not moving? and sy != 0
sy > 0 ? move_down : move_up
end
# c‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
else
# ㉺•ûŒü‚ð—D悵AƒvƒŒƒCƒ„[‚Ì‚¢‚È‚¢‚Ù‚¤‚ÖˆÚ“®
sy > 0 ? move_down : move_up
if not moving? and sx != 0
sx > 0 ? move_right : move_left
end
end
end
#------------------------------------------
# œ ˆê•à‘Oi
#------------------------------------------
def move_forward
case @direction
when 2
move_down(false)
when 4
move_left(false)
when 6
move_right(false)
when 8
move_up(false)
end
end
#------------------------------------------
# œ ˆê•àŒã‘Þ
#------------------------------------------
def move_backward
# Œü‚«ŒÅ’è‚Ìó‘Ô‚ð‹L‰¯
last_direction_fix = @direction_fix
# ‹§“I‚ÉŒü‚«ŒÅ’è
@direction_fix = true
# Œü‚«‚Å•ªŠò
case @direction
when 2 # ‰º
move_up(false)
when 4 # ¶
move_right(false)
when 6 # ‰E
move_left(false)
when 8 # ã
move_down(false)
end
# Œü‚«ŒÅ’è‚Ìó‘Ô‚ðŒ³‚É–ß‚·
@direction_fix = last_direction_fix
end
#------------------------------------------
# œ ƒWƒƒƒ“ƒv
# x_plus : X À•W‰ÁZ’l
# y_plus : Y À•W‰ÁZ’l
#------------------------------------------
def jump(x_plus, y_plus)
# ‰ÁZ’l‚ª (0,0) ‚Å‚Í‚È‚¢ê‡
if x_plus != 0 or y_plus != 0
# ‰¡‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
if x_plus.abs > y_plus.abs
# ¶‰E‚Ç‚¿‚ç‚©‚ÉŒü‚«•ÏX
x_plus < 0 ? turn_left : turn_right
# c‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢‚©“™‚µ‚¢ê‡
else
# ㉺‚Ç‚¿‚ç‚©‚ÉŒü‚«•ÏX
y_plus < 0 ? turn_up : turn_down
end
end
# V‚µ‚¢À•W‚ðŒvZ
new_x = @x + x_plus
new_y = @y + y_plus
# ‰ÁZ’l‚ª (0,0) ‚Ìꇂ©AƒWƒƒƒ“ƒv悪’Ês‰Â”‚Èê‡
if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
# p¨‚ð‹¸³
straighten
# À•W‚ðXV
@x = new_x
@y = new_y
# ‹——£‚ðŒvZ
distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
# ƒWƒƒƒ“ƒvƒJƒEƒ“ƒg‚ðÝ’è
@jump_peak = 10 + distance - @move_speed
@jump_count = @jump_peak * 2
# ’â~ƒJƒEƒ“ƒg‚ðƒNƒŠƒA
@stop_count = 0
end
end
#------------------------------------------
# œ ‰º‚ðŒü‚
#------------------------------------------
def turn_down
unless @direction_fix
@direction = 2
@stop_count = 0
end
end
#------------------------------------------
# œ ¶‚ðŒü‚
#------------------------------------------
def turn_left
unless @direction_fix
@direction = 4
@stop_count = 0
end
end
#------------------------------------------
# œ ‰E‚ðŒü‚
#------------------------------------------
def turn_right
unless @direction_fix
@direction = 6
@stop_count = 0
end
end
#------------------------------------------
# œ ã‚ðŒü‚
#------------------------------------------
def turn_up
unless @direction_fix
@direction = 8
@stop_count = 0
end
end
#------------------------------------------
# œ ‰E‚É 90 “x‰ñ“]
#------------------------------------------
def turn_right_90
case @direction
when 2
turn_left
when 4
turn_up
when 6
turn_down
when 8
turn_right
end
end
#------------------------------------------
# œ ¶‚É 90 “x‰ñ“]
#------------------------------------------
def turn_left_90
case @direction
when 2
turn_right
when 4
turn_down
when 6
turn_up
when 8
turn_left
end
end
#------------------------------------------
# œ 180 “x‰ñ“]
#------------------------------------------
def turn_180
case @direction
when 2
turn_up
when 4
turn_right
when 6
turn_left
when 8
turn_down
end
end
#------------------------------------------
# œ ‰E‚©¶‚É 90 “x‰ñ“]
#------------------------------------------
def turn_right_or_left_90
if rand(2) == 0
turn_right_90
else
turn_left_90
end
end
#------------------------------------------
# œ ƒ‰ƒ“ƒ_ƒ€‚É•ûŒü“]Š·
#------------------------------------------
def turn_random
case rand(4)
when 0
turn_up
when 1
turn_right
when 2
turn_left
when 3
turn_down
end
end
#------------------------------------------
# œ ƒvƒŒƒCƒ„[‚Ì•û‚ðŒü‚
#------------------------------------------
def turn_toward_player
# ƒvƒŒƒCƒ„[‚ÌÀ•W‚Æ‚Ì·‚ð‹‚ß‚é
sx = @x - $game_player.x
sy = @y - $game_player.y
# À•W‚ª“™‚µ‚¢ê‡
if sx == 0 and sy == 0
return
end
# ‰¡‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
if sx.abs > sy.abs
# ¶‰E•ûŒü‚ŃvƒŒƒCƒ„[‚Ì‚¢‚é‚Ù‚¤‚ðŒü‚
sx > 0 ? turn_left : turn_right
# c‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
else
# ㉺•ûŒü‚ŃvƒŒƒCƒ„[‚Ì‚¢‚é‚Ù‚¤‚ðŒü‚
sy > 0 ? turn_up : turn_down
end
end
#------------------------------------------
# œ ƒvƒŒƒCƒ„[‚Ì‹t‚ðŒü‚
#------------------------------------------
def turn_away_from_player
# ƒvƒŒƒCƒ„[‚ÌÀ•W‚Æ‚Ì·‚ð‹‚ß‚é
sx = @x - $game_player.x
sy = @y - $game_player.y
# À•W‚ª“™‚µ‚¢ê‡
if sx == 0 and sy == 0
return
end
# ‰¡‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
if sx.abs > sy.abs
# ¶‰E•ûŒü‚ŃvƒŒƒCƒ„[‚Ì‚¢‚È‚¢‚Ù‚¤‚ðŒü‚
sx > 0 ? turn_right : turn_left
# c‚Ì‹——£‚Ì‚Ù‚¤‚ª’·‚¢ê‡
else
# ㉺•ûŒü‚ŃvƒŒƒCƒ„[‚Ì‚¢‚È‚¢‚Ù‚¤‚ðŒü‚
sy > 0 ? turn_down : turn_up
end
end
end