Advertisement
FlipelyFlip

Addon - Realistic Shadow

Aug 20th, 2024
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.89 KB | None | 0 0
  1. #==============================================================================
  2. # TSBS Addon - Realistic Shadow++
  3. # Version : 1.x (edited)
  4. # Language : English
  5. # Requires : Theolized Sideview Battle System
  6. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7. # Contact :
  8. #------------------------------------------------------------------------------
  9. # *> http://www.rpgmakerid.com
  10. # *> http://www.rpgmakervxace.net
  11. # *> http://theolized.blogspot.com
  12. #==============================================================================
  13. ($imported ||= {})[:TSBS_RealShadow] = true
  14. #==============================================================================
  15. # Change Logs:
  16. # -----------------------------------------------------------------------------
  17. # 2013.08.21 - Finished script
  18. # 2021.03.21 - flip fix & start fix
  19. # 2021.05.12 - And offset translation and rotation command
  20. #==============================================================================
  21. =begin
  22.  
  23.   ===================
  24.   || Introduction ||
  25.   -------------------
  26.   This TSBS addon will make the shadow more realistic. It projects the sprite
  27.   and draw it as a shadow. Best used in sideview style (not isometric looks
  28.   battle system) and custom spriteset. Because it won't show icon shadow if you
  29.   plan to use show weapon icon
  30.  
  31.   =================
  32.   || How to use ||
  33.   -----------------
  34.   This script is plug and play. Just put this below the TSBS implementation
  35.  
  36.   ===================
  37.   || Terms of use ||
  38.   -------------------
  39.   Credit me, TheoAllen. You are free to edit this script by your own. As long
  40.   as you don't claim it yours. For commercial purpose, don't forget to give me
  41.   a free copy of the game.  
  42.  
  43. =end
  44. #==============================================================================
  45. # Configurations
  46. #==============================================================================
  47. module TSBS
  48.   module RShadow
  49.    
  50.     Opacity = 128 # Shadow opacity. The lesser, the more transparent it will be
  51.     Scale   = 0.5 # Shadow scale from the original source
  52.    
  53.   end
  54. end
  55. #==============================================================================
  56. # End of configuration. Do not edit anything pass this line!
  57. #==============================================================================
  58. if $imported[:TSBS] >= '1.4.0'
  59. #==============================================================================
  60. # ** Sprite_BattlerShadow
  61. #------------------------------------------------------------------------------
  62. #  This sprite is used to display battler's shadow.
  63. #==============================================================================
  64. class Sprite_BattlerShadow < Sprite
  65.   # --------------------------------------------------------------------------
  66.   # * Initialize
  67.   # --------------------------------------------------------------------------
  68.   def initialize(sprite_battler, viewport = nil)
  69.     @sprite_battler = sprite_battler
  70.     super(viewport)
  71.     update_reference
  72.     self.mirror = enemy_start?
  73.     self.angle = 180
  74.     self.color.set(Color.new(0,0,0))
  75.     if @sprite_battler.battler.class == Game_Enemy
  76.       @sprite_battler.battler.init_shadow_start
  77.     end
  78.     update
  79.   end
  80.  
  81.   def enemy_start?
  82.     return @sprite_battler.battler.nil?
  83.   end
  84.  
  85.   def update_shadow
  86.   end
  87.   # --------------------------------------------------------------------------
  88.   # * Update Reference
  89.   # --------------------------------------------------------------------------
  90.   def update_reference
  91.     self.bitmap = @sprite_battler.bitmap
  92.     src_rect.set(@sprite_battler.src_rect)
  93.   end
  94.   # --------------------------------------------------------------------------
  95.   # * Update Size
  96.   # --------------------------------------------------------------------------
  97.   def update_size
  98.     self.zoom_y = TSBS::RShadow::Scale * ($imported[:TSBS_Camera] ?
  99.       $tsbs_camera.zoom : 1.0)
  100.     self.zoom_x = ($imported[:TSBS_Camera] ? $tsbs_camera.zoom : 1.0)
  101.     self.ox = width/2
  102.     self.oy = height
  103.   end
  104.  
  105.   def update_position
  106.     if @sprite_battler.battler
  107.       self.x = @sprite_battler.battler.shadow_x
  108.       self.y = @sprite_battler.battler.shadow_y + shift_y
  109.       self.angle = 180 + @sprite_battler.battler.srotate
  110.     end
  111.     self.z = @sprite_battler.z #FlipEdit
  112.   end
  113.  
  114.   # --------------------------------------------------------------------------
  115.   # * Update opacity
  116.   # --------------------------------------------------------------------------
  117.   def update_opacity
  118.     self.opacity = TSBS::RShadow::Opacity * (@sprite_battler.opacity/255.0)
  119.   end
  120.   # --------------------------------------------------------------------------
  121.   # * Update
  122.   # --------------------------------------------------------------------------
  123.   def update
  124.     super
  125.     update_size
  126.     update_position
  127.     update_opacity
  128.     update_visible
  129.     update_reference
  130.   end
  131.   # --------------------------------------------------------------------------
  132.   # * Update
  133.   # --------------------------------------------------------------------------  
  134.   def shift_y
  135.     return -data_battler.shadow_y * ($imported[:TSBS_Camera] ?
  136.       $tsbs_camera.zoom : 1.0)
  137.   end
  138. end
  139.  
  140. class Game_Enemy
  141.   def init_shadow_start
  142.     @shadow_point.x = x
  143.     @shadow_point.y = y
  144.   end
  145. end
  146. end
  147.  
  148. class Game_Battler
  149.   attr_reader :srotate
  150.  
  151.   alias clear_tsbs_shadow clear_tsbs
  152.   def clear_tsbs
  153.     @sox = 0
  154.     @soy = 0
  155.     @srotate = 0
  156.     clear_tsbs_shadow
  157.   end
  158.  
  159.   alias sxpos shadow_x
  160.   def shadow_x
  161.     return sxpos + @sox
  162.   end
  163.  
  164.   alias sypos shadow_y
  165.   def shadow_y
  166.     return sypos + @soy
  167.   end
  168.  
  169.   alias shadowoffset_custom custom_sequence_handler
  170.   def custom_sequence_handler
  171.     if @acts[0] == :shadow_transform
  172.       @sox = @acts[1] || @sox
  173.       @soy = @acts[2] || @soy
  174.       @srotate = @acts[3] || @srotate
  175.     else
  176.       shadowoffset_custom
  177.     end
  178.   end
  179.  
  180. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement