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

Project1

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

[有事请教] VA如何通过地图的备注来启动插件脚本?

[复制链接]

Lv1.梦旅人

梦石
0
星屑
70
在线时间
10 小时
注册时间
2025-5-6
帖子
1
跳转到指定楼层
1

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

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

x
本帖最后由 lifrtam 于 2025-8-7 16:11 编辑

如题:RPG maker VA怎么修改插件的代码,在地图设置里的备注写上一些开启代码,插件就会在这个地图里运行,在备注空白的其他地图里,插件就不会该地图里运行。
RUBY 代码复制
  1. module CXJ
  2.   module FREE_MOVEMENT
  3.  
  4.     ENABLE_DIAGONAL = true    # Enables diagonal movement.
  5.  
  6.     DEFAULT_COLLISION = [8, 12, 16, 20]
  7.     DEFAULT_INTERACTION = {
  8.     2 => [4, 0, 24, 24],
  9.     4 => [16, 10, 24, 24],
  10.     6 => [-8, 10, 24, 24],
  11.     8 => [4, 20, 24, 24],
  12.     }
  13.  
  14.     BOAT_COLLISION      = [4, 4, 24, 24]
  15.     AIRSHIP_COLLISION   = [4, 8, 24, 24]
  16.  
  17.     PIXELS_PER_STEP = 4
  18.  
  19.     FOLLOWERS_DISTANCE = 16
  20.     FOLLOWERS_DISTANCE_MARGIN = 4
  21.  
  22.     JUMP_SPEED = 0.5
  23.   end
  24. end
  25.  
  26. #==============================================================================
  27. # ** Game_Map
  28. #------------------------------------------------------------------------------
  29. #  This class handles maps. It includes scrolling and passage determination
  30. # functions. The instance of this class is referenced by $game_map.
  31. #==============================================================================
  32.  
  33. class Game_Map
  34.   #--------------------------------------------------------------------------
  35.   # * New: Determine Valid Coordinates
  36.   #--------------------------------------------------------------------------
  37.   def valid_rect?(x, y, rect)
  38.     x2 = x + (rect.x / 32.0)
  39.     y2 = y + (rect.y / 32.0)
  40.     x3 = x2 + (rect.width / 32.0)
  41.     y3 = y2 + (rect.height / 32.0)
  42.     round_x(x2) >= 0 && round_x(x3) < width && round_y(y2) >= 0 && round_y(y3) < height
  43.   end
  44.   #--------------------------------------------------------------------------
  45.   # * Override: Check Passage
  46.   #     bit:  Inhibit passage check bit
  47.   #--------------------------------------------------------------------------
  48.   def check_passage(x, y, bit)
  49.     x = round_x(x)
  50.     y = round_y(y)
  51.     all_tiles(x, y).each do |tile_id|
  52.       flag = tileset.flags[tile_id]
  53.       next if flag & 0x10 != 0            # [☆]: No effect on passage
  54.       return true  if flag & bit == 0     # [○] : Passable
  55.       return false if flag & bit == bit   # [×] : Impassable
  56.     end
  57.     return false                          # Impassable
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # * New: Determine Passability of Normal Character
  61.   #     d:  direction (2,4,6,8)
  62.   #    Determines whether the tile at the specified coordinates is passable
  63.   #    in the specified direction.
  64.   #--------------------------------------------------------------------------
  65.   def passable_rect?(x, y, d, rect)
  66.     x2 = x + (rect.x / 32.0)
  67.     y2 = y + (rect.y / 32.0)
  68.     x3 = x2 + (rect.width / 32.0)
  69.     y3 = y2 + (rect.height / 32.0)
  70.     return false unless check_passage(x2, y2, (1 << (d / 2 - 1)) & 0x0f)
  71.     return false unless check_passage(x2, y3, (1 << (d / 2 - 1)) & 0x0f)
  72.     return false unless check_passage(x3, y2, (1 << (d / 2 - 1)) & 0x0f)
  73.     return check_passage(x3, y3, (1 << (d / 2 - 1)) & 0x0f)
  74.   end
  75.   #--------------------------------------------------------------------------
  76.   # * Determine if Passable by Boat
  77.   #--------------------------------------------------------------------------
  78.   def boat_passable_rect?(x, y, rect)
  79.     x2 = x + (rect.x / 32.0)
  80.     y2 = y + (rect.y / 32.0)
  81.     x3 = x2 + (rect.width / 32.0)
  82.     y3 = y2 + (rect.height / 32.0)
  83.     return false unless check_passage(x2, y2, 0x0200)
  84.     return false unless check_passage(x2, y3, 0x0200)
  85.     return false unless check_passage(x3, y2, 0x0200)
  86.     return check_passage(x3, y3, 0x0200)
  87.   end
  88.   #--------------------------------------------------------------------------
  89.   # * Determine if Passable by Ship
  90.   #--------------------------------------------------------------------------
  91.   def ship_passable_rect?(x, y, rect)
  92.     x2 = x + (rect.x / 32.0)
  93.     y2 = y + (rect.y / 32.0)
  94.     x3 = x2 + (rect.width / 32.0)
  95.     y3 = y2 + (rect.height / 32.0)
  96.     return false unless check_passage(x2, y2, 0x0400)
  97.     return false unless check_passage(x2, y3, 0x0400)
  98.     return false unless check_passage(x3, y2, 0x0400)
  99.     return check_passage(x3, y3, 0x0400)
  100.   end
  101.   #--------------------------------------------------------------------------
  102.   # * Determine if Airship can Land
  103.   #--------------------------------------------------------------------------
  104.   def airship_land_ok_rect?(x, y, rect)
  105.     x2 = x + (rect.x / 32.0)
  106.     y2 = y + (rect.y / 32.0)
  107.     x3 = x2 + (rect.width / 32.0)
  108.     y3 = y2 + (rect.height / 32.0)
  109.     return false unless check_passage(x2, y2, 0x0800) && check_passage(x2, y2, 0x0f)
  110.     return false unless check_passage(x2, y3, 0x0800) && check_passage(x2, y3, 0x0f)
  111.     return false unless check_passage(x3, y2, 0x0800) && check_passage(x3, y2, 0x0f)
  112.     return check_passage(x3, y3, 0x0800) && check_passage(x3, y3, 0x0f)
  113.   end
  114.   #--------------------------------------------------------------------------
  115.   # * Get Array of Events at Designated Coordinates
  116.   #--------------------------------------------------------------------------
  117.   def events_xy_rect(x, y, rect)
  118.     @events.values.select {|event| event.pos_rect?(x, y, rect) }
  119.   end
  120.   #--------------------------------------------------------------------------
  121.   # * Get Array of Events at Designated Coordinates (Except Pass-Through)
  122.   #--------------------------------------------------------------------------
  123.   def events_xy_rect_nt(x, y, rect)
  124.     @events.values.select {|event| event.pos_rect_nt?(x, y, rect) }
  125.   end
  126.   #--------------------------------------------------------------------------
  127.   # * Get Array of Tile-Handling Events at Designated Coordinates
  128.   #   (Except Pass-Through)
  129.   #--------------------------------------------------------------------------
  130.   def tile_events_xy_rect(x, y, rect)
  131.     @tile_events.select {|event| event.pos_rect_nt?(x, y, rect) }
  132.   end
  133. end
  134.  
  135. #==============================================================================
  136. # ** Game_CharacterBase
  137. #------------------------------------------------------------------------------
  138. #  This base class handles characters. It retains basic information, such as
  139. # coordinates and graphics, shared by all characters.
  140. #==============================================================================
  141.  
  142. class Game_CharacterBase
  143.   attr_accessor :move_poll
  144.   #--------------------------------------------------------------------------
  145.   # * Alias: Object Initialization
  146.   #--------------------------------------------------------------------------
  147.   alias game_characterbase_initialize_cxj_fm initialize
  148.   def initialize
  149.     game_characterbase_initialize_cxj_fm
  150.     @move_poll = []
  151.   end
  152.   #--------------------------------------------------------------------------
  153.   # * Alias: Frame Update
  154.   #
  155.   # Added processing of movement being polled.
  156.   #--------------------------------------------------------------------------
  157.   alias game_characterbase_update_cxj_fm update
  158.   def update
  159.     interpret_move unless moving?
  160.     game_characterbase_update_cxj_fm
  161.   end
  162.   #--------------------------------------------------------------------------
  163.   # * New: Movement Interpreting
  164.   #     Interprets the polled movement.
  165.   #--------------------------------------------------------------------------
  166.   def interpret_move(step_left = distance_per_frame)
  167.     if @move_poll.size > 0
  168.       current_move = @move_poll.shift()
  169.       d = current_move[0]
  170.       horz = (d - 1) % 3 - 1
  171.       vert = 1 - ((d - 1) / 3)
  172.       turn_ok = current_move[1]
  173.       set_direction(d)
  174.       processed = false
  175.       if (d % 2 == 0 && passable?(@x, @y, d)) || (d % 2 != 0 && diagonal_passable?(@x, @y, horz, vert))
  176.         process_move(horz, vert)
  177.         processed = true
  178.       elsif d % 2 != 0 && !diagonal_passable?(@x, @y, horz, vert)
  179.         if passable?(@x, @y, horz + 5)
  180.           set_direction(horz + 5)
  181.           process_move(horz, 0)
  182.           processed = true
  183.         end
  184.         if passable?(@x, @y, 5 - vert * 3)
  185.           set_direction(5 - vert * 3)
  186.           process_move(0, vert)
  187.           processed = true
  188.         end
  189.       end
  190.       if(processed)
  191.         pixelstep = CXJ::FREE_MOVEMENT::PIXELS_PER_STEP / 32.0
  192.         if(step_left > pixelstep && !@move_poll.empty?)
  193.           interpret_move(step_left - pixelstep)
  194.         elsif(jumping? && !@move_poll.empty?)
  195.           interpret_move(0)
  196.         end
  197.       else
  198.         @move_poll.clear
  199.       end
  200.       current_move
  201.     end
  202.   end
  203.  
  204.   def process_move(horz, vert)
  205.     pixelstep = CXJ::FREE_MOVEMENT::PIXELS_PER_STEP / 32.0
  206.     @x = @x + horz * pixelstep
  207.     @y = @y + vert * pixelstep
  208.     if(!jumping?)
  209.       @x = $game_map.round_x(@x)
  210.       @y = $game_map.round_y(@y)
  211.       @real_x = @x - horz * pixelstep
  212.       @real_y = @y - vert * pixelstep
  213.       increase_steps
  214.     end
  215.   end
  216.   #--------------------------------------------------------------------------
  217.   # * New: Collision Rectangle
  218.   #     Gets the collision rectangle.
  219.   #--------------------------------------------------------------------------
  220.   def collision_rect
  221.     collision = CXJ::FREE_MOVEMENT::DEFAULT_COLLISION
  222.     return Rect.new(collision[0], collision[1], collision[2] - 1, collision[3] - 1)
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # * Override: Determine if Passable
  226.   #     d : Direction (2,4,6,8)
  227.   #--------------------------------------------------------------------------
  228.   def passable?(x, y, d)
  229.     horz = (d - 1) % 3 - 1
  230.     vert = 1 - ((d - 1) / 3)
  231.     pixelstep = CXJ::FREE_MOVEMENT::PIXELS_PER_STEP / 32.0
  232.     x2 = $game_map.round_x(x + horz * pixelstep)
  233.     y2 = $game_map.round_y(y + vert * pixelstep)
  234.     return false unless $game_map.valid_rect?(x2, y2, collision_rect)
  235.     return true if @through || debug_through?
  236.     return false unless map_passable_rect?(x, y, d, collision_rect)
  237.     return false unless map_passable_rect?(x2, y2, reverse_dir(d), collision_rect)
  238.     return false if collide_with_characters?(x2, y2)
  239.     return true
  240.   end
  241.   #--------------------------------------------------------------------------
  242.   # * Determine Diagonal Passability
  243.   #     horz : Horizontal (4 or 6)
  244.   #     vert : Vertical (2 or 8)
  245.   #--------------------------------------------------------------------------
  246.   def diagonal_passable?(x, y, horz, vert)
  247.     pixelstep = CXJ::FREE_MOVEMENT::PIXELS_PER_STEP / 32.0
  248.     x2 = $game_map.round_x(x + horz * pixelstep)
  249.     y2 = $game_map.round_y(y + vert * pixelstep)
  250.     d = (horz == 4 ? -1 : 1) + (vert == 2 ? -3 : 3) + 5
  251.     passable?(x, y, vert) && passable?(x, y, horz) && passable?(x, y, d) && passable?(x2, y2, vert) && passable?(x2, y2, horz) && passable?(x2, y2, d)
  252.   end
  253.   #--------------------------------------------------------------------------
  254.   # * Determine if Map is Passable
  255.   #     d : Direction (2,4,6,8)
  256.   #--------------------------------------------------------------------------
  257.   def map_passable_rect?(x, y, d, rect)
  258.     $game_map.passable_rect?(x, y, d, rect)
  259.   end
  260.   #--------------------------------------------------------------------------
  261.   # * Override: Change Direction to Designated Direction
  262.   #     d : Direction (2,4,6,8)
  263.   #
  264.   # Fix for diagonal movement.
  265.   #--------------------------------------------------------------------------
  266.   def set_direction(d)
  267.     if !@direction_fix && d != 0
  268.       @direction = d
  269.       if d % 2 != 0
  270.         @direction+= 1
  271.         @direction-= 2 if d > 5
  272.         @direction = 10 - direction if d > 2 && d < 8
  273.       end
  274.     end
  275.     @stop_count = 0
  276.   end
  277.   #--------------------------------------------------------------------------
  278.   # * Override: Move Straight
  279.   #     d:        Direction (2,4,6,8)
  280.   #     turn_ok : Allows change of direction on the spot
  281.   #
  282.   # Polls the movement instead of processing them immediately.
  283.   #--------------------------------------------------------------------------
  284.   def move_straight(d, turn_ok = true)
  285.     pixelstep = CXJ::FREE_MOVEMENT::PIXELS_PER_STEP / 32.0
  286.     @move_poll+= [[d, turn_ok]] * (distance_per_frame / pixelstep).ceil
  287.   end
  288.   #--------------------------------------------------------------------------
  289.   # * Override: Move Diagonally
  290.   #     horz:  Horizontal (4 or 6)
  291.   #     vert:  Vertical (2 or 8)
  292.   #
  293.   # Polls the movement instead of processing them immediately.
  294.   #--------------------------------------------------------------------------
  295.   def move_diagonal(horz, vert)
  296.     pixelstep = CXJ::FREE_MOVEMENT::PIXELS_PER_STEP / 32.0
  297.     @move_poll+= [[vert + (horz > 5 ? 1 : -1), true]] * (distance_per_frame / pixelstep).ceil
  298.   end
  299.   #--------------------------------------------------------------------------
  300.   # * New: Determine Coordinate Match
  301.   #--------------------------------------------------------------------------
  302.   def pos_rect?(x, y, rect)
  303.     main_left = @x + collision_rect.x / 32.0
  304.     main_top = @y + collision_rect.y / 32.0
  305.     main_right = main_left + collision_rect.width / 32.0
  306.     main_bottom = main_top + collision_rect.height / 32.0
  307.     other_left = x + rect.x / 32.0
  308.     other_top = y + rect.y / 32.0
  309.     other_right = other_left + rect.width / 32.0
  310.     other_bottom = other_top + rect.height / 32.0
  311.     coltest = true
  312.     coltest = false if main_right < other_left
  313.     coltest = false if main_left > other_right
  314.     coltest = false if main_bottom < other_top
  315.     coltest = false if main_top > other_bottom
  316.     if coltest == false && ($game_map.loop_horizontal? || $game_map.loop_vertical?) && x <= $game_map.width && y <= $game_map.height
  317.       return true if $game_map.loop_horizontal? && pos_rect?(x + $game_map.width, y, rect)
  318.       return true if $game_map.loop_vertical? && pos_rect?(x, y + $game_map.height, rect)
  319.     end
  320.     return coltest
  321.   end
  322.   #--------------------------------------------------------------------------
  323.   # * New: Determine if Coordinates Match and Pass-Through Is Off (nt = No Through)
  324.   #--------------------------------------------------------------------------
  325.   def pos_rect_nt?(x, y, rect)
  326.     pos_rect?(x, y, rect) && !@through
  327.   end
  328.   #--------------------------------------------------------------------------
  329.   # * Detect Collision with Event
  330.   #--------------------------------------------------------------------------
  331.   def collide_with_events?(x, y)
  332.     $game_map.events_xy_rect_nt(x, y, collision_rect).any? do |event|
  333.       (event.normal_priority? || self.is_a?(Game_Event)) && event != self
  334.     end
  335.   end
  336.   #--------------------------------------------------------------------------
  337.   # * Override: Detect Collision with Vehicle
  338.   #--------------------------------------------------------------------------
  339.   def collide_with_vehicles?(x, y)
  340.     $game_map.boat.pos_rect_nt?(x, y, collision_rect) || $game_map.ship.pos_rect_nt?(x, y, collision_rect)
  341.   end
  342.   #--------------------------------------------------------------------------
  343.   # * Override: Update While Jumping
  344.   #--------------------------------------------------------------------------
  345.   def update_jump
  346.     @jump_count -= 1
  347.     diff_x = @real_x
  348.     @real_x = (@real_x * @jump_count + @x) / (@jump_count + 1.0)
  349.     @real_y = (@real_y * @jump_count + @y) / (@jump_count + 1.0)
  350.     update_bush_depth
  351.     if @jump_count == 0
  352.       @real_x = @x = $game_map.round_x(@x)
  353.       @real_y = @y = $game_map.round_y(@y)
  354.     end
  355.   end
  356.   #--------------------------------------------------------------------------
  357.   # * Override: Calculate Jump Height
  358.   #--------------------------------------------------------------------------
  359.   def jump_height
  360.     (@jump_peak * @jump_peak - (@jump_count * CXJ::FREE_MOVEMENT::JUMP_SPEED - @jump_peak).abs ** 2) / 2
  361.   end
  362. end
  363. #==============================================================================
  364. # ** Game_Character
  365. #------------------------------------------------------------------------------
  366. #  A character class with mainly movement route and other such processing
  367. # added. It is used as a super class of Game_Player, Game_Follower,
  368. # GameVehicle, and Game_Event.
  369. #==============================================================================
  370.  
  371. class Game_Character < Game_CharacterBase
  372.   #--------------------------------------------------------------------------
  373.   # * Move at Random
  374.   #--------------------------------------------------------------------------
  375.   def move_random
  376.     @move_poll+= [[2 + rand(4) * 2, false]] * (32 / CXJ::FREE_MOVEMENT::PIXELS_PER_STEP)
  377.   end
  378.   #--------------------------------------------------------------------------
  379.   # * Move Toward Character
  380.   #--------------------------------------------------------------------------
  381.   def move_toward_character(character)
  382.     sx = distance_x_from(character.x)
  383.     sy = distance_y_from(character.y)
  384.     if sx.abs > sy.abs
  385.       @move_poll+= [[sx > 0 ? 4 : 6, true]]
  386.       @move_poll+= [[sy > 0 ? 8 : 2, true]] if !@move_succeed && sy != 0
  387.     elsif sy != 0
  388.       @move_poll+= [[sy > 0 ? 8 : 2, true]]
  389.       @move_poll+= [[sx > 0 ? 4 : 6, true]] if !@move_succeed && sx != 0
  390.     end
  391.   end
  392.   #--------------------------------------------------------------------------
  393.   # * Move Away from Character
  394.   #--------------------------------------------------------------------------
  395.   def move_away_from_character(character)
  396.     sx = distance_x_from(character.x)
  397.     sy = distance_y_from(character.y)
  398.     if sx.abs > sy.abs
  399.       move_straight(sx > 0 ? 6 : 4)
  400.       move_straight(sy > 0 ? 2 : 8) if !@move_succeed && sy != 0
  401.     elsif sy != 0
  402.       move_straight(sy > 0 ? 2 : 8)
  403.       move_straight(sx > 0 ? 6 : 4) if !@move_succeed && sx != 0
  404.     end
  405.   end
  406.   #--------------------------------------------------------------------------
  407.   # * Override: Jump
  408.   #     x_plus : x-coordinate plus value
  409.   #     y_plus : y-coordinate plus value
  410.   #--------------------------------------------------------------------------
  411.   def jump(x_plus, y_plus)
  412.     if x_plus.abs > y_plus.abs
  413.       set_direction(x_plus < 0 ? 4 : 6) if x_plus != 0
  414.     else
  415.       set_direction(y_plus < 0 ? 8 : 2) if y_plus != 0
  416.     end
  417.     distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
  418.     pollcount = distance * (32.0 / CXJ::FREE_MOVEMENT::PIXELS_PER_STEP).ceil
  419.     @move_poll+= [[(x_plus < 0 ? -1 : x_plus > 0 ? 1 : 0) + (y_plus < 0 ? 8 : y_plus > 0 ? 2 : 5), false]] * pollcount
  420.     @jump_peak = 10 + distance - @move_speed
  421.     @jump_count = @jump_peak / CXJ::FREE_MOVEMENT::JUMP_SPEED * 2
  422.     @stop_count = 0
  423.     straighten
  424.   end
  425. end
  426. #==============================================================================
  427. # ** Game_Player
  428. #------------------------------------------------------------------------------
  429. #  This class handles the player. It includes event starting determinants and
  430. # map scrolling functions. The instance of this class is referenced by
  431. # $game_player.
  432. #==============================================================================
  433.  
  434. class Game_Player < Game_Character
  435.   #--------------------------------------------------------------------------
  436.   # * Object Initialization
  437.   #--------------------------------------------------------------------------
  438.   alias game_player_initialize_cxj_fm initialize
  439.   def initialize
  440.     @last_poll = []
  441.     game_player_initialize_cxj_fm
  442.     @custom_collision = []
  443.     @interaction = CXJ::FREE_MOVEMENT::DEFAULT_INTERACTION
  444.     if @note =~ /<collisionbox:[ ]*(\s*),[ ]*(\s*),[ ]*(\s*),[ ]*(\s*)>/i
  445.       @custom_collision = Rect.new($1, $2, $3 - 1, $4)
  446.     end
  447.     if @note =~ /<interaction (\s*):[ ]*(\s*),[ ]*(\s*),[ ]*(\s*),[ ]*(\s*)>/i && $1 > 0 && $1 < 10 && $1 % 2 == 0
  448.       @interaction[$1] = [$2, $3, $4, $5]
  449.     end
  450.   end
  451.   #--------------------------------------------------------------------------
  452.   # * New: Movement Interpreting
  453.   #     Interprets the polled movement.
  454.   #--------------------------------------------------------------------------
  455.   def interpret_move(step_left = distance_per_frame)
  456.     current_move = super(step_left)
  457.     @last_poll.push(current_move) if !current_move.nil?
  458.   end
  459.   #--------------------------------------------------------------------------
  460.   # * New: Collision Rectangle
  461.   #     Gets the collision rectangle.
  462.   #--------------------------------------------------------------------------
  463.   def collision_rect
  464.     return @custom_collision if @custom_collision.size > 0
  465.     return super
  466.   end
  467.   #--------------------------------------------------------------------------
  468.   # * New: Interaction Rectangle
  469.   #     Gets the interaction rectangle.
  470.   #--------------------------------------------------------------------------
  471.   def interaction_rect
  472.     collision = @interaction[@direction]
  473.     return Rect.new(collision[0], collision[1], collision[2] - 1, collision[3] - 1)
  474.   end
  475.   #--------------------------------------------------------------------------
  476.   # * Override: Processing of Movement via Input from Directional Buttons
  477.   #
  478.   # Added diagonal movement.
  479.   #--------------------------------------------------------------------------
  480.   def move_by_input
  481.     return if !movable? || $game_map.interpreter.running?
  482.     if CXJ::FREE_MOVEMENT::ENABLE_DIAGONAL && Input.dir8 > 0 && Input.dir8 % 2 != 0
  483.       d = Input.dir8
  484.       horz = (d == 1 || d == 7 ? 4 : 6)
  485.       vert = (d == 1 || d == 3 ? 2 : 8)
  486.       move_diagonal(horz, vert)
  487.     elsif Input.dir4 > 0
  488.       move_straight(Input.dir4)
  489.     end
  490.   end
  491.   #--------------------------------------------------------------------------
  492.   # * Detect Collision (Including Followers)
  493.   #--------------------------------------------------------------------------
  494.   def collide_rect?(x, y, rect)
  495.     !@through && (pos_rect?(x, y, rect) || followers.collide_rect?(x, y, rect))
  496.   end
  497.   #--------------------------------------------------------------------------
  498.   # * Trigger Map Event
  499.   #     triggers : Trigger array
  500.   #     normal   : Is priority set to [Same as Characters] ?
  501.   #--------------------------------------------------------------------------
  502.   def start_map_event(x, y, triggers, normal, rect = collision_rect)
  503.     return if $game_map.interpreter.running?
  504.     $game_map.events_xy_rect(x, y, rect).each do |event|
  505.       if event.trigger_in?(triggers) && event.normal_priority? == normal
  506.         event.start
  507.       end
  508.     end
  509.   end
  510.   #--------------------------------------------------------------------------
  511.   # * Determine if Front Event is Triggered
  512.   #--------------------------------------------------------------------------
  513.   def check_event_trigger_there(triggers)
  514.     x2 = $game_map.round_x_with_direction(@x, @direction)
  515.     y2 = $game_map.round_y_with_direction(@y, @direction)
  516.     start_map_event(x2, y2, triggers, true, interaction_rect)
  517.     return if $game_map.any_event_starting?
  518.     return unless $game_map.counter?(x2, y2)
  519.     x3 = $game_map.round_x_with_direction(x2, @direction)
  520.     y3 = $game_map.round_y_with_direction(y2, @direction)
  521.     start_map_event(x3, y3, triggers, true, interaction_rect)
  522.   end
  523.   #--------------------------------------------------------------------------
  524.   # * Board Vehicle
  525.   #    Assumes that the player is not currently in a vehicle.
  526.   #--------------------------------------------------------------------------
  527.   def get_on_vehicle
  528.     front_x = $game_map.round_x_with_direction(@x, @direction)
  529.     front_y = $game_map.round_y_with_direction(@y, @direction)
  530.     @vehicle_type = :boat    if $game_map.boat.pos_rect?(front_x, front_y, interaction_rect)
  531.     @vehicle_type = :ship    if $game_map.ship.pos_rect?(front_x, front_y, interaction_rect)
  532.     @vehicle_type = :airship if $game_map.airship.pos_rect?(@x, @y, collision_rect)
  533.     if vehicle
  534.       @vehicle_getting_on = true
  535.       horz = (@x > vehicle.x ? -1 : @x < vehicle.x ? 1 : 0)
  536.       vert = (@y > vehicle.y ? -3 : @y < vehicle.y ? 3 : 0)
  537.       d = 5 + horz - vert
  538.       set_direction(d)
  539.       @x = vehicle.x
  540.       @y = vehicle.y
  541.       @followers.gather
  542.     end
  543.     @vehicle_getting_on
  544.   end
  545.   #--------------------------------------------------------------------------
  546.   # * Get Off Vehicle
  547.   #    Assumes that the player is currently riding in a vehicle.
  548.   #--------------------------------------------------------------------------
  549.   def get_off_vehicle
  550.     if vehicle.land_ok?(@x, @y, @direction)
  551.       set_direction(2) if in_airship?
  552.       @followers.synchronize(@x, @y, @direction)
  553.       vehicle.get_off
  554.       unless in_airship?
  555.         @x = $game_map.round_x_with_direction(@x, @direction)
  556.         @y = $game_map.round_y_with_direction(@y, @direction)
  557.         @transparent = false
  558.       end
  559.       @vehicle_getting_off = true
  560.       @move_speed = 4
  561.       @through = false
  562.       make_encounter_count
  563.       @followers.gather
  564.     end
  565.     @vehicle_getting_off
  566.   end
  567.   #--------------------------------------------------------------------------
  568.   # * Determine if Map is Passable
  569.   #     d:  Direction (2,4,6,8)
  570.   #--------------------------------------------------------------------------
  571.   def map_passable_rect?(x, y, d, rect)
  572.     case @vehicle_type
  573.     when :boat
  574.       $game_map.boat_passable_rect?(x, y, vehicle.collision_rect)
  575.     when :ship
  576.       $game_map.ship_passable_rect?(x, y, vehicle.collision_rect)
  577.     when :airship
  578.       true
  579.     else
  580.       super
  581.     end
  582.   end
  583.   #--------------------------------------------------------------------------
  584.   # * Override: Move Diagonally
  585.   #--------------------------------------------------------------------------
  586.   def move_diagonal(horz, vert)
  587.     @followers.move if diagonal_passable?(@x, @y, horz, vert) || passable?(@x, @y, horz + 5) || passable?(@x, @y, 5 - vert * 3)
  588.     super
  589.   end
  590.   #--------------------------------------------------------------------------
  591.   # * Alias: Create Encounter Count
  592.   #--------------------------------------------------------------------------
  593.   alias game_player_make_encounter_count_cxj_fm make_encounter_count
  594.   def make_encounter_count
  595.     game_player_make_encounter_count_cxj_fm
  596.     @encounter_count*= (32 / CXJ::FREE_MOVEMENT::PIXELS_PER_STEP) + (32 / 2 < CXJ::FREE_MOVEMENT::PIXELS_PER_STEP ? 1 : 0)
  597.   end
  598.   #--------------------------------------------------------------------------
  599.   # * Detect Collision with Vehicle
  600.   #--------------------------------------------------------------------------
  601.   def collide_with_vehicles?(x, y)
  602.     (@vehicle_type != :boat && $game_map.boat.pos_rect_nt?(x, y, collision_rect)) || (@vehicle_type != :ship && $game_map.ship.pos_rect_nt?(x, y, collision_rect))
  603.   end
  604.   #--------------------------------------------------------------------------
  605.   # * Processing When Not Moving
  606.   #     last_moving : Was it moving previously?
  607.   #--------------------------------------------------------------------------
  608.   alias game_player_update_nonmoving_cxj_fm update_nonmoving
  609.   def update_nonmoving(last_moving)
  610.     game_player_update_nonmoving_cxj_fm(last_moving)
  611.     update_encounter if !last_moving && !@last_poll.empty?
  612.     @last_poll.clear
  613.   end
  614. end
  615. #==============================================================================
  616. # ** Game_Followers
  617. #------------------------------------------------------------------------------
  618. #  This is a wrapper for a follower array. This class is used internally for
  619. # the Game_Player class.
  620. #==============================================================================
  621.  
  622. class Game_Followers
  623.   #--------------------------------------------------------------------------
  624.   # * Detect Collision
  625.   #--------------------------------------------------------------------------
  626.   def collide_rect?(x, y, rect)
  627.     visible_folloers.any? {|follower| follower.pos_rect?(x, y, rect) }
  628.   end
  629.   #--------------------------------------------------------------------------
  630.   # * Movement
  631.   #--------------------------------------------------------------------------
  632.   def move
  633.     reverse_each {|follower| follower.board if gathering?; follower.chase_preceding_character }
  634.   end
  635. end
  636. #==============================================================================
  637. # ** Game_Vehicle
  638. #------------------------------------------------------------------------------
  639. #  This class handles vehicles. It's used within the Game_Map class. If there
  640. # are no vehicles on the current map, the coordinates are set to (-1,-1).
  641. #==============================================================================
  642.  
  643. class Game_Vehicle < Game_Character
  644.   #--------------------------------------------------------------------------
  645.   # * New: Collision Rectangle
  646.   #     Gets the collision rectangle.
  647.   #--------------------------------------------------------------------------
  648.   def collision_rect
  649.     collision = CXJ::FREE_MOVEMENT::DEFAULT_COLLISION
  650.     case @type
  651.     when :boat
  652.       collision = CXJ::FREE_MOVEMENT::BOAT_COLLISION
  653.     when :airship
  654.       collision = CXJ::FREE_MOVEMENT::AIRSHIP_COLLISION
  655.     end
  656.     return Rect.new(collision[0], collision[1], collision[2] - 1, collision[3] - 1)
  657.   end
  658.   #--------------------------------------------------------------------------
  659.   # * Determine if Docking/Landing Is Possible
  660.   #     d:  Direction (2,4,6,8)
  661.   #--------------------------------------------------------------------------
  662.   def land_ok?(x, y, d)
  663.     if @type == :airship
  664.       return false unless $game_map.airship_land_ok_rect?(x, y, collision_rect)
  665.       return false unless $game_map.events_xy_rect(x, y, collision_rect).empty?
  666.     else
  667.       x2 = $game_map.round_x_with_direction(x, d)
  668.       y2 = $game_map.round_y_with_direction(y, d)
  669.       return false unless $game_map.valid_rect?(x2, y2, collision_rect)
  670.       return false unless $game_map.passable_rect?(x2, y2, reverse_dir(d), collision_rect)
  671.       return false if collide_with_characters?(x2, y2)
  672.     end
  673.     return true
  674.   end
  675. end
  676.  
  677. #==============================================================================
  678. # ** Game_Event
  679. #------------------------------------------------------------------------------
  680. #  This class handles events. Functions include event page switching via
  681. # condition determinants and running parallel process events. Used within the
  682. # Game_Map class.
  683. #==============================================================================
  684.  
  685. class Game_Event < Game_Character
  686.   #--------------------------------------------------------------------------
  687.   # * Initialize Public Member Variables
  688.   #--------------------------------------------------------------------------
  689.   alias game_event_init_public_members_cxj_fm init_public_members
  690.   def init_public_members
  691.     game_event_init_public_members_cxj_fm
  692.     @collisionbox = Rect.new(0, 0, 31, 31)
  693.   end
  694.   #--------------------------------------------------------------------------
  695.   # * Initialize Public Member Variables
  696.   #--------------------------------------------------------------------------
  697.   def set_collision_rect(x, y, width, height)
  698.     @collisionbox = Rect.new(x, y, width - 1, height - 1)
  699.   end
  700.   #--------------------------------------------------------------------------
  701.   # * New: Collision Rectangle
  702.   #     Gets the collision rectangle.
  703.   #--------------------------------------------------------------------------
  704.   def collision_rect
  705.     return @collisionbox
  706.   end
  707.   #--------------------------------------------------------------------------
  708.   # * Override: Move Straight
  709.   #     d:        Direction (2,4,6,8)
  710.   #     turn_ok : Allows change of direction on the spot
  711.   #
  712.   # Polls the movement instead of processing them immediately.
  713.   #--------------------------------------------------------------------------
  714.   def move_straight(d, turn_ok = true)
  715.     @move_poll+= [[d, turn_ok]] * (rand(32 / CXJ::FREE_MOVEMENT::PIXELS_PER_STEP))
  716.   end
  717.   #--------------------------------------------------------------------------
  718.   # * Detect Collision with Player (Including Followers)
  719.   #--------------------------------------------------------------------------
  720.   def collide_with_player_characters?(x, y)
  721.     normal_priority? && $game_player.collide_rect?(x, y, collision_rect)
  722.   end
  723. end
  724. #==============================================================================
  725. # ** Game_Follower
  726. #------------------------------------------------------------------------------
  727. #  This class handles followers. A follower is an allied character, other than
  728. # the front character, displayed in the party. It is referenced within the
  729. # Game_Followers class.
  730. #==============================================================================
  731.  
  732. class Game_Follower < Game_Character
  733.   #--------------------------------------------------------------------------
  734.   # * Alias: Object Initialization
  735.   #--------------------------------------------------------------------------
  736.   alias game_follower_initialize_cxj_fm initialize
  737.   def initialize(member_index, preceding_character)
  738.     game_follower_initialize_cxj_fm(member_index, preceding_character)
  739.     @force_chase = false
  740.     @board = false
  741.   end
  742.   #--------------------------------------------------------------------------
  743.   # * Pursue Preceding Character
  744.   #--------------------------------------------------------------------------
  745.   def chase_preceding_character
  746.     unless moving? && !@force_chase
  747.       dist = CXJ::FREE_MOVEMENT::FOLLOWERS_DISTANCE / 32.0
  748.       mrgn = CXJ::FREE_MOVEMENT::FOLLOWERS_DISTANCE_MARGIN / 32.0
  749.       sx = distance_x_from(@preceding_character.x)
  750.       sy = distance_y_from(@preceding_character.y)
  751.       sd = Math.hypot(sx, sy)
  752.       if @board
  753.         @x = @preceding_character.x
  754.         @y = @preceding_character.y
  755.         @board = false
  756.       elsif(sd > dist && sx.abs > mrgn && sy.abs > mrgn)
  757.         @move_poll+=[[(sx > 0 ? -1 : 1) + (sy > 0 ? 8 : 2), true]]
  758.       elsif sx.abs > dist && sx.abs > sy.abs
  759.         @move_poll+=[[sx > 0 ? 4 : 6, true]]
  760.       elsif sy.abs > dist && sx.abs < sy.abs
  761.         @move_poll+=[[sy > 0 ? 8 : 2, true]]
  762.       end
  763.     end
  764.   end
  765.  
  766.   def distance_preceding_character
  767.     sx = distance_x_from(@preceding_character.x)
  768.     sy = distance_y_from(@preceding_character.y)
  769.     return Math.hypot(sx, sy)
  770.   end
  771.  
  772.   def process_move(horz, vert)
  773.     super(horz, vert)
  774.     dist = CXJ::FREE_MOVEMENT::FOLLOWERS_DISTANCE / 32.0
  775.     if distance_preceding_character > dist && @move_poll.size == 0
  776.       @force_chase = true
  777.       chase_preceding_character
  778.       @force_chase = false
  779.     end
  780.   end
  781.  
  782.   def board
  783.     @board = true
  784.   end
  785. end
  786.  
  787. #==============================================================================
  788. # ** Game_Interpreter
  789. #------------------------------------------------------------------------------
  790. #  An interpreter for executing event commands. This class is used within the
  791. # Game_Map, Game_Troop, and Game_Event classes.
  792. #==============================================================================
  793.  
  794. class Game_Interpreter
  795.   #--------------------------------------------------------------------------
  796.   # * Initialize Public Member Variables
  797.   #--------------------------------------------------------------------------
  798.   def set_collision_rect(x, y, width, height)
  799.     $game_map.events[@event_id].set_collision_rect(x, y, width, height)
  800.   end
  801. end
  802.  
  803. =begin
  804. class Spriteset_Map
  805.   #--------------------------------------------------------------------------
  806.   # * Object Initialization
  807.   #--------------------------------------------------------------------------
  808.   def initialize
  809.     create_viewports
  810.     create_tilemap
  811.     create_parallax
  812.     create_characters
  813.     create_shadow
  814.     create_weather
  815.     create_pictures
  816.     create_timer
  817.     @colbox = Sprite.new
  818.     @colbox.bitmap = Bitmap.new(96, 96)
  819.     update
  820.   end
  821.   #--------------------------------------------------------------------------
  822.   # * Frame Update
  823.   #--------------------------------------------------------------------------
  824.   def update
  825.     update_tileset
  826.     update_tilemap
  827.     update_parallax
  828.     update_characters
  829.     update_shadow
  830.     update_weather
  831.     update_pictures
  832.     update_timer
  833.     update_viewports
  834.     @colbox.x = $game_player.screen_x - 48
  835.     @colbox.y = $game_player.screen_y - 64
  836.     @colbox.bitmap.clear
  837.     @colbox.bitmap.fill_rect(0, 0, 96, 96, Color.new(0, 0, 0, 64))
  838.     cRec = $game_player.collision_rect.dup
  839.     iRec = $game_player.interaction_rect.dup
  840.     d = $game_player.direction
  841.     cRec.set(cRec.x + 32, cRec.y + 32, cRec.width, cRec.height)
  842.     @colbox.bitmap.fill_rect(cRec, Color.new(0, 255, 0, 128))
  843.     #iRec.set(iRec.x + 32, iRec.y + 32, iRec.width, iRec.height)
  844.     iRec.set(iRec.x + 32 + 32 * (d == 4 ? -1 : d == 6 ? 1 : 0), iRec.y + 32 + 32 * (d == 8 ? -1 : d == 2 ? 1 : 0), iRec.width, iRec.height)
  845.     #iRec.set(iRec.x + 48 + 32 * (d == 4 ? -1 : d == 6 ? 1 : 0), iRec.y + 64 + 32 * (d == 8 ? -1 : d == 2 ? 1 : 0), iRec.width, iRec.height)
  846.     @colbox.bitmap.fill_rect(iRec, Color.new(255, 0, 0, 128))
  847.   end
  848. end
  849. =end

批注 2025-08-07 155747.png (35.94 KB, 下载次数: 1)

批注 2025-08-07 155747.png
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

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

GMT+8, 2025-8-12 16:29

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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