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

Project1

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

[有事请教] 求助!关于Theo - 终极防止卡顿脚本使用时报错问题

[复制链接]

Lv2.观梦者

梦石
0
星屑
847
在线时间
147 小时
注册时间
2019-9-17
帖子
19
跳转到指定楼层
1
50星屑
如图,本人在使用Theo防卡顿脚本时点击开始游戏后报错。为排除脚本冲突原因,特开了一个新建项目,只放了核心脚本与该脚本,结果还是报错。。。求助各位大佬帮忙指点一下QAQ
核心脚本:
  1. # =============================================================================
  2. # TheoAllen - 基础模块
  3. # 版本 : 1.5d
  4. # 联系方式 : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # 作者 : TheoAllen (初始编写者)
  6. # 汉化:Nil2018(○┰○)、MireniamuYuki
  7. # =============================================================================
  8. $imported = {} if $imported.nil?
  9. # =============================================================================
  10. # 本脚本是我个人的模块,用于脚本/系统的开发.无论是小实验还是大系统都便于我编写
  11. # 脚本.
  12. #
  13. # 然而,我的脚本并不是全部都需要基础模块,大部分不需要,其他的则需要。
  14. # -----------------------------------------------------------------------------
  15. # 模块包括 :
  16. # =============================================================================
  17. $imported[:Theo_BasicFuntions] = true  # 基础功能
  18. $imported[:Theo_BitmapAddons]  = true  # 位图额外插件
  19. $imported[:Theo_CoreDamage]    = true  # 核心伤害处理
  20. $imported[:Theo_CoreResult]    = true  # 核心伤害结果
  21. $imported[:Theo_Movement]      = true  # 对象核心移动
  22. $imported[:Theo_CoreFade]      = true  # 对象核心淡入淡出
  23. $imported[:Theo_Circular]      = true  # 对象循环移动
  24. $imported[:Theo_CloneImage]    = true  # 克隆图像. 残影的基础
  25. $imported[:Theo_RotateImage]   = true  # 转动精灵
  26. $imported[:Theo_SmoothMove]    = true  # 对象平滑移动
  27. # =============================================================================
  28. # 写给使用者:
  29. # -----------------------------------------------------------------------------
  30. # 本脚本作为基础脚本,意味着需要将本脚本放在其他自定义脚本之上.
  31. #
  32. # 我知道基础模块可能会与其他脚本不兼容,其实我的脚本并不是都需要基础模块.
  33. # 只要是需要基础模块的脚本我都会给予提示,为了提供更多的兼容性,你可以将需要禁
  34. # 用的功能设定为false.
  35. #
  36. # =============================================================================
  37. # 写给脚本师 :
  38. # -----------------------------------------------------------------------------
  39. # 下面就是脚本的各个部件.
  40. #
  41. # 如果你想要改善基础模块,可以任意编辑此脚本,请告诉我你编辑了哪些地方.
  42. # 我很乐意见到脚本师为基础模块做出改良.
  43. #
  44. # 如果你改良了基础模块,你可以在作者中署名。但请记住,基础模块不应该对默认脚本
  45. # 造成任何影响.仅为其他脚本提供可能需要的基础功能.
  46. # =============================================================================
  47. # 已知不兼容 :
  48. # >> Modern Algebra - Bitmap Addons (需要关闭"位图额外插件")
  49. # >> Tsukihime - Core Damage (需要关闭"核心伤害处理")
  50. # >> YEA - Lunatic Damage 疯狂的伤害 (需要关闭"核心伤害处理")
  51. # >> Enu - Tankentai (我只是听说的,还没真正试过)
  52. # =============================================================================
  53. # ChangeLogs :
  54. # =============================================================================
  55. # Version 1.0   : - Initial Release
  56. # Version 1.2   : - Add Bitmap Entire Fill
  57. #                 - Add Bitmap Border Fill
  58. #                 - Add To Center window position
  59. #                 - Add more description
  60. # Version 1.3   : - Added Clone Sprite function and afterimagebase
  61. # Version 1.3b  : - Added TSBS basic function
  62. #                 - Greatly reduced lag for afterimage effect
  63. # Version 1.4   : - Added rotate image basic module
  64. #                 - Fixed bug at Object Core Fade
  65. # Version 1.5   : - Added Smooth movement
  66. #                 - Fixed bug on circle movement
  67. #                 - Fixed bug on movement module where float may causes endless
  68. #                   moving
  69. #                 - Fixed wrong parameter in drawing eclipse / circle
  70. #                 - Fixed color parameter on drawing arrow
  71. #                 - Added Plane_Mask on basic functions
  72. #                 - Added step parameter on draw circle
  73. #                 - Fixed wrong target opacity in object core fade for Window
  74. #                 - Dispose afterimages from Sprite_Base
  75. # Version 1.5b    - Afterimage now followed by flashing sprite
  76. # Version 1.5c    - Fixed bug on object core fade.
  77. #                 - Remove core fade from window since it's absurb :v
  78. #                 - Compatibility with nickle's core
  79. # Version 1.5d    - Allow you to jump in same place
  80. # =============================================================================
  81. # RGSS3 ~ Bug Fixes (Taken from RMWeb.com)
  82. # forums.rpgmakerweb.com/index.php?/topic/1131-rgss3-unofficial-bugfix-snippets
  83. # =============================================================================
  84. # Screen shake bugfix
  85. # -----------------------------------------------------------------------------
  86. class Game_Interpreter
  87.   
  88.   def command_225
  89.     screen.start_shake(@params[0], @params[1], @params[2])
  90.     wait(@params[2]) if @params[3]
  91.   end
  92.   
  93. end
  94. # -----------------------------------------------------------------------------
  95. # Enemy targeting bugfix
  96. # -----------------------------------------------------------------------------
  97. class Game_Action
  98.   def targets_for_friends
  99.     if item.for_user?
  100.       [subject]
  101.     elsif item.for_dead_friend?
  102.       if item.for_one?
  103.         [friends_unit.smooth_dead_target(@target_index)]
  104.       else
  105.         friends_unit.dead_members
  106.       end
  107.     elsif item.for_friend?
  108.       if item.for_one?
  109.         if @target_index < 0
  110.           [friends_unit.random_target]
  111.         else
  112.           [friends_unit.smooth_target(@target_index)]
  113.         end
  114.       else
  115.         friends_unit.alive_members
  116.       end
  117.     end
  118.   end
  119. end
  120. # -----------------------------------------------------------------------------
  121. # process normal char bugfix
  122. # -----------------------------------------------------------------------------
  123. class Window_Base < Window
  124.   alias :process_normal_character_theolized :process_normal_character
  125.   def process_normal_character(c, pos)
  126.     return unless c >= ' '
  127.     process_normal_character_theolized(c, pos)
  128.   end
  129. end
  130. # -----------------------------------------------------------------------------
  131. # Disable Japanese input name
  132. # -----------------------------------------------------------------------------
  133. class Game_System
  134.   def japanese?
  135.     false
  136.   end
  137. end
  138. #==============================================================================
  139. # ** Basic Functions ~
  140. #------------------------------------------------------------------------------
  141. #  These are just basic functions. It will not do anything in script mechanics.
  142. # I only provide these functions to be used later in upcoming script or just
  143. # simply for experimental.
  144. #------------------------------------------------------------------------------
  145. if $imported[:Theo_BasicFuntions] # Activation flag
  146. #==============================================================================
  147. module Math
  148.   
  149.   # Convert degree to radian
  150.   def self.radian(degree)
  151.     return (degree.to_f/180) * Math::PI
  152.   end
  153.   
  154.   # Convert radian to degree
  155.   def self.degree(radian)
  156.     return (radian.to_f/Math::PI) * 180
  157.   end
  158.   
  159. end

  160. class Object
  161.   
  162.   # Generate number with range from minimum to maximum
  163.   unless method_defined?(:rand_range)
  164.     def rand_range(min,max,float = false)
  165.       range = max - min
  166.       return float ? (min + (rand*range)) : min + rand(range)
  167.     end
  168.   end

  169.   # ---------------------------------------------------------------------------
  170.   # Iterate instance variables one by one.
  171.   #
  172.   # Example usage :
  173.   # each_var do |ivar|
  174.   #   ivar.update if ivar.is_a?(Sprite)
  175.   # end
  176.   # ---------------------------------------------------------------------------
  177.   def each_var
  178.     instance_variables.each do |varsymb|
  179.       yield instance_variable_get(varsymb)
  180.     end
  181.   end
  182.   
  183. end
  184. #==============================================================================
  185. # ** Sprite_Screen
  186. #------------------------------------------------------------------------------
  187. #  Sprite that same size as the screen. It can be used to draw anything on
  188. # screen. I believe sometime you need it
  189. #
  190. # Example usage :
  191. # - http://goo.gl/E88ufV  ( Event Pointer )
  192. #==============================================================================

  193. class Sprite_Screen < Sprite
  194.   
  195.   def initialize(viewport = nil)
  196.     super(viewport)
  197.     self.bitmap = Bitmap.new(Graphics.width,Graphics.height)
  198.   end
  199.   
  200.   def dispose
  201.     self.bitmap.dispose
  202.     super
  203.   end
  204.   
  205. end

  206. #==============================================================================
  207. # ** Plane_Mask
  208. #------------------------------------------------------------------------------
  209. #  Sprite that same size as the map size. It's also scrolled alongside the map
  210. # if it's updated. It can be used to draw anything on map. Can be used as base
  211. # class of parallax lock actually
  212. #==============================================================================

  213. class Plane_Mask < Plane
  214.   
  215.   def initialize(vport)
  216.     super(vport)
  217.     @width = 1
  218.     @height = 1
  219.   end
  220.   
  221.   def update
  222.     if $game_map
  223.       if @width != $game_map.width || @height != $game_map.height
  224.         @width = $game_map.width
  225.         @height = $game_map.height
  226.         update_bitmap
  227.       end
  228.       self.ox = $game_map.display_x * 32
  229.       self.oy = $game_map.display_y * 32
  230.     end
  231.   end
  232.   
  233.   def update_bitmap
  234.     bmp = Bitmap.new(@width * 32, @height * 32)
  235.     self.bitmap = bmp
  236.   end
  237.   
  238. end

  239. #==============================================================================
  240. # ** Window_Confirmation
  241. #------------------------------------------------------------------------------
  242. #  Window command class that holds yes and no command. Used to make
  243. # confirmation function. If you want some alteration of this class, just make
  244. # inheritance.
  245. #
  246. #  This is for my personal development. I mean, if there is a simple script
  247. # that display window yes/no confirmation, it will not require this basic
  248. # module. I prefer to duplicate this class to my script instead. You know,
  249. # most people hates Core Script / Basic Modules
  250. #==============================================================================
  251. class Window_Confirmation < Window_Command
  252.   def window_width
  253.     return 100
  254.   end
  255.   
  256.   def make_command_list
  257.     add_command(ok_vocab, :ok, ok_condition)
  258.     add_command(cancel_vocab, :cancel, cancel_condition)
  259.   end
  260.   
  261.   # Vocab yes
  262.   def ok_vocab
  263.     return "确认"
  264.   end
  265.   
  266.   # Vocab cancel
  267.   def cancel_vocab
  268.     return "取消"
  269.   end
  270.   
  271.   # Overwrite this method in child class
  272.   def ok_condition
  273.     return true
  274.   end
  275.   
  276.   # Overwrite this method in child class
  277.   def cancel_condition
  278.     return true
  279.   end
  280.   
  281.   def alignment
  282.     return 1
  283.   end
  284.   
  285. end
  286. #==============================================================================
  287. # ** Coordinate
  288. #------------------------------------------------------------------------------
  289. #  Coordinate class that holds x dan y point. Can be used to calculate point
  290. # operation such as vector
  291. #
  292. # Example usage :
  293. # - http://goo.gl/E88ufV  ( Event Pointer )
  294. #==============================================================================
  295. class Coordinate
  296.   attr_accessor :x,:y
  297.   
  298.   def initialize(x,y)
  299.     @x = x
  300.     @y = y
  301.   end
  302.   
  303.   def + (other)
  304.     other = other.to_c unless other.is_a?(Coordinate)
  305.     Coordinate.new(self.x + other.x, self.y + other.y)
  306.   end
  307.   
  308.   def - (other)
  309.     other = other.to_c unless other.is_a?(Coordinate)
  310.     Coordinate.new(self.x - other.x, self.y - other.y)
  311.   end
  312.   
  313.   def == (other)
  314.     other = other.to_c unless other.is_a?(Coordinate)
  315.     return self.x == other.x && self.y == other.y
  316.   end
  317.   
  318.   # To String function
  319.   def to_s
  320.     return "(#{self.x},#{self.y})"
  321.   end
  322.   
  323. end
  324. #==============================================================================
  325. # ** Vector
  326. #------------------------------------------------------------------------------
  327. #  Vector class that handles all vector functions. Note that some of these
  328. # methods and variable terms are named in Indonesian terms. Because I don't
  329. # really know what is in English terms
  330. #
  331. # Example usage :
  332. # - http://goo.gl/E88ufV  ( Event Pointer )
  333. #==============================================================================
  334. class Vector
  335.   attr_accessor :pangkal  # Starting point
  336.   attr_accessor :ujung    # End point
  337.   
  338.   def initialize(pangkal,ujung,radius = 0)
  339.     @pangkal = pangkal.is_a?(Coordinate) ? pangkal : pangkal.to_c
  340.     if ujung.is_a?(Numeric)
  341.       x_pos = @pangkal.x + (Math.cos(Math.radian(ujung)) * radius)
  342.       y_pos = @pangkal.y + (Math.sin(Math.radian(ujung)) * radius)
  343.       @ujung = Coordinate.new(x_pos,y_pos)
  344.       return
  345.     end
  346.     @ujung = ujung.is_a?(Coordinate) ? ujung : ujung.to_c
  347.   end
  348.   
  349.   # Get scalar value
  350.   def skalar
  351.     Math.sqrt(jarak_x**2 + jarak_y**2)
  352.   end
  353.   
  354.   def + (other)
  355.     if other.is_a?(Coordinate)
  356.       return Vector.new(pangkal + other, ujung + other)
  357.     end
  358.     Vector.new(pangkal, ujung + other.satuan)
  359.   end
  360.   
  361.   def - (other)
  362.     if other.is_a?(Coordinate)
  363.       return Vector.new(pangkal - other, ujung - other)
  364.     end
  365.     Vector.new(pangkal, ujung - other.satuan)
  366.   end
  367.   
  368.   # Get degree upon two different point
  369.   def degree
  370.     Math.degree(Math.atan2(jarak_y,jarak_x)) rescue 0
  371.   end
  372.   
  373.   # Get distance X
  374.   def jarak_y
  375.     ujung.y - pangkal.y
  376.   end
  377.   
  378.   # Get distance Y
  379.   def jarak_x
  380.     ujung.x - pangkal.x
  381.   end
  382.   
  383.   # Convert vector to coordinate
  384.   def satuan
  385.     Coordinate.new(jarak_x, jarak_y)
  386.   end
  387.   
  388.   # To string format
  389.   def to_s
  390.     return @pangkal.to_s + " ---> " + @ujung.to_s
  391.   end
  392.   
  393. end
  394. #==============================================================================
  395. # ** VectorObject
  396. #------------------------------------------------------------------------------
  397. # This class handles two objects that their vector is later will be used.
  398. #
  399. # Example usage :
  400. # - http://goo.gl/E88ufV  ( Event Pointer )
  401. #==============================================================================
  402. class VectorObject
  403.   attr_accessor :pangkal  # Starting object
  404.   attr_accessor :ujung    # End object
  405.   attr_accessor :color    # Color value (to draw lines)
  406.   attr_accessor :offset_x # Offset value X
  407.   attr_accessor :offset_y # Offset value Y
  408.   
  409.   # Basically, offset value is a increment value upon a new vector that created
  410.   # using to_v vector. I don't really know if 'offset' is the right word. I'm
  411.   # suck at english afterall
  412.   
  413.   def initialize(pangkal,ujung,color = Color.new(255,255,255))
  414.     @pangkal = pangkal
  415.     @ujung = ujung
  416.     @color = color
  417.     @offset_x = 0
  418.     @offset_y = 0
  419.   end
  420.   
  421.   # Two object converted into vector
  422.   def to_v
  423.     a = @pangkal.to_c
  424.     b = @ujung.to_c
  425.     a.x += @offset_x
  426.     b.x += @offset_x
  427.     a.y += @offset_y
  428.     b.y += @offset_y
  429.     Vector.new(a,b)
  430.   end
  431.   
  432. end
  433. #==============================================================================
  434. # ** Bitmap
  435. #------------------------------------------------------------------------------
  436. # Built in class that handles bitmap
  437. #==============================================================================
  438. class Bitmap
  439.   
  440.   # Fill entire bitmap with color
  441.   def entire_fill(color = Color.new(0,0,0,150))
  442.     fill_rect(self.rect,color)
  443.   end
  444.   
  445.   # Fill bitmap edge only
  446.   def border_fill(color = Color.new(255,255,255))
  447.     fill_rect(0,0,width,1,color)
  448.     fill_rect(0,0,1,height,color)
  449.     fill_rect(width-1,0,1,height,color)
  450.     fill_rect(0,height-1,width,1,color)
  451.   end
  452.   
  453. end
  454. #==============================================================================
  455. # ** Window_Base
  456. #------------------------------------------------------------------------------
  457. # This is a super class of all windows within the game.
  458. #==============================================================================
  459. class Window_Base < Window
  460.   
  461.   # Same as bitmap entire fill
  462.   def entire_fill(color = Color.new(0,0,0,150))
  463.     contents.entire_fill(color)
  464.   end
  465.   
  466.   # Set window to center position of the screen
  467.   def to_center
  468.     self.x = Graphics.width/2 - self.width/2
  469.     self.y = Graphics.height/2 - self.height/2
  470.   end
  471.   
  472. end
  473. #==============================================================================
  474. # ** Color
  475. #------------------------------------------------------------------------------
  476. # Built in class that handles color
  477. #==============================================================================
  478. class Color
  479.   
  480.   # Is color same as other?
  481.   def same?(*args)
  482.     args = args.select {|color| color.is_a?(Color)}
  483.     return false if args.empty?
  484.     return args.any?{|color| self.red == color.red &&
  485.       self.green == color.green && self.blue == color.blue &&
  486.       self.alpha == color.alpha}
  487.   end
  488.   
  489.   # Is color empty?
  490.   def empty?
  491.     return self.alpha <= 0
  492.   end
  493.   
  494. end
  495. # -----------------------------------------------------------------------------
  496. # New Method : To Coordinate Conversion
  497. # -----------------------------------------------------------------------------
  498. class Object
  499.   
  500.   def to_c
  501.     return Coordinate.new(0,0)
  502.   end

  503. end

  504. class Numeric
  505.   
  506.   def to_c
  507.     return Coordinate.new(self,self)
  508.   end
  509.   
  510. end

  511. class Sprite
  512.   
  513.   def to_c
  514.     return Coordinate.new(self.x,self,y)
  515.   end
  516.   
  517. end

  518. class Window
  519.   
  520.   def to_c
  521.     return Coordinate.new(self.x,self,y)
  522.   end
  523.   
  524. end

  525. class Game_Enemy < Game_Battler
  526.   
  527.   def to_c
  528.     return Coordinate.new(self.screen_x,self,screen_y)
  529.   end
  530.   
  531. end

  532. class Game_CharacterBase
  533.   
  534.   def to_c(map = false)
  535.     if map
  536.       return Coordinate.new(self.real_x,self.real_y)
  537.     end
  538.     return Coordinate.new(self.screen_x,self.screen_y)
  539.   end
  540.   
  541. end
  542. # -----------------------------------------------------------------------------
  543. # Added TSBS basic function. To calculate sprite anim cell
  544. # -----------------------------------------------------------------------------
  545. module TSBS
  546.   def self.cell(row, col)
  547.     result = (MaxCol * (row - 1)) + (col - 1)
  548.     return result
  549.   end
  550. end
  551. end
  552. #==============================================================================
  553. # ** Bitmap Extra addons v2.1
  554. #------------------------------------------------------------------------------
  555. #  This bitmap extra addons provide basic function of drawing shapes. It could
  556. # be drawing polygon, line, arrow, elipse or such.
  557. #
  558. # The code may look messy. Even myself forget how it works. To be note that
  559. # even this current version is 2.1, the draw filled polygon is imperfect. Do
  560. # not use at this moment.
  561. #
  562. # Some functions may need my Basic Functions to be activated. So I suggest you
  563. # to also activate it
  564. #
  565. # Example usage :
  566. # - http://goo.gl/E88ufV ( Event Pointer )
  567. # - http://goo.gl/DlrPuR ( Simple Polygon Status )
  568. #------------------------------------------------------------------------------
  569. if $imported[:Theo_BitmapAddons]  # Activation flag
  570. # =============================================================================
  571. class Bitmap
  572.   attr_accessor :start_degree
  573.   
  574.   # ------------------------------------------------------------------------
  575.   # Static Members
  576.   # ------------------------------------------------------------------------
  577.   @@default_color = Color.new(255,255,255)
  578.   @@arrow_degree = 30
  579.   
  580.   def self.default_color=(color)
  581.     @@default_color = color
  582.   end
  583.   
  584.   def self.arrow_degree=(degree)
  585.     @@arrow_degree = degree
  586.   end
  587.   
  588.   def self.default_color
  589.     @@default_color
  590.   end
  591.   
  592.   def self.arrow_degree
  593.     @@arrow_degree
  594.   end
  595.   
  596.   alias theo_bitmap_init initialize
  597.   def initialize(*args)
  598.     theo_bitmap_init(*args)
  599.     @start_degree = 270
  600.   end
  601.   # ------------------------------------------------------------------------
  602.   # Bitmap draw line. The avalaible arguments to put are
  603.   # - draw_line(x1,x2,y1,y2,[color])
  604.   # - draw_line(coordinate1, coordinate2, [color])
  605.   # - draw_line(vector, [color])
  606.   #
  607.   # coordinate must be Coordinate object from this basic module.
  608.   # So do the vector
  609.   # ------------------------------------------------------------------------
  610.   def draw_line(x1, y1=0, x2=0, y2=0, color=@@default_color.dup,
  611.       color_set_skip = false)
  612.     # ----------------------------------------------------------------------
  613.     # If the argument is a vector
  614.     # ----------------------------------------------------------------------
  615.     if x1.is_a?(Vector)
  616.       new_color = (y1.is_a?(Color) ? y1 : color)
  617.       draw_line(x1.pangkal,x1.ujung,new_color) # Recursive
  618.       return # Exit
  619.     # ----------------------------------------------------------------------
  620.     # If two arguments are coordinates
  621.     # ----------------------------------------------------------------------
  622.     elsif x1.is_a?(Coordinate) && y1.is_a?(Coordinate)
  623.       pangkal = x1
  624.       ujung = y1
  625.       new_color = (x2.is_a?(Color) ? x2 : color)
  626.       draw_line(pangkal.x,pangkal.y,ujung.x,ujung.y,new_color) # Recursive
  627.       return # Exit
  628.     end
  629.     # ----------------------------------------------------------------------
  630.     # If two coordinate is same
  631.     # ----------------------------------------------------------------------
  632.     if x1 == x2 && y1 == y2
  633.       set_pixel(x1,y1,color)
  634.       yield [x1,x2] if block_given?
  635.       return # Exit
  636.     end
  637.     # ----------------------------------------------------------------------
  638.     # Calculate distance X dan Y
  639.     # ----------------------------------------------------------------------
  640.     jarak_x = (x2-x1)
  641.     jarak_y = (y2-y1)
  642.     # ----------------------------------------------------------------------
  643.     # If line is horz line or vert line
  644.     # ----------------------------------------------------------------------
  645.     if jarak_y == 0 || jarak_x == 0
  646.       
  647.       # Horizontal
  648.       if jarak_y == 0
  649.         draw_horz(x1,y1,jarak_x,color)
  650.         for j in 0..jarak_x
  651.           yield [x1,y1]
  652.           x1 += 1
  653.         end if block_given?
  654.         
  655.       # Vertikal
  656.       elsif jarak_x == 0
  657.         draw_vert(x1,y1,jarak_y,color)
  658.         for k in 0..jarak_y
  659.           yield [x1,y1]
  660.           y1 += 1
  661.         end if block_given?
  662.       end
  663.       return # Exit
  664.       
  665.     end
  666.     # ----------------------------------------------------------------------
  667.     # If line is diagonal
  668.     # ----------------------------------------------------------------------
  669.     maximum = [jarak_x.abs,jarak_y.abs].max
  670.     rasio_x = jarak_x / maximum.to_f
  671.     rasio_y = jarak_y / maximum.to_f
  672.     real_x = x1.to_f
  673.     real_y = y1.to_f
  674.     for i in 0..maximum
  675.       set_pixel(x1,y1,color) unless get_pixel(x1,y1).same?(color) ||
  676.         color_set_skip ? !get_pixel(x1,y1).empty? : false
  677.       real_x += rasio_x
  678.       real_y += rasio_y
  679.       yield [x1,y1] if block_given?
  680.       x1 = real_x.round
  681.       y1 = real_y.round
  682.     end
  683.   end
  684.   # ------------------------------------------------------------------------
  685.   # Gradient line
  686.   # ------------------------------------------------------------------------
  687.   def gradient_line(x1,y1=0,x2=0,y2=0,color1=@@default_color.dup,
  688.       color2 = color1)
  689.     if x1.is_a?(Vector)
  690.       warna_pangkal = (y1.is_a?(Color) ? y1 : color1)
  691.       warna_ujung = (x2.is_a?(Color) ? x2 : color2)
  692.       gradient_line(x1.pangkal, x1.ujung, warna_pangkal, warna_ujung)
  693.       return
  694.     elsif x1.is_a?(Coordinate) && y1.is_a?(Coordinate)
  695.       pangkal = x1
  696.       ujung = y1
  697.       warna_pangkal = (x2.is_a?(Color) ? x2 : color1)
  698.       warna_ujung = (y2.is_a?(Color) ? y2 : color2)
  699.       gradient_line(pangkal.x,pangkal.y,ujung.x,ujung.y,warna_pangkal,
  700.         warna_ujung)
  701.       return
  702.     end
  703.     jarak_x = (x2-x1)
  704.     jarak_y = (y2-y1)
  705.     radius = Math.sqrt((jarak_x**2) + (jarak_y**2))
  706.     red_diff = (color2.red - color1.red) / radius
  707.     green_diff = (color2.green - color1.green) / radius
  708.     blue_diff = (color2.blue - color1.blue) / radius
  709.     alpha_diff = (color2.alpha - color1.alpha) / radius
  710.     red = color1.red
  711.     green = color1.green
  712.     blue = color1.blue
  713.     alpha = color1.alpha
  714.     if jarak_y.abs == 0 || jarak_x.abs == 0
  715.       gradient_fill_rect(x1,y1,1,jarak_y,color1,color2,true) if jarak_y.abs == 0
  716.       gradient_fill_rect(x1,y1,jarak_x,1,color1,color2) if jarak_x.abs == 0
  717.       return
  718.     end
  719.     maximum = [jarak_x.abs,jarak_y.abs].max
  720.     rasio_x = jarak_x / maximum.to_f
  721.     rasio_y = jarak_y / maximum.to_f
  722.     real_x = x1.to_f
  723.     real_y = y1.to_f
  724.     for i in 0..maximum
  725.       new_color = Color.new(red,green,blue,alpha)
  726.       set_pixel(x1,y1,new_color) unless get_pixel(x1,y1).same?(new_color)
  727.       real_x += rasio_x
  728.       real_y += rasio_y
  729.       x1 = real_x.round
  730.       y1 = real_y.round
  731.       red += red_diff
  732.       blue += blue_diff
  733.       green += green_diff
  734.       alpha += alpha_diff
  735.     end
  736.   end
  737.   
  738.   # Draw horizontal line
  739.   def draw_horz(x,y,width,color = Color.new(255,255,255))
  740.     if width < 0
  741.       fill_rect(x+width+1,y,width.abs,1,color)
  742.       return
  743.     end
  744.     fill_rect(x,y,width,1,color)
  745.   end
  746.   
  747.   # Draw vertical line
  748.   def draw_vert(x,y,height,color = Color.new(255,255,255))
  749.     if height < 0
  750.       fill_rect(x,y+height+1,1,height.abs,color)
  751.       return
  752.     end
  753.     fill_rect(x,y,1,height,color)
  754.   end
  755.   
  756.   # --------------------------------------------------------------------------
  757.   # Drawing ellipse.
  758.   #
  759.   # The parameters are :
  760.   # - x     >> Center coordinate X
  761.   # - y     >> Center coordinate Y
  762.   # - horz  >> Horizontal Radius value
  763.   # - vert  >> Vertical Radius value
  764.   # - color >> Line color
  765.   # - thick >> Thickness of line
  766.   # - step  >> Dot step. Greater number may causes ellipse being drawn
  767.   #            imperfect. But may perform better
  768.   # --------------------------------------------------------------------------
  769.   def draw_ellipse(x,y=0,horz=1,vert=1,color=Color.new(255,255,255),thick=1,
  770.       step=0.1)
  771.     return if thick < 1
  772.     ori_x = x
  773.     ori_y = y
  774.     x += horz
  775.     degree = 0.0
  776.     while degree <= 360
  777.       yield [x,y] if block_given?
  778.       set_pixel(x,y,color) unless get_pixel(x,y).same?(color)
  779.       x = Math.cos(Math.radian(degree)) * horz + ori_x
  780.       y = Math.sin(Math.radian(degree)) * vert + ori_y
  781.       degree = [degree+step,361].min
  782.     end
  783.     if thick > 1
  784.       draw_ellipse(ori_x+1,ori_y+1,horz,vert,color,thick-1,step)
  785.       draw_ellipse(ori_x-1,ori_y-1,horz,vert,color,thick-1,step)
  786.       draw_ellipse(ori_x+1,ori_y-1,horz,vert,color,thick-1,step)
  787.       draw_ellipse(ori_x-1,ori_y+1,horz,vert,color,thick-1,step)
  788.     end
  789.   end
  790.   # --------------------------------------------------------------------------
  791.   # Draw circle. Similar of drawing ellipse. But only have one radius parameter
  792.   # --------------------------------------------------------------------------
  793.   def draw_circle(x,y,radius,color=Color.new(255,255,255),step=0.1,thick=1)
  794.     draw_ellipse(x,y,radius,radius,color,thick,step) {|coordinate|
  795.       yield coordinate if block_given?
  796.     }
  797.   end
  798.   
  799.   # Do not use ~ !
  800.   def fill_circle(x,y,radius,color1,color2=color1,step=0.1)
  801.     fill_ellipse(x,y,radius,radius,color1,color2,step)
  802.   end
  803.   
  804.   # Do not use ~ !
  805.   def fill_ellipse(x,y,horz,vert,color1,color2=color1,step=0.1)
  806.     draw_ellipse(x,y,horz,vert,1,color1,0.5) {|cor|
  807.       draw_line(x,y,cor[0],cor[1],color2,true)
  808.     }
  809.     for i in 0..1
  810.       for baris in 0..horz*2
  811.         for kolom in 0..vert*2
  812.           pos_x = baris-horz+x
  813.           pos_y = kolom-vert+y
  814.           syarat = (get_pixel(pos_x+1,pos_y).same?(color1,color2) &&
  815.           get_pixel(pos_x-1,pos_y).same?(color1,color2)) ||
  816.           (get_pixel(pos_x,pos_y-1).same?(color1,color2) &&
  817.           get_pixel(pos_x,pos_y+1).same?(color1,color2)) ||
  818.           (get_pixel(pos_x+1,pos_y+1).same?(color1,color2) &&
  819.           get_pixel(pos_x-1,pos_y-1).same?(color1,color2)) ||
  820.           (get_pixel(pos_x-1,pos_y+1).same?(color1,color2) &&
  821.           get_pixel(pos_x+1,pos_y-1).same?(color1,color2))
  822.           if syarat && !get_pixel(pos_x,pos_y).same?(color1,color2)
  823.             set_pixel(pos_x,pos_y,color2)
  824.           end
  825.         end
  826.       end
  827.     end
  828.   end
  829.   # ---------------------------------------------------------------------------
  830.   # Drawing polygon
  831.   #
  832.   # The parameters are :
  833.   # - x       >> Center coordinate X
  834.   # - y       >> Center coordinate Y
  835.   # - corner  >> Number of corner. The mininmal value is 3 (Triangle)
  836.   # - length  >> Radius range from center
  837.   # - color1  >> Edge line color
  838.   # - bone    >> Drawing bone? (true/false)
  839.   # - color2  >> Bone Color
  840.   # ---------------------------------------------------------------------------
  841.   def draw_polygon(x,y,corner,length,color1,bone=true,color2=color1)
  842.     return unless corner.is_a?(Numeric)
  843.     draw_shape(x,y,Array.new(corner){1},length,color1,bone,false,color2)
  844.   end
  845.   
  846.   # Do not use ~ !
  847.   def fill_polygon(x,y,corner,length,color1,color2=color1)
  848.     return unless corner.is_a?(Numeric)
  849.     draw_shape(x,y,Array.new(corner),length,color1,false,true,color2)
  850.   end
  851.   
  852.   # Draw polygon parameter
  853.   def draw_shape_params(x,y,params,length,color1,bone=true,color2=color1)
  854.     draw_shape(x,y,params,length,color1,bone,false,color2)
  855.   end
  856.   
  857.   # Do not use ~ !
  858.   def fill_shape_params(x,y,params,length,color1,color2=color1)
  859.     draw_shape(x,y,params,length,color1,false,true,color2)
  860.   end
  861.   
  862.   # Core function of drawing shape
  863.   def draw_shape(x,y,params,length,color1 = Color.new(255,255,255),
  864.       include_bone = true ,fill=false,color2 = color1)
  865.     return unless params.is_a?(Array) # Corner lenght should be array
  866.     return unless params.size >= 3    # At the size should have min 3
  867.     degree_plus = 360 / params.size
  868.     degree = @start_degree
  869.     coordinate = []
  870.     edge = []
  871.     params.each do |i|
  872.       x_des = x + Math.cos(Math.radian(degree)) * (length*(i.to_f/params.max))
  873.       y_des = y + Math.sin(Math.radian(degree)) * (length*(i.to_f/params.max))
  874.       draw_line(x,y,x_des,y_des,color2) if include_bone
  875.       degree += degree_plus
  876.       coordinate.push(Coordinate.new(x_des,y_des))
  877.     end
  878.     for i in -1..coordinate.size-2
  879.       c = coordinate
  880.       draw_line(c[i].x,c[i].y,c[i+1].x,c[i+1].y,color1) {|cor| edge.push(cor)}
  881.     end
  882.     return unless fill
  883.     # -------------------------------------------------------------------------
  884.     # Yes, it should return. Because the code below this point is sooo much
  885.     # messy.
  886.     # -------------------------------------------------------------------------
  887.     edge.each do |line|
  888.       draw_line(x,y,line[0],line[1],color2,true)
  889.     end
  890.     for i in 0..1
  891.       for baris in 0..length*2
  892.         for kolom in 0..length*2
  893.           pos_x = baris-length+x
  894.           pos_y = kolom-length+y
  895.           syarat = (get_pixel(pos_x+1,pos_y).same?(color1,color2) &&
  896.           get_pixel(pos_x-1,pos_y).same?(color1,color2)) ||
  897.           (get_pixel(pos_x,pos_y-1).same?(color1,color2) &&
  898.           get_pixel(pos_x,pos_y+1).same?(color1,color2)) ||
  899.           (get_pixel(pos_x+1,pos_y+1).same?(color1,color2) &&
  900.           get_pixel(pos_x-1,pos_y-1).same?(color1,color2)) ||
  901.           (get_pixel(pos_x-1,pos_y+1).same?(color1,color2) &&
  902.           get_pixel(pos_x+1,pos_y-1).same?(color1,color2))
  903.           if syarat && !get_pixel(pos_x,pos_y).same?(color1,color2)
  904.             set_pixel(pos_x,pos_y,color2)
  905.           end
  906.         end
  907.       end
  908.     end
  909.   end
  910.   
  911.   # ---------------------------------------------------------------------------
  912.   # Bitmap drawing arrows. It's similar as draw line actually
  913.   # - draw_arrow(x1,x2,y1,y2,[color])
  914.   # - draw_arrow(coordinate1, coordinate2, [color])
  915.   # - draw_arrow(vector, [color])
  916.   #
  917.   # coordinate must be Coordinate object from this basic module.
  918.   # So do the vector
  919.   # ---------------------------------------------------------------------------
  920.   def draw_arrow(x1,y1=0,x2=0,y2=0,color=@@default_color.dup)
  921.     if x1.is_a?(Vector)
  922.       new_color = (y1.is_a?(Color) ? y1 : color)
  923.       
  924.       # Recursive call. Split a vector to two coordinate.
  925.       draw_arrow(x1.pangkal,x1.ujung,new_color)
  926.       # Return
  927.       return
  928.     elsif x1.is_a?(Coordinate) && y1.is_a?(Coordinate)
  929.       pangkal = x1
  930.       ujung = y1
  931.       new_color = (x2.is_a?(Color) ? x2 : color)
  932.       
  933.       # Recursive call. Split each coordinate into two primitive x,y value
  934.       draw_arrow(pangkal.x,pangkal.y,ujung.x,ujung.y,new_color)
  935.       # Return
  936.       return
  937.     end
  938.     # Draw basic line
  939.     draw_line(x1,y1,x2,y2,color)
  940.     # Get reversed degree
  941.     degree = Vector.new(Coordinate.new(x1,y1),Coordinate.new(x2,y2)).degree-180
  942.     # Draw arrow
  943.     draw_line(Vector.new(Coordinate.new(x2,y2),degree + @@arrow_degree,10),
  944.       color)
  945.     draw_line(Vector.new(Coordinate.new(x2,y2),degree - @@arrow_degree,10),
  946.       color)
  947.   end
  948.   
  949. end
  950. # -----------------------------------------------------------------------------
  951. # Draw Polygon status
  952. # -----------------------------------------------------------------------------
  953. class Game_Battler < Game_BattlerBase
  954.   
  955.   def params_array
  956.     return [self.atk,self.def,self.mat,self.mdf,self.agi,self.luk]
  957.   end
  958.   
  959. end

  960. class Window_Base < Window
  961.   
  962.   def draw_polygon_params(x,y,actor,inner,outer,color1,color2)
  963.     contents.draw_shape_params(x,y,actor.params_array,inner,color1)
  964.     contents.draw_polygon(x,y,actor.params_array.size,outer,color2)
  965.   end
  966.   
  967. end
  968. end
  969. #==============================================================================
  970. # ** Core Damage Processing
  971. # -----------------------------------------------------------------------------
  972. # I altered the way how damage calculation to provide more flexibility. Any
  973. # scripts that also overwrite make_damage_value will highly incompatible.
  974. #
  975. # However, I don't have any script implements this module right now. So you
  976. # may disable it
  977. # -----------------------------------------------------------------------------
  978. if $imported[:Theo_CoreDamage]  # Activation flag
  979. #==============================================================================
  980. class Game_Battler < Game_BattlerBase
  981.   # ---------------------------------------------------------------------------
  982.   # *) Overwrite make damage value
  983.   # ---------------------------------------------------------------------------
  984.   def make_damage_value(user, item)
  985.     value = base_damage(user, item)
  986.     value = apply_element_rate(user, item, value)
  987.     value = process_damage_rate(user, item, value)
  988.     value = apply_damage_modifiers(user, item, value)
  989.     @result.make_damage(value.to_i, item)
  990.   end
  991.   # ---------------------------------------------------------------------------
  992.   # *) Make base damage. Evaling damage formula
  993.   # ---------------------------------------------------------------------------
  994.   def base_damage(user, item)
  995.     value = item.damage.eval(user, self, $game_variables)
  996.     value
  997.   end
  998.   # ---------------------------------------------------------------------------
  999.   # *) Apply element rate
  1000.   # ---------------------------------------------------------------------------
  1001.   def apply_element_rate(user, item, value)
  1002.     value *= item_element_rate(user, item)
  1003.     value
  1004.   end
  1005.   # ---------------------------------------------------------------------------
  1006.   # *) Apply damage rate. Such as physical, magical, recovery
  1007.   # ---------------------------------------------------------------------------
  1008.   def process_damage_rate(user, item, value)
  1009.     value *= pdr if item.physical?
  1010.     value *= mdr if item.magical?
  1011.     value *= rec if item.damage.recover?
  1012.     value
  1013.   end
  1014.   # ---------------------------------------------------------------------------
  1015.   # *) Apply damage modifier. Such as guard, critical, variance
  1016.   # ---------------------------------------------------------------------------
  1017.   def apply_damage_modifiers(user, item, value)
  1018.     value = apply_critical(value, user) if @result.critical
  1019.     value = apply_variance(value, item.damage.variance)
  1020.     value = apply_guard(value)
  1021.     value
  1022.   end
  1023.   # ---------------------------------------------------------------------------
  1024.   # *) Applying critical
  1025.   # ---------------------------------------------------------------------------
  1026.   def apply_critical(damage, user)
  1027.     damage * 3
  1028.   end
  1029.   
  1030. end
  1031. end
  1032. #=============================================================================
  1033. # ** Core Damage Result ~
  1034. #-----------------------------------------------------------------------------
  1035. # I altered how action result is being handled. It's used within my sideview
  1036. # battle system.
  1037. #-----------------------------------------------------------------------------
  1038. if $imported[:Theo_CoreResult]  # Activation flag
  1039. #=============================================================================
  1040. class Game_Battler < Game_BattlerBase
  1041.   
  1042.   def item_apply(user, item)
  1043.     make_base_result(user, item)
  1044.     apply_hit(user, item) if @result.hit?
  1045.   end
  1046.   
  1047.   def make_base_result(user, item)
  1048.     @result.clear
  1049.     @result.used = item_test(user, item)
  1050.     @result.missed = (@result.used && rand >= item_hit(user, item))
  1051.     @result.evaded = ([email protected] && rand < item_eva(user, item))
  1052.   end
  1053.   
  1054.   def apply_hit(user, item)  
  1055.     unless item.damage.none?
  1056.       determine_critical(user, item)
  1057.       make_damage_value(user, item)
  1058.       execute_damage(user)
  1059.     end
  1060.     apply_item_effects(user, item)
  1061.   end
  1062.   
  1063.   def determine_critical(user, item)
  1064.     @result.critical = (rand < item_cri(user, item))
  1065.   end
  1066.   
  1067.   def apply_item_effects(user, item)
  1068.     item.effects.each {|effect| item_effect_apply(user, item, effect) }
  1069.     item_user_effect(user, item)
  1070.   end
  1071.   
  1072. end
  1073. end
  1074. #==============================================================================
  1075. # ** Object Core Movement
  1076. #------------------------------------------------------------------------------
  1077. #  This basic module allow you to move objects like Window or Sprite to a
  1078. # certain position in a given time duration. The object must be updated in each
  1079. # frame. It could also applied to any classes that contains x,y and allow it to
  1080. # be modified
  1081. #
  1082. # Avalaible methods :
  1083. # - goto(x, y, duration, [jump])
  1084. #   Tells the object to move to specified x,y coordinate in a given time
  1085. #   duration in frame. By default, the jump value is zero.
  1086. #   
  1087. # - slide(x, y, duration, jump)
  1088. #   Tells the object to slide in x,y coordinate from original position in a
  1089. #   given time duration in frame. By default, the jump value is zero.
  1090. #
  1091. # I use this module within my sideview battle system movement sequences
  1092. #------------------------------------------------------------------------------
  1093. if $imported[:Theo_Movement]  # Activation flag
  1094. #==============================================================================
  1095. module THEO
  1096.   module Movement
  1097.     # =========================================================================
  1098.     # Exclusive class move object. To prevent adding to many instance variable
  1099.     # in object that implements this module
  1100.     # -------------------------------------------------------------------------
  1101.     class Move_Object
  1102.       attr_reader :obj # Reference object
  1103.       # -----------------------------------------------------------------------
  1104.       # *) Initialize
  1105.       # -----------------------------------------------------------------------
  1106.       def initialize(obj)
  1107.         @obj = obj
  1108.         clear_move_info
  1109.       end
  1110.       # -----------------------------------------------------------------------
  1111.       # *) Clear move info
  1112.       # -----------------------------------------------------------------------
  1113.       def clear_move_info
  1114.         @to_x = -1
  1115.         @to_y = -1
  1116.         @real_x = 0.0
  1117.         @real_y = 0.0
  1118.         @x_speed = 0.0
  1119.         @y_speed = 0.0
  1120.         @jump = 0.0
  1121.         @jump_interval = 0.0
  1122.         @offset = 0
  1123.         @duration = 0
  1124.       end
  1125.       # -----------------------------------------------------------------------
  1126.       # *) Tells the object to move
  1127.       # -----------------------------------------------------------------------
  1128.       def move_to(x,y=0,jump=0,duration=0)
  1129.         # You can also put the coordinate
  1130.         if x.is_a?(Coordinate)
  1131.           target = x
  1132.           move_to(target.x, target.y, y, jump)
  1133.           return
  1134.         end
  1135.         @to_x = x.to_i
  1136.         @to_y = y.to_i
  1137.         @real_x = @obj.x.to_f
  1138.         @real_y = @obj.y.to_f
  1139.         determine_speed(duration,jump)
  1140.       end
  1141.       # -----------------------------------------------------------------------
  1142.       # *) Determine traveling speed
  1143.       # -----------------------------------------------------------------------
  1144.       def determine_speed(duration,jump)
  1145.         @x_speed = (@to_x - @obj.x) / duration.to_f
  1146.         @y_speed = (@to_y - @obj.y) / duration.to_f
  1147.         @jump = jump.to_f
  1148.         @jump_interval = @jump/(duration/2.0)
  1149.         @duration = duration
  1150.       end
  1151.       # -----------------------------------------------------------------------
  1152.       # *) Is object currently moving?
  1153.       # -----------------------------------------------------------------------
  1154.       def moving?
  1155.         return false if @to_x == -1 && @to_y == -1
  1156.         result = @obj.x != @to_x || @obj.y != @to_y
  1157.         return result || @duration > 0
  1158.       end
  1159.       # -----------------------------------------------------------------------
  1160.       # *) Update movement
  1161.       # -----------------------------------------------------------------------
  1162.       def update_move
  1163.         @duration -= 1
  1164.         @real_x += @x_speed
  1165.         @real_y += @y_speed
  1166.         @obj.x = @real_x.round
  1167.         @obj.y = @real_y.round + @offset.round
  1168.         @jump -= @jump_interval
  1169.         @offset -= @jump
  1170.         clear_move_info unless moving?
  1171.       end
  1172.     end
  1173.     #==========================================================================
  1174.     # -------------------------------------------------------------------------
  1175.     # *) Set the movement object
  1176.     # -------------------------------------------------------------------------
  1177.     def set_obj(obj)
  1178.       # I just added only one instance variable
  1179.       @move_obj = Move_Object.new(obj)
  1180.     end
  1181.     # -------------------------------------------------------------------------
  1182.     # *) Tells the object to move
  1183.     # -------------------------------------------------------------------------
  1184.     def goto(x,y,duration = Graphics.frame_rate,jump = 0.0)
  1185.       @move_obj.move_to(x,y,jump,duration)
  1186.     end
  1187.     # -------------------------------------------------------------------------
  1188.     # *) Tells the object to slide
  1189.     # -------------------------------------------------------------------------
  1190.     def slide(x,y,duration = Graphics.frame_rate,jump = 0.0)
  1191.       slide_x = 0
  1192.       slide_y = 0
  1193.       if x.is_a?(Coordinate)
  1194.         target  = x
  1195.         slide_x = @move_obj.obj.x + target.x
  1196.         slide_y = @move_obj.obj.y + target.y
  1197.       else
  1198.         slide_x = @move_obj.obj.x + x
  1199.         slide_y = @move_obj.obj.y + y
  1200.       end
  1201.       goto(slide_x,slide_y,duration,jump) unless moving?
  1202.     end
  1203.     # -------------------------------------------------------------------------
  1204.     # *) Update movement
  1205.     # -------------------------------------------------------------------------
  1206.     def update_move
  1207.       @move_obj.update_move if moving?
  1208.     end
  1209.     # -------------------------------------------------------------------------
  1210.     # *) Is object moving?
  1211.     # -------------------------------------------------------------------------
  1212.     def moving?
  1213.       @move_obj.moving?
  1214.     end
  1215.     # -------------------------------------------------------------------------
  1216.     # *) Slide up
  1217.     # -------------------------------------------------------------------------
  1218.     def up(range,duration = Graphics.frame_rate,jump = 0.0)
  1219.       slide(0,-range,duration,jump)
  1220.     end
  1221.     # -------------------------------------------------------------------------
  1222.     # *) Slide down
  1223.     # -------------------------------------------------------------------------
  1224.     def down(range,duration = Graphics.frame_rate,jump = 0.0)
  1225.       slide(0,range,duration,jump)
  1226.     end
  1227.     # -------------------------------------------------------------------------
  1228.     # *) Slide to right
  1229.     # -------------------------------------------------------------------------
  1230.     def right(range,duration = Graphics.frame_rate,jump = 0.0)
  1231.       slide(range,0,duration,jump)
  1232.     end
  1233.     # -------------------------------------------------------------------------
  1234.     # *) Slide to left
  1235.     # -------------------------------------------------------------------------
  1236.     def left(range,duration = Graphics.frame_rate,jump = 0.0)
  1237.       slide(-range,0,duration,jump)
  1238.     end
  1239.     # -------------------------------------------------------------------------
  1240.     # *) Slide to upright
  1241.     # -------------------------------------------------------------------------
  1242.     def upright(range,duration = Graphics.frame_rate,jump = 0.0)
  1243.       slide(range,-range,duration,jump)
  1244.     end
  1245.     # -------------------------------------------------------------------------
  1246.     # *) Slide to upleft
  1247.     # -------------------------------------------------------------------------
  1248.     def upleft(range,duration = Graphics.frame_rate,jump = 0.0)
  1249.       slide(-range,-range,duration,jump)
  1250.     end
  1251.     # -------------------------------------------------------------------------
  1252.     # *) Slide to downright
  1253.     # -------------------------------------------------------------------------
  1254.     def downright(range,duration = Graphics.frame_rate,jump = 0.0)
  1255.       slide(range,-range,duration,jump)
  1256.     end
  1257.     # -------------------------------------------------------------------------
  1258.     # *) Slide to downleft
  1259.     # -------------------------------------------------------------------------
  1260.     def downleft(range,duration = Graphics.frame_rate,jump = 0.0)
  1261.       slide(-range,range,duration,jump)
  1262.     end   
  1263.   end
  1264. end
  1265. # -----------------------------------------------------------------------------
  1266. # Implemented to Sprite
  1267. # -----------------------------------------------------------------------------
  1268. class Sprite
  1269.   include THEO::Movement
  1270.   
  1271.   alias theolized_sprite_init initialize
  1272.   def initialize(*args)
  1273.     theolized_sprite_init(*args)
  1274.     set_obj(self)
  1275.   end
  1276.   
  1277.   alias theolized_move_update update
  1278.   def update
  1279.     theolized_move_update
  1280.     update_move
  1281.   end
  1282. end
  1283. # -----------------------------------------------------------------------------
  1284. # Implemented to Window
  1285. # -----------------------------------------------------------------------------
  1286. class Window
  1287.   include THEO::Movement
  1288.   
  1289.   alias theolized_move_window_init initialize
  1290.   def initialize(x, y, width, height)
  1291.     theolized_move_window_init(x, y, width, height)
  1292.     set_obj(self)
  1293.   end
  1294.   
  1295.   alias theolized_move_update update
  1296.   def update
  1297.     theolized_move_update
  1298.     update_move
  1299.   end
  1300.   
  1301. end
  1302. end
  1303. #==============================================================================
  1304. # ** Object Core Fade
  1305. #------------------------------------------------------------------------------
  1306. #  Same as core movement. But this one is dealing with opacity. It can be
  1307. # implemented to any object that has opacity value. Such as Window or Sprite
  1308. #
  1309. # Avalaible methods :
  1310. # - fade(target_opacity, duration)
  1311. # - fadeout(duration)
  1312. # - fadein(duration)
  1313. #
  1314. # I use this module within my sideview battle system
  1315. #------------------------------------------------------------------------------
  1316. if $imported[:Theo_CoreFade]  # Activation flag
  1317. #==============================================================================
  1318. module THEO
  1319.   module FADE
  1320.     # Default duration of fading
  1321.     DEFAULT_DURATION = 60
  1322.     # -------------------------------------------------------------------------
  1323.     # *) Init core fade instance variables
  1324.     # -------------------------------------------------------------------------
  1325.     def init_fade_members
  1326.       @obj = nil
  1327.       @target_opacity = -1
  1328.       @fade_speed = 0.0
  1329.       @pseudo_opacity = 0
  1330.     end
  1331.     # -------------------------------------------------------------------------
  1332.     # *) Set object
  1333.     # -------------------------------------------------------------------------
  1334.     def setfade_obj(obj)
  1335.       @obj = obj
  1336.       @pseudo_opacity = @obj.opacity
  1337.     end
  1338.     # -------------------------------------------------------------------------
  1339.     # *) Fade function
  1340.     # -------------------------------------------------------------------------
  1341.     def fade(opacity, duration = DEFAULT_DURATION)
  1342.       @target_opacity = opacity
  1343.       make_fade_speed(duration)
  1344.     end
  1345.     # -------------------------------------------------------------------------
  1346.     # *) Determine fade speed
  1347.     # -------------------------------------------------------------------------
  1348.     def make_fade_speed(duration)
  1349.       @fade_speed = (@target_opacity - @obj.opacity)/duration.to_f
  1350.       @pseudo_opacity = @obj.opacity.to_f
  1351.     end
  1352.     # -------------------------------------------------------------------------
  1353.     # *) Fadeout function
  1354.     # -------------------------------------------------------------------------
  1355.     def fadeout(duration = DEFAULT_DURATION)
  1356.       fade(0, duration)
  1357.     end
  1358.     # -------------------------------------------------------------------------
  1359.     # *) Fadein function
  1360.     # -------------------------------------------------------------------------
  1361.     def fadein(duration = DEFAULT_DURATION)
  1362.       fade(255, duration)
  1363.     end
  1364.     # -------------------------------------------------------------------------
  1365.     # *) Update fade
  1366.     # -------------------------------------------------------------------------
  1367.     def update_fade
  1368.       if fade?
  1369.         @pseudo_opacity += @fade_speed
  1370.         @obj.opacity = @pseudo_opacity
  1371.       else
  1372.         @target_opacity = -1
  1373.       end
  1374.     end
  1375.     # -------------------------------------------------------------------------
  1376.     # *) Is performing fade?
  1377.     # -------------------------------------------------------------------------
  1378.     def fade?
  1379.       return false if @target_opacity == -1
  1380.       @target_opacity != @pseudo_opacity.round
  1381.     end
  1382.    
  1383.   end
  1384. end
  1385. # -----------------------------------------------------------------------------
  1386. # Implements to Sprite
  1387. # -----------------------------------------------------------------------------
  1388. class Sprite
  1389.   
  1390.   include THEO::FADE
  1391.   
  1392.   alias pre_fade_init initialize
  1393.   def initialize(*args)
  1394.     pre_fade_init(*args)
  1395.     init_fade_members
  1396.     setfade_obj(self)
  1397.   end
  1398.   
  1399.   alias pre_fade_update update
  1400.   def update
  1401.     pre_fade_update
  1402.     update_fade
  1403.   end
  1404.   
  1405. end
  1406. end
  1407. #==============================================================================
  1408. # ** Object Circular Movement
  1409. #------------------------------------------------------------------------------
  1410. #   This is the most troublesome basic module I have ever made. I wrote this
  1411. # documentation after I made this modules months ago. So I little bit forgot
  1412. # how it works, why I did this, why I did that.
  1413. #
  1414. #   Well, this basic module is deal with circular movement of object. Like our
  1415. # Moon and Earth. You can set which coordinate/object that will be the center
  1416. # rotation. Then tells the object to surround. I'm aware this module is far
  1417. # from perfect. I'm open mind if anyone want to edit to make it better
  1418. #
  1419. # Avalaible Methods :
  1420. # - circle_move(degree, duration)
  1421. # - center_coordinate(x,y)
  1422. # - center_object(obj)
  1423. # - endless_circle(speed)
  1424. #------------------------------------------------------------------------------
  1425. if $imported[:Theo_Circular]  # Activation flag
  1426. #==============================================================================
  1427. module THEO
  1428.   module Circular
  1429.     class Circular_Obj
  1430.       attr_reader :ox           # Center coordinate X
  1431.       attr_reader :oy           # Center coordinate Y
  1432.       attr_reader :center_obj   # Center object
  1433.       attr_reader :obj          # Object
  1434.       # -----------------------------------------------------------------------
  1435.       # *) Initialize
  1436.       # -----------------------------------------------------------------------
  1437.       def initialize(obj,ox,oy,center_obj)
  1438.         @obj = obj
  1439.         @center_obj = center_obj if can_move?(center_obj)
  1440.         @ox = ox
  1441.         @oy = oy
  1442.         @speed = 0
  1443.         @endless = false
  1444.         @freeze = false
  1445.         refresh_info
  1446.       end
  1447.       # -----------------------------------------------------------------------
  1448.       # *) Refresh information
  1449.       # -----------------------------------------------------------------------
  1450.       def refresh_info
  1451.         @radius = radius
  1452.         @degree_dest = @current_degree = get_degree
  1453.       end
  1454.       # -----------------------------------------------------------------------
  1455.       # *) Set center object
  1456.       # -----------------------------------------------------------------------
  1457.       def center_obj=(center)
  1458.         return unless can_move?(center)
  1459.         @center_obj = center
  1460.         refresh_info
  1461.       end
  1462.       # -----------------------------------------------------------------------
  1463.       # *) Set center coordinate X
  1464.       # -----------------------------------------------------------------------
  1465.       def ox=(ox)
  1466.         @ox = ox
  1467.         refresh_info
  1468.       end
  1469.       # -----------------------------------------------------------------------
  1470.       # *) Set center coordinate Y
  1471.       # -----------------------------------------------------------------------
  1472.       def oy=(oy)
  1473.         @oy = oy
  1474.         refresh_info
  1475.       end
  1476.       # -----------------------------------------------------------------------
  1477.       # *) Is object can move?
  1478.       # -----------------------------------------------------------------------
  1479.       def can_move?(obj)
  1480.         obj.respond_to?("x") && obj.respond_to?("y")
  1481.       end
  1482.       # -----------------------------------------------------------------------
  1483.       # *) Circle move
  1484.       # -----------------------------------------------------------------------
  1485.       def circle_move(degree,duration)
  1486.         return if endless?
  1487.         @degree_dest = (@current_degree + degree)
  1488.         @speed = (@degree_dest - @current_degree) / duration.to_f
  1489.       end
  1490.       # -----------------------------------------------------------------------
  1491.       # *) Go to specified degree
  1492.       # -----------------------------------------------------------------------
  1493.       def circle_goto(degree,duration)
  1494.         return if endless?
  1495.         @degree_dest = degree
  1496.         @speed = (@degree_dest - @current_degree) / duration.to_f
  1497.       end
  1498.       # -----------------------------------------------------------------------
  1499.       # *) Endless circle movement
  1500.       # -----------------------------------------------------------------------
  1501.       def endless_circle(speed)
  1502.         @speed = speed
  1503.         @endless = true
  1504.       end
  1505.       # -----------------------------------------------------------------------
  1506.       # *) Get current degree from center point
  1507.       # -----------------------------------------------------------------------
  1508.       def get_degree
  1509.         Math.degree(Math.atan2(range_y,range_x)) rescue 0
  1510.       end
  1511.       # -----------------------------------------------------------------------
  1512.       # *) Get distance X from center point
  1513.       # -----------------------------------------------------------------------
  1514.       def range_x
  1515.         @obj.x - center_x
  1516.       end
  1517.       # -----------------------------------------------------------------------
  1518.       # *) Get distance Y from center point
  1519.       # -----------------------------------------------------------------------
  1520.       def range_y
  1521.         @obj.y - center_y
  1522.       end
  1523.       # -----------------------------------------------------------------------
  1524.       # *) Get coordinate X from center point
  1525.       # -----------------------------------------------------------------------
  1526.       def center_x
  1527.         @center_obj.nil? ? @ox : @center_obj.x
  1528.       end
  1529.       # -----------------------------------------------------------------------
  1530.       # *) Get coordinate Y from center point
  1531.       # -----------------------------------------------------------------------
  1532.       def center_y
  1533.         @center_obj.nil? ? @oy : @center_obj.y
  1534.       end
  1535.       # -----------------------------------------------------------------------
  1536.       # *) Get radius value from center point
  1537.       # -----------------------------------------------------------------------
  1538.       def radius
  1539.         Math.sqrt((range_x**2) + (range_y**2))
  1540.       end
  1541.       # -----------------------------------------------------------------------
  1542.       # *) Update circle movement
  1543.       # -----------------------------------------------------------------------
  1544.       def update_circle
  1545.         return if circle_frozen?
  1546.         return unless rotate? || @endless
  1547.         @current_degree += @speed
  1548.         update_x
  1549.         update_y
  1550.         @degree_dest = @current_degree if @endless
  1551.       end
  1552.       # -----------------------------------------------------------------------
  1553.       # *) Object is moving?
  1554.       # -----------------------------------------------------------------------
  1555.       def rotate?
  1556.         return @current_degree.round != @degree_dest.round
  1557.       end
  1558.       # -----------------------------------------------------------------------
  1559.       # *) Update X position
  1560.       # -----------------------------------------------------------------------
  1561.       def update_x
  1562.         @obj.x = center_x + (@radius *
  1563.           Math.cos(Math.radian(@current_degree))).round
  1564.       end
  1565.       # -----------------------------------------------------------------------
  1566.       # *) Update Y position
  1567.       # -----------------------------------------------------------------------
  1568.       def update_y
  1569.         @obj.y = center_y + (@radius *
  1570.           Math.sin(Math.radian(@current_degree))).round
  1571.       end
  1572.       # -----------------------------------------------------------------------
  1573.       # *) Freeze circle
  1574.       # -----------------------------------------------------------------------
  1575.       def circle_freeze
  1576.         @freeze = true
  1577.       end
  1578.       # -----------------------------------------------------------------------
  1579.       # *) Unfreeze circle
  1580.       # -----------------------------------------------------------------------
  1581.       def circle_unfreeze
  1582.         @freeze = false
  1583.       end
  1584.       # -----------------------------------------------------------------------
  1585.       # *) Is frozen?
  1586.       # -----------------------------------------------------------------------
  1587.       def circle_frozen?
  1588.         @freeze
  1589.       end
  1590.       # -----------------------------------------------------------------------
  1591.       # *) Stop circling
  1592.       # -----------------------------------------------------------------------
  1593.       def stop
  1594.         @endless = false
  1595.       end
  1596.       # -----------------------------------------------------------------------
  1597.       # *) Continue circling
  1598.       # -----------------------------------------------------------------------
  1599.       def continue
  1600.         @endless = true
  1601.       end
  1602.       # -----------------------------------------------------------------------
  1603.       # *) Endless circle?
  1604.       # -----------------------------------------------------------------------
  1605.       def endless?
  1606.         @endless
  1607.       end
  1608.     end
  1609.     # =========================================================================
  1610.     # These methods below aren't necessary to comment
  1611.     # -------------------------------------------------------------------------
  1612.     def set_circle(obj,ox = 0,oy = 0,center_obj = nil)
  1613.       @circle = Circular_Obj.new(obj,ox,oy,center_obj)
  1614.     end
  1615.    
  1616.     def stop
  1617.       @circle.stop
  1618.     end
  1619.    
  1620.     def continue
  1621.       @circle.continue
  1622.     end
  1623.    
  1624.     def endless?
  1625.       @circle.endless?
  1626.     end
  1627.    
  1628.     def circle_move(degree, dur = Graphics.frame_rate)
  1629.       @circle.circle_move(degree,dur)
  1630.     end
  1631.    
  1632.     def endless_circle(speed)
  1633.       @circle.endless_circle(speed)
  1634.     end
  1635.    
  1636.     def circle_freeze
  1637.       @circle.circle_freeze
  1638.     end
  1639.    
  1640.     def circle_unfreeze
  1641.       @circle.circle_unfreeze
  1642.     end
  1643.    
  1644.     def circle_frozed?
  1645.       @circle.circle_frozen?
  1646.     end
  1647.    
  1648.     def update_circle
  1649.       @circle.update_circle
  1650.     end
  1651.    
  1652.     def rotating?
  1653.       @circle.rotate?
  1654.     end
  1655.    
  1656.     def center_coordinate(ox,oy)
  1657.       @circle.ox = ox
  1658.       @circle.oy = oy
  1659.     end
  1660.    
  1661.     def center_distance(ox,oy)
  1662.       @circle.ox = @circle.obj.x + ox
  1663.       @circle.oy = @circle.obj.y + oy
  1664.     end
  1665.    
  1666.     def center_obj(obj)
  1667.       @circle.center_obj = obj
  1668.     end
  1669.    
  1670.     def refresh_info
  1671.       @circle.refresh_info
  1672.     end
  1673.    
  1674.   end
  1675. end
  1676. # -----------------------------------------------------------------------------
  1677. # Implements to window
  1678. # -----------------------------------------------------------------------------
  1679. class Window
  1680.   
  1681.   include THEO::Circular
  1682.   
  1683.   alias theolized_circle_window_init initialize
  1684.   def initialize(*args)
  1685.     theolized_circle_window_init(*args)
  1686.     set_circle(self,x,y)
  1687.   end
  1688.   
  1689.   alias window_circle_update update
  1690.   def update
  1691.     window_circle_update
  1692.     update_circle
  1693.   end
  1694.   
  1695. end
  1696. # -----------------------------------------------------------------------------
  1697. # Implements to sprite
  1698. # -----------------------------------------------------------------------------
  1699. class Sprite
  1700.   
  1701.   include THEO::Circular
  1702.   
  1703.   alias theolized_circle_init initialize
  1704.   def initialize(*args)
  1705.     theolized_circle_init(*args)
  1706.     set_circle(self,x,y)
  1707.   end
  1708.   
  1709.   alias sprite_circle_update update
  1710.   def update
  1711.     sprite_circle_update
  1712.     update_circle
  1713.   end
  1714.   
  1715. end
  1716. end
  1717. #==============================================================================
  1718. # ** Clone Image / Afterimage Base
  1719. #------------------------------------------------------------------------------
  1720. #  This basic modules is purposely to make sprite can be cloned / duplicated.
  1721. # In more complex concept, it could be used as base of afterimage. It's used
  1722. # within my sideview battle system
  1723. #------------------------------------------------------------------------------
  1724. if $imported[:Theo_CloneImage]  # Activation flag
  1725. #==============================================================================
  1726. class Sprite
  1727.   attr_reader :clone_bitmap
  1728.   # ---------------------------------------------------------------------------
  1729.   # *) Aliased Initialize
  1730.   # ---------------------------------------------------------------------------
  1731.   alias theo_clonesprites_init initialize
  1732.   def initialize(*args)
  1733.     @cloned_sprites = []
  1734.     @color_flash = Color.new(0,0,0,0)
  1735.     @alpha_val = 0.0
  1736.     @alpha_ease = 0.0
  1737.     @dur_flash = 0
  1738.     theo_clonesprites_init(*args)
  1739.   end
  1740.   # ---------------------------------------------------------------------------
  1741.   # *) Base function to clone sprite
  1742.   # ---------------------------------------------------------------------------
  1743.   def clone(z_pos = 0, clone_bitmap = false)
  1744.     @cloned_sprites.delete_if {|spr| spr.disposed? }
  1745.     cloned = clone_class.new(viewport)
  1746.     cloned.x = x
  1747.     cloned.y = y
  1748.     cloned.bitmap = bitmap
  1749.     cloned.bitmap = bitmap.clone if clone_bitmap
  1750.     if z_pos != 0
  1751.       cloned.z = z + z_pos
  1752.     else
  1753.       @cloned_sprites.each do |spr|
  1754.         spr.z -= 1
  1755.       end
  1756.       cloned.z = z - 1
  1757.     end
  1758.     cloned.src_rect.set(src_rect)
  1759.     cloned.zoom_x = zoom_x
  1760.     cloned.zoom_y = zoom_y
  1761.     cloned.angle = angle
  1762.     cloned.mirror = mirror
  1763.     cloned.opacity = opacity
  1764.     cloned.blend_type = blend_type
  1765.     cloned.color.set(color)
  1766.     cloned.tone.set(tone)
  1767.     cloned.visible = visible
  1768.     cloned.bush_depth = bush_depth
  1769.     cloned.bush_opacity = bush_opacity
  1770.     cloned.ox = ox
  1771.     cloned.oy = oy
  1772.     on_after_cloning(cloned)
  1773.     @cloned_sprites.push(cloned)
  1774.     cloned
  1775.   end
  1776.    
  1777.   def on_after_cloning(cloned)
  1778.     cloned.theo_clonesprites_flash(@color_flash, @dur_flash)
  1779.     # Abstract method. Overwrite it as you want
  1780.   end
  1781.   
  1782.   # Sprite class for cloned sprite
  1783.   def clone_class
  1784.     Sprite
  1785.   end
  1786.   
  1787.   alias theo_clonesprites_flash flash
  1788.   def flash(color, duration)
  1789.     theo_clonesprites_flash(color, duration)
  1790.     @dur_flash = duration
  1791.     @color_flash = color.clone
  1792.     @alpha_val = color.alpha.to_f
  1793.     @alpha_ease = @alpha_val / duration
  1794.   end
  1795.   
  1796.   alias theo_clonesprites_update update
  1797.   def update
  1798.     theo_clonesprites_update
  1799.     @dur_flash = [@dur_flash - 1,0].max
  1800.     @alpha_val = [@alpha_val - @alpha_ease,0.0].max
  1801.     @color_flash.alpha = @alpha_val
  1802.   end
  1803.   
  1804. end

  1805. # =============================================================================
  1806. # Afterimages basic module for all sprite base instance object. Any classes
  1807. # that inherited from Sprite_Base will highly possible to make afterimage
  1808. # effect.
  1809. #
  1810. # How to setup :
  1811. # - Make sure "def afterimage" should return to true
  1812. # - Set rate and opacity easing
  1813. # - Higher rate means the higher delay between displayed afterimage
  1814. # - Higher opac means the faster afterimage will fadeout
  1815. # =============================================================================

  1816. class Sprite_Base < Sprite
  1817.   attr_accessor :afterimage       # Afterimage flag
  1818.   attr_accessor :afterimage_opac  # Afterimage opacity easing
  1819.   attr_accessor :afterimage_rate  # Afterimage thick rate
  1820.   # ---------------------------------------------------------------------------
  1821.   # *) Aliased initialize
  1822.   # ---------------------------------------------------------------------------
  1823.   alias theo_afterimagebase_init initialize
  1824.   def initialize(*args)
  1825.     init_afterimage_base
  1826.     theo_afterimagebase_init(*args)
  1827.   end
  1828.   # ---------------------------------------------------------------------------
  1829.   # *) Initialize afterimage variables
  1830.   # ---------------------------------------------------------------------------
  1831.   def init_afterimage_base
  1832.     @afterimage = false
  1833.     @afterimage_count = 0
  1834.     @afterimage_rate = 3
  1835.     @afterimage_opac = 5
  1836.     @afterimages = []
  1837.   end
  1838.   # ---------------------------------------------------------------------------
  1839.   # *) Aliased update method
  1840.   # ---------------------------------------------------------------------------
  1841.   alias theo_afterimagebase_update update
  1842.   def update
  1843.     theo_afterimagebase_update
  1844.     update_afterimage_effect
  1845.   end
  1846.   # ---------------------------------------------------------------------------
  1847.   # *) Update afterimage
  1848.   # ---------------------------------------------------------------------------
  1849.   def update_afterimage_effect
  1850.     # Update and delete afterimage once its opacity has reached zero
  1851.     @afterimages.delete_if do |image|
  1852.       image.opacity -= afterimage_opac
  1853.       image.update if updating_afterimages?
  1854.       if image.opacity == 0
  1855.         image.dispose
  1856.       end
  1857.       image.disposed?
  1858.     end
  1859.     return unless afterimage
  1860.     @afterimage_count += 1
  1861.     if @afterimage_count % afterimage_rate == 0
  1862.       @afterimages.push(clone)
  1863.     end
  1864.   end
  1865.   # ---------------------------------------------------------------------------
  1866.   # *) Is afterimages are need to be updated?
  1867.   # ---------------------------------------------------------------------------
  1868.   def updating_afterimages?
  1869.     return false
  1870.   end
  1871.   # ---------------------------------------------------------------------------
  1872.   # *) Disposes sprite alongside the afterimage to prevent RGSS3 crash
  1873.   # ---------------------------------------------------------------------------
  1874.   alias theo_afterimagebase_dispose dispose
  1875.   def dispose
  1876.     theo_afterimagebase_dispose
  1877.     @afterimages.each do |afimg|
  1878.       afimg.dispose
  1879.     end
  1880.   end
  1881.   
  1882. end
  1883. end
  1884. #==============================================================================
  1885. # ** Sprite Rotate Basic module
  1886. #------------------------------------------------------------------------------
  1887. #  This basic module only dealing with sprite angle. It's used within my
  1888. # sideview battle system to rotate weapon icon.
  1889. #------------------------------------------------------------------------------
  1890. if $imported[:Theo_RotateImage]
  1891. #==============================================================================
  1892. module Theo
  1893.   module Rotation
  1894.     # -------------------------------------------------------------------------
  1895.     # *) Init rotate function
  1896.     # -------------------------------------------------------------------------
  1897.     def init_rotate
  1898.       @degree = self.angle.to_f
  1899.       @target_degree = 0
  1900.       @rotating = false
  1901.       @rotate_speed = 0.0
  1902.     end
  1903.     # -------------------------------------------------------------------------
  1904.     # *) Change to specific angle
  1905.     # -------------------------------------------------------------------------
  1906.     def change_angle(target_degree, duration)
  1907.       @degree = self.angle.to_f
  1908.       @target_degree = target_degree.to_f
  1909.       if duration == 0
  1910.         @rotate_speed = target_degree
  1911.       else
  1912.         @rotate_speed = (target_degree - @degree) / duration
  1913.       end
  1914.       @rotating = true
  1915.     end
  1916.     # -------------------------------------------------------------------------
  1917.     # *) Update rotation
  1918.     # -------------------------------------------------------------------------
  1919.     def update_rotation
  1920.       return unless @rotating
  1921.       @degree += @rotate_speed
  1922.       new_angle = @degree.round
  1923.       self.angle = new_angle
  1924.       if new_angle == @target_degree
  1925.         init_rotate
  1926.       end
  1927.     end
  1928.     # -------------------------------------------------------------------------
  1929.     # *) Start rotate to additional degree
  1930.     # -------------------------------------------------------------------------
  1931.     def start_rotate(degree_plus, duration)
  1932.       change_angle(@degree + degree_plus, duration)
  1933.     end
  1934.    
  1935.   end
  1936. end
  1937. # -----------------------------------------------------------------------------
  1938. # Implements on sprite
  1939. # -----------------------------------------------------------------------------
  1940. class Sprite
  1941.   include Theo::Rotation
  1942.   
  1943.   alias theo_spr_rotate_init initialize
  1944.   def initialize(viewport = nil)
  1945.     theo_spr_rotate_init(viewport)
  1946.     init_rotate
  1947.   end
  1948.   
  1949.   alias theo_spr_rotate_update update
  1950.   def update
  1951.     theo_spr_rotate_update
  1952.     update_rotation
  1953.   end
  1954.   
  1955. end

  1956. end
  1957. #==============================================================================
  1958. # ** Smooth_Slide
  1959. #------------------------------------------------------------------------------
  1960. #  This module provides basic module for smooth sliding. It can be implemented
  1961. # to any classes as long as they have x and y.
  1962. #
  1963. # Avalaible methods :
  1964. # - smooth_move(x,y,dur,[reverse])
  1965. #   Tells the object to move to specific x,y coordinate in given time duration
  1966. #   in frame. If reverse set to true, object will start with maximum speed
  1967. #
  1968. # - smooth_slide(x,y,dur,[reverse])
  1969. #   Tells the object to slide to specific x,y coordinate from original position
  1970. #   in given time duration in frame. If reverse set to true, object will start
  1971. #   with maximum speed
  1972. #------------------------------------------------------------------------------
  1973. if $imported[:Theo_SmoothMove]  # Activation Flag
  1974. #==============================================================================
  1975. module Smooth_Slide
  1976.   # ---------------------------------------------------------------------------
  1977.   # Initialize smooth movement data
  1978.   # ---------------------------------------------------------------------------
  1979.   def init_smove
  1980.     @smooth_dur = 0     # Travel duration
  1981.     @accel_x = 0.0      # Acceleration X
  1982.     @accel_y = 0.0      # Acceleration Y
  1983.     @vel_x = 0.0        # Velocity X
  1984.     @vel_y = 0.0        # Velocity Y
  1985.     @sreal_x = self.x   # Real position X
  1986.     @sreal_y = self.y   # Real Position Y
  1987.     @starget_x = 0.0    # Target X
  1988.     @starget_y = 0.0    # Target Y
  1989.     @srev = false       # Reverse Flag
  1990.     @smove = false      # Moving Flag
  1991.    
  1992.     # The reason why I give 's' in front of most instance variables is for
  1993.     # uniqueness. Well, if there is any basic module / script out there that
  1994.     # also use same instance name, it may causes incompatibility
  1995.    
  1996.   end
  1997.   # ---------------------------------------------------------------------------
  1998.   # Do smooth movement
  1999.   # ---------------------------------------------------------------------------
  2000.   def smooth_move(x,y,dur,reverse = false)
  2001.     init_smove
  2002.     @srev = reverse
  2003.     @smove = true
  2004.     @smooth_dur = dur
  2005.     @sreal_x = self.x.to_f
  2006.     @sreal_y = self.y.to_f
  2007.     @starget_x = x.to_i
  2008.     @starget_y = y.to_i
  2009.     calc_accel
  2010.   end
  2011.   # ---------------------------------------------------------------------------
  2012.   # Do smooth slide
  2013.   # ---------------------------------------------------------------------------
  2014.   def smooth_slide(x,y,dur,reverse = false)
  2015.     tx = x + self.x
  2016.     ty = y + self.y
  2017.     smooth_move(tx,ty,dur,reverse)
  2018.   end
  2019.   # ---------------------------------------------------------------------------
  2020.   # Calculate acceleration
  2021.   # ---------------------------------------------------------------------------
  2022.   def calc_accel
  2023.     # Get travel distance
  2024.     dist_x = @starget_x - @sreal_x
  2025.     dist_y = @starget_y - @sreal_y
  2026.    
  2027.     # Calculate acceleration
  2028.     @accel_x = (dist_x/((@smooth_dur**2)/2.0))
  2029.     @accel_y = (dist_y/((@smooth_dur**2)/2.0))
  2030.    
  2031.     # If reverse, velocity started on max speed
  2032.     if @srev
  2033.       @vel_x = (@accel_x * (@smooth_dur.to_f - 0.5))
  2034.       @vel_y = (@accel_y * (@smooth_dur.to_f - 0.5))
  2035.     end
  2036.   end
  2037.   # ---------------------------------------------------------------------------
  2038.   # Execute end smooth
  2039.   # ---------------------------------------------------------------------------
  2040.   def end_smooth_slide
  2041.     init_smove
  2042.   end
  2043.   # ---------------------------------------------------------------------------
  2044.   # Update Smooth movement
  2045.   # ---------------------------------------------------------------------------
  2046.   def update_smove
  2047.     if @smove
  2048.       # If not reversed. Increase velocity on the first time executed
  2049.       if !@srev
  2050.         @vel_x += @accel_x
  2051.         @vel_y += @accel_y
  2052.       end
  2053.       
  2054.       # Give increment / decrement upon real position
  2055.       @sreal_x = (@starget_x > @sreal_x ?
  2056.         [@sreal_x + @vel_x, @starget_x].min :
  2057.         [@sreal_x + @vel_x, @starget_x].max)
  2058.       @sreal_y = (@starget_y > @sreal_y ?
  2059.         [@sreal_y + @vel_y, @starget_y].min :
  2060.         [@sreal_y + @vel_y, @starget_y].max)
  2061.       
  2062.       # Rounded real position
  2063.       self.x = @sreal_x.round
  2064.       self.y = @sreal_y.round
  2065.       
  2066.       # If reversed, decrease velocity after make a change to real position
  2067.       if @srev
  2068.         @vel_x -= @accel_x
  2069.         @vel_y -= @accel_y
  2070.       end
  2071.       
  2072.       # If target has reach it's destination, call end execution
  2073.       if (self.x == @starget_x && self.y == @starget_y)
  2074.         end_smooth_slide
  2075.       end
  2076.     end
  2077.   end
  2078.   # ---------------------------------------------------------------------------
  2079.   # Get smooth moving flag
  2080.   # ---------------------------------------------------------------------------
  2081.   def smoving?
  2082.     @smove
  2083.   end
  2084.   
  2085. end
  2086. # -----------------------------------------------------------------------------
  2087. # Implemented on sprite
  2088. # -----------------------------------------------------------------------------
  2089. class Sprite
  2090.   include Smooth_Slide
  2091.   
  2092.   alias smooth_init initialize
  2093.   def initialize(v=nil)
  2094.     smooth_init(v)
  2095.     init_smove
  2096.   end
  2097.   
  2098.   alias smooth_update update
  2099.   def update
  2100.     smooth_update
  2101.     update_smove
  2102.   end
  2103.   
  2104. end
  2105. # -----------------------------------------------------------------------------
  2106. # Implemented on window
  2107. # -----------------------------------------------------------------------------
  2108. class Window
  2109.   include Smooth_Slide
  2110.   
  2111.   alias smooth_init initialize
  2112.   def initialize(*args)
  2113.     smooth_init(*args)
  2114.     init_smove
  2115.   end
  2116.   
  2117.   alias smooth_update update
  2118.   def update
  2119.     smooth_update
  2120.     update_smove
  2121.   end
  2122.   
  2123. end

  2124. end
  2125. # =============================================================================
  2126. # Below this line are just miscellaneous functions
  2127. # -----------------------------------------------------------------------------
  2128. # Debug print line
  2129. # -----------------------------------------------------------------------------
  2130. def debug
  2131.   puts "这一行已被执行"
  2132. end
  2133. # -----------------------------------------------------------------------------
  2134. # Debug print frame
  2135. # -----------------------------------------------------------------------------
  2136. def debugc
  2137.   puts Graphics.frame_count
  2138. end
  2139. # -----------------------------------------------------------------------------
  2140. # Copy object. Because calling clone/dup sometimes is not enough
  2141. # -----------------------------------------------------------------------------
  2142. def copy(object)
  2143.   Marshal.load(Marshal.dump(object))
  2144. end
复制代码

防卡顿脚本:
  1. #===============================================================================
  2. # TheoAllen - 终极防止卡顿
  3. # Version : 1.1
  4. # Language : English
  5. #-------------------------------------------------------------------------------
  6. # 帮助编写此脚本的人 :
  7. # - Tsukihime
  8. # - KilloZapit
  9. # - Galv
  10. #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  11. # Contact :
  12. #-------------------------------------------------------------------------------
  13. # *> http://www.rpgmakerid.com
  14. # *> http://www.rpgmakervxace.net
  15. # *> http://www.theolized.com
  16. #===============================================================================
  17. ($imported ||= {})[:Theo_AntiLag] = true
  18. #===============================================================================
  19. # Change Logs:
  20. # ------------------------------------------------------------------------------
  21. # 2015.02.20 - Added page check enhancer to work with parallel process
  22. # 2015.01.25 - Compatibility with Shaz's Mouse Script. def events_xy now should
  23. #              always return array,
  24. #            - Avoid error 'undefined method delete_sprite for nilClass'
  25. # 2015.01.01 - Avoid unexpected error 'undefined method spriteset for scene'
  26. # 2014.12.05 - Finished
  27. #===============================================================================
  28. =begin

  29.   ------------------------------------------
  30.   *) 介绍 :
  31.   ------------------------------------------
  32.   如你所知, RPG Maker 游戏中出现卡顿是个常见问题.
  33.   你开始猜想会不会是因为在地图上设定了过多的事件,因此,为了防卡,你将地图拆分
  34.   为小块,同时减少事件的使用.

  35.   这也不全错,因为过多事件的确会让程序花更多时间去检查。可是,减少事件并不能
  36.   极大地优化游戏速度。
  37.   本脚本将提升游戏运行效率,阻止一些不必要的更新以提升游戏速度。
  38.    
  39.   注意,因为我改了许多地方,因此不能完全保证其可以较高的兼容其他脚本。
  40.   相比于兼容其他人的脚本,我很可能会优先兼容我自己的脚本。
  41.   
  42.   ------------------------------------------
  43.   *) 使用方法 :
  44.   ------------------------------------------
  45.   将本脚本防在插件脚本之下,Main之上。建议尽可能放在其他自定义脚本之上.
  46.   
  47.   如果发生兼容性的问题,在设定部分根据自己的需要进行修改。
  48.   
  49.   ------------------------------------------
  50.   *)   使用条款 :
  51.   署名脚本作者, TheoAllen. 你可以自由编辑此脚本,只要你不声明你是脚本的原作者
  52.   如果你想用此脚本于商业游戏,请和我共享收益.别忘了给我一份免费的游戏拷贝.
  53.   
  54.   在标题部分还写有帮助编写此脚本的人,如果要使用本脚本于商业游戏,记得也给他们
  55.   发一个免费的游戏拷贝 ;)
  56.   
  57. =end
  58. #==============================================================================
  59. # 设定 :
  60. #==============================================================================
  61. module Theo
  62.   module AntiLag
  63.    
  64.   #=============================================================================
  65.   # *) 普通优化
  66.   #-----------------------------------------------------------------------------
  67.   # 较为普通的优化方式,在地图中的总事件数为200 - 300之间时效果明显.
  68.   #=============================================================================
  69.   
  70.   #-----------------------------------------------------------------------------
  71.     Optimize_XY     = true
  72.   #-----------------------------------------------------------------------------
  73.   # 默认下,检查事件位置会检查同一地图中的全部事件的位置。如果你要检查事件的x,y
  74.   # 坐标,系统会确认全部事件是否匹配。启用此优化后,全部事件会登记到某一个table上。
  75.   # 检查时不会检查全部地图的事件,而是会检查某一个table内的事件。
  76.   #
  77.   # 建议将此优化设定为 true. 注意,此优化可能与“按像素移动”的脚本不兼容,
  78.   # 因为其使用的是新的碰撞接触系统,而不是默认的图块网格.
  79.   #-----------------------------------------------------------------------------
  80.   
  81.   #-----------------------------------------------------------------------------
  82.     Optimize_Event  = true
  83.   #-----------------------------------------------------------------------------
  84.   # 默认下,如果系统引擎想要检查是否有事件被触发,其会检查地图中的全部事件。
  85.   # 且每一帧都会检查。如果你在地图中设定了200个事件,则每秒会检查60 x 200次.
  86.   #
  87.   # 启用此优化后,如果某事件被触发,其会登记到一个记录列表中。
  88.   # 之后引擎只会在这个记录列表中检查是否有事件被触发,而不会检查地图中的全部事件。
  89.   #-----------------------------------------------------------------------------
  90.   
  91.   #-----------------------------------------------------------------------------
  92.     Optimize_Sprite = true
  93.   #-----------------------------------------------------------------------------
  94.   # 默认下,系统引擎会更新画面外的全部精灵。有时,不必要的画面外更新会浪费时间. By
  95.   # 启用此优化后,将会无视画面外精灵的更新。
  96.   #-----------------------------------------------------------------------------
  97.    
  98.   #=============================================================================
  99.   # *) 终极优化
  100.   #-----------------------------------------------------------------------------
  101.   # 此优化可以解决在同一地图中事件数大于230时发生卡顿的问题。
  102.   # 使用了一些像按table搜索和随时处理任何不必要精灵的方式。
  103.   #=============================================================================
  104.    
  105.   #-----------------------------------------------------------------------------
  106.     Table_Limit_Search = 230
  107.   #-----------------------------------------------------------------------------
  108.   # 按Table搜索是一种从地图table中拾取事件来读取的自定义算法。
  109.   # 区别于迭代所有事件并检查它们是否在画面中,此优化方式会先检查事件是否处于
  110.   # 玩家可见的地图table中。所以,离玩家画面很远的事件不会被更新。
  111.   # 但是,所并行处理和自动执行的事件,和事件中的移动路线设定仍然会正常更新。
  112.   #
  113.   # 当地图中的总事件数超过限制,脚本会使用table搜索的算法。当事件数为999 ,或
  114.   # 10.000 时你就不用担心了.
  115.   #
  116.   # Table搜索需要将 Optimize_XY 设定为 true.
  117.   #
  118.   # 如果你不想使用table搜索的算法,将其设定为nil即可.
  119.   #-----------------------------------------------------------------------------
  120.   
  121.   #-----------------------------------------------------------------------------
  122.     Table_Range_Search = 2
  123.   #-----------------------------------------------------------------------------
  124.   # 确定table搜索会检查的范围. 设定为 3 则意为会更新到画面外3图块的区域。
  125.   #
  126.   # 注意,范围大小会影响游戏表现效果。
  127.   # 建议设定为 2 - 4
  128.   #-----------------------------------------------------------------------------
  129.   
  130.   #-----------------------------------------------------------------------------
  131.     Dispose_Sprite  = true
  132.   #-----------------------------------------------------------------------------
  133.   # 有时,限制事件的更新远远不够。精灵对象也是个游戏表现杀手。
  134.   # 无视画面外精灵会击打提升游戏顺畅度。此优化仅在启用table搜索时有效。
  135.   #
  136.   # 即时无视精灵有时会出现一些问题,可以设定为false来禁用此功能.
  137.   #-----------------------------------------------------------------------------
  138.   
  139.   #-----------------------------------------------------------------------------
  140.     PageCheck_Enchancer = true
  141.   #-----------------------------------------------------------------------------
  142.   # 在同一地图中存在事件页有20页的事件,且有一大堆并行处理改变变量或开关时,你会
  143.   # 见到明显的卡顿。
  144.   #
  145.   # 此优化仅会刷新画面内事件的事件页。
  146.   # 刷新地图外的事件有时是愚蠢的,因为就算是画面内,玩家也永远都不会知道暗中发生
  147.   # 了什么。
  148.   #
  149.   # 可是,此优化可能会毁了某些系统,其仅为实验性功能。
  150.   #-----------------------------------------------------------------------------
  151.   
  152.   end
  153. end

  154. #===============================================================================
  155. # *) 最后的注释 :
  156. #-------------------------------------------------------------------------------
  157. # 最后说一下,以上是我对优化游戏速度的一些考量。游戏表现效果受到各种因素的影响:
  158. #
  159. # - 你电脑的 CPU 速度
  160. # - 你的笔记本电脑 / PC 的温度
  161. # - 你的电脑的 CPU 功率
  162. # - 任务数量
  163. # - 别人的脚本
  164. #
  165. # 以前我都是在旧电脑中使用 RM . 当我换更高级的笔记本后,发现60FPS真的是很顺滑.
  166. #
  167. # 如果你的 CPU 太热了, 关掉你的笔记本/ PC 使其冷却.
  168. # 因为风扇故障,有次我的笔记本过热了.玩我的游戏时仅10 FPS.
  169. # 我使用了自己的防卡脚本,但是没有一个起作用,直到我发现原来是笔记本过热了。
  170. #
  171. # 节能模式也会影响游戏体验. 为了防止卡顿,你可以试着切换到高性能模式.
  172. # 有一次我的朋友在节能模式下玩我的游戏,才得 15 FPS.
  173. #
  174. # 一次性执行多个进程,在RM游戏中也会出现一些卡顿。
  175. # 类似于画面在一段时间内不更新。
  176. #
  177. # 一些不完备的脚本也可能会影响显示效果。本防卡脚本仅在使用默认脚本的情况下进行
  178. # 测试。
  179. #
  180. #-------------------------------------------------------------------------------
  181. # *) 以下部分,除非你会写脚本,否则请勿改动。
  182. #===============================================================================

  183. #===============================================================================
  184. # ** MapTable
  185. #-------------------------------------------------------------------------------
  186. #  This class used to register the event into 2D table to increase performance
  187. #===============================================================================

  188. class MapTable
  189.   #-----------------------------------------------------------------------------
  190.   # * Initialize
  191.   #-----------------------------------------------------------------------------
  192.   def initialize
  193.     @table = []
  194.     ($game_map.width + 1).times do |x|
  195.       @table[x] = []
  196.       ($game_map.height + 1).times do |y|
  197.         @table[x][y] = []
  198.       end
  199.     end
  200.   end
  201.   #-----------------------------------------------------------------------------
  202.   # * Set value
  203.   #-----------------------------------------------------------------------------
  204.   def set(x,y,val)
  205.     @table[x][y] << val
  206.   end
  207.   #-----------------------------------------------------------------------------
  208.   # * Get array
  209.   #-----------------------------------------------------------------------------
  210.   def get(x,y)
  211.     @table[x][y]
  212.   end
  213.   
  214. end

  215. #===============================================================================
  216. # ** Array
  217. #===============================================================================

  218. class Array
  219.   
  220.   # Just a fool proof
  221.   def values
  222.     return self
  223.   end
  224.   
  225. end

  226. #===============================================================================
  227. # ** Game_Map
  228. #===============================================================================

  229. class Game_Map
  230.   #-----------------------------------------------------------------------------
  231.   # * Public attributes
  232.   #-----------------------------------------------------------------------------
  233.   attr_accessor :event_redirect     # Redirect events
  234.   attr_reader :forced_update_events # To keep force move route updated
  235.   attr_reader :keep_update_events   # To keep parallel process updated
  236.   attr_reader :cached_events        # To store event that need to be updated
  237.   attr_reader :starting_events      # To store activated event
  238.   attr_reader :table                # 2D Map table
  239.   #-----------------------------------------------------------------------------
  240.   # * Constant
  241.   #-----------------------------------------------------------------------------
  242.   EVENT_LIMIT = Theo::AntiLag::Table_Limit_Search
  243.   RANGE = Theo::AntiLag::Table_Range_Search
  244.   #-----------------------------------------------------------------------------
  245.   # * Alias method : Setup Events
  246.   #-----------------------------------------------------------------------------
  247.   alias theo_antilag_setup_events setup_events
  248.   def setup_events
  249.     @table = MapTable.new
  250.     @forced_update_events = []
  251.     @keep_update_events = []
  252.     @starting_events = []
  253.     @refreshed_events = []
  254.     theo_antilag_setup_events
  255.     select_on_screen_events
  256.   end
  257.   #-----------------------------------------------------------------------------
  258.   # * Overwrite method : Events
  259.   #-----------------------------------------------------------------------------
  260.   def events
  261.     @event_redirect ? @cached_events : @events
  262.   end
  263. #///////////////////////////////////////////////////////////////////////////////
  264.   if Theo::AntiLag::Optimize_XY
  265. #///////////////////////////////////////////////////////////////////////////////
  266.   #-----------------------------------------------------------------------------
  267.   # * Overwrite method : Event XY
  268.   #-----------------------------------------------------------------------------
  269.   def events_xy(x, y)
  270.     @table.get(x,y) || []
  271.   end
  272.   #-----------------------------------------------------------------------------
  273.   # * Overwrite method : Event XY nt
  274.   #-----------------------------------------------------------------------------
  275.   def events_xy_nt(x, y)
  276.     @table.get(x,y).select do |event|
  277.       event.pos_nt?(x, y)
  278.     end
  279.   end
  280. #///////////////////////////////////////////////////////////////////////////////
  281.   end
  282. #///////////////////////////////////////////////////////////////////////////////
  283.   if Theo::AntiLag::Optimize_Event
  284. #///////////////////////////////////////////////////////////////////////////////
  285.   #-----------------------------------------------------------------------------
  286.   # * Overwrite method : Setup starting event
  287.   #-----------------------------------------------------------------------------
  288.   def setup_starting_map_event
  289.     event = @starting_events[0]
  290.     event.clear_starting_flag if event
  291.     @interpreter.setup(event.list, event.id) if event
  292.     event
  293.   end
  294.   #-----------------------------------------------------------------------------
  295.   # * Overwrite method : Any event starting?
  296.   #-----------------------------------------------------------------------------
  297.   def any_event_starting?
  298.     !@starting_events.empty?
  299.   end
  300. #///////////////////////////////////////////////////////////////////////////////
  301.   end
  302. #///////////////////////////////////////////////////////////////////////////////
  303.   #-----------------------------------------------------------------------------
  304.   # * Overwrite method : Refresh
  305.   #-----------------------------------------------------------------------------
  306.   def refresh
  307.     return table_refresh if table_update? && Theo::AntiLag::PageCheck_Enchancer
  308.     @events.each_value {|event| next if event.never_refresh; event.refresh }
  309.     @common_events.each {|event| event.refresh }
  310.     refresh_tile_events
  311.     @need_refresh = false
  312.   end
  313.   #-----------------------------------------------------------------------------
  314.   # * New method : Refresh event by table search
  315.   #-----------------------------------------------------------------------------
  316.   def table_refresh
  317.     @refreshed_events = []
  318.     @tile_events = []
  319.     @common_events.each {|event| event.refresh }
  320.     @need_refresh = false
  321.   end
  322.   #-----------------------------------------------------------------------------
  323.   # * Overwrite method : Update events
  324.   #-----------------------------------------------------------------------------
  325.   def update_events
  326.     last_events = (@cached_events.dup rescue @events.values)
  327.     select_on_screen_events
  328.     events = @cached_events | @keep_update_events | @forced_update_events
  329.     if Theo::AntiLag::Dispose_Sprite
  330.       offscreen_events = last_events - events
  331.       offscreen_events.each {|event| event.delete_sprite}
  332.     end
  333.     events.each {|event| event.update}
  334.     @common_events.each {|event| event.update}
  335.   end
  336.   #-----------------------------------------------------------------------------
  337.   # * New method : Select on screen events
  338.   #-----------------------------------------------------------------------------
  339.   def select_on_screen_events
  340.     unless table_update?
  341.       @cached_events = @events.values
  342.       return
  343.     end
  344.     #---------------------------------------------------------------------------
  345.     # * Table search algorithm
  346.     #---------------------------------------------------------------------------
  347.     new_dpx = display_x.to_i
  348.     new_dpy = display_y.to_i
  349.     dpx = loop_horizontal? ? new_dpx - RANGE : [new_dpx - RANGE, 0].max
  350.     dpy = loop_vertical? ? new_dpy - RANGE : [new_dpy - RANGE, 0].max
  351.     sw = (Graphics.width >> 5) + RANGE * 2
  352.     sh = (Graphics.height >> 5) + RANGE * 2
  353.     @cached_events = []
  354.     sw.times do |x|
  355.       sh.times do |y|
  356.         xpos = loop_horizontal? ? (x + dpx) % width : x + dpx
  357.         ypos = loop_vertical? ? (y + dpy) % height : y + dpy
  358.         next if xpos >= width || ypos >= height
  359.         ary = @table.get(xpos, ypos)
  360.         ary.each do |ev|
  361.           unless @refreshed_events.include?(ev.id)
  362.             ev.refresh
  363.             @tile_events << ev if ev.tile?
  364.             @refreshed_events << ev.id
  365.           end
  366.         end if Theo::AntiLag::PageCheck_Enchancer
  367.         @cached_events += ary
  368.       end
  369.     end
  370.     @cached_events.uniq!
  371.   end
  372.   #-----------------------------------------------------------------------------
  373.   # * Check if table search need to be performed or not
  374.   #-----------------------------------------------------------------------------
  375.   def table_update?
  376.     EVENT_LIMIT && @events.size > EVENT_LIMIT && Theo::AntiLag::Optimize_XY
  377.   end
  378.   
  379. end

  380. #===============================================================================
  381. # ** Game_Temp
  382. #===============================================================================

  383. class Game_Temp
  384.   attr_reader :event_sprites
  385.   #-----------------------------------------------------------------------------
  386.   # * Alias method : Initialize
  387.   #-----------------------------------------------------------------------------
  388.   alias theo_antilag_init initialize
  389.   def initialize
  390.     theo_antilag_init
  391.     @event_sprites = {}
  392.   end
  393.   
  394. end

  395. #===============================================================================
  396. # ** Game_CharacterBase
  397. #===============================================================================

  398. class Game_CharacterBase
  399.   #-----------------------------------------------------------------------------
  400.   # * Empty method : Sprite
  401.   #-----------------------------------------------------------------------------
  402.   def sprite
  403.     return nil
  404.   end
  405.   #-----------------------------------------------------------------------------
  406.   # * Empty method : Sprite =
  407.   #-----------------------------------------------------------------------------
  408.   def sprite=(spr)
  409.   end
  410.   
  411. end

  412. #===============================================================================
  413. # ** Game_Event
  414. #===============================================================================

  415. class Game_Event
  416.   #-----------------------------------------------------------------------------
  417.   # * Never refesh flag
  418.   #-----------------------------------------------------------------------------
  419.   attr_reader :never_refresh
  420.   #-----------------------------------------------------------------------------
  421.   # * Alias method : Initialize
  422.   #-----------------------------------------------------------------------------
  423.   alias theo_antilag_init initialize
  424.   def initialize(map_id, event)
  425.     theo_antilag_init(map_id, event)
  426.     $game_map.table.set(x,y,self)
  427.     @last_x = @x
  428.     @last_y = @y
  429.   end
  430.   #-----------------------------------------------------------------------------
  431.   # * Alias method : Update
  432.   #-----------------------------------------------------------------------------
  433.   alias theo_antilag_update update
  434.   def update
  435.     if (sprite && sprite.disposed?) || sprite.nil?
  436.       spriteset = SceneManager.scene.spriteset
  437.       return unless spriteset
  438.       spriteset.add_sprite(self)
  439.     end
  440.     theo_antilag_update
  441.     if Theo::AntiLag::Optimize_XY && (@last_x != @x || @last_y != @y)
  442.       $game_map.table.get(@last_x, @last_y).delete(self)
  443.       $game_map.table.set(@x,@y,self)
  444.       @last_x = @x
  445.       @last_y = @y
  446.     end
  447.   end
  448.   #-----------------------------------------------------------------------------
  449.   # * Alias method : Start
  450.   #-----------------------------------------------------------------------------
  451.   alias theo_antilag_start start
  452.   def start
  453.     theo_antilag_start
  454.     return unless Theo::AntiLag::Optimize_Event
  455.     $game_map.starting_events << self if @starting
  456.   end
  457.   #-----------------------------------------------------------------------------
  458.   # * Alias method : Clear starting flag
  459.   #-----------------------------------------------------------------------------
  460.   alias theo_antilag_clear_start clear_starting_flag
  461.   def clear_starting_flag
  462.     theo_antilag_clear_start
  463.     return unless Theo::AntiLag::Optimize_Event
  464.     $game_map.starting_events.delete(self)
  465.   end
  466.   #-----------------------------------------------------------------------------
  467.   # * Alias method : Setup page setting
  468.   #-----------------------------------------------------------------------------
  469.   alias theo_antilag_setup_page_settings setup_page_settings
  470.   def setup_page_settings
  471.     theo_antilag_setup_page_settings
  472.     if @event.pages.size == 1 && no_condition?(@event.pages[0].condition)
  473.       @never_refresh = true
  474.     end
  475.     if @trigger == 3 || @interpreter
  476.       $game_map.keep_update_events << self
  477.       $game_map.keep_update_events.uniq!
  478.     else
  479.       $game_map.keep_update_events.delete(self)
  480.     end
  481.   end
  482.   #-----------------------------------------------------------------------------
  483.   # * Check if the events has no page condition
  484.   #-----------------------------------------------------------------------------
  485.   def no_condition?(page)
  486.     !page.switch1_valid && !page.switch2_valid && !page.variable_valid &&
  487.       !page.self_switch_valid && !page.item_valid && !page.actor_valid
  488.   end
  489.   #-----------------------------------------------------------------------------
  490.   # * Delete sprite
  491.   #-----------------------------------------------------------------------------
  492.   def delete_sprite
  493.     sprset = SceneManager.scene.spriteset
  494.     return unless sprset
  495.     SceneManager.scene.spriteset.delete_sprite(sprite)
  496.   end
  497.   #-----------------------------------------------------------------------------
  498.   # * Overwrite method : Force move route
  499.   #-----------------------------------------------------------------------------
  500.   def force_move_route(move_route)
  501.     super
  502.     $game_map.forced_update_events << self
  503.     $game_map.forced_update_events.uniq!
  504.   end
  505.   #-----------------------------------------------------------------------------
  506.   # * Overwrite method : Restore move route
  507.   #-----------------------------------------------------------------------------
  508.   def restore_move_route
  509.     super
  510.     $game_map.forced_update_events.delete(self)
  511.   end
  512.   #-----------------------------------------------------------------------------
  513.   # * Overwrite method : Sprite
  514.   #-----------------------------------------------------------------------------
  515.   def sprite
  516.     $game_temp.event_sprites[@id]
  517.   end
  518.   #-----------------------------------------------------------------------------
  519.   # * Overwrite method : Sprite =
  520.   #-----------------------------------------------------------------------------
  521.   def sprite=(spr)
  522.     $game_temp.event_sprites[@id] = spr
  523.   end
  524.   
  525. end

  526. #===============================================================================
  527. # ** Sprite Character
  528. #===============================================================================

  529. class Sprite_Character
  530.   #-----------------------------------------------------------------------------
  531.   # * Alias method : Initialize
  532.   #-----------------------------------------------------------------------------
  533.   alias theo_antilag_init initialize
  534.   def initialize(viewport, character = nil)
  535.     character.sprite = self if character
  536.     theo_antilag_init(viewport, character)
  537.   end
  538.   #-----------------------------------------------------------------------------
  539.   # * Alias method : Update
  540.   #-----------------------------------------------------------------------------
  541.   alias theo_antilag_update update
  542.   def update
  543.     @sx = @character.screen_x
  544.     @sy = @character.screen_y
  545.     if Theo::AntiLag::Optimize_Sprite && !need_update?
  546.       self.visible = false
  547.       return
  548.     end  
  549.     theo_antilag_update
  550.   end
  551.   #-----------------------------------------------------------------------------
  552.   # * New method : Determine if on screen
  553.   #-----------------------------------------------------------------------------
  554.   def need_update?
  555.     return true if graphic_changed?
  556.     return true if @character.animation_id > 0
  557.     return true if @balloon_sprite
  558.     return true if @character.balloon_id != 0
  559.     w = Graphics.width
  560.     h = Graphics.height
  561.     cw = @cw || 32
  562.     ch = @ch || 32
  563.     @sx.between?(-cw,w+cw) && @sy.between?(0,h+ch)
  564.   end
  565.   #-----------------------------------------------------------------------------
  566.   # * Overwrite update position.
  567.   # To limit screen_x and screen_y to be called many times
  568.   #-----------------------------------------------------------------------------
  569.   def update_position
  570.     move_animation(@sx - x, @sy - y)
  571.     self.x = @sx
  572.     self.y = @sy
  573.     self.z = @character.screen_z
  574.   end
  575.   #-----------------------------------------------------------------------------
  576.   # * Overwrite animation origin
  577.   # Since X and Y axis of sprite is not updated when off screen
  578.   #-----------------------------------------------------------------------------
  579.   def set_animation_origin
  580.     if @animation.position == 3
  581.       if viewport == nil
  582.         @ani_ox = Graphics.width / 2
  583.         @ani_oy = Graphics.height / 2
  584.       else
  585.         @ani_ox = viewport.rect.width / 2
  586.         @ani_oy = viewport.rect.height / 2
  587.       end
  588.     else
  589.       @ani_ox = @sx - ox + width / 2
  590.       @ani_oy = @sy - oy + height / 2
  591.       if @animation.position == 0
  592.         @ani_oy -= height / 2
  593.       elsif @animation.position == 2
  594.         @ani_oy += height / 2
  595.       end
  596.     end
  597.   end
  598.   
  599. end

  600. #===============================================================================
  601. # ** Spriteset_Map
  602. #===============================================================================

  603. class Spriteset_Map
  604.   #-----------------------------------------------------------------------------
  605.   # * Alias method : create character
  606.   #-----------------------------------------------------------------------------
  607.   alias theo_antilag_create_characters create_characters
  608.   def create_characters
  609.     $game_map.event_redirect = Theo::AntiLag::Dispose_Sprite
  610.     theo_antilag_create_characters
  611.     $game_map.event_redirect = false
  612.   end
  613.   #-----------------------------------------------------------------------------
  614.   # * New method : delete sprite
  615.   #-----------------------------------------------------------------------------
  616.   def delete_sprite(spr)
  617.     return unless spr
  618.     return if spr.disposed?
  619.     @character_sprites.delete(spr)
  620.     spr.dispose
  621.   end
  622.   #-----------------------------------------------------------------------------
  623.   # * New method : add sprite
  624.   #-----------------------------------------------------------------------------
  625.   def add_sprite(char)
  626.     spr = Sprite_Character.new(@viewport1, char)
  627.     @character_sprites.push(spr)
  628.   end
  629.   
  630. end

  631. #===============================================================================
  632. # ** Scene_Base
  633. #===============================================================================

  634. class Scene_Base
  635.   attr_reader :spriteset
  636. end
复制代码



0cc61e80-fa9c-48c2-b93e-2f9531fd1c2c.png (8.19 KB, 下载次数: 2)

0cc61e80-fa9c-48c2-b93e-2f9531fd1c2c.png

最佳答案

查看完整内容

https://rpg.blue/thread-350955-1-1.html 把这个脚本插入到Theo的脚本之上

Lv5.捕梦者

梦石
0
星屑
25535
在线时间
5213 小时
注册时间
2016-3-8
帖子
1645
2
发表于 7 天前 | 只看该作者
https://rpg.blue/thread-350955-1-1.html
把这个脚本插入到Theo的脚本之上

评分

参与人数 1+1 收起 理由
宝开君 + 1 塞糖

查看全部评分

回复

使用道具 举报

Lv2.观梦者

梦石
0
星屑
847
在线时间
147 小时
注册时间
2019-9-17
帖子
19
3
 楼主| 发表于 7 天前 | 只看该作者
alexncf125 发表于 2025-3-24 16:41
https://rpg.blue/thread-350955-1-1.html
把这个脚本插入到Theo的脚本之上

新工程的确能跑了,但是本来的工程还是不行。。。估计是脚本冲突吧,总之谢谢大佬了。
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2025-3-31 16:46

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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