Made multiple special battle animations easier to register

This commit is contained in:
Maruno17
2021-10-10 17:47:08 +01:00
parent 45fd570414
commit 0aad105c6d

View File

@@ -1,3 +1,33 @@
#===============================================================================
#
#===============================================================================
module SpecialBattleIntroAnimations
# [name, priority number, "trigger if" proc, animation proc]
@@anims = []
def self.register(name, priority, condition, hash)
@@anims.push([name, priority, condition, hash])
end
def self.remove(name)
@@anims.delete_if { |anim| anim[0] == name }
end
def self.each
ret = @@anims.sort { |a, b| b[1] <=> a[1] }
ret.each { |anim| yield anim[0], anim[1], anim[2], anim[3] }
end
def self.has?(name)
return @@anims.any? { |anim| anim[0] == name }
end
def self.get(name)
@@anims.each { |anim| return anim if anim[0] == name }
return nil
end
end
#=============================================================================== #===============================================================================
# Battle intro animation # Battle intro animation
#=============================================================================== #===============================================================================
@@ -29,7 +59,12 @@ def pbBattleAnimation(bgm=nil,battletype=0,foe=nil)
bgm = pbGetWildBattleBGM([]) if !bgm bgm = pbGetWildBattleBGM([]) if !bgm
pbBGMPlay(bgm) pbBGMPlay(bgm)
# Check for custom battle intro animations # Check for custom battle intro animations
handled = pbBattleAnimationOverride(viewport,battletype,foe) handled = false
SpecialBattleIntroAnimations.each do |name, priority, condition, animation|
next if !condition.call(battletype, foe)
animation.call(viewport, battletype, foe)
handled = true
end
# Default battle intro animation # Default battle intro animation
if !handled if !handled
# Determine which animation is played # Determine which animation is played
@@ -129,58 +164,83 @@ end
#=============================================================================== #===============================================================================
# Vs. battle intro animation # Vs. battle intro animation
# If you want to add a custom battle intro animation, copy the code below for
# the Vs. animation and adapt it to your own. The register call has 4 arguments:
# 1) The name of the animation. Typically unused, but helps to identify an
# animation.
# 2) The animation's priority. If multiple special animations could trigger
# for the same battle, the one with the highest priority number is used.
# 3) A condition proc which decides whether the animation should trigger.
# 4) The animation itself. Could be a bunch of code, or a call to, say,
# pbCommonEvent(20) or something else. By the end of the animation, the
# screen should be black.
# Note that you can get an image of the current game screen with
# Graphics.snap_to_bitmap.
#=============================================================================== #===============================================================================
def pbBattleAnimationOverride(viewport,battletype=0,foe=nil) ##### VS. animation, by Luka S.J. #####
##### VS. animation, by Luka S.J. ##### ##### Tweaked by Maruno #####
##### Tweaked by Maruno ##### SpecialBattleIntroAnimations.register("vs_animation", 50, # Priority 50
if (battletype==1 || battletype==3) && foe.length==1 # Against single trainer Proc.new { |battle_type, foe| # Condition
next false unless [1, 3].include?(battle_type) && foe.length == 1 # Only if a single trainer
tr_type = foe[0].trainer_type tr_type = foe[0].trainer_type
if tr_type next false if !tr_type
tbargraphic = sprintf("vsBar_%s", tr_type.to_s) rescue nil trainer_bar_graphic = sprintf("vsBar_%s", tr_type.to_s) rescue nil
tgraphic = sprintf("vsTrainer_%s", tr_type.to_s) rescue nil trainer_graphic = sprintf("vsTrainer_%s", tr_type.to_s) rescue nil
if pbResolveBitmap("Graphics/Transitions/" + tbargraphic) && pbResolveBitmap("Graphics/Transitions/" + tgraphic) next pbResolveBitmap("Graphics/Transitions/" + trainer_bar_graphic) &&
pbResolveBitmap("Graphics/Transitions/" + trainer_graphic)
},
Proc.new { |viewport, battle_type, foe| # Animation
# Determine filenames of graphics to be used
tr_type = foe[0].trainer_type
trainer_bar_graphic = sprintf("vsBar_%s", tr_type.to_s) rescue nil
trainer_graphic = sprintf("vsTrainer_%s", tr_type.to_s) rescue nil
player_tr_type = $Trainer.trainer_type player_tr_type = $Trainer.trainer_type
outfit = $Trainer.outfit outfit = $Trainer.outfit
# Set up player_bar_graphic = sprintf("vsBar_%s_%d", player_tr_type.to_s, outfit) rescue nil
viewplayer = Viewport.new(0,Graphics.height/3,Graphics.width/2,128) if !pbResolveBitmap("Graphics/Transitions/" + player_bar_graphic)
player_bar_graphic = sprintf("vsBar_%s", player_tr_type.to_s) rescue nil
end
player_graphic = sprintf("vsTrainer_%s_%d", player_tr_type.to_s, outfit) rescue nil
if !pbResolveBitmap("Graphics/Transitions/" + player_graphic)
player_graphic = sprintf("vsTrainer_%s", player_tr_type.to_s) rescue nil
end
# Set up viewports
viewplayer = Viewport.new(0, Graphics.height / 3, Graphics.width / 2, 128)
viewplayer.z = viewport.z viewplayer.z = viewport.z
viewopp = Viewport.new(Graphics.width/2,Graphics.height/3,Graphics.width/2,128) viewopp = Viewport.new(Graphics.width / 2, Graphics.height / 3, Graphics.width / 2, 128)
viewopp.z = viewport.z viewopp.z = viewport.z
viewvs = Viewport.new(0,0,Graphics.width,Graphics.height) viewvs = Viewport.new(0, 0, Graphics.width, Graphics.height)
viewvs.z = viewport.z viewvs.z = viewport.z
# Set up sprites
fade = Sprite.new(viewport) fade = Sprite.new(viewport)
fade.bitmap = RPG::Cache.transition("vsFlash") fade.bitmap = RPG::Cache.transition("vsFlash")
fade.tone = Tone.new(-255,-255,-255) fade.tone = Tone.new(-255, -255, -255)
fade.opacity = 100 fade.opacity = 100
overlay = Sprite.new(viewport) overlay = Sprite.new(viewport)
overlay.bitmap = Bitmap.new(Graphics.width,Graphics.height) overlay.bitmap = Bitmap.new(Graphics.width, Graphics.height)
pbSetSystemFont(overlay.bitmap) pbSetSystemFont(overlay.bitmap)
pbargraphic = sprintf("vsBar_%s_%d", player_tr_type.to_s, outfit) rescue nil xoffset = ((Graphics.width / 2) / 10) * 10
if !pbResolveBitmap("Graphics/Transitions/" + pbargraphic)
pbargraphic = sprintf("vsBar_%s", player_tr_type.to_s) rescue nil
end
xoffset = ((Graphics.width/2)/10)*10
bar1 = Sprite.new(viewplayer) bar1 = Sprite.new(viewplayer)
bar1.bitmap = RPG::Cache.transition(pbargraphic) bar1.bitmap = RPG::Cache.transition(player_bar_graphic)
bar1.x = -xoffset bar1.x = -xoffset
bar2 = Sprite.new(viewopp) bar2 = Sprite.new(viewopp)
bar2.bitmap = RPG::Cache.transition(tbargraphic) bar2.bitmap = RPG::Cache.transition(trainer_bar_graphic)
bar2.x = xoffset bar2.x = xoffset
vs = Sprite.new(viewvs) vs = Sprite.new(viewvs)
vs.bitmap = RPG::Cache.transition("vs") vs.bitmap = RPG::Cache.transition("vs")
vs.ox = vs.bitmap.width/2 vs.ox = vs.bitmap.width / 2
vs.oy = vs.bitmap.height/2 vs.oy = vs.bitmap.height / 2
vs.x = Graphics.width/2 vs.x = Graphics.width / 2
vs.y = Graphics.height/1.5 vs.y = Graphics.height / 1.5
vs.visible = false vs.visible = false
flash = Sprite.new(viewvs) flash = Sprite.new(viewvs)
flash.bitmap = RPG::Cache.transition("vsFlash") flash.bitmap = RPG::Cache.transition("vsFlash")
flash.opacity = 0 flash.opacity = 0
# Animate bars sliding in from either side # Animate bars sliding in from either side
slideInTime = (Graphics.frame_rate*0.25).floor slideInTime = (Graphics.frame_rate * 0.25).floor
for i in 0...slideInTime for i in 0...slideInTime
bar1.x = xoffset*(i+1-slideInTime)/slideInTime bar1.x = xoffset * (i + 1 - slideInTime) / slideInTime
bar2.x = xoffset*(slideInTime-i-1)/slideInTime bar2.x = xoffset * (slideInTime - i - 1) / slideInTime
pbWait(1) pbWait(1)
end end
bar1.dispose bar1.dispose
@@ -191,29 +251,25 @@ def pbBattleAnimationOverride(viewport,battletype=0,foe=nil)
flash.opacity = 255 flash.opacity = 255
# Replace bar sprites with AnimatedPlanes, set up trainer sprites # Replace bar sprites with AnimatedPlanes, set up trainer sprites
bar1 = AnimatedPlane.new(viewplayer) bar1 = AnimatedPlane.new(viewplayer)
bar1.bitmap = RPG::Cache.transition(pbargraphic) bar1.bitmap = RPG::Cache.transition(player_bar_graphic)
bar2 = AnimatedPlane.new(viewopp) bar2 = AnimatedPlane.new(viewopp)
bar2.bitmap = RPG::Cache.transition(tbargraphic) bar2.bitmap = RPG::Cache.transition(trainer_bar_graphic)
pgraphic = sprintf("vsTrainer_%s_%d", player_tr_type.to_s, outfit) rescue nil
if !pbResolveBitmap("Graphics/Transitions/" + pgraphic)
pgraphic = sprintf("vsTrainer_%s", player_tr_type.to_s) rescue nil
end
player = Sprite.new(viewplayer) player = Sprite.new(viewplayer)
player.bitmap = RPG::Cache.transition(pgraphic) player.bitmap = RPG::Cache.transition(player_graphic)
player.x = -xoffset player.x = -xoffset
trainer = Sprite.new(viewopp) trainer = Sprite.new(viewopp)
trainer.bitmap = RPG::Cache.transition(tgraphic) trainer.bitmap = RPG::Cache.transition(trainer_graphic)
trainer.x = xoffset trainer.x = xoffset
trainer.tone = Tone.new(-255,-255,-255) trainer.tone = Tone.new(-255, -255, -255)
# Dim the flash and make the trainer sprites appear, while animating bars # Dim the flash and make the trainer sprites appear, while animating bars
animTime = (Graphics.frame_rate*1.2).floor animTime = (Graphics.frame_rate * 1.2).floor
for i in 0...animTime for i in 0...animTime
flash.opacity -= 52*20/Graphics.frame_rate if flash.opacity>0 flash.opacity -= 52 * 20 / Graphics.frame_rate if flash.opacity > 0
bar1.ox -= 32*20/Graphics.frame_rate bar1.ox -= 32 * 20 / Graphics.frame_rate
bar2.ox += 32*20/Graphics.frame_rate bar2.ox += 32 * 20 / Graphics.frame_rate
if i>=animTime/2 && i<slideInTime+animTime/2 if i >= animTime / 2 && i < slideInTime + animTime / 2
player.x = xoffset*(i+1-slideInTime-animTime/2)/slideInTime player.x = xoffset * (i + 1 - slideInTime - animTime / 2) / slideInTime
trainer.x = xoffset*(slideInTime-i-1+animTime/2)/slideInTime trainer.x = xoffset * (slideInTime - i - 1 + animTime / 2) / slideInTime
end end
pbWait(1) pbWait(1)
end end
@@ -224,42 +280,42 @@ def pbBattleAnimationOverride(viewport,battletype=0,foe=nil)
pbSEPlay("Vs sword") pbSEPlay("Vs sword")
# Make the Vs logo and trainer names appear, and reset trainer's tone # Make the Vs logo and trainer names appear, and reset trainer's tone
vs.visible = true vs.visible = true
trainer.tone = Tone.new(0,0,0) trainer.tone = Tone.new(0, 0, 0)
trainername = foe[0].name trainername = foe[0].name
textpos = [ textpos = [
[$Trainer.name,Graphics.width/4,(Graphics.height/1.5)+4,2, [$Trainer.name, Graphics.width / 4, (Graphics.height / 1.5) + 4, 2,
Color.new(248,248,248),Color.new(12*6,12*6,12*6)], Color.new(248, 248, 248), Color.new(72, 72, 72)],
[trainername,(Graphics.width/4)+(Graphics.width/2),(Graphics.height/1.5)+4,2, [trainername, (Graphics.width / 4) + (Graphics.width / 2), (Graphics.height / 1.5) + 4, 2,
Color.new(248,248,248),Color.new(12*6,12*6,12*6)] Color.new(248, 248, 248), Color.new(72, 72, 72)]
] ]
pbDrawTextPositions(overlay.bitmap,textpos) pbDrawTextPositions(overlay.bitmap, textpos)
# Fade out flash, shudder Vs logo and expand it, and then fade to black # Fade out flash, shudder Vs logo and expand it, and then fade to black
animTime = (Graphics.frame_rate*2.75).floor animTime = (Graphics.frame_rate * 2.75).floor
shudderTime = (Graphics.frame_rate*1.75).floor shudderTime = (Graphics.frame_rate * 1.75).floor
zoomTime = (Graphics.frame_rate*2.5).floor zoomTime = (Graphics.frame_rate * 2.5).floor
shudderDelta = [4*20/Graphics.frame_rate,1].max shudderDelta = [4 * 20 / Graphics.frame_rate, 1].max
for i in 0...animTime for i in 0...animTime
if i<shudderTime # Fade out the white flash if i < shudderTime # Fade out the white flash
flash.opacity -= 52*20/Graphics.frame_rate if flash.opacity>0 flash.opacity -= 52 * 20 / Graphics.frame_rate if flash.opacity > 0
elsif i==shudderTime # Make the flash black elsif i == shudderTime # Make the flash black
flash.tone = Tone.new(-255,-255,-255) flash.tone = Tone.new(-255, -255, -255)
elsif i>=zoomTime # Fade to black elsif i >= zoomTime # Fade to black
flash.opacity += 52*20/Graphics.frame_rate if flash.opacity<255 flash.opacity += 52 * 20 / Graphics.frame_rate if flash.opacity < 255
end end
bar1.ox -= 32*20/Graphics.frame_rate bar1.ox -= 32 * 20 / Graphics.frame_rate
bar2.ox += 32*20/Graphics.frame_rate bar2.ox += 32 * 20 / Graphics.frame_rate
if i<shudderTime if i < shudderTime
j = i%(2*Graphics.frame_rate/20) j = i % (2 * Graphics.frame_rate / 20)
if j>=0.5*Graphics.frame_rate/20 && j<1.5*Graphics.frame_rate/20 if j >= 0.5 * Graphics.frame_rate / 20 && j < 1.5 * Graphics.frame_rate / 20
vs.x += shudderDelta vs.x += shudderDelta
vs.y -= shudderDelta vs.y -= shudderDelta
else else
vs.x -= shudderDelta vs.x -= shudderDelta
vs.y += shudderDelta vs.y += shudderDelta
end end
elsif i<zoomTime elsif i < zoomTime
vs.zoom_x += 0.4*20/Graphics.frame_rate vs.zoom_x += 0.4 * 20 / Graphics.frame_rate
vs.zoom_y += 0.4*20/Graphics.frame_rate vs.zoom_y += 0.4 * 20 / Graphics.frame_rate
end end
pbWait(1) pbWait(1)
end end
@@ -275,38 +331,6 @@ def pbBattleAnimationOverride(viewport,battletype=0,foe=nil)
viewvs.dispose viewvs.dispose
viewopp.dispose viewopp.dispose
viewplayer.dispose viewplayer.dispose
viewport.color = Color.new(0,0,0,255) viewport.color = Color.new(0, 0, 0, 255)
return true }
end )
end
end
return false
end
#===============================================================================
# Override battle intro animation
#===============================================================================
# If you want to add a custom battle intro animation, copy the following alias
# line and method into a new script section. Change the name of the alias part
# ("__over1__") in your copied code in both places. Then add in your custom
# transition code in the place shown.
# Note that you can get an image of the current game screen with
# Graphics.snap_to_bitmap.
# When the custom animation has finished, the screen should have faded to black
# somehow.
alias __over1__pbBattleAnimationOverride pbBattleAnimationOverride
def pbBattleAnimationOverride(viewport,battletype=0,foe=nil)
# The following example runs a common event that ought to do a custom
# animation if some condition is true:
#
# if $game_map.map_id==20 # If on map 20
# pbCommonEvent(20)
# return true # Note that the battle animation is done
# end
#
# The following line needs to call the aliased method if the custom transition
# animation was NOT shown.
return __over1__pbBattleAnimationOverride(viewport,battletype,foe)
end