Advertisement
Raizen

Akea Battle Camera(Atoa Add)

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