Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. {"slots":{"0":{"name":"slot1","type":{"methods":[],"events":[]}},"1":{"name":"slot2","type":{"methods":[],"events":[]}},"2":{"name":"slot3","type":{"methods":[],"events":[]}},"3":{"name":"slot4","type":{"methods":[],"events":[]}},"4":{"name":"slot5","type":{"methods":[],"events":[]}},"5":{"name":"slot6","type":{"methods":[],"events":[]}},"6":{"name":"slot7","type":{"methods":[],"events":[]}},"7":{"name":"slot8","type":{"methods":[],"events":[]}},"8":{"name":"slot9","type":{"methods":[],"events":[]}},"9":{"name":"slot10","type":{"methods":[],"events":[]}},"-1":{"name":"unit","type":{"methods":[],"events":[]}},"-2":{"name":"system","type":{"methods":[],"events":[]}},"-3":{"name":"library","type":{"methods":[],"events":[]}}},"handlers":[{"key":"0","filter":{"slotKey":-2,"signature":"start()","args":[]},"code":"self.system.freeze(1)\n\nscreenWidth = 2000\nscreenHeight = 1280\nbrickWidth = screenWidth / 10 -10\nbrickHeight = screenWidth / 20 -10\nballX=screenWidth/2\nballY=screenHeight*0.8\nspeedX=screenWidth/150\nspeedY=-speedX\nballRay = 30\nn=0\nbrickState={}\nbrickX={}\nbrickY={}\ncolor={\"#ff0000\",\"#ffac00\",\"#fff100\", \"#0bff00\",\"#00f6ff\"}\nscore = 0\nfor x=0 , 9 do\n\tbrickState[x]={}\n\tbrickX[x]={}\n\tbrickY[x]={}\n\tfor y=0 , 4\t do\n\t brickX[x][y] = screenWidth/10*x +5\n\t brickY[x][y] = screenWidth/20*y + screenHeight/12\n\t brickState[x][y] = 1\n\t score = score+1\n\tend\nend\nmaxScore = score\nbatWidth = screenWidth/10\nbatHeight = screenHeight/30\nbatX = screenWidth/2 - batWidth/2\nbatY = screenHeight-batHeight\n\nmaxBatSpeed = speedX*2\nbatSpeed =0;\nbatAcceleration = 4\nkeyLeft = false\nkeyRight = false\nlift = speedX\nmaxXspeed = speedX*1.5\nslot2.deactivate()"},{"key":"1","filter":{"slotKey":-2,"signature":"update()","args":[]},"code":"-- move the bat\nif (keyLeft) then\n\tbatSpeed = batSpeed -batAcceleration\n\tif batSpeed < -maxBatSpeed then \n\t\tbatSpeed = -maxBatSpeed\n\tend\nend\nif (keyRight) then\n\tbatSpeed = batSpeed + batAcceleration\n\tif batSpeed > maxBatSpeed then \n\t\tbatSpeed = maxBatSpeed\n\tend\nend\nif not(keyLeft or keyRight) then\n\tbatSpeed = batSpeed * 0.8\nend\n\nbatX = batX + batSpeed\nif batX<0 then \n\tbatX = 0\nend\nif batX> (screenWidth - batWidth) then\n\tbatX = screenWidth - batWidth\nend\n\n-- move the ball\nballX = ballX + speedX\nballY = ballY + speedY\nif ballX > screenWidth or ballX <0 then\n speedX = speedX *-1\n ballX = ballX + speedX\nend\nif ballY <0 then\n speedY = speedY *-1\n ballY = ballY + speedY\nend\n\nif ballY > screenHeight then\n\t-- lost game\n\tballX=screenWidth/2\n\tballY=screenHeight*0.8\n\tspeedX=screenWidth/150\n\tspeedY=-speedX\n\tfor x=0 , 9 do\n\t\tfor y=0 , 4\t do\n--\t\t\tbrickState[x][y] = 1\n\t\tend\n\tend\n\t--score = maxScore\nend\n\n\n-- check collisions with bricks\n-- test vertically\nfor x=0 , 9 do\n for y=0 , 4\t do\n if (brickState[x][y]==1) then\n\t\tif ballX>brickX[x][y] and ballX<(brickX[x][y]+brickWidth) then\n\t\t\tif (ballY-ballRay)<(brickY[x][y]+brickHeight) and (ballY+ballRay)>brickY[x][y] then\n\t\t\t\tbrickState[x][y] =0;\n\t\t\t\tscore = score -1\n\t\t\t\tspeedY = speedY *-1\n\t\t\t\tballY = ballY + speedY \n\t\t\tend\n\t\tend\n\tend\n end\nend\n-- test horizontally\nfor x=0 , 9 do\n for y=0 , 4\t do\n if (brickState[x][y]==1) then\n\t\tif ballY>brickY[x][y] and ballY<(brickY[x][y]+brickHeight) then\n\t\t if (ballX-ballRay)<(brickX[x][y]+brickWidth) and (ballX+ballRay)>brickX[x][y] then\n\t\t\tbrickState[x][y] =0;\n\t\t\tscore = score -1\n\t\t\tspeedX = speedX *-1\n\t\t\tballX = ballX + speedX \n\t\t end\n\t\tend\n\tend\n end\nend\n\nif score == 0 then\n\tslot2.activate()\nend\n\n-- check ball/bat collision\nif (ballY+ballRay) > batY then\n if (ballX-ballRay)<(batX+batWidth) and (ballX+ballRay)>batX then\n\tspeedY = speedY *-1\n\tballY = batY - ballRay\n\tspeedX = speedX + lift*(ballX-batX-batWidth/2)/(batWidth/2)\n\tif speedX > maxXspeed then\n\t\tspeedX = maxXspeed\n\tend\n\tif speedX < -maxXspeed then\n\t\tspeedX = -maxXspeed\n\tend\t\n end\nend\n\n-- render wall\nstr =\"<svg viewBox=\\\"0 0 2000 1199\\\" style=\\\"background-color:black; width:100%; height:100%\\\">\"\nfor x=0 , 9 do\n for y=0 , 4 do\n if brickState[x][y]==1 then\n bloc = \"<rect id=\\\"rect\"..n..\"\\\" x=\\\"\"..tostring(brickX[x][y])..\"\\\" y=\\\"\".. tostring(brickY[x][y])..\"\\\" width=\\\"\"..tostring(brickWidth) ..\"\\\" height=\\\"\"..tostring(brickHeight)..\"\\\" fill=\\\"\"..color[y+1]..\"\\\" />\"\n str = str .. bloc\n\t n = n+1;\n end\n end\nend\n-- render ball\nstr = str .. \"<circle cx=\\\"\".. tostring(ballX)..\"\\\" cy=\\\"\".. tostring(ballY)..\"\\\" r=\\\"\"..tostring(ballRay)..\"\\\" stroke=\\\"black\\\" stroke-width=\\\"3\\\" fill=\\\"white\\\" />\"\n-- render bat\nstr = str .. \"<rect x=\\\"\"..tostring(batX)..\"\\\" y=\\\"\".. tostring(batY)..\"\\\" width=\\\"\"..tostring(batWidth) ..\"\\\" height=\\\"\"..tostring(batHeight)..\"\\\" fill=\\\"#FFFFFF\\\" />\"\n\nstr = str .. \"</svg>\"\nself.slot1.clear()\nself.slot1.setContent(0,0,str)\n"},{"key":"2","filter":{"slotKey":-2,"signature":"actionStart(action)","args":[{"value":"left"}]},"code":"keyLeft = true"},{"key":"3","filter":{"slotKey":-2,"signature":"actionStop(action)","args":[{"value":"left"}]},"code":"keyLeft = false"},{"key":"4","filter":{"slotKey":-2,"signature":"actionStart(action)","args":[{"value":"right"}]},"code":"keyRight = true"},{"key":"5","filter":{"slotKey":-2,"signature":"actionStop(action)","args":[{"value":"right"}]},"code":"keyRight = False"}],"methods":[],"events":[]}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement