IceDragon200

PixelMovement

May 8th, 2011
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.47 KB | None | 0 0
  1. # ¤¢¤ XRXSv5. X,move{ ¤¢¤
  2. #
  3. # publish 2010/ 3/ 2
  4. # update     -  5/ 3
  5. #
  6. #==============================================================================
  7. # ƒJƒXƒ^ƒ}ƒCƒYƒ|ƒCƒ“ƒg
  8. #==============================================================================
  9. module XRXSV5
  10.   #
  11.   # [X.Move] - —LŒø‚É‚·‚éH
  12.   #
  13.   XMoveEnable = true
  14.   #
  15.   # [X.Move] - ˆÚ“®‘¬“x(1`6)
  16.   #
  17.   XMoveSpeed = 4
  18.   #
  19.   # [ƒiƒiƒ‘€ì] - —LŒø‚É‚·‚éH
  20.   #
  21.   SlantMoveInput = true
  22.   #
  23.   # [ƒiƒiƒƒOƒ‰ƒtƒBƒbƒN] - —LŒø‚É‚·‚éH
  24.   #
  25.   SlantGraphicEnable = true
  26.   #
  27.   # [ƒiƒiƒƒOƒ‰ƒtƒBƒbƒN] - ƒtƒ@ƒCƒ‹–¼•¶ŽšŽ®
  28.   #
  29.   SlantNameS = "$%s-%s-S"
  30. end
  31. #==============================================================================
  32. # XMove‘¬“xÝ’è
  33. #==============================================================================
  34. class Game_System
  35.   attr_accessor :xmove_speed
  36.   def xmove_speed
  37.     return (@xmove_speed ? @xmove_speed : XRXSV5::XMoveSpeed)
  38.   end
  39. end
  40. #==============================================================================
  41. # --- X.Move ---
  42. #==============================================================================
  43. module XMoveSmoother
  44.   #--------------------------------------------------------------------------
  45.   # ¤ ƒIƒuƒWƒFƒNƒg‰Šú‰»
  46.   #--------------------------------------------------------------------------
  47.   def initialize
  48.     xmove_reset
  49.     super
  50.   end
  51.   #--------------------------------------------------------------------------
  52.   # ‚¸‚ꃊƒZƒbƒg
  53.   #--------------------------------------------------------------------------
  54.   def xmove_reset
  55.     @xf = 0
  56.     @yf = 0
  57.   end
  58.   #--------------------------------------------------------------------------
  59.   # ¤ ˆÚ“®’†”»’è
  60.   #--------------------------------------------------------------------------
  61.   def moving?
  62.     if xmove_disable?
  63.       super
  64.     else
  65.       return (@real_x.to_i != (@x * 256 + @xf * 32) or
  66.               @real_y.to_i != (@y * 256 + @yf * 32)    )
  67.     end
  68.   end
  69.   #--------------------------------------------------------------------------
  70.   # ¤ ˆÚ“®Žž‚̍XV
  71.   #--------------------------------------------------------------------------
  72.   def update_move
  73.     if xmove_disable?
  74.       super
  75.     else
  76.       last_x = @x
  77.       last_y = @y
  78.       @x += @xf / 8.0
  79.       @y += @yf / 8.0
  80.       @move_speed = $game_system.xmove_speed
  81.       super
  82.       @move_speed = 4
  83.       @x = last_x
  84.       @y = last_y
  85.       @real_x.truncate
  86.       @real_y.truncate
  87.     end
  88.   end
  89.   #--------------------------------------------------------------------------
  90.   # ¤ Šg’£’ʍs‰Â”\”»’è
  91.   #--------------------------------------------------------------------------
  92.   def passable_x?(x, y)
  93.     result  = passable?(x, y)
  94.     result &= passable?(x-1, y) if @xf < 0
  95.     result &= passable?(x+1, y) if @xf > 0
  96.     result &= passable?(x, y-1) if @yf < 0
  97.     result &= passable?(x, y+1) if @yf > 0
  98.     return result
  99.   end
  100.   #--------------------------------------------------------------------------
  101.   # ŽŸ‚̃}ƒX‚ɐi‚ñ‚¾‚Æ‚«‚̏ˆ—
  102.   #--------------------------------------------------------------------------
  103.   def process_next_mass
  104.     increase_steps
  105.     check_touch_event
  106.     update_encounter
  107.   end
  108.   #--------------------------------------------------------------------------
  109.   # ‰º‚Ɉړ®
  110.   #--------------------------------------------------------------------------
  111.   def move_down(turn_ok = true)
  112.     if xmove_disable?
  113.       super
  114.     elsif @yf != 0 or passable_x?(@x, @y+1)
  115.       turn_down
  116.       @yf += 2
  117.       if @yf == 0
  118.         process_next_mass
  119.       elsif @yf >= 4
  120.         @yf = -4
  121.         @y = $game_map.round_y(@y+1)
  122.         @real_y = (@y-1)*256 + 64
  123.       end
  124.     else
  125.       turn_down if turn_ok
  126.       if not check_event_trigger_touch(@x, @y+1) and turn_ok
  127.         if passable?(@x, @y+1)
  128.           @xf = 0
  129.           process_next_mass
  130.         elsif @xf == 4 and passable?(@x+1, @y+1)
  131.           @xf = 0
  132.           @x = $game_map.round_x(@x+1)
  133.           @real_x = (@x-1)*256 + 128
  134.           process_next_mass
  135.         end
  136.       end
  137.     end
  138.   end
  139.   #--------------------------------------------------------------------------
  140.   # ¶‚Ɉړ®
  141.   #--------------------------------------------------------------------------
  142.   def move_left(turn_ok = true)
  143.     if xmove_disable?
  144.       super
  145.     elsif @xf != 0 or passable_x?(@x-1, @y)
  146.       turn_left
  147.       @xf -= 2
  148.       if @xf == 0
  149.         process_next_mass
  150.       elsif @xf <= -4
  151.         @xf = 4
  152.         @x = $game_map.round_x(@x-1)
  153.         @real_x = (@x+1)*256 - 64
  154.       end
  155.     else
  156.       turn_left if turn_ok
  157.       if not check_event_trigger_touch(@x-1, @y) and turn_ok
  158.         if passable?(@x-1, @y)
  159.           @yf = 0
  160.           process_next_mass
  161.         elsif @yf == 4 and passable?(@x-1, @y+1)
  162.           @yf = 0
  163.           @y = $game_map.round_x(@y+1)
  164.           @real_y = (@y-1)*256 + 128
  165.           process_next_mass
  166.         end
  167.       end
  168.     end
  169.   end
  170.   #--------------------------------------------------------------------------
  171.   # ‰E‚Ɉړ®
  172.   #--------------------------------------------------------------------------
  173.   def move_right(turn_ok = true)
  174.     if xmove_disable?
  175.       super
  176.     elsif @xf != 0 or passable_x?(@x+1, @y)
  177.       turn_right
  178.       @xf += 2
  179.       if @xf == 0
  180.         process_next_mass
  181.       elsif @xf >= 6
  182.         @xf = -2
  183.         @x = $game_map.round_x(@x+1)
  184.         @real_x = (@x-1)*256 + 128
  185.       end
  186.     else
  187.       turn_right if turn_ok
  188.       if not check_event_trigger_touch(@x+1, @y) and turn_ok
  189.         if passable?(@x+1, @y)
  190.           @yf = 0
  191.           process_next_mass
  192.         elsif @yf==4 and passable?(@x+1, @y+1)
  193.           @yf = 0
  194.           @y = $game_map.round_x(@y+1)
  195.           @real_y = (@y-1)*256 + 128
  196.           process_next_mass
  197.         end
  198.       end
  199.     end
  200.   end
  201.   #--------------------------------------------------------------------------
  202.   # ã‚Ɉړ®
  203.   #--------------------------------------------------------------------------
  204.   def move_up(turn_ok = true)
  205.     if xmove_disable?
  206.       super
  207.     elsif @yf != 0 or passable_x?(@x, @y-1)
  208.       turn_up
  209.       @yf -= 2
  210.       if @yf == 0
  211.         process_next_mass
  212.       elsif @yf <= -6
  213.         @yf = 2
  214.         @y = $game_map.round_y(@y-1)
  215.         @real_y = (@y+1)*256 - 128
  216.       end
  217.     else
  218.       turn_up if turn_ok
  219.       if not check_event_trigger_touch(@x, @y-1) and turn_ok
  220.         if passable?(@x, @y-1)
  221.           @xf = 0
  222.           process_next_mass
  223.         elsif @xf == 4 and passable?(@x+1, @y-1)
  224.           @xf = 0
  225.           @x = $game_map.round_x(@x+1)
  226.           @real_x = (@x-1)*256 + 128
  227.           process_next_mass
  228.         end
  229.       end
  230.     end
  231.   end
  232.   #--------------------------------------------------------------------------
  233.   # ¶‰º‚Ɉړ®
  234.   #--------------------------------------------------------------------------
  235.   def move_lower_left
  236.     if xmove_disable?
  237.       super
  238.     else
  239.       move_down(true)
  240.       move_left(true) unless $game_map.interpreter.running?
  241.     end
  242.   end
  243.   #--------------------------------------------------------------------------
  244.   # ‰E‰º‚Ɉړ®
  245.   #--------------------------------------------------------------------------
  246.   def move_lower_right
  247.     if xmove_disable?
  248.       super
  249.     else
  250.       move_down(true)
  251.       move_right(true) unless $game_map.interpreter.running?
  252.     end
  253.   end
  254.   #--------------------------------------------------------------------------
  255.   # ¶ã‚Ɉړ®
  256.   #--------------------------------------------------------------------------
  257.   def move_upper_left
  258.     if xmove_disable?
  259.       super
  260.     else
  261.       move_up(true)
  262.       move_left(true) unless $game_map.interpreter.running?
  263.     end
  264.   end
  265.   #--------------------------------------------------------------------------
  266.   # ‰Eã‚Ɉړ®
  267.   #--------------------------------------------------------------------------
  268.   def move_upper_right
  269.     if xmove_disable?
  270.       super
  271.     else
  272.       move_up(true)
  273.       move_right(true) unless $game_map.interpreter.running?
  274.     end
  275.   end
  276.   #--------------------------------------------------------------------------
  277.   # ¤ ˆÚ“®ƒ‹[ƒg‚Ì‹­§
  278.   #--------------------------------------------------------------------------
  279.   def force_move_route(move_route)
  280.     xmove_reset
  281.     super
  282.   end
  283.   #--------------------------------------------------------------------------
  284.   # ¤ Žw’èˆÊ’u‚Ɉړ®
  285.   #--------------------------------------------------------------------------
  286.   def moveto(x, y)
  287.     xmove_reset
  288.     super
  289.   end
  290.   #--------------------------------------------------------------------------
  291.   # X.ƒ€[ƒu‹@”\‚ð’âŽ~‚·‚é”»’è (ƒCƒxƒ“ƒg’†‚È‚Ç)
  292.   #--------------------------------------------------------------------------
  293.   def xmove_disable?
  294.     return (@move_route_forcing or @move_speed != 4 or in_vehicle?)
  295.   end
  296. end
  297. if XRXSV5::XMoveEnable
  298. class Game_Player < Game_Character
  299.   include XMoveSmoother
  300.   #--------------------------------------------------------------------------
  301.   # œ ˆÚ“®’†‚łȂ¢ê‡‚̏ˆ—
  302.   #    (false : “¥‚Ý‹N“®ƒCƒxƒ“ƒg‚ƃGƒ“ƒJƒEƒ“ƒg•à”ˆ—‚ð
  303.   #             last_moving‚ð–â‚킸‚ɋ֎~‚·‚é)
  304.   #--------------------------------------------------------------------------
  305.   alias xrxsv5_update_nonmoving update_nonmoving
  306.   def update_nonmoving(last_moving)
  307.     xrxsv5_update_nonmoving(false)
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # œ ³–ʂ̃Cƒxƒ“ƒg‹N“®”»’è
  311.   #--------------------------------------------------------------------------
  312.   alias xrxsv5_check_event_trigger_there check_event_trigger_there
  313.   def check_event_trigger_there(triggers)
  314.     return false if (@yf != 0 and [2,8].include?(@direction)) or
  315.                     (@xf != 0 and [4,6].include?(@direction))
  316.     xrxsv5_check_event_trigger_there(triggers)
  317.   end
  318.   #--------------------------------------------------------------------------
  319.   # œ êŠˆÚ“®‚ÌŽÀs
  320.   #--------------------------------------------------------------------------
  321.   alias xrxsv5_perform_transfer perform_transfer
  322.   def perform_transfer
  323.     $game_player.xmove_reset if self.transfer?
  324.     xrxsv5_perform_transfer
  325.   end
  326.   #--------------------------------------------------------------------------
  327.   # œ ‹­§“I‚Ɉê•à‘Oi
  328.   #--------------------------------------------------------------------------
  329.   alias xrxsv5_force_move_forward force_move_forward
  330.   def force_move_forward
  331.     xmove_reset
  332.     xrxsv5_force_move_forward
  333.   end
  334.   #--------------------------------------------------------------------------
  335.   # œ ”òs‘D‚ɏæ‚é
  336.   #--------------------------------------------------------------------------
  337.   alias xrxsv5_get_on_airship get_on_airship
  338.   def get_on_airship
  339.     xmove_reset
  340.     xrxsv5_get_on_airship
  341.   end
  342. end
  343. end
  344. #==============================================================================
  345. # ƒiƒiƒƒOƒ‰ƒtƒBƒbƒN‘Ήž‹@”\
  346. #==============================================================================
  347. module XSlantGraphic
  348.   attr_accessor :character_slant_mode
  349.   def character_slant_name
  350.     if [1,3,7,9].include?(@direction)
  351.       filename = sprintf(XRXSV5::SlantNameS, @character_name, (@character_index + 1).to_s)
  352.       begin
  353.         Cache.character(filename)
  354.       rescue
  355.         filename = nil
  356.       end
  357.       return filename
  358.     else
  359.       return nil
  360.     end
  361.   end
  362.   def character_name
  363.     name = character_slant_name
  364.     self.character_slant_mode = (name != nil)
  365.     return (self.character_slant_mode ? name : super)
  366.   end
  367.   def character_index
  368.     return (self.character_slant_mode ? 0    : super)
  369.   end
  370.   def direction
  371.     return [0,2,2,6,4,0,6,4,8,8][super]
  372.   end
  373.   def turn_lower_left
  374.     set_direction(1)
  375.   end
  376.   def turn_lower_right
  377.     set_direction(3)
  378.   end
  379.   def turn_upper_left
  380.     set_direction(7)
  381.   end
  382.   def turn_upper_right
  383.     set_direction(9)
  384.   end
  385.   def move_lower_left
  386.     super
  387.     turn_lower_left unless $game_map.interpreter.running?
  388.   end
  389.   def move_lower_right
  390.     super
  391.     turn_lower_right unless $game_map.interpreter.running?
  392.   end
  393.   def move_upper_left
  394.     super
  395.     turn_upper_left unless $game_map.interpreter.running?
  396.   end
  397.   def move_upper_right
  398.     super
  399.     turn_upper_right unless $game_map.interpreter.running?
  400.   end
  401. end
  402. class Game_Player < Game_Character
  403.   include XSlantGraphic if XRXSV5::SlantGraphicEnable
  404. end
  405. #==============================================================================
  406. # ƒiƒiƒ‘€ì‹@”\ (Ä’è‹`)
  407. #==============================================================================
  408. if XRXSV5::SlantMoveInput
  409.   class Game_Player < Game_Character
  410.     def move_by_input
  411.       return unless movable?
  412.       return if $game_map.interpreter.running?
  413.       case Input.dir8
  414.       when 1;  move_lower_left
  415.       when 7;  move_upper_left
  416.       when 9;  move_upper_right
  417.       when 3;  move_lower_right
  418.       when 2;  move_down
  419.       when 4;  move_left
  420.       when 6;  move_right
  421.       when 8;  move_up
  422.       end
  423.     end
  424.   end
  425. end
Advertisement
Add Comment
Please, Sign In to add comment