Advertisement
Guest User

sub-terrania mapmaking script

a guest
Sep 16th, 2011
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.82 KB | None | 0 0
  1. print("Sub-Terrania mapmaking Lua script")
  2. print("written by Dammit (September 15, 2011)")
  3. print("for use with: http://code.google.com/p/gens-rerecording/")
  4. print("* get the stage fully loaded and activate Graphics > Lock Pallete")
  5. print("* run from a savestate just before the stage loads")
  6. print("* hotkey 1/2: move camera by one screen width/height")
  7. print("* hotkey 3/4: move camera by half screen width/height")
  8. print()
  9.  
  10. local cheat = function() --unused
  11.     memory.writedword(0xFF5ECC, 0x270000) --inf shield
  12.     memory.writedword(0xFF5ED4, 0x290000) --inf fuel
  13.     memory.writedword(0xFF5EDC, 0x260000) --inf mega
  14. end
  15.  
  16. local screenshots, paused = false, false
  17. local width  = {ship_offset = 0xA0, cam_offset = 0x0, count = 0.0, max =
  18.     {3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 2.0, 3.0, 7.0, 0.5}}
  19. local height = {ship_offset = 0x44, cam_offset = 0x8, count = 0.0, max =
  20.     {3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 5.8, 4.6, 3.5, 0.5}}
  21.  
  22. local setcam = function()
  23.     print("screen widths: " .. width.count .. " / heights: " .. height.count)
  24.     local screen = {width = 0x140, height = 0xE0}
  25.     screen.x = screen.width  * width.count
  26.     screen.y = screen.height * height.count
  27.     screen.filename = "screens/r" .. height.count+1 .. ",c" .. width.count+1 .. ".png"
  28.     screen.x = screen.x +  width.cam_offset --compensate for camera's movement toward ship's facing direction
  29.     screen.y = screen.y + height.cam_offset
  30.     return screen
  31. end
  32. local screen = setcam()
  33.  
  34. local stage
  35. local increment = function(dim)
  36.     local diff = (dim.max[stage] or dim.max[1]) - dim.count
  37.     if diff >= 1 then --increase by one screen if 1+ screens under the max
  38.         return dim.count + 1
  39.     elseif diff <= 0 then --set to zero if over the max
  40.         return 0
  41.     else --set to max if diff is less than one screen
  42.         return dim.max[stage]
  43.     end
  44. end
  45.  
  46. input.registerhotkey(1, function()
  47.     width.count = increment(width)
  48.     screen = setcam()
  49. end)
  50.  
  51. input.registerhotkey(2, function()
  52.     height.count = increment(height)
  53.     screen = setcam()
  54. end)
  55.  
  56. input.registerhotkey(3, function()
  57.     height.count = height.count%1 > 0 and height.count - 0.5 or height.count + 0.5
  58.     screen = setcam()
  59. end)
  60.  
  61. input.registerhotkey(4, function()
  62.     width.count = width.count%1 > 0 and width.count - 0.5 or width.count + 0.5
  63.     screen = setcam()
  64. end)
  65.  
  66. emu.registerbefore(function()
  67.     stage = memory.readword(0xFF003A)
  68.     memory.writeword(0xFF80F0, screen.x) --foreground position
  69.     memory.writeword(0xFF80F4, screen.y)
  70.     memory.writeword(0xFF80E8, screen.x + width.ship_offset) --ship position
  71.     memory.writeword(0xFF80EC, screen.y + height.ship_offset)
  72.     memory.writeword(0xFF8206, 0x0800) --water level
  73.  
  74.     if memory.readdword(0xFF0000) == 0 and not paused then --map loaded
  75.         emu.message()
  76.         emu.pause()
  77.         paused = true
  78.     end
  79. end)
  80.  
  81. savestate.registerload(function()
  82.     paused = false
  83. end)
  84.  
  85. emu.registerstart(function()
  86.     paused = false
  87. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement