Advertisement
Guest User

hyper lode runner gb luascript bizhawk 1.11.6 mugg v6

a guest
Aug 10th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.56 KB | None | 0 0
  1. -- Luascript for Bizhawk 1.11.6
  2. -- by mugg1991 10th Aug 2016
  3. -- Hyper Lode Runner (W) (v1.1).gb
  4.  
  5. memory.usememorydomain("System Bus")
  6.  
  7. function text(x, y, text, col1, col2)
  8.     if col2==nil then col2=0x00000000 end
  9.     gui.pixelText(x, y, text,col1,col2)
  10. end
  11.  
  12. function box(x,y,x2,y2,col1,col2)
  13.     gui.drawBox(x,y,x2,y2,col1,col2)
  14. end
  15.  
  16. function line(x,y,x2,y2,col)
  17.     gui.drawLine(x,y,x2,y2,col)
  18. end
  19.  
  20. function pixel(x,y,col)
  21.     gui.drawPixel(x,y,col)
  22. end
  23.  
  24. function img(x,y,path)
  25.     gui.drawImage(path,x,y)
  26. end
  27.  
  28. function drawButton(posx,posy,width,height,color,frequency,label,clickedfunction)
  29.    
  30.     if MouseX>posx and MouseX<posx+width and MouseY>posy and MouseY<posy+height then
  31.  
  32.         if clicked and clickedFrames%frequency==1 then
  33.             clickedfunction()
  34.         end
  35.         gui.drawBox(posx,posy,posx+width,posy+height,0xFF808080,color+0xFF303030)
  36.     else
  37.         gui.drawBox(posx,posy,posx+width,posy+height,0xFF808080,color)
  38.     end
  39.    
  40.     text(posx+1,posy+1,label,0xFFFFFFFF)
  41.        
  42. end
  43.  
  44. levelMap={}
  45. room2_timerBefore=memory.read_u8(0xc049)
  46.  
  47.  
  48. BoolDisplayLevelMap=true
  49. BoolDisplayPlayers=true
  50. BoolDisplayCameraOutline=false
  51. BoolHighlightRespawnLocations=false
  52. clickedFrames=0
  53. clicked=false
  54.  
  55. local drawFramecountAndInput = function(x,y)
  56.  
  57.     if movie.mode()=="PLAY" then
  58.         text(x, y,emu.framecount().."/"..movie.length(),0xFFFFFFFF)
  59.     else
  60.         text(x, y,emu.framecount(),0xFFFFFFFF)
  61.     end
  62.        
  63.     text(x, y+8,emu.lagcount(),0xFFF08080)
  64.  
  65.     if emu.islagged() then
  66.         text(x+14, y+8,"*",0xFFF08080)
  67.     end
  68.    
  69.     local inputtable = {}
  70.    
  71.     if movie.mode()=="INACTIVE" then
  72.         inputtable = joypad.getimmediate()
  73.     elseif movie.mode()=="PLAY" or movie.mode()=="RECORD" then
  74.         inputtable = movie.getinput(emu.framecount()-1)
  75.     end
  76.    
  77.     local buttons = {["Up"]="^", ["Down"]="v", ["Left"]="<", ["Right"]=">", ["Select"]="s", ["Start"]="S", ["A"]="A", ["B"]="B", ["L"]="L", ["R"]="R"}
  78.     local s = ""
  79.     for k,v in pairs(inputtable) do
  80.         if v==true then
  81.             s=s..buttons[k]
  82.         end
  83.     end
  84.     text(x+26,y+8,s,0xFFffffff)
  85.  
  86. end
  87.  
  88. local updateLevelMap = function()
  89.     levelMap={}
  90.     for i=0,288,1 do
  91.         value=memory.read_s8(0xC96B+i)
  92.         value=string.format("%X",value)
  93.         table.insert(levelMap,value)           
  94.  
  95.     end
  96.  
  97. end
  98.  
  99. local drawCameraOutline = function()
  100.        
  101.     box(10,49,83,50+camy,0x00000000,0xA0000000) -- top
  102.     if camy < 16 then box(10,98+camy,83,114,0x00000000,0xA0000000) end -- bottom
  103.     if camx > 5 then box(10,49+camy,5+camx,math.min(99+camy,114),0x00000000,0xA0000000) end -- left
  104.     if camx < 34 then box(camx+59,camy+49,83,math.min(99+camy,114),0x00000000,0xA0000000) end -- right
  105.    
  106.     box(math.max(5+camx,10),49+camy,math.min(54+camx+5,83),math.min(98+camy,114),0xFFA0A020,0x08FFFFFF)
  107.     --text(100,50,camx,0x80000000,0xFFFFFFFF)
  108.     --text(100,60,camy,0x80000000,0xFFFFFFFF)
  109.    
  110. end
  111.  
  112. local drawPlayers = function()
  113.     text(10+player_xpos,49+player_ypos,"x",0xFF00FF00)
  114.    
  115.     if enemy1_exists then
  116.         text(10+enemy1_xpos,49+enemy1_ypos,"1",0xFFFFFFFF)
  117.     end
  118.    
  119.     if enemy2_exists then
  120.         text(10+enemy2_xpos,49+enemy2_ypos,"2",0xFFFFFFFF)
  121.     end
  122.    
  123.     if enemy3_exists then
  124.         text(10+enemy3_xpos,49+enemy3_ypos,"3",0xFFFFFFFF)
  125.     end
  126. end
  127.  
  128. local drawLevelMap = function()
  129.  
  130.     if emu.framecount()%15==0 then
  131.         updateLevelMap()
  132.     end
  133.    
  134.     index=1
  135.     if table.getn(levelMap)~=0 then
  136.         for a=1,16,1 do
  137.             for b=1,18,1 do
  138.  
  139.                 if levelMap[index] ..""==0 .."" then --brick
  140.                     box(6+b*4,45+a*4,11+b*4,50+a*4,0x00000000,0xFF805010)
  141.                 elseif levelMap[index] ..""==1 .."" then --block
  142.                     box(6+b*4,45+a*4,11+b*4,50+a*4,0x00000000,0xFF606060)
  143.                 elseif levelMap[index] ..""==2 .."" then --ladder
  144.                     line(7+b*4,46+a*4,7+b*4,49+a*4,0xFFC04040)
  145.                     line(10+b*4,46+a*4,10+b*4,49+a*4,0xFFC04040)
  146.                     line(7+b*4,46+a*4,10+b*4,46+a*4,0xFFC04040)
  147.                     line(7+b*4,48+a*4,10+b*4,48+a*4,0xFFC04040)
  148.                 elseif levelMap[index] ..""==3 .."" then --hanging rope
  149.                     line(7+b*4,47+a*4,10+b*4,47+a*4,0xFFC0A070)
  150.                 elseif levelMap[index] ..""==4 .."" then --gold
  151.                     line(8+b*4,47+a*4,9+b*4,47+a*4,0xFFC0A020)
  152.                     line(7+b*4,48+a*4,10+b*4,48+a*4,0xFFC0A020)
  153.                     line(7+b*4,49+a*4,10+b*4,49+a*4,0xFFC0A020)
  154.                 elseif levelMap[index] ..""==25 .."" then --hidden ladder
  155.                     line(7+b*4,46+a*4,7+b*4,49+a*4,0xFF702020)
  156.                     line(10+b*4,46+a*4,10+b*4,49+a*4,0xFF702020)
  157.                     line(7+b*4,46+a*4,10+b*4,46+a*4,0xFF702020)
  158.                     line(7+b*4,48+a*4,10+b*4,48+a*4,0xFF702020)
  159.                 elseif levelMap[index] ..""==9 .."" then --key
  160.                     line(6+b*4,47+a*4,8+b*4,47+a*4,0xFF904090)
  161.                     pixel(6+b*4,48+a*4,0xFF904090)
  162.                     pixel(10+b*4,47+a*4,0xFF904090)
  163.                     line(9+b*4,48+a*4,10+b*4,48+a*4,0xFF904090)
  164.                     line(8+b*4,46+a*4,10+b*4,46+a*4,0xFF904090)
  165.                 elseif levelMap[index] ..""==8 .."" then --door
  166.                     box(7+b*4,46+a*4,10+b*4,50+a*4,0x00000000,0xFF600060)
  167.                     line(7+b*4,47+a*4,7+b*4,49+a*4,0xFF904090)
  168.                     line(8+b*4,46+a*4,9+b*4,46+a*4,0xFF904090)
  169.                     line(10+b*4,47+a*4,10+b*4,49+a*4,0xFF904090)
  170.                 elseif levelMap[index] ..""==33 .."" then --trap block
  171.                     box(6+b*4,45+a*4,11+b*4,50+a*4,0x00000000,0xFF303030)
  172.                 end
  173.                
  174.                 index=index+1
  175.                 if index>table.getn(levelMap) then index=table.getn(levelMap) end
  176.             end
  177.         end
  178.     end
  179.    
  180. end
  181.  
  182. event.onloadstate(function()
  183.     updateLevelMap()
  184.     room2_timerBefore=memory.read_u8(0xc049)
  185. end)
  186.  
  187. event.onexit(function()
  188.     client.SetGameExtraPadding(0,0,0,0)
  189.     client.SetClientExtraPadding(0,0,0,0)
  190. end)
  191.  
  192. client.SetGameExtraPadding(95,0,0,0)
  193. updateLevelMap()
  194.  
  195. while true do
  196.  
  197.     MouseX = input.getmouse().X+95
  198.     MouseY = input.getmouse().Y
  199.     clicked = input.getmouse().Left
  200.    
  201.     if clicked then clickedFrames = clickedFrames + 1
  202.     else clickedFrames = 0 end
  203.  
  204.     player_xpos=    (memory.read_u8(0xc003)-22)/3
  205.     player_ypos=    memory.read_u8(0xc005)/3
  206.     enemy1_xpos=    (memory.read_u8(0xc013)-22)/3
  207.     enemy1_ypos=    memory.read_u8(0xc015)/3
  208.     enemy2_xpos=    (memory.read_u8(0xc023)-22)/3
  209.     enemy2_ypos=    memory.read_u8(0xc025)/3
  210.     enemy3_xpos=    (memory.read_u8(0xc033)-22)/3
  211.     enemy3_ypos=    memory.read_u8(0xc035)/3
  212.     camx=           memory.read_u8(0xffcc)/3
  213.     camy=           memory.read_u8(0xffce)/3
  214.     camx_restriction= memory.read_u8(0xffd2)/3
  215.     camy_restriction= memory.read_u8(0xffd3)/3
  216.     enemy1_droptimer=0
  217.     enemy2_droptimer=0
  218.     enemy3_droptimer=0
  219.    
  220.     if memory.read_u8(0xc010)>0 then
  221.         enemy1_exists=true
  222.     else enemy1_exists=false end
  223.    
  224.     if memory.read_u8(0xc020)>0 then
  225.         enemy2_exists=true
  226.     else enemy2_exists=false end
  227.    
  228.     if memory.read_u8(0xc030)>0 then
  229.         enemy3_exists=true
  230.     else enemy3_exists=false end
  231.    
  232.    
  233.     if enemy1_exists and memory.read_u8(0xc01F)==0xFF then
  234.         enemy1_droptimer= memory.read_u8(0xc019)
  235.     end
  236.    
  237.     if enemy2_exists and memory.read_u8(0xc02F)==0xFF then
  238.         enemy2_droptimer= memory.read_u8(0xc029)
  239.     end
  240.    
  241.     if enemy3_exists and memory.read_u8(0xc03F)==0xFF then
  242.         enemy3_droptimer= memory.read_u8(0xc039)
  243.     end
  244.    
  245.     globaltimer=    memory.read_u8(0xffd4)
  246.     room2_timer=    memory.read_u8(0xc049)
  247.    
  248.     if memory.read_u8(0x9067)==0 and memory.read_u8(0x9087)==0 then
  249.         room=0
  250.     elseif memory.read_u8(0x9067)==255 and memory.read_u8(0x9087)==255 then
  251.         room=1
  252.     else
  253.         room=-1
  254.     end
  255.  
  256.     level=          memory.read_u8(0xff9d)+1 .. "-" .. room+1
  257.  
  258.     if memory.read_u8(0xff96)==0 and room==1 then
  259.         if room2_timer==0 then
  260.             room2_timer=-1
  261.             room2_timerBefore=room2_timer
  262.         elseif room2_timer==30 and room2_timerBefore==0 then
  263.             room2_timer=-1
  264.             room2_timerBefore=room2_timer
  265.         elseif room2_timerBefore==-1 then
  266.             room2_timer=-1
  267.         else
  268.             room2_timerBefore=room2_timer-1
  269.             room2_timer=room2_timer-1 .. ":" .. 64-(globaltimer-1)%64 -1
  270.         end
  271.     else
  272.         room2_timer="-"
  273.     end
  274.    
  275.     gold_left=      memory.read_u8(0xffb4)
  276.     if gold_left==0xFF then gold_left="done!" end
  277.            
  278.     -- background gradient
  279.     for s=1,18,1 do
  280.         col=0x80606060 - s*0x07000000
  281.         box(-5+4*s,-1,4*s,160,0x00000000,col)
  282.     end
  283.    
  284.     -- framecount, lag, input
  285.     drawFramecountAndInput(52,4)
  286.  
  287.     -- level display
  288.     box(9,48,84,115,0xFF404000,0xFF000000)
  289.     box(10,49,83,114,0xFFA0A040,0xFF000000)
  290.    
  291.     if BoolDisplayLevelMap then
  292.         drawLevelMap()
  293.         mapcol=0xFF606060
  294.     else
  295.         mapcol=0xFF000000
  296.     end
  297.    
  298.  
  299.     -- camera outline display
  300.     if BoolDisplayCameraOutline then
  301.         drawCameraOutline()
  302.         camcol=0xFF606060
  303.     else
  304.         camcol=0xFF000000
  305.     end
  306.    
  307.     -- player display
  308.     if BoolDisplayPlayers then
  309.         drawPlayers()
  310.         playercol=0xFF606060
  311.     else
  312.         playercol=0xFF000000
  313.     end
  314.    
  315.     -- respawn locations
  316.         --todo
  317.        
  318.     -- buttons
  319.    
  320.     drawButton(85,49,7,9,mapcol,10,"m", function()
  321.         BoolDisplayLevelMap=not BoolDisplayLevelMap
  322.     end)
  323.        
  324.     drawButton(85,62,7,9,playercol,10,"p", function()
  325.         BoolDisplayPlayers=not BoolDisplayPlayers
  326.     end)
  327.    
  328.     drawButton(85,75,7,9,camcol,10,"c", function()
  329.         BoolDisplayCameraOutline=not BoolDisplayCameraOutline
  330.     end)
  331.    
  332.     -- stuff
  333.     if room2_timer==-1 then
  334.         box(10,29,82,40,0xFF404040,0xFF202020)
  335.         text(14,31,"   unwinnable!   ",0xFFFF0000)
  336.     else
  337.         text(10,23,"globaltimer: "..globaltimer,0xFF808080)
  338.         text(10,31,"room2 timer: "..room2_timer,0xFF808080)
  339.         text(10,39,"gold left: "..gold_left,0xFF808080)
  340.     end
  341.    
  342.     if enemy1_exists then
  343.         if enemy1_droptimer>0 then
  344.             col=0xFFFF8080
  345.         else
  346.             col=0xFF80FF80
  347.         end
  348.         text(10,118,"enemy1 drop: "..enemy1_droptimer,col)
  349.     end
  350.  
  351.     if enemy2_exists then
  352.         if enemy2_droptimer>0 then
  353.             col=0xFFFF8080
  354.         else
  355.             col=0xFF80FF80
  356.         end
  357.         text(10,126,"enemy2 drop: "..enemy2_droptimer,col)
  358.     end
  359.  
  360.     if enemy3_exists then
  361.         if enemy3_droptimer>0 then
  362.             col=0xFFFF8080
  363.         else
  364.             col=0xFF80FF80
  365.         end
  366.         text(10,134,"enemy3 drop: "..enemy3_droptimer,col)
  367.     end
  368.    
  369.     text(10,5,"Level\n"..level,0xFFD0A020)
  370.    
  371.    
  372.     --text(100,0,string.format("x: %03s", tostring(memory.read_u8(0xc003))).. string.format("  y: %03s", tostring(memory.read_u8(0xc005))),0xFFFFFFFF,0x80000000)
  373.  
  374.     emu.frameadvance()
  375.  
  376. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement