Advertisement
AngryPacman

max pls

Jun 15th, 2014
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.37 KB | None | 0 0
  1. # =============================================================================
  2. # Map Saver
  3. # Version 1.0
  4. # Author: Omegas7 and Pacman
  5. # Credit: Woratana for PNG Saver script.
  6. # =============================================================================
  7. # Save a whole map into a .png file by taking multiple screenshots and finally
  8. # combining them. Exporting the resulting bitmap to a .png image file using
  9. # Woratana's PNG Saver script.
  10. # =============================================================================
  11. # Instructions:
  12. #   Go to Paint or whatever image editing software you want.
  13. #   Create a new file, width and height will be the same as your map, but
  14. #   multiplied by 32. (If map's width is 20, the image's width will be 640).
  15. #   Name the image "Blank", and save it on the System folder of your game.
  16. #   Go to your game map, and put the player starting position on the
  17. #   bottom left part of the map.
  18. #   Now make a new event, autorun, with script call:
  19. #   $saver = Map_Saver.new
  20. #   Then turn self-switch A ON.
  21. #   Go to the event's second page, put as condition self-switch A, then put
  22. #   script call:
  23. #   $saver.update
  24. #   Finally make the second page to be autorun as well.
  25. #   Run the game, you will see the map will start scrolling. Let it be.
  26. #   At the end the script will start creating the image file, this process
  27. #   may take several minutes depending on your map's size.
  28. # =============================================================================
  29. # Notes:
  30. #   The final result will be an image file located on your game's main folder.
  31. #   The image will be exactly what appears on the screen, so if you got a HUD,
  32. #   it will appear as well.
  33. #   If you notice a problem with the final result, like with tiles etc,
  34. #   try activating "weird mode" below.
  35. #   If the final result is still not fixed, try to get support.
  36. # =============================================================================
  37.  
  38. class Map_Saver
  39.   def initialize
  40.  
  41.     # If the resulting image seems to be wrongly made, try turning this value
  42.     # to "true". Normally, this should be false.
  43.     @weird_mode = false
  44.  
  45.     @result = Bitmap.new("Graphics/System/Blank")
  46.     @bitmaps = []
  47.     @moving = true
  48.     @last_place = 'none'
  49.     @finishing = false
  50.     @pause_time = 30
  51.     @scrolling_x = 13
  52.   end
  53.   def update
  54.     if !(@finishing)
  55.       if !($game_map.scrolling?)
  56.         if @moving
  57.           execute_image
  58.         else
  59.           if can_move?(8)
  60.             $game_map.start_scroll(8, @scrolling_x, 7)
  61.             @moving = true
  62.             @last_place = 'down'
  63.           elsif can_move?(6) && @last_place == 'down'
  64.             $game_map.start_scroll(6, 17, 7)
  65.             @last_place = 'left'
  66.           elsif can_move?(2) && @last_place == 'left'
  67.             $game_map.start_scroll(2, $game_map.height, 9)
  68.             @last_place = 'up'
  69.             @moving = true
  70.           else
  71.             @finishing = true
  72.             for i in 0...@bitmaps.size
  73.               y = @bitmaps[i][2]*32
  74.               if @bitmaps[i][3] == true
  75.                 y += 16 if @weird_mode
  76.               end
  77.               @result.blt(@bitmaps[i][1]*32,y,@bitmaps[i][0],
  78.               Rect.new(0,0,Graphics.width,Graphics.height))
  79.             end
  80.             @result.make_png("Here's your map Max",'')
  81.             print "Map image production is over!"
  82.             exit
  83.           end
  84.         end
  85.       end
  86.     end
  87.   end
  88.   def execute_image
  89.     Graphics.freeze
  90.     @bitmaps.push([Graphics.snap_to_bitmap,
  91.     $game_map.display_x,
  92.     $game_map.display_y,
  93.     nil])
  94.     @moving = false
  95.     Graphics.transition(@pause_time)
  96.     if can_move?(8) && can_move?(2)
  97.       @bitmaps[@bitmaps.size - 1][3] = true
  98.     end
  99.   end
  100.   def can_move?(direction)
  101.     case direction
  102.     when 6
  103.       return false if ($game_map.display_x) == ($game_map.width - Graphics.width / 32)
  104.       return true
  105.     when 2
  106.       return false if ($game_map.display_y) == ($game_map.height - Graphics.height / 32)
  107.       return true
  108.     when 4
  109.       return false if ($game_map.display_x == 0)
  110.       return true
  111.     when 8
  112.       return false if ($game_map.display_y == 0)
  113.       return true
  114.     end
  115.   end
  116. end
  117.  
  118. # =============================================================================
  119. # PNG Saver by Woratana.
  120. # =============================================================================
  121. module Zlib
  122.   class Png_File < GzipWriter
  123.     def make_png(bitmap, mode = 0)
  124.       @bitmap, @mode = bitmap, mode
  125.       create_loader
  126.       self.write(make_header)
  127.       self.write(make_ihdr)
  128.       self.write(make_idat)
  129.       self.write(make_iend)
  130.     end
  131.     def create_loader
  132.       w = @bitmap.width
  133.       h = @bitmap.height
  134.       @calculated = [0,nil]
  135.       @calculated[1] = (w*h).to_f
  136.       @window = Window_Base.new(0,150,544,116)
  137.       @window.contents.font.size = 16
  138.       @update = ((@bitmap.width*@bitmap.height)/3000.0).floor.to_i
  139.       refresh_loader
  140.     end
  141.     def refresh_loader
  142.       Graphics.update
  143.       @window.contents.clear
  144.       text = ['Creating image file, please wait...',
  145.       percent.to_s + '% done...']
  146.       for i in 0...text.size
  147.         @window.contents.draw_text(0,20*i,520,20,text[i])
  148.       end
  149.       Graphics.update
  150.     end
  151.     def percent
  152.       return ((100/@calculated[1])*@calculated[0]).floor
  153.     end
  154.     def make_header
  155.       return [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a].pack('C*')
  156.     end
  157.     def make_ihdr
  158.       ih_size               = [13].pack('N')
  159.       ih_sign               = 'IHDR'
  160.       ih_width              = [@bitmap.width].pack('N')
  161.       ih_height             = [@bitmap.height].pack('N')
  162.       ih_bit_depth          = [8].pack('C')
  163.       ih_color_type         = [6].pack('C')
  164.       ih_compression_method = [0].pack('C')
  165.       ih_filter_method      = [0].pack('C')
  166.       ih_interlace_method   = [0].pack('C')
  167.       string = ih_sign + ih_width + ih_height + ih_bit_depth + ih_color_type +
  168.                ih_compression_method + ih_filter_method + ih_interlace_method
  169.       ih_crc = [Zlib.crc32(string)].pack('N')
  170.       return ih_size + string + ih_crc
  171.     end
  172.     def make_idat
  173.       header  = "\x49\x44\x41\x54"
  174.       data    = @mode == 0 ? make_bitmap_data0 : make_bitmap_data1
  175.       data    = Zlib::Deflate.deflate(data, 8)
  176.       crc     = [Zlib.crc32(header + data)].pack('N')
  177.       size    = [data.length].pack('N')
  178.       return size + header + data + crc
  179.     end
  180.     def make_bitmap_data0
  181.       gz = Zlib::GzipWriter.open('png2.tmp')
  182.       t_Fx = 0
  183.       w = @bitmap.width
  184.       h = @bitmap.height
  185.       data = []
  186.       for y in 0...h
  187.         data.push(0)
  188.         for x in 0...w
  189.           t_Fx += 1
  190.           if t_Fx % 10000 == 0
  191.             Graphics.update
  192.           end
  193.           if t_Fx % 100000 == 0
  194.             s = data.pack('C*')
  195.             gz.write(s)
  196.             data.clear
  197.           end
  198.           color = @bitmap.get_pixel(x, y)
  199.           red = color.red
  200.           green = color.green
  201.           blue = color.blue
  202.           alpha = color.alpha
  203.           data.push(red)
  204.           data.push(green)
  205.           data.push(blue)
  206.           data.push(alpha)
  207.           @calculated[0] += 1
  208.           if @calculated[0] % @update == 0
  209.             refresh_loader
  210.           end
  211.         end
  212.       end
  213.       s = data.pack('C*')
  214.       gz.write(s)
  215.       gz.close  
  216.       data.clear
  217.       gz = Zlib::GzipReader.open('png2.tmp')
  218.       data = gz.read
  219.       gz.close
  220.       File.delete('png2.tmp')
  221.       return data
  222.     end
  223.     def make_bitmap_data1
  224.       w = @bitmap.width
  225.       h = @bitmap.height
  226.       data = []
  227.       for y in 0...h
  228.         data.push(0)
  229.         for x in 0...w
  230.           color = @bitmap.get_pixel(x, y)
  231.           red = color.red
  232.           green = color.green
  233.           blue = color.blue
  234.           alpha = color.alpha
  235.           data.push(red)
  236.           data.push(green)
  237.           data.push(blue)
  238.           data.push(alpha)
  239.           @calculated[0] += 1
  240.           if @calculated[0] % @update == 0
  241.             refresh_loader
  242.           end
  243.         end
  244.       end
  245.       return data.pack('C*')
  246.     end
  247.     def make_iend
  248.       ie_size = [0].pack('N')
  249.       ie_sign = 'IEND'
  250.       ie_crc  = [Zlib.crc32(ie_sign)].pack('N')
  251.       return ie_size + ie_sign + ie_crc
  252.     end
  253.   end
  254. end
  255. #=============================================================================
  256. # ** Bitmap
  257. #=============================================================================
  258. class Bitmap
  259.   def make_png(name = 'like', path = '', mode = 0)
  260.     Zlib::Png_File.open('png.tmp')   { |gz| gz.make_png(self, mode) }
  261.     Zlib::GzipReader.open('png.tmp') { |gz| $read = gz.read }
  262.     f = File.open(path + name + '.png', 'wb')
  263.     f.write($read)
  264.     f.close
  265.     File.delete('png.tmp')
  266.   end
  267. end
  268.  
  269. class Scene_Title < Scene_Base
  270.   def start
  271.     super
  272.     SceneManager.clear
  273.     Graphics.freeze
  274.     create_command_window
  275.     create_background
  276.     create_foreground
  277.     command_new_game
  278.   end
  279. end
  280.  
  281.  
  282. class Scene_Map < Scene_Base
  283.   #--------------------------------------------------------------------------
  284.   # * Start Processing
  285.   #--------------------------------------------------------------------------
  286.   alias map_export_start start
  287.   def start(*args)
  288.     map_export_start(*args)
  289.     $saver = Map_Saver.new
  290.   end
  291.   alias map_export_update update
  292.   def update(*args)
  293.     map_export_update(*args)
  294.     $saver.update
  295.   end
  296. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement