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

Project1

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

[已经解决] 怎样让两个事件之间保持一定的距离,移动的时候一起移...

[复制链接]

Lv2.观梦者

梦石
0
星屑
552
在线时间
108 小时
注册时间
2012-9-30
帖子
102
跳转到指定楼层
1
发表于 2013-12-8 20:44:59 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 wgr273 于 2013-12-9 14:46 编辑

怎样让两个事件之间保持一定的距离,移动的时候一起移动?

Lv1.梦旅人

梦石
0
星屑
87
在线时间
303 小时
注册时间
2006-7-12
帖子
958
2
发表于 2013-12-9 14:36:27 | 只看该作者
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
552
在线时间
108 小时
注册时间
2012-9-30
帖子
102
3
 楼主| 发表于 2013-12-9 14:46:04 | 只看该作者
嫁衣 发表于 2013-12-9 14:36

我是要他们自动移动,不需要按按键哦!自动向左移动,自动向右移动!我已经自己解决了,只需要设置变量就可以了!谢谢你的回答!
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
147 小时
注册时间
2013-12-2
帖子
132
4
发表于 2013-12-9 16:22:58 | 只看该作者
或许你需要一个队友跟随的脚本
  1. # rgss-lib
  2. =begin

  3. DQシステムスクリプト Train_Actor
  4. Author:: yf30 at users.sourceforge.jp (http://sourceforge.jp/users/yf30/)
  5. Date:: 2009/02/26
  6. Copyright:: Copyright (C) 2004-2009 rgss-lib
  7. URL:: http://sourceforge.jp/projects/rgss-lib/

  8. =end
  9.          
  10. # dq
  11.          
  12. # train_actor
  13.          
  14. # Config.rb
  15. #==============================================================================
  16. # ■ Train_Actor::Config
  17. #------------------------------------------------------------------------------
  18. # マップ上でアクターを隊列移動させる
  19. #==============================================================================

  20. module Train_Actor

  21.   # ●透明状態用スイッチ設定
  22.   # true だとスイッチ制御を行う
  23.   #TRANSPARENT_SWITCH = true
  24.   TRANSPARENT_SWITCH = false

  25.   # ●透明状態用スイッチ番号
  26.   # TRANSPARENT_SWITCH が true で、この番号のスイッチがONだと透明になる
  27.   TRANSPARENT_SWITCHES_INDEX = 20

  28.   # ●アクターの最大数
  29.   # 将来的に多人数パーティが出来るようになったら…
  30.   TRAIN_ACTOR_SIZE_MAX = 4

  31.   # 死亡時のキャラクターグラフィック名
  32.   #DEAD_CHARACTER_NAME = "Coffin"
  33.   DEAD_CHARACTER_NAME = ""

  34.   # 定数
  35.   DOWN_LEFT  = 1
  36.   DOWN_RIGHT = 3
  37.   UP_LEFT    = 7
  38.   UP_RIGHT   = 9
  39.   JUMP       = 5
  40.   STOP       = 0

  41. end
  42.        
  43. # rgss
  44.          
  45. # Game_Event_Module.rb
  46. # Game_Event_Module
  47. # マップ上でアクターを隊列移動させる
  48. # Author:: fukuyama
  49. # Date:: 2006/03/05
  50. # Copyright:: Copyright (C) 2005 fukuyama

  51. module Train_Actor

  52.   module Game_Event_Module
  53.     # 通行可能判定
  54.     # x:: X 座標
  55.     # y:: Y 座標
  56.     # d:: 方向 (0,2,4,6,8)  ※ 0 = 全方向通行不可の場合を判定 (ジャンプ用)
  57.     # return:: 通行不可 false 可能 true
  58.     def passable?(x, y, d)
  59.       result = super(x, y, d)
  60.       return result if @through
  61.       if result
  62.         # 新しい座標を求める
  63.         new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  64.         new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  65.         # トレインアクターのループ
  66.         for actor in $game_party.characters
  67.           # 表示されている場合
  68.           if (not actor.character_name.empty?) and (not actor.transparent)
  69.             # アクターの座標が移動先と一致した場合
  70.             if actor.x == new_x and actor.y == new_y
  71.               # 自分がイベントの場合
  72.               if self != $game_player
  73.                 # 通行不可
  74.                 return false
  75.               end
  76.             end
  77.           end
  78.         end
  79.       end
  80.       return result
  81.     end
  82.   end

  83. end

  84. class Game_Event
  85.   include Train_Actor::Game_Event_Module
  86. end

  87. # Game_Party_Module.rb
  88. # Train_Actor::Game_Party_Module
  89. # Game_Party用隊列歩行モジュール
  90. # Author:: fukuyama
  91. # Date:: 2007/12/31
  92. # Copyright:: Copyright (C) 2005-2007 rgss-lib

  93. module Train_Actor

  94.   module Game_Party_Module
  95.     attr_reader :characters
  96.     def dead_actor_include?
  97.       for actor in actors
  98.         if actor.dead?
  99.           return true
  100.         end
  101.       end
  102.       return false
  103.     end
  104.     def get_active_party_order
  105.       if not dead_actor_include?
  106.         return actors
  107.       end
  108.       alive_actors = []
  109.       dead_actors = []
  110.       for actor in actors
  111.         if actor.dead?
  112.           dead_actors.push actor
  113.         else
  114.           alive_actors.push actor
  115.         end
  116.       end
  117.       return alive_actors + dead_actors
  118.     end
  119.     def setup_actor_character_sprites
  120.       if @characters.nil?
  121.         @characters = []
  122.         for i in 1 ... TRAIN_ACTOR_SIZE_MAX
  123.           @characters.push(Game_Party_Actor.new(i - 1))
  124.         end
  125.       end
  126.       setup_actors = get_active_party_order
  127.       for i in 1 .. @characters.size
  128.         @characters[i - 1].setup(setup_actors[i])
  129.       end
  130.       if $scene.class.method_defined?('setup_actor_character_sprites')
  131.         $scene.setup_actor_character_sprites
  132.       end
  133.     end
  134.     def transparent_switch
  135.       if TRANSPARENT_SWITCH
  136.         unless $game_player.transparent
  137.           return $game_switches[TRANSPARENT_SWITCHES_INDEX]
  138.         end
  139.       end
  140.       return $game_player.transparent
  141.     end
  142.     def update_party_actors
  143.       setup_actor_character_sprites
  144.       transparent = transparent_switch
  145.       for character in @characters
  146.         character.transparent = transparent
  147.         character.update
  148.       end
  149.     end
  150.    
  151.     #cob
  152.     def moveto_party_actors( x, y )
  153.       setup_actor_character_sprites
  154.       @move_list = []
  155.       move_list_setup      
  156.       follow = true
  157.       for character in @characters
  158.         if follow
  159.           if $game_player.passable?(x, y, 10 - $game_player.direction)
  160.             case $game_player.direction
  161.             when 2
  162.               y -= 1
  163.               add_move_list(Input::DOWN)
  164.             when 4
  165.               x += 1
  166.               add_move_list(Input::LEFT)
  167.             when 6
  168.               x -= 1
  169.               add_move_list(Input::RIGHT)
  170.             when 8
  171.               y += 1
  172.               add_move_list(Input::UP)
  173.             end            
  174.           else
  175.             follow = false
  176.           end
  177.         end
  178.         character.moveto(x, y)
  179.       end
  180.     end
  181.    
  182.     def move_party_actors
  183.       if @move_list == nil
  184.         @move_list = []
  185.         move_list_setup
  186.       end
  187.       @move_list.each_index do |i|
  188.         if not @characters[i].nil?
  189.           @characters[i].add_move_list_element(@move_list[i])
  190.         end
  191.       end
  192.     end
  193.    
  194.     #cob
  195.     def turn_left_party_actors
  196.       for character in @characters
  197.         character.turn_left
  198.       end      
  199.     end
  200.    
  201.     def initialize_location
  202.       for character in @characters
  203.         character.moveto($game_player.x, $game_player.y - 1)
  204.         character.turn_down
  205.       end      
  206.     end
  207.    
  208.     class Move_List_Element
  209.       def initialize(type,args)
  210.         @type = type
  211.         @args = args
  212.       end
  213.       def type() return @type end
  214.       def args() return @args end
  215.     end
  216.     def move_list_setup
  217.       for i in 0 .. TRAIN_ACTOR_SIZE_MAX
  218.         @move_list[i] = nil
  219.       end
  220.     end
  221.     def add_move_list(type,*args)
  222.       @move_list.unshift(Move_List_Element.new(type,args)).pop
  223.     end
  224.     def move_down_party_actors(turn_enabled = true)
  225.       move_party_actors
  226.       add_move_list(Input::DOWN,turn_enabled)
  227.     end
  228.     def move_left_party_actors(turn_enabled = true)
  229.       move_party_actors
  230.       add_move_list(Input::LEFT,turn_enabled)
  231.     end
  232.     def move_right_party_actors(turn_enabled = true)
  233.       move_party_actors
  234.       add_move_list(Input::RIGHT,turn_enabled)
  235.     end
  236.     def move_up_party_actors(turn_enabled = true)
  237.       move_party_actors
  238.       add_move_list(Input::UP,turn_enabled)
  239.     end
  240.     def move_lower_left_party_actors
  241.       move_party_actors
  242.       add_move_list(DOWN_LEFT)
  243.     end
  244.     def move_lower_right_party_actors
  245.       move_party_actors
  246.       add_move_list(DOWN_RIGHT)
  247.     end
  248.     def move_upper_left_party_actors
  249.       move_party_actors
  250.       add_move_list(UP_LEFT)
  251.     end
  252.     def move_upper_right_party_actors
  253.       move_party_actors
  254.       add_move_list(UP_RIGHT)
  255.     end
  256.     def jump_party_actors(x_plus, y_plus)
  257.       move_party_actors
  258.       add_move_list(JUMP,x_plus, y_plus)
  259.       move_stop_party_actors
  260.     end
  261.     def move_stop_party_actors
  262.       actors.each do |a|
  263.         move_party_actors
  264.         add_move_list(STOP)
  265.       end
  266.     end
  267.   end

  268. end

  269. class Game_Party
  270.   include Train_Actor::Game_Party_Module

  271.   # アクターを加える
  272.   # actor_id:: アクター ID
  273.   def add_actor(actor_id)
  274.     # アクターを取得
  275.     actor = $game_actors[actor_id]
  276.     # パーティ人数が 4 人未満で、このアクターがパーティにいない場合
  277.     if @actors.size < Train_Actor::TRAIN_ACTOR_SIZE_MAX and not @actors.include?(actor)
  278.       # アクターを追加
  279.       @actors.push(actor)
  280.       # プレイヤーをリフレッシュ
  281.       $game_player.refresh
  282.     end
  283.   end
  284. end

  285. # Game_Player_Module.rb
  286. # Train_Actor::Game_Player_Module
  287. # Game_Player用隊列歩行モジュール
  288. # Author:: fukuyama
  289. # Date:: 2007/12/31
  290. # Copyright:: Copyright (C) 2005-2007 rgss-lib

  291. module Train_Actor

  292.   module Game_Player_Module
  293.     attr_reader :move_speed
  294.     attr_reader :step_anime
  295.     attr_reader :direction_fix

  296.     def update_party_actors
  297.       if $game_party.actors.empty?
  298.         return
  299.       end
  300.       $game_party.update_party_actors
  301.       actor = $game_party.actors[0]
  302.       if not actor.dead?
  303.         if not @prev_dead.nil?
  304.           @character_name = actor.character_name
  305.           @character_hue = actor.character_hue
  306.           @prev_dead = nil
  307.         end
  308.         return
  309.       end
  310.       @prev_dead = true
  311.       $game_party.actors.each do |actor|
  312.         if not actor.dead?
  313.           @character_name = actor.character_name
  314.           @character_hue = actor.character_hue
  315.           break
  316.         end
  317.       end
  318.     end
  319.     def update
  320.       update_party_actors
  321.       super
  322.     end
  323.     def moveto( x, y )
  324.       $game_party.moveto_party_actors( x, y )
  325.       super( x, y )
  326.     end
  327.     def move_down(turn_enabled = true)
  328.       if passable?(@x, @y, Input::DOWN)
  329.         $game_party.move_down_party_actors(turn_enabled)
  330.       end
  331.       super(turn_enabled)
  332.     end
  333.     def move_left(turn_enabled = true)
  334.       if passable?(@x, @y, Input::LEFT)
  335.         $game_party.move_left_party_actors(turn_enabled)
  336.       end
  337.       super(turn_enabled)
  338.     end
  339.     def move_right(turn_enabled = true)
  340.       if passable?(@x, @y, Input::RIGHT)
  341.         $game_party.move_right_party_actors(turn_enabled)
  342.       end
  343.       super(turn_enabled)
  344.     end
  345.     def move_up(turn_enabled = true)
  346.       if passable?(@x, @y, Input::UP)
  347.         $game_party.move_up_party_actors(turn_enabled)
  348.       end
  349.       super(turn_enabled)
  350.     end
  351.     def move_lower_left
  352.       # 下→左、左→下 のどちらかのコースが通行可能な場合
  353.       if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT)) or
  354.        (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN))
  355.         $game_party.move_lower_left_party_actors
  356.       end
  357.       super
  358.     end
  359.     def move_lower_right
  360.       # 下→右、右→下 のどちらかのコースが通行可能な場合
  361.       if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT)) or
  362.        (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN))
  363.         $game_party.move_lower_right_party_actors
  364.       end
  365.       super
  366.     end
  367.     def move_upper_left
  368.       # 上→左、左→上 のどちらかのコースが通行可能な場合
  369.       if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT)) or
  370.        (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP))
  371.         $game_party.move_upper_left_party_actors
  372.       end
  373.       super
  374.     end
  375.     def move_upper_right
  376.       # 上→右、右→上 のどちらかのコースが通行可能な場合
  377.       if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT)) or
  378.        (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP))
  379.         $game_party.move_upper_right_party_actors
  380.       end
  381.       super
  382.     end
  383.     def jump(x_plus, y_plus)
  384.       # 新しい座標を計算
  385.       new_x = @x + x_plus
  386.       new_y = @y + y_plus
  387.       # 加算値が (0,0) の場合か、ジャンプ先が通行可能な場合
  388.       if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
  389.         $game_party.jump_party_actors(x_plus, y_plus)
  390.       end
  391.       super(x_plus, y_plus)
  392.     end
  393.   end

  394. end

  395. class Game_Player
  396.   include Train_Actor::Game_Player_Module
  397. end

  398. # Scene_Map_Module.rb
  399. # Train_Actor::Scene_Map_Module
  400. # Scene_Map用隊列歩行モジュール
  401. # Author:: fukuyama
  402. # Date:: 2007/12/31
  403. # Copyright:: Copyright (C) 2005-2007 rgss-lib

  404. module Train_Actor

  405.   module Scene_Map_Module
  406.     def setup_actor_character_sprites
  407.       @spriteset.setup_actor_character_sprites
  408.     end
  409.   end

  410. end

  411. class Scene_Map
  412.   include Train_Actor::Scene_Map_Module
  413. end

  414. # Spriteset_Map_Module.rb
  415. # Train_Actor::Spriteset_Map_Module
  416. # Spriteset_Map用隊列歩行モジュール
  417. # Author:: fukuyama
  418. # Date:: 2007/12/31
  419. # Copyright:: Copyright (C) 2005-2007 rgss-lib

  420. module Train_Actor

  421.   module Spriteset_Map_Module
  422.     def setup_actor_character_sprites?
  423.       return @setup_actor_character_sprites_flag != nil
  424.     end
  425.    
  426.     #cob
  427.     def setup_actor_character_sprites
  428.       return unless $game_party.characters
  429.       if not setup_actor_character_sprites?
  430.         for character in $game_party.characters.reverse
  431.           @character_sprites.unshift(Sprite_Character.new(@viewport1, character))
  432.         end
  433.         @setup_actor_character_sprites_flag = true
  434.       end
  435.     end
  436.   end

  437. end

  438. class Spriteset_Map
  439.   include Train_Actor::Spriteset_Map_Module
  440. end
  441.   
  442. # Game_Party_Actor.rb
  443. # Train_Actor::Game_Party_Actor
  444. # マップ上のパーティ用キャラクター
  445. # Author:: fukuyama
  446. # Date:: 2007/12/31
  447. # Copyright:: Copyright (C) 2005-2007 rgss-lib

  448. module Train_Actor

  449.   class Game_Party_Actor < Game_Character
  450.     def initialize(character_index)
  451.       super()
  452.       @character_index = character_index
  453.       @character_wait = 0
  454.       @through = true
  455.       # 不透明度と合成方法を初期化
  456.       [url=home.php?mod=space&uid=316553]@opacity[/url] = 255
  457.       @blend_type = 0
  458.       @move_list = []
  459.     end
  460.     def setup(actor)
  461.       # キャラクターのファイル名と色相を設定
  462.       if actor.nil?
  463.         @character_name = ""
  464.         @character_hue = 0
  465.       elsif not actor.dead? # 死んでる場合とりあえず、消しとこ…
  466.         @character_name = actor.character_name
  467.         @character_hue = actor.character_hue
  468.       else
  469.         @character_name = DEAD_CHARACTER_NAME
  470.         @character_hue = 0
  471.       end
  472.     end
  473.     def update
  474.       @move_speed = $game_player.move_speed
  475.       @step_anime = $game_player.step_anime
  476.       @opacity = $game_player.opacity
  477.       @blend_type = $game_player.blend_type
  478.       @direction_fix = $game_player.direction_fix
  479.       if @direction_fix
  480.         @direction = $game_player.direction
  481.       end
  482.       update_move_list()
  483.       super
  484.     end
  485.     def screen_z(height = 0)
  486.       if $game_player.screen_z(height) == 999
  487.         return 998
  488.       end
  489.       if $game_player.x == @x and $game_player.y == @y
  490.         super(height) - 1
  491.       else
  492.         super(height)
  493.       end
  494.     end
  495.     def add_move_list_element(element)
  496.       @move_list.push(element)
  497.       if @move_list.size == 1
  498.         update_move_list()
  499.       end
  500.     end
  501.     def move_list_size
  502.       return @move_list.size
  503.     end
  504.     def update_move_list()
  505.       return if moving?
  506.       
  507.       if @move_list.empty?
  508.         @direction = $game_player.direction unless @direction_fix
  509.         return
  510.       end
  511.       
  512.       return if @move_list.empty?
  513.       if @move_list[0].type == STOP
  514.         if @character_index != 0
  515.           character = $game_party.characters[@character_index - 1]
  516.           if character.x == @x and character.y == @y and character.direction == @direction
  517.             @character_wait = 128 / (2 ** @move_speed) + 1
  518.             while character.move_list_size < @move_list.size and @move_list[0].type == STOP
  519.               @move_list.shift
  520.             end
  521.           end
  522.         end
  523.       else
  524.         @character_wait = 0
  525.       end
  526.       if @character_wait > 0
  527.         @character_wait -= 1
  528.         return
  529.       end
  530.       element = @move_list.shift
  531.       while element.type == STOP
  532.         element = @move_list.shift
  533.       end
  534.       case element.type
  535.       when Input::DOWN
  536.         move_down(element.args[0])
  537.       when Input::LEFT
  538.         move_left(element.args[0])
  539.       when Input::RIGHT
  540.         move_right(element.args[0])
  541.       when Input::UP
  542.         move_up(element.args[0])
  543.       when DOWN_LEFT
  544.         move_lower_left
  545.       when DOWN_RIGHT
  546.         move_lower_right
  547.       when UP_LEFT
  548.         move_upper_left
  549.       when UP_RIGHT
  550.         move_upper_right
  551.       when JUMP
  552.         jump(element.args[0],element.args[1])
  553.       end
  554.     end
  555.    
  556.     #cob
  557.     def moveto( x, y )
  558.       @move_list.clear
  559.       straighten
  560.       @direction = $game_player.direction
  561.       super(x, y)
  562.     end
  563.    
  564.     #--------------------------------------------------------------------------
  565.     # ● 下に移動
  566.     #     turn_enabled : その場での向き変更を許可するフラグ
  567.     #--------------------------------------------------------------------------
  568.     def move_down(turn_enabled = true)
  569.       # 下を向く
  570.       if turn_enabled
  571.         turn_down
  572.       end
  573.       # 通行可能な場合
  574.       if passable?(@x, @y, Input::DOWN)
  575.         # 下を向く
  576.         turn_down
  577.         # 座標を更新
  578.         @y = (@y + 1 + $game_map.height) % ($game_map.height)
  579.         @real_y = (@y - 1) * 128
  580.       end
  581.     end
  582.     #--------------------------------------------------------------------------
  583.     # ● 左に移動
  584.     #     turn_enabled : その場での向き変更を許可するフラグ
  585.     #--------------------------------------------------------------------------
  586.     def move_left(turn_enabled = true)
  587.       # 左を向く
  588.       if turn_enabled
  589.         turn_left
  590.       end
  591.       # 通行可能な場合
  592.       if passable?(@x, @y, Input::LEFT)
  593.         # 左を向く
  594.         turn_left
  595.         # 座標を更新
  596.         @x = (@x - 1 + $game_map.width) % ($game_map.width)
  597.         @real_x = (@x + 1) * 128
  598.       end
  599.     end
  600.     #--------------------------------------------------------------------------
  601.     # ● 右に移動
  602.     #     turn_enabled : その場での向き変更を許可するフラグ
  603.     #--------------------------------------------------------------------------
  604.     def move_right(turn_enabled = true)
  605.       # 右を向く
  606.       if turn_enabled
  607.         turn_right
  608.       end
  609.       # 通行可能な場合
  610.       if passable?(@x, @y, Input::RIGHT)
  611.         # 右を向く
  612.         turn_right
  613.         # 座標を更新
  614.         @x = (@x + 1 + $game_map.width) % ($game_map.width)
  615.         @real_x = (@x - 1) * 128
  616.       end
  617.     end
  618.     #--------------------------------------------------------------------------
  619.     # ● 上に移動
  620.     #     turn_enabled : その場での向き変更を許可するフラグ
  621.     #--------------------------------------------------------------------------
  622.     def move_up(turn_enabled = true)
  623.       # 上を向く
  624.       if turn_enabled
  625.         turn_up
  626.       end
  627.       # 通行可能な場合
  628.       if passable?(@x, @y, Input::UP)
  629.         # 上を向く
  630.         turn_up
  631.         # 座標を更新
  632.         @y = (@y - 1 + $game_map.height) % ($game_map.height)
  633.         @real_y = (@y + 1) * 128
  634.       end
  635.     end
  636.   end

  637. end
  638.    
复制代码

点评

队友跟随脚本,我已经有了哦!非常你!  发表于 2013-12-9 16:30
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-25 19:17

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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