#=============================================================================== # Battle start animation #=============================================================================== def pbSceneStandby $scene.disposeSpritesets if $scene && $scene.is_a?(Scene_Map) GC.start Graphics.frame_reset yield $scene.createSpritesets if $scene && $scene.is_a?(Scene_Map) end def pbBattleAnimation(bgm=nil,battletype=0,foe=nil) $game_temp.in_battle = true viewport = Viewport.new(0,0,Graphics.width,Graphics.height) viewport.z = 99999 # Set up audio playingBGS = nil playingBGM = nil if $game_system && $game_system.is_a?(Game_System) playingBGS = $game_system.getPlayingBGS playingBGM = $game_system.getPlayingBGM $game_system.bgm_pause $game_system.bgs_pause end pbMEFade(0.25) pbWait(Graphics.frame_rate/4) pbMEStop # Play battle music bgm = pbGetWildBattleBGM([0]) if !bgm pbBGMPlay(bgm) # Take screenshot of game, for use in some animations $game_temp.background_bitmap.dispose if $game_temp.background_bitmap $game_temp.background_bitmap = Graphics.snap_to_bitmap # Check for custom battle intro animations handled = pbBattleAnimationOverride(viewport,battletype,foe) # Default battle intro animation if !handled # Determine which animation is played location = 0 # 0=outside, 1=inside, 2=cave, 3=water if $PokemonGlobal.surfing || $PokemonGlobal.diving location = 3 elsif $PokemonTemp.encounterType && ($PokemonTemp.encounterType==EncounterTypes::OldRod || $PokemonTemp.encounterType==EncounterTypes::GoodRod || $PokemonTemp.encounterType==EncounterTypes::SuperRod) location = 3 elsif $PokemonEncounters.has_cave_encounters? location = 2 elsif !GameData::MapMetadata.exists?($game_map.map_id) || !GameData::MapMetadata.get($game_map.map_id).outdoor_map location = 1 end anim = "" if PBDayNight.isDay? case battletype when 0, 2 # Wild, double wild anim = ["SnakeSquares","DiagonalBubbleTL","DiagonalBubbleBR","RisingSplash"][location] when 1 # Trainer anim = ["TwoBallPass","ThreeBallDown","BallDown","WavyThreeBallUp"][location] when 3 # Double trainer anim = "FourBallBurst" end else case battletype when 0, 2 # Wild, double wild anim = ["SnakeSquares","DiagonalBubbleBR","DiagonalBubbleBR","RisingSplash"][location] when 1 # Trainer anim = ["SpinBallSplit","BallDown","BallDown","WavySpinBall"][location] when 3 # Double trainer anim = "FourBallBurst" end end # Initial screen flashing if location==2 || PBDayNight.isNight? viewport.color = Color.new(0,0,0) # Fade to black a few times else viewport.color = Color.new(255,255,255) # Fade to white a few times end halfFlashTime = Graphics.frame_rate*2/10 # 0.2 seconds, 8 frames alphaDiff = (255.0/halfFlashTime).ceil 2.times do viewport.color.alpha = 0 for i in 0...halfFlashTime*2 if i0 bar1.ox -= 32*20/Graphics.frame_rate bar2.ox += 32*20/Graphics.frame_rate if i>=animTime/2 && i0 elsif i==shudderTime # Make the flash black flash.tone = Tone.new(-255,-255,-255) elsif i>=zoomTime # Fade to black flash.opacity += 52*20/Graphics.frame_rate if flash.opacity<255 end bar1.ox -= 32*20/Graphics.frame_rate bar2.ox += 32*20/Graphics.frame_rate if i=0.5*Graphics.frame_rate/20 && j<1.5*Graphics.frame_rate/20 vs.x += shudderDelta vs.y -= shudderDelta else vs.x -= shudderDelta vs.y += shudderDelta end elsif i80 @window.y -= 4 @window.dispose if @window.y+@window.height<0 else @window.y += 4 if @window.y<0 @frames += 1 end end end #=============================================================================== # Visibility circle in dark maps #=============================================================================== class DarknessSprite < SpriteWrapper attr_reader :radius def initialize(viewport=nil) super(viewport) @darkness = BitmapWrapper.new(Graphics.width,Graphics.height) @radius = radiusMin self.bitmap = @darkness self.z = 99998 refresh end def dispose @darkness.dispose super end def radiusMin; return 64; end # Before using Flash def radiusMax; return 176; end # After using Flash def radius=(value) @radius = value refresh end def refresh @darkness.fill_rect(0,0,Graphics.width,Graphics.height,Color.new(0,0,0,255)) cx = Graphics.width/2 cy = Graphics.height/2 cradius = @radius numfades = 5 for i in 1..numfades for j in cx-cradius..cx+cradius diff2 = (cradius * cradius) - ((j - cx) * (j - cx)) diff = Math.sqrt(diff2) @darkness.fill_rect(j,cy-diff,1,diff*2,Color.new(0,0,0,255.0*(numfades-i)/numfades)) end cradius = (cradius*0.9).floor end end end #=============================================================================== # Lights #=============================================================================== class LightEffect def initialize(event,viewport=nil,map=nil,filename=nil) @light = IconSprite.new(0,0,viewport) if filename!=nil && filename!="" && pbResolveBitmap("Graphics/Pictures/"+filename) @light.setBitmap("Graphics/Pictures/"+filename) else @light.setBitmap("Graphics/Pictures/LE") end @light.z = 1000 @event = event @map = (map) ? map : $game_map @disposed = false end def disposed? return @disposed end def dispose @light.dispose @map = nil @event = nil @disposed = true end def update @light.update end end class LightEffect_Lamp < LightEffect def initialize(event,viewport=nil,map=nil) lamp = AnimatedBitmap.new("Graphics/Pictures/LE") @light = Sprite.new(viewport) @light.bitmap = Bitmap.new(128,64) src_rect = Rect.new(0, 0, 64, 64) @light.bitmap.blt(0, 0, lamp.bitmap, src_rect) @light.bitmap.blt(20, 0, lamp.bitmap, src_rect) @light.visible = true @light.z = 1000 lamp.dispose @map = (map) ? map : $game_map @event = event end end class LightEffect_Basic < LightEffect def update return if !@light || !@event super @light.opacity = 100 @light.ox = 32 @light.oy = 48 if (Object.const_defined?(:ScreenPosHelper) rescue false) @light.x = ScreenPosHelper.pbScreenX(@event) @light.y = ScreenPosHelper.pbScreenY(@event) @light.zoom_x = ScreenPosHelper.pbScreenZoomX(@event) else @light.x = @event.screen_x @light.y = @event.screen_y @light.zoom_x = 1.0 end @light.zoom_y = @light.zoom_x @light.tone = $game_screen.tone end end class LightEffect_DayNight < LightEffect def update return if !@light || !@event super shade = PBDayNight.getShade if shade>=144 # If light enough, call it fully day shade = 255 elsif shade<=64 # If dark enough, call it fully night shade = 0 else shade = 255-(255*(144-shade)/(144-64)) end @light.opacity = 255-shade if @light.opacity>0 @light.ox = 32 @light.oy = 48 if (Object.const_defined?(:ScreenPosHelper) rescue false) @light.x = ScreenPosHelper.pbScreenX(@event) @light.y = ScreenPosHelper.pbScreenY(@event) @light.zoom_x = ScreenPosHelper.pbScreenZoomX(@event) @light.zoom_y = ScreenPosHelper.pbScreenZoomY(@event) else @light.x = @event.screen_x @light.y = @event.screen_y @light.zoom_x = 1.0 @light.zoom_y = 1.0 end @light.tone.set($game_screen.tone.red, $game_screen.tone.green, $game_screen.tone.blue, $game_screen.tone.gray) end end end Events.onSpritesetCreate += proc { |_sender,e| spriteset = e[0] # Spriteset being created viewport = e[1] # Viewport used for tilemap and characters map = spriteset.map # Map associated with the spriteset (not necessarily the current map) for i in map.events.keys if map.events[i].name[/^outdoorlight\((\w+)\)$/i] filename = $~[1].to_s spriteset.addUserSprite(LightEffect_DayNight.new(map.events[i],viewport,map,filename)) elsif map.events[i].name.downcase=="outdoorlight" spriteset.addUserSprite(LightEffect_DayNight.new(map.events[i],viewport,map)) elsif map.events[i].name[/^light\((\w+)\)$/i] filename = $~[1].to_s spriteset.addUserSprite(LightEffect_Basic.new(map.events[i],viewport,map,filename)) elsif map.events[i].name.downcase=="light" spriteset.addUserSprite(LightEffect_Basic.new(map.events[i],viewport,map)) end end spriteset.addUserSprite(Particle_Engine.new(viewport,map)) } #=============================================================================== # Entering/exiting cave animations #=============================================================================== def pbCaveEntranceEx(exiting) # Create bitmap sprite = BitmapSprite.new(Graphics.width,Graphics.height) sprite.z = 100000 # Define values used for the animation totalFrames = (Graphics.frame_rate*0.4).floor increment = (255.0/totalFrames).ceil totalBands = 15 bandheight = ((Graphics.height/2.0)-10)/totalBands bandwidth = ((Graphics.width/2.0)-12)/totalBands # Create initial array of band colors (black if exiting, white if entering) grays = Array.new(totalBands) { |i| (exiting) ? 0 : 255 } # Animate bands changing color totalFrames.times do |j| x = 0 y = 0 # Calculate color of each band for k in 0...totalBands next if k>=totalBands*j/totalFrames inc = increment inc *= -1 if exiting grays[k] -= inc grays[k] = 0 if grays[k]<0 end # Draw gray rectangles rectwidth = Graphics.width rectheight = Graphics.height for i in 0...totalBands currentGray = grays[i] sprite.bitmap.fill_rect(Rect.new(x,y,rectwidth,rectheight), Color.new(currentGray,currentGray,currentGray)) x += bandwidth y += bandheight rectwidth -= bandwidth*2 rectheight -= bandheight*2 end Graphics.update Input.update end # Set the tone at end of band animation if exiting pbToneChangeAll(Tone.new(255,255,255),0) else pbToneChangeAll(Tone.new(-255,-255,-255),0) end # Animate fade to white (if exiting) or black (if entering) for j in 0...totalFrames if exiting sprite.color = Color.new(255,255,255,j*increment) else sprite.color = Color.new(0,0,0,j*increment) end Graphics.update Input.update end # Set the tone at end of fading animation pbToneChangeAll(Tone.new(0,0,0),8) # Pause briefly (Graphics.frame_rate/10).times do Graphics.update Input.update end sprite.dispose end def pbCaveEntrance pbSetEscapePoint pbCaveEntranceEx(false) end def pbCaveExit pbEraseEscapePoint pbCaveEntranceEx(true) end #=============================================================================== # Blacking out animation #=============================================================================== def pbRxdataExists?(file) return pbRgssExists?(file+".rxdata") end def pbStartOver(gameover=false) if pbInBugContest? pbBugContestStartOver return end $Trainer.heal_party if $PokemonGlobal.pokecenterMapId && $PokemonGlobal.pokecenterMapId>=0 if gameover pbMessage(_INTL("\\w[]\\wm\\c[8]\\l[3]After the unfortunate defeat, you scurry back to a Pokémon Center.")) else pbMessage(_INTL("\\w[]\\wm\\c[8]\\l[3]You scurry back to a Pokémon Center, protecting your exhausted Pokémon from any further harm...")) end pbCancelVehicles pbRemoveDependencies $game_switches[Settings::STARTING_OVER_SWITCH] = true $game_temp.player_new_map_id = $PokemonGlobal.pokecenterMapId $game_temp.player_new_x = $PokemonGlobal.pokecenterX $game_temp.player_new_y = $PokemonGlobal.pokecenterY $game_temp.player_new_direction = $PokemonGlobal.pokecenterDirection $scene.transfer_player if $scene.is_a?(Scene_Map) $game_map.refresh else homedata = GameData::Metadata.get.home if homedata && !pbRxdataExists?(sprintf("Data/Map%03d",homedata[0])) if $DEBUG pbMessage(_ISPRINTF("Can't find the map 'Map{1:03d}' in the Data folder. The game will resume at the player's position.",homedata[0])) end $Trainer.heal_party return end if gameover pbMessage(_INTL("\\w[]\\wm\\c[8]\\l[3]After the unfortunate defeat, you scurry back home.")) else pbMessage(_INTL("\\w[]\\wm\\c[8]\\l[3]You scurry back home, protecting your exhausted Pokémon from any further harm...")) end if homedata pbCancelVehicles pbRemoveDependencies $game_switches[Settings::STARTING_OVER_SWITCH] = true $game_temp.player_new_map_id = homedata[0] $game_temp.player_new_x = homedata[1] $game_temp.player_new_y = homedata[2] $game_temp.player_new_direction = homedata[3] $scene.transfer_player if $scene.is_a?(Scene_Map) $game_map.refresh else $Trainer.heal_party end end pbEraseEscapePoint end #=============================================================================== # Various other screen effects #=============================================================================== def pbToneChangeAll(tone,duration) $game_screen.start_tone_change(tone,duration*Graphics.frame_rate/20) for picture in $game_screen.pictures picture.start_tone_change(tone,duration*Graphics.frame_rate/20) if picture end end def pbShake(power,speed,frames) $game_screen.start_shake(power,speed,frames*Graphics.frame_rate/20) end def pbFlash(color,frames) $game_screen.start_flash(color,frames*Graphics.frame_rate/20) end def pbScrollMap(direction,distance,speed) if speed==0 case direction when 2 then $game_map.scroll_down(distance * Game_Map::REAL_RES_Y) when 4 then $game_map.scroll_left(distance * Game_Map::REAL_RES_X) when 6 then $game_map.scroll_right(distance * Game_Map::REAL_RES_X) when 8 then $game_map.scroll_up(distance * Game_Map::REAL_RES_Y) end else $game_map.start_scroll(direction, distance, speed) oldx = $game_map.display_x oldy = $game_map.display_y loop do Graphics.update Input.update break if !$game_map.scrolling? pbUpdateSceneMap break if $game_map.display_x==oldx && $game_map.display_y==oldy oldx = $game_map.display_x oldy = $game_map.display_y end end end