Guest User

Untitled

a guest
Aug 29th, 2016
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.12 KB | None | 0 0
  1. #===============================================================================
  2. # * Character Selection - by FL (Credits will be apreciated)
  3. #===============================================================================
  4. #
  5. # This script is for Pokémon Essentials. It's a character selection screen
  6. # suggested for player selection or partner selection.
  7. #
  8. #===============================================================================
  9. #
  10. # To this script works, put it above main and put a 32x32 background at
  11. # "Graphics/Pictures/characterselectiontile" (may works with other sizes).
  12. #
  13. # To call this script, use 'pbCharacterSelection(overworld,battle)' passing two
  14. # arrays as arguments: the first must have the overworld graphics names and the
  15. # second must have the battle graphics, both using "Graphics/Pictures/" as
  16. # directory. Both arrays must have the same since that can't be an odd number.
  17. # The return is the player selected index, starting at 0.
  18. #
  19. # An example that initialize the player:
  20. #
  21. # overworld = ["trchar000","trchar001","trchar002","trchar003"]
  22. # battle = ["trainer000","trainer001","trainer002","trainer003"]
  23. # result = pbCharacterSelection(overworld,battle)
  24. # pbChangePlayer(result)
  25. #
  26. #===============================================================================
  27.  
  28. class CharacterSelectionScene
  29. SPEED=2 # Can be 1, 2, 4 or 8.
  30. TURNTIME=128 # In frames
  31.  
  32. def pbStartScene(overworld,battle)
  33. @overworld = overworld
  34. @battle = battle
  35. @sprites={}
  36. @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  37. @viewport.z=99999
  38. @sprites["bg"]=CharacterSelectionPlane.new(SPEED,TURNTIME,@viewport)
  39. @sprites["bg"].setBitmap("Graphics/Pictures/characterselectiontile")
  40. @sprites["arrow"]=IconSprite.new(@viewport)
  41. @sprites["arrow"].setBitmap("Graphics/Pictures/selarrow")
  42. @sprites["battlerbox"]=Window_AdvancedTextPokemon.new("")
  43. @sprites["battlerbox"].viewport=@viewport
  44. pbBottomLeftLines(@sprites["battlerbox"],5)
  45. @sprites["battlerbox"].width=256
  46. @sprites["battlerbox"].x=Graphics.width-@sprites["battlerbox"].width
  47. @sprites["battlerbox"].z=0
  48. @sprites["battler"]=IconSprite.new(384,284,@viewport)
  49. # Numbers for coordinates calculation
  50. lines = 2
  51. marginX = 64
  52. marginY = 72
  53. lastPointX = 512
  54. lastPointY = 232
  55. diferenceX = lastPointX - marginX*2
  56. diferenceY = lastPointY - marginY*2
  57. @sprites["icon#{i}"]=AnimatedChar.new(
  58. "Graphics/Characters/"+@overworld[i],4,16/SPEED,TURNTIME,@viewport)
  59. @sprites["icon#{i}"].x=marginX+(diferenceX*(i/2))/((@overworld.size-1)/2)
  60. @sprites["icon#{i}"].y=marginY+diferenceY*(i%lines)
  61. @sprites["icon#{i}"].start
  62. end
  63. updateCursor
  64. @sprites["messagebox"]=Window_AdvancedTextPokemon.new(
  65. _INTL("Choose your character."))
  66. @sprites["messagebox"].viewport=@viewport
  67. pbBottomLeftLines(@sprites["messagebox"],5)
  68. @sprites["messagebox"].width=256
  69. pbFadeInAndShow(@sprites) { update }
  70. end
  71.  
  72. def updateCursor(index=nil)
  73. @index=0
  74. if index
  75. pbSEPlay("Choose",80)
  76. @index=index
  77. end
  78. @sprites["arrow"].x=@sprites["icon#{@index}"].x-32
  79. @sprites["arrow"].y=@sprites["icon#{@index}"].y-32
  80. @sprites["battler"].setBitmap("Graphics/Characters/"+@battle[@index])
  81. @sprites["battler"].ox=@sprites["battler"].bitmap.width/2
  82. @sprites["battler"].oy=@sprites["battler"].bitmap.height/2
  83. end
  84.  
  85. def pbMidScene
  86. loop do
  87. Graphics.update
  88. Input.update
  89. self.update
  90. if Input.trigger?(Input::C)
  91. pbSEPlay("Choose",80)
  92. if pbDisplayConfirm(_INTL("Are you sure?"))
  93. pbSEPlay("Choose",80)
  94. return @index
  95. end
  96. pbSEPlay("Choose",80)
  97. end
  98. lines=2
  99. if Input.repeat?(Input::LEFT)
  100. updateCursor((@index-lines)>=0 ?
  101. @index-lines : @overworld.size-lines+(@index%lines))
  102. end
  103. if Input.repeat?(Input::RIGHT)
  104. updateCursor((@index+lines)<=(@overworld.size-1) ?
  105. @index+lines : @index%lines)
  106. end
  107. if Input.repeat?(Input::UP)
  108. updateCursor(@index!=0 ? @index-1 : @overworld.size-1)
  109. end
  110. if Input.repeat?(Input::DOWN)
  111. updateCursor(@[email protected] ? @index+1 : 0)
  112. end
  113. end
  114. end
  115.  
  116. def update
  117. pbUpdateSpriteHash(@sprites)
  118. end
  119.  
  120. def pbDisplayConfirm(text)
  121. ret=-1
  122. oldtext=@sprites["messagebox"].text
  123. @sprites["messagebox"].text=text
  124. using(cmdwindow=Window_CommandPokemon.new([_INTL("YES"),_INTL("NO")])){
  125. cmdwindow.visible=false
  126. pbBottomRight(cmdwindow)
  127. cmdwindow.y-=@sprites["messagebox"].height
  128. loop do
  129. Graphics.update
  130. Input.update
  131. cmdwindow.visible=true if !@sprites["messagebox"].busy?
  132. cmdwindow.update
  133. self.update
  134. if Input.trigger?(Input::B) && !@sprites["messagebox"].busy?
  135. ret=false
  136. end
  137. if (Input.trigger?(Input::C) &&
  138. @sprites["messagebox"].resume && !@sprites["messagebox"].busy?)
  139. ret=(cmdwindow.index==0)
  140. break
  141. end
  142. end
  143. }
  144. @sprites["messagebox"].text=oldtext
  145. return ret
  146. end
  147.  
  148. def pbEndScene
  149. pbFadeOutAndHide(@sprites) { update }
  150. pbDisposeSpriteHash(@sprites)
  151. @viewport.dispose
  152. end
  153.  
  154. class CharacterSelectionPlane < AnimatedPlane
  155. LIMIT=16
  156.  
  157. def initialize(speed, turnTime, viewport)
  158. super(viewport)
  159. @speed = speed
  160. @turnTime = turnTime
  161. end
  162.  
  163. def update
  164. super
  165. @frame=0 if !@frame
  166. @frame+=1
  167. @direction=0 if !@direction
  168. if @frame==@turnTime
  169. @frame=0
  170. @direction+=1
  171. @direction=0 if @direction==4
  172. end
  173. case @direction
  174. when 0 #down
  175. self.oy+=@speed
  176. when 1 #left
  177. self.ox-=@speed
  178. when 2 #up
  179. self.oy-=@speed
  180. when 3 #right
  181. self.ox+=@speed
  182. end
  183. self.ox=0 if self.ox==-LIMIT || self.ox==LIMIT
  184. self.oy=0 if self.oy==-LIMIT || self.oy==LIMIT
  185. end
  186. end
  187.  
  188. class AnimatedChar < AnimatedSprite
  189. def initialize(*args)
  190. viewport = args[4]
  191. @sprite=Sprite.new(viewport)
  192. @animname=pbBitmapName(args[0])
  193. @framecount=args[1]
  194. @frameskip=[1,args[2]].max
  195. @turnTime=args[3]
  196. @realframes=0
  197. @realframeschar=0
  198. @direction=0
  199. begin
  200. @animbitmap=AnimatedBitmap.new(animname).deanimate
  201. rescue
  202. @animbitmap=Bitmap.new(framecount*4,32)
  203. end
  204. if @animbitmap.width%framecount!=0
  205. raise _INTL("Bitmap's width ({1}) is not a multiple of frame count ({2}) [Bitmap={3}]",@animbitmap.width,framewidth,animname)
  206. end
  207. @[email protected]/@framecount
  208. @framesperrow=framecount
  209. @playing=false
  210. self.bitmap=@animbitmap
  211. self.src_rect.width=@framewidth
  212. self.src_rect.height=@frameheight
  213. self.ox=@framewidth/2
  214. self.oy=@frameheight
  215. self.frame=0
  216. end
  217.  
  218. def frame=(value)
  219. @frame=value
  220. @realframes=0
  221. self.src_rect.x=@frame%@framesperrow*@framewidth
  222. end
  223.  
  224. def update
  225. super
  226. if @playing
  227. @realframeschar+=1
  228. if @realframeschar==@turnTime
  229. @realframeschar=0
  230. @direction+=1
  231. @direction= 0 if @direction==4
  232. #Spin
  233. if @direction==2
  234. dir=3
  235. elsif @direction==3
  236. dir=2
  237. else
  238. dir=@direction
  239. end
  240. self.src_rect.y=@frameheight*dir
  241. end
  242. end
  243. end
  244. end
  245. end
  246.  
  247. class CharacterSelectionScreen
  248. def initialize(scene)
  249. @scene=scene
  250. end
  251.  
  252. def pbStartScreen(overworld,battle)
  253. @scene.pbStartScene(overworld,battle)
  254. ret = @scene.pbMidScene
  255. @scene.pbEndScene
  256. return ret
  257. end
  258. end
  259.  
  260. def pbCharacterSelection(overworld,battle)
  261. ret = nil
  262. pbFadeOutIn(99999) {
  263. scene=CharacterSelectionScene.new
  264. screen=CharacterSelectionScreen.new(scene)
  265. ret=screen.pbStartScreen(overworld,battle)
  266. }
  267. return ret
  268. end
Advertisement
Add Comment
Please, Sign In to add comment