Project1

标题: RMVX怎么实现多人战斗还有队友跟随还有换领队 [打印本页]

作者: 荷小青    时间: 2012-2-27 13:42
标题: RMVX怎么实现多人战斗还有队友跟随还有换领队
rtdsu_plus_rewardpost_czw
作者: victer    时间: 2012-2-27 22:07
我只有队友跟随
但也分享下
  1. #==============================================================================
  2. # ■ 人物跟随
  3. #------------------------------------------------------------------------------
  4. #
  5. #   本脚本来自www.66RPG.com,使用和转载请保留此信息
  6. #
  7. #   作者:fukuyama   
  8. #
  9. #   移植:ONEWateR
  10. #
  11. #==============================================================================
  12. module Train_Actor

  13. #是否使用停止跟随的方法,也就是说,这里false改为true的时候,如果TRANSPARENT_SWITCHES_INDEX
  14. #开关打开,跟随的人物就消失了(其实只是变成透明而已)

  15. TRANSPARENT_SWITCH = true
  16. TRANSPARENT_SWITCHES_INDEX = 1
  17. #举例:第一个为true,第二个为20,则打开20号开关,后面的人都没了。

  18. #跟随人数的最大数目,可以更改为2、3什么的。
  19. TRAIN_ACTOR_SIZE_MAX = 4

  20. # 定数
  21. DOWN_LEFT = 1
  22. DOWN_RIGHT = 3
  23. UP_LEFT = 7
  24. UP_RIGHT = 9
  25. JUMP = 5

  26. class Game_Party_Actor < Game_Character
  27. def initialize
  28. super()
  29. @through = true
  30. end
  31. def setup(actor)
  32. if actor != nil
  33. @character_index = actor.character_index
  34. @character_name = actor.character_name
  35. @priority_type = 1
  36. else
  37. @character_name = ""
  38. @character_index = 0
  39. @priority_type = 1
  40. end
  41. # 不透明度と合成方法を初期化
  42. @opacity = 255
  43. @blend_type = 0
  44. end
  45. #--------------------------------------------------------------------------
  46. # ● 下に移動
  47. # turn_enabled : その場での向き変更を許可するフラグ
  48. #--------------------------------------------------------------------------
  49. def move_down(turn_enabled = true)
  50. # 下を向く
  51. if turn_enabled
  52. turn_down
  53. end
  54. # 通行可能な場合
  55. if new_passable?(@x, @y, Input::DOWN)
  56. # 下を向く
  57. turn_down
  58. # 座標を更新
  59. @y += 1
  60. end
  61. end
  62. #--------------------------------------------------------------------------
  63. # ● 左に移動
  64. # turn_enabled : その場での向き変更を許可するフラグ
  65. #--------------------------------------------------------------------------
  66. def move_left(turn_enabled = true)
  67. # 左を向く
  68. if turn_enabled
  69. turn_left
  70. end
  71. # 通行可能な場合
  72. if new_passable?(@x, @y, Input::LEFT)
  73. # 左を向く
  74. turn_left
  75. # 座標を更新
  76. @x -= 1
  77. end
  78. end
  79. #--------------------------------------------------------------------------
  80. # ● 右に移動
  81. # turn_enabled : その場での向き変更を許可するフラグ
  82. #--------------------------------------------------------------------------
  83. def move_right(turn_enabled = true)
  84. # 右を向く
  85. if turn_enabled
  86. turn_right
  87. end
  88. # 通行可能な場合
  89. if new_passable?(@x, @y, Input::RIGHT)
  90. # 右を向く
  91. turn_right
  92. # 座標を更新
  93. @x += 1
  94. end
  95. end
  96. #--------------------------------------------------------------------------
  97. # ● 上に移動
  98. # turn_enabled : その場での向き変更を許可するフラグ
  99. #--------------------------------------------------------------------------
  100. def move_up(turn_enabled = true)
  101. # 上を向く
  102. if turn_enabled
  103. turn_up
  104. end
  105. # 通行可能な場合
  106. if new_passable?(@x, @y, Input::UP)
  107. # 上を向く
  108. turn_up
  109. # 座標を更新
  110. @y -= 1
  111. end
  112. end
  113. #--------------------------------------------------------------------------
  114. # ● 左下に移動
  115. #--------------------------------------------------------------------------
  116. def move_lower_left
  117. # 向き固定でない場合
  118. unless @direction_fix
  119. # 右向きだった場合は左を、上向きだった場合は下を向く
  120. @direction = (@direction == Input::RIGHT ? Input::LEFT : @direction == Input::UP ? Input::DOWN : @direction)
  121. end
  122. # 下→左、左→下 のどちらかのコースが通行可能な場合
  123. if (new_passable?(@x, @y, Input::DOWN) and new_passable?(@x, @y + 1, Input::LEFT)) or
  124. (new_passable?(@x, @y, Input::LEFT) and new_passable?(@x - 1, @y, Input::DOWN))
  125. # 座標を更新
  126. @x -= 1
  127. @y += 1
  128. end
  129. end
  130. #--------------------------------------------------------------------------
  131. # ● 右下に移動
  132. #--------------------------------------------------------------------------
  133. def move_lower_right
  134. # 向き固定でない場合
  135. unless @direction_fix
  136. # 左向きだった場合は右を、上向きだった場合は下を向く
  137. @direction = (@direction == Input::LEFT ? Input::RIGHT : @direction == Input::UP ? Input::DOWN : @direction)
  138. end
  139. # 下→右、右→下 のどちらかのコースが通行可能な場合
  140. if (new_passable?(@x, @y, Input::DOWN) and new_passable?(@x, @y + 1, Input::RIGHT)) or
  141. (new_passable?(@x, @y, Input::RIGHT) and new_passable?(@x + 1, @y, Input::DOWN))
  142. # 座標を更新
  143. @x += 1
  144. @y += 1
  145. end
  146. end
  147. #--------------------------------------------------------------------------
  148. # ● 左上に移動
  149. #--------------------------------------------------------------------------
  150. def move_upper_left
  151. # 向き固定でない場合
  152. unless @direction_fix
  153. # 右向きだった場合は左を、下向きだった場合は上を向く
  154. @direction = (@direction == Input::RIGHT ? Input::LEFT : @direction == Input::DOWN ? Input::UP : @direction)
  155. end
  156. # 上→左、左→上 のどちらかのコースが通行可能な場合
  157. if (new_passable?(@x, @y, Input::UP) and new_passable?(@x, @y - 1, Input::LEFT)) or
  158. (new_passable?(@x, @y, Input::LEFT) and new_passable?(@x - 1, @y, Input::UP))
  159. # 座標を更新
  160. @x -= 1
  161. @y -= 1
  162. end
  163. end
  164. #--------------------------------------------------------------------------
  165. # ● 右上に移動
  166. #--------------------------------------------------------------------------
  167. def move_upper_right
  168. # 向き固定でない場合
  169. unless @direction_fix
  170. # 左向きだった場合は右を、下向きだった場合は上を向く
  171. @direction = (@direction == Input::LEFT ? Input::RIGHT : @direction == Input::DOWN ? Input::UP : @direction)
  172. end
  173. # 上→右、右→上 のどちらかのコースが通行可能な場合
  174. if (new_passable?(@x, @y, Input::UP) and new_passable?(@x, @y - 1, Input::RIGHT)) or
  175. (new_passable?(@x, @y, Input::RIGHT) and new_passable?(@x + 1, @y, Input::UP))
  176. # 座標を更新
  177. @x += 1
  178. @y -= 1
  179. end
  180. end
  181. attr_writer :move_speed
  182. attr_writer :step_anime
  183. end
  184. module Spriteset_Map_Module
  185. def setup_actor_character_sprites?
  186. return @setup_actor_character_sprites_flag != nil
  187. end
  188. def setup_actor_character_sprites(characters)
  189. if !setup_actor_character_sprites?
  190. index_game_player = 0
  191. @character_sprites.each_index do |i|
  192. if @character_sprites[i].character.instance_of?(Game_Player)
  193. index_game_player = i
  194. break
  195. end
  196. end
  197. for character in characters.reverse
  198. @character_sprites.unshift(
  199. Sprite_Character.new(@viewport1, character)
  200. )
  201. end
  202. @setup_actor_character_sprites_flag = true
  203. end
  204. end
  205. end
  206. module Scene_Map_Module
  207. def setup_actor_character_sprites(characters)
  208. @spriteset.setup_actor_character_sprites(characters)
  209. end
  210. end
  211. module Game_Party_Module
  212. def set_transparent_actors(transparent)
  213. @transparent = transparent
  214. end
  215. def setup_actor_character_sprites
  216. if @characters == nil
  217. @characters = []

  218. for i in 1 ... TRAIN_ACTOR_SIZE_MAX
  219. @characters.push(Game_Party_Actor.new)
  220. end
  221. end
  222. for i in 1 ... TRAIN_ACTOR_SIZE_MAX
  223. @characters[i - 1].setup($game_party.members[i])
  224. end

  225. if $scene.class.method_defined?('setup_actor_character_sprites')
  226. $scene.setup_actor_character_sprites(@characters)
  227. end
  228. end
  229. def update_party_actors
  230. setup_actor_character_sprites
  231. transparent = $game_player.transparent
  232. if transparent == false
  233. if TRANSPARENT_SWITCH
  234. transparent = $game_switches[TRANSPARENT_SWITCHES_INDEX]
  235. end
  236. end
  237. for character in @characters
  238. character.transparent = transparent
  239. if $game_player.dash?
  240. character.move_speed = $game_player.move_speed*1.25
  241. else
  242. character.move_speed = $game_player.move_speed
  243. end
  244. character.step_anime = $game_player.step_anime
  245. character.update
  246. end
  247. end
  248. def moveto_party_actors( x, y )
  249. setup_actor_character_sprites
  250. for character in @characters
  251. character.moveto( x, y )
  252. end
  253. if @move_list == nil
  254. @move_list = []
  255. end
  256. move_list_setup
  257. end
  258. def move_party_actors
  259. if @move_list == nil
  260. @move_list = []
  261. move_list_setup
  262. end
  263. @move_list.each_index do |i|
  264. if @characters[i] != nil
  265. case @move_list[i].type
  266. when Input::DOWN
  267. @characters[i].move_down(@move_list[i].args[0])
  268. when Input::LEFT
  269. @characters[i].move_left(@move_list[i].args[0])
  270. when Input::RIGHT
  271. @characters[i].move_right(@move_list[i].args[0])
  272. when Input::UP
  273. @characters[i].move_up(@move_list[i].args[0])
  274. when DOWN_LEFT
  275. @characters[i].move_lower_left
  276. when DOWN_RIGHT
  277. @characters[i].move_lower_right
  278. when UP_LEFT
  279. @characters[i].move_upper_left
  280. when UP_RIGHT
  281. @characters[i].move_upper_right
  282. when JUMP
  283. @characters[i].jump(@move_list[i].args[0],@move_list[i].args[1])
  284. end
  285. end
  286. end
  287. end
  288. class Move_List_Element
  289. def initialize(type,args)
  290. @type = type
  291. @args = args
  292. end
  293. def type() return @type end
  294. def args() return @args end
  295. end
  296. def move_list_setup
  297. for i in 0 .. TRAIN_ACTOR_SIZE_MAX
  298. @move_list[i] = nil
  299. end
  300. end
  301. def add_move_list(type,*args)
  302. @move_list.unshift(Move_List_Element.new(type,args)).pop
  303. end
  304. def move_down_party_actors(turn_enabled = true)
  305. move_party_actors
  306. add_move_list(Input::DOWN,turn_enabled)
  307. end
  308. def move_left_party_actors(turn_enabled = true)
  309. move_party_actors
  310. add_move_list(Input::LEFT,turn_enabled)
  311. end
  312. def move_right_party_actors(turn_enabled = true)
  313. move_party_actors
  314. add_move_list(Input::RIGHT,turn_enabled)
  315. end
  316. def move_up_party_actors(turn_enabled = true)
  317. move_party_actors
  318. add_move_list(Input::UP,turn_enabled)
  319. end
  320. def move_lower_left_party_actors
  321. move_party_actors
  322. add_move_list(DOWN_LEFT)
  323. end
  324. def move_lower_right_party_actors
  325. move_party_actors
  326. add_move_list(DOWN_RIGHT)
  327. end
  328. def move_upper_left_party_actors
  329. move_party_actors
  330. add_move_list(UP_LEFT)
  331. end
  332. def move_upper_right_party_actors
  333. move_party_actors
  334. add_move_list(UP_RIGHT)
  335. end
  336. def jump_party_actors(x_plus, y_plus)
  337. move_party_actors
  338. add_move_list(JUMP,x_plus, y_plus)
  339. end
  340. end
  341. module Game_Player_Module
  342. def update
  343. $game_party.update_party_actors
  344. super
  345. end
  346. def moveto( x, y )
  347. $game_party.moveto_party_actors( x, y )
  348. super( x, y )
  349. end
  350. def move_down(turn_enabled = true)
  351. if new_passable?(@x, @y, Input::DOWN)
  352. $game_party.move_down_party_actors(turn_enabled)
  353. end
  354. super(turn_enabled)
  355. end
  356. def move_left(turn_enabled = true)
  357. if new_passable?(@x, @y, Input::LEFT)
  358. $game_party.move_left_party_actors(turn_enabled)
  359. end
  360. super(turn_enabled)
  361. end
  362. def move_right(turn_enabled = true)
  363. if new_passable?(@x, @y, Input::RIGHT)
  364. $game_party.move_right_party_actors(turn_enabled)
  365. end
  366. super(turn_enabled)
  367. end
  368. def move_up(turn_enabled = true)
  369. if new_passable?(@x, @y, Input::UP)
  370. $game_party.move_up_party_actors(turn_enabled)
  371. end
  372. super(turn_enabled)
  373. end
  374. def move_lower_left
  375. # 下→左、左→下 のどちらかのコースが通行可能な場合
  376. if (new_passable?(@x, @y, Input::DOWN) and new_passable?(@x, @y + 1, Input::LEFT)) or
  377. (new_passable?(@x, @y, Input::LEFT) and new_passable?(@x - 1, @y, Input::DOWN))
  378. $game_party.move_lower_left_party_actors
  379. end
  380. super
  381. end
  382. def move_lower_right
  383. # 下→右、右→下 のどちらかのコースが通行可能な場合
  384. if (new_passable?(@x, @y, Input::DOWN) and new_passable?(@x, @y + 1, Input::RIGHT)) or
  385. (new_passable?(@x, @y, Input::RIGHT) and new_passable?(@x + 1, @y, Input::DOWN))
  386. $game_party.move_lower_right_party_actors
  387. end
  388. super
  389. end
  390. def move_upper_left
  391. # 上→左、左→上 のどちらかのコースが通行可能な場合
  392. if (new_passable?(@x, @y, Input::UP) and new_passable?(@x, @y - 1, Input::LEFT)) or
  393. (new_passable?(@x, @y, Input::LEFT) and new_passable?(@x - 1, @y, Input::UP))
  394. $game_party.move_upper_left_party_actors
  395. end
  396. super
  397. end
  398. def move_upper_right
  399. # 上→右、右→上 のどちらかのコースが通行可能な場合
  400. if (new_passable?(@x, @y, Input::UP) and new_passable?(@x, @y - 1, Input::RIGHT)) or
  401. (new_passable?(@x, @y, Input::RIGHT) and new_passable?(@x + 1, @y, Input::UP))
  402. $game_party.move_upper_right_party_actors
  403. end
  404. super
  405. end
  406. def jump(x_plus, y_plus)
  407. # 新しい座標を計算
  408. new_x = @x + x_plus
  409. new_y = @y + y_plus
  410. # 加算値が (0,0) の場合か、ジャンプ先が通行可能な場合
  411. if (x_plus == 0 and y_plus == 0) or new_passable?(new_x, new_y, 0)
  412. $game_party.jump_party_actors(x_plus, y_plus)
  413. end
  414. super(x_plus, y_plus)
  415. end
  416. attr_accessor :move_speed
  417. attr_accessor :step_anime
  418. end
  419. end # module Train_Actor
  420. class Game_Party
  421. include Train_Actor::Game_Party_Module
  422. end
  423. class Game_Player
  424. include Train_Actor::Game_Player_Module
  425. end
  426. class Spriteset_Map
  427. include Train_Actor::Spriteset_Map_Module
  428. end
  429. class Scene_Map
  430. include Train_Actor::Scene_Map_Module
  431. end
  432. class Game_Character
  433. def new_passable?(x, y, d)
  434. new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  435. new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  436. unless $game_map.valid?(new_x, new_y)
  437. return false
  438. end
  439. x = $game_map.round_x(x)                        # 横方向循环修正
  440. y = $game_map.round_y(y)                        # 纵方向循环修正
  441. return false unless $game_map.valid?(x, y)      # 地图外?
  442. return true if @through or debug_through?       # 穿越 ON?
  443. return false unless map_passable?(new_x, new_y)         # 地图不能通行?
  444. return false if collide_with_characters?(new_x, new_y)  # 与角色冲突?
  445. return true                                     # 可以通行
  446. end
  447. end
复制代码

作者: a364774426    时间: 2012-2-27 22:37
LZ一题多问,忒不厚道。本来我这里有你需要的所有,但是……
作者: justice    时间: 2012-2-28 00:47
換領隊其實可以用事件解決...
用事件讓隊員離開再重新加入
比方說你希望拉爾夫當領隊
就設其他三人離開隊伍再立即重新加入
注意不要把能力初期化應該就行了




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1