Advertisement
Guest User

hyper lode runner gb luascript bizhawk 1.11.6 mugg v7

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