Project1

标题: 八脚方向问题 [打印本页]

作者: 仙芋    时间: 2010-6-27 18:49
标题: 八脚方向问题
本帖最后由 仙芋 于 2010-7-3 11:40 编辑

我已經有八脚方向的脚本
可是要怎样放上其他的行动图(例如:左上,右上)
脚本如下:
  1. TRANSPARENT_SWITCH = true
  2. TRANSPARENT_SWITCHES_INDEX = 96
  3. TRAIN_ACTOR_SIZE_MAX = 4
  4. TRAIN_ACTOR_DISTANCE = 1
  5. # 定数
  6. #Input::DOWN = 2
  7. #Input::LEFT = 4
  8. #Input::RIGHT = 6
  9. #Input::UP = 6
  10. DOWN_LEFT = 1
  11. DOWN_RIGHT = 3
  12. UP_LEFT = 7
  13. UP_RIGHT = 9
  14. JUMP = 5
  15. TRAIN_ACTOR_SIZE_MAX = TRAIN_ACTOR_SIZE_MAX * (TRAIN_ACTOR_DISTANCE+1) + 1
  16. class Game_Party_Actor < Game_Character
  17. def initialize
  18. super()
  19. @through = true
  20. end
  21. def setup(actor)
  22. # キャラクターのファイル名と色相を設定
  23. if actor != nil
  24. @character_name = actor.character_name
  25. @character_hue = actor.character_hue
  26. else
  27. @character_name = ""
  28. @character_hue = 0
  29. end
  30. # 不透明度と合成方法を初期化
  31. @opacity = 255
  32. @blend_type = 0
  33. end
  34. def screen_z(height = 0)
  35. if $game_player.x == @x and $game_player.y == @y
  36. return $game_player.screen_z(height) - 1
  37. end
  38. super(height)
  39. end
  40. #--------------------------------------------------------------------------
  41. # ● 下に移動
  42. # turn_enabled : その場での向き変更を許可するフラグ
  43. #--------------------------------------------------------------------------
  44. def move_down(turn_enabled = true)
  45. # 下を向く
  46. if turn_enabled
  47. turn_down
  48. end
  49. # 通行可能な場合
  50. if passable?(@x, @y, Input::DOWN)
  51. # 下を向く
  52. turn_down
  53. # 座標を更新
  54. @y += 1
  55. end
  56. end
  57. #--------------------------------------------------------------------------
  58. # ● 左に移動
  59. # turn_enabled : その場での向き変更を許可するフラグ
  60. #--------------------------------------------------------------------------
  61. def move_left(turn_enabled = true)
  62. # 左を向く
  63. if turn_enabled
  64. turn_left
  65. end
  66. # 通行可能な場合
  67. if passable?(@x, @y, Input::LEFT)
  68. # 左を向く
  69. turn_left
  70. # 座標を更新
  71. @x -= 1
  72. end
  73. end
  74. #--------------------------------------------------------------------------
  75. # ● 右に移動
  76. # turn_enabled : その場での向き変更を許可するフラグ
  77. #--------------------------------------------------------------------------
  78. def move_right(turn_enabled = true)
  79. # 右を向く
  80. if turn_enabled
  81. turn_right
  82. end
  83. # 通行可能な場合
  84. if passable?(@x, @y, Input::RIGHT)
  85. # 右を向く
  86. turn_right
  87. # 座標を更新
  88. @x += 1
  89. end
  90. end
  91. #--------------------------------------------------------------------------
  92. # ● 上に移動
  93. # turn_enabled : その場での向き変更を許可するフラグ
  94. #--------------------------------------------------------------------------
  95. def move_up(turn_enabled = true)
  96. # 上を向く
  97. if turn_enabled
  98. turn_up
  99. end
  100. # 通行可能な場合
  101. if passable?(@x, @y, Input::UP)
  102. # 上を向く
  103. turn_up
  104. # 座標を更新
  105. @y -= 1
  106. end
  107. end
  108. #--------------------------------------------------------------------------
  109. # ● 左下に移動
  110. #--------------------------------------------------------------------------
  111. def move_lower_left
  112. # 向き固定でない場合
  113. unless @direction_fix
  114. # 右向きだった場合は左を、上向きだった場合は下を向く
  115. @direction = (@direction == Input::RIGHT ? Input::LEFT : @direction == Input::UP ? Input::DOWN : @direction)
  116. end
  117. # 下→左、左→下 のどちらかのコースが通行可能な場合
  118. if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT)) or
  119. (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN))
  120. # 座標を更新
  121. @x -= 1
  122. @y += 1
  123. end
  124. end
  125. #--------------------------------------------------------------------------
  126. # ● 右下に移動
  127. #--------------------------------------------------------------------------
  128. def move_lower_right
  129. # 向き固定でない場合
  130. unless @direction_fix
  131. # 左向きだった場合は右を、上向きだった場合は下を向く
  132. @direction = (@direction == Input::LEFT ? Input::RIGHT : @direction == Input::UP ? Input::DOWN : @direction)
  133. end
  134. # 下→右、右→下 のどちらかのコースが通行可能な場合
  135. if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT)) or
  136. (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN))
  137. # 座標を更新
  138. @x += 1
  139. @y += 1
  140. end
  141. end
  142. #--------------------------------------------------------------------------
  143. # ● 左上に移動
  144. #--------------------------------------------------------------------------
  145. def move_upper_left
  146. # 向き固定でない場合
  147. unless @direction_fix
  148. # 右向きだった場合は左を、下向きだった場合は上を向く
  149. @direction = (@direction == Input::RIGHT ? Input::LEFT : @direction == Input::DOWN ? Input::UP : @direction)
  150. end
  151. # 上→左、左→上 のどちらかのコースが通行可能な場合
  152. if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT)) or
  153. (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP))
  154. # 座標を更新
  155. @x -= 1
  156. @y -= 1
  157. end
  158. end
  159. #--------------------------------------------------------------------------
  160. # ● 右上に移動
  161. #--------------------------------------------------------------------------
  162. def move_upper_right
  163. # 向き固定でない場合
  164. unless @direction_fix
  165. # 左向きだった場合は右を、下向きだった場合は上を向く
  166. @direction = (@direction == Input::LEFT ? Input::RIGHT : @direction == Input::DOWN ? Input::UP : @direction)
  167. end
  168. # 上→右、右→上 のどちらかのコースが通行可能な場合
  169. if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT)) or
  170. (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP))
  171. # 座標を更新
  172. @x += 1
  173. @y -= 1
  174. end
  175. end
  176. attr_writer :move_speed
  177. attr_writer :step_anime
  178. end
  179. module Spriteset_Map_Module
  180. def setup_actor_character_sprites?
  181. return @setup_actor_character_sprites_flag != nil
  182. end
  183. def setup_actor_character_sprites(characters)
  184. if !setup_actor_character_sprites?
  185. index_game_player = 0
  186. @character_sprites.each_index do |i|
  187. if @character_sprites[i].character.instance_of?(Game_Player)
  188. index_game_player = i
  189. break
  190. end
  191. end
  192. for character in characters.reverse
  193. @character_sprites.unshift(
  194. Sprite_Character.new(@viewport1, character)
  195. )
  196. end
  197. @setup_actor_character_sprites_flag = true
  198. end
  199. end
  200. end
  201. module Scene_Map_Module
  202. def setup_actor_character_sprites(characters)
  203. @spriteset.setup_actor_character_sprites(characters)
  204. end
  205. end
  206. module Game_Party_Module
  207. def set_transparent_actors(transparent)
  208. @transparent = transparent
  209. end
  210. def setup_actor_character_sprites
  211. if @characters == nil
  212. # 叶子到此一游
  213. @characters = []
  214. for i in 1 ... TRAIN_ACTOR_SIZE_MAX
  215. @characters.push(Game_Party_Actor.new)
  216. end
  217. end
  218. for i in 1 ... TRAIN_ACTOR_SIZE_MAX
  219. # 叶子到此一游
  220. if i % (TRAIN_ACTOR_DISTANCE+1) == 0
  221. @characters[i-1].setup(actors[i/(TRAIN_ACTOR_DISTANCE+1)])
  222. end
  223. end
  224. if $scene.class.method_defined?('setup_actor_character_sprites')
  225. $scene.setup_actor_character_sprites(@characters)
  226. end
  227. end
  228. def update_party_actors
  229. setup_actor_character_sprites
  230. transparent = $game_player.transparent
  231. if transparent == false
  232. if TRANSPARENT_SWITCH
  233. transparent = $game_switches[TRANSPARENT_SWITCHES_INDEX]
  234. end
  235. end
  236. for character in @characters
  237. character.transparent = transparent
  238. character.move_speed = $game_player.move_speed
  239. character.step_anime = $game_player.step_anime
  240. character.update
  241. end
  242. end
  243. def moveto_party_actors( x, y )
  244. setup_actor_character_sprites
  245. for character in @characters
  246. character.moveto( x, y )
  247. end
  248. if @move_list == nil
  249. @move_list = []
  250. end
  251. move_list_setup
  252. end
  253. def move_party_actors
  254. if @move_list == nil
  255. @move_list = []
  256. move_list_setup
  257. end
  258. @move_list.each_index do |i|
  259. if @characters[i] != nil
  260. case @move_list[i].type
  261. when Input::DOWN
  262. @characters[i].move_down(@move_list[i].args[0])
  263. when Input::LEFT
  264. @characters[i].move_left(@move_list[i].args[0])
  265. when Input::RIGHT
  266. @characters[i].move_right(@move_list[i].args[0])
  267. when Input::UP
  268. @characters[i].move_up(@move_list[i].args[0])
  269. when DOWN_LEFT
  270. @characters[i].move_lower_left
  271. when DOWN_RIGHT
  272. @characters[i].move_lower_right
  273. when UP_LEFT
  274. @characters[i].move_upper_left
  275. when UP_RIGHT
  276. @characters[i].move_upper_right
  277. when JUMP
  278. @characters[i].jump(@move_list[i].args[0],@move_list[i].args[1])
  279. end
  280. end
  281. end
  282. end
  283. class Move_List_Element
  284. def initialize(type,args)
  285. @type = type
  286. @args = args
  287. end
  288. def type() return @type end
  289. def args() return @args end
  290. end
  291. def move_list_setup
  292. for i in 0 .. TRAIN_ACTOR_SIZE_MAX
  293. @move_list[i] = nil
  294. end
  295. end
  296. def add_move_list(type,*args)
  297. @move_list.unshift(Move_List_Element.new(type,args)).pop
  298. end
  299. def move_down_party_actors(turn_enabled = true)
  300. move_party_actors
  301. add_move_list(Input::DOWN,turn_enabled)
  302. end
  303. def move_left_party_actors(turn_enabled = true)
  304. move_party_actors
  305. add_move_list(Input::LEFT,turn_enabled)
  306. end
  307. def move_right_party_actors(turn_enabled = true)
  308. move_party_actors
  309. add_move_list(Input::RIGHT,turn_enabled)
  310. end
  311. def move_up_party_actors(turn_enabled = true)
  312. move_party_actors
  313. add_move_list(Input::UP,turn_enabled)
  314. end
  315. def move_lower_left_party_actors
  316. move_party_actors
  317. add_move_list(DOWN_LEFT)
  318. end
  319. def move_lower_right_party_actors
  320. move_party_actors
  321. add_move_list(DOWN_RIGHT)
  322. end
  323. def move_upper_left_party_actors
  324. move_party_actors
  325. add_move_list(UP_LEFT)
  326. end
  327. def move_upper_right_party_actors
  328. move_party_actors
  329. add_move_list(UP_RIGHT)
  330. end
  331. def jump_party_actors(x_plus, y_plus)
  332. move_party_actors
  333. add_move_list(JUMP,x_plus, y_plus)
  334. end
  335. end
  336. module Game_Player_Module
  337. def update
  338. $game_party.update_party_actors
  339. super
  340. end
  341. def moveto( x, y )
  342. $game_party.moveto_party_actors( x, y )
  343. super( x, y )
  344. end
  345. def move_down(turn_enabled = true)
  346. if passable?(@x, @y, Input::DOWN)
  347. $game_party.move_down_party_actors(turn_enabled)
  348. end
  349. super(turn_enabled)
  350. end
  351. def move_left(turn_enabled = true)
  352. if passable?(@x, @y, Input::LEFT)
  353. $game_party.move_left_party_actors(turn_enabled)
  354. end
  355. super(turn_enabled)
  356. end
  357. def move_right(turn_enabled = true)
  358. if passable?(@x, @y, Input::RIGHT)
  359. $game_party.move_right_party_actors(turn_enabled)
  360. end
  361. super(turn_enabled)
  362. end
  363. def move_up(turn_enabled = true)
  364. if passable?(@x, @y, Input::UP)
  365. $game_party.move_up_party_actors(turn_enabled)
  366. end
  367. super(turn_enabled)
  368. end
  369. def move_lower_left
  370. # 下→左、左→下 のどちらかのコースが通行可能な場合
  371. if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT)) or
  372. (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN))
  373. $game_party.move_lower_left_party_actors
  374. end
  375. super
  376. end
  377. def move_lower_right
  378. # 下→右、右→下 のどちらかのコースが通行可能な場合
  379. if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT)) or
  380. (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN))
  381. $game_party.move_lower_right_party_actors
  382. end
  383. super
  384. end
  385. def move_upper_left
  386. # 上→左、左→上 のどちらかのコースが通行可能な場合
  387. if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT)) or
  388. (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP))
  389. $game_party.move_upper_left_party_actors
  390. end
  391. super
  392. end
  393. def move_upper_right
  394. # 上→右、右→上 のどちらかのコースが通行可能な場合
  395. if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT)) or
  396. (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP))
  397. $game_party.move_upper_right_party_actors
  398. end
  399. super
  400. end
  401. def jump(x_plus, y_plus)
  402. # 新しい座標を計算
  403. new_x = @x + x_plus
  404. new_y = @y + y_plus
  405. # 加算値が (0,0) の場合か、ジャンプ先が通行可能な場合
  406. if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
  407. $game_party.jump_party_actors(x_plus, y_plus)
  408. end
  409. super(x_plus, y_plus)
  410. end
  411. attr_reader :move_speed
  412. attr_reader :step_anime
  413. end
  414. end # module Train_Actor
  415. class Game_Party
  416. include Train_Actor::Game_Party_Module
  417. end
  418. class Game_Player
  419. include Train_Actor::Game_Player_Module
  420. end
  421. class Spriteset_Map
  422. include Train_Actor::Spriteset_Map_Module
  423. end
  424. class Scene_Map
  425. include Train_Actor::Scene_Map_Module
  426. end
复制代码

作者: jhhuang    时间: 2010-7-1 05:03
不知道你脚本适不适用 = =
一般的8方向行走图如下.

作者: 谈陈鸿杰    时间: 2010-7-1 09:06
不懂你的意思。。
你是说放在哪里吗?
Graphics\Characters里。
或者是其他意思?
作者: GM.01    时间: 2010-7-1 10:42
要有专门的行走图

作者: 仙芋    时间: 2010-7-1 16:48
它只有 4x4
我已经做了8x4的
可是它只会沿用 4x4 的
就是说
它把我 8x4 的图分开成 4x4
作者: jhhuang    时间: 2010-7-1 19:55
本帖最后由 jhhuang 于 2010-7-1 19:57 编辑

单独插入你这个脚本后发现= =
414行end #module Train_Actor错误.
你能用这脚本?

顺便发一个我正在用的:
  1. #==============================================================================
  2. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  3. #==============================================================================
  4. ###########################################################################################################################
  5. ###########################################################################################################################
  6. # 脚本功能:八方向走与多帧移动之图片修正__ver1.1。

  7. # 更新日期:2005年8月6日

  8. # 更新内容:增加斜方向触发,增加斜方向面向角色(1步之内)

  9. # 使用方法:将本脚本插入到main之前。如果你使用了雅土版的八方向走脚本,请确保这个脚本的顺序位置,在雅土八方向走脚本的后面。

  10. # 预先处理:请输入每一步的帧数和总共可用的方向数

  11. $c3_每一步的帧数 = 4
  12. $c3_总共可用的方向数 = 8 #——建议不要修改这个。如果要伪8方向的,就用伪的好了。

  13. # 图片处理与功能说明:

  14. # 1、每一步的帧数:
  15. #    众所周知,RMXP的移动行走图是一个方向共有4帧,很多人都觉得这个帧数有点少。
  16. # 使用这个脚本之后,只要将 $c3_每一步的帧数 这个变量设置一个需要的帧数即可修改
  17. # 单方向移动帧数为相应输入值。修改后,需要用photoshop将所有用到的素材的横排
  18. # 调整为相应帧数,比如输入了8则要将每一行设置8个图像(即每一个行走图有8列)。

  19. # 2、可用方向调整(可用数量:4、8):
  20. #    当为4方向时没有任何变化,还是一个图4行,上左右下4个方向。
  21. #    如果想使用8方向走,将需要八方向行走的行走图在延伸扩大的画布中按照左下、右下、左上、右上继续排布图像。
  22. # 即,行走图图片从上到下的面向排列顺序为:下,左,右,上,左下,右下,左上,右上。
  23. #    至于不需要8方向走的普通的NPC(character),使用photoshop将画布向下扩大一倍即可使用。
  24. #    需要注意的是,如果需要斜方向飞鸟,请不要忘记自制素材。

  25. # 特别提示:   
  26. #     使用本脚本前请先考虑清楚是否要做这种效果。因为使用本脚本后需要用photoshop处理character行走图素材
  27. # 虽然这种处理用photoshop定义动作只需要5分钟即可全部完成,但在制作阶段会感觉不是很爽(具体的用了才知道)
  28. # 作者的建议是,如果你没有足够的制作经验,使用这个脚本得不偿失。请确保自己的能力属于“高手”级别!

  29. # 附赠功能:
  30. #     可以让NPC角色随机8方向走,方法是:NPC角色移动路线为“自定义”,然后自定义里面使用脚本,输入c8即可
  31. #     可以让NPC角色随机4斜角方向走,方法是:NPC角色移动路线为“自定义”,然后自定义里面使用脚本,输入c4即可
  32. #     可以使用真·斜4方向行走,参考脚本53行开始

  33. # 作者:carol3
  34. ###########################################################################################################################
  35. ###########################################################################################################################

  36. class Game_Player < Game_Character
  37.   if $c3_总共可用的方向数 == 8
  38.     def update
  39.       last_moving = moving?
  40.       unless moving? or $game_system.map_interpreter.running? or
  41.              @move_route_forcing or $game_temp.message_window_showing
  42.         # 用井号后面的东西替代前面的,就可以实现斜4方向走
  43.         case Input.dir8
  44.         when 2
  45.           move_down #move_lower_left
  46.         when 4
  47.           move_left #move_upper_left
  48.         when 6
  49.           move_right #move_lower_right
  50.         when 8
  51.           move_up #move_upper_right
  52.         when 1
  53.           move_lower_left
  54.         when 3
  55.           move_lower_right
  56.         when 7
  57.           move_upper_left
  58.         when 9
  59.           move_upper_right
  60.         end
  61.       end
  62.       # 本地变量记忆坐标
  63.       last_real_x = @real_x
  64.       last_real_y = @real_y
  65.       super
  66.       # 角色向下移动、画面上的位置在中央下方的情况下
  67.       if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
  68.         # 画面向下卷动
  69.         $game_map.scroll_down(@real_y - last_real_y)
  70.       end
  71.       # 角色向左移动、画面上的位置在中央左方的情况下
  72.       if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
  73.         # 画面向左卷动
  74.         $game_map.scroll_left(last_real_x - @real_x)
  75.       end
  76.       # 角色向右移动、画面上的位置在中央右方的情况下
  77.       if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
  78.         # 画面向右卷动
  79.         $game_map.scroll_right(@real_x - last_real_x)
  80.       end
  81.       # 角色向上移动、画面上的位置在中央上方的情况下
  82.       if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
  83.         # 画面向上卷动
  84.         $game_map.scroll_up(last_real_y - @real_y)
  85.       end
  86.       # 不在移动中的情况下
  87.       unless moving?
  88.         # 上次主角移动中的情况
  89.         if last_moving
  90.           # 与同位置的事件接触就判定为事件启动
  91.           result = check_event_trigger_here([1,2])
  92.           # 没有可以启动的事件的情况下
  93.           if result == false
  94.             # 调试模式为 ON 并且按下 CTRL 键的情况下除外
  95.             unless $DEBUG and Input.press?(Input::CTRL)
  96.               # 遇敌计数下降
  97.               if @encounter_count > 0
  98.                 @encounter_count -= 1
  99.               end
  100.             end
  101.           end
  102.         end
  103.         # 按下 C 键的情况下
  104.         if Input.trigger?(Input::C)
  105.           # 判定为同位置以及正面的事件启动
  106.           check_event_trigger_here([0])
  107.           check_event_trigger_there([0,1,2])
  108.         end
  109.       end
  110.     end
  111.     #--------------------------------------------------------------------------
  112.     # ● 正面事件的启动判定
  113.     #--------------------------------------------------------------------------
  114.     def check_event_trigger_there(triggers)
  115.       result = false
  116.       # 事件执行中的情况下
  117.       if $game_system.map_interpreter.running?
  118.         return result
  119.       end
  120.       # 计算正面坐标
  121.       new_x = @x
  122.       new_y = @y
  123.       case @direction
  124.       when 1
  125.         new_x -= 1
  126.         new_y += 1
  127.       when 2
  128.         new_y += 1
  129.       when 3
  130.         new_x += 1
  131.         new_y += 1
  132.       when 4
  133.         new_x -= 1
  134.       when 6
  135.         new_x += 1
  136.       when 7
  137.         new_x -= 1
  138.         new_y -= 1
  139.       when 8
  140.         new_y -= 1
  141.       when 9
  142.         new_x += 1
  143.         new_y -= 1
  144.       end
  145.       # 全部事件的循环
  146.       for event in $game_map.events.values
  147.         # 事件坐标与目标一致的情况下
  148.         if event.x == new_x and event.y == new_y and
  149.            triggers.include?(event.trigger)
  150.           # 跳跃中以外的情况下、启动判定是正面的事件
  151.           if not event.jumping? and not event.over_trigger?
  152.             event.start
  153.             result = true
  154.           end
  155.         end
  156.       end
  157.       # 找不到符合条件的事件的情况下
  158.       if result == false
  159.         # 正面的元件是计数器的情况下
  160.         if $game_map.counter?(new_x, new_y)
  161.           # 计算 1 元件里侧的坐标
  162.           new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  163.           new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  164.           # 全事件的循环
  165.           for event in $game_map.events.values
  166.             # 事件坐标与目标一致的情况下
  167.             if event.x == new_x and event.y == new_y and
  168.                triggers.include?(event.trigger)
  169.               # 跳跃中以外的情况下、启动判定是正面的事件
  170.               if not event.jumping? and not event.over_trigger?
  171.                 event.start
  172.                 result = true
  173.               end
  174.             end
  175.           end
  176.         end
  177.       end
  178.       return result
  179.     end
  180.     #--------------------------------------------------------------------------
  181.     # ● 向左下移动
  182.     #--------------------------------------------------------------------------
  183.     def move_lower_left
  184.       # 没有固定面向的场合
  185.       unless @direction_fix
  186.         # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  187.         @direction = 1#(@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
  188.       end
  189.       # 下→左、左→下 的通道可以通行的情况下
  190.       if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
  191.          (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
  192.         # 更新坐标
  193.         @x -= 1
  194.         @y += 1
  195.         # 增加步数
  196.         increase_steps
  197.       else
  198.         check_event_trigger_touch(@x-1, @y+1)
  199.       end
  200.     end
  201.     #--------------------------------------------------------------------------
  202.     # ● 向右下移动
  203.     #--------------------------------------------------------------------------
  204.     def move_lower_right
  205.       # 没有固定面向的场合
  206.       unless @direction_fix
  207.         # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  208.         @direction = 3#(@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
  209.       end
  210.       # 下→右、右→下 的通道可以通行的情况下
  211.       if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
  212.          (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
  213.         # 更新坐标
  214.         @x += 1
  215.         @y += 1
  216.         # 增加步数
  217.         increase_steps
  218.       else
  219.         check_event_trigger_touch(@x+1, @y+1)
  220.       end
  221.     end
  222.     #--------------------------------------------------------------------------
  223.     # ● 向左上移动
  224.     #--------------------------------------------------------------------------
  225.     def move_upper_left
  226.       # 没有固定面向的场合
  227.       unless @direction_fix
  228.         # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  229.         @direction = 7#(@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
  230.       end
  231.       # 上→左、左→上 的通道可以通行的情况下
  232.       if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
  233.          (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
  234.         # 更新坐标
  235.         @x -= 1
  236.         @y -= 1
  237.         # 增加步数
  238.         increase_steps
  239.       else
  240.         check_event_trigger_touch(@x-1, @y-1)
  241.       end
  242.     end
  243.     #--------------------------------------------------------------------------
  244.     # ● 向右上移动
  245.     #--------------------------------------------------------------------------
  246.     def move_upper_right
  247.       # 没有固定面向的场合
  248.       unless @direction_fix
  249.         # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  250.         @direction = 9#(@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
  251.       end
  252.       # 上→右、右→上 的通道可以通行的情况下
  253.       if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
  254.          (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
  255.         # 更新坐标
  256.         @x += 1
  257.         @y -= 1
  258.         # 增加步数
  259.         increase_steps
  260.       else
  261.         check_event_trigger_touch(@x+1, @y-1)
  262.       end
  263.     end
  264.     #--------------------------------------------------------------------------
  265.     # ● 雅土左下移動
  266.     #--------------------------------------------------------------------------
  267.     def move_lower_left_p
  268.       unless @direction_fix
  269.         @direction = 1
  270.       end
  271.       distance = (2 ** @move_speed) / Math.sqrt(2)
  272.       turn_left unless down1(@x, @y, distance)
  273.       turn_down if @event
  274.       turn_down unless left1(@x, @y, distance) unless @event
  275.       turn_left if @event
  276.     end
  277.     #--------------------------------------------------------------------------
  278.     # ● 雅土右下移動
  279.     #--------------------------------------------------------------------------
  280.     def move_lower_right_p
  281.       unless @direction_fix
  282.         @direction = 3
  283.       end
  284.       distance = (2 ** @move_speed) / Math.sqrt(2)
  285.       turn_right unless down1(@x, @y, distance)
  286.       turn_down if @event
  287.       turn_down unless right1(@x, @y, distance) unless @event
  288.       turn_right if @event
  289.     end
  290.     #--------------------------------------------------------------------------
  291.     # ● 雅土左上移動
  292.     #--------------------------------------------------------------------------
  293.     def move_upper_left_p
  294.       unless @direction_fix
  295.         @direction = 7
  296.       end
  297.       distance = (2 ** @move_speed) / Math.sqrt(2)
  298.       turn_left unless up1(@x, @y, distance)
  299.       turn_up if @event
  300.       turn_up unless left1(@x, @y, distance) unless @event
  301.       turn_left if @event
  302.     end
  303.     #--------------------------------------------------------------------------
  304.     # ● 雅土右上移動
  305.     #--------------------------------------------------------------------------
  306.     def move_upper_right_p
  307.       unless @direction_fix
  308.         @direction = 9
  309.       end
  310.       distance = (2 ** @move_speed) / Math.sqrt(2)
  311.       turn_right unless up1(@x, @y, distance)
  312.       turn_up if @event
  313.       turn_up unless right1(@x, @y, distance) unless @event
  314.       turn_right if @event
  315.     end
  316.   end
  317. end


  318. class Sprite_Character < RPG::Sprite
  319.   def update
  320.     super
  321.     # 元件 ID、文件名、色相与现在的情况存在差异的情况下
  322.     if @tile_id != @character.tile_id or
  323.        @character_name != @character.character_name or
  324.        @character_hue != @character.character_hue
  325.       # 记忆元件 ID 与文件名、色相
  326.       @tile_id = @character.tile_id
  327.       @character_name = @character.character_name
  328.       @character_hue = @character.character_hue
  329.       # 元件 ID 为有效值的情况下
  330.       if @tile_id >= 384
  331.         self.bitmap = RPG::Cache.tile($game_map.tileset_name,
  332.           @tile_id, @character.character_hue)
  333.         self.src_rect.set(0, 0, 32, 32)
  334.         self.ox = 16
  335.         self.oy = 32
  336.       # 元件 ID 为无效值的情况下
  337.       else
  338.         self.bitmap = RPG::Cache.character(@character.character_name,
  339.           @character.character_hue)
  340.         @cw = bitmap.width / $c3_每一步的帧数
  341.         if $c3_总共可用的方向数==4
  342.           @ch = bitmap.height / 4
  343.         else
  344.           @ch = bitmap.height / 8
  345.         end
  346.         self.ox = @cw / 2
  347.         self.oy = @ch
  348.       end
  349.     end
  350.     # 设置可视状态
  351.     self.visible = (not @character.transparent)
  352.     # 图形是角色的情况下
  353.     if @tile_id == 0
  354.       # 设置传送目标的矩形
  355.       sx = @character.pattern * @cw
  356.       if $c3_总共可用的方向数==8
  357.         case @character.direction
  358.         when 2
  359.           sy = 0 * @ch
  360.         when 4
  361.           sy = 1 * @ch
  362.         when 6
  363.           sy = 2 * @ch
  364.         when 8
  365.           sy = 3 * @ch
  366.         when 1
  367.           sy = 4 * @ch
  368.         when 3
  369.           sy = 5 * @ch
  370.         when 7
  371.           sy = 6 * @ch
  372.         when 9
  373.           sy = 7 * @ch
  374.         end
  375.       else
  376.         sy = (@character.direction - 2) / 2 * @ch
  377.       end
  378.       self.src_rect.set(sx, sy, @cw, @ch)
  379.     end
  380.     # 设置脚本的坐标
  381.     self.x = @character.screen_x
  382.     self.y = @character.screen_y
  383.     self.z = @character.screen_z(@ch)
  384.     # 设置不透明度、合成方式、茂密
  385.     self.opacity = @character.opacity
  386.     self.blend_type = @character.blend_type
  387.     self.bush_depth = @character.bush_depth
  388.     # 动画
  389.     if @character.animation_id != 0
  390.       animation = $data_animations[@character.animation_id]
  391.       animation(animation, true)
  392.       @character.animation_id = 0
  393.     end
  394.   end
  395. end

  396. class Game_Character
  397.   def c8
  398.     # 随机 0~5 的分支
  399.     case rand(10)
  400.     when 0..3  # 随机
  401.       move_random
  402.     when 4  # 前进一步
  403.       move_forward
  404.     when 5  # 暂时停止
  405.       @stop_count = 0
  406.     when 6..9  #另外4方向随机
  407.       c4
  408.     end
  409.   end
  410.   def c4
  411.     case rand(5)
  412.     when 0
  413.       move_upper_left
  414.     when 1
  415.       move_upper_right
  416.     when 2
  417.       move_lower_left
  418.     when 3
  419.       move_lower_right
  420.     when 4
  421.       @stop_count = 0
  422.     end
  423.   end
  424.       
  425.   def update
  426.     # 跳跃中、移动中、停止中的分支
  427.     if jumping?
  428.       update_jump
  429.     elsif moving?
  430.       update_move
  431.     else
  432.       update_stop
  433.     end
  434.     # 动画计数超过最大值的情况下
  435.     # ※最大值等于基本值减去移动速度 * 1 的值
  436.     if @anime_count > 16*4/$c3_每一步的帧数 - @move_speed * 2
  437.       # 停止动画为 OFF 并且在停止中的情况下
  438.       if not @step_anime and @stop_count > 0
  439.         # 还原为原来的图形
  440.         @pattern = @original_pattern
  441.       # 停止动画为 ON 并且在移动中的情况下
  442.       else
  443.         # 更新图形
  444.         @pattern = (@pattern + 1) % $c3_每一步的帧数
  445.       end
  446.       # 清除动画计数
  447.       @anime_count = 0
  448.     end
  449.     # 等待中的情况下
  450.     if @wait_count > 0
  451.       # 减少等待计数
  452.       @wait_count -= 1
  453.       return
  454.     end
  455.     # 强制移动路线的场合
  456.     if @move_route_forcing
  457.       # 自定义移动
  458.       move_type_custom
  459.       return
  460.     end
  461.     # 事件执行待机中并且为锁定状态的情况下
  462.     if @starting or lock?
  463.       # 不做规则移动
  464.       return
  465.     end
  466.     # 如果停止计数超过了一定的值(由移动频度算出)
  467.     if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
  468.       # 移动类型分支
  469.       case @move_type
  470.       when 1  # 随机
  471.         move_type_random
  472.       when 2  # 接近
  473.         move_type_toward_player
  474.       when 3  # 自定义
  475.         move_type_custom
  476.       end
  477.     end
  478.   end
  479. end

  480. class Window_Base < Window
  481.   def draw_actor_graphic(actor, x, y)
  482.     bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
  483.     cw = bitmap.width / $c3_每一步的帧数
  484.     ch = bitmap.height / $c3_总共可用的方向数
  485.     src_rect = Rect.new(0, 0, cw, ch)
  486.     self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
  487.   end
  488. end

  489. class Game_Character
  490.   #--------------------------------------------------------------------------
  491.   # ● 面向主角的方向
  492.   #--------------------------------------------------------------------------
  493.   def turn_toward_player
  494.     # 求得与主角的坐标差
  495.     sx = @x - $game_player.x
  496.     sy = @y - $game_player.y
  497.     # 坐标相等的场合下
  498.     if sx == 0 and sy == 0
  499.       return
  500.     end
  501.     # 横侧距离长的情况下
  502.     if sx.abs > sy.abs
  503.       # 将左右方向变更为朝向主角的方向
  504.       sx > 0 ? turn_left : turn_right
  505.     # 竖侧距离长的情况下
  506.     else
  507.       # 将上下方向变更为朝向主角的方向
  508.       sy > 0 ? turn_up : turn_down
  509.     end
  510.     if sx == -1 and sy == -1
  511.       @direction = 3
  512.       @stop_count = 0
  513.     elsif sx == -1 and sy == 1
  514.       @direction = 9
  515.       @stop_count = 0
  516.     elsif sx == 1 and sy == -1
  517.       @direction = 1
  518.       @stop_count = 0
  519.     elsif sx == 1 and sy == 1
  520.       @direction = 7
  521.       @stop_count = 0
  522.     end
  523.   end
  524. end

  525. #==============================================================================
  526. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  527. #==============================================================================
复制代码

作者: 仙芋    时间: 2010-7-3 11:39
回复 jhhuang 的帖子
現在可以了
謝謝




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