Hi, everyone, I've loved VXA and all its quirks since it came out, and I'm happy to see there are still semi-regular posts in this board. I'm an inexperienced scripter, and I'd like to get some feedback on the code that I wrote to enhance Victor's Fog and Overlay for the Victor Engine.
The goal in this is to provide two new features.
Another feature I'm considering adding is an "Anchored" status, for fogs like trees or pillars coming out of the ground, where the player is supposed to be in front of them or behind them depending on where the player is (Probably only useful for people who are using tall sprites).
I've read that a lot of scripters don't like touching Victor's code, but Fog and Overlay has great performance and configurations, and it seems like a lot of people have used it throughout the history of the forum. I'm hoping there will be someone who can give me some perspective on whether the code I wrote is worth sharing in the completed scripts board or if it still needs work.
Also, I don't really know the scripting culture of the forum, so if I'm doing something crazy, please tell me, haha.
Prereqs:
Other Credit:
Fog and Overlay has a bug when the player transfers to a different location on a map they're already on. I tried for a long time to fix it myself, but only got 90% of the way there and gave up. Luckily, Source already fixed it ages ago. I've included that bug fix in my script.
The goal in this is to provide two new features.
- Add x and y offsets to give more control over where fog planes get displayed on a map.
- Add a "sprite" mode for some fog planes, where you can provide a smaller singular sprite image, and it will automatically get turned into a plane the size of the map. (Good for providing fine-tuned control and reusability of specific overlay elements)
Ruby:
#==============================================================================
# ** Gaydarade - VE: Overlay+
#------------------------------------------------------------------------------
# Author : Gaydarade
# Credit to: RPGM Source - For Game_Player.perform_transfer fix
#
# Version History:
# v 0.90 - 2023.12.24 > Pre-release
#------------------------------------------------------------------------------
# This script adds two new functions to Fog and Overlay, to provide parallax
# mappers more fine-tuned control of overlays.
# 1. Provide x and y offsets, for control over where overlays start.
# 2. Toggle an overlay's "Sprite" status, when the overlay image is smaller
# than the size of the map.
# Used together, these features can break parallaxes into separate elements
# for fine-tuned control over special parts of your overlay.
#------------------------------------------------------------------------------
# Compatibility
# Requires the script 'Victor Engine - Basic Module' v 1.27 or higher,
# and 'Victor Engine - Fog and Overlay' v 1.12
#
# * Overwrite methods
# class Game_Map
# def setup_fog
#
# class Game_Fog
# def show
#
# class Sprite_Fog < Plane
# def update_bitmap
#
#
# * Alias methods
# class Game_Player
# def perform_transfer
#
# class Game_Fog
# def init_basic
#
# class Sprite_Fog < Plane
# def update_position
#
#
# * New public Instance Variables
# class Game_Fog
# :sprite, :xoff, :yoff
#
#------------------------------------------------------------------------------
# Instructions:
# Open your script editor and insert this script under Materials,
# directly below 'Victor - Fog and Overlays'
#
#------------------------------------------------------------------------------
# Maps and Comment calls note tags:
# New settings to add to <fog effect> tags
#
# <fog effect>
# settings
# </fog effect>
# All values are optional. Offsets default to 0, sprite defaults to false.
# xoffset: x : fog x offset, increase to move image right
# yoffset: x : fog y offset, increase to move image down
# sprite: true : set true if fog image is smaller than maparea
#
#------------------------------------------------------------------------------
# Additional instructions:
#
# This add-on includes RPGM Source's map transfer bug fix. If you already
# have that script in your project, please remove it when adding this.
#
#==============================================================================
#==============================================================================
#
# Don't edit anything beyond this point, unless you intend to go anarchy mode.
#
#==============================================================================
#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
# This class handles the player. It includes event starting determinants and
# map scrolling functions. The instance of this class is referenced by
# $game_player.
#==============================================================================
class Game_Player < Game_Character #RPGM Source's code
#--------------------------------------------------------------------------
# * Alias Execute Player Transfer. [NEW]
#--------------------------------------------------------------------------
alias_method(:vf_transfer_fix_original_perform_transfer, :perform_transfer)
#--------------------------------------------------------------------------
# * Execute Player Transfer. [MOD]
#--------------------------------------------------------------------------
def perform_transfer
return unless transfer?
last_dx = $game_map.display_x
last_dy = $game_map.display_y
vf_transfer_fix_original_perform_transfer
$game_map.fog_x += $game_map.display_x - last_dx
$game_map.fog_y += $game_map.display_y - last_dy
end
end #End RPGM Source's code
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# This class handles maps. It includes scrolling and passage determination
# functions. The instance of this class is referenced by $game_map.
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# * Overwrite method: setup_fog
#--------------------------------------------------------------------------
def setup_fog(info)
id = info =~ /ID: (\d+)/i ? $1.to_i : 0
name = info =~ /NAME: #{get_filename}/i ? $1.dup : ""
op = info =~ /OPACITY: (\d+)/i ? $1.to_i : 255
move = info =~ /MOVE: (\d+)/i ? $1.to_i : 32
zoom = info =~ /ZOOM: (\d+)/i ? $1.to_f : 100.0
hue = info =~ /HUE: (\d+)/i ? $1.to_i : 0
blend = info =~ /BLEND: (\d+)/i ? $1.to_i : 0
depth = info =~ /DEPTH: ([+-]?\d+)/i ? $1.to_i : 300
xoff = info =~ /XOFFSET: ([+-]?\d+)/i ? $1.to_i : 0
yoff = info =~ /YOFFSET: ([+-]?\d+)/i ? $1.to_i : 0
sprite = info =~ /SPRITE: (true|false)/i ? ($1 == "true") : false
@screen.create_fog(id, name, op, move, zoom, hue, sprite, blend, xoff, yoff, depth)
end
end
#==============================================================================
# ** Game_Fog
#------------------------------------------------------------------------------
# This class handles fog data. This class is used within the Game_Fogs class.
#==============================================================================
class Game_Fog
#--------------------------------------------------------------------------
# * New public Instance Variables
#--------------------------------------------------------------------------
attr_reader :sprite, :xoff, :yoff
#--------------------------------------------------------------------------
# * alias method: init_basic
#--------------------------------------------------------------------------
alias :overlay_extender_init_basic :init_basic
def init_basic
overlay_extender_init_basic
@sprite = false
end
#--------------------------------------------------------------------------
# * overwrite method: show
#--------------------------------------------------------------------------
def show(id, name, opacity, move, zoom, hue, sprite, blend, xoff, yoff, depth)
@id = id
@name = name
@move = move
@zoom_x = zoom.to_f
@zoom_y = zoom.to_f
@depth = depth
@opacity = opacity.to_f
@blend_type = blend
@ox = 0
@oy = 0
@xoff = xoff
@yoff = yoff
@sprite = sprite
init_target
init_tone
end
end
#==============================================================================
# ** Sprite_Fog
#------------------------------------------------------------------------------
# This sprite is used to display fogs. It observes a instance of the
# Game_Fog class and automatically changes sprite conditions.
#==============================================================================
class Sprite_Fog < Plane
#--------------------------------------------------------------------------
# * overwrite method: update bitmap
#--------------------------------------------------------------------------
def update_bitmap
if @fog_name != @fog.name
src = Cache.fogs(@fog.name)
if @fog.sprite == true
maparea = Bitmap.new($game_map.width * 32, $game_map.height * 32)
maparea.blt(0,src.height % 32, src, src.rect)
self.bitmap = maparea
else
self.bitmap = src
end
@fog_name = @fog.name.dup
end
end
#--------------------------------------------------------------------------
# * Alias: update_position
#--------------------------------------------------------------------------
alias :overlay_extender_update_position :update_position
def update_position
overlay_extender_update_position
self.ox -= (32 * @fog.xoff)
self.oy -= (32 * @fog.yoff)
end
end
Another feature I'm considering adding is an "Anchored" status, for fogs like trees or pillars coming out of the ground, where the player is supposed to be in front of them or behind them depending on where the player is (Probably only useful for people who are using tall sprites).
I've read that a lot of scripters don't like touching Victor's code, but Fog and Overlay has great performance and configurations, and it seems like a lot of people have used it throughout the history of the forum. I'm hoping there will be someone who can give me some perspective on whether the code I wrote is worth sharing in the completed scripts board or if it still needs work.
Also, I don't really know the scripting culture of the forum, so if I'm doing something crazy, please tell me, haha.
Prereqs:
Other Credit:
Fog and Overlay has a bug when the player transfers to a different location on a map they're already on. I tried for a long time to fix it myself, but only got 90% of the way there and gave up. Luckily, Source already fixed it ages ago. I've included that bug fix in my script.