Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 114.11 KB | None | 0 0
  1. =begin
  2. - def pbChooseNewEnemy(index,party)
  3. Use this method to choose a new Pokémon for the enemy
  4. The enemy's party is guaranteed to have at least one
  5. choosable member.
  6. index - Index to the battler to be replaced (use e.g. @battle.battlers[index] to
  7. access the battler)
  8. party - Enemy's party
  9.  
  10. - def pbWildBattleSuccess
  11. This method is called when the player wins a wild Pokémon battle.
  12. This method can change the battle's music for example.
  13.  
  14. - def pbTrainerBattleSuccess
  15. This method is called when the player wins a Trainer battle.
  16. This method can change the battle's music for example.
  17.  
  18. - def pbFainted(pkmn)
  19. This method is called whenever a Pokémon faints.
  20. pkmn - PokeBattle_Battler object indicating the Pokémon that fainted
  21.  
  22. - def pbChooseEnemyCommand(index)
  23. Use this method to choose a command for the enemy.
  24. index - Index of enemy battler (use e.g. @battle.battlers[index] to
  25. access the battler)
  26.  
  27. - def pbCommandMenu(index)
  28. Use this method to display the list of commands and choose
  29. a command for the player.
  30. index - Index of battler (use e.g. @battle.battlers[index] to
  31. access the battler)
  32. Return values:
  33. 0 - Fight
  34. 1 - Pokémon
  35. 2 - Bag
  36. 3 - Run
  37. =end
  38.  
  39. #===============================================================================
  40. # Command menu (Fight/Pokémon/Bag/Run)
  41. #===============================================================================
  42. class CommandMenuDisplay
  43. attr_accessor :mode
  44.  
  45. def initialize(viewport=nil)
  46. @display=nil
  47. if PokeBattle_SceneConstants::USECOMMANDBOX
  48. @display=IconSprite.new(0,Graphics.height-96,viewport)
  49. @display.setBitmap("Graphics/Pictures/Battle/overlay_command")
  50. end
  51. @window=Window_CommandPokemon.newWithSize([],
  52. Graphics.width-240,Graphics.height-96,240,96,viewport)
  53. @window.columns=2
  54. @window.columnSpacing=4
  55. @window.ignore_input=true
  56. @msgbox=Window_UnformattedTextPokemon.newWithSize(
  57. "",16,Graphics.height-96+2,220,96,viewport)
  58. @msgbox.baseColor=PokeBattle_SceneConstants::MESSAGEBASECOLOR
  59. @msgbox.shadowColor=PokeBattle_SceneConstants::MESSAGESHADOWCOLOR
  60. @msgbox.windowskin=nil
  61. @title=""
  62. @buttons=nil
  63. if PokeBattle_SceneConstants::USECOMMANDBOX
  64. @window.opacity=0
  65. @window.x=Graphics.width
  66. @buttons=CommandMenuButtons.new(self.index,self.mode,viewport)
  67. end
  68. end
  69.  
  70. def x; @window.x; end
  71. def x=(value)
  72. @window.x=value
  73. @msgbox.x=value
  74. @display.x=value if @display
  75. @buttons.x=value if @buttons
  76. end
  77.  
  78. def y; @window.y; end
  79. def y=(value)
  80. @window.y=value
  81. @msgbox.y=value
  82. @display.y=value if @display
  83. @buttons.y=value if @buttons
  84. end
  85.  
  86. def z; @window.z; end
  87. def z=(value)
  88. @window.z=value
  89. @msgbox.z=value
  90. @display.z=value if @display
  91. @buttons.z=value+1 if @buttons
  92. end
  93.  
  94. def ox; @window.ox; end
  95. def ox=(value)
  96. @window.ox=value
  97. @msgbox.ox=value
  98. @display.ox=value if @display
  99. @buttons.ox=value if @buttons
  100. end
  101.  
  102. def oy; @window.oy; end
  103. def oy=(value)
  104. @window.oy=value
  105. @msgbox.oy=value
  106. @display.oy=value if @display
  107. @buttons.oy=value if @buttons
  108. end
  109.  
  110. def visible; @window.visible; end
  111. def visible=(value)
  112. @window.visible=value
  113. @msgbox.visible=value
  114. @display.visible=value if @display
  115. @buttons.visible=value if @buttons
  116. end
  117.  
  118. def color; @window.color; end
  119. def color=(value)
  120. @window.color=value
  121. @msgbox.color=value
  122. @display.color=value if @display
  123. @buttons.color=value if @buttons
  124. end
  125.  
  126. def disposed?
  127. return @msgbox.disposed? || @window.disposed?
  128. end
  129.  
  130. def dispose
  131. return if disposed?
  132. @msgbox.dispose
  133. @window.dispose
  134. @display.dispose if @display
  135. @buttons.dispose if @buttons
  136. end
  137.  
  138. def index; @window.index; end
  139. def index=(value); @window.index=value; end
  140.  
  141. def setTexts(value)
  142. @msgbox.text=value[0]
  143. commands=[]
  144. for i in 1..4
  145. commands.push(value[i]) if value[i] && value[i]!=nil
  146. end
  147. @window.commands=commands
  148. end
  149.  
  150. def refresh
  151. @msgbox.refresh
  152. @window.refresh
  153. @buttons.refresh(self.index,self.mode) if @buttons
  154. end
  155.  
  156. def update
  157. @msgbox.update
  158. @window.update
  159. @display.update if @display
  160. @buttons.update(self.index,self.mode) if @buttons
  161. end
  162. end
  163.  
  164.  
  165.  
  166. class CommandMenuButtons < BitmapSprite
  167. def initialize(index=0,mode=0,viewport=nil)
  168. super(260,96,viewport)
  169. self.x=Graphics.width-260
  170. self.y=Graphics.height-96
  171. @mode=mode
  172. @buttonbitmap=AnimatedBitmap.new(_INTL("Graphics/Pictures/Battle/cursor_command"))
  173. refresh(index,mode)
  174. end
  175.  
  176. def dispose
  177. @buttonbitmap.dispose
  178. super
  179. end
  180.  
  181. def update(index=0,mode=0)
  182. refresh(index,mode)
  183. end
  184.  
  185. def refresh(index,mode=0)
  186. self.bitmap.clear
  187. @mode=mode
  188. cmdarray=[0,2,1,3]
  189. case @mode
  190. when 1
  191. cmdarray=[0,2,1,4] # Use "Call"
  192. when 2
  193. cmdarray=[5,7,6,3] # Safari Zone battle
  194. when 3
  195. cmdarray=[0,8,1,3] # Bug Catching Contest
  196. end
  197. for i in 0...4
  198. next if i==index
  199. x=((i%2)==0) ? 0 : 126
  200. y=((i/2)==0) ? 6 : 48
  201. self.bitmap.blt(x,y,@buttonbitmap.bitmap,Rect.new(0,cmdarray[i]*46,130,46))
  202. end
  203. for i in 0...4
  204. next if i!=index
  205. x=((i%2)==0) ? 0 : 126
  206. y=((i/2)==0) ? 6 : 48
  207. self.bitmap.blt(x,y,@buttonbitmap.bitmap,Rect.new(130,cmdarray[i]*46,130,46))
  208. end
  209. end
  210. end
  211.  
  212.  
  213.  
  214. #===============================================================================
  215. # Fight menu (choose a move)
  216. #===============================================================================
  217. class FightMenuDisplay
  218. attr_reader :battler
  219. attr_reader :index
  220. attr_accessor :megaButton
  221.  
  222. def initialize(battler,viewport=nil)
  223. @display=nil
  224. if PokeBattle_SceneConstants::USEFIGHTBOX
  225. @display=IconSprite.new(0,Graphics.height-96,viewport)
  226. @display.setBitmap("Graphics/Pictures/Battle/overlay_fight")
  227. end
  228. @window=Window_CommandPokemon.newWithSize([],0,Graphics.height-96,320,96,viewport)
  229. @window.columns=2
  230. @window.columnSpacing=4
  231. @window.ignore_input=true
  232. pbSetNarrowFont(@window.contents)
  233. @info=Window_AdvancedTextPokemon.newWithSize(
  234. "",320,Graphics.height-96,Graphics.width-320,96,viewport)
  235. pbSetNarrowFont(@info.contents)
  236. @ctag=shadowctag(PokeBattle_SceneConstants::MENUBASECOLOR,
  237. PokeBattle_SceneConstants::MENUSHADOWCOLOR)
  238. @buttons=nil
  239. @battler=battler
  240. @index=0
  241. @megaButton=0 # 0=don't show, 1=show, 2=pressed
  242. if PokeBattle_SceneConstants::USEFIGHTBOX
  243. @window.opacity=0
  244. @window.x=Graphics.width
  245. @info.opacity=0
  246. @info.x=Graphics.width+Graphics.width-96
  247. @buttons=FightMenuButtons.new(self.index,nil,viewport)
  248. end
  249. refresh
  250. end
  251.  
  252. def x; @window.x; end
  253. def x=(value)
  254. @window.x=value
  255. @info.x=value
  256. @display.x=value if @display
  257. @buttons.x=value if @buttons
  258. end
  259.  
  260. def y; @window.y; end
  261. def y=(value)
  262. @window.y=value
  263. @info.y=value
  264. @display.y=value if @display
  265. @buttons.y=value if @buttons
  266. end
  267.  
  268. def z; @window.z; end
  269. def z=(value)
  270. @window.z=value
  271. @info.z=value
  272. @display.z=value if @display
  273. @buttons.z=value+1 if @buttons
  274. end
  275.  
  276. def ox; @window.ox; end
  277. def ox=(value)
  278. @window.ox=value
  279. @info.ox=value
  280. @display.ox=value if @display
  281. @buttons.ox=value if @buttons
  282. end
  283.  
  284. def oy; @window.oy; end
  285. def oy=(value)
  286. @window.oy=value
  287. @info.oy=value
  288. @display.oy=value if @display
  289. @buttons.oy=value if @buttons
  290. end
  291.  
  292. def visible; @window.visible; end
  293. def visible=(value)
  294. @window.visible=value
  295. @info.visible=value
  296. @display.visible=value if @display
  297. @buttons.visible=value if @buttons
  298. end
  299.  
  300. def color; @window.color; end
  301. def color=(value)
  302. @window.color=value
  303. @info.color=value
  304. @display.color=value if @display
  305. @buttons.color=value if @buttons
  306. end
  307.  
  308. def disposed?
  309. return @info.disposed? || @window.disposed?
  310. end
  311.  
  312. def dispose
  313. return if disposed?
  314. @info.dispose
  315. @display.dispose if @display
  316. @buttons.dispose if @buttons
  317. @window.dispose
  318. end
  319.  
  320. def battler=(value)
  321. @battler=value
  322. refresh
  323. end
  324.  
  325. def setIndex(value)
  326. if @battler && @battler.moves[value].id!=0
  327. @index=value
  328. @window.index=value
  329. refresh
  330. return true
  331. end
  332. return false
  333. end
  334.  
  335. def refresh
  336. return if !@battler
  337. commands=[]
  338. for i in 0...4
  339. break if @battler.moves[i].id==0
  340. commands.push(@battler.moves[i].name)
  341. end
  342. @window.commands=commands
  343. selmove=@battler.moves[@index]
  344. movetype=PBTypes.getName(selmove.type)
  345. if selmove.totalpp==0
  346. @info.text=_INTL("{1}PP: ---<br>TYPE/{2}",@ctag,movetype)
  347. else
  348. @info.text=_ISPRINTF("{1:s}PP: {2: 2d}/{3: 2d}<br>TYPE/{4:s}",
  349. @ctag,selmove.pp,selmove.totalpp,movetype)
  350. end
  351. @buttons.refresh(self.index,@battler ? @battler.moves : nil,@megaButton) if @buttons
  352. end
  353.  
  354. def update
  355. @info.update
  356. @window.update
  357. @display.update if @display
  358. if @buttons
  359. moves=@battler ? @battler.moves : nil
  360. @buttons.update(self.index,moves,@megaButton)
  361. end
  362. end
  363. end
  364.  
  365.  
  366.  
  367. class FightMenuButtons < BitmapSprite
  368. UPPERGAP=46
  369.  
  370. def initialize(index=0,moves=nil,viewport=nil)
  371. super(Graphics.width,96+UPPERGAP,viewport)
  372. self.x=0
  373. self.y=Graphics.height-96-UPPERGAP
  374. pbSetNarrowFont(self.bitmap)
  375. @buttonbitmap=AnimatedBitmap.new("Graphics/Pictures/Battle/cursor_fight")
  376. @typebitmap=AnimatedBitmap.new(_INTL("Graphics/Pictures/types"))
  377. @megaevobitmap=AnimatedBitmap.new(_INTL("Graphics/Pictures/Battle/cursor_mega"))
  378. refresh(index,moves,0)
  379. end
  380.  
  381. def dispose
  382. @buttonbitmap.dispose
  383. @typebitmap.dispose
  384. @megaevobitmap.dispose
  385. super
  386. end
  387.  
  388. def update(index=0,moves=nil,megaButton=0)
  389. refresh(index,moves,megaButton)
  390. end
  391.  
  392. def refresh(index,moves,megaButton)
  393. return if !moves
  394. self.bitmap.clear
  395. textpos=[]
  396. for i in 0...4
  397. next if i==index
  398. next if moves[i].id==0
  399. x=((i%2)==0) ? 4 : 192
  400. y=((i/2)==0) ? 6 : 48
  401. y+=UPPERGAP
  402. self.bitmap.blt(x,y,@buttonbitmap.bitmap,Rect.new(0,moves[i].type*46,192,46))
  403. textpos.push([moves[i].name,x+96,y+6,2,
  404. PokeBattle_SceneConstants::MENUBASECOLOR,PokeBattle_SceneConstants::MENUSHADOWCOLOR])
  405. end
  406. ppcolors=[
  407. PokeBattle_SceneConstants::PPTEXTBASECOLOR,PokeBattle_SceneConstants::PPTEXTSHADOWCOLOR,
  408. PokeBattle_SceneConstants::PPTEXTBASECOLOR,PokeBattle_SceneConstants::PPTEXTSHADOWCOLOR,
  409. PokeBattle_SceneConstants::PPTEXTBASECOLORYELLOW,PokeBattle_SceneConstants::PPTEXTSHADOWCOLORYELLOW,
  410. PokeBattle_SceneConstants::PPTEXTBASECOLORORANGE,PokeBattle_SceneConstants::PPTEXTSHADOWCOLORORANGE,
  411. PokeBattle_SceneConstants::PPTEXTBASECOLORRED,PokeBattle_SceneConstants::PPTEXTSHADOWCOLORRED
  412. ]
  413. for i in 0...4
  414. next if i!=index
  415. next if moves[i].id==0
  416. x=((i%2)==0) ? 4 : 192
  417. y=((i/2)==0) ? 6 : 48
  418. y+=UPPERGAP
  419. self.bitmap.blt(x,y,@buttonbitmap.bitmap,Rect.new(192,moves[i].type*46,192,46))
  420. self.bitmap.blt(416,20+UPPERGAP,@typebitmap.bitmap,Rect.new(0,moves[i].type*28,64,28))
  421. textpos.push([moves[i].name,x+96,y+6,2,
  422. PokeBattle_SceneConstants::MENUBASECOLOR,PokeBattle_SceneConstants::MENUSHADOWCOLOR])
  423. if moves[i].totalpp>0
  424. ppfraction=(4.0*moves[i].pp/moves[i].totalpp).ceil
  425. textpos.push([_INTL("PP: {1}/{2}",moves[i].pp,moves[i].totalpp),
  426. 448,50+UPPERGAP,2,ppcolors[(4-ppfraction)*2],ppcolors[(4-ppfraction)*2+1]])
  427. end
  428. end
  429. pbDrawTextPositions(self.bitmap,textpos)
  430. if megaButton>0
  431. self.bitmap.blt(146,0,@megaevobitmap.bitmap,Rect.new(0,(megaButton-1)*46,96,46))
  432. end
  433. end
  434. end
  435.  
  436.  
  437.  
  438. #===============================================================================
  439. # Data box for safari battles
  440. #===============================================================================
  441. class SafariDataBox < SpriteWrapper
  442. attr_accessor :selected
  443. attr_reader :appearing
  444.  
  445. def initialize(battle,viewport=nil)
  446. super(viewport)
  447. @selected = 0
  448. @battle = battle
  449. @databox = AnimatedBitmap.new("Graphics/Pictures/Battle/databox_safari")
  450. @spriteX = PokeBattle_SceneConstants::SAFARIBOX_X
  451. @spriteY = PokeBattle_SceneConstants::SAFARIBOX_Y
  452. @appearing = false
  453. @contents = BitmapWrapper.new(@databox.width,@databox.height)
  454. self.bitmap = @contents
  455. self.visible = false
  456. self.z = 50
  457. pbSetSystemFont(self.bitmap)
  458. refresh
  459. end
  460.  
  461. def appear
  462. refresh
  463. self.visible = true
  464. self.opacity = 255
  465. self.x = @spriteX+240
  466. self.y = @spriteY
  467. @appearing = true
  468. end
  469.  
  470. def refresh
  471. self.bitmap.clear
  472. self.bitmap.blt(0,0,@databox.bitmap,Rect.new(0,0,@databox.width,@databox.height))
  473. base = Color.new(72,72,72)
  474. shadow = Color.new(184,184,184)
  475. textpos = []
  476. textpos.push([_INTL("Safari Balls"),30,8,false,base,shadow])
  477. textpos.push([_INTL("Left: {1}",@battle.ballcount),30,38,false,base,shadow])
  478. pbDrawTextPositions(self.bitmap,textpos)
  479. end
  480.  
  481. def update
  482. super
  483. if @appearing
  484. self.x -= 12
  485. self.x = @spriteX if self.x<@spriteX
  486. @appearing = false if self.x<=@spriteX
  487. self.y = @spriteY
  488. return
  489. end
  490. self.x = @spriteX
  491. self.y = @spriteY
  492. end
  493. end
  494.  
  495.  
  496.  
  497. #===============================================================================
  498. # Data box for regular battles (both single and double)
  499. #===============================================================================
  500. class PokemonDataBox < SpriteWrapper
  501. attr_reader :battler
  502. attr_accessor :selected
  503. attr_accessor :appearing
  504. attr_reader :animatingHP
  505. attr_reader :animatingEXP
  506.  
  507. def initialize(battler,doublebattle,viewport=nil)
  508. super(viewport)
  509. @explevel = 0
  510. @battler = battler
  511. @selected = 0
  512. @frame = 0
  513. @showhp = false
  514. @showexp = false
  515. @appearing = false
  516. @animatingHP = false
  517. @starthp = 0
  518. @currenthp = 0
  519. @endhp = 0
  520. @expflash = 0
  521. @spritebaseX = ((@battler.index&1)==0) ? 34 : 16 # Player's/foe's
  522. @doublebattle=doublebattle
  523. if doublebattle
  524. case @battler.index
  525. when 0
  526. @databox = AnimatedBitmap.new("Graphics/Pictures/Battle/databox_thin")
  527. @spriteX = PokeBattle_SceneConstants::PLAYERBOXD1_X
  528. @spriteY = PokeBattle_SceneConstants::PLAYERBOXD1_Y
  529. when 1
  530. @databox = AnimatedBitmap.new("Graphics/Pictures/Battle/databox_thin_foe")
  531. @spriteX = PokeBattle_SceneConstants::FOEBOXD1_X
  532. @spriteY = PokeBattle_SceneConstants::FOEBOXD1_Y
  533. when 2
  534. @databox = AnimatedBitmap.new("Graphics/Pictures/Battle/databox_thin")
  535. @spriteX = PokeBattle_SceneConstants::PLAYERBOXD2_X
  536. @spriteY = PokeBattle_SceneConstants::PLAYERBOXD2_Y
  537. when 3
  538. @databox = AnimatedBitmap.new("Graphics/Pictures/Battle/databox_thin_foe")
  539. @spriteX = PokeBattle_SceneConstants::FOEBOXD2_X
  540. @spriteY = PokeBattle_SceneConstants::FOEBOXD2_Y
  541. end
  542. else
  543. case @battler.index
  544. when 0
  545. @databox = AnimatedBitmap.new("Graphics/Pictures/Battle/databox_normal")
  546. @spriteX = PokeBattle_SceneConstants::PLAYERBOX_X
  547. @spriteY = PokeBattle_SceneConstants::PLAYERBOX_Y
  548. @showhp = true
  549. @showexp = true
  550. when 1
  551. @databox = AnimatedBitmap.new("Graphics/Pictures/Battle/databox_normal_foe")
  552. @spriteX = PokeBattle_SceneConstants::FOEBOX_X
  553. @spriteY = PokeBattle_SceneConstants::FOEBOX_Y
  554. end
  555. end
  556. @statuses = AnimatedBitmap.new(_INTL("Graphics/Pictures/Battle/icon_statuses"))
  557. @hpbar = AnimatedBitmap.new(_INTL("Graphics/Pictures/Battle/overlay_hp"))
  558. @expbar = AnimatedBitmap.new(_INTL("Graphics/Pictures/Battle/overlay_exp"))
  559. @contents = BitmapWrapper.new(@databox.width,@databox.height)
  560. self.bitmap = @contents
  561. self.visible = false
  562. self.z = 50
  563. refreshExpLevel
  564. refresh
  565. end
  566.  
  567. def dispose
  568. @statuses.dispose
  569. @hpbar.dispose
  570. @expbar.dispose
  571. @databox.dispose
  572. @contents.dispose
  573. super
  574. end
  575.  
  576. def hp
  577. return (@animatingHP) ? @currenthp : @battler.hp
  578. end
  579.  
  580. def exp
  581. return (@animatingEXP) ? @currentexp : @explevel
  582. end
  583.  
  584. def animateHP(oldhp,newhp)
  585. @starthp = oldhp
  586. @currenthp = oldhp
  587. @endhp = newhp
  588. @animatingHP = true
  589. end
  590.  
  591. def animateEXP(oldexp,newexp)
  592. @currentexp = oldexp
  593. @endexp = newexp
  594. @animatingEXP = true
  595. end
  596.  
  597. def appear
  598. refreshExpLevel
  599. refresh
  600. self.visible = true
  601. self.opacity = 255
  602. self.x = ((@battler.index&1)==0) ? @spriteX+320 : @spriteX-320 # Player's/foe's
  603. self.y = @spriteY
  604. @appearing = true
  605. end
  606.  
  607. def refreshExpLevel
  608. if !@battler.pokemon
  609. @explevel = 0
  610. else
  611. growthrate = @battler.pokemon.growthrate
  612. startexp = PBExperience.pbGetStartExperience(@battler.pokemon.level,growthrate)
  613. endexp = PBExperience.pbGetStartExperience(@battler.pokemon.level+1,growthrate)
  614. if startexp==endexp
  615. @explevel = 0
  616. else
  617. @explevel = (@battler.pokemon.exp-startexp)*@expbar.bitmap.width/(endexp-startexp)
  618. end
  619. end
  620. end
  621.  
  622. def refresh
  623. self.bitmap.clear
  624. return if !@battler.pokemon
  625. self.bitmap.blt(0,0,@databox.bitmap,Rect.new(0,0,@databox.width,@databox.height))
  626. base = Color.new(32,40,48)
  627. shadow = Color.new(176,176,176)
  628. pbSetSystemFont(self.bitmap)
  629. bitmap.font.name="Power Green Small"
  630. bitmap.font.size=25
  631. textpos = []
  632. imagepos = []
  633. # Draw Pokémon's name
  634. textpos.push([@battler.name,@spritebaseX+8,6,false,base,shadow])
  635. # Draw Pokémon's gender symbol
  636. genderX = self.bitmap.text_size(@battler.name).width
  637. genderX += @spritebaseX+14
  638. case @battler.displayGender
  639. when 0 # Male
  640. #textpos.push([_INTL("♂"),genderX,6,false,Color.new(48,96,216),shadow])
  641. pbDrawOutlineText(self.bitmap,self.bitmap.text_size(@battler.name).width + 28,2,140,40,_INTL("♂"),Color.new(48,96,216),Color.new(0,0,0),0)
  642. when 1 # Female
  643. #textpos.push([_INTL("♀"),genderX,6,false,Color.new(248,88,40),shadow])
  644. pbDrawOutlineText(self.bitmap,self.bitmap.text_size(@battler.name).width + 28,2,140,40,_INTL("♀"),Color.new(248,88,40),Color.new(0,0,0),0)
  645. end
  646. #pbDrawTextPositions(self.bitmap,textpos)
  647. ## Draw Pokémon's level
  648. #pbSetSmallFont(self.bitmap)
  649. #imagepos.push(["Graphics/Pictures/Battle/overlay_lv",
  650. # @spritebaseX+180-self.bitmap.text_size(@battler.level.to_s).width,16,0,0,-1,-1])
  651. #textpos = [
  652. # [@battler.level.to_s,@spritebaseX+202,8,true,base,shadow]
  653. #]
  654. pbDrawOutlineText(self.bitmap,namex,namey,140,40,@battler.name,Color.new(255,255,255),Color.new(0,0,0),0)
  655. pbSetSmallFont(self.bitmap)
  656. pbDrawOutlineText(self.bitmap,140,4,140,40,_INTL("Lv{1}",@battler.level),Color.new(255,255,255),Color.new(0,0,0),1)
  657. # Draw Pokémon's HP numbers
  658. if @showhp
  659. hpstring = _ISPRINTF("{1: 2d}/{2: 2d}",self.hp,@battler.totalhp)
  660. #textpos.push([hpstring,@spritebaseX+188,48,true,base,shadow])
  661. bitmap.font.name="Power Green Small"
  662. bitmap.font.size=25
  663. pbDrawOutlineText(self.bitmap,114,48,140,25,hpstring,Color.new(255,255,255),Color.new(0,0,0),1)
  664. end
  665. pbDrawTextPositions(self.bitmap,textpos)
  666. # Draw shiny icon
  667. if @battler.isShiny?
  668. shinyX = ((@battler.index&1)==0) ? -6 : 206 # Player's/foe's
  669. imagepos.push(["Graphics/Pictures/shiny",@spritebaseX+shinyX,36,0,0,-1,-1])
  670. end
  671. # Draw Mega Evolution/Primal Reversion icon
  672. if @battler.isMega?
  673. imagepos.push(["Graphics/Pictures/Battle/icon_mega",@spritebaseX+8,34,0,0,-1,-1])
  674. elsif @battler.isPrimal?
  675. if isConst?(@battler.pokemon.species,PBSpecies,:KYOGRE)
  676. imagepos.push(["Graphics/Pictures/Battle/icon_primal_Kyogre",@spritebaseX+140,4,0,0,-1,-1])
  677. elsif isConst?(@battler.pokemon.species,PBSpecies,:GROUDON)
  678. imagepos.push(["Graphics/Pictures/Battle/icon_primal_Groudon",@spritebaseX+140,4,0,0,-1,-1])
  679. end
  680. end
  681. # Draw owned icon (foe Pokémon only)
  682. if @battler.owned && (@battler.index&1)==1
  683. imagepos.push(["Graphics/Pictures/Battle/icon_own",@spritebaseX+8,36,0,0,-1,-1])
  684. end
  685. # Draw status icon
  686. if @battler.status>0
  687. iconheight = 16
  688. self.bitmap.blt(@spritebaseX+24,36,@statuses.bitmap,
  689. Rect.new(0,(@battler.status-1)*iconheight,@statuses.bitmap.width,iconheight))
  690. end
  691. # Draw HP bar
  692. # Find out if it's a double battle, then also whether it's the ally or foe databox
  693. hpbarx=@spritebaseX+102 # default values
  694. hpbary=40 # default
  695. if @doublebattle
  696. case battler.index
  697. when 0 # First ally
  698. hpbarx=100
  699. hpbary=100
  700. when 1 # First foe
  701. when 2 # Second ally
  702. when 3 # Second foe
  703. end
  704. else
  705. case battler.index
  706. when 0 # Ally
  707. when 1 # Foe
  708. hpbarx=102
  709. hpbary=40
  710. end
  711. end
  712. hpgauge = (@battler.totalhp==0) ? 0 : self.hp*@hpbar.bitmap.width/@battler.totalhp
  713. hpgauge = 2 if hpgauge<2 && self.hp>0
  714. hpzone = 0
  715. hpzone = 1 if self.hp<=(@battler.totalhp/2).floor
  716. hpzone = 2 if self.hp<=(@battler.totalhp/4).floor
  717. if @animatingHP && self.hp>0 # fill with black (shows what the HP used to be)
  718. self.bitmap.fill_rect(hpbarx,hpbary,
  719. @starthp*@hpbar.bitmap.width/@battler.totalhp,@hpbar.bitmap.height/3,Color.new(0,0,0))
  720. end
  721. self.bitmap.blt(hpbarx,hpbary,@hpbar.bitmap,
  722. Rect.new(0,hpzone*@hpbar.bitmap.height/3,hpgauge,@hpbar.bitmap.height/3))
  723. # Draw Exp bar
  724. if @showexp
  725. self.bitmap.blt(@spritebaseX+6+42,76-8,@expbar.bitmap,
  726. Rect.new(0,0,self.exp,@expbar.bitmap.height))
  727. end
  728. pbDrawImagePositions(self.bitmap,imagepos)
  729. end
  730.  
  731. def update
  732. super
  733. @frame = (@frame+1)%24
  734. # Animate HP bar
  735. if @animatingHP
  736. if @currenthp<@endhp
  737. @currenthp += [1,(@battler.totalhp/96).floor].max
  738. @currenthp = @endhp if @currenthp>@endhp
  739. elsif @currenthp>@endhp
  740. @currenthp -= [1,(@battler.totalhp/96).floor].max
  741. @currenthp = @endhp if @currenthp<@endhp
  742. end
  743. @animatingHP = false if @currenthp==@endhp
  744. refresh
  745. end
  746. # Animate Exp bar
  747. if @animatingEXP
  748. if !@showexp
  749. @currentexp = @endexp
  750. elsif @currentexp<@endexp # Gaining Exp
  751. if @endexp>=192 ||
  752. @endexp-@currentexp>=192/4
  753. @currentexp += 4
  754. else
  755. @currentexp += 2
  756. end
  757. @currentexp = @endexp if @currentexp>@endexp
  758. elsif @currentexp>@endexp # Losing Exp
  759. if @endexp==0 ||
  760. @currentexp-@endexp>=192/4
  761. @currentexp -= 4
  762. elsif @currentexp>@endexp
  763. @currentexp -= 2
  764. end
  765. @currentexp = @endexp if @currentexp<@endexp
  766. end
  767. refresh
  768. if @currentexp==@endexp
  769. if @currentexp==192
  770. if @expflash==0
  771. pbSEPlay("Pkmn exp full")
  772. self.flash(Color.new(64,200,248),8)
  773. @expflash = 8
  774. else
  775. @expflash -= 1
  776. if @expflash==0
  777. @animatingEXP = false
  778. refreshExpLevel
  779. end
  780. end
  781. else
  782. @animatingEXP = false
  783. end
  784. end
  785. end
  786. # Move data box onto the screen
  787. if @appearing
  788. if (@battler.index&1)==0 # if player's Pokémon
  789. self.x -= 12
  790. self.x = @spriteX if self.x<@spriteX
  791. @appearing = false if self.x<=@spriteX
  792. else
  793. self.x += 12
  794. self.x = @spriteX if self.x>@spriteX
  795. @appearing = false if self.x>=@spriteX
  796. end
  797. self.y = @spriteY
  798. return
  799. end
  800. self.x = @spriteX
  801. self.y = @spriteY
  802. # Data box bobbing while Pokémon is selected
  803. if @selected==1 || @selected==2 # Choosing commands/targeted or damaged
  804. if (@frame/6).floor==1
  805. self.y = @spriteY-2
  806. elsif (@frame/6).floor==3
  807. self.y = @spriteY+2
  808. end
  809. end
  810. end
  811. end
  812.  
  813.  
  814.  
  815. #===============================================================================
  816. # Shows the enemy trainer(s)'s Pokémon being thrown out. It appears at coords
  817. # (@spritex,@spritey), and moves in y to @endspritey where it stays for the rest
  818. # of the battle, i.e. the latter is the more important value.
  819. # Doesn't show the ball itself being thrown.
  820. #===============================================================================
  821. class PokeballSendOutAnimation
  822. SPRITESTEPS=10
  823. STARTZOOM=0.125
  824.  
  825. def initialize(sprite,spritehash,pkmn,illusionpoke,doublebattle)
  826. @illusionpoke=illusionpoke
  827. @disposed=false
  828. @ballused=pkmn.pokemon ? pkmn.pokemon.ballused : 0
  829. if @illusionpoke
  830. @ballused=@illusionpoke.ballused || 0
  831. end
  832. @PokemonBattlerSprite=sprite
  833. @PokemonBattlerSprite.visible=false
  834. @PokemonBattlerSprite.tone=Tone.new(248,248,248,248)
  835. @pokeballsprite=IconSprite.new(0,0,sprite.viewport)
  836. @pokeballsprite.setBitmap(sprintf("Graphics/Pictures/Battle/ball_%02d",@ballused))
  837. if doublebattle
  838. @spritex=PokeBattle_SceneConstants::FOEBATTLERD1_X if pkmn.index==1
  839. @spritex=PokeBattle_SceneConstants::FOEBATTLERD2_X if pkmn.index==3
  840. else
  841. @spritex=PokeBattle_SceneConstants::FOEBATTLER_X
  842. end
  843. @spritey=0
  844. if @illusionpoke
  845. @endspritey=adjustBattleSpriteY(sprite,@illusionpoke.species,pkmn.index)
  846. else
  847. @endspritey=adjustBattleSpriteY(sprite,pkmn.species,pkmn.index)
  848. end
  849. if doublebattle
  850. @spritey=PokeBattle_SceneConstants::FOEBATTLERD1_Y if pkmn.index==1
  851. @spritey=PokeBattle_SceneConstants::FOEBATTLERD2_Y if pkmn.index==3
  852. @endspritey+=PokeBattle_SceneConstants::FOEBATTLERD1_Y if pkmn.index==1
  853. @endspritey+=PokeBattle_SceneConstants::FOEBATTLERD2_Y if pkmn.index==3
  854. else
  855. @spritey=PokeBattle_SceneConstants::FOEBATTLER_Y
  856. @endspritey+=PokeBattle_SceneConstants::FOEBATTLER_Y
  857. end
  858. @spritehash=spritehash
  859. @pokeballsprite.x=@spritex-@pokeballsprite.bitmap.width/2
  860. @pokeballsprite.y=@spritey-@pokeballsprite.bitmap.height/2-4
  861. @pokeballsprite.z=@PokemonBattlerSprite.z+1
  862. @pkmn=pkmn
  863. @shadowX=@spritex
  864. @shadowY=@spritey
  865. if @spritehash["shadow#{@pkmn.index}"] && @spritehash["shadow#{@pkmn.index}"].bitmap!=nil
  866. @shadowX-=@spritehash["shadow#{@pkmn.index}"].bitmap.width/2
  867. @shadowY-=@spritehash["shadow#{@pkmn.index}"].bitmap.height/2
  868. end
  869. @shadowVisible=showShadow?(pkmn.species)
  870. if @illusionpoke
  871. @shadowVisible=showShadow?(@illusionpoke.species)
  872. end
  873. @stepspritey=(@spritey-@endspritey)
  874. @zoomstep=(1.0-STARTZOOM)/SPRITESTEPS
  875. @animdone=false
  876. @frame=0
  877. end
  878.  
  879. def disposed?
  880. return @disposed
  881. end
  882.  
  883. def animdone?
  884. return @animdone
  885. end
  886.  
  887. def dispose
  888. return if disposed?
  889. @pokeballsprite.dispose
  890. @disposed=true
  891. end
  892.  
  893. def update
  894. return if disposed?
  895. @pokeballsprite.update
  896. @frame+=1
  897. if @frame==2
  898. pbSEPlay("Battle recall")
  899. end
  900. if @frame==4
  901. @PokemonBattlerSprite.visible=true
  902. @PokemonBattlerSprite.zoom_x=STARTZOOM
  903. @PokemonBattlerSprite.zoom_y=STARTZOOM
  904. pbSpriteSetCenter(@PokemonBattlerSprite,@spritex,@spritey)
  905. if @illusionpoke
  906. pbPlayCry(@illusionpoke)
  907. else
  908. if @pkmn.pokemon
  909. pbPlayCry(@pkmn.pokemon)
  910. else
  911. pbPlayCrySpecies(@pkmn.species,@pkmn.form)
  912. end
  913. end
  914. @pokeballsprite.setBitmap(sprintf("Graphics/Pictures/Battle/ball_%02d_open",@ballused))
  915. end
  916. if @frame==8
  917. @pokeballsprite.visible=false
  918. end
  919. if @frame>8 && @frame<=16
  920. color=Color.new(248,248,248,256-(16-@frame)*32)
  921. @spritehash["enemybase"].color=color
  922. @spritehash["playerbase"].color=color
  923. @spritehash["battlebg"].color=color
  924. for i in 0...4
  925. @spritehash["shadow#{i}"].color=color if @spritehash["shadow#{i}"]
  926. end
  927. end
  928. if @frame>16 && @frame<=24
  929. color=Color.new(248,248,248,(24-@frame)*32)
  930. tone=(24-@frame)*32
  931. @PokemonBattlerSprite.tone=Tone.new(tone,tone,tone,tone)
  932. @spritehash["enemybase"].color=color
  933. @spritehash["playerbase"].color=color
  934. @spritehash["battlebg"].color=color
  935. for i in 0...4
  936. @spritehash["shadow#{i}"].color=color if @spritehash["shadow#{i}"]
  937. end
  938. end
  939. if @frame>5 && @PokemonBattlerSprite.zoom_x<1.0
  940. @PokemonBattlerSprite.zoom_x+=@zoomstep
  941. @PokemonBattlerSprite.zoom_y+=@zoomstep
  942. @PokemonBattlerSprite.zoom_x=1.0 if @PokemonBattlerSprite.zoom_x > 1.0
  943. @PokemonBattlerSprite.zoom_y=1.0 if @PokemonBattlerSprite.zoom_y > 1.0
  944. currentY=@spritey-(@stepspritey*@PokemonBattlerSprite.zoom_y)
  945. pbSpriteSetCenter(@PokemonBattlerSprite,@spritex,currentY)
  946. @PokemonBattlerSprite.y=currentY
  947. end
  948. if @PokemonBattlerSprite.tone.gray<=0 && @PokemonBattlerSprite.zoom_x>=1.0
  949. @animdone=true
  950. if @spritehash["shadow#{@pkmn.index}"]
  951. @spritehash["shadow#{@pkmn.index}"].x=@shadowX
  952. @spritehash["shadow#{@pkmn.index}"].y=@shadowY
  953. @spritehash["shadow#{@pkmn.index}"].visible=@shadowVisible
  954. end
  955. end
  956. end
  957. end
  958.  
  959.  
  960.  
  961. #===============================================================================
  962. # Shows the player's (or partner's) Pokémon being thrown out. It appears at
  963. # (@spritex,@spritey), and moves in y to @endspritey where it stays for the rest
  964. # of the battle, i.e. the latter is the more important value.
  965. # Doesn't show the ball itself being thrown.
  966. #===============================================================================
  967. class PokeballPlayerSendOutAnimation
  968. # Ball curve: 8,52; 22,44; 52, 96
  969. # Player: Color.new(16*8,23*8,30*8)
  970. SPRITESTEPS=10
  971. STARTZOOM=0.125
  972.  
  973. def initialize(sprite,spritehash,pkmn,illusionpoke,doublebattle)
  974. @illusionpoke=illusionpoke
  975. @disposed=false
  976. @PokemonBattlerSprite=sprite
  977. @pkmn=pkmn
  978. @PokemonBattlerSprite.visible=false
  979. @PokemonBattlerSprite.tone=Tone.new(248,248,248,248)
  980. @spritehash=spritehash
  981. if doublebattle
  982. @spritex=PokeBattle_SceneConstants::PLAYERBATTLERD1_X if pkmn.index==0
  983. @spritex=PokeBattle_SceneConstants::PLAYERBATTLERD2_X if pkmn.index==2
  984. else
  985. @spritex=PokeBattle_SceneConstants::PLAYERBATTLER_X
  986. end
  987. @spritey=0
  988. if @illusionpoke
  989. @endspritey=adjustBattleSpriteY(sprite,@illusionpoke.species,pkmn.index)
  990. else
  991. @endspritey=adjustBattleSpriteY(sprite,pkmn.species,pkmn.index)
  992. end
  993. if doublebattle
  994. @spritey+=PokeBattle_SceneConstants::PLAYERBATTLERD1_Y if pkmn.index==0
  995. @spritey+=PokeBattle_SceneConstants::PLAYERBATTLERD2_Y if pkmn.index==2
  996. @endspritey+=PokeBattle_SceneConstants::PLAYERBATTLERD1_Y if pkmn.index==0
  997. @endspritey+=PokeBattle_SceneConstants::PLAYERBATTLERD2_Y if pkmn.index==2
  998. else
  999. @spritey+=PokeBattle_SceneConstants::PLAYERBATTLER_Y
  1000. @endspritey+=PokeBattle_SceneConstants::PLAYERBATTLER_Y
  1001. end
  1002. @animdone=false
  1003. @frame=0
  1004. end
  1005.  
  1006. def disposed?
  1007. return @disposed
  1008. end
  1009.  
  1010. def animdone?
  1011. return @animdone
  1012. end
  1013.  
  1014. def dispose
  1015. return if disposed?
  1016. @disposed=true
  1017. end
  1018.  
  1019. def update
  1020. return if disposed?
  1021. @frame+=1
  1022. if @frame==4
  1023. @PokemonBattlerSprite.visible=true
  1024. @PokemonBattlerSprite.zoom_x=STARTZOOM
  1025. @PokemonBattlerSprite.zoom_y=STARTZOOM
  1026. pbSEPlay("Battle recall")
  1027. pbSpriteSetCenter(@PokemonBattlerSprite,@spritex,@spritey)
  1028. if @illusionpoke
  1029. pbPlayCry(@illusionpoke)
  1030. else
  1031. if @pkmn.pokemon
  1032. pbPlayCry(@pkmn.pokemon)
  1033. else
  1034. pbPlayCrySpecies(@pkmn.species,@pkmn.form)
  1035. end
  1036. end
  1037. end
  1038. if @frame>8 && @frame<=16
  1039. color=Color.new(248,248,248,256-(16-@frame)*32)
  1040. @spritehash["enemybase"].color=color
  1041. @spritehash["playerbase"].color=color
  1042. @spritehash["battlebg"].color=color
  1043. for i in 0...4
  1044. @spritehash["shadow#{i}"].color=color if @spritehash["shadow#{i}"]
  1045. end
  1046. end
  1047. if @frame>16 && @frame<=24
  1048. color=Color.new(248,248,248,(24-@frame)*32)
  1049. tone=(24-@frame)*32
  1050. @PokemonBattlerSprite.tone=Tone.new(tone,tone,tone,tone)
  1051. @spritehash["enemybase"].color=color
  1052. @spritehash["playerbase"].color=color
  1053. @spritehash["battlebg"].color=color
  1054. for i in 0...4
  1055. @spritehash["shadow#{i}"].color=color if @spritehash["shadow#{i}"]
  1056. end
  1057. end
  1058. if @frame>5 && @PokemonBattlerSprite.zoom_x<1.0
  1059. @PokemonBattlerSprite.zoom_x+=0.1
  1060. @PokemonBattlerSprite.zoom_y+=0.1
  1061. @PokemonBattlerSprite.zoom_x=1.0 if @PokemonBattlerSprite.zoom_x > 1.0
  1062. @PokemonBattlerSprite.zoom_y=1.0 if @PokemonBattlerSprite.zoom_y > 1.0
  1063. pbSpriteSetCenter(@PokemonBattlerSprite,@spritex,0)
  1064. @PokemonBattlerSprite.y=@spritey+(@endspritey-@spritey)*@PokemonBattlerSprite.zoom_y
  1065. end
  1066. if @PokemonBattlerSprite.tone.gray<=0 && @PokemonBattlerSprite.zoom_x>=1.0
  1067. @animdone=true
  1068. end
  1069. end
  1070. end
  1071.  
  1072.  
  1073.  
  1074. #===============================================================================
  1075. # Shows the enemy trainer(s) and the enemy party lineup sliding off screen.
  1076. # Doesn't show the ball thrown or the Pokémon.
  1077. #===============================================================================
  1078. class TrainerFadeAnimation
  1079. def initialize(sprites)
  1080. @frame=0
  1081. @sprites=sprites
  1082. @animdone=false
  1083. end
  1084.  
  1085. def animdone?
  1086. return @animdone
  1087. end
  1088.  
  1089. def update
  1090. return if @animdone
  1091. @frame+=1
  1092. @sprites["trainer"].x+=8
  1093. @sprites["trainer2"].x+=8 if @sprites["trainer2"]
  1094. @sprites["partybarfoe"].x+=8
  1095. @sprites["partybarfoe"].opacity-=12
  1096. for i in 0...6
  1097. @sprites["enemy#{i}"].opacity-=12
  1098. @sprites["enemy#{i}"].x+=8 if @frame>=i*4
  1099. end
  1100. @animdone=true if @sprites["trainer"].x>=Graphics.width &&
  1101. (!@sprites["trainer2"] || @sprites["trainer2"].x>=Graphics.width)
  1102. end
  1103. end
  1104.  
  1105.  
  1106.  
  1107. #===============================================================================
  1108. # Shows the player (and partner) and the player party lineup sliding off screen.
  1109. # Shows the player's/partner's throwing animation (if they have one).
  1110. # Doesn't show the ball thrown or the Pokémon.
  1111. #===============================================================================
  1112. class PlayerFadeAnimation
  1113. def initialize(sprites)
  1114. @frame=0
  1115. @sprites=sprites
  1116. @animdone=false
  1117. end
  1118.  
  1119. def animdone?
  1120. return @animdone
  1121. end
  1122.  
  1123. def update
  1124. return if @animdone
  1125. @frame+=1
  1126. @sprites["player"].x-=8
  1127. @sprites["playerB"].x-=8 if @sprites["playerB"]
  1128. @sprites["partybarplayer"].x-=8
  1129. @sprites["partybarplayer"].opacity-=12
  1130. for i in 0...6
  1131. if @sprites["player#{i}"]
  1132. @sprites["player#{i}"].opacity-=12
  1133. @sprites["player#{i}"].x-=8 if @frame>=i*4
  1134. end
  1135. end
  1136. pa=@sprites["player"]
  1137. pb=@sprites["playerB"]
  1138. pawidth=128
  1139. pbwidth=128
  1140. if (pa && pa.bitmap && !pa.bitmap.disposed?)
  1141. if pa.bitmap.height<pa.bitmap.width
  1142. numframes=pa.bitmap.width/pa.bitmap.height # Number of frames
  1143. pawidth=pa.bitmap.width/numframes # Width per frame
  1144. @sprites["player"].src_rect.x=pawidth*1 if @frame>0
  1145. @sprites["player"].src_rect.x=pawidth*2 if @frame>8
  1146. @sprites["player"].src_rect.x=pawidth*3 if @frame>12
  1147. @sprites["player"].src_rect.x=pawidth*4 if @frame>16
  1148. @sprites["player"].src_rect.width=pawidth
  1149. else
  1150. pawidth=pa.bitmap.width
  1151. @sprites["player"].src_rect.x=0
  1152. @sprites["player"].src_rect.width=pawidth
  1153. end
  1154. end
  1155. if (pb && pb.bitmap && !pb.bitmap.disposed?)
  1156. if pb.bitmap.height<pb.bitmap.width
  1157. numframes=pb.bitmap.width/pb.bitmap.height # Number of frames
  1158. pbwidth=pb.bitmap.width/numframes # Width per frame
  1159. @sprites["playerB"].src_rect.x=pbwidth*1 if @frame>0
  1160. @sprites["playerB"].src_rect.x=pbwidth*2 if @frame>8
  1161. @sprites["playerB"].src_rect.x=pbwidth*3 if @frame>12
  1162. @sprites["playerB"].src_rect.x=pbwidth*4 if @frame>16
  1163. @sprites["playerB"].src_rect.width=pbwidth
  1164. else
  1165. pbwidth=pb.bitmap.width
  1166. @sprites["playerB"].src_rect.x=0
  1167. @sprites["playerB"].src_rect.width=pbwidth
  1168. end
  1169. end
  1170. if pb
  1171. @animdone=true if pb.x<=-pbwidth
  1172. else
  1173. @animdone=true if pa.x<=-pawidth
  1174. end
  1175. end
  1176. end
  1177.  
  1178.  
  1179.  
  1180. #===============================================================================
  1181. # Shows the player's Poké Ball being thrown to capture a Pokémon.
  1182. #===============================================================================
  1183. def pokeballThrow(ball,shakes,critical,targetBattler,scene,battler,burst=-1,showplayer=false)
  1184. balltype=pbGetBallType(ball)
  1185. animtrainer=false
  1186. if showplayer && @sprites["player"].bitmap.width>@sprites["player"].bitmap.height
  1187. animtrainer=true
  1188. end
  1189. oldvisible=@sprites["shadow#{targetBattler}"].visible
  1190. @sprites["shadow#{targetBattler}"].visible=false
  1191. ball=sprintf("Graphics/Pictures/Battle/ball_%02d",balltype)
  1192. ballopen=sprintf("Graphics/Pictures/Battle/ball_%02d_open",balltype)
  1193. # sprites
  1194. spritePoke=@sprites["pokemon#{targetBattler}"]
  1195. spriteBall=IconSprite.new(0,0,@viewport)
  1196. spriteBall.visible=false
  1197. spritePlayer=@sprites["player"] if animtrainer
  1198. # pictures
  1199. pictureBall=PictureEx.new(spritePoke.z+1)
  1200. picturePoke=PictureEx.new(spritePoke.z)
  1201. dims=[spritePoke.x,spritePoke.y]
  1202. center=getSpriteCenter(@sprites["pokemon#{targetBattler}"])
  1203. if @battle.doublebattle
  1204. ballendy=PokeBattle_SceneConstants::FOEBATTLERD1_Y-4 if targetBattler==1
  1205. ballendy=PokeBattle_SceneConstants::FOEBATTLERD2_Y-4 if targetBattler==3
  1206. else
  1207. ballendy=PokeBattle_SceneConstants::FOEBATTLER_Y-4
  1208. end
  1209. if animtrainer
  1210. picturePlayer=PictureEx.new(spritePoke.z+2)
  1211. playerpos=[@sprites["player"].x,@sprites["player"].y]
  1212. end
  1213. # starting positions
  1214. pictureBall.moveVisible(1,true)
  1215. pictureBall.moveName(1,ball)
  1216. pictureBall.moveOrigin(1,PictureOrigin::Center)
  1217. if animtrainer
  1218. pictureBall.moveXY(0,1,64,256)
  1219. else
  1220. pictureBall.moveXY(0,1,10,180)
  1221. end
  1222. picturePoke.moveVisible(1,true)
  1223. picturePoke.moveOrigin(1,PictureOrigin::Center)
  1224. picturePoke.moveXY(0,1,center[0],center[1])
  1225. if animtrainer
  1226. picturePlayer.moveVisible(1,true)
  1227. picturePlayer.moveName(1,spritePlayer.name)
  1228. picturePlayer.moveOrigin(1,PictureOrigin::TopLeft)
  1229. picturePlayer.moveXY(0,1,playerpos[0],playerpos[1])
  1230. end
  1231. # directives
  1232. picturePoke.moveSE(1,"Audio/SE/Battle throw")
  1233. if animtrainer
  1234. pictureBall.moveCurve(30,1,64,256,30+Graphics.width/2,10,center[0],center[1])
  1235. pictureBall.moveAngle(30,1,-720)
  1236. else
  1237. pictureBall.moveCurve(30,1,150,70,30+Graphics.width/2,10,center[0],center[1])
  1238. pictureBall.moveAngle(30,1,-1080)
  1239. end
  1240. pictureBall.moveAngle(0,pictureBall.totalDuration,0)
  1241. delay=pictureBall.totalDuration+4
  1242. picturePoke.moveTone(10,delay,Tone.new(0,-224,-224,0))
  1243. delay=picturePoke.totalDuration
  1244. picturePoke.moveSE(delay,"Audio/SE/Battle recall")
  1245. pictureBall.moveName(delay+4,ballopen)
  1246. if animtrainer
  1247. picturePlayer.moveSrc(1,@sprites["player"].bitmap.height,0)
  1248. picturePlayer.moveXY(0,1,playerpos[0]-14,playerpos[1])
  1249. picturePlayer.moveSrc(4,@sprites["player"].bitmap.height*2,0)
  1250. picturePlayer.moveXY(0,4,playerpos[0]-12,playerpos[1])
  1251. picturePlayer.moveSrc(8,@sprites["player"].bitmap.height*3,0)
  1252. picturePlayer.moveXY(0,8,playerpos[0]+20,playerpos[1])
  1253. picturePlayer.moveSrc(16,@sprites["player"].bitmap.height*4,0)
  1254. picturePlayer.moveXY(0,16,playerpos[0]+16,playerpos[1])
  1255. picturePlayer.moveSrc(40,0,0)
  1256. picturePlayer.moveXY(0,40,playerpos[0],playerpos[1])
  1257. end
  1258. loop do
  1259. pictureBall.update
  1260. picturePoke.update
  1261. picturePlayer.update if animtrainer
  1262. setPictureIconSprite(spriteBall,pictureBall)
  1263. setPictureSprite(spritePoke,picturePoke)
  1264. setPictureIconSprite(spritePlayer,picturePlayer) if animtrainer
  1265. pbGraphicsUpdate
  1266. pbInputUpdate
  1267. pbFrameUpdate
  1268. break if !pictureBall.running? && !picturePoke.running?
  1269. end
  1270. # Burst animation here
  1271. if burst>=0 && scene.battle.battlescene
  1272. scene.pbCommonAnimation("BallBurst#{burst}",battler,nil)
  1273. end
  1274. pictureBall.clearProcesses
  1275. picturePoke.clearProcesses
  1276. delay=0
  1277. picturePoke.moveZoom(15,delay,0)
  1278. picturePoke.moveXY(15,delay,center[0],center[1])
  1279. picturePoke.moveSE(delay+10,"Audio/SE/Battle jump to ball")
  1280. picturePoke.moveVisible(delay+15,false)
  1281. pictureBall.moveName(picturePoke.totalDuration+2,ball)
  1282. delay=pictureBall.totalDuration+6
  1283. if critical
  1284. pictureBall.moveSE(delay,"Audio/SE/Battle ball shake")
  1285. pictureBall.moveXY(2,delay,center[0]+4,center[1])
  1286. pictureBall.moveXY(4,pictureBall.totalDuration,center[0]-4,center[1])
  1287. pictureBall.moveSE(pictureBall.totalDuration,"Audio/SE/Battle ball shake")
  1288. pictureBall.moveXY(4,pictureBall.totalDuration,center[0]+4,center[1])
  1289. pictureBall.moveXY(4,pictureBall.totalDuration,center[0]-4,center[1])
  1290. pictureBall.moveXY(2,pictureBall.totalDuration,center[0],center[1])
  1291. delay=pictureBall.totalDuration+4
  1292. end
  1293. pictureBall.moveXY(10,delay,center[0],ballendy)
  1294. pictureBall.moveSE(pictureBall.totalDuration,"Audio/SE/Battle ball drop")
  1295. pictureBall.moveXY(5,pictureBall.totalDuration+2,center[0],ballendy-((ballendy-center[1])/2))
  1296. pictureBall.moveXY(5,pictureBall.totalDuration+2,center[0],ballendy)
  1297. pictureBall.moveSE(pictureBall.totalDuration,"Audio/SE/Battle ball drop")
  1298. pictureBall.moveXY(3,pictureBall.totalDuration+2,center[0],ballendy-((ballendy-center[1])/4))
  1299. pictureBall.moveXY(3,pictureBall.totalDuration+2,center[0],ballendy)
  1300. pictureBall.moveSE(pictureBall.totalDuration,"Audio/SE/Battle ball drop")
  1301. pictureBall.moveXY(1,pictureBall.totalDuration+2,center[0],ballendy-((ballendy-center[1])/8))
  1302. pictureBall.moveXY(1,pictureBall.totalDuration+2,center[0],ballendy)
  1303. pictureBall.moveSE(pictureBall.totalDuration,"Audio/SE/Battle ball drop")
  1304. picturePoke.moveXY(0,pictureBall.totalDuration,center[0],ballendy)
  1305. delay=pictureBall.totalDuration+18# if shakes==0
  1306. numshakes = (critical) ? 1 : [shakes,3].min
  1307. numshakes.times do
  1308. pictureBall.moveSE(delay,"Audio/SE/Battle ball shake")
  1309. pictureBall.moveXY(3,delay,center[0]-8,ballendy)
  1310. pictureBall.moveAngle(3,delay,20) # positive means counterclockwise
  1311. delay=pictureBall.totalDuration
  1312. pictureBall.moveXY(6,delay,center[0]+8,ballendy)
  1313. pictureBall.moveAngle(6,delay,-20) # negative means clockwise
  1314. delay=pictureBall.totalDuration
  1315. pictureBall.moveXY(3,delay,center[0],ballendy)
  1316. pictureBall.moveAngle(3,delay,0)
  1317. delay=pictureBall.totalDuration+18
  1318. end
  1319. if shakes<4
  1320. picturePoke.moveSE(delay,"Audio/SE/Battle recall")
  1321. pictureBall.moveName(delay,ballopen)
  1322. pictureBall.moveVisible(delay+10,false)
  1323. picturePoke.moveVisible(delay,true)
  1324. picturePoke.moveZoom(15,delay,100)
  1325. picturePoke.moveXY(15,delay,center[0],center[1])
  1326. picturePoke.moveTone(0,delay,Tone.new(248,248,248,248))
  1327. picturePoke.moveTone(24,delay,Tone.new(0,0,0,0))
  1328. delay=picturePoke.totalDuration
  1329. end
  1330. pictureBall.moveXY(0,delay,center[0],ballendy)
  1331. picturePoke.moveOrigin(picturePoke.totalDuration,PictureOrigin::TopLeft)
  1332. picturePoke.moveXY(0,picturePoke.totalDuration,dims[0],dims[1])
  1333. loop do
  1334. pictureBall.update
  1335. picturePoke.update
  1336. setPictureIconSprite(spriteBall,pictureBall)
  1337. setPictureSprite(spritePoke,picturePoke)
  1338. pbGraphicsUpdate
  1339. pbInputUpdate
  1340. pbFrameUpdate
  1341. break if !pictureBall.running? && !picturePoke.running?
  1342. end
  1343. if shakes<4
  1344. @sprites["shadow#{targetBattler}"].visible=oldvisible
  1345. spriteBall.dispose
  1346. else
  1347. spriteBall.tone=Tone.new(-64,-64,-64,128)
  1348. pbSEPlay("Battle ball drop",100,150)
  1349. @sprites["capture"]=spriteBall
  1350. spritePoke.visible=false
  1351. end
  1352. end
  1353.  
  1354.  
  1355.  
  1356. #===============================================================================
  1357. # Battle scene (the visuals of the battle)
  1358. #===============================================================================
  1359. class PokeBattle_Scene
  1360. attr_accessor :abortable
  1361. attr_reader :viewport
  1362. attr_reader :sprites
  1363. BLANK = 0
  1364. MESSAGEBOX = 1
  1365. COMMANDBOX = 2
  1366. FIGHTBOX = 3
  1367.  
  1368. def initialize
  1369. @battle=nil
  1370. @lastcmd=[0,0,0,0]
  1371. @lastmove=[0,0,0,0]
  1372. @pkmnwindows=[nil,nil,nil,nil]
  1373. @sprites={}
  1374. @battlestart=true
  1375. @messagemode=false
  1376. @abortable=false
  1377. @aborted=false
  1378. end
  1379.  
  1380. def pbUpdate
  1381. partyAnimationUpdate
  1382. @sprites["battlebg"].update if @sprites["battlebg"].respond_to?("update")
  1383. end
  1384.  
  1385. def pbGraphicsUpdate
  1386. partyAnimationUpdate
  1387. @sprites["battlebg"].update if @sprites["battlebg"].respond_to?("update")
  1388. Graphics.update
  1389. end
  1390.  
  1391. def pbInputUpdate
  1392. Input.update
  1393. if Input.trigger?(Input::B) && @abortable && !@aborted
  1394. @aborted=true
  1395. @battle.pbAbort
  1396. end
  1397. end
  1398.  
  1399. def pbShowWindow(windowtype)
  1400. @sprites["messagebox"].visible = (windowtype==MESSAGEBOX ||
  1401. windowtype==COMMANDBOX ||
  1402. windowtype==FIGHTBOX ||
  1403. windowtype==BLANK )
  1404. @sprites["messagewindow"].visible = (windowtype==MESSAGEBOX)
  1405. @sprites["commandwindow"].visible = (windowtype==COMMANDBOX)
  1406. @sprites["fightwindow"].visible = (windowtype==FIGHTBOX)
  1407. end
  1408.  
  1409. def pbSetMessageMode(mode)
  1410. @messagemode=mode
  1411. msgwindow=@sprites["messagewindow"]
  1412. if mode # Within Pokémon command
  1413. msgwindow.baseColor=PokeBattle_SceneConstants::MENUBASECOLOR
  1414. msgwindow.shadowColor=PokeBattle_SceneConstants::MENUSHADOWCOLOR
  1415. msgwindow.opacity=255
  1416. msgwindow.x=16
  1417. msgwindow.width=Graphics.width
  1418. msgwindow.height=96
  1419. msgwindow.y=Graphics.height-msgwindow.height+2
  1420. else
  1421. msgwindow.baseColor=PokeBattle_SceneConstants::MESSAGEBASECOLOR
  1422. msgwindow.shadowColor=PokeBattle_SceneConstants::MESSAGESHADOWCOLOR
  1423. msgwindow.opacity=0
  1424. msgwindow.x=16
  1425. msgwindow.width=Graphics.width-32
  1426. msgwindow.height=96
  1427. msgwindow.y=Graphics.height-msgwindow.height+2
  1428. end
  1429. end
  1430.  
  1431. def pbWaitMessage
  1432. if @briefmessage
  1433. pbShowWindow(MESSAGEBOX)
  1434. cw=@sprites["messagewindow"]
  1435. 40.times do
  1436. pbGraphicsUpdate
  1437. pbInputUpdate
  1438. pbFrameUpdate(cw)
  1439. end
  1440. cw.text=""
  1441. cw.visible=false
  1442. @briefmessage=false
  1443. end
  1444. end
  1445.  
  1446. def pbDisplay(msg,brief=false)
  1447. pbDisplayMessage(msg,brief)
  1448. end
  1449.  
  1450. def pbDisplayMessage(msg,brief=false)
  1451. pbWaitMessage
  1452. pbRefresh
  1453. pbShowWindow(MESSAGEBOX)
  1454. cw=@sprites["messagewindow"]
  1455. cw.text=msg
  1456. i=0
  1457. loop do
  1458. pbGraphicsUpdate
  1459. pbInputUpdate
  1460. pbFrameUpdate(cw)
  1461. if i==40
  1462. cw.text=""
  1463. cw.visible=false
  1464. return
  1465. end
  1466. if Input.trigger?(Input::C) || @abortable
  1467. if cw.pausing?
  1468. pbPlayDecisionSE() if !@abortable
  1469. cw.resume
  1470. end
  1471. end
  1472. if !cw.busy?
  1473. if brief
  1474. @briefmessage=true
  1475. return
  1476. end
  1477. i+=1
  1478. end
  1479. end
  1480. end
  1481.  
  1482. def pbDisplayPausedMessage(msg)
  1483. pbWaitMessage
  1484. pbRefresh
  1485. pbShowWindow(MESSAGEBOX)
  1486. if @messagemode
  1487. @switchscreen.pbDisplay(msg)
  1488. return
  1489. end
  1490. cw=@sprites["messagewindow"]
  1491. cw.text=_INTL("{1}\1",msg)
  1492. loop do
  1493. pbGraphicsUpdate
  1494. pbInputUpdate
  1495. pbFrameUpdate(cw)
  1496. if Input.trigger?(Input::C) || @abortable
  1497. if cw.busy?
  1498. pbPlayDecisionSE() if cw.pausing? && !@abortable
  1499. cw.resume
  1500. elsif !inPartyAnimation?
  1501. cw.text=""
  1502. pbPlayDecisionSE()
  1503. cw.visible=false if @messagemode
  1504. return
  1505. end
  1506. end
  1507. cw.update
  1508. end
  1509. end
  1510.  
  1511. def pbDisplayConfirmMessage(msg)
  1512. return pbShowCommands(msg,[_INTL("Yes"),_INTL("No")],1)==0
  1513. end
  1514.  
  1515. def pbShowCommands(msg,commands,defaultValue)
  1516. pbWaitMessage
  1517. pbRefresh
  1518. pbShowWindow(MESSAGEBOX)
  1519. dw=@sprites["messagewindow"]
  1520. dw.text=msg
  1521. cw = Window_CommandPokemon.new(commands)
  1522. cw.x=Graphics.width-cw.width
  1523. cw.y=Graphics.height-cw.height-dw.height
  1524. cw.index=0
  1525. cw.viewport=@viewport
  1526. pbRefresh
  1527. loop do
  1528. cw.visible=!dw.busy?
  1529. pbGraphicsUpdate
  1530. pbInputUpdate
  1531. pbFrameUpdate(cw)
  1532. dw.update
  1533. if Input.trigger?(Input::B) && defaultValue>=0
  1534. if dw.busy?
  1535. pbPlayDecisionSE() if dw.pausing?
  1536. dw.resume
  1537. else
  1538. cw.dispose
  1539. dw.text=""
  1540. return defaultValue
  1541. end
  1542. end
  1543. if Input.trigger?(Input::C)
  1544. if dw.busy?
  1545. pbPlayDecisionSE() if dw.pausing?
  1546. dw.resume
  1547. else
  1548. cw.dispose
  1549. dw.text=""
  1550. return cw.index
  1551. end
  1552. end
  1553. end
  1554. end
  1555.  
  1556. def pbFrameUpdate(cw=nil)
  1557. cw.update if cw
  1558. for i in 0...4
  1559. if @sprites["battlebox#{i}"]
  1560. @sprites["battlebox#{i}"].update
  1561. end
  1562. if @sprites["pokemon#{i}"]
  1563. @sprites["pokemon#{i}"].update
  1564. end
  1565. end
  1566. end
  1567.  
  1568. def pbRefresh
  1569. for i in 0...4
  1570. if @sprites["battlebox#{i}"]
  1571. @sprites["battlebox#{i}"].refresh
  1572. end
  1573. end
  1574. end
  1575.  
  1576. def pbAddSprite(id,x,y,filename,viewport)
  1577. sprite=IconSprite.new(x,y,viewport)
  1578. if filename
  1579. sprite.setBitmap(filename) rescue nil
  1580. end
  1581. @sprites[id]=sprite
  1582. return sprite
  1583. end
  1584.  
  1585. def pbAddPlane(id,filename,viewport)
  1586. sprite=AnimatedPlane.new(viewport)
  1587. if filename
  1588. sprite.setBitmap(filename)
  1589. end
  1590. @sprites[id]=sprite
  1591. return sprite
  1592. end
  1593.  
  1594. def pbDisposeSprites
  1595. pbDisposeSpriteHash(@sprites)
  1596. end
  1597.  
  1598. def pbBeginCommandPhase
  1599. # Called whenever a new round begins.
  1600. @battlestart=false
  1601. end
  1602.  
  1603. def pbShowOpponent(index)
  1604. if @battle.opponent
  1605. if @battle.opponent.is_a?(Array)
  1606. trainerfile=pbTrainerSpriteFile(@battle.opponent[index].trainertype)
  1607. else
  1608. trainerfile=pbTrainerSpriteFile(@battle.opponent.trainertype)
  1609. end
  1610. else
  1611. trainerfile="Graphics/Characters/trfront"
  1612. end
  1613. pbAddSprite("trainer",Graphics.width,PokeBattle_SceneConstants::FOETRAINER_Y,
  1614. trainerfile,@viewport)
  1615. if @sprites["trainer"].bitmap
  1616. @sprites["trainer"].y-=@sprites["trainer"].bitmap.height
  1617. @sprites["trainer"].z=8
  1618. end
  1619. 20.times do
  1620. pbGraphicsUpdate
  1621. pbInputUpdate
  1622. pbFrameUpdate
  1623. @sprites["trainer"].x-=6
  1624. end
  1625. end
  1626.  
  1627. def pbHideOpponent
  1628. 20.times do
  1629. pbGraphicsUpdate
  1630. pbInputUpdate
  1631. pbFrameUpdate
  1632. @sprites["trainer"].x+=6
  1633. end
  1634. end
  1635.  
  1636. def pbShowHelp(text)
  1637. @sprites["helpwindow"].resizeToFit(text,Graphics.width)
  1638. @sprites["helpwindow"].y=0
  1639. @sprites["helpwindow"].x=0
  1640. @sprites["helpwindow"].text=text
  1641. @sprites["helpwindow"].visible=true
  1642. end
  1643.  
  1644. def pbHideHelp
  1645. @sprites["helpwindow"].visible=false
  1646. end
  1647.  
  1648. def pbBackdrop
  1649. environ=@battle.environment
  1650. # Choose backdrop
  1651. backdrop="Field"
  1652. if environ==PBEnvironment::Cave
  1653. backdrop="Cave"
  1654. elsif environ==PBEnvironment::MovingWater || environ==PBEnvironment::StillWater
  1655. backdrop="Water"
  1656. elsif environ==PBEnvironment::Underwater
  1657. backdrop="Underwater"
  1658. elsif environ==PBEnvironment::Rock
  1659. backdrop="Mountain"
  1660. else
  1661. if !$game_map || !pbGetMetadata($game_map.map_id,MetadataOutdoor)
  1662. backdrop="IndoorA"
  1663. end
  1664. end
  1665. if $game_map
  1666. back=pbGetMetadata($game_map.map_id,MetadataBattleBack)
  1667. if back && back!=""
  1668. backdrop=back
  1669. end
  1670. end
  1671. if $PokemonGlobal && $PokemonGlobal.nextBattleBack
  1672. backdrop=$PokemonGlobal.nextBattleBack
  1673. end
  1674. # Choose bases
  1675. base=""
  1676. trialname=""
  1677. if environ==PBEnvironment::Grass || environ==PBEnvironment::TallGrass
  1678. trialname="Grass"
  1679. elsif environ==PBEnvironment::Sand
  1680. trialname="Sand"
  1681. elsif $PokemonGlobal.surfing
  1682. trialname="Water"
  1683. end
  1684. if pbResolveBitmap(sprintf("Graphics/Battlebacks/playerbase"+backdrop+trialname))
  1685. base=trialname
  1686. end
  1687. # Choose time of day
  1688. time=""
  1689. if ENABLESHADING
  1690. trialname=""
  1691. timenow=pbGetTimeNow
  1692. if PBDayNight.isNight?(timenow)
  1693. trialname="Night"
  1694. elsif PBDayNight.isEvening?(timenow)
  1695. trialname="Eve"
  1696. end
  1697. if pbResolveBitmap(sprintf("Graphics/Battlebacks/battlebg"+backdrop+trialname))
  1698. time=trialname
  1699. end
  1700. end
  1701. # Apply graphics
  1702. battlebg="Graphics/Battlebacks/battlebg"+backdrop+time
  1703. enemybase="Graphics/Battlebacks/enemybase"+backdrop+base+time
  1704. playerbase="Graphics/Battlebacks/playerbase"+backdrop+base+time
  1705. pbAddPlane("battlebg",battlebg,@viewport)
  1706. pbAddSprite("playerbase",
  1707. PokeBattle_SceneConstants::PLAYERBASEX,
  1708. PokeBattle_SceneConstants::PLAYERBASEY,playerbase,@viewport)
  1709. @sprites["playerbase"].x-=@sprites["playerbase"].bitmap.width/2 if @sprites["playerbase"].bitmap!=nil
  1710. @sprites["playerbase"].y-=@sprites["playerbase"].bitmap.height if @sprites["playerbase"].bitmap!=nil
  1711. pbAddSprite("enemybase",
  1712. PokeBattle_SceneConstants::FOEBASEX,
  1713. PokeBattle_SceneConstants::FOEBASEY,enemybase,@viewport)
  1714. @sprites["enemybase"].x-=@sprites["enemybase"].bitmap.width/2 if @sprites["enemybase"].bitmap!=nil
  1715. @sprites["enemybase"].y-=@sprites["enemybase"].bitmap.height/2 if @sprites["enemybase"].bitmap!=nil
  1716. @sprites["battlebg"].z=0
  1717. @sprites["playerbase"].z=1
  1718. @sprites["enemybase"].z=1
  1719. end
  1720.  
  1721. # Returns whether the party line-ups are currently appearing on-screen
  1722. def inPartyAnimation?
  1723. return @enablePartyAnim && @partyAnimPhase<3
  1724. end
  1725.  
  1726. # Shows the party line-ups appearing on-screen
  1727. def partyAnimationUpdate
  1728. return if !inPartyAnimation?
  1729. ballmovedist=16 # How far a ball moves each frame
  1730. # Bar slides on
  1731. if @partyAnimPhase==0
  1732. @sprites["partybarfoe"].x+=16
  1733. @sprites["partybarplayer"].x-=16
  1734. if @sprites["partybarfoe"].x+@sprites["partybarfoe"].bitmap.width>=PokeBattle_SceneConstants::FOEPARTYBAR_X
  1735. @sprites["partybarfoe"].x=PokeBattle_SceneConstants::FOEPARTYBAR_X-@sprites["partybarfoe"].bitmap.width
  1736. @sprites["partybarplayer"].x=PokeBattle_SceneConstants::PLAYERPARTYBAR_X
  1737. @partyAnimPhase=1
  1738. end
  1739. return
  1740. end
  1741. # Set up all balls ready to slide on
  1742. if @partyAnimPhase==1
  1743. @xposplayer=PokeBattle_SceneConstants::PLAYERPARTYBALL1_X
  1744. counter=0
  1745. # Make sure the ball starts off-screen
  1746. while @xposplayer<Graphics.width
  1747. counter+=1; @xposplayer+=ballmovedist
  1748. end
  1749. @xposenemy=PokeBattle_SceneConstants::FOEPARTYBALL1_X-counter*ballmovedist
  1750. for i in 0...6
  1751. # Choose the ball's graphic (player's side)
  1752. ballgraphic="Graphics/Pictures/Battle/icon_ball_empty"
  1753. if i<@battle.party1.length && @battle.party1[i]
  1754. if @battle.party1[i].hp<=0 || @battle.party1[i].isEgg?
  1755. ballgraphic="Graphics/Pictures/Battle/icon_ball_faint"
  1756. elsif @battle.party1[i].status>0
  1757. ballgraphic="Graphics/Pictures/Battle/icon_ball_status"
  1758. else
  1759. ballgraphic="Graphics/Pictures/Battle/icon_ball"
  1760. end
  1761. end
  1762. pbAddSprite("player#{i}",
  1763. @xposplayer+i*ballmovedist*6,PokeBattle_SceneConstants::PLAYERPARTYBALL1_Y,
  1764. ballgraphic,@viewport)
  1765. @sprites["player#{i}"].z=41
  1766. # Choose the ball's graphic (opponent's side)
  1767. ballgraphic="Graphics/Pictures/Battle/icon_ball_empty"
  1768. enemyindex=i
  1769. if @battle.doublebattle && i>=3
  1770. enemyindex=(i%3)+@battle.pbSecondPartyBegin(1)
  1771. end
  1772. if enemyindex<@battle.party2.length && @battle.party2[enemyindex]
  1773. if @battle.party2[enemyindex].hp<=0 || @battle.party2[enemyindex].isEgg?
  1774. ballgraphic="Graphics/Pictures/Battle/icon_ball_faint"
  1775. elsif @battle.party2[enemyindex].status>0
  1776. ballgraphic="Graphics/Pictures/Battle/icon_ball_status"
  1777. else
  1778. ballgraphic="Graphics/Pictures/Battle/icon_ball"
  1779. end
  1780. end
  1781. pbAddSprite("enemy#{i}",
  1782. @xposenemy-i*ballmovedist*6,PokeBattle_SceneConstants::FOEPARTYBALL1_Y,
  1783. ballgraphic,@viewport)
  1784. @sprites["enemy#{i}"].z=41
  1785. end
  1786. @partyAnimPhase=2
  1787. end
  1788. # Balls slide on
  1789. if @partyAnimPhase==2
  1790. for i in 0...6
  1791. if @sprites["enemy#{i}"].x<PokeBattle_SceneConstants::FOEPARTYBALL1_X-i*PokeBattle_SceneConstants::FOEPARTYBALL_GAP
  1792. @sprites["enemy#{i}"].x+=ballmovedist
  1793. @sprites["player#{i}"].x-=ballmovedist
  1794. if @sprites["enemy#{i}"].x>=PokeBattle_SceneConstants::FOEPARTYBALL1_X-i*PokeBattle_SceneConstants::FOEPARTYBALL_GAP
  1795. @sprites["enemy#{i}"].x=PokeBattle_SceneConstants::FOEPARTYBALL1_X-i*PokeBattle_SceneConstants::FOEPARTYBALL_GAP
  1796. @sprites["player#{i}"].x=PokeBattle_SceneConstants::PLAYERPARTYBALL1_X+i*PokeBattle_SceneConstants::PLAYERPARTYBALL_GAP
  1797. if i==5
  1798. @partyAnimPhase=3
  1799. end
  1800. end
  1801. end
  1802. end
  1803. end
  1804. end
  1805.  
  1806. def pbStartBattle(battle)
  1807. # Called whenever the battle begins
  1808. @battle=battle
  1809. @lastcmd=[0,0,0,0]
  1810. @lastmove=[0,0,0,0]
  1811. @showingplayer=true
  1812. @showingenemy=true
  1813. @sprites.clear
  1814. @viewport=Viewport.new(0,Graphics.height/2,Graphics.width,0)
  1815. @viewport.z=99999
  1816. @traineryoffset=(Graphics.height-320) # Adjust player's side for screen size
  1817. @foeyoffset=(@traineryoffset*3/4).floor # Adjust foe's side for screen size
  1818. pbBackdrop
  1819. pbAddSprite("partybarfoe",
  1820. PokeBattle_SceneConstants::FOEPARTYBAR_X,
  1821. PokeBattle_SceneConstants::FOEPARTYBAR_Y,
  1822. "Graphics/Pictures/Battle/overlay_lineup",@viewport)
  1823. pbAddSprite("partybarplayer",
  1824. PokeBattle_SceneConstants::PLAYERPARTYBAR_X,
  1825. PokeBattle_SceneConstants::PLAYERPARTYBAR_Y,
  1826. "Graphics/Pictures/Battle/overlay_lineup",@viewport)
  1827. @sprites["partybarfoe"].x-=@sprites["partybarfoe"].bitmap.width
  1828. @sprites["partybarplayer"].mirror=true
  1829. @sprites["partybarfoe"].z=40
  1830. @sprites["partybarplayer"].z=40
  1831. @sprites["partybarfoe"].visible=false
  1832. @sprites["partybarplayer"].visible=false
  1833. if @battle.player.is_a?(Array)
  1834. trainerfile=pbPlayerSpriteBackFile(@battle.player[0].trainertype)
  1835. pbAddSprite("player",
  1836. PokeBattle_SceneConstants::PLAYERTRAINERD1_X,
  1837. PokeBattle_SceneConstants::PLAYERTRAINERD1_Y,trainerfile,@viewport)
  1838. trainerfile=pbTrainerSpriteBackFile(@battle.player[1].trainertype)
  1839. pbAddSprite("playerB",
  1840. PokeBattle_SceneConstants::PLAYERTRAINERD2_X,
  1841. PokeBattle_SceneConstants::PLAYERTRAINERD2_Y,trainerfile,@viewport)
  1842. if @sprites["player"].bitmap
  1843. if @sprites["player"].bitmap.width>@sprites["player"].bitmap.height
  1844. @sprites["player"].src_rect.x=0
  1845. @sprites["player"].src_rect.width=@sprites["player"].bitmap.width/5
  1846. end
  1847. @sprites["player"].x-=(@sprites["player"].src_rect.width/2)
  1848. @sprites["player"].y-=@sprites["player"].bitmap.height
  1849. @sprites["player"].z=30
  1850. end
  1851. if @sprites["playerB"].bitmap
  1852. if @sprites["playerB"].bitmap.width>@sprites["playerB"].bitmap.height
  1853. @sprites["playerB"].src_rect.x=0
  1854. @sprites["playerB"].src_rect.width=@sprites["playerB"].bitmap.width/5
  1855. end
  1856. @sprites["playerB"].x-=(@sprites["playerB"].src_rect.width/2)
  1857. @sprites["playerB"].y-=@sprites["playerB"].bitmap.height
  1858. @sprites["playerB"].z=31
  1859. end
  1860. else
  1861. trainerfile=pbPlayerSpriteBackFile(@battle.player.trainertype)
  1862. pbAddSprite("player",
  1863. PokeBattle_SceneConstants::PLAYERTRAINER_X,
  1864. PokeBattle_SceneConstants::PLAYERTRAINER_Y,trainerfile,@viewport)
  1865. if @sprites["player"].bitmap
  1866. if @sprites["player"].bitmap.width>@sprites["player"].bitmap.height
  1867. @sprites["player"].src_rect.x=0
  1868. @sprites["player"].src_rect.width=@sprites["player"].bitmap.width/5
  1869. end
  1870. @sprites["player"].x-=(@sprites["player"].src_rect.width/2)
  1871. @sprites["player"].y-=@sprites["player"].bitmap.height
  1872. @sprites["player"].z=30
  1873. end
  1874. end
  1875. if @battle.opponent
  1876. if @battle.opponent.is_a?(Array)
  1877. trainerfile=pbTrainerSpriteFile(@battle.opponent[1].trainertype)
  1878. pbAddSprite("trainer2",
  1879. PokeBattle_SceneConstants::FOETRAINERD2_X,
  1880. PokeBattle_SceneConstants::FOETRAINERD2_Y,trainerfile,@viewport)
  1881. trainerfile=pbTrainerSpriteFile(@battle.opponent[0].trainertype)
  1882. pbAddSprite("trainer",
  1883. PokeBattle_SceneConstants::FOETRAINERD1_X,
  1884. PokeBattle_SceneConstants::FOETRAINERD1_Y,trainerfile,@viewport)
  1885. else
  1886. trainerfile=pbTrainerSpriteFile(@battle.opponent.trainertype)
  1887. pbAddSprite("trainer",
  1888. PokeBattle_SceneConstants::FOETRAINER_X,
  1889. PokeBattle_SceneConstants::FOETRAINER_Y,trainerfile,@viewport)
  1890. end
  1891. else
  1892. trainerfile="Graphics/Characters/trfront"
  1893. pbAddSprite("trainer",
  1894. PokeBattle_SceneConstants::FOETRAINER_X,
  1895. PokeBattle_SceneConstants::FOETRAINER_Y,trainerfile,@viewport)
  1896. end
  1897. if @sprites["trainer"].bitmap
  1898. @sprites["trainer"].x-=(@sprites["trainer"].bitmap.width/2)
  1899. @sprites["trainer"].y-=@sprites["trainer"].bitmap.height
  1900. @sprites["trainer"].z=8
  1901. end
  1902. if @sprites["trainer2"] && @sprites["trainer2"].bitmap
  1903. @sprites["trainer2"].x-=(@sprites["trainer2"].bitmap.width/2)
  1904. @sprites["trainer2"].y-=@sprites["trainer2"].bitmap.height
  1905. @sprites["trainer2"].z=7
  1906. end
  1907. @sprites["shadow0"]=IconSprite.new(0,0,@viewport)
  1908. @sprites["shadow0"].z=3
  1909. pbAddSprite("shadow1",0,0,"Graphics/Pictures/Battle/object_shadow",@viewport)
  1910. @sprites["shadow1"].z=3
  1911. @sprites["shadow1"].visible=false
  1912. @sprites["pokemon0"]=PokemonBattlerSprite.new(battle.doublebattle,0,@viewport)
  1913. @sprites["pokemon0"].z=21
  1914. @sprites["pokemon1"]=PokemonBattlerSprite.new(battle.doublebattle,1,@viewport)
  1915. @sprites["pokemon1"].z=16
  1916. if battle.doublebattle
  1917. @sprites["shadow2"]=IconSprite.new(0,0,@viewport)
  1918. @sprites["shadow2"].z=3
  1919. pbAddSprite("shadow3",0,0,"Graphics/Pictures/Battle/object_shadow",@viewport)
  1920. @sprites["shadow3"].z=3
  1921. @sprites["shadow3"].visible=false
  1922. @sprites["pokemon2"]=PokemonBattlerSprite.new(battle.doublebattle,2,@viewport)
  1923. @sprites["pokemon2"].z=26
  1924. @sprites["pokemon3"]=PokemonBattlerSprite.new(battle.doublebattle,3,@viewport)
  1925. @sprites["pokemon3"].z=11
  1926. end
  1927. @sprites["battlebox0"]=PokemonDataBox.new(battle.battlers[0],battle.doublebattle,@viewport)
  1928. @sprites["battlebox1"]=PokemonDataBox.new(battle.battlers[1],battle.doublebattle,@viewport)
  1929. if battle.doublebattle
  1930. @sprites["battlebox2"]=PokemonDataBox.new(battle.battlers[2],battle.doublebattle,@viewport)
  1931. @sprites["battlebox3"]=PokemonDataBox.new(battle.battlers[3],battle.doublebattle,@viewport)
  1932. end
  1933. pbAddSprite("messagebox",0,Graphics.height-96,"Graphics/Pictures/Battle/overlay_message",@viewport)
  1934. @sprites["messagebox"].z=90
  1935. @sprites["helpwindow"]=Window_UnformattedTextPokemon.newWithSize("",0,0,32,32,@viewport)
  1936. @sprites["helpwindow"].visible=false
  1937. @sprites["helpwindow"].z=90
  1938. @sprites["messagewindow"]=Window_AdvancedTextPokemon.new("")
  1939. @sprites["messagewindow"].letterbyletter=true
  1940. @sprites["messagewindow"].viewport=@viewport
  1941. @sprites["messagewindow"].z=100
  1942. @sprites["commandwindow"]=CommandMenuDisplay.new(@viewport)
  1943. @sprites["commandwindow"].z=100
  1944. @sprites["fightwindow"]=FightMenuDisplay.new(nil,@viewport)
  1945. @sprites["fightwindow"].z=100
  1946. pbShowWindow(MESSAGEBOX)
  1947. pbSetMessageMode(false)
  1948. trainersprite1=@sprites["trainer"]
  1949. trainersprite2=@sprites["trainer2"]
  1950. if !@battle.opponent
  1951. @sprites["trainer"].visible=false
  1952. if @battle.party2.length>=1
  1953. if @battle.party2.length==1
  1954. species=@battle.party2[0].species
  1955. @sprites["pokemon1"].setPokemonBitmap(@battle.party2[0],false)
  1956. @sprites["pokemon1"].tone=Tone.new(-128,-128,-128,-128)
  1957. @sprites["pokemon1"].x=PokeBattle_SceneConstants::FOEBATTLER_X
  1958. @sprites["pokemon1"].x-=@sprites["pokemon1"].width/2
  1959. @sprites["pokemon1"].y=PokeBattle_SceneConstants::FOEBATTLER_Y
  1960. @sprites["pokemon1"].y+=adjustBattleSpriteY(@sprites["pokemon1"],species,1)
  1961. @sprites["pokemon1"].visible=true
  1962. @sprites["shadow1"].x=PokeBattle_SceneConstants::FOEBATTLER_X
  1963. @sprites["shadow1"].y=PokeBattle_SceneConstants::FOEBATTLER_Y
  1964. @sprites["shadow1"].x-=@sprites["shadow1"].bitmap.width/2 if @sprites["shadow1"].bitmap!=nil
  1965. @sprites["shadow1"].y-=@sprites["shadow1"].bitmap.height/2 if @sprites["shadow1"].bitmap!=nil
  1966. @sprites["shadow1"].visible=showShadow?(species)
  1967. trainersprite1=@sprites["pokemon1"]
  1968. elsif @battle.party2.length==2
  1969. species=@battle.party2[0].species
  1970. @sprites["pokemon1"].setPokemonBitmap(@battle.party2[0],false)
  1971. @sprites["pokemon1"].tone=Tone.new(-128,-128,-128,-128)
  1972. @sprites["pokemon1"].x=PokeBattle_SceneConstants::FOEBATTLERD1_X
  1973. @sprites["pokemon1"].x-=@sprites["pokemon1"].width/2
  1974. @sprites["pokemon1"].y=PokeBattle_SceneConstants::FOEBATTLERD1_Y
  1975. @sprites["pokemon1"].y+=adjustBattleSpriteY(@sprites["pokemon1"],species,1)
  1976. @sprites["pokemon1"].visible=true
  1977. @sprites["shadow1"].x=PokeBattle_SceneConstants::FOEBATTLERD1_X
  1978. @sprites["shadow1"].y=PokeBattle_SceneConstants::FOEBATTLERD1_Y
  1979. @sprites["shadow1"].x-=@sprites["shadow1"].bitmap.width/2 if @sprites["shadow1"].bitmap!=nil
  1980. @sprites["shadow1"].y-=@sprites["shadow1"].bitmap.height/2 if @sprites["shadow1"].bitmap!=nil
  1981. @sprites["shadow1"].visible=showShadow?(species)
  1982. trainersprite1=@sprites["pokemon1"]
  1983. species=@battle.party2[1].species
  1984. @sprites["pokemon3"].setPokemonBitmap(@battle.party2[1],false)
  1985. @sprites["pokemon3"].tone=Tone.new(-128,-128,-128,-128)
  1986. @sprites["pokemon3"].x=PokeBattle_SceneConstants::FOEBATTLERD2_X
  1987. @sprites["pokemon3"].x-=@sprites["pokemon3"].width/2
  1988. @sprites["pokemon3"].y=PokeBattle_SceneConstants::FOEBATTLERD2_Y
  1989. @sprites["pokemon3"].y+=adjustBattleSpriteY(@sprites["pokemon3"],species,3)
  1990. @sprites["pokemon3"].visible=true
  1991. @sprites["shadow3"].x=PokeBattle_SceneConstants::FOEBATTLERD2_X
  1992. @sprites["shadow3"].y=PokeBattle_SceneConstants::FOEBATTLERD2_Y
  1993. @sprites["shadow3"].x-=@sprites["shadow3"].bitmap.width/2 if @sprites["shadow3"].bitmap!=nil
  1994. @sprites["shadow3"].y-=@sprites["shadow3"].bitmap.height/2 if @sprites["shadow3"].bitmap!=nil
  1995. @sprites["shadow3"].visible=showShadow?(species)
  1996. trainersprite2=@sprites["pokemon3"]
  1997. end
  1998. end
  1999. end
  2000. #################
  2001. # Move trainers/bases/etc. off-screen
  2002. oldx=[]
  2003. oldx[0]=@sprites["playerbase"].x; @sprites["playerbase"].x+=Graphics.width
  2004. oldx[1]=@sprites["player"].x; @sprites["player"].x+=Graphics.width
  2005. if @sprites["playerB"]
  2006. oldx[2]=@sprites["playerB"].x; @sprites["playerB"].x+=Graphics.width
  2007. end
  2008. oldx[3]=@sprites["enemybase"].x; @sprites["enemybase"].x-=Graphics.width
  2009. oldx[4]=trainersprite1.x; trainersprite1.x-=Graphics.width
  2010. if trainersprite2
  2011. oldx[5]=trainersprite2.x; trainersprite2.x-=Graphics.width
  2012. end
  2013. oldx[6]=@sprites["shadow1"].x; @sprites["shadow1"].x-=Graphics.width
  2014. if @sprites["shadow3"]
  2015. oldx[7]=@sprites["shadow3"].x; @sprites["shadow3"].x-=Graphics.width
  2016. end
  2017. @sprites["partybarfoe"].x-=PokeBattle_SceneConstants::FOEPARTYBAR_X
  2018. @sprites["partybarplayer"].x+=Graphics.width-PokeBattle_SceneConstants::PLAYERPARTYBAR_X
  2019. #################
  2020. appearspeed=12
  2021. (1+Graphics.width/appearspeed).times do
  2022. tobreak=true
  2023. if @viewport.rect.y>0
  2024. @viewport.rect.y-=appearspeed/2
  2025. @viewport.rect.y=0 if @viewport.rect.y<0
  2026. @viewport.rect.height+=appearspeed
  2027. @viewport.rect.height=Graphics.height if @viewport.rect.height>Graphics.height
  2028. tobreak=false
  2029. end
  2030. if !tobreak
  2031. for i in @sprites
  2032. i[1].ox=@viewport.rect.x
  2033. i[1].oy=@viewport.rect.y
  2034. end
  2035. end
  2036. if @sprites["playerbase"].x>oldx[0]
  2037. @sprites["playerbase"].x-=appearspeed; tobreak=false
  2038. @sprites["playerbase"].x=oldx[0] if @sprites["playerbase"].x<oldx[0]
  2039. end
  2040. if @sprites["player"].x>oldx[1]
  2041. @sprites["player"].x-=appearspeed; tobreak=false
  2042. @sprites["player"].x=oldx[1] if @sprites["player"].x<oldx[1]
  2043. end
  2044. if @sprites["playerB"] && @sprites["playerB"].x>oldx[2]
  2045. @sprites["playerB"].x-=appearspeed; tobreak=false
  2046. @sprites["playerB"].x=oldx[2] if @sprites["playerB"].x<oldx[2]
  2047. end
  2048. if @sprites["enemybase"].x<oldx[3]
  2049. @sprites["enemybase"].x+=appearspeed; tobreak=false
  2050. @sprites["enemybase"].x=oldx[3] if @sprites["enemybase"].x>oldx[3]
  2051. end
  2052. if trainersprite1.x<oldx[4]
  2053. trainersprite1.x+=appearspeed; tobreak=false
  2054. trainersprite1.x=oldx[4] if trainersprite1.x>oldx[4]
  2055. end
  2056. if trainersprite2 && trainersprite2.x<oldx[5]
  2057. trainersprite2.x+=appearspeed; tobreak=false
  2058. trainersprite2.x=oldx[5] if trainersprite2.x>oldx[5]
  2059. end
  2060. if @sprites["shadow1"].x<oldx[6]
  2061. @sprites["shadow1"].x+=appearspeed; tobreak=false
  2062. @sprites["shadow1"].x=oldx[6] if @sprites["shadow1"].x>oldx[6]
  2063. end
  2064. if @sprites["shadow3"] && @sprites["shadow3"].x<oldx[7]
  2065. @sprites["shadow3"].x+=appearspeed; tobreak=false
  2066. @sprites["shadow3"].x=oldx[7] if @sprites["shadow3"].x>oldx[7]
  2067. end
  2068. pbGraphicsUpdate
  2069. pbInputUpdate
  2070. pbFrameUpdate
  2071. break if tobreak
  2072. end
  2073. #################
  2074. if @battle.opponent
  2075. @enablePartyAnim=true
  2076. @partyAnimPhase=0
  2077. @sprites["partybarfoe"].visible=true
  2078. @sprites["partybarplayer"].visible=true
  2079. else
  2080. pbPlayCry(@battle.party2[0]) # Play cry for wild Pokémon
  2081. @sprites["battlebox1"].appear
  2082. @sprites["battlebox3"].appear if @battle.party2.length==2
  2083. appearing=true
  2084. begin
  2085. pbGraphicsUpdate
  2086. pbInputUpdate
  2087. pbFrameUpdate
  2088. @sprites["pokemon1"].tone.red+=8 if @sprites["pokemon1"].tone.red<0
  2089. @sprites["pokemon1"].tone.blue+=8 if @sprites["pokemon1"].tone.blue<0
  2090. @sprites["pokemon1"].tone.green+=8 if @sprites["pokemon1"].tone.green<0
  2091. @sprites["pokemon1"].tone.gray+=8 if @sprites["pokemon1"].tone.gray<0
  2092. appearing=@sprites["battlebox1"].appearing
  2093. if @battle.party2.length==2
  2094. @sprites["pokemon3"].tone.red+=8 if @sprites["pokemon3"].tone.red<0
  2095. @sprites["pokemon3"].tone.blue+=8 if @sprites["pokemon3"].tone.blue<0
  2096. @sprites["pokemon3"].tone.green+=8 if @sprites["pokemon3"].tone.green<0
  2097. @sprites["pokemon3"].tone.gray+=8 if @sprites["pokemon3"].tone.gray<0
  2098. appearing=(appearing || @sprites["battlebox3"].appearing)
  2099. end
  2100. end while appearing
  2101. # Show shiny animation for wild Pokémon
  2102. if @battle.battlers[1].isShiny? && @battle.battlescene
  2103. pbCommonAnimation("Shiny",@battle.battlers[1],nil)
  2104. end
  2105. if @battle.party2.length==2
  2106. if @battle.battlers[3].isShiny? && @battle.battlescene
  2107. pbCommonAnimation("Shiny",@battle.battlers[3],nil)
  2108. end
  2109. end
  2110. end
  2111. end
  2112.  
  2113. def pbEndBattle(result)
  2114. @abortable=false
  2115. pbShowWindow(BLANK)
  2116. # Fade out all sprites
  2117. pbBGMFade(1.0)
  2118. pbFadeOutAndHide(@sprites)
  2119. pbDisposeSprites
  2120. end
  2121.  
  2122. def pbRecall(battlerindex)
  2123. @briefmessage=false
  2124. if @battle.pbIsOpposing?(battlerindex)
  2125. origin=PokeBattle_SceneConstants::FOEBATTLER_Y
  2126. if @battle.doublebattle
  2127. origin=PokeBattle_SceneConstants::FOEBATTLERD1_Y if battlerindex==1
  2128. origin=PokeBattle_SceneConstants::FOEBATTLERD2_Y if battlerindex==3
  2129. end
  2130. @sprites["shadow#{battlerindex}"].visible=false
  2131. else
  2132. origin=PokeBattle_SceneConstants::PLAYERBATTLER_Y
  2133. if @battle.doublebattle
  2134. origin=PokeBattle_SceneConstants::PLAYERBATTLERD1_Y if battlerindex==0
  2135. origin=PokeBattle_SceneConstants::PLAYERBATTLERD2_Y if battlerindex==2
  2136. end
  2137. end
  2138. spritePoke=@sprites["pokemon#{battlerindex}"]
  2139. picturePoke=PictureEx.new(spritePoke.z)
  2140. dims=[spritePoke.x,spritePoke.y]
  2141. center=getSpriteCenter(spritePoke)
  2142. # starting positions
  2143. picturePoke.moveVisible(1,true)
  2144. picturePoke.moveOrigin(1,PictureOrigin::Center)
  2145. picturePoke.moveXY(0,1,center[0],center[1])
  2146. # directives
  2147. picturePoke.moveTone(10,1,Tone.new(248,248,248,248))
  2148. delay=picturePoke.totalDuration
  2149. picturePoke.moveSE(delay,"Audio/SE/Battle recall")
  2150. picturePoke.moveZoom(15,delay,0)
  2151. picturePoke.moveXY(15,delay,center[0],origin)
  2152. picturePoke.moveVisible(picturePoke.totalDuration,false)
  2153. picturePoke.moveTone(0,picturePoke.totalDuration,Tone.new(0,0,0,0))
  2154. picturePoke.moveOrigin(picturePoke.totalDuration,PictureOrigin::TopLeft)
  2155. loop do
  2156. picturePoke.update
  2157. setPictureSprite(spritePoke,picturePoke)
  2158. pbGraphicsUpdate
  2159. pbInputUpdate
  2160. pbFrameUpdate
  2161. break if !picturePoke.running?
  2162. end
  2163. end
  2164.  
  2165. def pbTrainerSendOut(battlerindex,pkmn)
  2166. illusionpoke=@battle.battlers[battlerindex].effects[PBEffects::Illusion]
  2167. @briefmessage=false
  2168. fadeanim=nil
  2169. while inPartyAnimation?; end
  2170. if @showingenemy
  2171. fadeanim=TrainerFadeAnimation.new(@sprites)
  2172. end
  2173. frame=0
  2174. @sprites["pokemon#{battlerindex}"].setPokemonBitmap(pkmn,false)
  2175. if illusionpoke
  2176. @sprites["pokemon#{battlerindex}"].setPokemonBitmap(illusionpoke,false)
  2177. end
  2178. sendout=PokeballSendOutAnimation.new(@sprites["pokemon#{battlerindex}"],
  2179. @sprites,@battle.battlers[battlerindex],illusionpoke,@battle.doublebattle)
  2180. loop do
  2181. fadeanim.update if fadeanim
  2182. frame+=1
  2183. if frame==1
  2184. @sprites["battlebox#{battlerindex}"].appear
  2185. end
  2186. if frame>=10
  2187. sendout.update
  2188. end
  2189. pbGraphicsUpdate
  2190. pbInputUpdate
  2191. pbFrameUpdate
  2192. break if (!fadeanim || fadeanim.animdone?) && sendout.animdone? &&
  2193. !@sprites["battlebox#{battlerindex}"].appearing
  2194. end
  2195. if @battle.battlers[battlerindex].isShiny? && @battle.battlescene
  2196. pbCommonAnimation("Shiny",@battle.battlers[battlerindex],nil)
  2197. end
  2198. sendout.dispose
  2199. if @showingenemy
  2200. @showingenemy=false
  2201. pbDisposeSprite(@sprites,"trainer")
  2202. pbDisposeSprite(@sprites,"partybarfoe")
  2203. for i in 0...6
  2204. pbDisposeSprite(@sprites,"enemy#{i}")
  2205. end
  2206. end
  2207. pbRefresh
  2208. end
  2209.  
  2210. def pbSendOut(battlerindex,pkmn) # Player sending out Pokémon
  2211. while inPartyAnimation?; end
  2212. illusionpoke=@battle.battlers[battlerindex].effects[PBEffects::Illusion]
  2213. balltype=pkmn.ballused
  2214. balltype=illusionpoke.ballused if illusionpoke
  2215. ballbitmap=sprintf("Graphics/Pictures/Battle/ball_%02d",balltype)
  2216. pictureBall=PictureEx.new(32)
  2217. delay=1
  2218. pictureBall.moveVisible(delay,true)
  2219. pictureBall.moveName(delay,ballbitmap)
  2220. pictureBall.moveOrigin(delay,PictureOrigin::Center)
  2221. # Setting the ball's movement path
  2222. path=[[0, 146], [10, 134], [21, 122], [30, 112],
  2223. [39, 104], [46, 99], [53, 95], [61, 93],
  2224. [68, 93], [75, 96], [82, 102], [89, 111],
  2225. [94, 121], [100, 134], [106, 150], [111, 166],
  2226. [116, 183], [120, 199], [124, 216], [127, 238]]
  2227. spriteBall=IconSprite.new(0,0,@viewport)
  2228. spriteBall.visible=false
  2229. angle=0
  2230. multiplier=1.0
  2231. if @battle.doublebattle
  2232. multiplier=(battlerindex==0) ? 0.7 : 1.3
  2233. end
  2234. for coord in path
  2235. delay=pictureBall.totalDuration
  2236. pictureBall.moveAngle(0,delay,angle)
  2237. pictureBall.moveXY(1,delay,coord[0]*multiplier,coord[1])
  2238. angle+=40
  2239. angle%=360
  2240. end
  2241. pictureBall.adjustPosition(0,@traineryoffset)
  2242. @sprites["battlebox#{battlerindex}"].visible=false
  2243. @briefmessage=false
  2244. fadeanim=nil
  2245. if @showingplayer
  2246. fadeanim=PlayerFadeAnimation.new(@sprites)
  2247. end
  2248. frame=0
  2249. @sprites["pokemon#{battlerindex}"].setPokemonBitmap(pkmn,true)
  2250. if illusionpoke
  2251. @sprites["pokemon#{battlerindex}"].setPokemonBitmap(illusionpoke,true)
  2252. end
  2253. sendout=PokeballPlayerSendOutAnimation.new(@sprites["pokemon#{battlerindex}"],
  2254. @sprites,@battle.battlers[battlerindex],illusionpoke,@battle.doublebattle)
  2255. loop do
  2256. fadeanim.update if fadeanim
  2257. frame+=1
  2258. if frame>1 && !pictureBall.running? && !@sprites["battlebox#{battlerindex}"].appearing
  2259. @sprites["battlebox#{battlerindex}"].appear
  2260. end
  2261. if frame>=3 && !pictureBall.running?
  2262. sendout.update
  2263. end
  2264. if (frame>=10 || !fadeanim) && pictureBall.running?
  2265. pictureBall.update
  2266. setPictureIconSprite(spriteBall,pictureBall)
  2267. end
  2268. pbGraphicsUpdate
  2269. pbInputUpdate
  2270. pbFrameUpdate
  2271. break if (!fadeanim || fadeanim.animdone?) && sendout.animdone? &&
  2272. !@sprites["battlebox#{battlerindex}"].appearing
  2273. end
  2274. spriteBall.dispose
  2275. sendout.dispose
  2276. if @battle.battlers[battlerindex].isShiny? && @battle.battlescene
  2277. pbCommonAnimation("Shiny",@battle.battlers[battlerindex],nil)
  2278. end
  2279. if @showingplayer
  2280. @showingplayer=false
  2281. pbDisposeSprite(@sprites,"player")
  2282. pbDisposeSprite(@sprites,"partybarplayer")
  2283. for i in 0...6
  2284. pbDisposeSprite(@sprites,"player#{i}")
  2285. end
  2286. end
  2287. pbRefresh
  2288. end
  2289.  
  2290. def pbTrainerWithdraw(battle,pkmn)
  2291. pbRefresh
  2292. end
  2293.  
  2294. def pbWithdraw(battle,pkmn)
  2295. pbRefresh
  2296. end
  2297.  
  2298. def pbMoveString(move)
  2299. ret=move.name
  2300. typename=PBTypes.getName(move.type)
  2301. if move.id>0
  2302. ret+=_INTL(" ({1}) PP: {2}/{3}",typename,move.pp,move.totalpp)
  2303. end
  2304. return ret
  2305. end
  2306.  
  2307. def pbBeginAttackPhase
  2308. pbSelectBattler(-1)
  2309. pbGraphicsUpdate
  2310. end
  2311.  
  2312. def pbSafariStart
  2313. @briefmessage=false
  2314. @sprites["battlebox0"]=SafariDataBox.new(@battle,@viewport)
  2315. @sprites["battlebox0"].appear
  2316. loop do
  2317. @sprites["battlebox0"].update
  2318. pbGraphicsUpdate
  2319. pbInputUpdate
  2320. pbFrameUpdate
  2321. break if !@sprites["battlebox0"].appearing
  2322. end
  2323. pbRefresh
  2324. end
  2325.  
  2326. def pbResetCommandIndices
  2327. @lastcmd=[0,0,0,0]
  2328. end
  2329.  
  2330. def pbResetMoveIndex(index)
  2331. @lastmove[index]=0
  2332. end
  2333.  
  2334. def pbSafariCommandMenu(index)
  2335. pbCommandMenuEx(index,[
  2336. _INTL("What will\n{1} throw?",@battle.pbPlayer.name),
  2337. _INTL("Ball"),
  2338. _INTL("Bait"),
  2339. _INTL("Rock"),
  2340. _INTL("Run")
  2341. ],2)
  2342. end
  2343.  
  2344. # Use this method to display the list of commands.
  2345. # Return values: 0=Fight, 1=Bag, 2=Pokémon, 3=Run, 4=Call
  2346. def pbCommandMenu(index)
  2347. shadowTrainer=(hasConst?(PBTypes,:SHADOW) && @battle.opponent)
  2348. ret=pbCommandMenuEx(index,[
  2349. _INTL("What will\n{1} do?",@battle.battlers[index].name),
  2350. _INTL("Fight"),
  2351. _INTL("Bag"),
  2352. _INTL("Pokémon"),
  2353. shadowTrainer ? _INTL("Call") : _INTL("Run")
  2354. ],(shadowTrainer ? 1 : 0))
  2355. ret=4 if ret==3 && shadowTrainer # Convert "Run" to "Call"
  2356. return ret
  2357. end
  2358.  
  2359. def pbCommandMenuEx(index,texts,mode=0) # Mode: 0 - regular battle
  2360. pbShowWindow(COMMANDBOX) # 1 - Shadow Pokémon battle
  2361. cw=@sprites["commandwindow"] # 2 - Safari Zone
  2362. cw.setTexts(texts) # 3 - Bug Catching Contest
  2363. cw.index=@lastcmd[index]
  2364. cw.mode=mode
  2365. pbSelectBattler(index)
  2366. pbRefresh
  2367. loop do
  2368. pbGraphicsUpdate
  2369. pbInputUpdate
  2370. pbFrameUpdate(cw)
  2371. # Update selected command
  2372. if Input.trigger?(Input::LEFT) && (cw.index&1)==1
  2373. pbPlayCursorSE
  2374. cw.index-=1
  2375. elsif Input.trigger?(Input::RIGHT) && (cw.index&1)==0
  2376. pbPlayCursorSE
  2377. cw.index+=1
  2378. elsif Input.trigger?(Input::UP) && (cw.index&2)==2
  2379. pbPlayCursorSE
  2380. cw.index-=2
  2381. elsif Input.trigger?(Input::DOWN) && (cw.index&2)==0
  2382. pbPlayCursorSE
  2383. cw.index+=2
  2384. end
  2385. if Input.trigger?(Input::C) # Confirm choice
  2386. pbPlayDecisionSE
  2387. ret=cw.index
  2388. @lastcmd[index]=ret
  2389. return ret
  2390. elsif Input.trigger?(Input::B) && index==2 && @lastcmd[0]!=2 # Cancel
  2391. pbPlayDecisionSE
  2392. return -1
  2393. end
  2394. end
  2395. end
  2396.  
  2397. # Use this method to display the list of moves for a Pokémon
  2398. def pbFightMenu(index)
  2399. pbShowWindow(FIGHTBOX)
  2400. cw = @sprites["fightwindow"]
  2401. battler=@battle.battlers[index]
  2402. cw.battler=battler
  2403. lastIndex=@lastmove[index]
  2404. if battler.moves[lastIndex].id!=0
  2405. cw.setIndex(lastIndex)
  2406. else
  2407. cw.setIndex(0)
  2408. end
  2409. cw.megaButton=0
  2410. cw.megaButton=1 if @battle.pbCanMegaEvolve?(index)
  2411. pbSelectBattler(index)
  2412. pbRefresh
  2413. loop do
  2414. pbGraphicsUpdate
  2415. pbInputUpdate
  2416. pbFrameUpdate(cw)
  2417. # Update selected command
  2418. if Input.trigger?(Input::LEFT) && (cw.index&1)==1
  2419. pbPlayCursorSE if cw.setIndex(cw.index-1)
  2420. elsif Input.trigger?(Input::RIGHT) && (cw.index&1)==0
  2421. pbPlayCursorSE if cw.setIndex(cw.index+1)
  2422. elsif Input.trigger?(Input::UP) && (cw.index&2)==2
  2423. pbPlayCursorSE if cw.setIndex(cw.index-2)
  2424. elsif Input.trigger?(Input::DOWN) && (cw.index&2)==0
  2425. pbPlayCursorSE if cw.setIndex(cw.index+2)
  2426. end
  2427. if Input.trigger?(Input::C) # Confirm choice
  2428. ret=cw.index
  2429. pbPlayDecisionSE
  2430. @lastmove[index]=ret
  2431. return ret
  2432. elsif Input.trigger?(Input::A) # Use Mega Evolution
  2433. if @battle.pbCanMegaEvolve?(index)
  2434. @battle.pbRegisterMegaEvolution(index)
  2435. cw.megaButton=2
  2436. pbPlayDecisionSE
  2437. end
  2438. elsif Input.trigger?(Input::B) # Cancel fight menu
  2439. @lastmove[index]=cw.index
  2440. pbPlayCancelSE
  2441. return -1
  2442. end
  2443. end
  2444. end
  2445.  
  2446. # Use this method to display the inventory
  2447. # The return value is the item chosen, or 0 if the choice was canceled.
  2448. def pbItemMenu(index)
  2449. ret=0
  2450. retindex=-1
  2451. pkmnid=-1
  2452. endscene=true
  2453. oldsprites=pbFadeOutAndHide(@sprites)
  2454. oldlastpocket = $PokemonBag.lastpocket
  2455. oldchoices = $PokemonBag.getAllChoices
  2456. $PokemonBag.lastpocket = @baglastpocket if @baglastpocket!=nil
  2457. $PokemonBag.setAllChoices(@bagchoices) if @bagchoices!=nil
  2458. itemscene=PokemonBag_Scene.new
  2459. itemscene.pbStartScene($PokemonBag,true,Proc.new{|item|
  2460. $ItemData[item][ITEMBATTLEUSE]>0 || pbIsPokeBall?(item)
  2461. },false)
  2462. loop do
  2463. item=itemscene.pbChooseItem
  2464. break if item==0
  2465. usetype=$ItemData[item][ITEMBATTLEUSE]
  2466. cmdUse=-1
  2467. commands=[]
  2468. if usetype==0
  2469. commands[commands.length]=_INTL("Cancel")
  2470. else
  2471. commands[cmdUse=commands.length]=_INTL("Use")
  2472. commands[commands.length]=_INTL("Cancel")
  2473. end
  2474. itemname=PBItems.getName(item)
  2475. command=itemscene.pbShowCommands(_INTL("{1} is selected.",itemname),commands)
  2476. if cmdUse>=0 && command==cmdUse
  2477. if usetype==1 || usetype==3
  2478. modparty=[]
  2479. for i in 0...6
  2480. modparty.push(@battle.party1[@battle.party1order[i]])
  2481. end
  2482. pkmnlist=PokemonParty_Scene.new
  2483. pkmnscreen=PokemonPartyScreen.new(pkmnlist,modparty)
  2484. itemscene.pbEndScene
  2485. pkmnscreen.pbStartScene(_INTL("Use on which Pokémon?"),@battle.doublebattle)
  2486. activecmd=pkmnscreen.pbChoosePokemon
  2487. pkmnid=@battle.party1order[activecmd]
  2488. if activecmd>=0 && pkmnid>=0 && ItemHandlers.hasBattleUseOnPokemon(item)
  2489. pkmnlist.pbEndScene
  2490. ret=item
  2491. retindex=pkmnid
  2492. endscene=false
  2493. break
  2494. end
  2495. pkmnlist.pbEndScene
  2496. itemscene.pbStartScene($PokemonBag)
  2497. elsif usetype==2 || usetype==4
  2498. if ItemHandlers.hasBattleUseOnBattler(item)
  2499. ret=item
  2500. retindex=index
  2501. break
  2502. end
  2503. end
  2504. end
  2505. end
  2506. pbConsumeItemInBattle($PokemonBag,ret) if ret>0
  2507. itemscene.pbEndScene if endscene
  2508. @baglastpocket = $PokemonBag.lastpocket
  2509. @bagchoices = $PokemonBag.getAllChoices
  2510. $PokemonBag.lastpocket = oldlastpocket
  2511. $PokemonBag.setAllChoices(oldchoices)
  2512. pbFadeInAndShow(@sprites,oldsprites)
  2513. return [ret,retindex]
  2514. end
  2515.  
  2516. # Called whenever a Pokémon should forget a move. It should return -1 if the
  2517. # selection is canceled, or 0 to 3 to indicate the move to forget. The function
  2518. # should not allow HM moves to be forgotten.
  2519. def pbForgetMove(pokemon,moveToLearn)
  2520. ret=-1
  2521. pbFadeOutIn(99999){
  2522. scene=PokemonSummary_Scene.new
  2523. screen=PokemonSummaryScreen.new(scene)
  2524. ret=screen.pbStartForgetScreen([pokemon],0,moveToLearn)
  2525. }
  2526. return ret
  2527. end
  2528.  
  2529. # Called whenever a Pokémon needs one of its moves chosen. Used for Ether.
  2530. def pbChooseMove(pokemon,message)
  2531. ret=-1
  2532. pbFadeOutIn(99999){
  2533. scene=PokemonSummary_Scene.new
  2534. screen=PokemonSummaryScreen.new(scene)
  2535. ret=screen.pbStartChooseMoveScreen([pokemon],0,message)
  2536. }
  2537. return ret
  2538. end
  2539.  
  2540. def pbNameEntry(helptext,pokemon)
  2541. return pbEnterPokemonName(helptext,0,PokeBattle_Pokemon::NAMELIMIT,"",pokemon)
  2542. end
  2543.  
  2544. def pbSelectBattler(index,selectmode=1)
  2545. numwindows=@battle.doublebattle ? 4 : 2
  2546. for i in 0...numwindows
  2547. sprite=@sprites["battlebox#{i}"]
  2548. sprite.selected=(i==index) ? selectmode : 0
  2549. sprite=@sprites["pokemon#{i}"]
  2550. sprite.selected=(i==index) ? selectmode : 0
  2551. end
  2552. end
  2553.  
  2554. def pbFirstTarget(index,targettype)
  2555. case targettype
  2556. when PBTargets::SingleNonUser
  2557. for i in 0...4
  2558. if i!=index && !@battle.battlers[i].isFainted? &&
  2559. @battle.battlers[index].pbIsOpposing?(i)
  2560. return i
  2561. end
  2562. end
  2563. when PBTargets::UserOrPartner
  2564. return index
  2565. end
  2566. return -1
  2567. end
  2568.  
  2569. def pbUpdateSelected(index)
  2570. numwindows=@battle.doublebattle ? 4 : 2
  2571. for i in 0...numwindows
  2572. if i==index
  2573. @sprites["battlebox#{i}"].selected=2
  2574. @sprites["pokemon#{i}"].selected=2
  2575. else
  2576. @sprites["battlebox#{i}"].selected=0
  2577. @sprites["pokemon#{i}"].selected=0
  2578. end
  2579. end
  2580. pbFrameUpdate
  2581. end
  2582.  
  2583. # Use this method to make the player choose a target
  2584. # for certain moves in double battles.
  2585. def pbChooseTarget(index,targettype)
  2586. pbShowWindow(FIGHTBOX)
  2587. cw = @sprites["fightwindow"]
  2588. battler=@battle.battlers[index]
  2589. cw.battler=battler
  2590. lastIndex=@lastmove[index]
  2591. if battler.moves[lastIndex].id!=0
  2592. cw.setIndex(lastIndex)
  2593. else
  2594. cw.setIndex(0)
  2595. end
  2596. curwindow=pbFirstTarget(index,targettype)
  2597. if curwindow==-1
  2598. raise RuntimeError.new(_INTL("No targets somehow..."))
  2599. end
  2600. loop do
  2601. pbGraphicsUpdate
  2602. pbInputUpdate
  2603. pbUpdateSelected(curwindow)
  2604. if Input.trigger?(Input::B)
  2605. pbUpdateSelected(-1)
  2606. return -1
  2607. elsif Input.trigger?(Input::C)
  2608. pbUpdateSelected(-1)
  2609. return curwindow
  2610. end
  2611. if curwindow>=0
  2612. if Input.trigger?(Input::RIGHT) || Input.trigger?(Input::DOWN)
  2613. loop do
  2614. case targettype
  2615. when PBTargets::SingleNonUser
  2616. case curwindow
  2617. when 0; newcurwindow=2
  2618. when 1; newcurwindow=0
  2619. when 2; newcurwindow=3
  2620. when 3; newcurwindow=1
  2621. end
  2622. when PBTargets::UserOrPartner
  2623. newcurwindow=(curwindow+2)%4
  2624. end
  2625. curwindow=newcurwindow
  2626. next if targettype==PBTargets::SingleNonUser && curwindow==index
  2627. break if !@battle.battlers[curwindow].isFainted?
  2628. end
  2629. elsif Input.trigger?(Input::LEFT) || Input.trigger?(Input::UP)
  2630. loop do
  2631. case targettype
  2632. when PBTargets::SingleNonUser
  2633. case curwindow
  2634. when 0; newcurwindow=1
  2635. when 1; newcurwindow=3
  2636. when 2; newcurwindow=0
  2637. when 3; newcurwindow=2
  2638. end
  2639. when PBTargets::UserOrPartner
  2640. newcurwindow=(curwindow+2)%4
  2641. end
  2642. curwindow=newcurwindow
  2643. next if targettype==PBTargets::SingleNonUser && curwindow==index
  2644. break if !@battle.battlers[curwindow].isFainted?
  2645. end
  2646. end
  2647. end
  2648. end
  2649. end
  2650.  
  2651. def pbSwitch(index,lax,cancancel)
  2652. party=@battle.pbParty(index)
  2653. partypos=@battle.party1order
  2654. ret=-1
  2655. # Fade out and hide all sprites
  2656. visiblesprites=pbFadeOutAndHide(@sprites)
  2657. pbShowWindow(BLANK)
  2658. pbSetMessageMode(true)
  2659. modparty=[]
  2660. for i in 0...6
  2661. modparty.push(party[partypos[i]])
  2662. end
  2663. scene=PokemonParty_Scene.new
  2664. @switchscreen=PokemonPartyScreen.new(scene,modparty)
  2665. @switchscreen.pbStartScene(_INTL("Choose a Pokémon."),
  2666. @battle.doublebattle && !@battle.fullparty1)
  2667. loop do
  2668. scene.pbSetHelpText(_INTL("Choose a Pokémon."))
  2669. activecmd=@switchscreen.pbChoosePokemon
  2670. if cancancel && activecmd==-1
  2671. ret=-1
  2672. break
  2673. end
  2674. if activecmd>=0
  2675. commands=[]
  2676. cmdShift=-1
  2677. cmdSummary=-1
  2678. pkmnindex=partypos[activecmd]
  2679. commands[cmdShift=commands.length]=_INTL("Switch In") if !party[pkmnindex].isEgg?
  2680. commands[cmdSummary=commands.length]=_INTL("Summary")
  2681. commands[commands.length]=_INTL("Cancel")
  2682. command=scene.pbShowCommands(_INTL("Do what with {1}?",party[pkmnindex].name),commands)
  2683. if cmdShift>=0 && command==cmdShift
  2684. canswitch=lax ? @battle.pbCanSwitchLax?(index,pkmnindex,true) :
  2685. @battle.pbCanSwitch?(index,pkmnindex,true)
  2686. if canswitch
  2687. ret=pkmnindex
  2688. break
  2689. end
  2690. elsif cmdSummary>=0 && command==cmdSummary
  2691. scene.pbSummary(activecmd)
  2692. end
  2693. end
  2694. end
  2695. @switchscreen.pbEndScene
  2696. @switchscreen=nil
  2697. pbShowWindow(BLANK)
  2698. pbSetMessageMode(false)
  2699. # back to main battle screen
  2700. pbFadeInAndShow(@sprites,visiblesprites)
  2701. return ret
  2702. end
  2703.  
  2704. def pbDamageAnimation(pkmn,effectiveness)
  2705. pkmnsprite=@sprites["pokemon#{pkmn.index}"]
  2706. shadowsprite=@sprites["shadow#{pkmn.index}"]
  2707. sprite=@sprites["battlebox#{pkmn.index}"]
  2708. oldshadowvisible=shadowsprite.visible
  2709. oldvisible=sprite.visible
  2710. sprite.selected=3
  2711. @briefmessage=false
  2712. 6.times do
  2713. pbGraphicsUpdate
  2714. pbInputUpdate
  2715. pbFrameUpdate
  2716. end
  2717. case effectiveness
  2718. when 0
  2719. pbSEPlay("Battle damage normal")
  2720. when 1
  2721. pbSEPlay("Battle damage weak")
  2722. when 2
  2723. pbSEPlay("Battle damage super")
  2724. end
  2725. 8.times do
  2726. pkmnsprite.visible=!pkmnsprite.visible
  2727. if oldshadowvisible
  2728. shadowsprite.visible=!shadowsprite.visible
  2729. end
  2730. 4.times do
  2731. pbGraphicsUpdate
  2732. pbInputUpdate
  2733. pbFrameUpdate
  2734. sprite.update
  2735. end
  2736. end
  2737. sprite.selected=0
  2738. sprite.visible=oldvisible
  2739. end
  2740.  
  2741. # This method is called whenever a Pokémon's HP changes.
  2742. # Used to animate the HP bar.
  2743. def pbHPChanged(pkmn,oldhp,anim=false)
  2744. @briefmessage=false
  2745. hpchange=pkmn.hp-oldhp
  2746. if hpchange<0
  2747. hpchange=-hpchange
  2748. PBDebug.log("[HP change] #{pkmn.pbThis} lost #{hpchange} HP (#{oldhp}=>#{pkmn.hp})")
  2749. else
  2750. PBDebug.log("[HP change] #{pkmn.pbThis} gained #{hpchange} HP (#{oldhp}=>#{pkmn.hp})")
  2751. end
  2752. if anim && @battle.battlescene
  2753. if pkmn.hp>oldhp
  2754. pbCommonAnimation("HealthUp",pkmn,nil)
  2755. elsif pkmn.hp<oldhp
  2756. pbCommonAnimation("HealthDown",pkmn,nil)
  2757. end
  2758. end
  2759. sprite=@sprites["battlebox#{pkmn.index}"]
  2760. sprite.animateHP(oldhp,pkmn.hp)
  2761. while sprite.animatingHP
  2762. pbGraphicsUpdate
  2763. pbInputUpdate
  2764. pbFrameUpdate
  2765. sprite.update
  2766. end
  2767. end
  2768.  
  2769. # This method is called whenever a Pokémon faints.
  2770. def pbFainted(pkmn)
  2771. frames=pbCryFrameLength(pkmn.pokemon)
  2772. pbPlayCry(pkmn.pokemon)
  2773. frames.times do
  2774. pbGraphicsUpdate
  2775. pbInputUpdate
  2776. pbFrameUpdate
  2777. end
  2778. @sprites["shadow#{pkmn.index}"].visible=false
  2779. pkmnsprite=@sprites["pokemon#{pkmn.index}"]
  2780. ycoord=0
  2781. if @battle.doublebattle
  2782. ycoord=PokeBattle_SceneConstants::PLAYERBATTLERD1_Y if pkmn.index==0
  2783. ycoord=PokeBattle_SceneConstants::FOEBATTLERD1_Y if pkmn.index==1
  2784. ycoord=PokeBattle_SceneConstants::PLAYERBATTLERD2_Y if pkmn.index==2
  2785. ycoord=PokeBattle_SceneConstants::FOEBATTLERD2_Y if pkmn.index==3
  2786. else
  2787. if @battle.pbIsOpposing?(pkmn.index)
  2788. ycoord=PokeBattle_SceneConstants::FOEBATTLER_Y
  2789. else
  2790. ycoord=PokeBattle_SceneConstants::PLAYERBATTLER_Y
  2791. end
  2792. end
  2793. pbSEPlay("Pkmn faint")
  2794. loop do
  2795. pkmnsprite.y+=8
  2796. if pkmnsprite.y-pkmnsprite.oy+pkmnsprite.src_rect.height>=ycoord
  2797. pkmnsprite.src_rect.height=ycoord-pkmnsprite.y+pkmnsprite.oy
  2798. end
  2799. pbGraphicsUpdate
  2800. pbInputUpdate
  2801. pbFrameUpdate
  2802. break if pkmnsprite.y>=ycoord
  2803. end
  2804. pkmnsprite.visible=false
  2805. 8.times do
  2806. @sprites["battlebox#{pkmn.index}"].opacity-=32
  2807. pbGraphicsUpdate
  2808. pbInputUpdate
  2809. pbFrameUpdate
  2810. end
  2811. @sprites["battlebox#{pkmn.index}"].visible=false
  2812. pkmn.pbResetForm
  2813. end
  2814.  
  2815. # Use this method to choose a command for the enemy.
  2816. def pbChooseEnemyCommand(index)
  2817. @battle.pbDefaultChooseEnemyCommand(index)
  2818. end
  2819.  
  2820. # Use this method to choose a new Pokémon for the enemy
  2821. # The enemy's party is guaranteed to have at least one choosable member.
  2822. def pbChooseNewEnemy(index,party)
  2823. @battle.pbDefaultChooseNewEnemy(index,party)
  2824. end
  2825.  
  2826. # This method is called when the player wins a wild Pokémon battle.
  2827. # This method can change the battle's music for example.
  2828. def pbWildBattleSuccess
  2829. pbBGMPlay(pbGetWildVictoryME())
  2830. end
  2831.  
  2832. # This method is called when the player wins a Trainer battle.
  2833. # This method can change the battle's music for example.
  2834. def pbTrainerBattleSuccess
  2835. pbBGMPlay(pbGetTrainerVictoryME(@battle.opponent))
  2836. end
  2837.  
  2838. def pbEXPBar(pokemon,battler,startexp,endexp,tempexp1,tempexp2)
  2839. if battler
  2840. @sprites["battlebox#{battler.index}"].refreshExpLevel
  2841. exprange=(endexp-startexp)
  2842. startexplevel=0
  2843. endexplevel=0
  2844. if exprange!=0
  2845. startexplevel=(tempexp1-startexp)*192/exprange
  2846. endexplevel=(tempexp2-startexp)*192/exprange
  2847. end
  2848. @sprites["battlebox#{battler.index}"].animateEXP(startexplevel,endexplevel)
  2849. while @sprites["battlebox#{battler.index}"].animatingEXP
  2850. pbGraphicsUpdate
  2851. pbInputUpdate
  2852. pbFrameUpdate
  2853. @sprites["battlebox#{battler.index}"].update
  2854. end
  2855. end
  2856. end
  2857.  
  2858. def pbShowPokedex(species)
  2859. pbFadeOutIn(99999){
  2860. scene = PokemonPokedexInfo_Scene.new
  2861. screen = PokemonPokedexInfoScreen.new(scene)
  2862. screen.pbDexEntry(species)
  2863. }
  2864. end
  2865.  
  2866. def pbChangeSpecies(attacker,species)
  2867. pkmn=@sprites["pokemon#{attacker.index}"]
  2868. shadow=@sprites["shadow#{attacker.index}"]
  2869. back=!@battle.pbIsOpposing?(attacker.index)
  2870. pkmn.setPokemonBitmapSpecies(attacker.pokemon,species,back)
  2871. pkmn.x=-pkmn.bitmap.width/2
  2872. pkmn.y=adjustBattleSpriteY(pkmn,species,attacker.index)
  2873. if @battle.doublebattle
  2874. case attacker.index
  2875. when 0
  2876. pkmn.x+=PokeBattle_SceneConstants::PLAYERBATTLERD1_X
  2877. pkmn.y+=PokeBattle_SceneConstants::PLAYERBATTLERD1_Y
  2878. when 1
  2879. pkmn.x+=PokeBattle_SceneConstants::FOEBATTLERD1_X
  2880. pkmn.y+=PokeBattle_SceneConstants::FOEBATTLERD1_Y
  2881. when 2
  2882. pkmn.x+=PokeBattle_SceneConstants::PLAYERBATTLERD2_X
  2883. pkmn.y+=PokeBattle_SceneConstants::PLAYERBATTLERD2_Y
  2884. when 3
  2885. pkmn.x+=PokeBattle_SceneConstants::FOEBATTLERD2_X
  2886. pkmn.y+=PokeBattle_SceneConstants::FOEBATTLERD2_Y
  2887. end
  2888. else
  2889. pkmn.x+=PokeBattle_SceneConstants::PLAYERBATTLER_X if attacker.index==0
  2890. pkmn.y+=PokeBattle_SceneConstants::PLAYERBATTLER_Y if attacker.index==0
  2891. pkmn.x+=PokeBattle_SceneConstants::FOEBATTLER_X if attacker.index==1
  2892. pkmn.y+=PokeBattle_SceneConstants::FOEBATTLER_Y if attacker.index==1
  2893. end
  2894. if shadow && !back
  2895. shadow.visible=showShadow?(species)
  2896. end
  2897. end
  2898.  
  2899. def pbChangePokemon(attacker,pokemon)
  2900. pkmn=@sprites["pokemon#{attacker.index}"]
  2901. shadow=@sprites["shadow#{attacker.index}"]
  2902. back=!@battle.pbIsOpposing?(attacker.index)
  2903. pkmn.setPokemonBitmap(pokemon,back)
  2904. pkmn.x=-pkmn.bitmap.width/2
  2905. pkmn.y=adjustBattleSpriteY(pkmn,pokemon.species,attacker.index)
  2906. if @battle.doublebattle
  2907. case attacker.index
  2908. when 0
  2909. pkmn.x+=PokeBattle_SceneConstants::PLAYERBATTLERD1_X
  2910. pkmn.y+=PokeBattle_SceneConstants::PLAYERBATTLERD1_Y
  2911. when 1
  2912. pkmn.x+=PokeBattle_SceneConstants::FOEBATTLERD1_X
  2913. pkmn.y+=PokeBattle_SceneConstants::FOEBATTLERD1_Y
  2914. when 2
  2915. pkmn.x+=PokeBattle_SceneConstants::PLAYERBATTLERD2_X
  2916. pkmn.y+=PokeBattle_SceneConstants::PLAYERBATTLERD2_Y
  2917. when 3
  2918. pkmn.x+=PokeBattle_SceneConstants::FOEBATTLERD2_X
  2919. pkmn.y+=PokeBattle_SceneConstants::FOEBATTLERD2_Y
  2920. end
  2921. else
  2922. pkmn.x+=PokeBattle_SceneConstants::PLAYERBATTLER_X if attacker.index==0
  2923. pkmn.y+=PokeBattle_SceneConstants::PLAYERBATTLER_Y if attacker.index==0
  2924. pkmn.x+=PokeBattle_SceneConstants::FOEBATTLER_X if attacker.index==1
  2925. pkmn.y+=PokeBattle_SceneConstants::FOEBATTLER_Y if attacker.index==1
  2926. end
  2927. if shadow && !back
  2928. shadow.visible=showShadow?(pokemon.species)
  2929. end
  2930. end
  2931.  
  2932. def pbSaveShadows
  2933. shadows=[]
  2934. for i in 0...4
  2935. s=@sprites["shadow#{i}"]
  2936. shadows[i]=s ? s.visible : false
  2937. s.visible=false if s
  2938. end
  2939. yield
  2940. for i in 0...4
  2941. s=@sprites["shadow#{i}"]
  2942. s.visible=shadows[i] if s
  2943. end
  2944. end
  2945.  
  2946. def pbFindAnimation(moveid,userIndex,hitnum)
  2947. begin
  2948. move2anim=load_data("Data/move2anim.dat")
  2949. noflip=false
  2950. if (userIndex&1)==0 # On player's side
  2951. anim=move2anim[0][moveid]
  2952. else # On opposing side
  2953. anim=move2anim[1][moveid]
  2954. noflip=true if anim
  2955. anim=move2anim[0][moveid] if !anim
  2956. end
  2957. return [anim+hitnum,noflip] if anim
  2958. # Actual animation not found, get the default animation for the move's type
  2959. move=PBMoveData.new(moveid)
  2960. type=move.type
  2961. typedefaultanim=[[:NORMAL,:TACKLE],
  2962. [:FIGHTING,:COMETPUNCH],
  2963. [:FLYING,:GUST],
  2964. [:POISON,:SLUDGE],
  2965. [:GROUND,:MUDSLAP],
  2966. [:ROCK,:ROCKTHROW],
  2967. [:BUG,:TWINEEDLE],
  2968. [:GHOST,:NIGHTSHADE],
  2969. [:STEEL,:GYROBALL],
  2970. [:FIRE,:EMBER],
  2971. [:WATER,:WATERGUN],
  2972. [:GRASS,:RAZORLEAF],
  2973. [:ELECTRIC,:THUNDERSHOCK],
  2974. [:PSYCHIC,:CONFUSION],
  2975. [:ICE,:ICEBALL],
  2976. [:DRAGON,:DRAGONRAGE],
  2977. [:DARK,:PURSUIT],
  2978. [:FAIRY,:FAIRYWIND]]
  2979. for i in typedefaultanim
  2980. if isConst?(type,PBTypes,i[0]) && hasConst?(PBMoves,i[1])
  2981. noflip=false
  2982. if (userIndex&1)==0 # On player's side
  2983. anim=move2anim[0][getConst(PBMoves,i[1])]
  2984. else # On opposing side
  2985. anim=move2anim[1][getConst(PBMoves,i[1])]
  2986. noflip=true if anim
  2987. anim=move2anim[0][getConst(PBMoves,i[1])] if !anim
  2988. end
  2989. return [anim,noflip] if anim
  2990. break
  2991. end
  2992. end
  2993. # Default animation for the move's type not found, use Tackle's animation
  2994. if hasConst?(PBMoves,:TACKLE)
  2995. anim=move2anim[0][getConst(PBMoves,:TACKLE)]
  2996. return [anim,false] if anim
  2997. end
  2998. rescue
  2999. return nil
  3000. end
  3001. return nil
  3002. end
  3003.  
  3004. def pbCommonAnimation(animname,user,target,hitnum=0)
  3005. animations=load_data("Data/PkmnAnimations.rxdata")
  3006. for i in 0...animations.length
  3007. if animations[i] && animations[i].name=="Common:"+animname
  3008. pbAnimationCore(animations[i],user,(target!=nil) ? target : user)
  3009. return
  3010. end
  3011. end
  3012. end
  3013.  
  3014. def pbAnimation(moveid,user,target,hitnum=0)
  3015. animid=pbFindAnimation(moveid,user.index,hitnum)
  3016. return if !animid
  3017. anim=animid[0]
  3018. animations=load_data("Data/PkmnAnimations.rxdata")
  3019. pbSaveShadows {
  3020. if animid[1] # On opposing side and using OppMove animation
  3021. pbAnimationCore(animations[anim],target,user,true)
  3022. else # On player's side, and/or using Move animation
  3023. pbAnimationCore(animations[anim],user,target)
  3024. end
  3025. }
  3026. if PBMoveData.new(moveid).function==0x69 && user && target # Transform
  3027. # Change form to transformed version
  3028. pbChangePokemon(user,target.pokemon)
  3029. end
  3030. end
  3031.  
  3032. def pbAnimationCore(animation,user,target,oppmove=false)
  3033. return if !animation
  3034. @briefmessage=false
  3035. usersprite=(user) ? @sprites["pokemon#{user.index}"] : nil
  3036. targetsprite=(target) ? @sprites["pokemon#{target.index}"] : nil
  3037. olduserx=usersprite ? usersprite.x : 0
  3038. oldusery=usersprite ? usersprite.y : 0
  3039. oldtargetx=targetsprite ? targetsprite.x : 0
  3040. oldtargety=targetsprite ? targetsprite.y : 0
  3041. if !targetsprite
  3042. target=user if !target
  3043. animplayer=PBAnimationPlayerX.new(animation,user,target,self,oppmove)
  3044. userwidth=(!usersprite || !usersprite.bitmap || usersprite.bitmap.disposed?) ? 128 : usersprite.bitmap.width
  3045. userheight=(!usersprite || !usersprite.bitmap || usersprite.bitmap.disposed?) ? 128 : usersprite.bitmap.height
  3046. animplayer.setLineTransform(
  3047. PokeBattle_SceneConstants::FOCUSUSER_X,PokeBattle_SceneConstants::FOCUSUSER_Y,
  3048. PokeBattle_SceneConstants::FOCUSTARGET_X,PokeBattle_SceneConstants::FOCUSTARGET_Y,
  3049. olduserx+(userwidth/2),oldusery+(userheight/2),
  3050. olduserx+(userwidth/2),oldusery+(userheight/2))
  3051. else
  3052. animplayer=PBAnimationPlayerX.new(animation,user,target,self,oppmove)
  3053. userwidth=(!usersprite || !usersprite.bitmap || usersprite.bitmap.disposed?) ? 128 : usersprite.bitmap.width
  3054. userheight=(!usersprite || !usersprite.bitmap || usersprite.bitmap.disposed?) ? 128 : usersprite.bitmap.height
  3055. targetwidth=(!targetsprite.bitmap || targetsprite.bitmap.disposed?) ? 128 : targetsprite.bitmap.width
  3056. targetheight=(!targetsprite.bitmap || targetsprite.bitmap.disposed?) ? 128 : targetsprite.bitmap.height
  3057. animplayer.setLineTransform(
  3058. PokeBattle_SceneConstants::FOCUSUSER_X,PokeBattle_SceneConstants::FOCUSUSER_Y,
  3059. PokeBattle_SceneConstants::FOCUSTARGET_X,PokeBattle_SceneConstants::FOCUSTARGET_Y,
  3060. olduserx+(userwidth/2),oldusery+(userheight/2),
  3061. oldtargetx+(targetwidth/2),oldtargety+(targetheight/2))
  3062. end
  3063. animplayer.start
  3064. while animplayer.playing?
  3065. animplayer.update
  3066. pbGraphicsUpdate
  3067. pbInputUpdate
  3068. pbFrameUpdate
  3069. end
  3070. usersprite.ox=0 if usersprite
  3071. usersprite.oy=0 if usersprite
  3072. usersprite.x=olduserx if usersprite
  3073. usersprite.y=oldusery if usersprite
  3074. targetsprite.ox=0 if targetsprite
  3075. targetsprite.oy=0 if targetsprite
  3076. targetsprite.x=oldtargetx if targetsprite
  3077. targetsprite.y=oldtargety if targetsprite
  3078. animplayer.dispose
  3079. end
  3080.  
  3081. def pbLevelUp(pokemon,battler,oldtotalhp,oldattack,olddefense,oldspeed,
  3082. oldspatk,oldspdef)
  3083. pbTopRightWindow(_INTL("Max. HP<r>+{1}\r\nAttack<r>+{2}\r\nDefense<r>+{3}\r\nSp. Atk<r>+{4}\r\nSp. Def<r>+{5}\r\nSpeed<r>+{6}",
  3084. pokemon.totalhp-oldtotalhp,
  3085. pokemon.attack-oldattack,
  3086. pokemon.defense-olddefense,
  3087. pokemon.spatk-oldspatk,
  3088. pokemon.spdef-oldspdef,
  3089. pokemon.speed-oldspeed))
  3090. pbTopRightWindow(_INTL("Max. HP<r>{1}\r\nAttack<r>{2}\r\nDefense<r>{3}\r\nSp. Atk<r>{4}\r\nSp. Def<r>{5}\r\nSpeed<r>{6}",
  3091. pokemon.totalhp,pokemon.attack,pokemon.defense,pokemon.spatk,pokemon.spdef,pokemon.speed))
  3092. end
  3093.  
  3094. def pbThrowAndDeflect(ball,targetBattler)
  3095. @briefmessage=false
  3096. balltype=pbGetBallType(ball)
  3097. ball=sprintf("Graphics/Pictures/Battle/ball_%02d",balltype)
  3098. # sprite
  3099. spriteBall=IconSprite.new(0,0,@viewport)
  3100. spriteBall.visible=false
  3101. # picture
  3102. pictureBall=PictureEx.new(@sprites["pokemon#{targetBattler}"].z+1)
  3103. center=getSpriteCenter(@sprites["pokemon#{targetBattler}"])
  3104. # starting positions
  3105. pictureBall.moveVisible(1,true)
  3106. pictureBall.moveName(1,ball)
  3107. pictureBall.moveOrigin(1,PictureOrigin::Center)
  3108. pictureBall.moveXY(0,1,10,180)
  3109. # directives
  3110. pictureBall.moveSE(1,"Audio/SE/Battle throw")
  3111. pictureBall.moveCurve(30,1,150,70,30+Graphics.width/2,10,center[0],center[1])
  3112. pictureBall.moveAngle(30,1,-1080)
  3113. pictureBall.moveAngle(0,pictureBall.totalDuration,0)
  3114. delay=pictureBall.totalDuration
  3115. pictureBall.moveSE(delay,"Audio/SE/Battle ball drop")
  3116. pictureBall.moveXY(20,delay,0,Graphics.height)
  3117. loop do
  3118. pictureBall.update
  3119. setPictureIconSprite(spriteBall,pictureBall)
  3120. pbGraphicsUpdate
  3121. pbInputUpdate
  3122. pbFrameUpdate
  3123. break if !pictureBall.running?
  3124. end
  3125. spriteBall.dispose
  3126. end
  3127.  
  3128. def pbThrow(ball,shakes,critical,targetBattler,showplayer=false)
  3129. @briefmessage=false
  3130. burst=-1
  3131. animations=load_data("Data/PkmnAnimations.rxdata")
  3132. for i in 0...2
  3133. t=(i==0) ? ball : 0
  3134. for j in 0...animations.length
  3135. if animations[j]
  3136. if animations[j].name=="Common:BallBurst#{t}"
  3137. burst=t if burst<0
  3138. break
  3139. end
  3140. end
  3141. end
  3142. break if burst>=0
  3143. end
  3144. pokeballThrow(ball,shakes,critical,targetBattler,self,@battle.battlers[targetBattler],burst,showplayer)
  3145. end
  3146.  
  3147. def pbThrowSuccess
  3148. if !@battle.opponent
  3149. @briefmessage=false
  3150. pbMEPlay("Battle capture success")
  3151. frames=(3.5*Graphics.frame_rate).to_i
  3152. frames.times do
  3153. pbGraphicsUpdate
  3154. pbInputUpdate
  3155. pbFrameUpdate
  3156. end
  3157. end
  3158. end
  3159.  
  3160. def pbHideCaptureBall
  3161. if @sprites["capture"]
  3162. loop do
  3163. break if @sprites["capture"].opacity<=0
  3164. @sprites["capture"].opacity-=12
  3165. pbGraphicsUpdate
  3166. pbInputUpdate
  3167. pbFrameUpdate
  3168. end
  3169. end
  3170. end
  3171.  
  3172. def pbThrowBait
  3173. @briefmessage=false
  3174. ball=sprintf("Graphics/Pictures/Battle/object_bait")
  3175. armanim=false
  3176. if @sprites["player"].bitmap.width>@sprites["player"].bitmap.height
  3177. armanim=true
  3178. end
  3179. # sprites
  3180. spritePoke=@sprites["pokemon1"]
  3181. spritePlayer=@sprites["player"]
  3182. spriteBall=IconSprite.new(0,0,@viewport)
  3183. spriteBall.visible=false
  3184. # pictures
  3185. pictureBall=PictureEx.new(spritePoke.z+1)
  3186. picturePoke=PictureEx.new(spritePoke.z)
  3187. picturePlayer=PictureEx.new(spritePoke.z+2)
  3188. dims=[spritePoke.x,spritePoke.y]
  3189. pokecenter=getSpriteCenter(@sprites["pokemon1"])
  3190. playerpos=[@sprites["player"].x,@sprites["player"].y]
  3191. ballendy=PokeBattle_SceneConstants::FOEBATTLER_Y-4
  3192. # starting positions
  3193. pictureBall.moveVisible(1,true)
  3194. pictureBall.moveName(1,ball)
  3195. pictureBall.moveOrigin(1,PictureOrigin::Center)
  3196. pictureBall.moveXY(0,1,64,256)
  3197. picturePoke.moveVisible(1,true)
  3198. picturePoke.moveOrigin(1,PictureOrigin::Center)
  3199. picturePoke.moveXY(0,1,pokecenter[0],pokecenter[1])
  3200. picturePlayer.moveVisible(1,true)
  3201. picturePlayer.moveName(1,@sprites["player"].name)
  3202. picturePlayer.moveOrigin(1,PictureOrigin::TopLeft)
  3203. picturePlayer.moveXY(0,1,playerpos[0],playerpos[1])
  3204. # directives
  3205. picturePoke.moveSE(1,"Audio/SE/Battle throw")
  3206. pictureBall.moveCurve(30,1,64,256,Graphics.width/2,48,
  3207. PokeBattle_SceneConstants::FOEBATTLER_X-48,
  3208. PokeBattle_SceneConstants::FOEBATTLER_Y)
  3209. pictureBall.moveAngle(30,1,-720)
  3210. pictureBall.moveAngle(0,pictureBall.totalDuration,0)
  3211. if armanim
  3212. picturePlayer.moveSrc(1,@sprites["player"].bitmap.height,0)
  3213. picturePlayer.moveXY(0,1,playerpos[0]-14,playerpos[1])
  3214. picturePlayer.moveSrc(4,@sprites["player"].bitmap.height*2,0)
  3215. picturePlayer.moveXY(0,4,playerpos[0]-12,playerpos[1])
  3216. picturePlayer.moveSrc(8,@sprites["player"].bitmap.height*3,0)
  3217. picturePlayer.moveXY(0,8,playerpos[0]+20,playerpos[1])
  3218. picturePlayer.moveSrc(16,@sprites["player"].bitmap.height*4,0)
  3219. picturePlayer.moveXY(0,16,playerpos[0]+16,playerpos[1])
  3220. picturePlayer.moveSrc(40,0,0)
  3221. picturePlayer.moveXY(0,40,playerpos[0],playerpos[1])
  3222. end
  3223. # Show Pokémon jumping before eating the bait
  3224. picturePoke.moveSE(50,"Audio/SE/Player jump")
  3225. picturePoke.moveXY(8,50,pokecenter[0],pokecenter[1]-8)
  3226. picturePoke.moveXY(8,58,pokecenter[0],pokecenter[1])
  3227. pictureBall.moveVisible(66,false)
  3228. picturePoke.moveSE(66,"Audio/SE/Player jump")
  3229. picturePoke.moveXY(8,66,pokecenter[0],pokecenter[1]-8)
  3230. picturePoke.moveXY(8,74,pokecenter[0],pokecenter[1])
  3231. # TODO: Show Pokémon eating the bait (pivots at the bottom right corner)
  3232. picturePoke.moveOrigin(picturePoke.totalDuration,PictureOrigin::TopLeft)
  3233. picturePoke.moveXY(0,picturePoke.totalDuration,dims[0],dims[1])
  3234. loop do
  3235. pictureBall.update
  3236. picturePoke.update
  3237. picturePlayer.update
  3238. setPictureIconSprite(spriteBall,pictureBall)
  3239. setPictureSprite(spritePoke,picturePoke)
  3240. setPictureIconSprite(spritePlayer,picturePlayer)
  3241. pbGraphicsUpdate
  3242. pbInputUpdate
  3243. pbFrameUpdate
  3244. break if !pictureBall.running? && !picturePoke.running? && !picturePlayer.running?
  3245. end
  3246. spriteBall.dispose
  3247. end
  3248.  
  3249. def pbThrowRock
  3250. @briefmessage=false
  3251. ball=sprintf("Graphics/Pictures/Battle/object_rock")
  3252. anger=sprintf("Graphics/Pictures/Battle/object_anger")
  3253. armanim=false
  3254. if @sprites["player"].bitmap.width>@sprites["player"].bitmap.height
  3255. armanim=true
  3256. end
  3257. # sprites
  3258. spritePoke=@sprites["pokemon1"]
  3259. spritePlayer=@sprites["player"]
  3260. spriteBall=IconSprite.new(0,0,@viewport)
  3261. spriteBall.visible=false
  3262. spriteAnger=IconSprite.new(0,0,@viewport)
  3263. spriteAnger.visible=false
  3264. # pictures
  3265. pictureBall=PictureEx.new(spritePoke.z+1)
  3266. picturePoke=PictureEx.new(spritePoke.z)
  3267. picturePlayer=PictureEx.new(spritePoke.z+2)
  3268. pictureAnger=PictureEx.new(spritePoke.z+1)
  3269. dims=[spritePoke.x,spritePoke.y]
  3270. pokecenter=getSpriteCenter(@sprites["pokemon1"])
  3271. playerpos=[@sprites["player"].x,@sprites["player"].y]
  3272. ballendy=PokeBattle_SceneConstants::FOEBATTLER_Y-4
  3273. # starting positions
  3274. pictureBall.moveVisible(1,true)
  3275. pictureBall.moveName(1,ball)
  3276. pictureBall.moveOrigin(1,PictureOrigin::Center)
  3277. pictureBall.moveXY(0,1,64,256)
  3278. picturePoke.moveVisible(1,true)
  3279. picturePoke.moveOrigin(1,PictureOrigin::Center)
  3280. picturePoke.moveXY(0,1,pokecenter[0],pokecenter[1])
  3281. picturePlayer.moveVisible(1,true)
  3282. picturePlayer.moveName(1,@sprites["player"].name)
  3283. picturePlayer.moveOrigin(1,PictureOrigin::TopLeft)
  3284. picturePlayer.moveXY(0,1,playerpos[0],playerpos[1])
  3285. pictureAnger.moveVisible(1,false)
  3286. pictureAnger.moveName(1,anger)
  3287. pictureAnger.moveXY(0,1,pokecenter[0]-56,pokecenter[1]-48)
  3288. pictureAnger.moveOrigin(1,PictureOrigin::Center)
  3289. pictureAnger.moveZoom(0,1,100)
  3290. # directives
  3291. picturePoke.moveSE(1,"Audio/SE/Battle throw")
  3292. pictureBall.moveCurve(30,1,64,256,Graphics.width/2,48,pokecenter[0],pokecenter[1])
  3293. pictureBall.moveAngle(30,1,-720)
  3294. pictureBall.moveAngle(0,pictureBall.totalDuration,0)
  3295. pictureBall.moveSE(30,"Audio/SE/Battle damage weak")
  3296. if armanim
  3297. picturePlayer.moveSrc(1,@sprites["player"].bitmap.height,0)
  3298. picturePlayer.moveXY(0,1,playerpos[0]-14,playerpos[1])
  3299. picturePlayer.moveSrc(4,@sprites["player"].bitmap.height*2,0)
  3300. picturePlayer.moveXY(0,4,playerpos[0]-12,playerpos[1])
  3301. picturePlayer.moveSrc(8,@sprites["player"].bitmap.height*3,0)
  3302. picturePlayer.moveXY(0,8,playerpos[0]+20,playerpos[1])
  3303. picturePlayer.moveSrc(16,@sprites["player"].bitmap.height*4,0)
  3304. picturePlayer.moveXY(0,16,playerpos[0]+16,playerpos[1])
  3305. picturePlayer.moveSrc(40,0,0)
  3306. picturePlayer.moveXY(0,40,playerpos[0],playerpos[1])
  3307. end
  3308. pictureBall.moveVisible(40,false)
  3309. # Show Pokémon being angry
  3310. pictureAnger.moveSE(48,"Audio/SE/Player jump")
  3311. pictureAnger.moveVisible(48,true)
  3312. pictureAnger.moveZoom(8,48,130)
  3313. pictureAnger.moveZoom(8,56,100)
  3314. pictureAnger.moveXY(0,64,pokecenter[0]+56,pokecenter[1]-64)
  3315. pictureAnger.moveSE(64,"Audio/SE/Player jump")
  3316. pictureAnger.moveZoom(8,64,130)
  3317. pictureAnger.moveZoom(8,72,100)
  3318. pictureAnger.moveVisible(80,false)
  3319. picturePoke.moveOrigin(picturePoke.totalDuration,PictureOrigin::TopLeft)
  3320. picturePoke.moveXY(0,picturePoke.totalDuration,dims[0],dims[1])
  3321. loop do
  3322. pictureBall.update
  3323. picturePoke.update
  3324. picturePlayer.update
  3325. pictureAnger.update
  3326. setPictureIconSprite(spriteBall,pictureBall)
  3327. setPictureSprite(spritePoke,picturePoke)
  3328. setPictureIconSprite(spritePlayer,picturePlayer)
  3329. setPictureIconSprite(spriteAnger,pictureAnger)
  3330. pbGraphicsUpdate
  3331. pbInputUpdate
  3332. pbFrameUpdate
  3333. break if !pictureBall.running? && !picturePoke.running? &&
  3334. !picturePlayer.running? && !pictureAnger.running?
  3335. end
  3336. spriteBall.dispose
  3337. end
  3338. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement