Advertisement
Guest User

BW2 Utilities

a guest
Aug 15th, 2016
2,335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.26 KB | None | 0 0
  1. # Be sure to copy this Script ALWAYS when you copy one of the costum scripts.
  2. # Otherwise you can encounter "undefined method" errors, because I created
  3. # these Methods to make a lot of things more simple. It won't have any side
  4. # effects to copy this script, except getting your copied script to work.
  5.  
  6.  
  7. # Just a quick way to bypass repeating these lines.
  8. def pbShowAnimation(sprite)
  9.   @sprites["#{sprite}"].setBitmap("Graphics/Pictures/Universal/#{sprite}2")
  10.   pbWait(10)
  11.   @sprites["#{sprite}"].setBitmap("Graphics/Pictures/Universal/#{sprite}")
  12.   pbWait(5)
  13. end
  14.  
  15. # Returning the current Time in this format: M/D/Y at HH:MM
  16. def retTimeFormatOne
  17.   time=_ISPRINTF("{1:02d}:{2:02d}",Time.now.hour,Time.now.min)
  18.   return ("#{pbGetTimeNow.mon}/#{pbGetTimeNow.day}/#{pbGetTimeNow.year} at #{time}")
  19. end
  20.  
  21. =begin
  22. # draws the BW2 Cursor Sprite.
  23. # NOTE: changing the graphic for the Cursor Sprite is very easy now.
  24. #       feel free to change the width/height of the sprites,graphic etc.
  25. #       Just make sure, that every corner of the cursor is at the corner
  26. #       of the sprite.
  27. def drawBW2Cursor(x,y,width,height)
  28.   disposeBW2Cursor if @cursor_1
  29.   @frame=0
  30.   @shown=0 if @shown==nil;@shown+=1 if !(@shown==2)
  31.   @cursor_1=Sprite.new
  32.   @cursor_1.z=99999
  33.   @cursor_1.bitmap=Bitmap.new("Graphics/Pictures/Universal/select")
  34.   @cursor_2=Sprite.new
  35.   @cursor_2.z=99999
  36.   @cursor_2.bitmap=Bitmap.new("Graphics/Pictures/Universal/select")
  37.   @cursor_3=Sprite.new
  38.   @cursor_3.z=99999
  39.   @cursor_3.bitmap=Bitmap.new("Graphics/Pictures/Universal/select")
  40.   @cursor_4=Sprite.new
  41.   @cursor_4.z=99999
  42.   @cursor_4.bitmap=Bitmap.new("Graphics/Pictures/Universal/select")
  43.   sprite_width_cut=@cursor_1.bitmap.width/2
  44.   sprite_height_cut=@cursor_1.bitmap.height/2
  45.   # x coordinate.
  46.   @cursor_1.x =x
  47.   @cursor_2.x =x
  48.   @cursor_3.x =x+width
  49.   @cursor_4.x =x+width
  50.   # y coordinate.
  51.   @cursor_1.y =y
  52.   @cursor_2.y =y+height
  53.   @cursor_3.y =y
  54.   @cursor_4.y =y+height
  55.   # width.
  56.   @cursor_1.src_rect.width=sprite_width_cut
  57.   @cursor_2.src_rect.width=sprite_width_cut
  58.   @cursor_3.src_rect.width=sprite_width_cut
  59.   @cursor_3.src_rect.x+=sprite_width_cut
  60.   @cursor_4.src_rect.width=sprite_width_cut
  61.   @cursor_4.src_rect.x+=sprite_width_cut
  62.   # height.
  63.   @cursor_1.src_rect.height=sprite_height_cut
  64.   @cursor_2.src_rect.height=sprite_height_cut
  65.   @cursor_2.src_rect.y+=sprite_height_cut
  66.   @cursor_3.src_rect.height=sprite_height_cut
  67.   @cursor_4.src_rect.height=sprite_height_cut
  68.   @cursor_4.src_rect.y+=sprite_height_cut
  69. end
  70.  
  71. # Animates the BW2 Cursor Sprite.
  72. def animateBW2Cursor(width_distance,height_distance,duration)
  73.   @frame+=1
  74.   if @frame<=(duration/2)
  75.     @cursor_1.x-=width_distance
  76.     @cursor_1.y-=height_distance
  77.     @cursor_2.x-=width_distance
  78.     @cursor_2.y+=height_distance
  79.     @cursor_3.x+=width_distance
  80.     @cursor_3.y-=height_distance
  81.     @cursor_4.x+=width_distance
  82.     @cursor_4.y+=height_distance
  83.   elsif @frame>(duration/2)
  84.     @cursor_1.x+=width_distance
  85.     @cursor_1.y+=height_distance
  86.     @cursor_2.x+=width_distance
  87.     @cursor_2.y-=height_distance
  88.     @cursor_3.x-=width_distance
  89.     @cursor_3.y+=height_distance
  90.     @cursor_4.x-=width_distance
  91.     @cursor_4.y-=height_distance
  92.   end
  93.   @frame=0 if @frame>=duration
  94. end
  95.  
  96. # Disposes the BW2 Cursor Sprite.
  97. def disposeBW2Cursor
  98.   return if !@cursor_1
  99.   @cursor_1.dispose
  100.   @cursor_2.dispose
  101.   @cursor_3.dispose
  102.   @cursor_4.dispose
  103. end
  104.  
  105. # Wait and Update Method (Used the most for
  106. def WaitAndUpdate(sprite,path)
  107.   @sprites["#{sprite}"].setBitmap("#{path}2")
  108.   10.times do
  109.     Graphics.update
  110.     Input.update
  111.     pbWait(1)
  112.   end
  113.   @sprites["#{sprite}"].setBitmap("#{path}")
  114.   5.times do
  115.     Graphics.updatevv
  116.     Input.update
  117.     pbWait(1)
  118.   end
  119. end
  120.  
  121. # Positions the Pokémon Sprite into the middle.
  122. def pbPositionBW2Sprite(sprite,x,y)
  123.   if sprite.bitmap && !sprite.bitmap.disposed?
  124.     sprite.x=x-(sprite.bitmap.width/3)
  125.     sprite.y=y-(sprite.bitmap.height/3)
  126.   else
  127.     sprite.x=x
  128.     sprite.y=y
  129.   end
  130. end
  131. =end
  132.  
  133.  
  134. # class which was being made to draw the cursor sprite easily and in a good
  135. # way. thanks Luka S.J for it!
  136. class UniversalCursor
  137.  
  138.   # the filepath to the full cursor sprite
  139.   FILE = "Graphics/Pictures/Universal/select"
  140.   # the border size around the target object by which the cursor sprite will
  141.   # be increased so that it does not overlap the target object
  142.   BORDER = 16 # 8 pixels on each side (to account for animation too)
  143.  
  144.   def initialize(viewport)
  145.     @viewport = viewport
  146.     @sprite = Sprite.new(@viewport)
  147.     @cursor = BitmapCache.load_bitmap(FILE)
  148.     @frame = 0
  149.     @offset = BORDER/2
  150.   end
  151.  
  152.   def setTo(object)
  153.     # ways to create the cursor bitmap when object is a sprite
  154.     if object.is_a?(Sprite)
  155.       if object.bitmap
  156.         @sprite.bitmap = Bitmap.new(object.bitmap.width+BORDER,object.bitmap.height+BORDER)
  157.         @sprite.ox = @sprite.bitmap.width/2
  158.         @sprite.oy = @sprite.bitmap.height/2
  159.         @sprite.x = object.x + object.bitmap.width/2
  160.         @sprite.y = object.y + object.bitmap.height/2
  161.         @sprite.z=object.z+1
  162.       end
  163.     # ways to create the cursor bitmap when object is a rect
  164.     elsif object.is_a?(Rect)
  165.       @sprite.bitmap = Bitmap.new(object.width+BORDER,object.height+BORDER)
  166.       @sprite.ox = @sprite.bitmap.width/2
  167.       @sprite.oy = @sprite.bitmap.height/2
  168.       @sprite.x = object.x + object.width/2
  169.       @sprite.y = object.y + object.height/2
  170.     end
  171.     self.draw
  172.   end
  173.  
  174.   def draw
  175.     return if !@sprite.bitmap
  176.     @sprite.bitmap.clear
  177.     # top left corner
  178.     @sprite.bitmap.blt(0,0,@cursor,Rect.new(@offset,@offset,@cursor.width/2,@cursor.height/2))
  179.     # top right corner
  180.     @sprite.bitmap.blt(@sprite.bitmap.width-@cursor.width/2-@offset,@offset,@cursor,Rect.new(@cursor.width/2,0,@cursor.width/2,@cursor.height/2))
  181.     # bottom left corner
  182.     @sprite.bitmap.blt(@offset,@sprite.bitmap.height-@cursor.height/2-@offset,@cursor,Rect.new(0,@cursor.height/2,@cursor.width/2,@cursor.height/2))
  183.     # bottom right corner
  184.     @sprite.bitmap.blt(@sprite.bitmap.width-@cursor.width/2-@offset,@sprite.bitmap.height-@cursor.height/2-@offset,@cursor,Rect.new(@cursor.width/2,@cursor.height/2,@cursor.width/2,@cursor.height/2))
  185.   end
  186.      
  187.   def animate
  188.     return if !@sprite.bitmap
  189.     @frame+=1
  190.     if @frame > 4
  191.       @offset = (@offset > 0) ? 0 : BORDER/2
  192.       self.draw
  193.       @frame = 0
  194.     end
  195.   end
  196.  
  197.   def dispose
  198.     return if @sprite.disposed?
  199.     @sprite.dispose
  200.   end
  201.  
  202. end
  203.  
  204.  
  205. # class which was made to bypass confusion with the bitmap wrappers and
  206. # to simply use them as sprites. thanks Luka S.J for it!
  207. class AnimatedSpriteWrapper < Sprite
  208.   def setBitmap(path,scale=1)
  209.     @bitmap = AnimatedBitmapWrapper.new(path,scale)
  210.     self.bitmap = @bitmap.bitmap.clone
  211.   end
  212.  
  213.   def play
  214.     @bitmap.play
  215.     self.bitmap = @bitmap.bitmap.clone
  216.   end
  217.  
  218.   def finished?; return @bitmap.finished?; end
  219.   def animatedBitmap; return @bitmap; end
  220.  
  221.   def update
  222.     @bitmap.update
  223.     self.bitmap = @bitmap.bitmap.clone
  224.   end
  225. end
  226.  
  227. # Method for automatically starting the animated stuff.
  228. def startTransition(path)
  229.   sprite=AnimatedSpriteWrapper.new
  230.   sprite.setBitmap(path)
  231.   loop do
  232.     sprite.play
  233.     break if sprite.finished?
  234.     pbWait(1)
  235.   end
  236.   sprite.dispose
  237. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement