幻想森林

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1802|回复: 0

[RMXP] 求对事件绕圈脚本的速度优化!

[复制链接]

40

主题

190

帖子

1635

积分

⑥精研

●~  ●~   ●

积分
1635
发表于 2010-5-31 14:21:09 | 显示全部楼层 |阅读模式
以下脚本的功能是让一个事件围绕主角转圈子,但是对游戏速度影响比较大,在我的电脑上测试游戏,不用此脚本帧数34左右,用了帧数8左右,相差二十几帧,又不想放弃这个效果。。求速度优化!


比如让33号事件绕主角转圈:
运行$game_map.events[33].rotation($game_player, 96, 6)
$game_player是围绕的对象
96是半径
6是绕圈的速度


  1. class Game_Character
  2. alias :plus_initialize :initialize
  3. alias :plus_screen_x :screen_x
  4. alias :plus_screen_y :screen_y
  5. alias :plus_screen_z :screen_z
  6. def initialize(*avgc)
  7. plus_initialize(*avgc)
  8. @rotating = false # 旋转中?
  9. @rotation_object = nil # 围绕的对象
  10. @rotation_radius = 0 # 旋转半径
  11. @rotation_speed = 0 # 旋转速度
  12. @rotation_count = 0 # 旋转计数
  13. end
  14. # rotating?
  15. def rotating?
  16. return @rotating
  17. end
  18. # object : Game_Character
  19. # radius : Int
  20. def rotation(object, radius, speed)
  21. @rotation_object = object
  22. @rotation_radius = radius
  23. @rotation_speed = speed
  24. @rotating = true
  25. end
  26. def stop_rotation
  27. @rotating = false
  28. @rotation_object = nil
  29. @rotation_radius = 0
  30. @rotation_speed = 0
  31. @rotation_count = 0
  32. end
  33. def update_rotating
  34. @rotation_count += @rotation_speed
  35. end
  36. def rota_screen_x
  37. return @rotation_object.screen_x + Math.cos(@rotation_count * Math::PI / 180) * @rotation_radius
  38. end
  39. def rota_screen_y
  40. return @rotation_object.screen_y + Math.sin(@rotation_count * Math::PI / 180) * @rotation_radius
  41. end
  42. def rota_screen_z
  43. return 9999
  44. end
  45. #--------------------------------------------------------------------------
  46. # ● 获取画面 X 坐标
  47. #--------------------------------------------------------------------------
  48. def screen_x
  49. if rotating?
  50. rota_screen_x
  51. else
  52. plus_screen_x
  53. end
  54. end
  55. #--------------------------------------------------------------------------
  56. # ● 获取画面 Y 坐标
  57. #--------------------------------------------------------------------------
  58. def screen_y
  59. if rotating?
  60. rota_screen_y
  61. else
  62. plus_screen_y
  63. end
  64. end
  65. #--------------------------------------------------------------------------
  66. # ● 获取画面 Z 坐标
  67. # height : 角色的高度
  68. #--------------------------------------------------------------------------
  69. def screen_z(height = 0)
  70. if rotating?
  71. rota_screen_z
  72. else
  73. plus_screen_z(height)
  74. end
  75. end
  76. #--------------------------------------------------------------------------
  77. # ● 刷新画面
  78. #--------------------------------------------------------------------------
  79. def update
  80. # 跳跃中、移动中、停止中的分支
  81. if jumping?
  82. update_jump
  83. elsif moving?
  84. update_move
  85. elsif rotating?
  86. update_rotating
  87. else
  88. update_stop
  89. end
  90. # 动画计数超过最大值的情况下
  91. # ※最大值等于基本值减去移动速度 * 1 的值
  92. if @anime_count > 18 - @move_speed * 2
  93. # 停止动画为 OFF 并且在停止中的情况下
  94. if not @step_anime and @stop_count > 0
  95. # 还原为原来的图形
  96. @pattern = @original_pattern
  97. # 停止动画为 ON 并且在移动中的情况下
  98. else
  99. # 更新图形
  100. @pattern = (@pattern + 1) % 4
  101. end
  102. # 清除动画计数
  103. @anime_count = 0
  104. end
  105. # 等待中的情况下
  106. if @wait_count > 0
  107. # 减少等待计数
  108. @wait_count -= 1
  109. return
  110. end
  111. # 强制移动路线的场合
  112. if @move_route_forcing
  113. # 自定义移动
  114. move_type_custom
  115. return
  116. end
  117. # 事件执行待机中并且为锁定状态的情况下
  118. if @starting or lock?
  119. # 不做规则移动
  120. return
  121. end
  122. # 如果停止计数超过了一定的值(由移动频度算出)
  123. if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
  124. # 移动类型分支
  125. case @move_type
  126. when 1 # 随机
  127. move_type_random
  128. when 2 # 接近
  129. move_type_toward_player
  130. when 3 # 自定义
  131. move_type_custom
  132. end
  133. end
  134. # 环绕魔法的命中调用公共事件判定
  135. for i in 1..20
  136. next if $game_self_switches[[$game_map.map_id,i,"C"]] == true or !$game_map.events[i].name.include?("敌人")
  137. if ($game_map.events[33].screen_x - $game_map.events[i].screen_x).abs <= 10 and ($game_map.events[33].screen_y - $game_map.events[i].screen_y).abs <= 10
  138. $game_map.events[i].animation_id = 300
  139. end
  140. end
  141. end
  142. end
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|幻想森林

GMT+8, 2024-5-15 00:30 , Processed in 0.020912 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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