Advertisement
Raizen

Akea Battle Camera(English)

Apr 20th, 2015
1,124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.80 KB | None | 0 0
  1. #=======================================================
  2. #        Akea Battle Camera
  3. # Author: Raizen
  4. # Community: http://www.centrorpg.com/
  5. # Compatibility: RMVXAce
  6. #
  7. #=======================================================
  8. # =========================Don't Modify==============================
  9. $included ||= Hash.new
  10. $included[:akea_battlecamera] = true
  11. module Akea_BattleCamera
  12. Camera_Config = []
  13. # =========================Don't Modify==============================
  14. # Instructions:
  15. # The camera system allows zoom and camera movimentation as you wish, you can
  16. # adjust it to be the target or the user and to where the camera will move.
  17. # To make the call script just:
  18.  
  19. # Script Call: akea_camera(n), where n is the id in the configuration below.
  20. # This script call can be used either in battle events, or in battle systems that do allows
  21. # Script calls.(Akea Animated Battle System, Victor Animated Battle and others)
  22. # For some battle system, you might need to put this before the script call
  23. # SceneManager.scene, so for example it can be SceneManager.scene.akea_camera(n)
  24.  
  25. # Below is configured the camera moves, follow the instructions :)
  26.  
  27. # :focus is where the camera will be moved, it can be absolute movement, enemy movement,
  28. # or user movement.
  29. # To absolute movement use the following
  30.  
  31. # :focus => [x, y, type]
  32. # x is the x position, y is the y position, and type is the type of movement where.
  33. # 0 will move the camera to x axis and y axis, and 1 will move x pixels and y pixels,
  34. # Example [300, 200, 0] will move the camera to position 300, 200
  35. # [300, 200, 1] will move the camera 300 pixels to the left, 200 pixels down.
  36.  
  37. # The other tags for focus are:
  38. # 'none' => no camera movement
  39. # 'target' => target camera movement(Note, it will only work on Akea Animated Battle System!).
  40. # 'user' => The camera focus the user
  41. # 'center' => return the camera to its original position
  42.  
  43. # :zoom_x/:zoom_y is the camera zoom, where 1 would be 100%
  44. # So if I want 2 times smaller(50%) I would just... :zoom_x => 0.5,
  45. # :time in frames that will happen the camera movement
  46. # :time => 20, would mean 20 frames (1/3 seconds)
  47.  
  48.  
  49. # :offset_x/:offset_y would simply mean if you want to make an adjust on final
  50. # camera positions, this is more for the 'user'/'target' focus
  51.  
  52. #==============================================================================
  53. # Camera_Config[0] => camera moves 300 to the left and
  54. # zooms 200%
  55. #==============================================================================
  56. Camera_Config[0] = {
  57. :focus => [-300, 0, 1],
  58. :zoom_x => 2,
  59. :zoom_y => 2,
  60. :time => 20,
  61. :offset_x => 0,
  62. :offset_y => 0,
  63. }
  64. #==============================================================================
  65. # Camera_Config[1] => camera returns to center position
  66. # and zoom is reseted
  67. #==============================================================================
  68. Camera_Config[1] = {
  69. :focus => 'center',
  70. :zoom_x => 1,
  71. :zoom_y => 1,
  72. :time => 20,
  73. :offset_x => 0,
  74. :offset_y => 0,
  75. }
  76. #==============================================================================
  77. # Camera_Config[2] => camera goes toward the target with 20% larger sprites
  78. #==============================================================================
  79. Camera_Config[2] = {
  80. :focus => 'target',
  81. :zoom_x => 1.2,
  82. :zoom_y => 1.2,
  83. :time => 20,
  84. :offset_x => 0,
  85. :offset_y => 0,
  86. }
  87. #==============================================================================
  88. # Camera_Config[3] => camera just zooms 200%
  89. #==============================================================================
  90. Camera_Config[3] = {
  91. :focus => 'none',
  92. :zoom_x => 2,
  93. :zoom_y => 2,
  94. :time => 60,
  95. :offset_x => 0,
  96. :offset_y => 0,
  97. }
  98. #==============================================================================
  99. # Camera_Config[3] => camera goes to the user with 200% zoom
  100. #==============================================================================
  101. Camera_Config[4] = {
  102. :focus => 'user',
  103. :zoom_x => 2,
  104. :zoom_y => 2,
  105. :time => 20,
  106. :offset_x => 0,
  107. :offset_y => 0,
  108. }
  109. end
  110. #==============================================================================
  111. #==============================================================================
  112. # Here Starts the Script!
  113. #==============================================================================
  114. #==============================================================================
  115. #==============================================================================
  116. # ** Scene_Battle
  117. #------------------------------------------------------------------------------
  118. #  Esta classe executa o processamento da tela de batalha.
  119. #==============================================================================
  120.  
  121. class Scene_Battle < Scene_Base
  122. alias :akea_bcamera_update_basic :update_basic
  123. alias :akea_bcamera_start :start
  124.   #--------------------------------------------------------------------------
  125.   # * Inicialização do processo
  126.   #--------------------------------------------------------------------------
  127.   def start
  128.     @akea_camera_time = 0
  129.     @akea_camera_config = Hash.new
  130.     akea_bcamera_start
  131.   end
  132.   #--------------------------------------------------------------------------
  133.   # * Atualização das animações de camera
  134.   #--------------------------------------------------------------------------
  135.   def update_akea_camera
  136.     @akea_camera_time -= 1
  137.     time = @akea_camera_config[:time] - @akea_camera_time
  138.     @spriteset.move_camera(@akea_camera_config[:final_x] * time/@akea_camera_config[:time], @akea_camera_config[:final_y] * time/@akea_camera_config[:time])
  139.     @spriteset.make_zoom(@akea_camera_config[:speed_zoom_x], @akea_camera_config[:speed_zoom_y])
  140.     if @akea_camera_time == 0
  141.       @spriteset.set_zoom(@akea_camera_config[:zoom_x], @akea_camera_config[:zoom_y])
  142.     end
  143.   end
  144.   #--------------------------------------------------------------------------
  145.   # * Atualização
  146.   #--------------------------------------------------------------------------
  147.   def update_basic
  148.     akea_bcamera_update_basic
  149.     update_akea_camera if @akea_camera_time > 0
  150.   end
  151.   #--------------------------------------------------------------------------
  152.   # * Método de definição da configuração
  153.   #--------------------------------------------------------------------------
  154.   def akea_camera(n)
  155.     @akea_camera_config = Akea_BattleCamera::Camera_Config[n].dup
  156.     @akea_camera_time = @akea_camera_config[:time]
  157.     get_akea_camera_speed
  158.     get_akea_camera_zoom
  159.   end
  160.   #--------------------------------------------------------------------------
  161.   # * Método que obtém a velocidade da camera
  162.   #--------------------------------------------------------------------------
  163.   def get_akea_camera_speed
  164.     @akea_camera_config[:final_y] = @akea_camera_config[:offset_y] + camera_akea_position_y(@akea_camera_config[:focus])
  165.     @akea_camera_config[:final_x] = @akea_camera_config[:offset_x] + camera_akea_position_x(@akea_camera_config[:focus])
  166.     @spriteset.set_ox_oy_camera
  167.   end
  168.   #--------------------------------------------------------------------------
  169.   # * Método que obtem o zoom da camera
  170.   #--------------------------------------------------------------------------
  171.   def get_akea_camera_zoom
  172.     @akea_camera_config[:speed_zoom_y] = (@akea_camera_config[:zoom_y] - @spriteset.zoom_sprites_y).to_f/@akea_camera_time.to_f
  173.     @akea_camera_config[:speed_zoom_x] = (@akea_camera_config[:zoom_x] - @spriteset.zoom_sprites_x).to_f/@akea_camera_time.to_f
  174.     @spriteset.set_ox_oy_zoom
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # * Método de verificação da posição y
  178.   #--------------------------------------------------------------------------
  179.   def camera_akea_position_y(type)
  180.     if type.is_a?(Array)
  181.       if type[2] == 0
  182.         return type[1] - @spriteset.get_viewport1_oy
  183.       else
  184.         return type[1]
  185.       end
  186.     end
  187.     case type
  188.     when 'none'
  189.       return 0
  190.     when 'target'
  191.       return @reuse_targets[0].screen_y - Graphics.height/2 - @spriteset.get_viewport1_ox
  192.     when 'user'
  193.       return @subject.screen_y - Graphics.height/2 - @spriteset.get_viewport1_ox
  194.     when 'center'
  195.       return -@spriteset.get_viewport1_oy
  196.     end
  197.   end
  198.   #--------------------------------------------------------------------------
  199.   # * Método de verificação da posição x
  200.   #--------------------------------------------------------------------------
  201.   def camera_akea_position_x(type)
  202.     if type.is_a?(Array)
  203.       if type[2] == 0
  204.         return type[0] - @spriteset.get_viewport1_ox
  205.       else
  206.         return type[0]
  207.       end
  208.     end
  209.     case type
  210.     when 'none'
  211.       return 0
  212.     when 'target'
  213.       return @reuse_targets[0].screen_x - Graphics.width/2 - @spriteset.get_viewport1_oy
  214.     when 'user'
  215.       return @subject.screen_x - Graphics.width/2 - @spriteset.get_viewport1_oy
  216.     when 'center'
  217.       return -@spriteset.get_viewport1_ox
  218.     end
  219.   end
  220.  
  221. end
  222.  
  223.  
  224.  
  225. #==============================================================================
  226. # ** Spriteset_Battle
  227. #------------------------------------------------------------------------------
  228. #  Esta classe reune os sprites da tela de batalha. Esta classe é usada
  229. # internamente pela classe Scene_Battle.
  230. #==============================================================================
  231.  
  232. class Spriteset_Battle
  233. alias :akea_bcamera_initialize :initialize
  234. attr_reader :zoom_sprites_x
  235. attr_reader :zoom_sprites_y
  236.   #--------------------------------------------------------------------------
  237.   # * Inicialização do objeto
  238.   #--------------------------------------------------------------------------
  239.   def initialize
  240.     @akea_bcamera_x = 0
  241.     @akea_bcamera_y = 0
  242.     @zoom_sprites_x = 1
  243.     @zoom_sprites_y = 1
  244.     akea_bcamera_initialize
  245.   end
  246.   #--------------------------------------------------------------------------
  247.   # * Método que retem os valores de camera
  248.   #--------------------------------------------------------------------------
  249.   def move_camera(x, y)
  250.     @akea_bcamera_x = x + @viewport_cam_1_ox
  251.     @akea_bcamera_y = y + @viewport_cam_1_oy
  252.   end
  253.   #--------------------------------------------------------------------------
  254.   # * Método que realiza os zooms
  255.   #--------------------------------------------------------------------------
  256.   def make_zoom(x, y)
  257.     @actor_sprites.each{|sprt| sprt.zoom_x += x; sprt.zoom_y += y}
  258.     @enemy_sprites.each{|sprt| sprt.zoom_x += x; sprt.zoom_y += y}
  259.     @back1_sprite.zoom_x += x
  260.     @back1_sprite.zoom_y += y
  261.     @back2_sprite.zoom_x += x
  262.     @back2_sprite.zoom_y += y
  263.     @zoom_sprites_x += x
  264.     @zoom_sprites_y += y
  265.   end
  266.   #--------------------------------------------------------------------------
  267.   # * Método quue seta os valores de zoom(correção de bug)
  268.   #--------------------------------------------------------------------------
  269.   def set_zoom(x, y)
  270.     @actor_sprites.each{|sprt| sprt.zoom_x = x; sprt.zoom_y = y}
  271.     @enemy_sprites.each{|sprt| sprt.zoom_x = x; sprt.zoom_y = y}
  272.     @back1_sprite.zoom_x = x
  273.     @back1_sprite.zoom_y = y
  274.     @back2_sprite.zoom_x = x
  275.     @back2_sprite.zoom_y = y
  276.     @zoom_sprites_x = x
  277.     @zoom_sprites_y = y
  278.   end
  279.   #--------------------------------------------------------------------------
  280.   # * Obtenção do ox do viewport1
  281.   #--------------------------------------------------------------------------
  282.   def get_viewport1_ox
  283.     @viewport1.ox
  284.   end
  285.   #--------------------------------------------------------------------------
  286.   # * Obtenção do oy do viewport1
  287.   #--------------------------------------------------------------------------
  288.   def get_viewport1_oy
  289.     @viewport1.oy
  290.   end
  291.   #--------------------------------------------------------------------------
  292.   # * Setar os valores iniciais de zoom
  293.   #--------------------------------------------------------------------------
  294.   def set_ox_oy_zoom
  295.     @zoom_sprites_x = @back1_sprite.zoom_x
  296.     @zoom_sprites_y = @back1_sprite.zoom_y
  297.   end
  298.   #--------------------------------------------------------------------------
  299.   # * Setar a posção inicial da camera
  300.   #--------------------------------------------------------------------------
  301.   def set_ox_oy_camera
  302.     @viewport_cam_1_ox = @viewport1.ox
  303.     @viewport_cam_1_oy = @viewport1.oy
  304.   end
  305.   #--------------------------------------------------------------------------
  306.   # * Atualização do viewports
  307.   #--------------------------------------------------------------------------
  308.   def update_viewports
  309.     @viewport1.tone.set($game_troop.screen.tone)
  310.     @viewport1.ox = $game_troop.screen.shake
  311.     @viewport1.ox += @akea_bcamera_x
  312.     @viewport1.oy = @akea_bcamera_y
  313.     @viewport2.color.set($game_troop.screen.flash_color)
  314.     @viewport3.color.set(0, 0, 0, 255 - $game_troop.screen.brightness)
  315.     @viewport1.update
  316.     @viewport2.update
  317.     @viewport3.update
  318.   end
  319. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement