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

Project1

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

[已经过期] RMXP队伍跟随问题。。求大神

[复制链接]

Lv1.梦旅人

梦石
0
星屑
85
在线时间
210 小时
注册时间
2013-7-26
帖子
346
跳转到指定楼层
1
发表于 2015-1-15 21:45:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
我写的队员跟随脚本,八方向。。。结果失败了。。。
怎么办? 我用了正切一次函数。。。
  1.   #--------------------------------------------------------------------------
  2.   # ● 队员跟随 头像
  3.   #--------------------------------------------------------------------------
  4.   def 队员跟随生成
  5.     return if $队员跟随 == false
  6.     @队员跟随 = Sprite.new
  7.     @队员跟随.bitmap = Bitmap.new(640,480)
  8.     队员跟随检测
  9.   end
  10.   def 队员跟随释放
  11.     return if @队员跟随.bitmap.disposed? == true
  12.     @队员跟随 .bitmap.dispose
  13.     @队员跟随.dispose
  14.   end
  15.   def 队员跟随检测
  16.     return if $队员跟随 == false
  17.     @队员,@队员x,@队员y,@队员id = [],[],[],[]
  18.     for i in 1..4
  19.       @队员[i] = false
  20.     end
  21.     a = 1
  22.     for i in 1...$game_party.actors.size
  23.       if $game_party.actors[i].id < 50
  24.         @队员[a] = true
  25.         @队员id[a] = $game_party.actors[i].id
  26.         a += 1
  27.       end
  28.     end
  29.     for i in 1..4
  30.       @队员x[i],@队员y[i] = $game_player.screen_x,$game_player.screen_y
  31.     end
  32.   end
  33.   def 队员跟随更新
  34.     return if $队员跟随 == false
  35.     @队员跟随.bitmap.clear
  36.     s = 0
  37.     for i in 1..4
  38.       s += 1 if @队员[i] == true
  39.     end
  40.     @队员x[0],@队员y[0] = $game_player.screen_x,$game_player.screen_y
  41.     for i in 0...s
  42.       #判断方向
  43.       w = @队员x[i] - @队员x[i + 1]
  44.       h = @队员y[i] - @队员y[i + 1]
  45.       h *= - 1.0
  46.       a,b = 2.414235624,0.414235624
  47.       if w == 0
  48.         c = w / h
  49.       else
  50.         c = h / w
  51.       end
  52.       if - b <= c and c < b
  53.         if w > 0
  54.           #右边
  55.           d = 3
  56.         else
  57.           #左边
  58.           d = 2
  59.         end
  60.       elsif b <= c and c < a
  61.         if w > 0
  62.           #右上
  63.           d = 8
  64.         else
  65.           #左下
  66.           d = 5
  67.         end
  68.       elsif a <= c and c < - a
  69.         if h > 0
  70.           #上
  71.           d = 4
  72.         else
  73.           #下
  74.           d = 1
  75.         end
  76.       elsif - a <= c and c < - b
  77.         if w > 0
  78.           #右下
  79.           d = 6
  80.         else
  81.           #左上
  82.           d = 7
  83.         end
  84.       else
  85.         d = 1
  86.       end
  87.       #判断移动与待机
  88.       if w > 50 or
  89.          w < - 50 or
  90.          h > 50 or
  91.          h < - 50
  92.          for x in 1..w
  93.            @队员x[i + 1] = x + @队员x[i]
  94.            @队员y[i + 1] = x * c + @队员y[i]
  95.          end
  96.          @队员跟随.bitmap.sailcat_draw_text(@队员x[i + 1],@队员y[i + 1],200,30,$game_actors[@队员id[i + 1]].name,0)
  97.          #移动情况
  98.        else
  99.          @队员跟随.bitmap.sailcat_draw_text(@队员x[i + 1],@队员y[i + 1],200,30,$game_actors[@队员id[i + 1]].name,0)
  100.          #待机情况
  101.       end
  102.     end
  103.   end
  104.   #--------------------------------------------------------------------------
  105.   # ● 队员跟随 头像 末尾
  106.   #--------------------------------------------------------------------------
复制代码

点评

这不就是八方的吗  发表于 2015-1-16 18:31

Lv2.观梦者

梦石
0
星屑
380
在线时间
602 小时
注册时间
2014-5-8
帖子
699
2
发表于 2015-1-16 13:45:08 | 只看该作者
这种东西明明就有,干嘛自己动手呢
  1. #===================================================================
  2. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  3. #===================================================================
  4. # ————————————————————————————————————
  5. # ▼▲▼ XRXS13. パーティ列車移動 ver.1.02 ▼▲▼
  6. # by fukuyama
  7. #
  8. # Train_Actor
  9. #
  10. # [email protected]
  11. # http://www4.big.or.jp/~fukuyama/rgss/Train_Actor.txt
  12. #
  13. module Train_Actor

  14.   #是否使用停止跟随的方法,也就是说,这里false改为true的时候,如果TRANSPARENT_SWITCHES_INDEX
  15.   #开关打开,跟随的人物就消失了(其实只是变成透明而已)
  16.   TRANSPARENT_SWITCH = true
  17.   TRANSPARENT_SWITCHES_INDEX = 20
  18.   #举例:第一个为true,第二个为20,则打开20号开关,后面的人都没了。

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

  21.   # 定数
  22.   #Input::DOWN = 2
  23.   #Input::LEFT = 4
  24.   #Input::RIGHT = 6
  25.   #Input::UP = 6
  26.   DOWN_LEFT = 1
  27.   DOWN_RIGHT = 3
  28.   UP_LEFT = 7
  29.   UP_RIGHT = 9
  30.   JUMP = 5

  31.   class Game_Party_Actor < Game_Character
  32.    
  33.     def initialize
  34.         super()

  35.         @through = true
  36.     end
  37.       
  38.     def setup(actor)

  39.         # キャラクターのファイル名と色相を設定
  40.         if actor != nil
  41.            @character_name = actor.character_name
  42.            @character_hue = actor.character_hue
  43.            @tempneme = actor.name           
  44.         else
  45.            @character_name = ""
  46.            @character_hue = 0
  47.            @tempneme = ""      
  48.         end
  49.         # 不透明度と合成方法を初期化
  50.         @opacity = 255
  51.         @blend_type = 0
  52.     end

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

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

点评

谢谢  发表于 2015-1-16 21:40
有木有八方向的? 最好还有待机动画的?  发表于 2015-1-16 17:59
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
85
在线时间
210 小时
注册时间
2013-7-26
帖子
346
3
 楼主| 发表于 2015-1-16 21:53:44 | 只看该作者
如何向左上 右上 左下 右下 移动
   待机动画的名称为  行走图名称+"_W1"
@RyanBern
@布罗利
  1. #==============================================================================
  2. # ■ Game_Character (分割定义 1)
  3. #------------------------------------------------------------------------------
  4. #  处理角色的类。本类作为 Game_Player 类与 Game_Event
  5. # 类的超级类使用。
  6. #==============================================================================

  7. class Game_Character
  8.   #--------------------------------------------------------------------------
  9.   # ● 定义实例变量
  10.   #--------------------------------------------------------------------------
  11.   attr_reader   :id                       # ID
  12.   attr_reader   :x                        # 地图 X 坐标 (理论坐标)
  13.   attr_reader   :y                        # 地图 Y 坐标 (理论坐标)
  14.   attr_reader   :real_x                   # 地图 X 坐标 (实际坐标 * 128)
  15.   attr_reader   :real_y                   # 地图 Y 坐标 (实际坐标 * 128)
  16.   attr_reader   :tile_id                  # 元件 ID  (0 为无效)
  17.   attr_reader   :character_name           # 角色 文件名
  18.   attr_reader   :character_hue            # 角色 色相
  19.   attr_reader   :opacity                  # 不透明度
  20.   attr_reader   :blend_type               # 合成方式
  21.   attr_reader   :direction                # 朝向
  22.   attr_reader   :pattern                  # 图案
  23.   attr_reader   :move_route_forcing       # 移动路线强制标志
  24.   attr_reader   :through                  # 穿透
  25.   attr_accessor :animation_id             # 动画 ID
  26.   attr_accessor :transparent              # 透明状态
  27.   #--------------------------------------------------------------------------
  28.   # ● 初始化对像
  29.   #--------------------------------------------------------------------------
  30.   def initialize
  31.     @id = 0
  32.     @x = 0
  33.     @y = 0
  34.     @real_x = 0
  35.     @real_y = 0
  36.     @tile_id = 0
  37.     @character_name = ""
  38.     @character_hue = 0
  39.     @opacity = 255
  40.     @blend_type = 0
  41.     @direction = 2
  42.     @pattern = 0
  43.     @move_route_forcing = false
  44.     @through = false
  45.     @animation_id = 0
  46.     @transparent = false
  47.     @original_direction = 2
  48.     @original_pattern = 0
  49.     @move_type = 0
  50.     @move_speed = 3
  51.     @move_frequency = 6
  52.     @move_route = nil
  53.     @move_route_index = 0
  54.     @original_move_route = nil
  55.     @original_move_route_index = 0
  56.     @walk_anime = true
  57.     @step_anime = false
  58.     @direction_fix = false
  59.     @always_on_top = false
  60.     @anime_count = 0
  61.     @stop_count = 0
  62.     @jump_count = 0
  63.     @jump_peak = 0
  64.     @wait_count = 0
  65.     @locked = false
  66.     @prelock_direction = 0
  67.   end
  68.   #--------------------------------------------------------------------------
  69.   # ● 移动中判定
  70.   #--------------------------------------------------------------------------
  71.   def moving?
  72.     # 如果在移动中理论坐标与实际坐标不同
  73.     return (@real_x != @x * 128 or @real_y != @y * 128)
  74.   end
  75.   #--------------------------------------------------------------------------
  76.   # ● 跳跃中判定
  77.   #--------------------------------------------------------------------------
  78.   def jumping?
  79.     # 如果跳跃中跳跃点数比 0 大
  80.     return @jump_count > 0
  81.   end
  82.   #--------------------------------------------------------------------------
  83.   # ● 矫正姿势
  84.   #--------------------------------------------------------------------------
  85.   def straighten
  86.     # 移动时动画以及停止动画为 ON 的情况下
  87.     if @walk_anime or @step_anime
  88.       # 设置图形为 0
  89.       @pattern = 0
  90.     end
  91.     # 清除动画计数
  92.     @anime_count = 0
  93.     # 清除被锁定的向前朝向
  94.     @prelock_direction = 0
  95.   end
  96.   #--------------------------------------------------------------------------
  97.   # ● 强制移动路线
  98.   #     move_route : 新的移动路线
  99.   #--------------------------------------------------------------------------
  100.   def force_move_route(move_route)
  101.     # 保存原来的移动路线
  102.     if @original_move_route == nil
  103.       @original_move_route = @move_route
  104.       @original_move_route_index = @move_route_index
  105.     end
  106.     # 更改移动路线
  107.     @move_route = move_route
  108.     @move_route_index = 0
  109.     # 设置强制移动路线标志
  110.     @move_route_forcing = true
  111.     # 清除被锁定的向前朝向
  112.     @prelock_direction = 0
  113.     # 清除等待计数
  114.     @wait_count = 0
  115.     # 自定义移动
  116.     move_type_custom
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # ● 可以通行判定
  120.   #     x : X 坐标
  121.   #     y : Y 坐标
  122.   #     d : 方向 (0,2,4,6,8)  ※ 0 = 全方向不能通行的情况判定 (跳跃用)
  123.   #--------------------------------------------------------------------------
  124.   def passable?(x, y, d)
  125.     # 求得新的坐标
  126.     new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  127.     new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  128.     # 坐标在地图以外的情况
  129.     unless $game_map.valid?(new_x, new_y)
  130.       # 不能通行
  131.       return false
  132.     end
  133.     # 穿透是 ON 的情况下
  134.     if @through
  135.       # 可以通行
  136.       return true
  137.     end
  138.     # 移动者的元件无法来到指定方向的情况下
  139.     unless $game_map.passable?(x, y, d, self)
  140.       # 通行不可
  141.       return false
  142.     end
  143.     # 从指定方向不能进入到移动处的元件的情况下
  144.     unless $game_map.passable?(new_x, new_y, 10 - d)
  145.       # 不能通行
  146.       return false
  147.     end
  148.     # 循环全部事件
  149.     for event in $game_map.events.values
  150.       # 事件坐标于移动目标坐标一致的情况下
  151.       if event.x == new_x and event.y == new_y
  152.         # 穿透为 ON
  153.         unless event.through
  154.           # 自己就是事件的情况下
  155.           if self != $game_player
  156.             # 不能通行
  157.             return false
  158.           end
  159.           # 自己是主角、对方的图形是角色的情况下
  160.           if event.character_name != ""
  161.             # 不能通行
  162.             return false
  163.           end
  164.         end
  165.       end
  166.     end
  167.     # 主角的坐标与移动目标坐标一致的情况下
  168.     if $game_player.x == new_x and $game_player.y == new_y
  169.       # 穿透为 ON
  170.       unless $game_player.through
  171.         # 自己的图形是角色的情况下
  172.         if @character_name != ""
  173.           # 不能通行
  174.           return false
  175.         end
  176.       end
  177.     end
  178.     # 可以通行
  179.     return true
  180.   end
  181.   #--------------------------------------------------------------------------
  182.   # ● 锁定
  183.   #--------------------------------------------------------------------------
  184.   def lock
  185.     # 如果已经被锁定的情况下
  186.     if @locked
  187.       # 过程结束
  188.       return
  189.     end
  190.     # 保存锁定前的朝向
  191.     @prelock_direction = @direction
  192.     # 保存主角的朝向
  193.     turn_toward_player
  194.     # 设置锁定中标志
  195.     @locked = true
  196.   end
  197.   #--------------------------------------------------------------------------
  198.   # ● 锁定中判定
  199.   #--------------------------------------------------------------------------
  200.   def lock?
  201.     return @locked
  202.   end
  203.   #--------------------------------------------------------------------------
  204.   # ● 解除锁定
  205.   #--------------------------------------------------------------------------
  206.   def unlock
  207.     # 没有锁定的情况下
  208.     unless @locked
  209.       # 过程结束
  210.       return
  211.     end
  212.     # 清除锁定中标志
  213.     @locked = false
  214.     # 没有固定朝向的情况下
  215.     unless @direction_fix
  216.       # 如果保存了锁定前的方向
  217.       if @prelock_direction != 0
  218.         # 还原为锁定前的方向
  219.         @direction = @prelock_direction
  220.       end
  221.     end
  222.   end
  223.   #--------------------------------------------------------------------------
  224.   # ● 移动到指定位置
  225.   #     x : X 坐标
  226.   #     y : Y 坐标
  227.   #--------------------------------------------------------------------------
  228.   def moveto(x, y)
  229.     @x = x % $game_map.width
  230.     @y = y % $game_map.height
  231.     @real_x = @x * 128
  232.     @real_y = @y * 128
  233.     @prelock_direction = 0
  234.   end
  235.   #--------------------------------------------------------------------------
  236.   # ● 获取画面 X 坐标
  237.   #--------------------------------------------------------------------------
  238.   def screen_x
  239.     # 通过实际坐标和地图的显示位置来求得画面坐标
  240.     return (@real_x - $game_map.display_x + 3) / 4 + 16
  241.   end
  242.   #--------------------------------------------------------------------------
  243.   # ● 获取画面 Y 坐标
  244.   #--------------------------------------------------------------------------
  245.   def screen_y
  246.     # 通过实际坐标和地图的显示位置来求得画面坐标
  247.     y = (@real_y - $game_map.display_y + 3) / 4 + 32
  248.     # 取跳跃计数小的 Y 坐标
  249.     if @jump_count >= @jump_peak
  250.       n = @jump_count - @jump_peak
  251.     else
  252.       n = @jump_peak - @jump_count
  253.     end
  254.     return y - (@jump_peak * @jump_peak - n * n) / 2
  255.   end
  256.   #--------------------------------------------------------------------------
  257.   # ● 获取画面 Z 坐标
  258.   #     height : 角色的高度
  259.   #--------------------------------------------------------------------------
  260.   def screen_z(height = 0)
  261.     # 在最前显示的标志为 ON 的情况下
  262.     if @always_on_top
  263.       # 无条件设置为 999
  264.       return 999
  265.     end
  266.     # 通过实际坐标和地图的显示位置来求得画面坐标
  267.     z = (@real_y - $game_map.display_y + 3) / 4 + 32
  268.     # 元件的情况下
  269.     if @tile_id > 0
  270.       # 元件的优先不足 * 32
  271.       return z + $game_map.priorities[@tile_id] * 32
  272.     # 角色的场合
  273.     else
  274.       # 如果高度超过 32 就判定为满足 31
  275.       return z + ((height > 32) ? 31 : 0)
  276.     end
  277.   end
  278.   #--------------------------------------------------------------------------
  279.   # ● 取得茂密
  280.   #--------------------------------------------------------------------------
  281.   def bush_depth
  282.     # 是元件、并且在最前显示为 ON 的情况下
  283.     if @tile_id > 0 or @always_on_top
  284.       return 0
  285.     end
  286.     # 以跳跃中以外要是繁茂处属性的元件为 12,除此之外为 0
  287.     if @jump_count == 0 and $game_map.bush?(@x, @y)
  288.       return 12
  289.     else
  290.       return 0
  291.     end
  292.   end
  293.   #--------------------------------------------------------------------------
  294.   # ● 取得地形标记
  295.   #--------------------------------------------------------------------------
  296.   def terrain_tag
  297.     return $game_map.terrain_tag(@x, @y)
  298.   end
  299. end
复制代码
  1. #==============================================================================
  2. # ■ Game_Character (分割定义 2)
  3. #------------------------------------------------------------------------------
  4. #  处理角色的类。本类作为 Game_Player 类与 Game_Event
  5. # 类的超级类使用。
  6. #==============================================================================

  7. class Game_Character
  8.   #--------------------------------------------------------------------------
  9.   # ● 刷新画面
  10.   #--------------------------------------------------------------------------
  11.   def update
  12.     # 跳跃中、移动中、停止中的分支
  13.     if jumping?
  14.       update_jump
  15.     elsif moving?
  16.       update_move
  17.     else
  18.       update_stop
  19.     end
  20.     # 动画计数超过最大值的情况下
  21.     # ※最大值等于基本值减去移动速度 * 1 的值
  22.     if @anime_count > 18 - @move_speed * 2
  23.       # 停止动画为 OFF 并且在停止中的情况下
  24.       if not @step_anime and @stop_count > 0
  25.         # 还原为原来的图形
  26.         @pattern = @original_pattern
  27.       # 停止动画为 ON 并且在移动中的情况下
  28.       else
  29.         # 更新图形
  30.         @pattern = (@pattern + 1) % 4
  31.       end
  32.       # 清除动画计数
  33.       @anime_count = 0
  34.     end
  35.     # 等待中的情况下
  36.     if @wait_count > 0
  37.       # 减少等待计数
  38.       @wait_count -= 1
  39.       return
  40.     end
  41.     # 强制移动路线的场合
  42.     if @move_route_forcing
  43.       # 自定义移动
  44.       move_type_custom
  45.       return
  46.     end
  47.     # 事件执行待机中并且为锁定状态的情况下
  48.     if @starting or lock?
  49.       # 不做规则移动
  50.       return
  51.     end
  52.     # 如果停止计数超过了一定的值(由移动频度算出)
  53.     if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
  54.       # 移动类型分支
  55.       case @move_type
  56.       when 1  # 随机
  57.         move_type_random
  58.       when 2  # 接近
  59.         move_type_toward_player
  60.       when 3  # 自定义
  61.         move_type_custom
  62.       end
  63.     end
  64.   end
  65.   #--------------------------------------------------------------------------
  66.   # ● 更新画面 (跳跃)
  67.   #--------------------------------------------------------------------------
  68.   def update_jump
  69.     # 跳跃计数减 1
  70.     @jump_count -= 1
  71.     # 计算新坐标
  72.     @real_x = (@real_x * @jump_count + @x * 128) / (@jump_count + 1)
  73.     @real_y = (@real_y * @jump_count + @y * 128) / (@jump_count + 1)
  74.   end
  75.   #--------------------------------------------------------------------------
  76.   # ● 更新画面 (移动)
  77.   #--------------------------------------------------------------------------
  78.   def update_move
  79.     # 移动速度转换为地图坐标系的移动距离
  80.     distance = (2 ** @move_speed) #+ 5
  81.     if self.is_a?(Game_Player)
  82.       distance = (2 ** @move_speed) + 8
  83.     end
  84.     # 理论坐标在实际坐标下方的情况下
  85.     if @y * 128 > @real_y
  86.       # 向下移动
  87.       @real_y = [@real_y + distance, @y * 128].min
  88.     end
  89.     # 理论坐标在实际坐标左方的情况下
  90.     if @x * 128 < @real_x
  91.       # 向左移动
  92.       @real_x = [@real_x - distance, @x * 128].max
  93.     end
  94.     # 理论坐标在实际坐标右方的情况下
  95.     if @x * 128 > @real_x
  96.       # 向右移动
  97.       @real_x = [@real_x + distance, @x * 128].min
  98.     end
  99.     # 理论坐标在实际坐标上方的情况下
  100.     if @y * 128 < @real_y
  101.       # 向上移动
  102.       @real_y = [@real_y - distance, @y * 128].max
  103.     end
  104.     # 移动时动画为 ON 的情况下
  105.     if @walk_anime
  106.       # 动画计数增加 1.5
  107.       @anime_count += 1.5
  108.     # 移动时动画为 OFF、停止时动画为 ON 的情况下
  109.     elsif @step_anime
  110.       # 动画计数增加 1
  111.       @anime_count += 1
  112.     end
  113.   end
  114.   #--------------------------------------------------------------------------
  115.   # ● 更新画面 (停止)
  116.   #--------------------------------------------------------------------------
  117.   def update_stop
  118.     # 停止时动画为 ON 的情况下
  119.     if @step_anime
  120.       # 动画计数增加 1
  121.       @anime_count += 1
  122.     # 停止时动画为 OFF 并且、现在的图像与原来的不同的情况下
  123.     elsif @pattern != @original_pattern
  124.       # 动画计数增加 1.5
  125.       @anime_count += 1.5
  126.     end
  127.     # 事件执行待机中并且不是锁定状态的情况下
  128.     # ※缩定、处理成立刻停止执行中的事件
  129.     unless @starting or lock?
  130.       # 停止计数增加 1
  131.       @stop_count += 1
  132.     end
  133.   end
  134.   #--------------------------------------------------------------------------
  135.   # ● 移动类型 : 随机
  136.   #--------------------------------------------------------------------------
  137.   def move_type_random
  138.     # 随机 0~5 的分支
  139.     case rand(6)
  140.     when 0..3  # 随机
  141.       move_random
  142.     when 4  # 前进一步
  143.       move_forward
  144.     when 5  # 暂时停止
  145.       @stop_count = 0
  146.     end
  147.   end
  148.   #--------------------------------------------------------------------------
  149.   # ● 移动类型 : 接近
  150.   #--------------------------------------------------------------------------
  151.   def move_type_toward_player
  152.     # 求得与主角坐标的差
  153.     sx = @x - $game_player.x
  154.     sy = @y - $game_player.y
  155.     # 求得差的绝对值
  156.     abs_sx = sx > 0 ? sx : -sx
  157.     abs_sy = sy > 0 ? sy : -sy
  158.     # 如果纵横共计离开 20 个元件
  159.     if sx + sy >= 20
  160.       # 随机
  161.       move_random
  162.       return
  163.     end
  164.     # 随机 0~5 的分支
  165.     case rand(6)
  166.     when 0..3  # 接近主角
  167.       move_toward_player
  168.     when 4  # 随机
  169.       move_random
  170.     when 5  # 前进一步
  171.       move_forward
  172.     end
  173.   end
  174.   #--------------------------------------------------------------------------
  175.   # ● 移动类型 : 自定义
  176.   #--------------------------------------------------------------------------
  177.   def move_type_custom
  178.     # 如果不是停止中就中断
  179.     if jumping? or moving?
  180.       return
  181.     end
  182.     # 如果在移动指令列表最后结束还没到达就循环执行
  183.     while @move_route_index < @move_route.list.size
  184.       # 获取移动指令
  185.       command = @move_route.list[@move_route_index]
  186.       # 指令编号 0 号 (列表最后) 的情况下
  187.       if command.code == 0
  188.         # 选项 [反复动作] 为 ON 的情况下
  189.         if @move_route.repeat
  190.           # 还原为移动路线的最初索引
  191.           @move_route_index = 0
  192.         end
  193.         # 选项 [反复动作] 为 OFF 的情况下
  194.         unless @move_route.repeat
  195.           # 强制移动路线的场合
  196.           if @move_route_forcing and not @move_route.repeat
  197.             # 强制解除移动路线
  198.             @move_route_forcing = false
  199.             # 还原为原始的移动路线
  200.             @move_route = @original_move_route
  201.             @move_route_index = @original_move_route_index
  202.             @original_move_route = nil
  203.           end
  204.           # 清除停止计数
  205.           @stop_count = 0
  206.         end
  207.         return
  208.       end
  209.       # 移动系指令 (向下移动~跳跃) 的情况下
  210.       if command.code <= 14
  211.         # 命令编号分支
  212.         case command.code
  213.         when 1  # 向下移动
  214.           move_down
  215.         when 2  # 向左移动
  216.           move_left
  217.         when 3  # 向右移动
  218.           move_right
  219.         when 4  # 向上移动
  220.           move_up
  221.         when 5  # 向左下移动
  222.           move_lower_left
  223.         when 6  # 向右下移动
  224.           move_lower_right
  225.         when 7  # 向左上移动
  226.           move_upper_left
  227.         when 8  # 向右上
  228.           move_upper_right
  229.         when 9  # 随机移动
  230.           move_random
  231.         when 10  # 接近主角
  232.           move_toward_player
  233.         when 11  # 远离主角
  234.           move_away_from_player
  235.         when 12  # 前进一步
  236.           move_forward
  237.         when 13  # 后退一步
  238.           move_backward
  239.         when 14  # 跳跃
  240.           jump(command.parameters[0], command.parameters[1])
  241.         end
  242.         # 选项 [无视无法移动的情况] 为 OFF 、移动失败的情况下
  243.         if not @move_route.skippable and not moving? and not jumping?
  244.           return
  245.         end
  246.         @move_route_index += 1
  247.         return
  248.       end
  249.       # 等待的情况下
  250.       if command.code == 15
  251.         # 设置等待计数
  252.         @wait_count = command.parameters[0] * 2 - 1
  253.         @move_route_index += 1
  254.         return
  255.       end
  256.       # 朝向变更系指令的情况下
  257.       if command.code >= 16 and command.code <= 26
  258.         # 命令编号分支
  259.         case command.code
  260.         when 16  # 面向下
  261.           turn_down
  262.         when 17  # 面向左
  263.           turn_left
  264.         when 18  # 面向右
  265.           turn_right
  266.         when 19  # 面向上
  267.           turn_up
  268.         when 20  # 向右转 90 度
  269.           turn_right_90
  270.         when 21  # 向左转 90 度
  271.           turn_left_90
  272.         when 22  # 旋转 180 度
  273.           turn_180
  274.         when 23  # 从右向左转 90 度
  275.           turn_right_or_left_90
  276.         when 24  # 随机变换方向
  277.           turn_random
  278.         when 25  # 面向主角的方向
  279.           turn_toward_player
  280.         when 26  # 背向主角的方向
  281.           turn_away_from_player
  282.         end
  283.         @move_route_index += 1
  284.         return
  285.       end
  286.       # 其它指令的场合
  287.       if command.code >= 27
  288.         # 命令编号分支
  289.         case command.code
  290.         when 27  # 开关 ON
  291.           $game_switches[command.parameters[0]] = true
  292.           $game_map.need_refresh = true
  293.         when 28  # 开关 OFF
  294.           $game_switches[command.parameters[0]] = false
  295.           $game_map.need_refresh = true
  296.         when 29  # 更改移动速度
  297.           @move_speed = command.parameters[0]
  298.         when 30  # 更改移动频度
  299.           @move_frequency = command.parameters[0]
  300.         when 31  # 移动时动画 ON
  301.           @walk_anime = true
  302.         when 32  # 移动时动画 OFF
  303.           @walk_anime = false
  304.         when 33  # 停止时动画 ON
  305.           @step_anime = true
  306.         when 34  # 停止时动画 OFF
  307.           @step_anime = false
  308.         when 35  # 朝向固定 ON
  309.           @direction_fix = true
  310.         when 36  # 朝向固定 OFF
  311.           @direction_fix = false
  312.         when 37  # 穿透 ON
  313.           @through = true
  314.         when 38  # 穿透 OFF
  315.           @through = false
  316.         when 39  # 在最前面显示 ON
  317.           @always_on_top = true
  318.         when 40  # 在最前面显示 OFF
  319.           @always_on_top = false
  320.         when 41  # 更改图形
  321.           @tile_id = 0
  322.           @character_name = command.parameters[0]
  323.           @character_hue = command.parameters[1]
  324.           if @original_direction != command.parameters[2]
  325.             @direction = command.parameters[2]
  326.             @original_direction = @direction
  327.             @prelock_direction = 0
  328.           end
  329.           if @original_pattern != command.parameters[3]
  330.             @pattern = command.parameters[3]
  331.             @original_pattern = @pattern
  332.           end
  333.         when 42  # 不更改不透明度
  334.           @opacity = command.parameters[0]
  335.         when 43  # 更改合成方式
  336.           @blend_type = command.parameters[0]
  337.         when 44  # 演奏 SE
  338.           $game_system.se_play(command.parameters[0])
  339.         when 45  # 脚本
  340.           result = eval(command.parameters[0])
  341.         end
  342.         @move_route_index += 1
  343.       end
  344.     end
  345.   end
  346.   #--------------------------------------------------------------------------
  347.   # ● 增加步数
  348.   #--------------------------------------------------------------------------
  349.   def increase_steps
  350.     # 清除停止步数
  351.     @stop_count = 0
  352.   end
  353. end
复制代码
  1. #==============================================================================
  2. # ■ Game_Character (分割定义 3)
  3. #------------------------------------------------------------------------------
  4. #  处理角色的类。本类作为 Game_Player 类与 Game_Event
  5. # 类的超级类使用。
  6. #==============================================================================

  7. class Game_Character
  8.   #--------------------------------------------------------------------------
  9.   # ● 向下移动
  10.   #     turn_enabled : 本场地位置更改许可标志
  11.   #--------------------------------------------------------------------------
  12.   def move_down(turn_enabled = true)
  13.     # 面向下
  14.     if turn_enabled
  15.       turn_down
  16.     end
  17.     # 可以通行的场合
  18.     if passable?(@x, @y, 2)
  19.       # 面向下
  20.       turn_down
  21.       # 更新坐标
  22.       @y += 1
  23.       # 增加步数
  24.       increase_steps
  25.     # 不能通行的情况下
  26.     else
  27.       # 接触事件的启动判定
  28.       check_event_trigger_touch(@x, @y+1)
  29.     end
  30.   end
  31.   #--------------------------------------------------------------------------
  32.   # ● 向左移动
  33.   #     turn_enabled : 本场地位置更改许可标志
  34.   #--------------------------------------------------------------------------
  35.   def move_left(turn_enabled = true)
  36.     # 面向左
  37.     if turn_enabled
  38.       turn_left
  39.     end
  40.     # 可以通行的情况下
  41.     if passable?(@x, @y, 4)
  42.       # 面向左
  43.       turn_left
  44.       # 更新坐标
  45.       @x -= 1
  46.       # 增加步数
  47.       increase_steps
  48.     # 不能通行的情况下
  49.     else
  50.       # 接触事件的启动判定
  51.       check_event_trigger_touch(@x-1, @y)
  52.     end
  53.   end
  54.   #--------------------------------------------------------------------------
  55.   # ● 向右移动
  56.   #     turn_enabled : 本场地位置更改许可标志
  57.   #--------------------------------------------------------------------------
  58.   def move_right(turn_enabled = true)
  59.     # 面向右
  60.     if turn_enabled
  61.       turn_right
  62.     end
  63.     # 可以通行的场合
  64.     if passable?(@x, @y, 6)
  65.       # 面向右
  66.       turn_right
  67.       # 更新坐标
  68.       @x += 1
  69.       # 增加部数
  70.       increase_steps
  71.     # 不能通行的情况下
  72.     else
  73.       # 接触事件的启动判定
  74.       check_event_trigger_touch(@x+1, @y)
  75.     end
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # ● 向上移动
  79.   #     turn_enabled : 本场地位置更改许可标志
  80.   #--------------------------------------------------------------------------
  81.   def move_up(turn_enabled = true)
  82.     # 面向上
  83.     if turn_enabled
  84.       turn_up
  85.     end
  86.     # 可以通行的情况下
  87.     if passable?(@x, @y, 8)
  88.       # 面向上
  89.       turn_up
  90.       # 更新坐标
  91.       @y -= 1
  92.       # 歩数増加
  93.       increase_steps
  94.     # 不能通行的情况下
  95.     else
  96.       # 接触事件的启动判定
  97.       check_event_trigger_touch(@x, @y-1)
  98.     end
  99.   end
  100.   #--------------------------------------------------------------------------
  101.   # ● 向左下移动
  102.   #--------------------------------------------------------------------------
  103.   def move_lower_left
  104.     # 没有固定面向的场合
  105.     unless @direction_fix
  106.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  107.       @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
  108.     end
  109.     # 下→左、左→下 的通道可以通行的情况下
  110.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
  111.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
  112.       # 更新坐标
  113.       @x -= 1
  114.       @y += 1
  115.       # 增加步数
  116.       increase_steps
  117.     end
  118.   end
  119.   #--------------------------------------------------------------------------
  120.   # ● 向右下移动
  121.   #--------------------------------------------------------------------------
  122.   def move_lower_right
  123.     # 没有固定面向的场合
  124.     unless @direction_fix
  125.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  126.       @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
  127.     end
  128.     # 下→右、右→下 的通道可以通行的情况下
  129.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
  130.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
  131.       # 更新坐标
  132.       @x += 1
  133.       @y += 1
  134.       # 增加步数
  135.       increase_steps
  136.     end
  137.   end
  138.   #--------------------------------------------------------------------------
  139.   # ● 向左上移动
  140.   #--------------------------------------------------------------------------
  141.   def move_upper_left
  142.     # 没有固定面向的场合
  143.     unless @direction_fix
  144.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  145.       @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
  146.     end
  147.     # 上→左、左→上 的通道可以通行的情况下
  148.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
  149.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
  150.       # 更新坐标
  151.       @x -= 1
  152.       @y -= 1
  153.       # 增加步数
  154.       increase_steps
  155.     end
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # ● 向右上移动
  159.   #--------------------------------------------------------------------------
  160.   def move_upper_right
  161.     # 没有固定面向的场合
  162.     unless @direction_fix
  163.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  164.       @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
  165.     end
  166.     # 上→右、右→上 的通道可以通行的情况下
  167.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
  168.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
  169.       # 更新坐标
  170.       @x += 1
  171.       @y -= 1
  172.       # 增加步数
  173.       increase_steps
  174.     end
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # ● 随机移动
  178.   #--------------------------------------------------------------------------
  179.   def move_random
  180.     case rand(4)
  181.     when 0  # 向下移动
  182.       move_down(false)
  183.     when 1  # 向左移动
  184.       move_left(false)
  185.     when 2  # 向右移动
  186.       move_right(false)
  187.     when 3  # 向上移动
  188.       move_up(false)
  189.     end
  190.   end
  191.   #--------------------------------------------------------------------------
  192.   # ● 接近主角
  193.   #--------------------------------------------------------------------------
  194.   def move_toward_player
  195.     # 求得与主角的坐标差
  196.     sx = @x - $game_player.x
  197.     sy = @y - $game_player.y
  198.     # 坐标相等情况下
  199.     if sx == 0 and sy == 0
  200.       return
  201.     end
  202.     # 求得差的绝对值
  203.     abs_sx = sx.abs
  204.     abs_sy = sy.abs
  205.     # 横距离与纵距离相等的情况下
  206.     if abs_sx == abs_sy
  207.       # 随机将边数增加 1
  208.       rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
  209.     end
  210.     # 横侧距离长的情况下
  211.     if abs_sx > abs_sy
  212.       # 左右方向优先。向主角移动
  213.       sx > 0 ? move_left : move_right
  214.       if not moving? and sy != 0
  215.         sy > 0 ? move_up : move_down
  216.       end
  217.     # 竖侧距离长的情况下
  218.     else
  219.       # 上下方向优先。向主角移动
  220.       sy > 0 ? move_up : move_down
  221.       if not moving? and sx != 0
  222.         sx > 0 ? move_left : move_right
  223.       end
  224.     end
  225.   end
  226.   #--------------------------------------------------------------------------
  227.   # ● 远离主角
  228.   #--------------------------------------------------------------------------
  229.   def move_away_from_player
  230.     # 求得与主角的坐标差
  231.     sx = @x - $game_player.x
  232.     sy = @y - $game_player.y
  233.     # 坐标相等情况下
  234.     if sx == 0 and sy == 0
  235.       return
  236.     end
  237.     # 求得差的绝对值
  238.     abs_sx = sx.abs
  239.     abs_sy = sy.abs
  240.     # 横距离与纵距离相等的情况下
  241.     if abs_sx == abs_sy
  242.       # 随机将边数增加 1
  243.       rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
  244.     end
  245.     # 横侧距离长的情况下
  246.     if abs_sx > abs_sy
  247.       # 左右方向优先。远离主角移动
  248.       sx > 0 ? move_right : move_left
  249.       if not moving? and sy != 0
  250.         sy > 0 ? move_down : move_up
  251.       end
  252.     # 竖侧距离长的情况下
  253.     else
  254.       # 上下方向优先。远离主角移动
  255.       sy > 0 ? move_down : move_up
  256.       if not moving? and sx != 0
  257.         sx > 0 ? move_right : move_left
  258.       end
  259.     end
  260.   end
  261.   #--------------------------------------------------------------------------
  262.   # ● 前进一步
  263.   #--------------------------------------------------------------------------
  264.   def move_forward
  265.     case @direction
  266.     when 2
  267.       move_down(false)
  268.     when 4
  269.       move_left(false)
  270.     when 6
  271.       move_right(false)
  272.     when 8
  273.       move_up(false)
  274.     end
  275.   end
  276.   #--------------------------------------------------------------------------
  277.   # ● 后退一步
  278.   #--------------------------------------------------------------------------
  279.   def move_backward
  280.     # 记忆朝向固定信息
  281.     last_direction_fix = @direction_fix
  282.     # 强制固定朝向
  283.     @direction_fix = true
  284.     # 朝向分支
  285.     case @direction
  286.     when 2  # 下
  287.       move_up(false)
  288.     when 4  # 左
  289.       move_right(false)
  290.     when 6  # 右
  291.       move_left(false)
  292.     when 8  # 上
  293.       move_down(false)
  294.     end
  295.     # 还原朝向固定信息
  296.     @direction_fix = last_direction_fix
  297.   end
  298.   #--------------------------------------------------------------------------
  299.   # ● 跳跃
  300.   #     x_plus : X 坐标增加值
  301.   #     y_plus : Y 坐标增加值
  302.   #--------------------------------------------------------------------------
  303.   def jump(x_plus, y_plus)
  304.     # 增加值不是 (0,0) 的情况下
  305.     if x_plus != 0 or y_plus != 0
  306.       # 横侧距离长的情况下
  307.       if x_plus.abs > y_plus.abs
  308.         # 变更左右方向
  309.         x_plus < 0 ? turn_left : turn_right
  310.       # 竖侧距离长的情况下
  311.       else
  312.         # 变更上下方向
  313.         y_plus < 0 ? turn_up : turn_down
  314.       end
  315.     end
  316.     # 计算新的坐标
  317.     new_x = @x + x_plus
  318.     new_y = @y + y_plus
  319.     # 增加值为 (0,0) 的情况下、跳跃目标可以通行的场合
  320.     if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
  321.       # 矫正姿势
  322.       straighten
  323.       # 更新坐标
  324.       @x = new_x
  325.       @y = new_y
  326.       # 距计算距离
  327.       distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
  328.       # 设置跳跃记数
  329.       @jump_peak = 10 + distance - @move_speed
  330.       @jump_count = @jump_peak * 2
  331.       # 清除停止记数信息
  332.       @stop_count = 0
  333.     end
  334.   end
  335.   #--------------------------------------------------------------------------
  336.   # ● 面向向下
  337.   #--------------------------------------------------------------------------
  338.   def turn_down
  339.     unless @direction_fix
  340.       @direction = 2
  341.       @stop_count = 0
  342.     end
  343.   end
  344.   #--------------------------------------------------------------------------
  345.   # ● 面向向左
  346.   #--------------------------------------------------------------------------
  347.   def turn_left
  348.     unless @direction_fix
  349.       @direction = 4
  350.       @stop_count = 0
  351.     end
  352.   end
  353.   #--------------------------------------------------------------------------
  354.   # ● 面向向右
  355.   #--------------------------------------------------------------------------
  356.   def turn_right
  357.     unless @direction_fix
  358.       @direction = 6
  359.       @stop_count = 0
  360.     end
  361.   end
  362.   #--------------------------------------------------------------------------
  363.   # ● 面向向上
  364.   #--------------------------------------------------------------------------
  365.   def turn_up
  366.     unless @direction_fix
  367.       @direction = 8
  368.       @stop_count = 0
  369.     end
  370.   end
  371.   #--------------------------------------------------------------------------
  372.   # ● 向右旋转 90 度
  373.   #--------------------------------------------------------------------------
  374.   def turn_right_90
  375.     case @direction
  376.     when 2
  377.       turn_left
  378.     when 4
  379.       turn_up
  380.     when 6
  381.       turn_down
  382.     when 8
  383.       turn_right
  384.     end
  385.   end
  386.   #--------------------------------------------------------------------------
  387.   # ● 向左旋转 90 度
  388.   #--------------------------------------------------------------------------
  389.   def turn_left_90
  390.     case @direction
  391.     when 2
  392.       turn_right
  393.     when 4
  394.       turn_down
  395.     when 6
  396.       turn_up
  397.     when 8
  398.       turn_left
  399.     end
  400.   end
  401.   #--------------------------------------------------------------------------
  402.   # ● 旋转 180 度
  403.   #--------------------------------------------------------------------------
  404.   def turn_180
  405.     case @direction
  406.     when 2
  407.       turn_up
  408.     when 4
  409.       turn_right
  410.     when 6
  411.       turn_left
  412.     when 8
  413.       turn_down
  414.     end
  415.   end
  416.   #--------------------------------------------------------------------------
  417.   # ● 从右向左旋转 90 度
  418.   #--------------------------------------------------------------------------
  419.   def turn_right_or_left_90
  420.     if rand(2) == 0
  421.       turn_right_90
  422.     else
  423.       turn_left_90
  424.     end
  425.   end
  426.   #--------------------------------------------------------------------------
  427.   # ● 随机变换方向
  428.   #--------------------------------------------------------------------------
  429.   def turn_random
  430.     case rand(4)
  431.     when 0
  432.       turn_up
  433.     when 1
  434.       turn_right
  435.     when 2
  436.       turn_left
  437.     when 3
  438.       turn_down
  439.     end
  440.   end
  441.   #--------------------------------------------------------------------------
  442.   # ● 接近主角的方向
  443.   #--------------------------------------------------------------------------
  444.   def turn_toward_player
  445.     # 求得与主角的坐标差
  446.     sx = @x - $game_player.x
  447.     sy = @y - $game_player.y
  448.     # 坐标相等的场合下
  449.     if sx == 0 and sy == 0
  450.       return
  451.     end
  452.     # 横侧距离长的情况下
  453.     if sx.abs > sy.abs
  454.       # 将左右方向变更为朝向主角的方向
  455.       sx > 0 ? turn_left : turn_right
  456.     # 竖侧距离长的情况下
  457.     else
  458.       # 将上下方向变更为朝向主角的方向
  459.       sy > 0 ? turn_up : turn_down
  460.     end
  461.   end
  462.   #--------------------------------------------------------------------------
  463.   # ● 背向主角的方向
  464.   #--------------------------------------------------------------------------
  465.   def turn_away_from_player
  466.     # 求得与主角的坐标差
  467.     sx = @x - $game_player.x
  468.     sy = @y - $game_player.y
  469.     # 坐标相等的场合下
  470.     if sx == 0 and sy == 0
  471.       return
  472.     end
  473.     # 横侧距离长的情况下
  474.     if sx.abs > sy.abs
  475.       # 将左右方向变更为背离主角的方向
  476.       sx > 0 ? turn_right : turn_left
  477.     # 竖侧距离长的情况下
  478.     else
  479.       # 将上下方向变更为背离主角的方向
  480.       sy > 0 ? turn_down : turn_up
  481.     end
  482.   end
  483. end
复制代码
  1. #==============================================================================
  2. # ■ Sprite_Character
  3. #------------------------------------------------------------------------------
  4. #  角色显示用脚本。监视 Game_Character 类的实例、
  5. # 自动变化脚本状态。
  6. #==============================================================================

  7. class Sprite_Character < RPG::Sprite
  8.   #--------------------------------------------------------------------------
  9.   # ● 定义实例变量
  10.   #--------------------------------------------------------------------------
  11.   attr_accessor :character                # 角色
  12.   #--------------------------------------------------------------------------
  13.   # ● 初始化对像
  14.   #     viewport  : 查看端口
  15.   #     character : 角色 (Game_Character)
  16.   #--------------------------------------------------------------------------
  17.   def initialize(viewport, character = nil)
  18.     super(viewport)
  19.     [url=home.php?mod=space&uid=2631396]@character[/url] = character
  20.     # 事件显示名字脚本加强★★★★★★★★★★★★★★★★★★★★★★★★★
  21.     name = character.name
  22.     @namesprite = Sprite.new(viewport)
  23.     @namesprite.bitmap = Bitmap.new(160, 48)
  24.     @namesprite.bitmap.font.name = "宋体"
  25.     @namesprite.bitmap.font.size = 16
  26.     @namesprite.bitmap.font.color.set(255, 250, 0, 255)      # 黄色
  27.     @evname = name
  28.     @evname_split = name.split(/,/)[0]
  29.     if name.split(/,/)[1] != nil
  30.       case name.split(/,/)[1]
  31.       when "0"
  32.         @namesprite.bitmap.font.color.set(60, 255, 80, 255)  # 绿色
  33.       when "1"
  34.         @namesprite.bitmap.font.color.set(190, 130, 0, 255)  # 橙色
  35.       when "2"
  36.         @namesprite.bitmap.font.color.set(0, 120, 210, 255)  # 蓝色
  37.       when "3"
  38.         @namesprite.bitmap.font.color.set(255, 0, 50, 255)   # 红色
  39.       end
  40.     end
  41.     if @evname_split != "" and @evname_split != nil and not $game_temp.in_battle
  42.       @namesprite.bitmap.draw_text(0, 0, 160, 36, @evname_split, 1)
  43.     end
  44.     # 事件显示名字脚本加强★★★★★★★★★★★★★★★★★★★★★★★★★
  45.     update
  46.   end
  47.   #--------------------------------------------------------------------------
  48.   # ● 更新画面
  49.   #--------------------------------------------------------------------------
  50.   def update
  51.     super
  52.     # 事件显示名字脚本加强★★★★★★★★★★★★★★★★★★★★★★★★★
  53.     if @evname != @character.name
  54.       @namesprite.bitmap.clear
  55.     end
  56.     @namesprite.x = self.x - 80    # 显示坐标
  57.     @namesprite.y = self.y - self.oy - 24 + 130  # 显示坐标
  58.     # 元件 ID、文件名、色相与现在的情况存在差异的情况下
  59.     if @tile_id != @character.tile_id or
  60.        @character_name != @character.character_name or
  61.        @character_hue != @character.character_hue
  62.       # 记忆元件 ID 与文件名、色相
  63.       @tile_id = @character.tile_id
  64.       @character_name = @character.character_name
  65.       @character_hue = @character.character_hue
  66.       # 元件 ID 为有效值的情况下
  67.       if @tile_id >= 384
  68.         self.bitmap = RPG::Cache.tile($game_map.tileset_name,
  69.           @tile_id, @character.character_hue)
  70.         self.src_rect.set(0, 0, 32, 32)
  71.         self.ox = 16
  72.         self.oy = 32
  73.       # 元件 ID 为无效值的情况下
  74.       else
  75.         self.bitmap = RPG::Cache.character(@character.character_name,
  76.           @character.character_hue)
  77.         # 素材处理★★★★★★★★★★★★★★★★★★★★★★★★★★★
  78.         # 需要使用特殊的素材文件名为识别处理的情况时!列如:
  79.         # 当素材文件名为“场所移动”时,对该素材处理方法
  80.         if @character_name == "场所移动"  
  81.           @cw = bitmap.width / 19
  82.           @ch = bitmap.height
  83.         # 除此以外,其他素材和角色行走图等素材的处理  
  84.         else   
  85.           @cw = bitmap.width / 8
  86.           @ch = bitmap.height / 8
  87.         end
  88.         # ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★   
  89.         self.ox = @cw / 2
  90.         self.oy = @ch
  91.       end
  92.     end
  93.     # 设置可视状态
  94.     self.visible = (not @character.transparent)
  95.     # 图形是角色的情况下
  96.     if @tile_id == 0
  97.       # 设置传送目标的矩形
  98.       sx = @character.pattern * @cw
  99.       # 八向素材处理★★★★★★★★★★★★★★★★★★★★★★★★★★★
  100.       # 需要使用特殊的素材文件名为识别处理的情况时!列如:
  101.         if @character_name == "场所移动"  
  102.           sy = 0 * @ch
  103.         else
  104.           case @character.direction
  105.           when 2
  106.             sy = 0 * @ch   #  下
  107.           when 4
  108.             sy = 1 * @ch   #  左
  109.           when 6
  110.             sy = 2 * @ch   #  右
  111.           when 8
  112.             sy = 3 * @ch   #  上
  113.           when 1
  114.             sy = 4 * @ch   #  左下
  115.           when 3
  116.             sy = 5 * @ch   #  右下
  117.           when 7
  118.             sy = 6 * @ch   #  左上
  119.           when 9
  120.             sy = 7 * @ch   #  右上
  121.           end
  122.         end
  123.       # ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
  124.       self.src_rect.set(sx, sy, @cw, @ch)
  125.     end
  126.     # 设置脚本的坐标
  127.     self.x = @character.screen_x
  128.     self.y = @character.screen_y
  129.     self.z = @character.screen_z(@ch)
  130.     # 设置不透明度、合成方式、茂密
  131.     self.opacity = @character.opacity
  132.     self.blend_type = @character.blend_type
  133.     self.bush_depth = @character.bush_depth
  134.     # 动画
  135.     if @character.animation_id != 0
  136.       animation = $data_animations[@character.animation_id]
  137.       animation(animation, true)
  138.       @character.animation_id = 0
  139.     end
  140.   end
  141.   def dispose
  142.     super
  143.     unless @namesprite.disposed?
  144.       @namesprite.bitmap.dispose
  145.       @namesprite.dispose
  146.     end
  147.   end
  148. end
复制代码
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-9-22 15:48

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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