设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 51|回复: 1
打印 上一主题 下一主题

[有事请教] 请问有没有让主角自由移动的脚本,不受格子的限制

[复制链接]

Lv1.梦旅人

梦石
0
星屑
197
在线时间
21 小时
注册时间
2025-7-10
帖子
7
跳转到指定楼层
1
发表于 昨天 17:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
我用高级搜索搜“人物移动”和“移动”都没搜到qwq

Lv6.析梦学徒

花匠

梦石
64
星屑
15464
在线时间
4003 小时
注册时间
2016-6-17
帖子
1063

极短26获奖极短24参与开拓者

2
发表于 昨天 20:44 | 只看该作者
一般来说这种要搜像素移动

RUBY 代码复制
  1. #-------------------------------------------------------------------------------
  2. # * [ACE] Khas Pixel Movement
  3. #-------------------------------------------------------------------------------
  4. # * by Khas Arcthunder
  5. # * Version: 1.2 EN
  6. # * Released on: 01/28/2012
  7. # * Blog: khasarcthunder.wordpress.com
  8. #
  9. #-------------------------------------------------------------------------------
  10. # * Terms of Use
  11. #-------------------------------------------------------------------------------
  12. # When using any Khas script, you agree with the following terms:
  13. # 1. You must give credit to Khas;
  14. # 2. All Khas scripts are licensed under a Creative Commons license;
  15. # 3. All Khas scripts are for non-commercial projects. If you need some script
  16. #    for your commercial project (I accept requests for this type of project),
  17. #    send an email to [email protected] with your request;
  18. # 4. All Khas scripts are for personal use, you can use or edit for your own
  19. #    project, but you are not allowed to post any modified version;
  20. # 5. You can’t give credit to yourself for posting any Khas script;
  21. # 6. If you want to share a Khas script, don’t post the direct download link,
  22. #    please redirect the user to arcthunder.site40.net
  23. #
  24. #-------------------------------------------------------------------------------
  25. # * Updates
  26. #-------------------------------------------------------------------------------
  27. # Version 1.2 01/28/2012
  28. # - Move Route bug fixed.
  29. #
  30. # Version 1.1 01/13/2012
  31. # - Diagonal movement bug fixed;
  32. # - Improved AI;
  33. # - New map refresh function;
  34. #
  35. #-------------------------------------------------------------------------------
  36. # * Features
  37. #-------------------------------------------------------------------------------
  38. # - Pixel Movement for player, events, vehicles and followers
  39. # - Plug and Play
  40. # - Lag free
  41. # - Map loading
  42. # - Better follower AI
  43. # - Better collision
  44. # - Compatible with region and terrain
  45. # - Compatible with any vehicle
  46. # - Auto multiply event commands
  47. # - Compatible with bushes
  48. #
  49. #-------------------------------------------------------------------------------
  50. # * How to use
  51. #-------------------------------------------------------------------------------
  52. # 1. How to install
  53. # Place Khas Pixel Movement above Main.
  54. #
  55. # 2. Physics System
  56. # In order to run this script with the best performance, there's a system
  57. # called "Physics". This system will load each map between the transitions,
  58. # so you may experience little loadings. The Khas Pixel Movement is not
  59. # recommended for huge maps.
  60. #
  61. # 3. Event Commands (place a comment)
  62. # There are two special commands for events, you may add a comment with
  63. # the following sintax:
  64. #
  65. # a. [collision_x A]
  66. # This command sets the x collision to A (A must be an integer)
  67. #
  68. # b. [collision_y B]
  69. # This command sets the y collision to B (B must be an integer)
  70. #
  71. # Please check the demo to understand how the collision system works!
  72. #
  73. # 4. Event Commands (call script)
  74. # You can call the following commands for the player or the events
  75. #
  76. # character.px
  77. # This command returns the pixel coordinate X (4 px = 1 tile)
  78. #
  79. # character.py
  80. # This command returns the pixel coordinate Y (4 py = 1 tile)
  81. #
  82. # character.pixel_passable?(px,py,d)
  83. # This command checks the pixel passability from (px, py) to the direction d.
  84. #
  85. # 5. Map Commands
  86. # You can call a special command to update the passability of the current
  87. # map. You MUST run this command if the option "Auto_Refresh_Tile_Events"
  88. # is set to false.
  89. #
  90. # "But when do I need to use this command?"
  91. # Well, if you change a event graphic to a tileset graphic, or if you remove
  92. # this event graphic, then your map need to be updated!
  93. #
  94. # $game_map.refresh_table(start_x,start_y,end_x,end_y)
  95. #
  96. # Where:
  97. # start_x => Initial X
  98. # start_y => Initial Y
  99. # end_x => End X
  100. # end_y => End Y
  101. #
  102. #-------------------------------------------------------------------------------
  103. # * Warning!
  104. #-------------------------------------------------------------------------------
  105. # Check your tileset directions. If any direction is set as unpassable, the
  106. # system will set the whole tile as unpassable. Setup your tilesets before
  107. # using them!
  108. #
  109. #-------------------------------------------------------------------------------
  110. # * Incompatibility
  111. #-------------------------------------------------------------------------------
  112. # The Khas Pixel Movement is incompatible with:
  113. # 1. Loop maps
  114. # 2. Heavy modifications on Game_Character, Game_Player and Game_Event classes
  115. #
  116. #-------------------------------------------------------------------------------
  117. # * Setup Part
  118. #-------------------------------------------------------------------------------
  119. module Pixel_Core
  120.  
  121.   # Pixel Movement maps (ID)
  122.   # Example
  123.   # Maps = [1,3,4,5,6,7]
  124.   Maps = [1,2,3,4,5,6]
  125.  
  126.   # Auto Multiply event commands?
  127.   # (this option will multiply the event commands by 4 if set to true)
  128.   Multiply_Commands = true
  129.  
  130.   # Commands to multiply (ID)
  131.   Commands = [1,2,3,4,5,6,7,8,9,10,11,12,13]
  132.  
  133.   # Can the airship land at bushes?
  134.   Airship_Bush = true
  135.  
  136.   # Follow distance (float)
  137.   Follow_Distance = 0.75
  138.  
  139.   # Auto Update events with tileset graphics?
  140.   Auto_Refresh_Tile_Events = true
  141.  
  142.   # Auto Update range
  143.   TileEvent_Range = 3
  144.  
  145. #-------------------------------------------------------------------------------
  146. # * Constants - Do not modify!
  147. #-------------------------------------------------------------------------------
  148.   Pixel = 4
  149.   Tile = 0.25
  150.   Default_Collision_X = 3
  151.   Default_Collision_Y = 3
  152.   Body_Axis = [0.25,0.25,0.5,0.75]
  153.   Bush_Axis = [0.5,0.75]
  154.   Counter_Axis = [0.25,0.25,0.25,0.25]
  155.   Ladder_Axis = [0.25,0.25]
  156.   Pixel_Range = {2=>[0,0.25],4=>[-0.25,0],6=>[0.25,0],8=>[0,-0.25]}
  157.   Tile_Range = {2=>[0,1],4=>[-1,0],6=>[1,0],8=>[0,-1]}
  158.   Trigger_Range = {2=>[0,2],4=>[-2,0],6=>[2,0],8=>[0,-2]}
  159.   Counter_Range = {2=>[0,3],4=>[-3,0],6=>[3,0],8=>[0,-3]}
  160.   Vehicle_Range = {2=>[0,3],4=>[-3,0],6=>[3,0],8=>[0,-3]}
  161.   Chase_Axis = {2=>[0,1],4=>[1,0],6=>[1,0],8=>[0,1]}
  162. end
  163. #-------------------------------------------------------------------------------
  164. # * End of Configuration
  165. #-------------------------------------------------------------------------------
  166. if $khas_awesome.nil?
  167.   $khas_awesome = []
  168. else
  169.   scripts = []
  170.   $khas_awesome.each { |script| scripts << script[0] }
  171.   if scripts.include?("Sapphire Action System")
  172.     error = Sprite.new
  173.     error.bitmap = Bitmap.new(544,416)
  174.     error.bitmap.draw_text(0,208,544,32,"Please remove the Khas Pixel Movement!",1)
  175.     error.bitmap.draw_text(0,240,544,32,"The Sapphire Action System IV has this function.",1)
  176.     continue = Sprite.new
  177.     continue.bitmap = Bitmap.new(544,416)
  178.     continue.bitmap.font.color = Color.new(0,255,0)
  179.     continue.bitmap.font.size = error.bitmap.font.size - 3
  180.     continue.bitmap.draw_text(0,384,544,32,"Press Enter to exit",1)
  181.     add = Math::PI/80; max = 2*Math::PI; angle = 0
  182.     loop do
  183.       Graphics.update; Input.update
  184.       angle += add; angle %= max
  185.       continue.opacity = 185 + 70* Math.cos(angle)
  186.       break if Input.trigger?(Input::C)
  187.     end
  188.     error.bitmap.dispose; continue.bitmap.dispose
  189.     error.bitmap = nil; continue.bitmap = nil
  190.     error.dispose; continue.dispose
  191.     error = nil; continue = nil
  192.     exit
  193.   end
  194. end
  195. $khas_awesome << ["Pixel Movement",1.2]
  196. #-------------------------------------------------------------------------------
  197. # * Game_Map
  198. #-------------------------------------------------------------------------------
  199. class Game_Map
  200.   include Pixel_Core
  201.   attr_reader :pixel_table
  202.   alias kp_referesh_vehicles referesh_vehicles
  203.   def pixel_valid?(x, y)
  204.     x >= 0 && x <= @pixel_wm && y >= 0 && y <= @pixel_hm
  205.   end
  206.   def referesh_vehicles
  207.     setup_table if Pixel_Core::Maps.include?(@map_id)
  208.     kp_referesh_vehicles
  209.   end
  210.   def setup_table
  211.     Graphics.update
  212.     @pixel_table = Table.new(width*Pixel, height*Pixel,6)
  213.     for x in 0...(width*Pixel)
  214.       for y in 0...(height*Pixel)
  215.         @pixel_table[x,y,0] = table_collision(x*Tile,y*Tile,0x0f)
  216.         @pixel_table[x,y,1] = table_collision(x*Tile,y*Tile,0x0200)
  217.         @pixel_table[x,y,2] = table_collision(x*Tile,y*Tile,0x0400)
  218.         @pixel_table[x,y,3] = table_ladder(x*Tile,y*Tile)
  219.         @pixel_table[x,y,4] = table_bush(x*Tile+Bush_Axis[0],y*Tile+Bush_Axis[1])
  220.         @pixel_table[x,y,5] = table_counter(x*Tile+Counter_Axis[0],y*Tile+Counter_Axis[1])
  221.       end
  222.     end
  223.     @pixel_wm = (width-1)*Pixel
  224.     @pixel_hm = (height-1)*Pixel
  225.   end
  226.   def table_collision(x,y,flag)
  227.     return 0 unless table_passage((x+Body_Axis[0]).to_i,(y+Body_Axis[1]).to_i,flag)
  228.     return 0 unless table_passage((x+Body_Axis[2]).to_i,(y+Body_Axis[1]).to_i,flag)
  229.     return 0 unless table_passage((x+Body_Axis[0]).to_i,(y+Body_Axis[3]).to_i,flag)
  230.     return 0 unless table_passage((x+Body_Axis[2]).to_i,(y+Body_Axis[3]).to_i,flag)
  231.     return 1
  232.   end
  233.   def table_bush(x,y)
  234.     return layered_tiles_flag?(x.to_i, y.to_i, 0x40) ? 1 : 0
  235.   end
  236.   def table_ladder(x,y)
  237.     return 1 if layered_tiles_flag?(x.to_i,(y+Ladder_Axis[1]).to_i, 0x20)
  238.     return 1 if layered_tiles_flag?((x+Ladder_Axis[0]).to_i, (y+Ladder_Axis[1]).to_i, 0x20)
  239.     return 0
  240.   end
  241.   def table_counter(x,y)
  242.     return 1 if layered_tiles_flag?(x.to_i,y.to_i, 0x80)
  243.     return 1 if layered_tiles_flag?((x+Counter_Axis[2]).to_i,y.to_i, 0x80)
  244.     return 1 if layered_tiles_flag?(x.to_i,(y+Counter_Axis[3]).to_i, 0x80)
  245.     return 1 if layered_tiles_flag?((x+Counter_Axis[2]).to_i,(y+Counter_Axis[3]).to_i, 0x80)
  246.     return 0
  247.   end
  248.   def table_passage(x,y,bit)
  249.     layered_tiles(x,y).each do |tile_id|
  250.       flag = tileset.flags[tile_id]
  251.       next if flag & 0x10 != 0
  252.       return true  if flag & bit == 0
  253.       return false if flag & bit == bit
  254.     end
  255.     return false
  256.   end
  257.   def table_passage_rf(x,y,bit)
  258.     all_tiles(x,y).each do |tile_id|
  259.       flag = tileset.flags[tile_id]
  260.       next if flag & 0x10 != 0
  261.       return true  if flag & bit == 0
  262.       return false if flag & bit == bit
  263.     end
  264.     return false
  265.   end
  266.   def table_collision_rf(x,y,flag)
  267.     return 0 unless table_passage_rf((x+Body_Axis[0]).to_i,(y+Body_Axis[1]).to_i,flag)
  268.     return 0 unless table_passage_rf((x+Body_Axis[2]).to_i,(y+Body_Axis[1]).to_i,flag)
  269.     return 0 unless table_passage_rf((x+Body_Axis[0]).to_i,(y+Body_Axis[3]).to_i,flag)
  270.     return 0 unless table_passage_rf((x+Body_Axis[2]).to_i,(y+Body_Axis[3]).to_i,flag)
  271.     return 1
  272.   end
  273.   def refresh_table(start_x,start_y,end_x,end_y)
  274.     for x in (start_x*Pixel)..(end_x*Pixel)
  275.       for y in (start_y*Pixel)..(end_y*Pixel)
  276.         @pixel_table[x,y,0] = table_collision_rf(x*Tile,y*Tile,0x0f)
  277.         @pixel_table[x,y,1] = table_collision_rf(x*Tile,y*Tile,0x0200)
  278.         @pixel_table[x,y,2] = table_collision_rf(x*Tile,y*Tile,0x0400)
  279.       end
  280.     end
  281.   end
  282.   def refresh_table_px(start_px,start_py,end_px,end_py)
  283.     for x in start_px..end_px
  284.       for y in start_py..end_py
  285.         @pixel_table[x,y,0] = table_collision_rf(x*Tile,y*Tile,0x0f)
  286.         @pixel_table[x,y,1] = table_collision_rf(x*Tile,y*Tile,0x0200)
  287.         @pixel_table[x,y,2] = table_collision_rf(x*Tile,y*Tile,0x0400)
  288.       end
  289.     end
  290.   end
  291. end
  292.  
  293. if Pixel_Core::Auto_Refresh_Tile_Events
  294.   class Game_Map
  295.     def refresh_tile_events
  296.       @tile_events = @events.values.select {|event| event.tile? }
  297.       @tile_events.each { |event| refresh_table_px(event.px-TileEvent_Range,event.py-TileEvent_Range,event.px+TileEvent_Range,event.py+TileEvent_Range)}
  298.     end
  299.   end
  300. end
  301.  
  302. #-------------------------------------------------------------------------------
  303. # * Game_CharacterBase
  304. #-------------------------------------------------------------------------------
  305. class Game_CharacterBase
  306.   include Pixel_Core
  307.   attr_accessor :px
  308.   attr_accessor :py
  309.   attr_accessor :cx
  310.   attr_accessor :cy
  311.   alias kp_public_members init_public_members
  312.   alias kp_moveto moveto
  313.   alias kp_move_straight move_straight
  314.   alias kp_move_diagonal move_diagonal
  315.   alias kp_bush? bush?
  316.   alias kp_ladder? ladder?
  317.   alias kp_terrain_tag terrain_tag
  318.   alias kp_region_id region_id
  319.   def init_public_members
  320.     kp_public_members
  321.     if (Maps.include?($game_map.map_id) rescue false)
  322.       @x = @x.to_f
  323.       @y = @y.to_f
  324.       @pixel = true
  325.     else
  326.       @pixel = false
  327.     end
  328.     @px = (@x*Pixel).to_i
  329.     @py = (@y*Pixel).to_i
  330.     @cx = Default_Collision_X
  331.     @cy = Default_Collision_Y
  332.   end
  333.   def moveto(x,y)
  334.     @pixel = Maps.include?($game_map.map_id)
  335.     kp_moveto(x,y)
  336.     if @pixel
  337.       @x = @x.to_f
  338.       @y = @y.to_f
  339.     end
  340.     @px = (@x*Pixel).to_i
  341.     @py = (@y*Pixel).to_i
  342.   end
  343.   def pixel_passable?(px,py,d)
  344.     nx = px+Tile_Range[d][0]
  345.     ny = py+Tile_Range[d][1]
  346.     return false unless $game_map.pixel_valid?(nx,ny)
  347.     return true if @through || debug_through?
  348.     return false if $game_map.pixel_table[nx,ny,0] == 0
  349.     return false if collision?(nx,ny)
  350.     return true
  351.   end
  352.   def collision?(px,py)
  353.     for event in $game_map.events.values
  354.       if (event.px - px).abs <= event.cx && (event.py - py).abs <= event.cy
  355.         next if event.through || event == self
  356.         return true if event.priority_type == 1
  357.       end
  358.     end
  359.     if @priority_type == 1 && !$game_player.in_airship?
  360.       return true if ($game_player.px - px).abs <= @cx && ($game_player.py - py).abs <= @cy
  361.     end
  362.     return false
  363.   end
  364.   def move_straight(d,turn_ok = true)
  365.     @pixel ? move_pixel(d,turn_ok) : kp_move_straight(d,turn_ok)
  366.   end
  367.   def move_diagonal(horz, vert)
  368.     @pixel ? move_dpixel(horz,vert) : kp_move_diagonal(horz,vert)
  369.   end
  370.   def move_pixel(d,t)
  371.     @move_succeed = pixel_passable?(@px,@py,d)
  372.     if @move_succeed
  373.       set_direction(d)
  374.       @px += Tile_Range[d][0]
  375.       @py += Tile_Range[d][1]
  376.       @real_x = @x
  377.       @real_y = @y
  378.       @x += Pixel_Range[d][0]
  379.       @y += Pixel_Range[d][1]
  380.       increase_steps
  381.     elsif t
  382.       set_direction(d)
  383.       front_pixel_touch?(@px + Tile_Range[d][0],@py + Tile_Range[d][1])
  384.     end
  385.   end
  386.   def move_dpixel(h,v)
  387.     @move_succeed = false
  388.     if pixel_passable?(@px,@py,v)
  389.       @move_succeed = true
  390.       @real_x = @x
  391.       @real_y = @y
  392.       set_direction(v)
  393.       @px += Tile_Range[v][0]
  394.       @py += Tile_Range[v][1]
  395.       @x += Pixel_Range[v][0]
  396.       @y += Pixel_Range[v][1]
  397.       increase_steps
  398.     else
  399.       set_direction(v)
  400.       front_pixel_touch?(@px + Tile_Range[v][0],@py + Tile_Range[v][1])
  401.     end
  402.     if pixel_passable?(@px,@py,h)
  403.       unless @move_succeed
  404.         @real_x = @x
  405.         @real_y = @y
  406.         @move_succeed = true
  407.       end
  408.       set_direction(h)
  409.       @px += Tile_Range[h][0]
  410.       @py += Tile_Range[h][1]
  411.       @x += Pixel_Range[h][0]
  412.       @y += Pixel_Range[h][1]
  413.       increase_steps
  414.     else
  415.       set_direction(h)
  416.       front_pixel_touch?(@px + Tile_Range[h][0],@py + Tile_Range[h][1])
  417.     end
  418.   end
  419.   def bush?
  420.     return (@pixel ? $game_map.pixel_table[@px, @py, 4] == 1 : kp_bush?)
  421.   end
  422.   def ladder?
  423.     return (@pixel ? $game_map.pixel_table[@px, @py, 3] == 1 : kp_ladder?)
  424.   end
  425.   def terrain_tag
  426.     if @pixel
  427.       rx = ((@px % Pixel) > 1 ? @x.to_i + 1 : @x.to_i)
  428.       ry = ((@py % Pixel) > 1 ? @y.to_i + 1 : @y.to_i)
  429.       return $game_map.terrain_tag(rx,ry)
  430.     else
  431.       return kp_terrain_tag
  432.     end
  433.   end
  434.   def region_id
  435.     if @pixel
  436.       rx = ((@px % Pixel) > 1 ? @x.to_i + 1 : @x.to_i)
  437.       ry = ((@py % Pixel) > 1 ? @y.to_i + 1 : @y.to_i)
  438.       return $game_map.region_id(rx, ry)
  439.     else
  440.       return kp_region_id
  441.     end
  442.   end
  443.   def front_pixel_touch?(x,y)
  444.   end
  445. end
  446. #-------------------------------------------------------------------------------
  447. # * Game_Character
  448. #-------------------------------------------------------------------------------
  449. class Game_Character < Game_CharacterBase
  450.   alias kp_force_move_route force_move_route
  451.   alias kp_move_toward_character move_toward_character
  452.   alias kp_move_away_from_character move_away_from_character
  453.   alias kp_jump jump
  454.   def force_move_route(route)
  455.     kp_force_move_route(route.clone)
  456.     multiply_commands
  457.   end
  458.   def multiply_commands
  459.     return unless @pixel
  460.     return unless Multiply_Commands
  461.     return if @move_route.list.empty?
  462.     new_route = []
  463.     for cmd in @move_route.list
  464.       if Commands.include?(cmd.code)
  465.         Pixel.times do
  466.           new_route << cmd
  467.         end
  468.       else
  469.         new_route << cmd
  470.       end
  471.     end
  472.     @move_route.list = new_route
  473.   end
  474.   def move_toward_character(character)
  475.     if @pixel
  476.       dx = @px - character.px
  477.       dy = @py - character.py
  478.       if dx.abs < character.cx
  479.         unless dy.abs < character.cy
  480.           move_pixel(dy < 0 ? 2 : 8,true)
  481.           unless @move_succeed
  482.             return if dx.abs - Chase_Axis[@direction][0] <= @cx && dy.abs - Chase_Axis[@direction][1] <= @cy
  483.             move_dpixel(dx < 0 ? 6 : 4, dy < 0 ? 2 : 8)
  484.           end
  485.         end
  486.       else
  487.         if dy.abs < character.cy
  488.           move_pixel(dx < 0 ? 6 : 4,true)
  489.           unless @move_succeed
  490.             return if dx.abs - Chase_Axis[@direction][0] <= @cx && dy.abs - Chase_Axis[@direction][1] <= @cy
  491.             move_dpixel(dx < 0 ? 6 : 4, dy < 0 ? 2 : 8)
  492.           end
  493.         else
  494.           move_dpixel(dx < 0 ? 6 : 4, dy < 0 ? 2 : 8)
  495.         end
  496.       end
  497.     else
  498.       kp_move_toward_character(character)
  499.     end
  500.   end
  501.   def move_toward_character_uns(character)
  502.     dx = distance_x_from(character.x)
  503.     dy = distance_y_from(character.y)
  504.     if dx == 0
  505.       move_pixel(dy < 0 ? 2 : 8,true)
  506.     else
  507.       if dy == 0
  508.         move_pixel(dx < 0 ? 6 : 4,true)
  509.       else
  510.         move_dpixel(dx < 0 ? 6 : 4, dy < 0 ? 2 : 8)
  511.       end
  512.     end
  513.   end
  514.   def move_away_from_character(character)
  515.     if @pixel
  516.       dx = distance_x_from(character.x)
  517.       dy = distance_y_from(character.y)
  518.       if dx == 0
  519.         move_pixel(dy > 0 ? 2 : 8,true)
  520.       else
  521.         if dy == 0
  522.           move_pixel(dx > 0 ? 6 : 4,true)
  523.         else
  524.           move_dpixel(dx > 0 ? 6 : 4, dy > 0 ? 2 : 8)
  525.         end
  526.       end
  527.     else
  528.       kp_move_away_from_character(character)
  529.     end
  530.   end
  531.   def jump(xp,yp)
  532.     kp_jump(xp,yp)
  533.     @px = @x*Pixel
  534.     @py = @y*Pixel
  535.   end
  536. end
  537. #-------------------------------------------------------------------------------
  538. # * Game_Player
  539. #-------------------------------------------------------------------------------
  540. class Game_Player < Game_Character
  541.   alias kp_move_by_input move_by_input
  542.   alias kp_on_damage_floor? on_damage_floor?
  543.   alias kp_get_on_off_vehicle get_on_off_vehicle
  544.   alias kp_check_event_trigger_here check_event_trigger_here
  545.   alias kp_check_event_trigger_there check_event_trigger_there
  546.   def encounter_progress_value
  547.     value = bush? ? 2 : 1
  548.     value *= 0.5 if $game_party.encounter_half?
  549.     value *= 0.5 if in_ship?
  550.     value
  551.   end
  552.   def get_on_off_vehicle
  553.     @pixel ? pixel_gov : kp_get_on_off_vehicle
  554.   end
  555.   def pixel_gov
  556.     vehicle ? get_fv : get_nv
  557.   end
  558.   def get_nv
  559.     fx = @px+Trigger_Range[@direction][0]
  560.     fy = @py+Trigger_Range[@direction][1]
  561.     if ($game_map.boat.px - fx).abs <= $game_map.boat.cx && ($game_map.boat.py - fy).abs <= $game_map.boat.cy
  562.       return false if $game_map.pixel_table[@px+Vehicle_Range[@direction][0],@py+Vehicle_Range[@direction][1],1] == 0
  563.       jump(Vehicle_Range[@direction][0]*Tile,Vehicle_Range[@direction][1]*Tile)
  564.       @vehicle_type = :boat   
  565.       @vehicle_getting_on = true
  566.       @followers.gather
  567.     elsif ($game_map.ship.px - fx).abs <= $game_map.ship.cx && ($game_map.ship.py - fy).abs <= $game_map.ship.cy
  568.       return false if $game_map.pixel_table[@px+Vehicle_Range[@direction][0],@py+Vehicle_Range[@direction][1],2] == 0
  569.       jump(Vehicle_Range[@direction][0]*Tile,Vehicle_Range[@direction][1]*Tile)
  570.       @vehicle_type = :ship
  571.       @vehicle_getting_on = true
  572.       @followers.gather
  573.     elsif ($game_map.airship.px - fx).abs <= $game_map.airship.cx && ($game_map.airship.py - fy).abs <= $game_map.airship.cy
  574.       $game_player.centralize($game_map.airship.x,$game_map.airship.y)
  575.       @vehicle_type = :airship
  576.       @vehicle_getting_on = true
  577.       @followers.gather
  578.     end
  579.     return @vehicle_getting_on
  580.   end
  581.   def get_fv
  582.     if in_airship?
  583.       return unless pixel_airdocs?(@px,@py)
  584.       set_direction(2)
  585.     else
  586.       fx = @px+Vehicle_Range[@direction][0]
  587.       fy = @py+Vehicle_Range[@direction][1]
  588.       return unless pixel_walk?(fx,fy)
  589.       jump(Vehicle_Range[@direction][0]*Tile,Vehicle_Range[@direction][1]*Tile)
  590.       @transparent = false
  591.     end
  592.     @followers.synchronize(@x, @y, @direction)
  593.     vehicle.get_off
  594.     @vehicle_getting_off = true
  595.     @move_speed = 4
  596.     @through = false
  597.     make_encounter_count
  598.     @followers.gather
  599.   end
  600.   def pixel_airdocs?(px,py)
  601.     return false if $game_map.pixel_table[px,py,0] == 0
  602.     return false if $game_map.pixel_table[px,py,4] == 1 && !Airship_Bush
  603.     return false if collision?(px,py)
  604.     return true
  605.   end
  606.   def pixel_walk?(px,py)
  607.     return false if $game_map.pixel_table[px,py,0] == 0
  608.     return false if collision?(px,py)
  609.     return true
  610.   end
  611.   def centralize(fx=@x.to_i,fy=@y.to_i)
  612.     cx = @x - fx
  613.     cy = @y - fy
  614.     tx = (cx/Tile).to_i
  615.     ty = (cy/Tile).to_i
  616.     tx.times do; move_pixel(cx > 0 ? 4 : 6,false); end
  617.     ty.times do; move_pixel(cy > 0 ? 8 : 2,false); end
  618.   end
  619.   def check_event_trigger_here(triggers)
  620.     if @pixel
  621.       for event in $game_map.events.values
  622.         if (event.px - @px).abs <= event.cx && (event.py - @py).abs <= event.cy
  623.           event.start if triggers.include?(event.trigger) && event.priority_type != 1
  624.         end
  625.       end
  626.     else
  627.       kp_check_event_trigger_here(triggers)
  628.     end
  629.   end
  630.   def check_event_trigger_there(triggers)
  631.     if @pixel
  632.       fx = @px+Trigger_Range[@direction][0]
  633.       fy = @py+Trigger_Range[@direction][1]
  634.       for event in $game_map.events.values
  635.         if (event.px - fx).abs <= event.cx && (event.py - fy).abs <= event.cy
  636.           if triggers.include?(event.trigger) && event.normal_priority?
  637.             event.start
  638.             return
  639.           end
  640.         end
  641.       end
  642.       if $game_map.pixel_table[fx,fy,5] == 1
  643.         fx += Counter_Range[@direction][0]
  644.         fy += Counter_Range[@direction][1]
  645.         for event in $game_map.events.values
  646.           if (event.px - fx).abs <= event.cx && (event.py - fy).abs <= event.cy
  647.             if triggers.include?(event.trigger) && event.normal_priority?
  648.               event.start
  649.               return
  650.             end
  651.           end
  652.         end
  653.       end
  654.     else
  655.       kp_check_event_trigger_there(triggers)
  656.     end
  657.   end
  658.   def front_pixel_touch?(px,py)
  659.     return if $game_map.interpreter.running?
  660.     for event in $game_map.events.values
  661.       if (event.px - px).abs <= event.cx && (event.py - py).abs <= event.cy
  662.         if [1,2].include?(event.trigger) && event.normal_priority?
  663.           event.start
  664.           result = true
  665.         end
  666.       end
  667.     end
  668.   end
  669.   def pixel_passable?(px,py,d)
  670.     nx = px+Tile_Range[d][0]
  671.     ny = py+Tile_Range[d][1]
  672.     return false unless $game_map.pixel_valid?(nx,ny)
  673.     return true if @through || debug_through?
  674.     case @vehicle_type
  675.     when :boat
  676.       return false if $game_map.pixel_table[nx,ny,1] == 0
  677.     when :ship
  678.       return false if $game_map.pixel_table[nx,ny,2] == 0
  679.     when :airship
  680.       return true
  681.     else
  682.       return false if $game_map.pixel_table[nx,ny,0] == 0
  683.     end
  684.     return false if collision?(nx,ny)
  685.     return true
  686.   end
  687.   def move_by_input
  688.     @pixel ? pixel_move_by_input : kp_move_by_input
  689.   end
  690.   def pixel_move_by_input
  691.     return if !movable? || $game_map.interpreter.running?
  692.     case Input.dir8
  693.       when 1; move_dpixel(4,2)
  694.       when 2; move_pixel(2,true)
  695.       when 3; move_dpixel(6,2)
  696.       when 4; move_pixel(4,true)
  697.       when 6; move_pixel(6,true)
  698.       when 7; move_dpixel(4,8)
  699.       when 8; move_pixel(8,true)
  700.       when 9; move_dpixel(6,8)
  701.     end
  702.   end
  703.   def on_damage_floor?
  704.     return (@pixel ? false : kp_on_damage_floor?)
  705.   end
  706.   def collision?(px,py)
  707.     for event in $game_map.events.values
  708.       if (event.px - px).abs <= event.cx && (event.py - py).abs <= event.cy
  709.         next if event.through
  710.         return true if event.priority_type == 1
  711.       end
  712.     end
  713.     return false
  714.   end
  715.   def move_pixel(d,t)
  716.     super(d,t)
  717.     @followers.move
  718.   end
  719.   def move_dpixel(h,v)
  720.     super(h,v)
  721.     @followers.move
  722.   end
  723. end
  724. #-------------------------------------------------------------------------------
  725. # * Game_Follower
  726. #-------------------------------------------------------------------------------
  727. class Game_Follower < Game_Character
  728.   alias kp_chase_preceding_character chase_preceding_character
  729.   alias kp_initialize initialize
  730.   attr_accessor :through
  731.   def initialize(i,p)
  732.     kp_initialize(i,p)
  733.     @through = false
  734.   end
  735.   def chase_preceding_character
  736.     if @pixel
  737.       return if moving?
  738.       if $game_player.followers.gathering?
  739.         dx = distance_x_from($game_player.x)
  740.         dy = distance_y_from($game_player.y)
  741.         if dx.abs < Follow_Distance
  742.           if dy.abs < Follow_Distance
  743.             return if gather?
  744.             $game_player.in_airship? ? move_toward_character_uns(@preceding_character) : jump(-dx,-dy)
  745.           else
  746.             move_pixel(dy < 0 ? 2 : 8,true)
  747.           end
  748.         else
  749.           if dy.abs < Follow_Distance
  750.             move_pixel(dx < 0 ? 6 : 4,true)
  751.           else
  752.             move_dpixel(dx < 0 ? 6 : 4, dy < 0 ? 2 : 8)
  753.           end
  754.         end
  755.       else
  756.         dx = distance_x_from(@preceding_character.x)
  757.         dy = distance_y_from(@preceding_character.y)
  758.         if dx.abs < Follow_Distance
  759.           unless dy.abs < Follow_Distance
  760.             move_pixel(dy < 0 ? 2 : 8,true)
  761.             unless @move_succeed
  762.               return if dx == 0 && dy == 0
  763.               move_dpixel(dx < 0 ? 6 : 4, dy < 0 ? 2 : 8)
  764.             end
  765.           end
  766.         else
  767.           if dy.abs < Follow_Distance
  768.             move_pixel(dx < 0 ? 6 : 4,true)
  769.             unless @move_succeed
  770.               return if dx == 0 && dy == 0
  771.               move_dpixel(dx < 0 ? 6 : 4, dy < 0 ? 2 : 8)
  772.             end
  773.           else
  774.             move_dpixel(dx < 0 ? 6 : 4, dy < 0 ? 2 : 8)
  775.           end
  776.         end
  777.       end
  778.     else
  779.       kp_chase_preceding_character
  780.     end
  781.   end
  782.   def collision?(px,py)
  783.     for event in $game_map.events.values
  784.       if (event.px - px).abs <= event.cx && (event.py - py).abs <= event.cy
  785.         next if event.through || event == self
  786.         return true if event.priority_type == 1
  787.       end
  788.     end
  789.     return false
  790.   end
  791.   def gather?
  792.     result = !moving? && pos?(@preceding_character.x, @preceding_character.y)
  793.     @through = !result
  794.     return result
  795.   end
  796. end
  797. #-------------------------------------------------------------------------------
  798. # * Game_Followers
  799. #-------------------------------------------------------------------------------
  800. class Game_Followers
  801.   alias kp_gather gather
  802.   def gather
  803.     kp_gather
  804.     each { |char| char.through = true}
  805.   end
  806. end
  807. #-------------------------------------------------------------------------------
  808. # * Game_Vehicle
  809. #-------------------------------------------------------------------------------
  810. class Game_Vehicle < Game_Character
  811.   alias kp_set_location set_location
  812.   alias kp_sync_with_player sync_with_player
  813.   def set_location(map_id, x, y)
  814.     @px = (@x*Pixel).to_i
  815.     @py = (@y*Pixel).to_i
  816.     kp_set_location(map_id,x.to_f,y.to_f)
  817.   end
  818.   def sync_with_player
  819.     @px = $game_player.px
  820.     @py = $game_player.py
  821.     kp_sync_with_player
  822.   end
  823. end
  824. #-------------------------------------------------------------------------------
  825. # * Game_Event
  826. #-------------------------------------------------------------------------------
  827. class Game_Event < Game_Character
  828.   alias kp_move_type_toward_player move_type_toward_player
  829.   alias kp_initialize initialize
  830.   alias kp_setup_page_settings setup_page_settings
  831.   def initialize(m,e)
  832.     kp_initialize(m,e)
  833.     setup_collision
  834.   end
  835.   def move_type_toward_player
  836.     if @pixel
  837.       move_toward_player if near_the_player?
  838.     else
  839.       kp_move_type_toward_player
  840.     end
  841.   end
  842.   def setup_page_settings
  843.     kp_setup_page_settings
  844.     setup_collision
  845.     multiply_commands
  846.   end
  847.   def collision?(px,py)
  848.     for event in $game_map.events.values
  849.       if (event.px - px).abs <= event.cx && (event.py - py).abs <= event.cy
  850.         next if event.through || event == self
  851.         return true if event.priority_type == 1
  852.       end
  853.     end
  854.     if @priority_type == 1 && !$game_player.in_airship?
  855.       return true if ($game_player.px - px).abs <= @cx && ($game_player.py - py).abs <= @cy
  856.       for follower in $game_player.followers.visible_folloers
  857.         return true if (follower.px - px).abs <= @cx && (follower.py - py).abs <= @cy
  858.       end
  859.     end
  860.     return false
  861.   end
  862.   def setup_collision
  863.     @cx = Default_Collision_X
  864.     @cy = Default_Collision_Y
  865.     unless @list.nil?
  866.       for value in 0...@list.size
  867.         next if @list[value].code != 108 && @list[value].code != 408
  868.         if @list[value].parameters[0].include?("[collision_x ")
  869.           @list[value].parameters[0].scan(/\[collision_x ([0.0-9.9]+)\]/)
  870.           @cx = $1.to_i
  871.         end
  872.         if @list[value].parameters[0].include?("[collision_y ")
  873.           @list[value].parameters[0].scan(/\[collision_y ([0.0-9.9]+)\]/)
  874.           @cy = $1.to_i
  875.         end
  876.       end
  877.     end
  878.   end
  879.   def front_pixel_touch?(px,py)
  880.     return if $game_map.interpreter.running? || !$game_player.normal_walk?
  881.     if @trigger == 2 && ($game_player.px - px).abs <= @cx && ($game_player.py - py).abs <= @cy
  882.       start if !jumping? && normal_priority?
  883.     end
  884.   end
  885. end
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2025-9-9 15:41

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表