Game_Character 3

Publié le par chindan

#============================================
# ¡ 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‚ðXV
@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‚ðXV
@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‚ðXV
@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‚ðXV
@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‚ðXV
@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
# ‰º¨‰EA‰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‚ðXV
@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‚ðXV
@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
# ã¨‰EA‰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‚ðXV
@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
#------------------------------------------
# œ ˆê•à‘Oi
#------------------------------------------
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‚ðŒvŽZ
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‚ðXV
@x = new_x
@y = new_y
# ‹——£‚ðŒvŽZ
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

Publié dans poubelle

Pour être informé des derniers articles, inscrivez vous :
Commenter cet article