Updating a RUBY script into Java

● ARCHIVED · READ-ONLY
Started by Pachurick 1 posts View original ↗
  1. I'm looking for help on updating a particular script written for ruby into java.
    The script is from this thread: https://forums.rpgmakerweb.com/inde...ation-in-a-tile-in-front-of-the-player.16998/

    Code:
    #========================================================================# OFFSET ANIMATIONS# Version 1.0# Author: Shaz#------------------------------------------------------------------------# DESCRIPTION# Allows you to set an animation to play on a tile next to the character,# rather than right over it#------------------------------------------------------------------------# TO INSTALL# Copy and paste into a new slot in Materials.# This script aliases the following methods, and should be placed # below any other scripts that overwrite them:#   Game_CharacterBase.init_public_members#   Sprite_Base.initialize#   Sprite_Base.start_animation#   Sprite_Character.setup_new_effect# This script overwrites the following method, and should be placed above# any other scripts that alias the same:#   Sprite_Base.animation_set_sprites# No customization necessary.#------------------------------------------------------------------------# TO USE# Call the method play_offset_animation(anim_id[, offset]) on the character# (which could be the player, a follower, a vehicle or an event) to start# the animation in a location other than over the character.# Call the method cancel_offset_animation to cancel it, so the next animation# will not be played with the same offset# # Valid values:# - the following values do not take the player's facing direction into account# :over        (default - play animation on the character)# :above       (play animation on the tile above the character)# :below       (play animation on the tile below the character)# :left        (play animation on the tile to the left of the character)# :right       (play animation on the tile to the right of the character)# - the following values DO take the player's facing direction into account# :front       (play animation on the tile in front of the character)# :back        (play animation on the tile behind the character)# :charleft    (play animation on the tile to the character's left)# :charright   (play animation on the tile to the character's right)#------------------------------------------------------------------------# WARNINGS# This script will NOT move around if the character changes direction while the #  animation is playing (so if you set a long animation to play in front#  of the character, and make the character turn around, the animation will#  continue playing where it started.#------------------------------------------------------------------------# EXAMPLES# $game_player.play_offset_animation(10, :above)# $game_map.events[8].play_offset_animation(10, :front)#========================================================================class Game_CharacterBase  attr_reader    :anim_offset             # animation offset    alias shaz_oa_init_public_members init_public_members  def init_public_members    shaz_oa_init_public_members    @anim_offset = :over  end  def play_offset_animation(anim_id, offset = :over)    @anim_offset = offset    @animation_id = anim_id  end  def cancel_offset_animation    @anim_offset = :over  endend#==============================================================================# ** Sprite_Base#------------------------------------------------------------------------------#  A sprite class with animation display processing added.#==============================================================================class Sprite_Base < Sprite  attr_accessor        :anim_offset  attr_accessor        :char_dir  #--------------------------------------------------------------------------  # * Object Initialization  #--------------------------------------------------------------------------  alias shaz_oa_initialize initialize  def initialize(viewport = nil)    shaz_oa_initialize(viewport)    @anim_offset = :over    @char_dir = 0  end  #--------------------------------------------------------------------------  # * Start Animation  #--------------------------------------------------------------------------  alias shaz_oa_start_animation start_animation  def start_animation(animation, mirror = false)    @offset_ox = 0    @offset_oy = 0    shaz_oa_start_animation(animation, mirror)    if @animation      setup_animation_offset if @anim_offset != :over    end  end  #--------------------------------------------------------------------------  # * Offset Animation to Another Tile  #--------------------------------------------------------------------------  def setup_animation_offset    case @anim_offset    when :left; @offset_ox -= 32    when :right; @offset_ox += 32    when :above; @offset_oy -= 32    when :below; @offset_oy += 32    when :front      case @char_dir      when 2; @offset_oy += 32      when 4; @offset_ox -= 32      when 6; @offset_ox += 32      when 8; @offset_oy -= 32      end    when :back      case @char_dir      when 2; @offset_oy -= 32      when 4; @offset_ox += 32      when 6; @offset_ox -= 32      when 8; @offset_oy += 32      end    when :charleft      case @char_dir      when 2; @offset_ox += 32      when 4; @offset_oy += 32      when 6; @offset_oy -= 32      when 8; @offset_ox -= 32      end    when :charright      case @char_dir      when 2; @offset_ox -= 32      when 4; @offset_oy -= 32      when 6; @offset_oy += 32      when 8; @offset_ox += 32      end    end  end    #--------------------------------------------------------------------------  # * Set Animation Sprite  #     frame : Frame data (RPG::Animation::Frame)  #--------------------------------------------------------------------------  def animation_set_sprites(frame)    cell_data = frame.cell_data    @ani_sprites.each_with_index do |sprite, i|      next unless sprite      pattern = cell_data[i, 0]      if !pattern || pattern < 0        sprite.visible = false        next      end      sprite.bitmap = pattern < 100 ? @ani_bitmap1 : @ani_bitmap2      sprite.visible = true      sprite.src_rect.set(pattern % 5 * 192,        pattern % 100 / 5 * 192, 192, 192)      if @ani_mirror        sprite.x = @ani_ox - cell_data[i, 1] + @offset_ox        sprite.y = @ani_oy + cell_data[i, 2] + @offset_oy        sprite.angle = (360 - cell_data[i, 4])        sprite.mirror = (cell_data[i, 5] == 0)      else        sprite.x = @ani_ox + cell_data[i, 1] + @offset_ox        sprite.y = @ani_oy + cell_data[i, 2] + @offset_oy        sprite.angle = cell_data[i, 4]        sprite.mirror = (cell_data[i, 5] == 1)      end      sprite.z = self.z + 300 + i      sprite.ox = 96      sprite.oy = 96      sprite.zoom_x = cell_data[i, 3] / 100.0      sprite.zoom_y = cell_data[i, 3] / 100.0      sprite.opacity = cell_data[i, 6] * self.opacity / 255.0      sprite.blend_type = cell_data[i, 7]    end  endendclass Sprite_Character < Sprite_Base  alias shaz_oa_setup_new_effect setup_new_effect  def setup_new_effect    @anim_offset = @character.anim_offset    @char_dir = @character.direction    shaz_oa_setup_new_effect  endend

    Thank you