Advertisement
Guest User

Untitled

a guest
Nov 29th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.36 KB | None | 0 0
  1. ################################################################################
  2. # Unown Script
  3. # By Richard PT
  4. ################################################################################
  5. # Turns a normal string into a Unown string and displays it.
  6. #
  7. # How to use:
  8. # - Insert the graphics provided to: YourGameFolder/Graphics/Pictures OR add
  9. # your own graphics (to the same folder)
  10. # - Customize the settings to make sure everything works the way it should
  11. # - Test it out
  12. # - Report any problems
  13. #
  14. #
  15. # Call with: Unown.show("Text")
  16. ################################################################################
  17.  
  18.  
  19. class Unown
  20. BackgroundFile = "UnownBackground" # Background of the Unown (EG a stone tablet)
  21. FilePrefix = "Unown" # The prefix of the Unown characters (EG if the prefix
  22. # is "Unown_" then it will look for "Unown_A",
  23. # "Unown_B", "Unown_C", ect.)
  24.  
  25. # THESE OPTIONS ARE MEASURED IN PIXELS!
  26. UnownStartX = 32 # The Starting X (per line) on which a Unown character is shown
  27. UnownStartY = 32 # The Starting Y point on which Unown is shown
  28. UnownNewLineAt = Graphics.width - UnownStartX # The maximum X before we go to
  29. # a new line
  30.  
  31. # THESE OPTIONS ARE MEASURED IN PIXELS!
  32. UnownPaddingX = 10 # Padding between each Unown character (Left to Right)
  33. UnownPaddingY = 10 # Padding between each Unown character (Top to Bottom)
  34.  
  35.     def self.show(text)
  36.       scene = Unown.new(text)
  37.       scene.main
  38.     end
  39.    
  40.     def initialize(text)
  41.       @text = unownAlphabetString(text)
  42.       @exit = false
  43.     end
  44.    
  45.     # Converts a normal string into an unown alphabetical string
  46.     # Removes all uneeded characters, converts numbers into the correct format
  47.     # ect.
  48.     def unownAlphabetString(input)
  49.       input[/([A-Za-z0-9# ]*)/]
  50.       input = $1
  51.       output = ""
  52.       char = "A"
  53.       for i in 0...input.length
  54.         prev_char = char
  55.         charI = input[i]
  56.         char = " "
  57.         char[0] = charI
  58.         # Check to see if we are at the start of an integer
  59.         if (char == "0" || char.to_i != 0) &&
  60.           (prev_char != "0" && prev_char.to_i == 0 && prev_char != "#")
  61.           output += "#" # Add a number sign to the start of numbers
  62.         end
  63.        
  64.         # Convert each integer into a letter, because this is how it is in Unown
  65.         if char == "1"
  66.           output << "A"
  67.         elsif char == "2"
  68.           output << "B"
  69.         elsif char == "3"
  70.           output << "C"
  71.         elsif char == "4"
  72.           output << "D"
  73.         elsif char == "5"
  74.           output << "E"
  75.         elsif char == "6"
  76.           output << "F"
  77.         elsif char == "7"
  78.           output << "G"
  79.         elsif char == "8"
  80.           output << "H"
  81.         elsif char == "9"
  82.           output << "I"
  83.         elsif char == "0"
  84.           output << "J"
  85.         else # If it's not a letter, just add the character.
  86.           output << char
  87.         end
  88.       end
  89.       return output
  90.     end
  91.    
  92.     def create_spriteset
  93.       @sprites = {}
  94.       @sprites["background"] = IconSprite.new
  95.       @sprites["background"].setBitmap("Graphics/Pictures/" + BackgroundFile)
  96.       x = UnownStartX + UnownPaddingX
  97.       y = UnownStartY + UnownPaddingY
  98.       for i in 0...@text.length
  99.         file = "Graphics/Pictures/" + FilePrefix + "A"
  100.         t = @text[i]
  101.         if t == "#"[0]
  102.           t = "NS"
  103.         elsif t == " "[0]
  104.           t = "Space"
  105.         end
  106.         file[file.length - 1] = t
  107.         if FileTest.image_exist?(file)
  108.           @sprites["letter#{i}"] = IconSprite.new(x, y)
  109.           @sprites["letter#{i}"].setBitmap(file)
  110.           x += @sprites["letter#{i}"].bitmap.width + UnownPaddingX
  111.           if x >= UnownNewLineAt - UnownPaddingX
  112.             x = UnownStartX + UnownPaddingX
  113.             y += @sprites["letter#{i}"].bitmap.height + UnownPaddingX
  114.           end
  115.         else
  116.           c = "A"
  117.           c[0] = @text[i]
  118.           c = c.upcase
  119.           raise "Could not find the file Unown file for the character: #{c}!"
  120.         end
  121.       end
  122.     end
  123.    
  124.     def main
  125.       create_spriteset
  126.       loop do
  127.         Graphics.update
  128.         Input.update
  129.         update
  130.         break if @exit
  131.       end
  132.       pbDisposeSpriteHash(@sprites)
  133.     end
  134.    
  135.    
  136.     def update
  137.       pbUpdateSpriteHash(@sprites)
  138.       if Input.trigger?(Input::C) || Input.trigger?(Input::B)
  139.         @exit = true
  140.       end
  141.     end
  142. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement