-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgramming Board Code
1 lines (1 loc) · 16.9 KB
/
Programming Board Code
1
{"slots":{"0":{"name":"Screen","type":{"events":[],"methods":[]}},"1":{"name":"slot1","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"if Mode == 0 then --If clicking on the title then start level one\n Mode = 1\n return\nend\n\nif Mode == -1 then --If clicking on the scoreboard, then return to title\n Mode = 0\n score = 0\n strikes = ''\n ballcolor = {255, 255, 255}\n backgroundcolor = {128, 128, 128}\n return\nend\n\nif Mode ~= 0 and Mode ~= -1 then\n if math.abs(x*100 - ball.x) < 7 and math.abs(y*100 - ball.y) < 7 then --Did we click on the ball?\n score = score+1\n ball.speed = 1+score/20 --Increase ball speed based on current score\n ball.speed = ball.speed+(score/5 - math.floor(score/5))/2 --Further increase ball speed based on time since the score was a multiple of 5\n if math.ceil(score / 5) == score / 5 then --Every 5 levels remove a strike and change the level\n strikes = strikes == \"XXX\" and \"XX\" or strikes == \"XX\" and \"X\" or strikes == \"X\" and \"\" or \"\" --Remove a strike, to a minimum of 0 strikes\n Mode = Mode+1 --Advance the level, if there is a next level to advance to\n end\n ball.x = math.random()*100 --randomize position of ball\n ball.y = math.random()*100 \n ball.xd = math.random() --Pick random ball direction\n ball.yd = math.random()\n ball.xd, ball.yd = ball.xd/math.sqrt(ball.xd^2+ball.yd^2)*ball.speed, ball.yd/math.sqrt(ball.xd^2+ball.yd^2)*ball.speed --use maths to adjust deltas to current speed \n ball.yd = ball.yd*1.4 --adjust ball deltas to account for widescreens\n ball.xd = ball.xd*0.8\n else --If we missed the ball, add a strike instead\n strikes = strikes..\"X\"\n end\nend\n\nif Mode >= 2 then --Make things more colorful after level 2\n backgroundcolor = ColorList[math.ceil(math.random()*#ColorList)] \n ballcolor = {255-backgroundcolor[1], 255-backgroundcolor[2], 255-backgroundcolor[3]}\nend\n\nif Mode >= 4 then --randomize barriers after level 4\n barrierA.x = 10+math.random()*75 barrierA.y = 10+math.random()*20 barrierA.h = 40+math.random()*20 barrierA.w = 5+math.random()*10 --Tall barrier\n barrierB.x = 10+math.random()*20 barrierB.y = 10+math.random()*75 barrierB.h = 5+math.random()*10 barrierB.w = 40+math.random()*20 --Wide barrier\nend\n\nif strikes == \"XXXX\" then --Four strikes, game over, display scoreboard\n Mode = -1\n TopScores[#TopScores+1] = score --Add player's score\n TopNames[#TopNames+1] = tostring(system.getPlayerName(unit.getMasterPlayerId())) --Add player's name\n for i = #TopScores, 2, -1 do --Sort the top 10 scores\n if TopScores[i-1] == nil or TopScores[i] > TopScores[i-1] then\n TopScores[i], TopScores[i-1] = TopScores[i-1], TopScores[i]\n TopNames[i], TopNames[i-1] = TopNames[i-1], TopNames[i]\n end\n end\n TopScores[11] = nil --delete 11th score, if it exists\n TopNames[11] = nil\n if databank then\n for i = 1, #TopScores do --update databank with top 10 scores\n databank.setStringValue(i,TopNames[i])\n databank.setIntValue(i+10, TopScores[i])\n end\n end\nend","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"0"},"key":"0"},{"code":"for k,v in pairs(unit) do --Find databank slot\n if type(v) == \"table\" and v.getElementClass then\n if v.getElementClass() == \"DataBankUnit\" then databank = v end\n end\nend\n\nScreen.activate()\nMode = 0 -- -1 for scoreboard, 0 for title\nball = {}\nball.x = 50 --Ball position\nball.y = 50\nball.xd = 1 --Ball movement\nball.yd = 1\nball.speed = 1\nball.o = 1 --Ball Opacity\nball.od = 0.02 --Ball Opacity Delta\nscore = 0\nstrikes = ''\nbarrierA = {}\nbarrierB = {}\nunit.setTimer(\"game\", 0.01)\n\nlocal red = {255,0,0}\nlocal maroon = {128, 0, 0}\nlocal lime = {0,255,0}\nlocal green = {0, 128, 0}\nlocal blue = {0,0,255}\nlocal navy = {0, 0, 128}\nlocal magenta = {255,0,255}\nlocal purple = {128, 0, 128}\nlocal cyan = {0, 255, 255}\nlocal teal = {0, 128, 128}\nlocal yellow = {255, 255, 0}\nlocal olive = {128, 128, 0}\nlocal white = {255, 255, 255}\n\nColorList = {white, red, maroon, lime, green, blue, navy, magenta, purple, cyan, teal, yellow, olive}\n\nballcolor = {255, 255, 255}\nbackgroundcolor = {128, 128, 128}\n\nTopScores = {}\nTopNames = {}\nif databank then\nfor i = 1, 10 do\n TopNames[#TopNames+1] = databank.hasKey(i) == 1 and databank.getStringValue(i) or nil\n TopScores[#TopScores+1] = databank.hasKey(i+10) == 1 and databank.getIntValue(i+10) or nil\nend\nend","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"1"},{"code":"if Mode == 0 then --Title Screen\n html = [[<html height:100%;width:100% style=\"background-image: linear-gradient(rgb(50,150,255), rgb(50,150,255), rgb(0,50,100));\">\n <div style=\"height:100%;width:100%;\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n align-content: center;\n font-family: sans-serif;\"> \n <text style=\"font-size:40vh; color:white;font-style:italic;text-shadow: -1vw 1vh 0 rgb(50,100,150);margin:20vh;\">Bounce!</text>\n<text style=\"font-size:3vh; color:black;\">click anywhere</text>\n</div></html>]]\nend\n \nif Mode == 1 or Mode == 2 then --Level 1 and 2\n ball.x = ball.x+ball.xd --Move ball\n ball.y = ball.y+ball.yd\n if ball.x <= 0 then ball.xd = -ball.xd ball.x = -ball.x end --Bounce off left wall\n if ball.x >= 100 then ball.xd = -ball.xd ball.x = 100-(ball.x-100) end --Bounce off right wall\n if ball.y <= 0 then ball.yd = -ball.yd ball.y = -ball.y end --Bounce off top wall\n if ball.y >= 100 then ball.yd = -ball.yd ball.y = 100-(ball.y-100) end --Bounce off bottom wall\n html = \n [[<svg height=100% width=100% style=\"background-color:rgb(]].. backgroundcolor[1] ..[[,]].. backgroundcolor[2] ..[[,]].. backgroundcolor[3] ..[[)\">\n <circle cx=]].. ball.x ..[[vw cy=]].. ball.y ..[[vh r=2vh stroke=\"black\" stroke-width=1 fill=rgb(]].. ballcolor[1] ..[[,]].. ballcolor[2] ..[[,]].. ballcolor[3] ..[[) />\n <text x=40% y=10% fill=\"Black\" font-size=8vh font-family=cursive>Score: ]].. score ..[[</text>\n <text x=5% y=10% fill=\"Red\" font-size=12vh font-family=cursive>]].. strikes ..[[</text>\n </svg>]]\nend\n\nif Mode == 3 then --Level 3\n ball.x = ball.x+ball.xd --Move ball\n ball.y = ball.y+ball.yd\n if score/2 == math.floor(score/2) then\n if ball.x <= 0 then ball.xd = -ball.xd ball.x = -ball.x end --Bounce off left wall\n if ball.x >= 100 then ball.xd = -ball.xd ball.x = 100-(ball.x-100) end --Bounce off right wall\n if ball.y < 0 then ball.y = 100+ball.y end --Ball wraps around top and bottom\n if ball.y > 100 then ball.y = ball.y-100 end\n else\n if ball.x < 0 then ball.x = 100+ball.x end --Ball wraps around left and right\n if ball.x > 100 then ball.x = ball.x-100 end \n if ball.y <= 0 then ball.yd = -ball.yd ball.y = -ball.y end --Bounce off top wall\n if ball.y >= 100 then ball.yd = -ball.yd ball.y = 100-(ball.y-100) end --Bounce off bottom wall \n end\n html = \n [[<svg height=100% width=100% style=\"background-color:rgb(]].. backgroundcolor[1] ..[[,]].. backgroundcolor[2] ..[[,]].. backgroundcolor[3] ..[[)\">\n <circle cx=]].. ball.x ..[[vw cy=]].. ball.y ..[[vh r=2vh stroke=\"black\" stroke-width=1 fill=rgb(]].. ballcolor[1] ..[[,]].. ballcolor[2] ..[[,]].. ballcolor[3] ..[[) />\n <text x=40% y=10% fill=\"Black\" font-size=8vh font-family=cursive>Score: ]].. score ..[[</text>\n <text x=5% y=10% fill=\"Red\" font-size=12vh font-family=cursive>]].. strikes ..[[</text>\n </svg>]] \nend\n\nif Mode == 4 then --Level 4\n ball.x = ball.x+ball.xd --Move ball\n ball.y = ball.y+ball.yd\n if score/2 == math.floor(score/2) then\n if ball.x <= 0 then ball.xd = -ball.xd ball.x = -ball.x end --Bounce off left wall\n if ball.x >= 100 then ball.xd = -ball.xd ball.x = 100-(ball.x-100) end --Bounce off right wall\n if ball.y < 0 then ball.y = 100+ball.y end --Ball wraps around top and bottom\n if ball.y > 100 then ball.y = ball.y-100 end\n else\n if ball.x < 0 then ball.x = 100+ball.x end --Ball wraps around left and right\n if ball.x > 100 then ball.x = ball.x-100 end \n if ball.y <= 0 then ball.yd = -ball.yd ball.y = -ball.y end --Bounce off top wall\n if ball.y >= 100 then ball.yd = -ball.yd ball.y = 100-(ball.y-100) end --Bounce off bottom wall \n end\n barrierA.x = barrierA.x <= 100 and barrierA.x + 1 or 0-barrierA.w\n barrierB.y = barrierB.y <= 100 and barrierB.y + 1 or 0-barrierB.h\n html = \n [[<svg height=100% width=100% style=\"background-color:rgb(]].. backgroundcolor[1] ..[[,]].. backgroundcolor[2] ..[[,]].. backgroundcolor[3] ..[[)\">\n <circle cx=]].. ball.x ..[[vw cy=]].. ball.y ..[[vh r=2vh stroke=\"black\" stroke-width=1 fill=rgb(]].. ballcolor[1] ..[[,]].. ballcolor[2] ..[[,]].. ballcolor[3] ..[[) />\n <rect rx=20 ry= 20 x=]].. barrierA.x ..[[vw y=]].. barrierA.y ..[[vh width=]].. barrierA.w ..[[% height=]].. barrierA.h ..[[% style=\"fill:rgb(]].. ballcolor[1] ..[[,]].. ballcolor[2] ..[[,]].. ballcolor[3] ..[[);stroke-width:3;stroke:black\" />\n <rect rx=20 ry= 20 x=]].. barrierB.x ..[[vw y=]].. barrierB.y ..[[vh width=]].. barrierB.w ..[[% height=]].. barrierB.h ..[[% style=\"fill:rgb(]].. ballcolor[1] ..[[,]].. ballcolor[2] ..[[,]].. ballcolor[3] ..[[);stroke-width:3;stroke:black\" />\n <text x=40% y=10% fill=\"Black\" font-size=8vh font-family=cursive>Score: ]].. score ..[[</text>\n <text x=5% y=10% fill=\"Red\" font-size=12vh font-family=cursive>]].. strikes ..[[</text>\n </svg>]] \nend\n\nif Mode == 5 then --Level 4\n ball.x = ball.x+ball.xd --Move ball\n ball.y = ball.y+ball.yd\n if score/2 == math.floor(score/2) then\n if ball.x <= 0 then ball.xd = -ball.xd ball.x = -ball.x end --Bounce off left wall\n if ball.x >= 100 then ball.xd = -ball.xd ball.x = 100-(ball.x-100) end --Bounce off right wall\n if ball.y < 0 then ball.y = 100+ball.y end --Ball wraps around top and bottom\n if ball.y > 100 then ball.y = ball.y-100 end\n else\n if ball.x < 0 then ball.x = 100+ball.x end --Ball wraps around left and right\n if ball.x > 100 then ball.x = ball.x-100 end \n if ball.y <= 0 then ball.yd = -ball.yd ball.y = -ball.y end --Bounce off top wall\n if ball.y >= 100 then ball.yd = -ball.yd ball.y = 100-(ball.y-100) end --Bounce off bottom wall \n end\n if ball.o <= -0.3 then ball.od = 0.02 elseif ball.o >= 2 then ball.od = -0.02 end --Cycle ball opacity\n ball.o = ball.o + ball.od\n barrierA.x = barrierA.x <= 100 and barrierA.x + 1 or 0-barrierA.w\n barrierB.y = barrierB.y <= 100 and barrierB.y + 1 or 0-barrierB.h\n html = \n [[<svg height=100% width=100% style=\"background-image:linear-gradient(]].. math.atan(ball.x-50,100-ball.y-50)*180/math.pi ..[[deg,rgb(0,0,0),rgb(]].. backgroundcolor[1] ..[[,]].. backgroundcolor[2] ..[[,]].. backgroundcolor[3] ..[[))\">\n <circle cx=]].. ball.x ..[[vw cy=]].. ball.y ..[[vh r=2vh stroke=\"black\" stroke-width=1 fill=rgb(]].. ballcolor[1] ..[[,]].. ballcolor[2] ..[[,]].. ballcolor[3] ..[[) opacity=]].. ball.o ..[[ />\n <rect rx=20 ry= 20 x=]].. barrierA.x ..[[vw y=]].. barrierA.y ..[[vh width=]].. barrierA.w ..[[% height=]].. barrierA.h ..[[% style=\"fill:rgb(]].. ballcolor[1] ..[[,]].. ballcolor[2] ..[[,]].. ballcolor[3] ..[[);stroke-width:3;stroke:black\" />\n <rect rx=20 ry= 20 x=]].. barrierB.x ..[[vw y=]].. barrierB.y ..[[vh width=]].. barrierB.w ..[[% height=]].. barrierB.h ..[[% style=\"fill:rgb(]].. ballcolor[1] ..[[,]].. ballcolor[2] ..[[,]].. ballcolor[3] ..[[);stroke-width:3;stroke:black\" />\n <text x=40% y=10% fill=\"Black\" font-size=8vh font-family=cursive>Score: ]].. score ..[[</text>\n <text x=5% y=10% fill=\"Red\" font-size=12vh font-family=cursive>]].. strikes ..[[</text>\n </svg>]] \nend\n\nif Mode >= 6 then --Level 5\n ball.x = ball.x+ball.xd --Move ball\n ball.y = ball.y+ball.yd\n if score/2 == math.floor(score/2) then\n if ball.x <= 0 then ball.xd = -ball.xd ball.x = -ball.x end --Bounce off left wall\n if ball.x >= 100 then ball.xd = -ball.xd ball.x = 100-(ball.x-100) end --Bounce off right wall\n if ball.y < 0 then ball.y = 100+ball.y end --Ball wraps around top and bottom\n if ball.y > 100 then ball.y = ball.y-100 end\n else\n if ball.x < 0 then ball.x = 100+ball.x end --Ball wraps around left and right\n if ball.x > 100 then ball.x = ball.x-100 end \n if ball.y <= 0 then ball.yd = -ball.yd ball.y = -ball.y end --Bounce off top wall\n if ball.y >= 100 then ball.yd = -ball.yd ball.y = 100-(ball.y-100) end --Bounce off bottom wall \n end\n if ball.o <= -0.3 then ball.od = 0.02 elseif ball.o >= 2 then ball.od = -0.02 end --Cycle ball opacity\n ball.o = ball.o + ball.od\n i = i and i <= 100 and i+1 or 1 --just a cycling number to offset the background\n barrierA.x = barrierA.x <= 100 and barrierA.x + 1 or 0-barrierA.w\n barrierB.y = barrierB.y <= 100 and barrierB.y + 1 or 0-barrierB.h\n html = \n [[<svg height=100% width=100% style=\"background-image:radial-gradient(rgb(]].. backgroundcolor[1] ..[[,]].. backgroundcolor[2] ..[[,]].. backgroundcolor[3] ..[[) ]].. i-100 ..[[%, rgb(0,0,0) ]].. i-50 ..[[%, rgb(]].. backgroundcolor[1] ..[[,]].. backgroundcolor[2] ..[[,]].. backgroundcolor[3] ..[[) ]].. i ..[[%, rgb(0,0,0) ]].. i+50 ..[[%, rgb(]].. backgroundcolor[1] ..[[,]].. backgroundcolor[2] ..[[,]].. backgroundcolor[3] ..[[) ]].. i+100 ..[[%)\">\n <circle cx=]].. ball.x ..[[vw cy=]].. ball.y ..[[vh r=2vh stroke=\"black\" stroke-width=1 fill=rgb(]].. ballcolor[1] ..[[,]].. ballcolor[2] ..[[,]].. ballcolor[3] ..[[) opacity=]].. ball.o ..[[ />\n <rect rx=20 ry= 20 x=]].. barrierA.x ..[[vw y=]].. barrierA.y ..[[vh width=]].. barrierA.w ..[[% height=]].. barrierA.h ..[[% style=\"fill:rgb(]].. ballcolor[1] ..[[,]].. ballcolor[2] ..[[,]].. ballcolor[3] ..[[);stroke-width:3;stroke:black\" />\n <rect rx=20 ry= 20 x=]].. barrierB.x ..[[vw y=]].. barrierB.y ..[[vh width=]].. barrierB.w ..[[% height=]].. barrierB.h ..[[% style=\"fill:rgb(]].. ballcolor[1] ..[[,]].. ballcolor[2] ..[[,]].. ballcolor[3] ..[[);stroke-width:3;stroke:black\" />\n <text x=40% y=10% fill=\"Black\" font-size=8vh font-family=cursive>Score: ]].. score ..[[</text>\n <text x=5% y=10% fill=\"Red\" font-size=12vh font-family=cursive>]].. strikes ..[[</text>\n </svg>]] \nend\n\nif Mode == -1 then --Scoreboard\n html = [[<html height=100% width=100% style=\"background-image: radial-gradient(rgb(155,0,0) 0%, rgb(75,0,0) 110%);\">\n <div style=\"font-size:10vh;color:gray;text-align:center;\">Your Score: ]].. score ..[[</div>\n <div style=\"display: grid; grid-template-columns: auto auto auto; justify-content:left;\n grid-column-gap: 3vw;\n grid-row-gap: 2vh;\n font-size:5vh;color:black;align:bottom;margin-top:10vh;margin-left:15vw;\">]]\n for i = 1, #TopNames do\n html = html..[[<div>#]].. i ..[[:</div><div>]].. TopNames[i] ..[[</div><div>]].. TopScores[i] ..[[</div>]] \n end\n html = html..[[</div></html>]] --Webcode sent to screen to display scoreboard \nend","filter":{"args":[{"value":"game"}],"signature":"tick(timerId)","slotKey":"-1"},"key":"2"},{"code":"html = [[<html style=\"background-image: radial-gradient(rgb(50,150,255) 0%, rgb(50,150,255) 50%, rgb(0,50,100) 110%);opacity:0.65;\">\n <div style=\"height:100%;width:100%;\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n align-content: center;\n font-family: sans-serif;\"> \n<text style=\"font-size:40vh; color:white;font-style:italic;text-shadow: -1vw 1vh 0 rgb(50,100,150);position:absolute;top:15%;\">Bounce!</text>\n<text style=\"font-size:3vh; color:black;position:absolute;bottom:3%;\">Activate programming board to start</text>\n<div style=\"\nposition:absolute;\ndisplay: grid;\ngrid-template-columns: auto auto auto;\njustify-content:left;\ngrid-column-gap: 3vw;\ngrid-row-gap: 2vh;\nfont-size:5vh;\ncolor:black;\nalign:bottom;\ntop:63%;\">]]\n\nfor i = 1, #TopNames > 3 and 3 or #TopNames do\n html = html..[[<div>#]].. i ..[[:</div><div>]].. TopNames[i] ..[[</div><div>]].. TopScores[i] ..[[</div>]] \nend\n\nhtml = html..[[</div></html>]]\n\nScreen.setHTML(html)","filter":{"args":[],"signature":"stop()","slotKey":"-1"},"key":"3"},{"code":"Screen.setHTML(html)","filter":{"args":[],"signature":"update()","slotKey":"-2"},"key":"4"}],"methods":[],"events":[]}