Advertisement
bowei

Untitled

Feb 12th, 2019
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.20 KB | None | 0 0
  1. #==============================================================================
  2. # ** Game_Picture
  3. #------------------------------------------------------------------------------
  4. #  This class handles pictures. It is created only when a picture of a specific
  5. # number is required internally for the Game_Pictures class.
  6. #==============================================================================
  7.  
  8. class Game_Picture
  9.   #--------------------------------------------------------------------------
  10.   # * Public Instance Variables
  11.   #--------------------------------------------------------------------------
  12.   attr_reader   :number                   # picture index
  13.   attr_reader   :name                     # filename
  14.   attr_reader   :origin                   # starting point
  15.   attr_reader   :x                        # x-coordinate
  16.   attr_reader   :y                        # y-coordinate
  17.   attr_reader   :zoom_x                   # x directional zoom rate
  18.   attr_reader   :zoom_y                   # y directional zoom rate
  19.   attr_reader   :opacity                  # opacity level
  20.   attr_reader   :blend_type               # blend method
  21.   attr_reader   :tone                     # color tone
  22.   attr_reader   :angle                    # rotation angle
  23.   #--------------------------------------------------------------------------
  24.   # * Object Initialization
  25.   #--------------------------------------------------------------------------
  26.   def initialize(number)
  27.     @number = number
  28.     init_basic
  29.     init_target
  30.     init_tone
  31.     init_rotate
  32.   end
  33.   #--------------------------------------------------------------------------
  34.   # * Initialize Basic Variable
  35.   #--------------------------------------------------------------------------
  36.   def init_basic
  37.     @name = ""
  38.     @origin = @x = @y = 0
  39.     @zoom_x = @zoom_y = 100.0
  40.     @opacity = 255.0
  41.     @blend_type = 1
  42.   end
  43.   #--------------------------------------------------------------------------
  44.   # * Initialize Movement Target
  45.   #--------------------------------------------------------------------------
  46.   def init_target
  47.     @target_x = @x
  48.     @target_y = @y
  49.     @target_zoom_x = @zoom_x
  50.     @target_zoom_y = @zoom_y
  51.     @target_opacity = @opacity
  52.     @duration = 0
  53.   end
  54.   #--------------------------------------------------------------------------
  55.   # * Initialize Color Tone
  56.   #--------------------------------------------------------------------------
  57.   def init_tone
  58.     @tone = Tone.new
  59.     @tone_target = Tone.new
  60.     @tone_duration = 0
  61.   end
  62.   #--------------------------------------------------------------------------
  63.   # * Initialize Rotation
  64.   #--------------------------------------------------------------------------
  65.   def init_rotate
  66.     @angle = 0
  67.     @rotate_speed = 0
  68.   end
  69.   #--------------------------------------------------------------------------
  70.   # * Show Picture
  71.   #--------------------------------------------------------------------------
  72.   def show(name, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
  73.     @name = name
  74.     @origin = origin
  75.     @x = x.to_f
  76.     @y = y.to_f
  77.     @zoom_x = zoom_x.to_f
  78.     @zoom_y = zoom_y.to_f
  79.     @opacity = opacity.to_f
  80.     @blend_type = blend_type
  81.     init_target
  82.     init_tone
  83.     init_rotate
  84.   end
  85.   #--------------------------------------------------------------------------
  86.   # * Move Picture
  87.   #--------------------------------------------------------------------------
  88.   def move(origin, x, y, zoom_x, zoom_y, opacity, blend_type, duration)
  89.     @origin = origin
  90.     @target_x = x.to_f
  91.     @target_y = y.to_f
  92.     @target_zoom_x = zoom_x.to_f
  93.     @target_zoom_y = zoom_y.to_f
  94.     @target_opacity = opacity.to_f
  95.     @blend_type = blend_type
  96.     @duration = duration
  97.   end
  98.   #--------------------------------------------------------------------------
  99.   # * Change Rotation Speed
  100.   #--------------------------------------------------------------------------
  101.   def rotate(speed)
  102.     @rotate_speed = speed
  103.   end
  104.   #--------------------------------------------------------------------------
  105.   # * Start Changing Color Tone
  106.   #--------------------------------------------------------------------------
  107.   def start_tone_change(tone, duration)
  108.     @tone_target = tone.clone
  109.     @tone_duration = duration
  110.     @tone = @tone_target.clone if @tone_duration == 0
  111.   end
  112.   #--------------------------------------------------------------------------
  113.   # * Erase Picture
  114.   #--------------------------------------------------------------------------
  115.   def erase
  116.     @name = ""
  117.     @origin = 0
  118.   end
  119.   #--------------------------------------------------------------------------
  120.   # * Frame Update
  121.   #--------------------------------------------------------------------------
  122.   def update
  123.     update_move
  124.     update_tone_change
  125.     update_rotate
  126.   end
  127.   #--------------------------------------------------------------------------
  128.   # * Update Picture Move
  129.   #--------------------------------------------------------------------------
  130.   def update_move
  131.     return if @duration == 0
  132.     d = @duration
  133.     @x = (@x * (d - 1) + @target_x) / d
  134.     @y = (@y * (d - 1) + @target_y) / d
  135.     @zoom_x  = (@zoom_x  * (d - 1) + @target_zoom_x)  / d
  136.     @zoom_y  = (@zoom_y  * (d - 1) + @target_zoom_y)  / d
  137.     @opacity = (@opacity * (d - 1) + @target_opacity) / d
  138.     @duration -= 1
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # * Update Color Tone Change
  142.   #--------------------------------------------------------------------------
  143.   def update_tone_change
  144.     return if @tone_duration == 0
  145.     d = @tone_duration
  146.     @tone.red   = (@tone.red   * (d - 1) + @tone_target.red)   / d
  147.     @tone.green = (@tone.green * (d - 1) + @tone_target.green) / d
  148.     @tone.blue  = (@tone.blue  * (d - 1) + @tone_target.blue)  / d
  149.     @tone.gray  = (@tone.gray  * (d - 1) + @tone_target.gray)  / d
  150.     @tone_duration -= 1
  151.   end
  152.   #--------------------------------------------------------------------------
  153.   # * Update Rotation
  154.   #--------------------------------------------------------------------------
  155.   def update_rotate
  156.     return if @rotate_speed == 0
  157.     @angle += @rotate_speed / 2.0
  158.     @angle += 360 while @angle < 0
  159.     @angle %= 360
  160.   end
  161. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement