#============================================================================== # ¡á Game_Character (ºÐÇÒ Á¤ÀÇ 3) #------------------------------------------------------------------------------ # ¡¡Ä³¸¯Å͸¦ Ãë±ÞÇϴ Ŭ·¡½ºÀÔ´Ï´Ù. ÀÌ Å¬·¡½º´Â Game_Player Ŭ·¡½º¿Í Game_Event # Ŭ·¡½ºÀÇ ½´ÆÛ Å¬·¡½º·Î¼­ »ç¿ëµË´Ï´Ù. #============================================================================== class Game_Character #-------------------------------------------------------------------------- # ¡Ü ¾Æ·¡¿¡ À̵¿ # turn_enabled : ±× ÀÚ¸®¿¡¼­ÀÇ ÇâÇØ º¯°æÀ» Çã°¡ÇÏ´Â Ç÷¡±× #-------------------------------------------------------------------------- def move_down(turn_enabled = true) # ¾Æ·¡¸¦ ÇâÇÑ´Ù if turn_enabled turn_down end # ÅëÇà °¡´ÉÇÑ °æ¿ì if passable? (@x, @y, 2) # ¾Æ·¡¸¦ ÇâÇÑ´Ù turn_down # ÁÂÇ¥¸¦ °»½Å @y += 0.5 # º¸¼ö Áõ°¡ increase_steps # ÅëÇà ºÒ°¡´ÉÇÑ °æ¿ì else # Á¢ÃË À̺¥Æ®ÀÇ ±âµ¿ ÆÇÁ¤ check_event_trigger_touch(@x, @y+1) end end #-------------------------------------------------------------------------- # ¡Ü ¿ÞÂÊÀ¸·Î À̵¿ # turn_enabled : ±× ÀÚ¸®¿¡¼­ÀÇ ÇâÇØ º¯°æÀ» Çã°¡ÇÏ´Â Ç÷¡±× #-------------------------------------------------------------------------- def move_left(turn_enabled = true) # ¿ÞÂÊÀ» ÇâÇÑ´Ù if turn_enabled turn_left end # ÅëÇà °¡´ÉÇÑ °æ¿ì if passable? (@x, @y, 4) # ¿ÞÂÊÀ» ÇâÇÑ´Ù turn_left # ÁÂÇ¥¸¦ °»½Å @x -= 0.5 # º¸¼ö Áõ°¡ increase_steps # ÅëÇà ºÒ°¡´ÉÇÑ °æ¿ì else # Á¢ÃË À̺¥Æ®ÀÇ ±âµ¿ ÆÇÁ¤ check_event_trigger_touch(@x-1, @y) end end #-------------------------------------------------------------------------- # ¡Ü ¿À¸¥ÂÊÀ¸·Î À̵¿ # turn_enabled : ±× ÀÚ¸®¿¡¼­ÀÇ ÇâÇØ º¯°æÀ» Çã°¡ÇÏ´Â Ç÷¡±× #-------------------------------------------------------------------------- def move_right(turn_enabled = true) # ¿À¸¥ÂÊÀ» ÇâÇÑ´Ù if turn_enabled turn_right end # ÅëÇà °¡´ÉÇÑ °æ¿ì if passable? (@x, @y, 6) # ¿À¸¥ÂÊÀ» ÇâÇÑ´Ù turn_right # ÁÂÇ¥¸¦ °»½Å @x += 0.5 # º¸¼ö Áõ°¡ increase_steps # ÅëÇà ºÒ°¡´ÉÇÑ °æ¿ì else # Á¢ÃË À̺¥Æ®ÀÇ ±âµ¿ ÆÇÁ¤ check_event_trigger_touch(@x+1, @y) end end #-------------------------------------------------------------------------- # ¡Ü À§¿¡ À̵¿ # turn_enabled : ±× ÀÚ¸®¿¡¼­ÀÇ ÇâÇØ º¯°æÀ» Çã°¡ÇÏ´Â Ç÷¡±× #-------------------------------------------------------------------------- def move_up(turn_enabled = true) # À§¸¦ ÇâÇÑ´Ù if turn_enabled turn_up end # ÅëÇà °¡´ÉÇÑ °æ¿ì if passable? (@x, @y, 8) # À§¸¦ ÇâÇÑ´Ù turn_up # ÁÂÇ¥¸¦ °»½Å @y -= 0.5 # º¸¼ö Áõ°¡ increase_steps # ÅëÇà ºÒ°¡´ÉÇÑ °æ¿ì else # Á¢ÃË À̺¥Æ®ÀÇ ±âµ¿ ÆÇÁ¤ check_event_trigger_touch(@x, @y-1) end end #-------------------------------------------------------------------------- # ¡Ü ÁÂÇÏ¿¡ À̵¿ #-------------------------------------------------------------------------- def move_lower_left # ¹æÇâ °íÁ¤ÀÌ ¾Æ´Ñ °æ¿ì unless @direction_fix # ¿À¸¥ÂÊ ¹æÇâÀ̾ú´ø °æ¿ì´Â ¿ÞÂÊÀ», ¿À¸§»õ¿´´ø °æ¿ì´Â ¾Æ·¡¸¦ ÇâÇÑ´Ù @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction) end # ÇÏ¡æ¿ÞÂÊ, ¿ÞÂÊ¡æÇÏÀÇ ¾î´À ÂÊÀΰ¡ÀÇ ÄÚ½º°¡ ÅëÇà °¡´ÉÇÑ °æ¿ì if (passable? (@x, @y, 2) and passable? (@x, @y + 1, 4)) or (passable? (@x, @y, 4) and passable? (@x - 1, @y, 2)) # ÁÂÇ¥¸¦ °»½Å @x -= 0.5 @y += 0.5 # º¸¼ö Áõ°¡ increase_steps end end #-------------------------------------------------------------------------- # ¡Ü ¿ìÇÏ¿¡ À̵¿ #-------------------------------------------------------------------------- def move_lower_right # ¹æÇâ °íÁ¤ÀÌ ¾Æ´Ñ °æ¿ì unless @direction_fix # ÁÂÇâÀ̾ú´ø °æ¿ì´Â ¿À¸¥ÂÊÀ», ¿À¸§»õ¿´´ø °æ¿ì´Â ¾Æ·¡¸¦ ÇâÇÑ´Ù @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction) end # ÇÏ¡æ¿À¸¥ÂÊ, ¿À¸¥ÂÊ¡æÇÏÀÇ ¾î´À ÂÊÀΰ¡ÀÇ ÄÚ½º°¡ ÅëÇà °¡´ÉÇÑ °æ¿ì if (passable? (@x, @y, 2) and passable? (@x, @y + 1, 6)) or (passable? (@x, @y, 6) and passable? (@x + 1, @y, 2)) # ÁÂÇ¥¸¦ °»½Å @x += 0.5 @y += 0.5 # º¸¼ö Áõ°¡ increase_steps end end #-------------------------------------------------------------------------- # ¡Ü ÁÂ»ó¿¡ À̵¿ #-------------------------------------------------------------------------- def move_upper_left # ¹æÇâ °íÁ¤ÀÌ ¾Æ´Ñ °æ¿ì unless @direction_fix # ¿À¸¥ÂÊ ¹æÇâÀ̾ú´ø °æ¿ì´Â ¿ÞÂÊÀ», ÇÏÇâÀ̾ú´ø °æ¿ì´Â À§¸¦ ÇâÇÑ´Ù @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction) end # »ó¡æ¿ÞÂÊ, ¿ÞÂÊ¡æ»óÀÇ ¾î´À ÂÊÀΰ¡ÀÇ ÄÚ½º°¡ ÅëÇà °¡´ÉÇÑ °æ¿ì if (passable? (@x, @y, 8) and passable? (@x, @y - 1, 4)) or (passable? (@x, @y, 4) and passable? (@x - 1, @y, 8)) # ÁÂÇ¥¸¦ °»½Å @x -= 0.5 @y -= 0.5 # º¸¼ö Áõ°¡ increase_steps end end #-------------------------------------------------------------------------- # ¡Ü ¿ì»ó¿¡ À̵¿ #-------------------------------------------------------------------------- def move_upper_right # ¹æÇâ °íÁ¤ÀÌ ¾Æ´Ñ °æ¿ì unless @direction_fix # ÁÂÇâÀ̾ú´ø °æ¿ì´Â ¿À¸¥ÂÊÀ», ÇÏÇâÀ̾ú´ø °æ¿ì´Â À§¸¦ ÇâÇÑ´Ù @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction) end # »ó¡æ¿À¸¥ÂÊ, ¿À¸¥ÂÊ¡æ»óÀÇ ¾î´À ÂÊÀΰ¡ÀÇ ÄÚ½º°¡ ÅëÇà °¡´ÉÇÑ °æ¿ì if (passable? (@x, @y, 8) and passable? (@x, @y - 1, 6)) or (passable? (@x, @y, 6) and passable? (@x + 1, @y, 8)) # ÁÂÇ¥¸¦ °»½Å @x += 0.5 @y -= 0.5 # º¸¼ö Áõ°¡ increase_steps end end #-------------------------------------------------------------------------- # ¡Ü ·£´ý¿¡ À̵¿ #-------------------------------------------------------------------------- def move_random case rand(4) when 0 # ÇÏ¿¡ À̵¿ move_down(false) when 1 # ¿ÞÂÊÀ¸·Î À̵¿ move_left(false) when 2 # ¿À¸¥ÂÊÀ¸·Î À̵¿ move_right(false) when 3 # »ó¿¡ À̵¿ move_up(false) end end #-------------------------------------------------------------------------- # ¡Ü Ç÷¹À̾ °¡±î¿öÁø´Ù #-------------------------------------------------------------------------- def move_toward_player # Ç÷¹À̾îÀÇ ÁÂÇ¥¿ÍÀÇ Â÷À̸¦ ¿ä±¸ÇÑ´Ù sx = @x - $game_player.x sy = @y - $game_player.y # ÁÂÇ¥°¡ µ¿ÀÏÇÑ °æ¿ì if sx == 0 and sy == 0 return end # Â÷ÀÌÀÇ Àý´ëÄ¡¸¦ ¿ä±¸ÇÑ´Ù abs_sx = sx.abs abs_sy = sy.abs # ¿·ÀÇ °Å¸®¿Í ¼¼·ÎÀÇ °Å¸®°¡ µ¿ÀÏÇÑ °æ¿ì if abs_sx == abs_sy # ·£´ýÀ¸·Î ¾î´À ÂÊÀÎÁö¸¦ 1 ´Ã¸°´Ù rand(2) == 0 ? abs_sx += 1 : abs_sy += 1 end # ¿·ÀÇ °Å¸® ÂÊÀÌ ±ä °æ¿ì if abs_sx > abs_sy # ÁÂ¿ì ¹æÇâÀ» ¿ì¼±ÇØ, Ç÷¹À̾ ÀÖ´Â Æí¿¡ À̵¿ sx > 0 ? move_left : move_right if not moving? and sy != 0 sy > 0 ? move_up : move_down end # ¼¼·ÎÀÇ °Å¸® ÂÊÀÌ ±ä °æ¿ì else # »óÇÏ ¹æÇâÀ» ¿ì¼±ÇØ, Ç÷¹À̾ ÀÖ´Â Æí¿¡ À̵¿ sy > 0 ? move_up : move_down if not moving? and sx != 0 sx > 0 ? move_left : move_right end end end #-------------------------------------------------------------------------- # ¡Ü Ç÷¹À̾î·ÎºÎÅÍ ¸Ö¾îÁø´Ù #-------------------------------------------------------------------------- def move_away_from_player # Ç÷¹À̾îÀÇ ÁÂÇ¥¿ÍÀÇ Â÷À̸¦ ¿ä±¸ÇÑ´Ù sx = @x - $game_player.x sy = @y - $game_player.y # ÁÂÇ¥°¡ µ¿ÀÏÇÑ °æ¿ì if sx == 0 and sy == 0 return end # Â÷ÀÌÀÇ Àý´ëÄ¡¸¦ ¿ä±¸ÇÑ´Ù abs_sx = sx.abs abs_sy = sy.abs # ¿·ÀÇ °Å¸®¿Í ¼¼·ÎÀÇ °Å¸®°¡ µ¿ÀÏÇÑ °æ¿ì if abs_sx == abs_sy # ·£´ýÀ¸·Î ¾î´À ÂÊÀÎÁö¸¦ 1 ´Ã¸°´Ù rand(2) == 0 ? abs_sx += 1 : abs_sy += 1 end # ¿·ÀÇ °Å¸® ÂÊÀÌ ±ä °æ¿ì if abs_sx > abs_sy # ÁÂ¿ì ¹æÇâÀ» ¿ì¼±ÇØ, Ç÷¹À̾îÀÇ ¾ø´Â Æí¿¡ À̵¿ sx > 0 ? move_right : move_left if not moving? and sy != 0 sy > 0 ? move_down : move_up end # ¼¼·ÎÀÇ °Å¸® ÂÊÀÌ ±ä °æ¿ì else # »óÇÏ ¹æÇâÀ» ¿ì¼±ÇØ, Ç÷¹À̾îÀÇ ¾ø´Â Æí¿¡ À̵¿ sy > 0 ? move_down : move_up if not moving? and sx != 0 sx > 0 ? move_right : move_left end end end #-------------------------------------------------------------------------- # ¡Ü ÇÑ °ÉÀ½ ÀüÁø #-------------------------------------------------------------------------- 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 # ¹æÇâ °íÁ¤ »óŸ¦ ±â¾ï last_direction_fix = @direction_fix # °­Á¦ÀûÀ¸·Î ÇâÇØ °íÁ¤ @direction_fix = true # ¹æÇâÀ¸·Î ºÐ±â case @direction when 2 # ÇÏ move_up(false) when 4 # ¿ÞÂÊ move_right(false) when 6 # ¿À¸¥ÂÊ move_left(false) when 8 # »ó move_down(false) end # ¹æÇâ °íÁ¤ »óŸ¦ ¹ÙÅÁÀ¸·Î µÇµ¹¸°´Ù @direction_fix = last_direction_fix end #-------------------------------------------------------------------------- # ¡Ü Á¡ÇÁ # x_plus : X ÁÂÇ¥ °¡»êÄ¡ # y_plus : Y ÁÂÇ¥ °¡»êÄ¡ #-------------------------------------------------------------------------- def jump(x_plus, y_plus) # °¡»êÄ¡°¡ (0,0)°¡ ¾Æ´Ñ °æ¿ì if x_plus != 0 or y_plus != 0 # ¿·ÀÇ °Å¸® ÂÊÀÌ ±ä °æ¿ì if x_plus.abs > y_plus.abs # ÁÂ¿ì ¾îµò°¡¿¡ ÇâÇØ º¯°æ x_plus < 0 ? turn_left : turn_right # ¼¼·ÎÀÇ °Å¸® ÂÊÀÌ ±ä°¡ µ¿ÀÏÇÑ °æ¿ì else # »óÇÏ ¾îµò°¡¿¡ ÇâÇØ º¯°æ y_plus < 0 ? turn_up : turn_down end end # »õ·Î¿î ÁÂÇ¥¸¦ °è»ê new_x = @x + x_plus new_y = @y + y_plus # °¡»êÄ¡°¡ (0,0)ÀÇ °æ¿ìÀΰ¡, Á¡ÇÁó°¡ ÅëÇà °¡´ÉÇÑ °æ¿ì if (x_plus == 0 and y_plus == 0) or passable? (new_x, new_y, 0) # ÀÚ¼¼¸¦ ±³Á¤ straighten # ÁÂÇ¥¸¦ °»½Å @x = new_x @y = new_y # °Å¸®¸¦ °è»ê distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus). round # Á¡ÇÁ Ä«¿îÆ®¸¦ ¼³Á¤ @jump_peak = 10 + distance - @move_speed @jump_count = @jump_peak * 2 # Á¤Áö Ä«¿îÆ®¸¦ Ŭ¸®¾î @stop_count = 0 end end #-------------------------------------------------------------------------- # ¡Ü ¾Æ·¡¸¦ ÇâÇÑ´Ù #-------------------------------------------------------------------------- def turn_down unless @direction_fix @direction = 2 end end #-------------------------------------------------------------------------- # ¡Ü ¿ÞÂÊÀ» ÇâÇÑ´Ù #-------------------------------------------------------------------------- def turn_left unless @direction_fix @direction = 4 end end #-------------------------------------------------------------------------- # ¡Ü ¿À¸¥ÂÊÀ» ÇâÇÑ´Ù #-------------------------------------------------------------------------- def turn_right unless @direction_fix @direction = 6 end end #-------------------------------------------------------------------------- # ¡Ü À§¸¦ ÇâÇÑ´Ù #-------------------------------------------------------------------------- def turn_up unless @direction_fix @direction = 8 end end #-------------------------------------------------------------------------- # ¡Ü ¿À¸¥ÂÊÀ¸·Î 90 ¹ø ȸÀü #-------------------------------------------------------------------------- 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 ¹ø ȸÀü #-------------------------------------------------------------------------- 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 ¹ø ȸÀü #-------------------------------------------------------------------------- def turn_180 case @direction when 2 turn_up when 4 turn_right when 6 turn_left when 8 turn_down end end #-------------------------------------------------------------------------- # ¡Ü ¿À¸¥ÂÊÀ̳ª ¿ÞÂÊÀ¸·Î 90 ¹ø ȸÀü #-------------------------------------------------------------------------- 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 #-------------------------------------------------------------------------- # ¡Ü Ç÷¹À̾îÀÇ ºÐÀ» ÇâÇÑ´Ù #-------------------------------------------------------------------------- def turn_toward_player # Ç÷¹À̾îÀÇ ÁÂÇ¥¿ÍÀÇ Â÷À̸¦ ¿ä±¸ÇÑ´Ù sx = @x - $game_player.x sy = @y - $game_player.y # ÁÂÇ¥°¡ µ¿ÀÏÇÑ °æ¿ì if sx == 0 and sy == 0 return end # ¿·ÀÇ °Å¸® ÂÊÀÌ ±ä °æ¿ì if sx.abs > sy.abs # ÁÂ¿ì ¹æÇâÀ¸·Î Ç÷¹À̾ ÀÖ´Â ÆíÀ» ÇâÇÑ´Ù sx > 0 ? turn_left : turn_right # ¼¼·ÎÀÇ °Å¸® ÂÊÀÌ ±ä °æ¿ì else # »óÇÏ ¹æÇâÀ¸·Î Ç÷¹À̾ ÀÖ´Â ÆíÀ» ÇâÇÑ´Ù sy > 0 ? turn_up : turn_down end end #-------------------------------------------------------------------------- # ¡Ü Ç÷¹À̾îÀÇ ¿ªÀ» ÇâÇÑ´Ù #-------------------------------------------------------------------------- def turn_away_from_player # Ç÷¹À̾îÀÇ ÁÂÇ¥¿ÍÀÇ Â÷À̸¦ ¿ä±¸ÇÑ´Ù sx = @x - $game_player.x sy = @y - $game_player.y # ÁÂÇ¥°¡ µ¿ÀÏÇÑ °æ¿ì if sx == 0 and sy == 0 return end # ¿·ÀÇ °Å¸® ÂÊÀÌ ±ä °æ¿ì if sx.abs > sy.abs # ÁÂ¿ì ¹æÇâÀ¸·Î Ç÷¹À̾îÀÇ ¾ø´Â ÆíÀ» ÇâÇÑ´Ù sx > 0 ? turn_right : turn_left # ¼¼·ÎÀÇ °Å¸® ÂÊÀÌ ±ä °æ¿ì else # »óÇÏ ¹æÇâÀ¸·Î Ç÷¹À̾îÀÇ ¾ø´Â ÆíÀ» ÇâÇÑ´Ù sy > 0 ? turn_down : turn_up end end end