#--# Bestiary Addon: Basic Animated Sprites v1.0 by Enelvon# =============================================================================## Summary# -----------------------------------------------------------------------------# This addon allows the bestiary to display animated sprites for enemies. These# sprites should be formatted as normal RPG Maker VX Ace sprites and be present# in the Graphics/Characters folder.## Compatibility Information# -----------------------------------------------------------------------------# **Required Scripts:**# SES Core v2.2 or higher.# SES Bestiary v1.0 or higher.## **Known Incompatibilities:**# None.## Usage# -----------------------------------------------------------------------------# This script uses a single Notes tag to accomplish its task.## ### Enemy Note Tags:## `<sprite: !Name!, !Index!>`## Place this in a Notes box to give an enemy an animated sprite.## **Replacements:**## `!Name!` with the name of the sprite's characterset.## `!Index!` with the index of the desired sprite within the characterset.## Aliased Methods# -----------------------------------------------------------------------------# * `class Bestiary`# - `draw_enemy`# - `turn_page`## License# -----------------------------------------------------------------------------# This script is made available under the terms of the MIT Expat license.# View [this page]([URL="http://sesvxace.wordpress.com/license/"]http://sesvxace.wordpress.com/license/[/URL]) for more detailed# information.## Installation# -----------------------------------------------------------------------------# This script requires the SES Core (v2.2 or higher) and the SES Bestiary# (v1.0 or higher) in order to function.# These scripst can be found in the SES source repositories at the following# locations:## * [Core]([URL="https://github.com/sesvxace/core/blob/master/lib/core.rb"]https://github.com/sesvxace/core/blob/master/lib/core.rb[/URL])# * [Bestiary]([URL="https://github.com/sesvxace/bestiary/blob/master/lib/bestiary.rb"]https://github.com/sesvxace/bestiary/blob/master/lib/bestiary.rb[/URL])## Place this script below Materials, but above Main. Place this script below# the SES Core.##++module SES module Bestiary # Number of frames to wait before each frame of animation AnimeSpeed = 24 endendclass Bestiary < Window_Book alias_method :en_bab_b_de, :draw_enemy # Draws the current enemy's battler. def draw_enemy if @battler_sprite @battler_sprite.visible = true return end character_name = nil if !@character_index @character_index = -1 @enemy.enemy.note.split(/[\r\n]+/).each do |line| if line[/<sprite:\s*(.+)?,\s*(\d+)>/i] character_name, @character_index = $1, $2.to_i break end end end if @character_index > -1 draw_animated_enemy(character_name) else en_bab_b_de end end # Draws an animated enemy sprite. def draw_animated_enemy(character_name) @pattern = @anime_count = 0 @battler_sprite = Sprite.new @battler_sprite.z = 255 @battler_sprite.bitmap = Cache.character(character_name) sign = character_name[/^[\!\$]./] if sign && sign.include?('$') @cw = @battler_sprite.bitmap.width / 3 @ch = @battler_sprite.bitmap.height / 4 else @cw = @battler_sprite.bitmap.width / 12 @ch = @battler_sprite.bitmap.height / 8 end update_battler_sprite xpos, ypos = (@battler_size[0] - @cw) / 2, (@battler_size[1] - @ch) / 2 xpos += @enemy.enemy.bestiary_image_offset @battler_sprite.x, @battler_sprite.y = max_width + xpos, @draw_y + ypos end # Updates the window. def update super if @battler_sprite && !@battler_sprite.disposed? @anime_count += 1 if @anime_count > AnimeSpeed update_battler_sprite @anime_count = 0 end end end # Disposes the window. def dispose @battler_sprite.dispose if @battler_sprite super end alias_method :en_bab_b_tp, :turn_page # Turns the page. def turn_page(num) if @battler_sprite @battler_sprite.dispose @battler_sprite = nil end @character_index = nil en_bab_b_tp end # Refreshes the window. def refresh @battler_sprite.visible = false if @battler_sprite super end # Updates the source rectangle of the battler sprite. def update_battler_sprite @pattern = (@pattern + 1) % 4 pattern = @pattern < 3 ? @pattern : 1 sx = (@character_index % 4 * 3 + pattern) * @cw sy = (@character_index / 4 * 4) * @ch @battler_sprite.src_rect.set(sx, sy, @cw, @ch) endend