Animations and Actions Mirroring

So since Witness to Unity uses a “side-view battle system”, it means I need to have animations mirror depending on where they’re coming from. Unfortunately, RPG Maker XP does not even have under the hood ability to understand this, because it was front-view by default. (VXAce meanwhile added some unused variables for scripters to make use of that made this sort of thing easier.)

The current state of my code looks like this. It’s kind of a mess.

# Cycle for hits (from reflect or not)
for target in @target_battlers      
	# Mirror animation
  
  # Note, this is currently set up incorrectly.
  # It relies entirely on the starting x/y of the targets 
  # to presume how to mirror the animations, because there's 
  # no way to get the current x/y from target.
  if item.for_ally? || item.for_dead_ally?
		target.mirror_animation = false
  elsif target.screen_x > Tayruu::SW/2
		# Note: takes current mirror_animation state:
		# If set to true because of reflected skill, this
		# will un-mirror it back.
		#target.mirror_animation = !target.mirror_animation
		target.mirror_animation = true
  else
		target.mirror_animation = false
  end
  # Get animation effect
  target.animation_id = @animation2_id
  target.animation_hit = !target.missed

The problem is that target contains nothing about the current location of a battler’s on-screen sprite. screen_x and screen_y originally defined where a sprite was, but this is only for its initial location on render. This is moot when sprites can move around.

Never mind the fact it's based on whether the (initial) screen_y is past the half-way mark of the screen!

The correct way to do this would be to reference the relative position between the attacker and target, but that’s a bit hard to do when the actual x/y information is stored in Sprite_Battlers, but not the Game_Battlers. The sprites know what their battlers are, but not the other way around — and the battlers are what you're referencing in battle functionality.

So the simple solution? Add a current_x/y variable to Game_Battler which I can update from Sprite_Battler, where the values are in the first place.

# ------------------------------
# In Sprite_Battler:
# ------------------------------

do_tween({:x=>x, :y=>y}, speed)
until @tween.nil?
  [$scene.spriteset, Graphics].each {|a| a.update }
end
# Store current location
@battler.current_x = x
@battler.current_y = y
# Return to normal
@battler.update_animbat_pose if !knockback

# ------------------------------
# In Scene_Battle:
# ------------------------------

# Mirror animation
# For allies, ignore
if item.for_ally? || item.for_dead_ally?
  target.mirror_animation = false
# If attacker is to the left of the target, flip the animation 
elsif @active_battler.current_x <= target.current_x
  target.mirror_animation = true
# Otherwise, leave alone
else
  target.mirror_animation = false
end

While I am now sending this current_x/y to the battler, to be clear again — this information is only referential — it's not used by battlers to then place a sprite on the screen, it's telling the battlers information for the benefit of other functions.