TheoAllen

Theo - Basic Modules

Jun 9th, 2013
809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 42.27 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Basic Modules
  3. # Version : 1.4
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (Some of documentations was written in informal indonesian language)
  6. # =============================================================================
  7. $imported = {} if $imported.nil?
  8. # =============================================================================
  9. # This module contains :
  10. # =============================================================================
  11. $imported[:Theo_BasicFuntions] = true  # Basic Funtions
  12. $imported[:Theo_BitmapAddons]  = true  # Bitmap Extra Addons
  13. $imported[:Theo_CoreDamage]    = true  # Core Damage Processing
  14. $imported[:Theo_CoreResult]    = true  # Core Damage Result
  15. $imported[:Theo_Movement]      = true  # Object Core Movement
  16. $imported[:Theo_CoreFade]      = true  # Object Core Fade
  17. $imported[:Theo_Circular]      = true  # Object Circular Movement
  18. $imported[:Theo_CloneImage]    = true  # Clone Image. For Afterimage Base
  19. $imported[:Theo_RotateImage]   = true  # To rotate sprite
  20. # =============================================================================
  21. # NOTE:
  22. # -----------------------------------------------------------------------------
  23. # Categorize this script as core script. It means that you have to put this
  24. # script above all custom script
  25. #
  26. # If u want to disable one of these, just replace "true" with "false"
  27. # =============================================================================
  28. # Known incompatibility :
  29. # >> Modern Algebra - Bitmap Addons (Disable the Bitmap Addon)
  30. # >> Tsukihime - Core Damage (Disable the Core Damage processing)
  31. # >> Enu - Tankentai
  32. # =============================================================================
  33. # ChangeLogs :
  34. # =============================================================================
  35. # Version 1.0   : - Initial Release
  36. # Version 1.2   : - Add Bitmap Entire Fill
  37. #                 - Add Bitmap Border Fill
  38. #                 - Add To Center window position
  39. #                 - Add more description
  40. # Version 1.3   : - Added Clone Sprite function and afterimagebase
  41. # Version 1.3b  : - Added TSBS basic function
  42. #                 - Greatly reduced lag for afterimage effect
  43. # Version 1.4   : - Added rotate image basic module
  44. #                 - Fixed bug at Object Core Fade
  45. # =============================================================================
  46. # RGSS3 ~ Bug Fixes (Taken from RMWeb.com)
  47. # forums.rpgmakerweb.com/index.php?/topic/1131-rgss3-unofficial-bugfix-snippets
  48. # =============================================================================
  49. # Screen shake bugfix
  50. # -----------------------------------------------------------------------------
  51. class Game_Interpreter
  52.  
  53.   def command_225
  54.     screen.start_shake(@params[0], @params[1], @params[2])
  55.     wait(@params[2]) if @params[3]
  56.   end
  57.  
  58. end
  59. # -----------------------------------------------------------------------------
  60. # Enemy targeting bugfix
  61. # -----------------------------------------------------------------------------
  62. class Game_Action
  63.   def targets_for_friends
  64.     if item.for_user?
  65.       [subject]
  66.     elsif item.for_dead_friend?
  67.       if item.for_one?
  68.         [friends_unit.smooth_dead_target(@target_index)]
  69.       else
  70.         friends_unit.dead_members
  71.       end
  72.     elsif item.for_friend?
  73.       if item.for_one?
  74.         if @target_index < 0
  75.           [friends_unit.random_target]
  76.         else
  77.           [friends_unit.smooth_target(@target_index)]
  78.         end
  79.       else
  80.         friends_unit.alive_members
  81.       end
  82.     end
  83.   end
  84. end
  85. # -----------------------------------------------------------------------------
  86. # process normal char bugfix
  87. # -----------------------------------------------------------------------------
  88. class Window_Base < Window
  89.   alias :process_normal_character_vxa :process_normal_character
  90.   def process_normal_character(c, pos)
  91.     return unless c >= ' '
  92.     process_normal_character_vxa(c, pos)
  93.   end
  94. end
  95. # -----------------------------------------------------------------------------
  96. # Disable Japanese input name
  97. # -----------------------------------------------------------------------------
  98. class Game_System
  99.   def japanese?
  100.     false
  101.   end
  102. end
  103. # =============================================================================
  104. # Basic Functions ~
  105. # -----------------------------------------------------------------------------
  106. if $imported[:Theo_BasicFuntions]
  107. # =============================================================================
  108. module Math
  109.  
  110.   # Konversi dari derajat ke radian
  111.   def self.radian(degree)
  112.     return (degree.to_f/180) * Math::PI
  113.   end
  114.  
  115.   # Konversi dari radian ke derajat
  116.   def self.degree(radian)
  117.     return (radian.to_f/Math::PI) * 180
  118.   end
  119.  
  120. end
  121.  
  122. class Object
  123.  
  124.   # Generate angka random dari jarak minimum - maksimum
  125.   unless method_defined?(:rand_range)
  126.     def rand_range(min,max,float = false)
  127.       range = max - min
  128.       return float ? (min + (rand*range)) : min + rand(range)
  129.     end
  130.   end
  131.  
  132.   # iterasi instance variable satu2
  133.   def each_var
  134.     instance_variables.each do |varsymb|
  135.       yield instance_variable_get(varsymb)
  136.     end
  137.   end
  138.  
  139. end
  140. # -----------------------------------------------------------------------------
  141. # Sprite yang gedenya selayar penuh (buat nggambar2)
  142. # -----------------------------------------------------------------------------
  143. class Sprite_Screen < Sprite
  144.  
  145.   def initialize(viewport = nil)
  146.     super(viewport)
  147.     self.bitmap = Bitmap.new(Graphics.width,Graphics.height)
  148.   end
  149.  
  150.   def dispose
  151.     self.bitmap.dispose
  152.     super
  153.   end
  154.  
  155. end
  156.  
  157. class Window_Confirmation < Window_Command
  158.   def window_width
  159.     return 100
  160.   end
  161.  
  162.   def make_command_list
  163.     add_command(ok_vocab, :ok, ok_condition)
  164.     add_command(cancel_vocab, :cancel, cancel_condition)
  165.   end
  166.  
  167.   def ok_vocab
  168.     return "Yes"
  169.   end
  170.  
  171.   def cancel_vocab
  172.     return "No"
  173.   end
  174.  
  175.   def ok_condition
  176.     return true
  177.   end
  178.  
  179.   def cancel_condition
  180.     return true
  181.   end
  182.  
  183.   def alignment
  184.     return 1
  185.   end
  186.  
  187. end
  188. # ----------------------------------------------------------------------------
  189. # Class Coordinate (nyimpen posisi x dan posisi y)
  190. # ----------------------------------------------------------------------------
  191. class Coordinate
  192.   attr_accessor :x,:y
  193.  
  194.   def initialize(x,y)
  195.     @x = x
  196.     @y = y
  197.   end
  198.  
  199.   def + (other)
  200.     other = other.to_c unless other.is_a?(Coordinate)
  201.     Coordinate.new(self.x + other.x, self.y + other.y)
  202.   end
  203.  
  204.   def - (other)
  205.     other = other.to_c unless other.is_a?(Coordinate)
  206.     Coordinate.new(self.x + other.x, self.y + other.y)
  207.   end
  208.  
  209.   def == (other)
  210.     other = other.to_c unless other.is_a?(Coordinate)
  211.     return self.x == other.x && self.y == other.y
  212.   end
  213.  
  214.   def to_s
  215.     return "(#{self.x},#{self.y})"
  216.   end
  217.  
  218. end
  219. # ----------------------------------------------------------------------------
  220. # Class vector (Handles vector object)
  221. # ----------------------------------------------------------------------------
  222. class Vector
  223.   attr_accessor :pangkal
  224.   attr_accessor :ujung
  225.  
  226.   def initialize(pangkal,ujung,radius = 0)
  227.     @pangkal = pangkal.is_a?(Coordinate) ? pangkal : pangkal.to_c
  228.     if ujung.is_a?(Numeric)
  229.       x_pos = @pangkal.x + (Math.cos(Math.radian(ujung)) * radius)
  230.       y_pos = @pangkal.y + (Math.sin(Math.radian(ujung)) * radius)
  231.       @ujung = Coordinate.new(x_pos,y_pos)
  232.       return
  233.     end
  234.     @ujung = ujung.is_a?(Coordinate) ? ujung : ujung.to_c
  235.   end
  236.  
  237.   def skalar
  238.     Math.sqrt(jarak_x**2 + jarak_y**2)
  239.   end
  240.  
  241.   def + (other)
  242.     if other.is_a?(Coordinate)
  243.       return Vector.new(pangkal + other, ujung + other)
  244.     end
  245.     Vector.new(pangkal, ujung + other.satuan)
  246.   end
  247.  
  248.   def - (other)
  249.     if other.is_a?(Coordinate)
  250.       return Vector.new(pangkal - other, ujung - other)
  251.     end
  252.     Vector.new(pangkal, ujung - other.satuan)
  253.   end
  254.  
  255.   def degree
  256.     Math.degree(Math.atan2(jarak_y,jarak_x)) rescue 0
  257.   end
  258.  
  259.   def jarak_y
  260.     ujung.y - pangkal.y
  261.   end
  262.  
  263.   def jarak_x
  264.     ujung.x - pangkal.x
  265.   end
  266.  
  267.   def satuan
  268.     Coordinate.new(jarak_x, jarak_y)
  269.   end
  270.  
  271.   def to_s
  272.     return @pangkal.to_s + " ---> " + @ujung.to_s
  273.   end
  274.  
  275. end
  276. # -----------------------------------------------------------------------------
  277. # Class Vector Object (untuk ngejadiin dua object jadi vector)
  278. # -----------------------------------------------------------------------------
  279. class VectorObject
  280.   attr_accessor :pangkal
  281.   attr_accessor :ujung
  282.   attr_accessor :color
  283.   attr_accessor :offset_x
  284.   attr_accessor :offset_y
  285.  
  286.   def initialize(pangkal,ujung,color)
  287.     @pangkal = pangkal
  288.     @ujung = ujung
  289.     @color = color
  290.     @offset_x = 0
  291.     @offset_y = 0
  292.   end
  293.  
  294.   def to_v
  295.     a = @pangkal.to_c
  296.     b = @ujung.to_c
  297.     a.x += @offset_x
  298.     b.x += @offset_x
  299.     a.y += @offset_y
  300.     b.y += @offset_y
  301.     Vector.new(a,b)
  302.   end
  303.  
  304. end
  305. # -----------------------------------------------------------------------------
  306. # Class Bitmap
  307. # -----------------------------------------------------------------------------
  308. class Bitmap
  309.  
  310.   def entire_fill(color = Color.new(0,0,0,150))
  311.     fill_rect(self.rect,color)
  312.   end
  313.  
  314.   def border_fill(color = Color.new(255,255,255))
  315.     fill_rect(0,0,width,1,color)
  316.     fill_rect(0,0,1,height,color)
  317.     fill_rect(width-1,0,1,height,color)
  318.     fill_rect(0,height-1,width,1,color)
  319.   end
  320.  
  321. end
  322. # -----------------------------------------------------------------------------
  323. # Class Window_Base
  324. # -----------------------------------------------------------------------------
  325. class Window_Base < Window
  326.  
  327.   def entire_fill(color = Color.new(0,0,0,150))
  328.     contents.entire_fill(color)
  329.   end
  330.  
  331.   def to_center
  332.     self.x = Graphics.width/2 - self.width/2
  333.     self.y = Graphics.height/2 - self.height/2
  334.   end
  335.  
  336. end
  337. # -----------------------------------------------------------------------------
  338. # Class Color
  339. # -----------------------------------------------------------------------------
  340. class Color
  341.  
  342.   def same?(*args)
  343.     args = args.select {|color| color.is_a?(Color)}
  344.     return false if args.empty?
  345.     return args.any?{|color| self.red == color.red &&
  346.       self.green == color.green && self.blue == color.blue &&
  347.       self.alpha == color.alpha}
  348.   end
  349.  
  350.   def empty?
  351.     return self.alpha <= 0
  352.   end
  353.  
  354. end
  355. # -----------------------------------------------------------------------------
  356. # New Method : To Coordinate Object
  357. # -----------------------------------------------------------------------------
  358. class Object
  359.  
  360.   def to_c
  361.     return Coordinate.new(0,0)
  362.   end
  363.  
  364. end
  365.  
  366. class Numeric
  367.  
  368.   def to_c
  369.     return Coordinate.new(self,self)
  370.   end
  371.  
  372. end
  373.  
  374. class Sprite
  375.  
  376.   def to_c
  377.     return Coordinate.new(self.x,self,y)
  378.   end
  379.  
  380. end
  381.  
  382. class Window
  383.  
  384.   def to_c
  385.     return Coordinate.new(self.x,self,y)
  386.   end
  387.  
  388. end
  389.  
  390. class Game_Enemy < Game_Battler
  391.  
  392.   def to_c
  393.     return Coordinate.new(self.screen_x,self,screen_y)
  394.   end
  395.  
  396. end
  397.  
  398. class Game_CharacterBase
  399.  
  400.   def to_c(map = false)
  401.     if map
  402.       return Coordinate.new(self.real_x,self.real_y)
  403.     end
  404.     return Coordinate.new(self.screen_x,self.screen_y)
  405.   end
  406.  
  407. end
  408. # -----------------------------------------------------------------------------
  409. # Added TSBS basic function
  410. # -----------------------------------------------------------------------------
  411. module TSBS
  412.   def self.cell(row, col)
  413.     result = (MaxCol * (row - 1)) + (col - 1)
  414.     return result
  415.   end
  416. end
  417. end
  418. # =============================================================================
  419. # Bitmap Extra addons v2.1
  420. # -----------------------------------------------------------------------------
  421. if $imported[:Theo_BitmapAddons]
  422. # =============================================================================
  423. class Bitmap
  424.   attr_accessor :start_degree
  425.  
  426.   # ------------------------------------------------------------------------
  427.   # Static Members
  428.   # ------------------------------------------------------------------------
  429.   @@default_color = Color.new(255,255,255)
  430.   @@arrow_degree = 30
  431.  
  432.   def self.default_color=(color)
  433.     @@default_color = color
  434.   end
  435.  
  436.   def self.arrow_degree=(degree)
  437.     @@arrow_degree = degree
  438.   end
  439.  
  440.   def self.default_color
  441.     @@default_color
  442.   end
  443.  
  444.   def self.arrow_degree
  445.     @@arrow_degree
  446.   end
  447.  
  448.   alias theo_bitmap_init initialize
  449.   def initialize(*args)
  450.     theo_bitmap_init(*args)
  451.     @start_degree = 270
  452.   end
  453.   # ------------------------------------------------------------------------
  454.   # Bitmap draw line
  455.   # ------------------------------------------------------------------------
  456.   def draw_line(x1, y1=0, x2=0, y2=0, color=@@default_color.dup,
  457.       color_set_skip = false)
  458.     # ----------------------------------------------------------------------
  459.     # Jika yang dimasukkan adalah class Vector
  460.     # ----------------------------------------------------------------------
  461.     if x1.is_a?(Vector)
  462.       new_color = (y1.is_a?(Color) ? y1 : color)
  463.       draw_line(x1.pangkal,x1.ujung,new_color) # rekursif
  464.       return
  465.     # ----------------------------------------------------------------------
  466.     # Jika yang dimasukkan adalah dua koordinat
  467.     # ----------------------------------------------------------------------
  468.     elsif x1.is_a?(Coordinate) && y1.is_a?(Coordinate)
  469.       pangkal = x1
  470.       ujung = y1
  471.       new_color = (x2.is_a?(Color) ? x2 : color)
  472.       draw_line(pangkal.x,pangkal.y,ujung.x,ujung.y,new_color) # rekursif
  473.       return # Exit
  474.     end
  475.     # ----------------------------------------------------------------------
  476.     # Jika yang dimasukkan adalah koordinat yang sama
  477.     # ----------------------------------------------------------------------
  478.     if x1 == x2 && y1 == y2
  479.       set_pixel(x1,y1,color)
  480.       yield [x1,x2] if block_given?
  481.       return # Exit
  482.     end
  483.     # ----------------------------------------------------------------------
  484.     # kalkulasi jarak x dan jarak y
  485.     # ----------------------------------------------------------------------
  486.     jarak_x = (x2-x1)
  487.     jarak_y = (y2-y1)
  488.     # ----------------------------------------------------------------------
  489.     # Jika garis merupakan garis horizontal / vertikal
  490.     # ----------------------------------------------------------------------
  491.     if jarak_y == 0 || jarak_x == 0
  492.      
  493.       # Horizontal
  494.       if jarak_y == 0
  495.         draw_horz(x1,y1,jarak_x,color)
  496.         for j in 0..jarak_x
  497.           yield [x1,y1]
  498.           x1 += 1
  499.         end if block_given?
  500.        
  501.       # Vertikal
  502.       elsif jarak_x == 0
  503.         draw_vert(x1,y1,jarak_y,color)
  504.         for k in 0..jarak_y
  505.           yield [x1,y1]
  506.           y1 += 1
  507.         end if block_given?
  508.       end
  509.       return # Exit
  510.      
  511.     end
  512.     # ----------------------------------------------------------------------
  513.     # Jika garis adalah diagonal
  514.     # ----------------------------------------------------------------------
  515.     maximum = [jarak_x.abs,jarak_y.abs].max
  516.     rasio_x = jarak_x / maximum.to_f
  517.     rasio_y = jarak_y / maximum.to_f
  518.     real_x = x1.to_f
  519.     real_y = y1.to_f
  520.     for i in 0..maximum
  521.       set_pixel(x1,y1,color) unless get_pixel(x1,y1).same?(color) ||
  522.         color_set_skip ? !get_pixel(x1,y1).empty? : false
  523.       real_x += rasio_x
  524.       real_y += rasio_y
  525.       yield [x1,y1] if block_given?
  526.       x1 = real_x.round
  527.       y1 = real_y.round
  528.     end
  529.   end
  530.  
  531.   # ------------------------------------------------------------------------
  532.   # Garis Gradient ~
  533.   # ------------------------------------------------------------------------
  534.   def gradient_line(x1,y1=0,x2=0,y2=0,color1=@@default_color.dup,color2 = color1)
  535.     if x1.is_a?(Vector)
  536.       warna_pangkal = (y1.is_a?(Color) ? y1 : color1)
  537.       warna_ujung = (x2.is_a?(Color) ? x2 : color2)
  538.       gradient_line(x1.pangkal, x1.ujung, warna_pangkal, warna_ujung)
  539.       return
  540.     elsif x1.is_a?(Coordinate) && y1.is_a?(Coordinate)
  541.       pangkal = x1
  542.       ujung = y1
  543.       warna_pangkal = (x2.is_a?(Color) ? x2 : color1)
  544.       warna_ujung = (y2.is_a?(Color) ? y2 : color2)
  545.       gradient_line(pangkal.x,pangkal.y,ujung.x,ujung.y,warna_pangkal,
  546.         warna_ujung)
  547.       return
  548.     end
  549.     jarak_x = (x2-x1)
  550.     jarak_y = (y2-y1)
  551.     radius = Math.sqrt((jarak_x**2) + (jarak_y**2))
  552.     red_diff = (color2.red - color1.red) / radius
  553.     green_diff = (color2.green - color1.green) / radius
  554.     blue_diff = (color2.blue - color1.blue) / radius
  555.     alpha_diff = (color2.alpha - color1.alpha) / radius
  556.     red = color1.red
  557.     green = color1.green
  558.     blue = color1.blue
  559.     alpha = color1.alpha
  560.     if jarak_y.abs == 0 || jarak_x.abs == 0
  561.       gradient_fill_rect(x1,y1,1,jarak_y,color1,color2,true) if jarak_y.abs == 0
  562.       gradient_fill_rect(x1,y1,jarak_x,1,color1,color2) if jarak_x.abs == 0
  563.       return
  564.     end
  565.     maximum = [jarak_x.abs,jarak_y.abs].max
  566.     rasio_x = jarak_x / maximum.to_f
  567.     rasio_y = jarak_y / maximum.to_f
  568.     real_x = x1.to_f
  569.     real_y = y1.to_f
  570.     for i in 0..maximum
  571.       new_color = Color.new(red,green,blue,alpha)
  572.       set_pixel(x1,y1,new_color) unless get_pixel(x1,y1).same?(new_color)
  573.       real_x += rasio_x
  574.       real_y += rasio_y
  575.       x1 = real_x.round
  576.       y1 = real_y.round
  577.       red += red_diff
  578.       blue += blue_diff
  579.       green += green_diff
  580.       alpha += alpha_diff
  581.     end
  582.   end
  583.  
  584.   def draw_horz(x,y,width,color = Color.new(255,255,255))
  585.     if width < 0
  586.       fill_rect(x+width+1,y,width.abs,1,color)
  587.       return
  588.     end
  589.     fill_rect(x,y,width,1,color)
  590.   end
  591.  
  592.   def draw_vert(x,y,height,color = Color.new(255,255,255))
  593.     if height < 0
  594.       fill_rect(x,y+height+1,1,height.abs,color)
  595.       return
  596.     end
  597.     fill_rect(x,y,1,height,color)
  598.   end
  599.  
  600.   def draw_ellipse(x,y=0,horz=1,vert=1,color=Color.new(255,255,255),think=1,
  601.       step=0.1)
  602.     return if think < 1
  603.     ori_x = x
  604.     ori_y = y
  605.     x += horz
  606.     degree = 0.0
  607.     while degree <= 360
  608.       yield [x,y] if block_given?
  609.       set_pixel(x,y,color) unless get_pixel(x,y).same?(color)
  610.       x = Math.cos(Math.radian(degree)) * horz + ori_x
  611.       y = Math.sin(Math.radian(degree)) * vert + ori_y
  612.       degree = [degree+step,361].min
  613.     end
  614.     if think > 1
  615.       draw_ellipse(ori_x+1,ori_y+1,horz,vert,think-1,color,step)
  616.       draw_ellipse(ori_x-1,ori_y-1,horz,vert,think-1,color,step)
  617.       draw_ellipse(ori_x+1,ori_y-1,horz,vert,think-1,color,step)
  618.       draw_ellipse(ori_x-1,ori_y+1,horz,vert,think-1,color,step)
  619.     end
  620.   end
  621.  
  622.   def draw_circle(x,y,radius,color=Color.new(255,255,255),think=1)
  623.     draw_ellipse(x,y,radius,radius,think,color) {|coordinate|
  624.       yield coordinate if block_given?
  625.     }
  626.   end
  627.  
  628.   def fill_circle(x,y,radius,color1,color2=color1,step=0.1)
  629.     fill_ellipse(x,y,radius,radius,color1,color2,step)
  630.   end
  631.  
  632.   def fill_ellipse(x,y,horz,vert,color1,color2=color1,step=0.1)
  633.     draw_ellipse(x,y,horz,vert,1,color1,0.5) {|cor|
  634.       draw_line(x,y,cor[0],cor[1],color2,true)
  635.     }
  636.     for i in 0..1
  637.       for baris in 0..horz*2
  638.         for kolom in 0..vert*2
  639.           pos_x = baris-horz+x
  640.           pos_y = kolom-vert+y
  641.           syarat = (get_pixel(pos_x+1,pos_y).same?(color1,color2) &&
  642.           get_pixel(pos_x-1,pos_y).same?(color1,color2)) ||
  643.           (get_pixel(pos_x,pos_y-1).same?(color1,color2) &&
  644.           get_pixel(pos_x,pos_y+1).same?(color1,color2)) ||
  645.           (get_pixel(pos_x+1,pos_y+1).same?(color1,color2) &&
  646.           get_pixel(pos_x-1,pos_y-1).same?(color1,color2)) ||
  647.           (get_pixel(pos_x-1,pos_y+1).same?(color1,color2) &&
  648.           get_pixel(pos_x+1,pos_y-1).same?(color1,color2))
  649.           if syarat && !get_pixel(pos_x,pos_y).same?(color1,color2)
  650.             set_pixel(pos_x,pos_y,color2)
  651.           end
  652.         end
  653.       end
  654.     end
  655.   end
  656.  
  657.   def draw_polygon(x,y,corner,length,color1,bone=true,color2=color1)
  658.     return unless corner.is_a?(Numeric)
  659.     draw_shape(x,y,Array.new(corner){1},length,color1,bone,false,color2)
  660.   end
  661.  
  662.   def fill_polygon(x,y,corner,length,color1,color2=color1)
  663.     return unless corner.is_a?(Numeric)
  664.     draw_shape(x,y,Array.new(corner),length,color1,false,true,color2)
  665.   end
  666.  
  667.   def draw_shape_params(x,y,params,length,color1,bone=true,color2=color1)
  668.     draw_shape(x,y,params,length,color1,bone,false,color2)
  669.   end
  670.  
  671.   def fill_shape_params(x,y,params,length,color1,color2=color1)
  672.     draw_shape(x,y,params,length,color1,false,true,color2)
  673.   end
  674.  
  675.   def draw_shape(x,y,params,length,color1 = Color.new(255,255,255),
  676.       include_bone = true ,fill=false,color2 = color1)
  677.     return unless params.is_a?(Array)
  678.     return unless params.size >= 3
  679.     degree_plus = 360 / params.size
  680.     degree = @start_degree
  681.     coordinate = []
  682.     edge = []
  683.     params.each do |i|
  684.       x_des = x + Math.cos(Math.radian(degree)) * (length*(i.to_f/params.max))
  685.       y_des = y + Math.sin(Math.radian(degree)) * (length*(i.to_f/params.max))
  686.       draw_line(x,y,x_des,y_des,color2) if include_bone
  687.       degree += degree_plus
  688.       coordinate.push(Coordinate.new(x_des,y_des))
  689.     end
  690.     for i in -1..coordinate.size-2
  691.       c = coordinate
  692.       draw_line(c[i].x,c[i].y,c[i+1].x,c[i+1].y,color1) {|cor| edge.push(cor)}
  693.     end
  694.     return unless fill
  695.     edge.each do |line|
  696.       draw_line(x,y,line[0],line[1],color2,true)
  697.     end
  698.     for i in 0..1
  699.       for baris in 0..length*2
  700.         for kolom in 0..length*2
  701.           pos_x = baris-length+x
  702.           pos_y = kolom-length+y
  703.           syarat = (get_pixel(pos_x+1,pos_y).same?(color1,color2) &&
  704.           get_pixel(pos_x-1,pos_y).same?(color1,color2)) ||
  705.           (get_pixel(pos_x,pos_y-1).same?(color1,color2) &&
  706.           get_pixel(pos_x,pos_y+1).same?(color1,color2)) ||
  707.           (get_pixel(pos_x+1,pos_y+1).same?(color1,color2) &&
  708.           get_pixel(pos_x-1,pos_y-1).same?(color1,color2)) ||
  709.           (get_pixel(pos_x-1,pos_y+1).same?(color1,color2) &&
  710.           get_pixel(pos_x+1,pos_y-1).same?(color1,color2))
  711.           if syarat && !get_pixel(pos_x,pos_y).same?(color1,color2)
  712.             set_pixel(pos_x,pos_y,color2)
  713.           end
  714.         end
  715.       end
  716.     end
  717.   end
  718.  
  719.   def draw_arrow(x1,y1=0,x2=0,y2=0,color=@@default_color.dup)
  720.     if x1.is_a?(Vector)
  721.       new_color = (y1.is_a?(Color) ? y1 : color)
  722.       draw_arrow(x1.pangkal,x1.ujung,new_color)
  723.       return
  724.     elsif x1.is_a?(Coordinate) && y1.is_a?(Coordinate)
  725.       pangkal = x1
  726.       ujung = y1
  727.       new_color = (x2.is_a?(Color) ? x2 : color)
  728.       draw_arrow(pangkal.x,pangkal.y,ujung.x,ujung.y,new_color)
  729.       return
  730.     end
  731.     draw_line(x1,y1,x2,y2,color)
  732.     degree = Vector.new(Coordinate.new(x1,y1),Coordinate.new(x2,y2)).degree-180
  733.     draw_line(Vector.new(Coordinate.new(x2,y2),degree + @@arrow_degree,10))
  734.     draw_line(Vector.new(Coordinate.new(x2,y2),degree - @@arrow_degree,10))
  735.   end
  736.  
  737. end
  738. # -----------------------------------------------------------------------------
  739. # Draw Polygon status
  740. # -----------------------------------------------------------------------------
  741. class Game_Battler < Game_BattlerBase
  742.  
  743.   def params_array
  744.     return [self.atk,self.def,self.mat,self.mdf,self.agi,self.luk]
  745.   end
  746.  
  747. end
  748.  
  749. class Window_Base < Window
  750.  
  751.   def draw_polygon_params(x,y,actor,inner,outer,color1,color2)
  752.     contents.draw_shape_params(x,y,actor.params_array,inner,color1)
  753.     contents.draw_polygon(x,y,actor.params_array.size,outer,color2)
  754.   end
  755.  
  756. end
  757. end
  758. # ============================================================================
  759. # Core Damage Processing ~
  760. # ----------------------------------------------------------------------------
  761. if $imported[:Theo_CoreDamage]
  762. # ============================================================================
  763. class Game_Battler < Game_BattlerBase
  764.  
  765.   def make_damage_value(user, item)
  766.     value = base_damage(user, item)
  767.     value = apply_element_rate(user, item, value)
  768.     value = process_damage_rate(user, item, value)
  769.     value = apply_damage_modifiers(user, item, value)
  770.     @result.make_damage(value.to_i, item)
  771.   end
  772.  
  773.   def base_damage(user, item)
  774.     value = item.damage.eval(user, self, $game_variables)
  775.     value
  776.   end
  777.  
  778.   def apply_element_rate(user, item, value)
  779.     value *= item_element_rate(user, item)
  780.     value
  781.   end
  782.  
  783.   def process_damage_rate(user, item, value)
  784.     value *= pdr if item.physical?
  785.     value *= mdr if item.magical?
  786.     value *= rec if item.damage.recover?
  787.     value
  788.   end
  789.  
  790.   def apply_damage_modifiers(user, item, value)
  791.     value = apply_critical(value, user) if @result.critical
  792.     value = apply_variance(value, item.damage.variance)
  793.     value = apply_guard(value)
  794.     value
  795.   end
  796.  
  797.   def apply_critical(damage, user)
  798.     damage * 3
  799.   end
  800.  
  801. end
  802. end
  803. # ============================================================================
  804. # Core Damage Result ~
  805. # ----------------------------------------------------------------------------
  806. if $imported[:Theo_CoreResult]
  807. # ============================================================================
  808. class Game_Battler < Game_BattlerBase
  809.  
  810.   def item_apply(user, item)
  811.     make_base_result(user, item)
  812.     apply_hit(user, item) if @result.hit?
  813.   end
  814.  
  815.   def make_base_result(user, item)
  816.     @result.clear
  817.     @result.used = item_test(user, item)
  818.     @result.missed = (@result.used && rand >= item_hit(user, item))
  819.     @result.evaded = (!@result.missed && rand < item_eva(user, item))
  820.   end
  821.  
  822.   def apply_hit(user, item)  
  823.     unless item.damage.none?
  824.       determine_critical(user, item)
  825.       make_damage_value(user, item)
  826.       execute_damage(user)
  827.     end
  828.     apply_item_effects(user, item)
  829.   end
  830.  
  831.   def determine_critical(user, item)
  832.     @result.critical = (rand < item_cri(user, item))
  833.   end
  834.  
  835.   def apply_item_effects(user, item)
  836.     item.effects.each {|effect| item_effect_apply(user, item, effect) }
  837.     item_user_effect(user, item)
  838.   end
  839.  
  840. end
  841. end
  842. # ============================================================================
  843. # Object Core Movement
  844. # ----------------------------------------------------------------------------
  845. if $imported[:Theo_Movement]
  846. # ============================================================================
  847. module THEO
  848.   module Movement
  849.     class Move_Object
  850.       attr_reader :obj
  851.      
  852.       def initialize(obj)
  853.         @obj = obj
  854.         clear_move_info
  855.       end
  856.      
  857.       def clear_move_info
  858.         @to_x = -1
  859.         @to_y = -1
  860.         @real_x = 0.0
  861.         @real_y = 0.0
  862.         @x_speed = 0.0
  863.         @y_speed = 0.0
  864.         @jump = 0.0
  865.         @jump_interval = 0.0
  866.         @offset = 0
  867.       end
  868.      
  869.       def move_to(x,y=0,jump=0,duration=0)
  870.         if x.is_a?(Coordinate)
  871.           target = x
  872.           move_to(target.x, target.y, y, jump)
  873.           return
  874.         end
  875.         @to_x = x
  876.         @to_y = y
  877.         @real_x = @obj.x.to_f
  878.         @real_y = @obj.y.to_f
  879.         determine_speed(duration,jump)
  880.       end
  881.      
  882.       def determine_speed(duration,jump)
  883.         @x_speed = (@to_x - @obj.x) / duration.to_f
  884.         @y_speed = (@to_y - @obj.y) / duration.to_f
  885.         @jump = jump.to_f
  886.         @jump_interval = @jump/(duration/2.0)
  887.       end
  888.      
  889.       def moving?
  890.         return false if @to_x == -1 && @to_y == -1
  891.         result = @obj.x != @to_x || @obj.y != @to_y
  892.         return result
  893.       end
  894.      
  895.       def update_move
  896.         @real_x += @x_speed
  897.         @real_y += @y_speed
  898.         @obj.x = @real_x.round
  899.         @obj.y = @real_y.round + @offset.round
  900.         @jump -= @jump_interval
  901.         @offset -= @jump
  902.         clear_move_info unless moving?
  903.       end
  904.      
  905.     end
  906.    
  907.     def can_move?(obj)
  908.       return obj.is_a?(Window) || obj.is_a?(Sprite)
  909.     end
  910.    
  911.     def set_obj(obj)
  912.       @move_obj = Move_Object.new(obj)
  913.     end
  914.    
  915.     def goto(x,y,duration = Graphics.frame_rate,jump = 0.0)
  916.       @move_obj.move_to(x,y,jump,duration)
  917.     end
  918.    
  919.     def slide(x,y,duration = Graphics.frame_rate,jump = 0.0)
  920.       slide_x = 0
  921.       slide_y = 0
  922.       if x.is_a?(Coordinate)
  923.         target  = x
  924.         slide_x = @move_obj.obj.x + target.x
  925.         slide_y = @move_obj.obj.y + target.y
  926.       else
  927.         slide_x = @move_obj.obj.x + x
  928.         slide_y = @move_obj.obj.y + y
  929.       end
  930.       goto(slide_x,slide_y,duration,jump) unless moving?
  931.     end
  932.    
  933.     def update_move
  934.       @move_obj.update_move if moving?
  935.     end
  936.    
  937.     def moving?
  938.       @move_obj.moving?
  939.     end
  940.    
  941.     def up(range,duration = Graphics.frame_rate,jump = 0.0)
  942.       slide(0,-range,duration,jump)
  943.     end
  944.    
  945.     def down(range,duration = Graphics.frame_rate,jump = 0.0)
  946.       slide(0,range,duration,jump)
  947.     end
  948.    
  949.     def right(range,duration = Graphics.frame_rate,jump = 0.0)
  950.       slide(range,0,duration,jump)
  951.     end
  952.    
  953.     def left(range,duration = Graphics.frame_rate,jump = 0.0)
  954.       slide(-range,0,duration,jump)
  955.     end
  956.    
  957.     def upright(range,duration = Graphics.frame_rate,jump = 0.0)
  958.       slide(range,-range,duration,jump)
  959.     end
  960.    
  961.     def upleft(range,duration = Graphics.frame_rate,jump = 0.0)
  962.       slide(-range,-range,duration,jump)
  963.     end
  964.    
  965.     def downright(range,duration = Graphics.frame_rate,jump = 0.0)
  966.       slide(range,-range,duration,jump)
  967.     end
  968.    
  969.     def downleft(range,duration = Graphics.frame_rate,jump = 0.0)
  970.       slide(-range,range,duration,jump)
  971.     end
  972.    
  973.   end
  974. end
  975.  
  976. class Sprite
  977.   include THEO::Movement
  978.  
  979.   alias theolized_sprite_init initialize
  980.   def initialize(*args)
  981.     theolized_sprite_init(*args)
  982.     set_obj(self)
  983.   end
  984.  
  985.   alias theolized_move_update update
  986.   def update
  987.     theolized_move_update
  988.     update_move
  989.   end
  990.  
  991. end
  992.  
  993. class Window
  994.   include THEO::Movement
  995.  
  996.   alias theolized_move_window_init initialize
  997.   def initialize(x, y, width, height)
  998.     theolized_move_window_init(x, y, width, height)
  999.     set_obj(self)
  1000.   end
  1001.  
  1002.   alias theolized_move_update update
  1003.   def update
  1004.     theolized_move_update
  1005.     update_move
  1006.   end
  1007.  
  1008. end
  1009. end
  1010. # =============================================================================
  1011. # Object Core Fade
  1012. # -----------------------------------------------------------------------------
  1013. if $imported[:Theo_CoreFade]
  1014. # =============================================================================
  1015. module THEO
  1016.   module FADE
  1017.    
  1018.     DEFAULT_DURATION = 60
  1019.     # set default durationnya disini (dalam satuan frame)
  1020.    
  1021.     def init_fade_members
  1022.       @obj = nil
  1023.       @target_opacity = -1
  1024.       @target_contents_opacity = -1
  1025.       @fade_speed = 0.0
  1026.       @fade_speed2 = 0.0
  1027.     end
  1028.    
  1029.     def setfade_obj(obj)
  1030.       @obj = obj
  1031.       @target_opacity = (window? ? @obj.back_opacity : @obj.opacity)
  1032.       @target_contents_opacity = @obj.contents_opacity if window?
  1033.     end
  1034.    
  1035.     def fade(opacity, duration = DEFAULT_DURATION)
  1036.       @target_opacity = opacity
  1037.       @target_contents_opacity = opacity if @obj.is_a?(Window)
  1038.       make_fade_speed(duration)
  1039.     end
  1040.    
  1041.     def contents_fade(opacity, duration = DEFAULT_DURATION)
  1042.       return unless window?
  1043.       @target_contents_opacity = opacity
  1044.       make_fade_speed(duration)
  1045.     end
  1046.    
  1047.     def back_fade(opacity, duration = DEFAULT_DURATION)
  1048.       return unless window?
  1049.       @target_opacity = opacity
  1050.       make_fade_speed(duration)
  1051.     end
  1052.    
  1053.     def make_fade_speed(duration)
  1054.       @fade_speed = (@target_opacity - (window? ? @obj.back_opacity :
  1055.         @obj.opacity))/duration.to_f
  1056.       @fade_speed2 = (@target_contents_opacity - @obj.contents_opacity) /
  1057.       duration.to_f if window?
  1058.     end
  1059.    
  1060.     def window?
  1061.       @obj.is_a?(Window)
  1062.     end
  1063.    
  1064.     def fadeout(duration = DEFAULT_DURATION)
  1065.       fade(0, duration)
  1066.     end
  1067.    
  1068.     def fadein(duration = DEFAULT_DURATION)
  1069.       fade(255, duration)
  1070.     end
  1071.    
  1072.     def update_fade
  1073.       return unless fade?
  1074.       @obj.opacity += @fade_speed
  1075.       @obj.contents_opacity += @fade_speed2 if window?
  1076.       @target_opacity = -1 unless fade?
  1077.     end
  1078.    
  1079.     def fade?
  1080.       return false if @target_opacity == -1
  1081.       if window?
  1082.         (@target_opacity != @obj.opacity) &&
  1083.         (@target_contents_opacity != @obj.contents_opacity)
  1084.       else
  1085.         @target_opacity != @obj.opacity
  1086.       end
  1087.     end
  1088.    
  1089.   end
  1090. end
  1091.  
  1092. class Window
  1093.  
  1094.   include THEO::FADE
  1095.  
  1096.   alias pre_fade_init initialize
  1097.   def initialize(*args)
  1098.     pre_fade_init(*args)
  1099.     init_fade_members
  1100.     setfade_obj(self)
  1101.   end
  1102.  
  1103.   alias pre_fade_update update
  1104.   def update
  1105.     pre_fade_update
  1106.     update_fade
  1107.   end
  1108.  
  1109. end
  1110.  
  1111. class Sprite
  1112.  
  1113.   include THEO::FADE
  1114.  
  1115.   alias pre_fade_init initialize
  1116.   def initialize(*args)
  1117.     pre_fade_init(*args)
  1118.     init_fade_members
  1119.     setfade_obj(self)
  1120.   end
  1121.  
  1122.   alias pre_fade_update update
  1123.   def update
  1124.     pre_fade_update
  1125.     update_fade
  1126.   end
  1127.  
  1128. end
  1129. end
  1130. # =============================================================================
  1131. # Object Circular Movement
  1132. # -----------------------------------------------------------------------------
  1133. if $imported[:Theo_Circular]
  1134. # =============================================================================
  1135. module THEO
  1136.   module Circular
  1137.     class Circular_Obj
  1138.       attr_reader :ox
  1139.       attr_reader :oy
  1140.       attr_reader :center_obj
  1141.       attr_reader :obj
  1142.      
  1143.       def initialize(obj,ox,oy,center_obj)
  1144.         @obj = obj
  1145.         @center_obj = center_obj if can_move?(center_obj)
  1146.         @ox = ox
  1147.         @oy = oy
  1148.         @speed = 0
  1149.         @endless = false
  1150.         @freeze = false
  1151.         refresh_info
  1152.       end
  1153.      
  1154.       def refresh_info
  1155.         @radius = radius
  1156.         @degree_dest = @current_degree = get_degree
  1157.       end
  1158.      
  1159.       def center_obj=(center)
  1160.         return unless can_move?(center)
  1161.         @center_obj = center
  1162.         refresh_info
  1163.       end
  1164.      
  1165.       def ox=(ox)
  1166.         @ox = ox
  1167.         refresh_info
  1168.       end
  1169.      
  1170.       def oy=(oy)
  1171.         @oy = oy
  1172.         refresh_info
  1173.       end
  1174.      
  1175.       def can_move?(obj)
  1176.         obj.is_a?(Window) || obj.is_a?(Sprite)
  1177.       end
  1178.      
  1179.       def circle_move(degree,duration)
  1180.         return if endless?
  1181.         @degree_dest = (@current_degree + degree)
  1182.         @speed = (@degree_dest - @current_degree) / duration.to_f
  1183.       end
  1184.      
  1185.       def endless_circle(speed)
  1186.         @speed = speed
  1187.         @endless = true
  1188.       end
  1189.      
  1190.       def get_degree
  1191.         Math.degree(Math.atan2(range_y,range_x)) rescue 0
  1192.       end
  1193.      
  1194.       def range_x
  1195.         @obj.x - center_x
  1196.       end
  1197.      
  1198.       def range_y
  1199.         @obj.y - center_y
  1200.       end
  1201.      
  1202.       def center_x
  1203.         @center_obj.nil? ? @ox : @center_obj.x
  1204.       end
  1205.      
  1206.       def center_y
  1207.         @center_obj.nil? ? @oy : @center_obj.y
  1208.       end
  1209.      
  1210.       def radius
  1211.         Math.sqrt((range_x**2) + (range_y**2))
  1212.       end
  1213.      
  1214.       def update_circle
  1215.         return if circle_frozen?
  1216.         return unless rotate? || @endless
  1217.         @current_degree += @speed
  1218.         update_x
  1219.         update_y
  1220.         @degree_dest = @current_degree if @endless
  1221.       end
  1222.      
  1223.       def rotate?
  1224.         return @current_degree != @degree_dest
  1225.       end
  1226.      
  1227.       def update_x
  1228.         @obj.x = center_x + (@radius * Math.cos(Math.radian(@current_degree))).round
  1229.       end
  1230.      
  1231.       def update_y
  1232.         @obj.y = center_y + (@radius * Math.sin(Math.radian(@current_degree))).round
  1233.       end
  1234.      
  1235.       def circle_freeze
  1236.         @freeze = true
  1237.       end
  1238.      
  1239.       def circle_unfreeze
  1240.         @freeze = false
  1241.       end
  1242.      
  1243.       def circle_frozen?
  1244.         @freeze
  1245.       end
  1246.      
  1247.       def stop
  1248.         @endless = false
  1249.       end
  1250.      
  1251.       def continue
  1252.         @endless = true
  1253.       end
  1254.      
  1255.       def endless?
  1256.         @endless
  1257.       end
  1258.      
  1259.     end
  1260.    
  1261.     def set_circle(obj,ox = 0,oy = 0,center_obj = nil)
  1262.       @circle = Circular_Obj.new(obj,ox,oy,center_obj)
  1263.     end
  1264.    
  1265.     def stop
  1266.       @circle.stop
  1267.     end
  1268.    
  1269.     def continue
  1270.       @circle.continue
  1271.     end
  1272.    
  1273.     def endless?
  1274.       @circle.endless?
  1275.     end
  1276.    
  1277.     def circle_move(degree, dur = Graphics.frame_rate)
  1278.       @circle.circle_move(degree,dur)
  1279.     end
  1280.    
  1281.     def endless_circle(speed)
  1282.       @circle.endless_circle(speed)
  1283.     end
  1284.    
  1285.     def circle_freeze
  1286.       @circle.circle_freeze
  1287.     end
  1288.    
  1289.     def circle_unfreeze
  1290.       @circle.circle_unfreeze
  1291.     end
  1292.    
  1293.     def circle_frozed?
  1294.       @circle.circle_frozen?
  1295.     end
  1296.    
  1297.     def update_circle
  1298.       @circle.update_circle
  1299.     end
  1300.    
  1301.     def rotating?
  1302.       @circle.rotate?
  1303.     end
  1304.    
  1305.     def center_coordinate(ox,oy)
  1306.       @circle.ox = ox
  1307.       @circle.oy = oy
  1308.     end
  1309.    
  1310.     def center_distance(ox,oy)
  1311.       @circle.ox = @circle.obj.x + ox
  1312.       @circle.oy = @circle.obj.y + oy
  1313.     end
  1314.    
  1315.     def center_obj(obj)
  1316.       @circle.center_obj = obj
  1317.     end
  1318.    
  1319.     def refresh_info
  1320.       @circle.refresh_info
  1321.     end
  1322.    
  1323.   end
  1324. end
  1325.  
  1326. class Window
  1327.  
  1328.   include THEO::Circular
  1329.  
  1330.   alias theolized_circle_window_init initialize
  1331.   def initialize(*args)
  1332.     theolized_circle_window_init(*args)
  1333.     set_circle(self,x,y)
  1334.   end
  1335.  
  1336.   alias window_circle_update update
  1337.   def update
  1338.     window_circle_update
  1339.     update_circle
  1340.   end
  1341.  
  1342. end
  1343.  
  1344. class Sprite
  1345.  
  1346.   include THEO::Circular
  1347.  
  1348.   alias theolized_circle_init initialize
  1349.   def initialize(*args)
  1350.     theolized_circle_init(*args)
  1351.     set_circle(self,x,y)
  1352.   end
  1353.  
  1354.   alias sprite_circle_update update
  1355.   def update
  1356.     sprite_circle_update
  1357.     update_circle
  1358.   end
  1359.  
  1360. end
  1361. end
  1362. # =============================================================================
  1363. # Afterimage Base
  1364. # -----------------------------------------------------------------------------
  1365. if $imported[:Theo_CloneImage]
  1366. # =============================================================================
  1367. #~ class Bitmap
  1368. #~   attr_reader :filename
  1369. #~  
  1370. #~   alias theo_filename_init initialize
  1371. #~   def initialize(*args)
  1372. #~     @filename = ""
  1373. #~     if args[0].is_a?(String)
  1374. #~       @filename = args[0].dup.freeze
  1375. #~     end
  1376. #~     theo_filename_init(*args)
  1377. #~   end
  1378. #~  
  1379. #~ end
  1380.  
  1381. class Sprite
  1382.   attr_reader :clone_bitmap
  1383.  
  1384.   alias theo_clonesprites_init initialize
  1385.   def initialize(*args)
  1386.     @cloned_sprites = []
  1387.     theo_clonesprites_init(*args)
  1388.   end
  1389.  
  1390.   # --------------------------------------------------------------------------
  1391.   # Base function to clone sprite
  1392.   # --------------------------------------------------------------------------
  1393.   def clone(z_pos = 0, clone_bitmap = false)
  1394.     @cloned_sprites.delete_if {|spr| spr.disposed? }
  1395.     cloned = clone_class.new(viewport)
  1396.     cloned.x = x
  1397.     cloned.y = y
  1398.     cloned.bitmap = bitmap
  1399.     cloned.bitmap = bitmap.clone if clone_bitmap
  1400.     if z_pos != 0
  1401.       cloned.z = z + z_pos
  1402.     else
  1403.       @cloned_sprites.each do |spr|
  1404.         spr.z -= 1
  1405.       end
  1406.       cloned.z = z - 1
  1407.     end
  1408.     cloned.src_rect.set(src_rect)
  1409.     cloned.zoom_x = zoom_x
  1410.     cloned.zoom_y = zoom_y
  1411.     cloned.angle = angle
  1412.     cloned.mirror = mirror
  1413.     cloned.opacity = opacity
  1414.     cloned.blend_type = blend_type
  1415.     cloned.color.set(color)
  1416.     cloned.tone.set(tone)
  1417.     cloned.visible = visible
  1418.     cloned.bush_depth = bush_depth
  1419.     cloned.bush_opacity = bush_opacity
  1420.     cloned.ox = ox
  1421.     cloned.oy = oy
  1422.     on_after_cloning(cloned)
  1423.     @cloned_sprites.push(cloned)
  1424.     cloned
  1425.   end
  1426.    
  1427.   def on_after_cloning(cloned)
  1428.     # Abstract method. Overwrite it as you want
  1429.   end
  1430.  
  1431.   # Sprite class for cloned sprite
  1432.   def clone_class
  1433.     Sprite
  1434.   end
  1435.  
  1436. end
  1437.  
  1438. # =============================================================================
  1439. # Afterimages basic module for all sprite base instance object
  1440. # =============================================================================
  1441. class Sprite_Base < Sprite
  1442.   attr_accessor :afterimage
  1443.   attr_accessor :afterimage_opac
  1444.   attr_accessor :afterimage_rate
  1445.  
  1446.   alias theo_afterimagebase_init initialize
  1447.   def initialize(*args)
  1448.     init_afterimage_base
  1449.     theo_afterimagebase_init(*args)
  1450.   end
  1451.  
  1452.   def init_afterimage_base
  1453.     @afterimage = false
  1454.     @afterimage_count = 0
  1455.     @afterimage_rate = 3
  1456.     @afterimage_opac = 5
  1457.     @afterimages = []
  1458.   end
  1459.  
  1460.   alias theo_afterimagebase_update update
  1461.   def update
  1462.     theo_afterimagebase_update
  1463.     update_afterimage_effect
  1464.   end
  1465.  
  1466.   def update_afterimage_effect
  1467.     @afterimages.delete_if do |image|
  1468.       image.opacity -= afterimage_opac
  1469.       image.update if updating_afterimages?
  1470.       if image.opacity == 0
  1471.         image.dispose
  1472.       end
  1473.       image.disposed?
  1474.     end
  1475.     return unless afterimage
  1476.     @afterimage_count += 1
  1477.     if @afterimage_count % afterimage_rate == 0
  1478.       @afterimages.push(clone)
  1479.     end
  1480.   end
  1481.  
  1482.   def updating_afterimages?
  1483.     return false
  1484.   end
  1485.  
  1486. end
  1487. end
  1488. # =============================================================================
  1489. # Sprite Rotate Basic module
  1490. # -----------------------------------------------------------------------------
  1491. if $imported[:Theo_RotateImage]
  1492. # =============================================================================
  1493. module Theo
  1494.   module Rotation
  1495.    
  1496.     def init_rotate
  1497.       @degree = self.angle.to_f
  1498.       @target_degree = 0
  1499.       @rotating = false
  1500.       @rotate_speed = 0.0
  1501.     end
  1502.    
  1503.     def change_angle(target_degree, duration)
  1504.       @degree = self.angle.to_f
  1505.       @target_degree = target_degree.to_f
  1506.       if duration == 0
  1507.         @rotate_speed = target_degree
  1508.       else
  1509.         @rotate_speed = (target_degree - @degree) / duration
  1510.       end
  1511.       @rotating = true
  1512.     end
  1513.    
  1514.     def update_rotation
  1515.       return unless @rotating
  1516.       @degree += @rotate_speed
  1517.       new_angle = @degree.round
  1518.       self.angle = new_angle
  1519.       if new_angle == @target_degree
  1520.         init_rotate
  1521.       end
  1522.     end
  1523.    
  1524.     def start_rotate(degree_plus, duration)
  1525.       change_angle(@degree + degree_plus, duration)
  1526.     end
  1527.    
  1528.   end
  1529. end
  1530.  
  1531. class Sprite
  1532.   include Theo::Rotation
  1533.  
  1534.   alias theo_spr_rotate_init initialize
  1535.   def initialize(viewport = nil)
  1536.     theo_spr_rotate_init(viewport)
  1537.     init_rotate
  1538.   end
  1539.  
  1540.   alias theo_spr_rotate_update update
  1541.   def update
  1542.     theo_spr_rotate_update
  1543.     update_rotation
  1544.   end
  1545.  
  1546. end
  1547.  
  1548. end
  1549.  
  1550. def debug
  1551.   puts "This line is executed"
  1552. end
  1553.  
  1554. def debugc
  1555.   puts Graphics.frame_count
  1556. end
Advertisement
Add Comment
Please, Sign In to add comment