#----------------------------------------------------------------------------
# Sprite Range - Used to display all "RANGES" during battle
#----------------------------------------------------------------------------
class Sprite_Range < RPG::Sprite
attr_accessor

x
attr_accessor

y
#----------------------------------------------------------------------------
#Constants
#----------------------------------------------------------------------------
ANIM_FRAMES = 4
ANIM_TILES = true
ATTACK_COLOR = 'RED'
MOVE_COLOR = 'BLUE'
HELP_SKILL_COLOR = 'GREEN'
ATTACK_SKILL_COLOR = 'YELLOW'
#----------------------------------------------------------------------------
# Object initialization
#----------------------------------------------------------------------------
# type = 1-7, passed by 'def draw_ranges' from Scene_Battle_TBS
#----------------------------------------------------------------------------
def initialize(viewport, type, x, y, visible = true)
super(viewport)
self.visible = visible
self.bitmap = Bitmap.new(32,32)
self.opacity = 100
@wait = 6
@pattern = [0,1,2,3]
@p_index = 0 #pattern index
@h = 0
@type = type
@x = x, @y = y
@oy = y; @ox = x
@iso = $game_map.iso? rescue @iso = false
@anim = ANIM_TILES
moveto(@ox, @oy)
refresh
end
#----------------------------------------------------------------------------
# Get Color for tile
#----------------------------------------------------------------------------
def get_color(color)
case color
when "RED"
return Color.new(255,0,0,255)
when "BLUE"
return Color.new(0,0,255,255)
when "GREEN"
return Color.new(0,255,0,255)
when "YELLOW"
return Color.new(255,255,0,255)
when "PURPLE"
return Color.new(128,0,255,255)
when "ORANGE"
return Color.new(255,128,0,255)
when "BROWN"
return Color.new(128,64,0,255)
when "BLACK"
return Color.new(0,0,0,255)
when "WHITE"
return Color.new(255,255,255,255)
when "PINK"
return Color.new(255,128,255,255)
when "TAN"
return Color.new(200,200,110,255)
end
end
#----------------------------------------------------------------------------
# Map is Iso?
#----------------------------------------------------------------------------
def iso?
return @iso
end
#----------------------------------------------------------------------------
# Refresh - Process to update/set the bitmap for the object
#----------------------------------------------------------------------------
def refresh
#create rectangle to fill is not using a picture
rect = Rect.new(1, 1, 30, 30)
if iso?
case @type
when 1; self.bitmap = RPG::Cache.picture(sprintf("TBS Movement/#{ATTACK_COLOR}_iso_range"))
when 2; self.bitmap = RPG::Cache.picture(sprintf("TBS Movement/#{MOVE_COLOR}_iso_range"))
when 3; self.bitmap = RPG::Cache.picture(sprintf("TBS Movement/#{HELP_SKILL_COLOR}_iso_range"))
when 4; self.bitmap = RPG::Cache.picture(sprintf("TBS Movement/#{ATTACK_SKILL_COLOR}_iso_range"))
when 5; self.bitmap = RPG::Cache.picture(sprintf("TBS Movement/#{ATTACK_SKILL_COLOR}_iso_range"))
when 6; self.bitmap = RPG::Cache.picture(sprintf("TBS Movement/#{HELP_SKILL_COLOR}_iso_range"))
when 7; self.bitmap = RPG::Cache.picture(sprintf("TBS Movement/#{ATTACK_COLOR}_iso_range"))
end
else #non iso
if @anim
case @type
when 1; self.bitmap = RPG::Cache.picture(sprintf("TBS Movement/#{ATTACK_COLOR}_range"))
when 2; self.bitmap = RPG::Cache.picture(sprintf("TBS Movement/#{MOVE_COLOR}_range"))
when 3; self.bitmap = RPG::Cache.picture(sprintf("TBS Movement/#{HELP_SKILL_COLOR}_range"))
when 4; self.bitmap = RPG::Cache.picture(sprintf("TBS Movement/#{ATTACK_SKILL_COLOR}_range"))
when 5; self.bitmap = RPG::Cache.picture(sprintf("TBS Movement/#{ATTACK_SKILL_COLOR}_range"))
when 6; self.bitmap = RPG::Cache.picture(sprintf("TBS Movement/#{HELP_SKILL_COLOR}_range"))
when 7; self.bitmap = RPG::Cache.picture(sprintf("TBS Movement/#{ATTACK_COLOR}_range"))
end
else
case @type
when 1; self.bitmap.fill_rect(rect, get_color(ATTACK_COLOR))
when 2; self.bitmap.fill_rect(rect, get_color(MOVE_COLOR))
when 3; self.bitmap.fill_rect(rect, get_color(HELP_SKILL_COLOR))
when 4; self.bitmap.fill_rect(rect, get_color(ATTACK_SKILL_COLOR))
when 5; self.bitmap.fill_rect(rect, get_color(ATTACK_SKILL_COLOR))
when 6; self.bitmap.fill_rect(rect, get_color(HELP_SKILL_COLOR))
when 7; self.bitmap.fill_rect(rect, get_color(ATTACK_COLOR))
end
end
end
if [5,6,7].include?(@type)
self.opacity = 255
end
if @anim
@cw = self.bitmap.width / ANIM_FRAMES
else
@cw = self.bitmap.width
end
@ch = self.bitmap.height
self.opacity = 0 if visible == false
update
end
#----------------------------------------------------------------------------
# Dispose process
#----------------------------------------------------------------------------
def dispose
unless self.bitmap == nil
self.bitmap.dispose
self.bitmap = nil
end
super
end
#----------------------------------------------------------------------------
# MoveTo - sets the current X,Y location on the map
#----------------------------------------------------------------------------
def moveto(x, y)
@ox = x; @oy = y
@x = x % $game_map.width
@y = y % $game_map.height
@real_x = @x * 128
@real_y = @y * 128
end
#----------------------------------------------------------------------------
# Get X Coords
#----------------------------------------------------------------------------
def screen_x
if iso?
return ((@real_x - @real_y)/4 + 32*$game_map.height - 0 - $game_map.display_x/4)-27
else
return (@real_x - $game_map.display_x + 3) / 4
end
end
#----------------------------------------------------------------------------
# Get Y Coords
#----------------------------------------------------------------------------
def screen_y
if iso?
y = ((@real_y + @real_x) / 8 + 24 - $game_map.display_y / 4 - (@h) * 8) - 25
return y
else
y = (@real_y - $game_map.display_y + 3) / 4
return y
end
end
#----------------------------------------------------------------------------
# Get Z coords
#----------------------------------------------------------------------------
def screen_z(height = @h)
if iso?
z = (0 + (height * 64))
z = z < 0 ? 0 : z
return z
else
return 0
end
end
#----------------------------------------------------------------------------
# Get the current screen Tile Height
#----------------------------------------------------------------------------
def screen_th
return 0 if !iso?
tile_id = $game_map.map.data[self.ox,self.oy,0]
return 0 if tile_id == nil
t_x = (tile_id - 384) % 8
t_y = (tile_id - 384) / 8
th = t_x + t_y * 8
return th
end
#----------------------------------------------------------------------------
# Update Process
#----------------------------------------------------------------------------
def update
super unless self.disposed?
update_animation
update_bitmap
update_height
update_location
end
#----------------------------------------------------------------------------
# Update animation - used to progress the animation frame index
#----------------------------------------------------------------------------
def update_animation
if @wait != 0
@wait -= 1
if @wait == 0
@wait = 6
#update frame every six updates
@p_index += 1
if @p_index == @pattern.size
@p_index = 0
end
end
end
end
#----------------------------------------------------------------------------
# Updates the height to that of the tile it is over
#----------------------------------------------------------------------------
def update_height
if @h != screen_th
@h = screen_th
end
end
#----------------------------------------------------------------------------
# Update bitmap based on pattern
#----------------------------------------------------------------------------
def update_bitmap
if @anim
sx = @pattern[@p_index] * @cw rescue sx = 0
self.src_rect.set(sx, 0, @cw, @ch)
else #if not using animated tiles, but using ISO, use first frame only.
if iso?
self.src_rect.set(0, 0, @cw, @ch)
end
end
end
#----------------------------------------------------------------------------
# Updates X, Y, Z coords
#----------------------------------------------------------------------------
def update_location
self.x = screen_x unless self.disposed?
self.y = screen_y unless self.disposed?
self.z = screen_z unless self.disposed?
end
end