BiggusWeeabus

Untitled

Apr 10th, 2021
1,139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 20.11 KB | None | 0 0
  1. #===============================================================================
  2. # Data box for regular battles
  3. #===============================================================================
  4. class PokemonDataBox < SpriteWrapper
  5.   attr_reader   :battler
  6.   attr_accessor :selected
  7.   attr_reader   :animatingHP
  8.   attr_reader   :animatingExp
  9.  
  10.   # Time in seconds to fully fill the Exp bar (from empty).
  11.   EXP_BAR_FILL_TIME  = 1.75
  12.   # Maximum time in seconds to make a change to the HP bar.
  13.   HP_BAR_CHANGE_TIME = 1.0
  14.   STATUS_ICON_HEIGHT = 16
  15.   NAME_BASE_COLOR = Color.new(255,255,255)
  16.   NAME_SHADOW_COLOR = Color.new(107,107,107)
  17.   MALE_BASE_COLOR = Color.new(0,198,255)
  18.   MALE_SHADOW_COLOR = NAME_SHADOW_COLOR
  19.   FEMALE_BASE_COLOR = Color.new(248,88,40)
  20.   FEMALE_SHADOW_COLOR = NAME_SHADOW_COLOR
  21.  
  22.  
  23.   def initialize(battler,sideSize,viewport=nil)
  24.     super(viewport)
  25.     @battler      = battler
  26.     @sprites      = {}
  27.     @spriteX      = 0
  28.     @spriteY      = 0
  29.     @spriteBaseX  = 0
  30.     @selected     = 0
  31.     @frame        = 0
  32.     @showHP       = false   # Specifically, show the HP numbers
  33.     @animatingHP  = false
  34.     @showExp      = false   # Specifically, show the Exp bar
  35.     @animatingExp = false
  36.     @expFlash     = 0
  37.     initializeDataBoxGraphic(sideSize)
  38.     initializeOtherGraphics(viewport)
  39.     refresh
  40.   end
  41.  
  42.   def initializeDataBoxGraphic(sideSize)
  43.     onPlayerSide = ((@battler.index%2)==0)
  44.     # Get the data box graphic and set whether the HP numbers/Exp bar are shown
  45.     if sideSize==1   # One Pokémon on side, use the regular dara box BG
  46.       bgFilename = ["Graphics/Pictures/Battle/databox_normal",
  47.                     "Graphics/Pictures/Battle/databox_normal_foe"][@battler.index%2]
  48.       if onPlayerSide
  49.         @showHP  = true
  50.         @showExp = true
  51.       end
  52.     else   # Multiple Pokémon on side, use the thin dara box BG
  53.       bgFilename = ["Graphics/Pictures/Battle/databox_thin",
  54.                     "Graphics/Pictures/Battle/databox_thin_foe"][@battler.index%2]
  55.     end
  56.     @databoxBitmap  = AnimatedBitmap.new(bgFilename)
  57.     # Determine the co-ordinates of the data box and the left edge padding width
  58.     if onPlayerSide
  59.       @spriteX = Graphics.width - 256
  60.       @spriteY = Graphics.height - 192
  61.       @spriteBaseX = 34
  62.     else
  63.       @spriteX = -16
  64.       @spriteY = 36
  65.       @spriteBaseX = 16
  66.     end
  67.     case sideSize
  68.     when 2
  69.       @spriteX += [-12,  12,  0,  0][@battler.index]
  70.       @spriteY += [-20, -34, 34, 20][@battler.index]
  71.     when 3
  72.       @spriteX += [-12,  12, -6,  6,  0,  0][@battler.index]
  73.       @spriteY += [-42, -46,  4,  0, 50, 46][@battler.index]
  74.     end
  75.   end
  76.  
  77.   def initializeOtherGraphics(viewport)
  78.     # Create other bitmaps
  79.     @numbersBitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Battle/icon_numbers"))
  80.     @hpBarBitmap   = AnimatedBitmap.new(_INTL("Graphics/Pictures/Battle/overlay_hp"))
  81.     @expBarBitmap  = AnimatedBitmap.new(_INTL("Graphics/Pictures/Battle/overlay_exp"))
  82.     # Create sprite to draw HP numbers on
  83.     @hpNumbers = BitmapSprite.new(124,16,viewport)
  84.     pbSetSmallFont(@hpNumbers.bitmap)
  85.     @sprites["hpNumbers"] = @hpNumbers
  86.     # Create sprite wrapper that displays HP bar
  87.     @hpBar = SpriteWrapper.new(viewport)
  88.     @hpBar.bitmap = @hpBarBitmap.bitmap
  89.     @hpBar.src_rect.height = @hpBarBitmap.height/3
  90.     @sprites["hpBar"] = @hpBar
  91.     # Create sprite wrapper that displays Exp bar
  92.     @expBar = SpriteWrapper.new(viewport)
  93.     @expBar.bitmap = @expBarBitmap.bitmap
  94.     @sprites["expBar"] = @expBar
  95.     # Create sprite wrapper that displays everything except the above
  96.     @contents = BitmapWrapper.new(@databoxBitmap.width,@databoxBitmap.height)
  97.     self.bitmap  = @contents
  98.     self.visible = false
  99.     self.z       = 150+((@battler.index)/2)*5
  100.     pbSetSystemFont(self.bitmap)
  101.   end
  102.  
  103.   def dispose
  104.     pbDisposeSpriteHash(@sprites)
  105.     @databoxBitmap.dispose
  106.     @numbersBitmap.dispose
  107.     @hpBarBitmap.dispose
  108.     @expBarBitmap.dispose
  109.     @contents.dispose
  110.     super
  111.   end
  112.  
  113.  def x=(value)
  114.     super
  115.     @hpBar.x     = value+@spriteBaseX+102
  116.     @expBar.x    = value+@spriteBaseX+6
  117.     @hpNumbers.x = value+@spriteBaseX+80
  118.   end
  119.  
  120.   def y=(value)
  121.     super
  122.     @hpBar.y     = value+40
  123.     @expBar.y    = value+74
  124.     @hpNumbers.y = value+51
  125.   end
  126.  
  127.   def z=(value)
  128.     super
  129.     @hpBar.z     = value+1
  130.     @expBar.z    = value+1
  131.     @hpNumbers.z = value+2
  132.   end
  133.  
  134.   def opacity=(value)
  135.     super
  136.     for i in @sprites
  137.       i[1].opacity = value if !i[1].disposed?
  138.     end
  139.   end
  140.  
  141.   def visible=(value)
  142.     super
  143.     for i in @sprites
  144.       i[1].visible = value if !i[1].disposed?
  145.     end
  146.     @expBar.visible = (value && @showExp)
  147.   end
  148.  
  149.   def color=(value)
  150.     super
  151.     for i in @sprites
  152.       i[1].color = value if !i[1].disposed?
  153.     end
  154.   end
  155.  
  156.   def battler=(b)
  157.     @battler = b
  158.     self.visible = (@battler && !@battler.fainted?)
  159.   end
  160.  
  161.   def hp
  162.     return (@animatingHP) ? @currentHP : @battler.hp
  163.   end
  164.  
  165.   def expFraction
  166.     return (@animatingExp) ? @currentExp.to_f/@rangeExp : @battler.pokemon.expFraction
  167.   end
  168.  
  169.   def animateHP(oldHP,newHP,rangeHP)
  170.     @currentHP   = oldHP
  171.     @endHP       = newHP
  172.     @rangeHP     = rangeHP
  173.     # NOTE: A change in HP takes the same amount of time to animate, no matter
  174.     #       how big a change it is.
  175.     @hpIncPerFrame = (newHP-oldHP).abs/(HP_BAR_CHANGE_TIME*Graphics.frame_rate)
  176.     # minInc is the smallest amount that HP is allowed to change per frame.
  177.     # This avoids a tiny change in HP still taking HP_BAR_CHANGE_TIME seconds.
  178.     minInc = (rangeHP*4)/(@hpBarBitmap.width*HP_BAR_CHANGE_TIME*Graphics.frame_rate)
  179.     @hpIncPerFrame = minInc if @hpIncPerFrame<minInc
  180.     @animatingHP   = true
  181.   end
  182.  
  183.   def animateExp(oldExp,newExp,rangeExp)
  184.     @currentExp     = oldExp
  185.     @endExp         = newExp
  186.     @rangeExp       = rangeExp
  187.     # NOTE: Filling the Exp bar from empty to full takes EXP_BAR_FILL_TIME
  188.     #       seconds no matter what. Filling half of it takes half as long, etc.
  189.     @expIncPerFrame = rangeExp/(EXP_BAR_FILL_TIME*Graphics.frame_rate)
  190.     @animatingExp   = true
  191.     pbSEPlay("Pkmn exp gain") if @showExp
  192.   end
  193.  
  194.   def pbDrawNumber(number,btmp,startX,startY,align=0)
  195.     n = (number==-1) ? [10] : number.to_i.digits   # -1 means draw the / character
  196.     charWidth  = @numbersBitmap.width/11
  197.     charHeight = @numbersBitmap.height
  198.     startX -= charWidth*n.length if align==1
  199.     n.each do |i|
  200.       btmp.blt(startX,startY,@numbersBitmap.bitmap,Rect.new(i*charWidth,0,charWidth,charHeight))
  201.       startX += charWidth
  202.     end
  203.   end
  204.  
  205.   def refresh
  206.     self.bitmap.clear
  207.     return if !@battler.pokemon
  208.     textPos = []
  209.     imagePos = []
  210.     # Draw background panel
  211.     self.bitmap.blt(0,0,@databoxBitmap.bitmap,Rect.new(0,0,@databoxBitmap.width,@databoxBitmap.height))
  212.     # Draw Pokémon's name
  213.     nameWidth = self.bitmap.text_size(@battler.name).width
  214.     nameOffset = 0
  215.     nameOffset = nameWidth-116 if nameWidth>116
  216.     textPos.push([@battler.name,@spriteBaseX+11-nameOffset,5,false,NAME_BASE_COLOR,NAME_SHADOW_COLOR])
  217.     # Draw Pokémon's gender symbol
  218.     case @battler.displayGender
  219.     when 0   # Male
  220.       textPos.push([_INTL("♂"),@spriteBaseX+125,6,false,MALE_BASE_COLOR,MALE_SHADOW_COLOR])
  221.     when 1   # Female
  222.       textPos.push([_INTL("♀"),@spriteBaseX+125,6,false,FEMALE_BASE_COLOR,FEMALE_SHADOW_COLOR])
  223.     end
  224.     pbDrawTextPositions(self.bitmap,textPos)
  225.     # Draw Pokémon's level
  226.     imagePos.push(["Graphics/Pictures/Battle/overlay_lv",@spriteBaseX+140,16])
  227.     pbDrawNumber(@battler.level,self.bitmap,@spriteBaseX+162,16)
  228.     # Draw shiny icon
  229.     if @battler.shiny?
  230.       shinyX = (@battler.opposes?(0)) ? 206 : -6   # Foe's/player's
  231.       imagePos.push(["Graphics/Pictures/shiny",@spriteBaseX+shinyX,36])
  232.     end
  233.     # Draw Mega Evolution/Primal Reversion icon
  234.     if @battler.mega?
  235.       imagePos.push(["Graphics/Pictures/Battle/icon_mega",@spriteBaseX+8,34])
  236.     elsif @battler.primal?
  237.       primalX = (@battler.opposes?) ? 208 : -28   # Foe's/player's
  238.       if @battler.isSpecies?(:KYOGRE)
  239.         imagePos.push(["Graphics/Pictures/Battle/icon_primal_Kyogre",@spriteBaseX+primalX,4])
  240.       elsif @battler.isSpecies?(:GROUDON)
  241.         imagePos.push(["Graphics/Pictures/Battle/icon_primal_Groudon",@spriteBaseX+primalX,4])
  242.       end
  243.     end
  244.     # Draw owned icon (foe Pokémon only)
  245.     if @battler.owned? && @battler.opposes?(0)
  246.       imagePos.push(["Graphics/Pictures/Battle/icon_own",@spriteBaseX+8,36])
  247.     end
  248.     # Draw status icon
  249.     if @battler.status>0
  250.       s = @battler.status
  251.       s = 6 if s==PBStatuses::POISON && @battler.statusCount>0   # Badly poisoned
  252.       imagePos.push(["Graphics/Pictures/Battle/icon_statuses",@spriteBaseX+24,36,
  253.          0,(s-1)*STATUS_ICON_HEIGHT,-1,STATUS_ICON_HEIGHT])
  254.     end
  255.     pbDrawImagePositions(self.bitmap,imagePos)
  256.     refreshHP
  257.     refreshExp
  258.   end
  259.  
  260.   def refreshHP
  261.     @hpNumbers.bitmap.clear
  262.     return if !@battler.pokemon
  263.     # Show HP numbers
  264.     if @showHP
  265.       pbDrawNumber(self.hp,@hpNumbers.bitmap,54,2,1)
  266.       pbDrawNumber(-1,@hpNumbers.bitmap,54,2)   # / char
  267.       pbDrawNumber(@battler.totalhp,@hpNumbers.bitmap,70,2)
  268.     end
  269.     # Resize HP bar
  270.     w = 0
  271.     if self.hp>0
  272.       w = @hpBarBitmap.width.to_f*self.hp/@battler.totalhp
  273.       w = 1 if w<1
  274.       # NOTE: The line below snaps the bar's width to the nearest 2 pixels, to
  275.       #       fit in with the rest of the graphics which are doubled in size.
  276.       w = ((w/2.0).round)*2
  277.     end
  278.     @hpBar.src_rect.width = w
  279.     hpColor = 0                                  # Green bar
  280.     hpColor = 1 if self.hp<=@battler.totalhp/2   # Yellow bar
  281.     hpColor = 2 if self.hp<=@battler.totalhp/4   # Red bar
  282.     @hpBar.src_rect.y = hpColor*@hpBarBitmap.height/3
  283.   end
  284.  
  285.   def refreshExp
  286.     return if !@showExp
  287.     w = self.expFraction*@expBarBitmap.width
  288.     # NOTE: The line below snaps the bar's width to the nearest 2 pixels, to
  289.     #       fit in with the rest of the graphics which are doubled in size.
  290.     w = ((w/2).round)*2
  291.     @expBar.src_rect.width = w
  292.   end
  293.  
  294.   def updateHPAnimation
  295.     return if !@animatingHP
  296.     if @currentHP<@endHP      # Gaining HP
  297.       @currentHP += @hpIncPerFrame
  298.       @currentHP = @endHP if @currentHP>=@endHP
  299.     elsif @currentHP>@endHP   # Losing HP
  300.       @currentHP -= @hpIncPerFrame
  301.       @currentHP = @endHP if @currentHP<=@endHP
  302.     end
  303.     # Refresh the HP bar/numbers
  304.     refreshHP
  305.     @animatingHP = false if @currentHP==@endHP
  306.   end
  307.  
  308.   def updateExpAnimation
  309.     return if !@animatingExp
  310.     if !@showExp   # Not showing the Exp bar, no need to waste time animating it
  311.       @currentExp = @endExp
  312.       @animatingExp = false
  313.       return
  314.     end
  315.     if @currentExp<@endExp   # Gaining Exp
  316.       @currentExp += @expIncPerFrame
  317.       @currentExp = @endExp if @currentExp>=@endExp
  318.     elsif @currentExp>@endExp   # Losing Exp
  319.       @currentExp -= @expIncPerFrame
  320.       @currentExp = @endExp if @currentExp<=@endExp
  321.     end
  322.     # Refresh the Exp bar
  323.     refreshExp
  324.     return if @currentExp!=@endExp   # Exp bar still has more to animate
  325.     # Exp bar is completely filled, level up with a flash and sound effect
  326.     if @currentExp>=@rangeExp
  327.       if @expFlash==0
  328.         pbSEStop
  329.         @expFlash = Graphics.frame_rate/5
  330.         pbSEPlay("Pkmn exp full")
  331.         self.flash(Color.new(64,200,248,192),@expFlash)
  332.         for i in @sprites
  333.           i[1].flash(Color.new(64,200,248,192),@expFlash) if !i[1].disposed?
  334.         end
  335.       else
  336.         @expFlash -= 1
  337.         @animatingExp = false if @expFlash==0
  338.       end
  339.     else
  340.       pbSEStop
  341.       # Exp bar has finished filling, end animation
  342.       @animatingExp = false
  343.     end
  344.   end
  345.  
  346.   QUARTER_ANIM_PERIOD = Graphics.frame_rate*3/20
  347.  
  348.   def updatePositions(frameCounter)
  349.     self.x = @spriteX
  350.     self.y = @spriteY
  351.     # Data box bobbing while Pokémon is selected
  352.     if @selected==1 || @selected==2   # Choosing commands/targeted or damaged
  353.       case (frameCounter/QUARTER_ANIM_PERIOD).floor
  354.       when 1; self.y = @spriteY-2
  355.       when 3; self.y = @spriteY+2
  356.       end
  357.     end
  358.   end
  359.  
  360.   def update(frameCounter=0)
  361.     super()
  362.     # Animate HP bar
  363.     updateHPAnimation
  364.     # Animate Exp bar
  365.     updateExpAnimation
  366.     # Update coordinates of the data box
  367.     updatePositions(frameCounter)
  368.     pbUpdateSpriteHash(@sprites)
  369.   end
  370. end
  371.  
  372.  
  373.  
  374. #===============================================================================
  375. # Splash bar to announce a triggered ability
  376. #===============================================================================
  377. class AbilitySplashBar < SpriteWrapper
  378.   attr_reader :battler
  379.   attr_accessor :ability
  380.  
  381.   TEXT_BASE_COLOR   = Color.new(0,0,0)
  382.   TEXT_SHADOW_COLOR = Color.new(248,248,248)
  383.  
  384.   def initialize(side,viewport=nil)
  385.     super(viewport)
  386.     @side    = side
  387.     @battler = nil
  388.     @ability = ability
  389.     # Create sprite wrapper that displays background graphic
  390.     @bgBitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Battle/ability_bar"))
  391.     @bgSprite = SpriteWrapper.new(viewport)
  392.     @bgSprite.bitmap = @bgBitmap.bitmap
  393.     @bgSprite.src_rect.y      = (side==0) ? 0 : @bgBitmap.height/2
  394.     @bgSprite.src_rect.height = @bgBitmap.height/2
  395.     # Create bitmap that displays the text
  396.     @contents = BitmapWrapper.new(@bgBitmap.width,@bgBitmap.height/2)
  397.     self.bitmap = @contents
  398.     pbSetSystemFont(self.bitmap)
  399.     # Position the bar
  400.     self.x       = (side==0) ? -Graphics.width/2 : Graphics.width
  401.     self.y       = (side==0) ? 180 : 80
  402.     self.z       = 120
  403.     self.visible = false
  404.   end
  405.  
  406.   def dispose
  407.     @bgSprite.dispose
  408.     @bgBitmap.dispose
  409.     @contents.dispose
  410.     super
  411.   end
  412.  
  413.   def x=(value)
  414.     super
  415.     @bgSprite.x = value
  416.   end
  417.  
  418.   def y=(value)
  419.     super
  420.     @bgSprite.y = value
  421.   end
  422.  
  423.   def z=(value)
  424.     super
  425.     @bgSprite.z = value-1
  426.   end
  427.  
  428.   def opacity=(value)
  429.     super
  430.     @bgSprite.opacity = value
  431.   end
  432.  
  433.   def visible=(value)
  434.     super
  435.     @bgSprite.visible = value
  436.   end
  437.  
  438.   def color=(value)
  439.     super
  440.     @bgSprite.color = value
  441.   end
  442.  
  443.   def battler=(value)
  444.     @battler = value
  445.     refresh
  446.   end
  447.  
  448.   def ability=(value)
  449.     @ability = value
  450.     refresh
  451.   end
  452.  
  453.   def refresh
  454.     self.bitmap.clear
  455.     return if !@battler
  456.     textPos = []
  457.     textX = (@side==0) ? 10 : self.bitmap.width-8
  458.     # Draw Pokémon's name
  459.     textPos.push([_INTL("{1}'s",@battler.name),textX,2,@side==1,
  460.        TEXT_BASE_COLOR,TEXT_SHADOW_COLOR,true])
  461.     # Draw Pokémon's ability
  462.     textPos.push([(@ability.is_a?(String))? @ability : @battler.abilityName,textX,32,@side==1,
  463.        TEXT_BASE_COLOR,TEXT_SHADOW_COLOR,true])
  464.     pbDrawTextPositions(self.bitmap,textPos)
  465.   end
  466.  
  467.   def update
  468.     super
  469.     @bgSprite.update
  470.   end
  471. end
  472.  
  473.  
  474.  
  475. #===============================================================================
  476. # Pokémon sprite (used in battle)
  477. #===============================================================================
  478. class PokemonBattlerSprite < RPG::Sprite
  479.   attr_reader   :pkmn
  480.   attr_accessor :index
  481.   attr_accessor :selected
  482.   attr_reader   :sideSize
  483.  
  484.   def initialize(viewport,sideSize,index,battleAnimations)
  485.     super(viewport)
  486.     @pkmn             = nil
  487.     @sideSize         = sideSize
  488.     @index            = index
  489.     @battleAnimations = battleAnimations
  490.     # @selected: 0 = not selected, 1 = choosing action bobbing for this Pokémon,
  491.     #            2 = flashing when targeted
  492.     @selected         = 0
  493.     @frame            = 0
  494.     @updating         = false
  495.     @spriteX          = 0   # Actual x coordinate
  496.     @spriteY          = 0   # Actual y coordinate
  497.     @spriteXExtra     = 0   # Offset due to "bobbing" animation
  498.     @spriteYExtra     = 0   # Offset due to "bobbing" animation
  499.     @_iconBitmap      = nil
  500.     self.visible      = false
  501.   end
  502.  
  503.   def dispose
  504.     @_iconBitmap.dispose if @_iconBitmap
  505.     @_iconBitmap = nil
  506.     self.bitmap = nil if !self.disposed?
  507.     super
  508.   end
  509.  
  510.   def x; return @spriteX; end
  511.   def y; return @spriteY; end
  512.  
  513.   def x=(value)
  514.     @spriteX = value
  515.     super(value+@spriteXExtra)
  516.   end
  517.  
  518.   def y=(value)
  519.     @spriteY = value
  520.     super(value+@spriteYExtra)
  521.   end
  522.  
  523.   def width;  return (self.bitmap) ? self.bitmap.width : 0;  end
  524.   def height; return (self.bitmap) ? self.bitmap.height : 0; end
  525.  
  526.   def visible=(value)
  527.     @spriteVisible = value if !@updating   # For selection/targeting flashing
  528.     super
  529.   end
  530.  
  531.   # Set sprite's origin to bottom middle
  532.   def pbSetOrigin
  533.     return if !@_iconBitmap
  534.     self.ox = @_iconBitmap.width/2
  535.     self.oy = @_iconBitmap.height
  536.   end
  537.  
  538.   def pbSetPosition
  539.     return if !@_iconBitmap
  540.     pbSetOrigin
  541.     if (@index%2)==0
  542.       self.z = 50+5*@index/2
  543.     else
  544.       self.z = 50-5*(@index+1)/2
  545.     end
  546.     # Set original position
  547.     p = PokeBattle_SceneConstants.pbBattlerPosition(@index,@sideSize)
  548.     @spriteX = p[0]
  549.     @spriteY = p[1]
  550.     # Apply metrics
  551.     pbApplyBattlerMetricsToSprite(self,@index,@pkmn.fSpecies)
  552.   end
  553.  
  554.   def setPokemonBitmap(pkmn,back=false)
  555.     @pkmn = pkmn
  556.     @_iconBitmap.dispose if @_iconBitmap
  557.     @_iconBitmap = pbLoadPokemonBitmap(@pkmn,back)
  558.     self.bitmap = (@_iconBitmap) ? @_iconBitmap.bitmap : nil
  559.     pbSetPosition
  560.   end
  561.  
  562.   # This method plays the battle entrance animation of a Pokémon. By default
  563.   # this is just playing the Pokémon's cry, but you can expand on it. The
  564.   # recommendation is to create a PictureEx animation and push it into the
  565.   # @battleAnimations array.
  566.   def pbPlayIntroAnimation(pictureEx=nil)
  567.     return if !@pkmn
  568.     cry = pbCryFile(@pkmn)
  569.     pbSEPlay(cry) if cry
  570.   end
  571.  
  572.   QUARTER_ANIM_PERIOD = Graphics.frame_rate*3/20
  573.   SIXTH_ANIM_PERIOD   = Graphics.frame_rate*2/20
  574.  
  575.   def update(frameCounter=0)
  576.     return if !@_iconBitmap
  577.     @updating = true
  578.     # Update bitmap
  579.     @_iconBitmap.update
  580.     self.bitmap = @_iconBitmap.bitmap
  581.     # Pokémon sprite bobbing while Pokémon is selected
  582.     @spriteYExtra = 0
  583.     if @selected==1    # When choosing commands for this Pokémon
  584.       case (frameCounter/QUARTER_ANIM_PERIOD).floor
  585.       when 1; @spriteYExtra = 2
  586.       when 3; @spriteYExtra = -2
  587.       end
  588.     end
  589.     self.x       = self.x
  590.     self.y       = self.y
  591.     self.visible = @spriteVisible
  592.     # Pokémon sprite blinking when targeted
  593.     if @selected==2 && @spriteVisible
  594.       case (frameCounter/SIXTH_ANIM_PERIOD).floor
  595.       when 2, 5; self.visible = false
  596.       else;      self.visible = true
  597.       end
  598.     end
  599.     @updating = false
  600.   end
  601. end
  602.  
  603.  
  604.  
  605. #===============================================================================
  606. # Shadow sprite for Pokémon (used in battle)
  607. #===============================================================================
  608. class PokemonBattlerShadowSprite < RPG::Sprite
  609.   attr_reader   :pkmn
  610.   attr_accessor :index
  611.   attr_accessor :selected
  612.  
  613.   def initialize(viewport,sideSize,index)
  614.     super(viewport)
  615.     @pkmn        = nil
  616.     @sideSize    = sideSize
  617.     @index       = index
  618.     @_iconBitmap = nil
  619.     self.visible = false
  620.   end
  621.  
  622.   def dispose
  623.     @_iconBitmap.dispose if @_iconBitmap
  624.     @_iconBitmap = nil
  625.     self.bitmap = nil if !self.disposed?
  626.     super
  627.   end
  628.  
  629.   def width;  return (self.bitmap) ? self.bitmap.width : 0;  end
  630.   def height; return (self.bitmap) ? self.bitmap.height : 0; end
  631.  
  632.   # Set sprite's origin to centre
  633.   def pbSetOrigin
  634.     return if !@_iconBitmap
  635.     self.ox = @_iconBitmap.width/2
  636.     self.oy = @_iconBitmap.height/2
  637.   end
  638.  
  639.   def pbSetPosition
  640.     return if !@_iconBitmap
  641.     pbSetOrigin
  642.     self.z = 3
  643.     # Set original position
  644.     p = PokeBattle_SceneConstants.pbBattlerPosition(@index,@sideSize)
  645.     self.x = p[0]
  646.     self.y = p[1]
  647.     # Apply metrics
  648.     pbApplyBattlerMetricsToSprite(self,@index,@pkmn.fSpecies,true)
  649.   end
  650.  
  651.   def setPokemonBitmap(pkmn)
  652.     @pkmn = pkmn
  653.     @_iconBitmap.dispose if @_iconBitmap
  654.     @_iconBitmap = pbLoadPokemonShadowBitmap(@pkmn)
  655.     self.bitmap = (@_iconBitmap) ? @_iconBitmap.bitmap : nil
  656.     pbSetPosition
  657.   end
  658.  
  659.   def update(frameCounter=0)
  660.     return if !@_iconBitmap
  661.     # Update bitmap
  662.     @_iconBitmap.update
  663.     self.bitmap = @_iconBitmap.bitmap
  664.   end
  665. end
  666.  
Advertisement
Add Comment
Please, Sign In to add comment