## Eventing: Fine Tuning v3.1 ##
# Fine tune the x-y position, zoom, rotation, hue, as well as mirror and
# flash event's sprites!
#
# Usage: All script calls are made with set move route
# offset(x,y) within set move route x and y are equal to
# the number of pixels to be offset
#
# set_zoom(zoom) where zoom is a number
#
#
#
# blend(color) where color is a color object
# -> Color.new(red,blue,green,alpha)
#
#
#
# flash(color,duration) where color is a color object and duration
# is the length of the flash
#
# slide(x, y) offsets the sprite, but moves them to the
# position instead of transfering
#
# waypoint(x,y) will cause the character to head towards the
# specified point. Next command starts after
# point is reached.
#
# moveto(x,y) Not actually a new command, but one that is
# nice to know, transfers event to specified
# point.
#
# New Commands:
# @shakechar has been changed to offset
# @zoom has been changed to set_zoom
# (The old commands will still work)
#
# fadein Fades the character to 255 opacity based
# fadein(duration) on duration. Default of 10 frames.
#
# fadeout Fades the character to 0 opacity based
# fadeout(duration) on duration. Default of 10 frames.
#
# shake Shakes the sprite, default duration of 30
# shake(duration) frames.
#
# random Moves the character to a random location
# random(width,height) on the map. Can specify maximum range.
#
# random_region(id) Moves the character to a random location on
# random_region(id,w,h) the map with the same region. Can specify
# maximum range.
#
# self_switch("letter",value) Sets the self switch of the event. Letter is
# "A" to "D", value is true or false.
#
# balloon(id) Plays the specific balloon animation on the
# char
#
#
#------#
#-- Script by: V.M of D.T
#
#- Questions or comments can be:
# posted on the thread for the script
# given by email:
sumptuaryspade@live.ca
# provided on facebook:
http://www.facebook.com/DaimoniousTailsGames
#
#- Free to use in any project with credit given,
#-- donations always welcome via paypal!
class Game_CharacterBase
alias shake_init_public_members init_public_members
alias shake_update update
attr_accessor :zoom
attr_accessor :flash_on
attr_accessor :flash_color
attr_accessor :flash_time
attr_accessor :angle
attr_accessor :need_rotate
def init_public_members
shake_init_public_members
reset_event_details
end
def reset_event_details
@shakechar = [false, 0, 0]
@zoom = 1
@flash_on = false
@flash_color = Color.new(0,0,0,0)
@flash_duration = 0
@angle = 0
@total_angle = 0
@need_rotate = false
@Fade = @opacity
@fade_time = 0
@shake_time = 0
@shake_direction = 0
end
def offset(x,y); @shakechar = [true, x, y]; end
def reset
reset_event_details
rotate(@total_angle*-1)
end
def set_zoom(size); @zoom = size; end
def flash(color,duration)
@flash_color = color
@flash_time = duration
@flash_on = true
end
def rotate(angle)
@total_angle += angle
@angle = angle
@need_rotate = true
end
def rotateoff; @need_rotate = false; end
def flashoff; @flash_on = false; end
def blend(color); @blend_color = color; end
def screen_x
if @shakechar[0] == false || @shakechar[1] == nil then
$game_map.adjust_x(@real_x) * 32 + 16 else
$game_map.adjust_x(@real_x) * 32 + 16 + @shakechar[1] end
end
def screen_y
if @shakechar[0] == false || @shakechar[2] == nil then
$game_map.adjust_y(@real_y) * 32 + 32 - shift_y - jump_height else
$game_map.adjust_y(@real_y) * 32 + 32 - shift_y - jump_height + @shakechar[2] end
end
def slide(x, y)
@next_x = x + @shakechar[1]
@next_y = y + @shakechar[2]
@step_anime = true
@shakechar[0] = true
@sliding = true
end
def fadein(time = 10)
@fade_time = time
@Fade = 255
end
def fadeout(time = 10)
@fade_time = time
@Fade = 0
end
def shake(time = 30)
@shakechar[0] = true
@shake_time = time
end
def random(rect_x = 250, rect_y = 250)
tiles = []
tiles = tile_array(rect_x,rect_y)
tiles = tiles.compact
return if tiles.empty?
tile = rand(tiles.size)
moveto(tiles[tile][0],tiles[tile][1])
end
def random_region(id, rect_x = 250, rect_y = 250)
tiles = tile_array(rect_x,rect_y)
tiles.each_index do |i|
next if tiles
.nil?
erase = false
erase = true unless $game_map.region_id(tiles[0], tiles[1]) == id
tiles = nil if erase
end
tiles = tiles.compact
return if tiles.empty?
tile = rand(tiles.size)
moveto(tiles[tile][0],tiles[tile][1])
end
def tile_array(rect_x,rect_y)
tiles = [];nx = 0;ny = 0
($game_map.width * $game_map.height).times do |i|
tiles.push([nx,ny])
nx += 1
if nx == $game_map.width
nx = 0
ny += 1
end
end
tiles.each_index do |i|
erase = false
erase = true if tiles[0] == $game_player.x && tiles[1] == $game_player.y
erase = true if tiles[0] == x && tiles[1] == y
erase = true if tiles[0] > x + rect_x || tiles[0] < x - rect_x
erase = true if tiles[1] > y + rect_y || tiles[1] < y - rect_y
erase = true if !$game_map.check_passage(tiles[0], tiles[1], 0x0f)
tiles = nil if erase
end
return tiles
end
def self_switch(symbol, boolean)
return if !self.is_a?(Game_Event)
key = [$game_map.map_id, self.event.id, symbol]
$game_self_switches[key] = boolean
end
def balloon(id)
@balloon_id = id
end
def update
shake_update
update_sliding if @sliding
update_fading if @opacity != @Fade && @fade_time > 0
update_shake if @shake_time > 0
end
def update_fading
@opacity += (255 / @fade_time) if @Fade > @opacity
@opacity -= (255 / @fade_time) if @Fade < @opacity
@opacity = 0 if @opacity < 0; @opacity = 255 if @opacity > 255
@fade_time = 0 if @opacity == 0 || @opacity == 255
end
def update_sliding
@shakechar[1] += 0.5 if @next_x > @shakechar[1]
@shakechar[1] -= 0.5 if @next_x < @shakechar[1]
@shakechar[2] += 0.5 if @next_y > @shakechar[2]
@shakechar[2] -= 0.5 if @next_y < @shakechar[2]
return unless @shakechar[1] == @next_x
return unless @shakechar[2] == @next_y
@sliding = false
@step_anime = false
end
def update_shake
@shake_time -= 1
@shakechar[2] += 1 if @shake_direction == 0
@shakechar[2] -= 1 if @shake_direction == 1
if @shake_time % 3 == 0
@shake_direction += 1
@shake_direction = 0 if @shake_direction > 1
end
end
end
class Game_Character
alias eft_init_private_members init_private_members
def init_private_members
eft_init_private_members
@waypoint = [-1,-1]
end
def update_routine_move
if @wait_count > 0
@wait_count -= 1
else
@move_succeed = true
command = @move_route.list[@move_route_index]
if command
if @waypoint[0] != -1
process_waypoint_command
advance_waypoint_route_index
else
process_move_command(command)
advance_move_route_index
end
end
end
end
def process_waypoint_command
sx = distance_x_from(@waypoint[0])
sy = distance_y_from(@waypoint[1])
if sx.abs > sy.abs
move_straight(sx > 0 ? 4 : 6)
move_straight(sy > 0 ? 8 : 2) if !@move_succeed && sy != 0
elsif sy != 0
move_straight(sy > 0 ? 8 : 2)
move_straight(sx > 0 ? 4 : 6) if !@move_succeed && sx != 0
end
@waypoint = [-1,-1] if !@move_succeed && @move_route.skippable
end
def advance_waypoint_route_index
return unless @x == @waypoint[0]
return unless @y == @waypoint[1]
@waypoint = [-1,-1]
end
def waypoint(x,y); @waypoint = [x,y]; end
end
class Sprite_Character
alias eventfp_update update
def update
eventfp_update
zoom_update
rotate_update if @character.need_rotate
flash_update if @character.flash_on
end
def blend_update; self.color = @character.blend_color; end
def zoom_update
self.zoom_y = @character.zoom
self.zoom_x = @character.zoom
end
def flash_update
flash(@character.flash_color,@character.flash_time)
@character.flashoff
end
def rotate_update
self.angle = @character.angle
@character.rotateoff
end
end