Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
653
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. for i in 0...@overworld.size
  58. @sprites["icon#{i}"]=AnimatedChar.new(
  59. "Graphics/Characters/"+@overworld[i],4,16/SPEED,TURNTIME,@viewport)
  60. @sprites["icon#{i}"].x=marginX+(diferenceX*(i/2))/((@overworld.size-1)/2)
  61. @sprites["icon#{i}"].y=marginY+diferenceY*(i%lines)
  62. @sprites["icon#{i}"].start
  63. end
  64. updateCursor
  65. @sprites["messagebox"]=Window_AdvancedTextPokemon.new(
  66. _INTL("Choose your character."))
  67. @sprites["messagebox"].viewport=@viewport
  68. pbBottomLeftLines(@sprites["messagebox"],5)
  69. @sprites["messagebox"].width=256
  70. pbFadeInAndShow(@sprites) { update }
  71. end
  72.  
  73. def updateCursor(index=nil)
  74. @index=0
  75. if index
  76. pbSEPlay("Choose",80)
  77. @index=index
  78. end
  79. @sprites["arrow"].x=@sprites["icon#{@index}"].x-32
  80. @sprites["arrow"].y=@sprites["icon#{@index}"].y-32
  81. @sprites["battler"].setBitmap("Graphics/Characters/"+@battle[@index])
  82. @sprites["battler"].ox=@sprites["battler"].bitmap.width/2
  83. @sprites["battler"].oy=@sprites["battler"].bitmap.height/2
  84. end
  85.  
  86. def pbMidScene
  87. loop do
  88. Graphics.update
  89. Input.update
  90. self.update
  91. if Input.trigger?(Input::C)
  92. pbSEPlay("Choose",80)
  93. if pbDisplayConfirm(_INTL("Are you sure?"))
  94. pbSEPlay("Choose",80)
  95. return @index
  96. end
  97. pbSEPlay("Choose",80)
  98. end
  99. lines=2
  100. if Input.repeat?(Input::LEFT)
  101. updateCursor((@index-lines)>=0 ?
  102. @index-lines : @overworld.size-lines+(@index%lines))
  103. end
  104. if Input.repeat?(Input::RIGHT)
  105. updateCursor((@index+lines)<=(@overworld.size-1) ?
  106. @index+lines : @index%lines)
  107. end
  108. if Input.repeat?(Input::UP)
  109. updateCursor(@index!=0 ? @index-1 : @overworld.size-1)
  110. end
  111. if Input.repeat?(Input::DOWN)
  112. updateCursor(@index!=@overworld.size-1 ? @index+1 : 0)
  113. end
  114. end
  115. end
  116.  
  117. def update
  118. pbUpdateSpriteHash(@sprites)
  119. end
  120.  
  121. def pbDisplayConfirm(text)
  122. ret=-1
  123. oldtext=@sprites["messagebox"].text
  124. @sprites["messagebox"].text=text
  125. using(cmdwindow=Window_CommandPokemon.new([_INTL("YES"),_INTL("NO")])){
  126. cmdwindow.z=@viewport.z+1
  127. cmdwindow.visible=false
  128. pbBottomRight(cmdwindow)
  129. cmdwindow.y-=@sprites["messagebox"].height
  130. loop do
  131. Graphics.update
  132. Input.update
  133. cmdwindow.visible=true if !@sprites["messagebox"].busy?
  134. cmdwindow.update
  135. self.update
  136. if Input.trigger?(Input::B) && !@sprites["messagebox"].busy?
  137. ret=false
  138. end
  139. if (Input.trigger?(Input::C) &&
  140. @sprites["messagebox"].resume && !@sprites["messagebox"].busy?)
  141. ret=(cmdwindow.index==0)
  142. break
  143. end
  144. end
  145. }
  146. @sprites["messagebox"].text=oldtext
  147. return ret
  148. end
  149.  
  150. def pbEndScene
  151. pbFadeOutAndHide(@sprites) { update }
  152. pbDisposeSpriteHash(@sprites)
  153. @viewport.dispose
  154. end
  155.  
  156. class CharacterSelectionPlane < AnimatedPlane
  157. LIMIT=16
  158.  
  159. def initialize(speed, turnTime, viewport)
  160. super(viewport)
  161. @speed = speed
  162. @turnTime = turnTime
  163. end
  164.  
  165. def update
  166. super
  167. @frame=0 if !@frame
  168. @frame+=1
  169. @direction=0 if !@direction
  170. if @frame==@turnTime
  171. @frame=0
  172. @direction+=1
  173. @direction=0 if @direction==4
  174. end
  175. case @direction
  176. when 0 #down
  177. self.oy+=@speed
  178. when 1 #left
  179. self.ox-=@speed
  180. when 2 #up
  181. self.oy-=@speed
  182. when 3 #right
  183. self.ox+=@speed
  184. end
  185. self.ox=0 if self.ox==-LIMIT || self.ox==LIMIT
  186. self.oy=0 if self.oy==-LIMIT || self.oy==LIMIT
  187. end
  188. end
  189.  
  190. class AnimatedChar < AnimatedSprite
  191. def initialize(*args)
  192. viewport = args[4]
  193. @sprite=Sprite.new(viewport)
  194. @animname=pbBitmapName(args[0])
  195. @framecount=args[1]
  196. @frameskip=[1,args[2]].max
  197. @turnTime=args[3]
  198. @realframes=0
  199. @realframeschar=0
  200. @direction=0
  201. begin
  202. @animbitmap=AnimatedBitmap.new(animname).deanimate
  203. rescue
  204. @animbitmap=Bitmap.new(framecount*4,32)
  205. end
  206. if @animbitmap.width%framecount!=0
  207. raise _INTL("Bitmap's width ({1}) is not a multiple of frame count ({2}) [Bitmap={3}]",@animbitmap.width,framewidth,animname)
  208. end
  209. @framewidth=@animbitmap.width/@framecount
  210. @frameheight=@animbitmap.height/4
  211. @framesperrow=framecount
  212. @playing=false
  213. self.bitmap=@animbitmap
  214. self.src_rect.width=@framewidth
  215. self.src_rect.height=@frameheight
  216. self.ox=@framewidth/2
  217. self.oy=@frameheight
  218. self.frame=0
  219. end
  220.  
  221. def frame=(value)
  222. @frame=value
  223. @realframes=0
  224. self.src_rect.x=@frame%@framesperrow*@framewidth
  225. end
  226.  
  227. def update
  228. super
  229. if @playing
  230. @realframeschar+=1
  231. if @realframeschar==@turnTime
  232. @realframeschar=0
  233. @direction+=1
  234. @direction= 0 if @direction==4
  235. #Spin
  236. if @direction==2
  237. dir=3
  238. elsif @direction==3
  239. dir=2
  240. else
  241. dir=@direction
  242. end
  243. self.src_rect.y=@frameheight*dir
  244. end
  245. end
  246. end
  247. end
  248. end
  249.  
  250. class CharacterSelectionScreen
  251. def initialize(scene)
  252. @scene=scene
  253. end
  254.  
  255. def pbStartScreen(overworld,battle)
  256. @scene.pbStartScene(overworld,battle)
  257. ret = @scene.pbMidScene
  258. @scene.pbEndScene
  259. return ret
  260. end
  261. end
  262.  
  263. def pbCharacterSelection(overworld,battle)
  264. ret = nil
  265. pbFadeOutIn(99999) {
  266. scene=CharacterSelectionScene.new
  267. screen=CharacterSelectionScreen.new(scene)
  268. ret=screen.pbStartScreen(overworld,battle)
  269. }
  270. return ret
  271. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement