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

Project1

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

[已经过期] 类似勇者斗恶龙的那种跟随者移动实现

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
148 小时
注册时间
2012-7-2
帖子
157
跳转到指定楼层
1
发表于 2012-7-9 11:26:40 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 limaolinghu 于 2012-7-9 11:29 编辑

实现一个经典的勇者斗恶龙里面,角色队伍都显示在地图上,并且跟随主角移动。
我用创建事件和控制事件实现了一个,不知道有没有什么问题,或者有没有更好的方式,请大家帮忙看看

untitled.JPG (40.39 KB, 下载次数: 17)

untitled.JPG

点评

请楼主尽快结帖  发表于 2012-7-24 09:40

Lv1.梦旅人

梦石
0
星屑
50
在线时间
148 小时
注册时间
2012-7-2
帖子
157
2
 楼主| 发表于 2012-7-9 11:30:05 | 只看该作者
本帖最后由 limaolinghu 于 2012-7-9 11:32 编辑

  #--------------------------------------------------------------------------
  # ● 设置事件
  #--------------------------------------------------------------------------
  def setup_events
    @events = {}          # 地图事件
   
    event_index = 0
    for event_index in @map.events.keys
      @events[event_index] = Game_Event.new(@map_id, @map.events[event_index])
    end

    # 在Game_Map的setup_events里面创建5个跟随者,图片这里是随便写的,可以替换为真正的主角行走图
    fellow_event1 = RPG::Event.new(5, 10)
    fellow_event1.name = "fellow1"
    fellow_event1.pages[0].graphic.character_name = "Evil"
    fellow_event1.pages[0].graphic.character_index = 1
    fellow_event1.pages[0].move_speed = 4
    fellow_event1.pages[0].through = 1
   
    fellow_event2 = RPG::Event.new(5, 10)
    fellow_event2.name = "fellow2"
    fellow_event2.pages[0].graphic.character_name = "Evil"
    fellow_event2.pages[0].graphic.character_index = 2
    fellow_event2.pages[0].move_speed = 4
    fellow_event2.pages[0].through = 1
   
    fellow_event3 = RPG::Event.new(5, 10)
    fellow_event3.name = "fellow3"
    fellow_event3.pages[0].graphic.character_name = "Evil"
    fellow_event3.pages[0].graphic.character_index = 3
    fellow_event3.pages[0].move_speed = 4
    fellow_event3.pages[0].through = 1
   
    fellow_event4 = RPG::Event.new(5, 10)
    fellow_event4.name = "fellow4"
    fellow_event4.pages[0].graphic.character_name = "Evil"
    fellow_event4.pages[0].graphic.character_index = 4
    fellow_event4.pages[0].move_speed = 4
    fellow_event4.pages[0].through = 1
   
    fellow_event5 = RPG::Event.new(5, 10)
    fellow_event5.name = "fellow5"
    fellow_event5.pages[0].graphic.character_name = "Evil"
    fellow_event5.pages[0].graphic.character_index = 5
    fellow_event5.pages[0].move_speed = 4
    fellow_event5.pages[0].through = 1
   
    #将者5个跟随者事件,添加到当前地图事件列表中
    @events[event_index+=1] = Game_Event.new(@map_id, fellow_event1)
    @events[event_index+=1] = Game_Event.new(@map_id, fellow_event2)
    @events[event_index+=1] = Game_Event.new(@map_id, fellow_event3)
    @events[event_index+=1] = Game_Event.new(@map_id, fellow_event4)
    @events[event_index+=1] = Game_Event.new(@map_id, fellow_event5)
   
   
    @common_events = {}   # 公共事件
    for i in 1...$data_common_events.size
      @common_events = Game_CommonEvent.new(i)
    end
  end


在Game_Player里面:
  #--------------------------------------------------------------------------
  # ● 方向键移动处理
  #--------------------------------------------------------------------------
  def move_by_input
    return unless movable?
    return if $game_map.interpreter.running?
   
    #loop当前地图所有事件,如果存在跟随者,则记录该跟随者的先驱对象
    #其中,第一个跟随者的先驱是主角,其他跟随者则跟随前一个跟随者
    for i in $game_map.events.keys.sort
      if $game_map.events.event.name == "fellow1"
        @before_move_locations["fellow1"] = self.clone
        fellow1_index = i
      elsif $game_map.events.event.name == "fellow2"
        @before_move_locations["fellow2"] = $game_map.events[fellow1_index].clone
        fellow2_index = i
      elsif $game_map.events.event.name == "fellow3"
        @before_move_locations["fellow3"] = $game_map.events[fellow2_index].clone
        fellow3_index = i      
      elsif $game_map.events.event.name == "fellow4"
        @before_move_locations["fellow4"] = $game_map.events[fellow3_index].clone
        fellow4_index = i            
      elsif $game_map.events.event.name == "fellow5"
         @before_move_locations["fellow5"] = $game_map.events[fellow4_index].clone
        fellow5_index = i               
      end
    end
   
    #记录一个是否真正移动过得变量
    moved = true
    case Input.dir4
    when 2;  move_down
    when 4;  move_left
    when 6;  move_right
    when 8;  move_up
    else
      moved = false
    end

    #如果地图事件中有跟随者,并且主角确实移动过,则让跟随者朝着先驱的方向移动
    fellows = ["fellow1", "fellow2", "fellow3", "fellow4", "fellow5"]
    for event in $game_map.events.values
      if fellows.include?(event.event.name) and moved
        event.follow_preemptor
      end
    end
  end

Game_Event里面添加一个简单的函数,来跟随先驱:
  #--------------------------------------------------------------------------
  # ● 跟随前者
  #--------------------------------------------------------------------------
  def follow_preemptor
   if @x < $game_player.before_move_locations[@event.name].x
      move_right
    elsif @x > $game_player.before_move_locations[@event.name].x
      move_left
    elsif @y > $game_player.before_move_locations[@event.name].y
      move_up
    elsif @y < $game_player.before_move_locations[@event.name].y
      move_down
    end   
  end
end
���
回复

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1409
在线时间
962 小时
注册时间
2012-4-30
帖子
1475

开拓者

3
发表于 2012-7-21 22:08:46 | 只看该作者
我跟你说有脚本哦
  1. class Game_Player
  2.   #--------------------------------------------------------------------------
  3.   # * Move Down
  4.   #     turn_enabled : a flag permits direction change on that spot
  5.   #--------------------------------------------------------------------------
  6.   def move_down(turn_enabled = true)   
  7.     super(turn_enabled)
  8.   end
  9.   #--------------------------------------------------------------------------
  10.   # * Move Left
  11.   #     turn_enabled : a flag permits direction change on that spot
  12.   #--------------------------------------------------------------------------
  13.   def move_left(turn_enabled = true)
  14.     super(turn_enabled)
  15.   end
  16.   #--------------------------------------------------------------------------
  17.   # * Move Right
  18.   #     turn_enabled : a flag permits direction change on that spot
  19.   #--------------------------------------------------------------------------
  20.   def move_right(turn_enabled = true)
  21.     super(turn_enabled)
  22.   end
  23.   #--------------------------------------------------------------------------
  24.   # * Move up
  25.   #     turn_enabled : a flag permits direction change on that spot
  26.   #--------------------------------------------------------------------------
  27.   def move_up(turn_enabled = true)
  28.     super(turn_enabled)
  29.   end
  30.   #--------------------------------------------------------------------------
  31.   # * Move Lower Left
  32.   #--------------------------------------------------------------------------
  33.   def move_lower_left
  34.     super
  35.   end
  36.   #--------------------------------------------------------------------------
  37.   # * Move Lower Right
  38.   #--------------------------------------------------------------------------
  39.   def move_lower_right
  40.     super
  41.   end
  42.   #--------------------------------------------------------------------------
  43.   # * Move Upper Left
  44.   #--------------------------------------------------------------------------
  45.   def move_upper_left
  46.     super
  47.   end
  48.   #--------------------------------------------------------------------------
  49.   # * Move Upper Right
  50.   #--------------------------------------------------------------------------
  51.   def move_upper_right
  52.     super
  53.   end
  54. end

  55. class Game_Follower < Game_Character
  56.   #--------------------------------------------------------------------------
  57.   # * Public Instance Variables
  58.   #--------------------------------------------------------------------------
  59.   attr_reader   :actor
  60.   attr_accessor :move_speed
  61.   #--------------------------------------------------------------------------
  62.   # * Object Initialization
  63.   #--------------------------------------------------------------------------
  64.   def initialize(actor)
  65.     super()
  66.     @through = true
  67.     @actor = actor
  68.   end
  69.   #--------------------------------------------------------------------------
  70.   # * Set Actor
  71.   #--------------------------------------------------------------------------
  72.   def actor=(actor)
  73.     @actor = actor
  74.     setup
  75.   end
  76.   #--------------------------------------------------------------------------
  77.   # * Setup
  78.   #--------------------------------------------------------------------------
  79.   def setup
  80.     if @actor != nil      
  81.       @character_name = $game_actors[@actor].character_name
  82.       @character_index = $game_actors[@actor].character_index
  83.     else
  84.       @character_name = ""
  85.       @character_index = 0
  86.     end
  87.     @opacity = 255
  88.     @blend_type = 0
  89.     @priority_type = 0
  90.   end
  91.   
  92.   #--------------------------------------------------------------------------
  93.   # * Screen Z
  94.   #--------------------------------------------------------------------------
  95.   def screen_z
  96.     if $game_player.x == @x and $game_player.y == @y
  97.       return $game_player.screen_z - 1
  98.     end
  99.     super
  100.   end
  101.   #--------------------------------------------------------------------------
  102.   # * Same Position Starting Determinant (Disabled)
  103.   #--------------------------------------------------------------------------
  104.   def check_event_trigger_here(triggers)
  105.     result = false
  106.     return result
  107.   end
  108.   #--------------------------------------------------------------------------
  109.   # * Front Envent Starting Determinant (Disabled)
  110.   #--------------------------------------------------------------------------
  111.   def check_event_trigger_there(triggers)
  112.     result = false
  113.     return result
  114.   end
  115.   #--------------------------------------------------------------------------
  116.   # * Touch Event Starting Determinant (Disabled)
  117.   #--------------------------------------------------------------------------
  118.   def check_event_trigger_touch(x, y)
  119.     result = false
  120.     return result
  121.   end
  122. end

  123. class Spriteset_Map
  124.   alias_method :spriteset_map_create_characters, :create_characters
  125.   def create_characters
  126.     spriteset_map_create_characters
  127.     $game_party.followers.each do |char|
  128.       @character_sprites << Sprite_Character.new(@viewport1, char)
  129.     end
  130.   end
  131. end

  132. class Game_Party
  133.   #--------------------------------------------------------------------------
  134.   # * Constants
  135.   #--------------------------------------------------------------------------
  136.   MAX_SIZE = 8
  137.   CATERPILLAR = 2
  138.   #--------------------------------------------------------------------------
  139.   # * Public Instance Variables
  140.   #--------------------------------------------------------------------------
  141.   attr_reader :followers
  142.   #--------------------------------------------------------------------------
  143.   # * Object Initialization
  144.   #--------------------------------------------------------------------------
  145.   alias_method :trick_caterpillar_party_initialize, :initialize
  146.   def initialize
  147.     trick_caterpillar_party_initialize
  148.     @followers = Array.new(MAX_SIZE - 1) {Game_Follower.new(nil)}
  149.     @move_list = []
  150.   end
  151.   #--------------------------------------------------------------------------
  152.   # * Update Followers
  153.   #--------------------------------------------------------------------------
  154.   def update_followers
  155.     flag = $game_player.transparent || $game_switches[CATERPILLAR]
  156.     @followers.each_with_index do |char, i|
  157.       char.actor = @actors[i + 1]
  158.       char.move_speed = $game_player.move_speed
  159.       if $game_player.dash?
  160.         char.move_speed += 1
  161.       end
  162.       char.update
  163.       char.transparent = flag
  164.     end
  165.   end
  166.   #--------------------------------------------------------------------------
  167.   # * Move To Party
  168.   #--------------------------------------------------------------------------
  169.   def moveto_party(x, y)
  170.     @followers.each {|char| char.moveto(x, y)}
  171.     @move_list.clear
  172.   end
  173.   #--------------------------------------------------------------------------
  174.   # * Move Party
  175.   #--------------------------------------------------------------------------
  176.   def move_party
  177.     @move_list.each_index do |i|
  178.       if @followers[i] == nil
  179.         @move_list[i...@move_list.size] = nil
  180.         next
  181.       end
  182.       case @move_list[i].type
  183.       when 2
  184.         @followers[i].move_down(*@move_list[i].args)
  185.       when 4
  186.         @followers[i].move_left(*@move_list[i].args)
  187.       when 6
  188.         @followers[i].move_right(*@move_list[i].args)
  189.       when 8
  190.         @followers[i].move_up(*@move_list[i].args)
  191.       when 1
  192.         @followers[i].move_lower_left
  193.       when 3
  194.         @followers[i].move_lower_right
  195.       when 7
  196.         @followers[i].move_upper_left
  197.       when 9
  198.         @followers[i].move_upper_right
  199.       when 5
  200.         @followers[i].jump(*@move_list[i].args)
  201.       end
  202.     end
  203.   end
  204.   #--------------------------------------------------------------------------
  205.   # * Add Move List
  206.   #--------------------------------------------------------------------------
  207.   def update_move(type, *args)
  208.     move_party
  209.     @move_list.unshift(Game_MoveListElement.new(type, args))
  210.   end
  211. end

  212. class Game_MoveListElement
  213.   #--------------------------------------------------------------------------
  214.   # * Object Initialization
  215.   #--------------------------------------------------------------------------
  216.   def initialize(type, args)
  217.     @type = type
  218.     @args = args
  219.   end
  220.   #--------------------------------------------------------------------------
  221.   # * Type
  222.   #--------------------------------------------------------------------------
  223.   def type
  224.     return @type
  225.   end
  226.   #--------------------------------------------------------------------------
  227.   # * Args
  228.   #--------------------------------------------------------------------------
  229.   def args
  230.     return @args
  231.   end
  232. end

  233. class Game_Player
  234.   #--------------------------------------------------------------------------
  235.   # * Public Instance Variables
  236.   #--------------------------------------------------------------------------
  237.   attr_reader :move_speed
  238.   
  239.   #--------------------------------------------------------------------------
  240.   # * Update
  241.   #--------------------------------------------------------------------------
  242.   alias_method :trick_caterpillar_player_update, :update
  243.   def update
  244.     $game_party.update_followers
  245.     trick_caterpillar_player_update
  246.   end
  247.   #--------------------------------------------------------------------------
  248.   # * Moveto
  249.   #--------------------------------------------------------------------------
  250.   alias_method :trick_caterpillar_player_moveto, :moveto
  251.   def moveto(x, y)
  252.     $game_party.moveto_party(x, y)
  253.     trick_caterpillar_player_moveto(x, y)
  254.   end
  255.   #--------------------------------------------------------------------------
  256.   # * Move Down
  257.   #--------------------------------------------------------------------------
  258.   alias_method :trick_caterpillar_player_move_down, :move_down
  259.   def move_down(turn_enabled = true)
  260.     if passable?(@x, @y+1)
  261.       $game_party.update_move(2, turn_enabled)
  262.     end   
  263.     trick_caterpillar_player_move_down(turn_enabled)   
  264.   end
  265.   #--------------------------------------------------------------------------
  266.   # * Move Left
  267.   #--------------------------------------------------------------------------
  268.   alias_method :trick_caterpillar_player_move_left, :move_left
  269.   def move_left(turn_enabled = true)
  270.     if passable?(@x-1, @y)
  271.       $game_party.update_move(4, turn_enabled)
  272.     end
  273.     trick_caterpillar_player_move_left(turn_enabled)
  274.   end
  275.   #--------------------------------------------------------------------------
  276.   # * Move Right
  277.   #--------------------------------------------------------------------------
  278.   alias_method :trick_caterpillar_player_move_right, :move_right
  279.   def move_right(turn_enabled = true)
  280.     if passable?(@x+1, @y)
  281.       $game_party.update_move(6, turn_enabled)
  282.     end
  283.     trick_caterpillar_player_move_right(turn_enabled)
  284.   end
  285.   #--------------------------------------------------------------------------
  286.   # * Move Up
  287.   #--------------------------------------------------------------------------
  288.   alias_method :trick_caterpillar_player_move_up, :move_up
  289.   def move_up(turn_enabled = true)
  290.     if passable?(@x, @y-1)
  291.       $game_party.update_move(8, turn_enabled)
  292.     end
  293.     trick_caterpillar_player_move_up(turn_enabled)
  294.   end
  295.   #--------------------------------------------------------------------------
  296.   # * Move Lower Left
  297.   #--------------------------------------------------------------------------
  298.   alias_method :trick_caterpillar_player_move_lower_left, :move_lower_left
  299.   def move_lower_left
  300.     if passable?(@x - 1, @y) and passable?(@x, @y + 1)
  301.       $game_party.update_move(1)
  302.     end
  303.     trick_caterpillar_player_move_lower_left
  304.   end
  305.   #--------------------------------------------------------------------------
  306.   # * Move Lower Right
  307.   #--------------------------------------------------------------------------
  308.   alias_method :trick_caterpillar_player_move_lower_right, :move_lower_right
  309.   def move_lower_right
  310.     if passable?(@x + 1, @y) and passable?(@x, @y + 1)
  311.       $game_party.update_move(3)
  312.     end
  313.     trick_caterpillar_player_move_lower_right
  314.   end
  315.   #--------------------------------------------------------------------------
  316.   # * Move Upper Left
  317.   #--------------------------------------------------------------------------
  318.   alias_method :trick_caterpillar_player_move_upper_left, :move_upper_left
  319.   def move_upper_left
  320.     if passable?(@x - 1, @y) and passable?(@x, @y - 1)
  321.       $game_party.update_move(7)
  322.     end
  323.     trick_caterpillar_player_move_upper_left
  324.   end
  325.   #--------------------------------------------------------------------------
  326.   # * Move Upper Right
  327.   #--------------------------------------------------------------------------
  328.   alias_method :trick_caterpillar_player_move_upper_right, :move_upper_right
  329.   def move_upper_right
  330.     if passable?(@x + 1, @y) and passable?(@x, @y - 1)
  331.       $game_party.update_move(9)
  332.     end
  333.     trick_caterpillar_player_move_upper_right
  334.   end
  335.   #--------------------------------------------------------------------------
  336.   # * Jump
  337.   #--------------------------------------------------------------------------
  338.   alias_method :trick_caterpillar_player_jump, :jump
  339.   def jump(x_plus, y_plus)
  340.     new_x = @x + x_plus
  341.     new_y = @y + y_plus
  342.     if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y)
  343.       $game_party.update_move(5, x_plus, y_plus)
  344.     end
  345.     trick_caterpillar_player_jump(x_plus, y_plus)
  346.   end
  347. end###########
  348. ###########
  349. ###########
复制代码
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-12-24 00:42

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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