Advertisement
Raizen

Akea Animated Battle Pictures(English)

Apr 26th, 2015
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 14.77 KB | None | 0 0
  1. #=======================================================
  2. #        Akea Animated Battle Pictures
  3. # Author: Raizen
  4. # Comunity: http://www.centrorpg.com/
  5. # Compatibility: RMVXAce
  6. #
  7.  
  8. # Instructions:
  9. # The script adds the function that, you can use it to animate
  10. # pictures or icons, this allows portraits to be shown, items to be thrown
  11. # (arrows and spells), and many things that you can think of.
  12.  
  13.  
  14.  
  15. #=======================================================
  16. # =========================Don't modify!==============================
  17. $imported ||= Hash.new
  18. $imported[:akea_battlepictures] = 1.0
  19. module Akea_BattlePic
  20. Battle_Pic = Array.new
  21. Movement = Array.new
  22. # =========================Don't modify!==============================
  23.  
  24. # Instances is the number of max pictures simultaneous on the screen
  25. Instances = 5
  26.  
  27. # Below is Configured the Battle Pic, Battle_Pic is where the initial
  28. # and global configuration will be, they all use this template
  29.  
  30. =begin
  31.   id is the id number, must be unique
  32. Battle_Pic[id] = {    
  33.   this is where the picture goes, put picture name inside "", you
  34.   can also use icons, just putting the icon index without ""
  35.   Picture must be in folder Graphics/Akea of your project
  36. :picture => "arrow",    
  37.   This is the movement it will make, check the Movement configuration below
  38.   and put the id inside [], you can have as many movement as wanted, just
  39.   separate them by commas ,
  40. :movement => [0],
  41.   Here goes the initial position, it can be a exact position, [pos x, pos y]
  42.   'user', or 'target' target only works for akea, contact me for other system supports
  43. :position => 'user',
  44.   Offset is like the position, but from the position, how
  45.   many pixels in x and y I will "offset"
  46. :offset => [-10, -40],
  47.   Here is the z position, for picture overlay correction
  48. :z_pos => 100,
  49.   Total frames, put 1 if the picture has no more then 1 frame
  50. :frames => 1,
  51.   Time to change frames, put 1 if the picture has no more then 1 frame
  52. :time => 1,
  53. } <- don't take this out
  54.  
  55.  
  56. =end
  57.  
  58. # To call this script just,
  59. # akea_picture(n), where n is the id
  60. # Some systems can have script calls different,
  61. # if akea_picture(n) does not work, use SceneManager.scene.akea_picture(n)
  62.  
  63. #==============================================================================
  64. # Battle_Pic[0] => arrow animation
  65. #==============================================================================
  66. Battle_Pic[0] = {
  67. :picture => "arrow",
  68. :movement => [0],
  69. :position => 'user',
  70. :offset => [-10, -30],
  71. :z_pos => 100,
  72. :frames => 1,
  73. :time => 1,
  74. }
  75. #==============================================================================
  76. # Battle_Pic[1] => throw axe animation
  77. #==============================================================================
  78. Battle_Pic[1] = {
  79. :picture => 144,
  80. :movement => [1],
  81. :position => 'user',
  82. :offset => [-10, -40],
  83. :z_pos => 100,
  84. :frames => 1,
  85. :time => 1,
  86. }
  87. #==============================================================================
  88. # Battle_Pic[2] => wind animation
  89. #==============================================================================
  90. Battle_Pic[2] = {
  91. :picture => 'animated_state2',
  92. :movement => [2],
  93. :position => 'user',
  94. :offset => [-10, -40],
  95. :z_pos => 100,
  96. :frames => 12,
  97. :time => 5,
  98. }
  99. #==============================================================================
  100. # Battle_Pic[3] => special skill animation
  101. #==============================================================================
  102. Battle_Pic[3] = {
  103. :picture => 'special',
  104. :movement => [3, 4],
  105. :position => [300, 200],
  106. :offset => [0, 0],
  107. :z_pos => 100,
  108. :frames => 1,
  109. :time => 1,
  110. }
  111.  
  112. # Below is Configured the Movement, the movement is the id
  113. # that will go inside the :movement =>, in above configuration
  114.  
  115. =begin
  116.   id is the id number, must be unique
  117. Movement[id] = {
  118.   this is the end position of the movement, can be an exact position [pos x, pos y]
  119.   or 'user' or 'target', target only works with akea animated battle, for
  120.   other battler systems contact me
  121. :end => 'target',
  122.   offset is the same offset from BattlePic, it is how much it will
  123.   offset from the final position
  124. :offset => [-10, -40],
  125.   time is the tame this movement will take
  126. :time => 30,
  127.   jumpheight is the height of the jump, good for animation of throwing items
  128. :jumpheight => 0,
  129.   rotate is if the picture will rotate, and how much it will,
  130.   0 = no rotation, the higher the faster.
  131. :rotate => 0,
  132. } <- don't take this out
  133.  
  134.  
  135. =end
  136. #==============================================================================
  137. # Movement[0] => picture goes toward the target
  138. #==============================================================================
  139. Movement[0] = {
  140. :end => 'target',
  141. :offset => [-10, -40],
  142. :time => 30,
  143. :jumpheight => 0,
  144. :rotate => 0,
  145. }
  146. #==============================================================================
  147. # Movement[1] => picture goes toward the target(but with jump and rotation)
  148. #==============================================================================
  149. Movement[1] = {
  150. :end => 'target',
  151. :offset => [-10, -40],
  152. :time => 30,
  153. :jumpheight => 30,
  154. :rotate => 10,
  155. }
  156. #==============================================================================
  157. # Movement[2] => picture goes toward the target(longer)
  158. #==============================================================================
  159. Movement[2] = {
  160. :end => 'target',
  161. :offset => [-10, -40],
  162. :time => 60,
  163. :jumpheight => 0,
  164. :rotate => 0,
  165. }
  166. #==============================================================================
  167. # Movement[3] => picture goes to position 300, 200
  168. #==============================================================================
  169. Movement[3] = {
  170. :end => [300, 200],
  171. :offset => [0, 0],
  172. :time => 30,
  173. :jumpheight => 0,
  174. :rotate => 0,
  175. }
  176. #==============================================================================
  177. # Movement[4] => picture goes to position -100, 200
  178. #==============================================================================
  179. Movement[4] = {
  180. :end => [-100, 200],
  181. :offset => [0, 0],
  182. :time => 60,
  183. :jumpheight => 0,
  184. :rotate => 0,
  185. }
  186. end
  187. #==============================================================================
  188. #--------------------------------------------------------------------------
  189. # HERE STARTS THE SCRIPT!!!
  190. #--------------------------------------------------------------------------
  191. #==============================================================================
  192. #==============================================================================
  193. # ** Scene_Battle
  194. #------------------------------------------------------------------------------
  195. #  Esta classe executa o processamento da tela de batalha.
  196. #==============================================================================
  197.  
  198. class Scene_Battle < Scene_Base
  199. alias :akea_bp_update_basic :update_basic
  200. alias :akea_battlepictures_start :start  
  201.   #--------------------------------------------------------------------------
  202.   # * Inicialização do processo
  203.   #--------------------------------------------------------------------------
  204.   def start
  205.     @akea_bp_pic = Array.new(Akea_BattlePic::Instances)
  206.     @akea_cont_pic = Array.new(Akea_BattlePic::Instances)
  207.     @akea_act_mov = Array.new(Akea_BattlePic::Instances)
  208.     for n in 0...@akea_bp_pic.size
  209.       @akea_bp_pic[n] = Sprite.new
  210.       @akea_cont_pic[n] = Array.new
  211.       @akea_act_mov[n] = Array.new
  212.     end
  213.     akea_battlepictures_start
  214.   end
  215.   #--------------------------------------------------------------------------
  216.   # * atualização basica
  217.   #--------------------------------------------------------------------------
  218.   def update_basic
  219.     update_abp_pictures
  220.     akea_bp_update_basic
  221.   end
  222.   #--------------------------------------------------------------------------
  223.   # * Atualização das imagens
  224.   #--------------------------------------------------------------------------
  225.   def update_abp_pictures
  226.     for n in 0...Akea_BattlePic::Instances
  227.       upt_ind_akea_pictures(n) unless @akea_cont_pic[n].empty?
  228.     end
  229.   end
  230.   #--------------------------------------------------------------------------
  231.   # * Atualização do frame das imagens
  232.   #--------------------------------------------------------------------------
  233.   def update_pic_akea_frame(z)
  234.     if @akea_cont_pic[z][:c_frames] < @akea_cont_pic[z][:frames]
  235.       @akea_cont_pic[z][:c_frames] += 1
  236.     else
  237.       @akea_cont_pic[z][:c_frames] = 1
  238.     end
  239.     cx = @akea_cont_pic[z][:c_frames] - 1
  240.     @akea_bp_pic[z].src_rect.set(cx * @akea_bp_pic[z].bitmap.width/@akea_cont_pic[z][:frames], 0, @akea_bp_pic[z].bitmap.width/@akea_cont_pic[z][:frames], @akea_bp_pic[z].bitmap.height)
  241.   end
  242.   #--------------------------------------------------------------------------
  243.   # * Atualização d posição das imagens
  244.   #--------------------------------------------------------------------------
  245.   def upt_ind_akea_pictures(n)
  246.     @akea_act_mov[n][:time] -= 1
  247.     update_pic_akea_frame(n) if @akea_cont_pic[n][:frames] > 1 && Graphics.frame_count % @akea_cont_pic[n][:time] == 0
  248.     @akea_bp_pic[n].x += @akea_cont_pic[n][:move_to][0]
  249.     @akea_bp_pic[n].y += @akea_cont_pic[n][:move_to][1]
  250.     @akea_bp_pic[n].y += get_pic_akea_height(@akea_cont_pic[n][:move_init][0], @akea_cont_pic[n][:move_final][0], @akea_act_mov[n][:jumpheight], @akea_bp_pic[n].x)
  251.     @akea_bp_pic[n].angle += @akea_act_mov[n][:rotate]
  252.     if @akea_act_mov[n][:time] <= 0
  253.       @akea_act_mov[n] = []
  254.       @akea_cont_pic[n][:movement].shift
  255.       akea_calc_movement(n)
  256.     end
  257.   end
  258.   #--------------------------------------------------------------------------
  259.   # * Processo principal
  260.   #--------------------------------------------------------------------------
  261.   def akea_picture(n)
  262.     z = 0
  263.     z += 1 until @akea_cont_pic[z].empty?
  264.     @akea_cont_pic[z] = Marshal::load(Marshal.dump(Akea_BattlePic::Battle_Pic[n]))
  265.     @akea_bp_pic[z].bitmap.dispose if @akea_bp_pic[z].bitmap
  266.     if Akea_BattlePic::Battle_Pic[n][:picture].is_a?(Integer)
  267.       icon_index = Akea_BattlePic::Battle_Pic[n][:picture]
  268.       @akea_bp_pic[z].bitmap = Cache.system("Iconset")
  269.       @akea_bp_pic[z].src_rect.set(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  270.       @akea_bp_pic[z].ox = 12
  271.       @akea_bp_pic[z].oy = 12
  272.     else
  273.       @akea_bp_pic[z].bitmap = Cache.akea(Akea_BattlePic::Battle_Pic[n][:picture])
  274.       if @akea_cont_pic[z][:frames] > 1
  275.         @akea_bp_pic[z].src_rect.set(0, 0, @akea_bp_pic[z].bitmap.width/@akea_cont_pic[z][:frames], @akea_bp_pic[z].bitmap.height)
  276.       end
  277.       @akea_bp_pic[z].ox =  @akea_bp_pic[z].bitmap.width/(2*@akea_cont_pic[z][:frames])
  278.       @akea_bp_pic[z].oy =  @akea_bp_pic[z].bitmap.height/2
  279.     end
  280.     if @akea_cont_pic[z][:position].is_a?(Array)
  281.       @akea_bp_pic[z].x = @akea_cont_pic[z][:position][0]
  282.       @akea_bp_pic[z].y = @akea_cont_pic[z][:position][1]
  283.     else
  284.       case @akea_cont_pic[z][:position]
  285.       when 'target'
  286.         @akea_bp_pic[z].x = @reuse_targets[0].screen_x
  287.         @akea_bp_pic[z].y = @reuse_targets[0].screen_y
  288.       when 'user'
  289.         @akea_bp_pic[z].x = @subject.screen_x
  290.         @akea_bp_pic[z].y = @subject.screen_y
  291.       end
  292.     end
  293.     @akea_bp_pic[z].x += @akea_cont_pic[z][:offset][0]
  294.     @akea_bp_pic[z].y += @akea_cont_pic[z][:offset][1]
  295.     @akea_bp_pic[z].z = @akea_cont_pic[z][:z_pos]
  296.     @akea_cont_pic[z][:c_frames] = 1
  297.     @akea_bp_pic[z].angle = 0
  298.     akea_calc_movement(z)
  299.   end
  300.   #--------------------------------------------------------------------------
  301.   # * Cálculo da distancia e velocidade do movimento
  302.   #--------------------------------------------------------------------------
  303.   def akea_calc_movement(z)
  304.     if @akea_cont_pic[z][:movement].empty?
  305.       @akea_cont_pic[z] = []
  306.       @akea_bp_pic[z].bitmap.dispose
  307.       return
  308.     else
  309.       @akea_act_mov[z] = Akea_BattlePic::Movement[@akea_cont_pic[z][:movement].first].dup
  310.     end
  311.     x = @akea_bp_pic[z].x
  312.     y = @akea_bp_pic[z].y
  313.     if @akea_act_mov[z][:end].is_a?(Array)
  314.         final_x = @akea_act_mov[z][:end][0]
  315.         final_y = @akea_act_mov[z][:end][1]
  316.       else
  317.       case @akea_act_mov[z][:end]
  318.       when 'target'
  319.         final_x = @reuse_targets[0].screen_x
  320.         final_y = @reuse_targets[0].screen_y
  321.       when 'user'
  322.         final_x = @subject.screen_x
  323.         final_y = @subject.screen_y
  324.       end
  325.     end
  326.     final_x += @akea_act_mov[z][:offset][0]
  327.     final_y += @akea_act_mov[z][:offset][1]
  328.     @akea_cont_pic[z][:move_init] = [x, y]
  329.     @akea_cont_pic[z][:move_final] = [final_x, final_y]
  330.     @akea_cont_pic[z][:move_to] = [(final_x - x)/@akea_act_mov[z][:time], (final_y - y)/@akea_act_mov[z][:time]]
  331.   end
  332.   #--------------------------------------------------------------------------
  333.   # * Cálculo da altura
  334.   #--------------------------------------------------------------------------
  335.   def get_pic_akea_height(initial, final, height , moment)
  336.     if initial > final
  337.       jump_peak = (final - initial)/2
  338.       jump_peak += initial
  339.       pos_x = (jump_peak - moment).to_f / [jump_peak, 1].max
  340.       [height * pos_x, height].min
  341.     else
  342.       jump_peak = (initial - final)/2
  343.       jump_peak += final
  344.       pos_x = (jump_peak - moment).to_f / [jump_peak, 1].max
  345.       pos_x *= -1
  346.       [height * pos_x, height].min
  347.     end
  348.   end
  349. end
  350.  
  351.  
  352. #==============================================================================
  353. # ** Cache
  354. #------------------------------------------------------------------------------
  355. #  Este modulo carrega cada gráfico, cria um objeto de Bitmap e retém ele.
  356. # Para acelerar o carregamento e preservar memória, este módulo matém o
  357. # objeto de Bitmap em uma Hash interna, permitindo que retorne objetos
  358. # pré-existentes quando mesmo Bitmap é requerido novamente.
  359. #==============================================================================
  360.  
  361.  
  362. module Cache
  363.   #--------------------------------------------------------------------------
  364.   # * Carregamento dos gráficos de animação
  365.   #     filename : nome do arquivo
  366.   #     hue      : informações da alteração de tonalidade
  367.   #--------------------------------------------------------------------------
  368.   def self.akea(filename)
  369.     load_bitmap("Graphics/Akea/", filename)
  370.   end
  371. end
  372.  
  373. #==============================================================================
  374. # ** Game_Interpreter
  375. #------------------------------------------------------------------------------
  376. #  Um interpretador para executar os comandos de evento. Esta classe é usada
  377. # internamente pelas classes Game_Map, Game_Troop e Game_Event.
  378. #==============================================================================
  379. class Game_Interpreter
  380.   #--------------------------------------------------------------------------
  381.   # * M[etodo de picture
  382.   #--------------------------------------------------------------------------
  383.   def akea_picture(n)
  384.     SceneManager.scene.akea_picture(n)
  385.   end
  386. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement