Advertisement
Dotsarecool

Kirby and the Amazing Mirror Level Mapping Tool

Feb 28th, 2017
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.58 KB | None | 0 0
  1. -- KatAM level mapping tool by Dotsarecool
  2. -- outputs a bunch of images of the level to be stitched together by another program
  3. local i = 0
  4. local x = 0
  5. local y = 0
  6. local done = false
  7. local level = -1;
  8. local w = 0
  9. local h = 0
  10.  
  11. local BACKGROUND_LAYER_REGISTER = 0x3691
  12. local LEVEL_NUMBER = 0x20F40
  13. local LEVEL_WIDTH = 0x235EC
  14. local LEVEL_HEIGHT = 0x235EE
  15.  
  16. -- camera position
  17. local CAMERA_X_POS = 0x23660
  18. local CAMERA_Y_POS = 0x23662
  19. -- "updated" camera position
  20. -- if camera is out of bounds, this register holds the camera position mod the level width/height
  21. local CAMERA_X_POS_2 = 0x23664
  22. local CAMERA_Y_POS_2 = 0x23666
  23.  
  24. -- Start Main --
  25.  
  26. console.writeline("Starting...")
  27.  
  28. -- disable the background for prettier pictures
  29. memory.usememorydomain("IWRAM")
  30. memory.writebyte(BACKGROUND_LAYER_REGISTER, 0x08)
  31. memory.usememorydomain("EWRAM")
  32. -- grab level info
  33. level = memory.read_u16_le(LEVEL_NUMBER)
  34. -- grab width and height of level so we know how big the final map should be
  35. -- (I should have used these values to iterate over the level space, but these values were found after the majority of the script was written)
  36. w = memory.read_u16_le(LEVEL_WIDTH)
  37. h = memory.read_u16_le(LEVEL_HEIGHT)
  38.  
  39. while not done do
  40.     i = i + 1
  41.  
  42.     memory.write_s16_le(CAMERA_X_POS, x)
  43.     memory.write_s16_le(CAMERA_Y_POS, y)
  44.     emu.frameadvance()
  45.    
  46.     -- if we hit the right edge of the level
  47.     if memory.read_s16_le(CAMERA_X_POS_2) ~= x then
  48.         x = 0
  49.         y = y + 20 * 8
  50.  
  51.         -- move camera down
  52.         memory.write_s16_le(CAMERA_X_POS, x)
  53.         memory.write_s16_le(CAMERA_Y_POS, y)
  54.         emu.frameadvance()
  55.        
  56.         -- if we hit the bottom edge of the level
  57.         if memory.read_s16_le(CAMERA_Y_POS_2) ~= y then
  58.             -- we done, boys
  59.             done = true
  60.         end
  61.     end
  62.    
  63.     if not done then
  64.         local j = 0
  65.         while j < 1 do -- set 1 to something higher to enable slow mode
  66.             memory.write_s16_le(CAMERA_X_POS, x)
  67.             memory.write_s16_le(CAMERA_Y_POS, y)
  68.        
  69.             --gui.drawText(20, 45, "x: " .. x)
  70.             --gui.drawText(20, 55, "y: " .. y)
  71.            
  72.             emu.frameadvance()
  73.             j = j + 1
  74.         end
  75.         -- save the image
  76.         client.screenshot("C:/Users/Alex/Desktop/KatAM/level-" .. level .. "_w-" .. w .. "_h-" .. h .."/y-" .. y .."_x-" .. x .. ".png")
  77.        
  78.         x = x + 30 * 8
  79.     end
  80. end
  81.  
  82. memory.usememorydomain("IWRAM")
  83. -- enable background only
  84. memory.writebyte(BACKGROUND_LAYER_REGISTER, 0x01)
  85. emu.frameadvance()
  86. -- save image of the background
  87. client.screenshot("C:/Users/Alex/Desktop/KatAM/level-" .. level .. "_w-" .. w .. "_h-" .. h .."/b.png")
  88.  
  89. -- restore background layers
  90. memory.writebyte(BACKGROUND_LAYER_REGISTER, 0x1B)
  91. console.writeline("Done.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement