Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Bricks = {{1,1,colors.orange}, {2,1,colors.orange}, {3,1,colors.orange}, {4,1,colors.orange}}
- local MaxX,MaxY = term.getSize()
- local x,y = 10, 10
- local pX,pY = 20, MaxY-3
- local sx,sy = 1,-1
- function Draw()
- term.setBackgroundColour(colors.black)
- term.clear()
- --Bricks
- for i,u in pairs(Bricks) do
- paintutils.drawPixel(u[1], u[2], u[3])
- end
- --Ball
- paintutils.drawPixel(x, y, colors.white)
- --Player bar
- paintutils.drawLine(pX,pY, pX+4,pY, colors.blue)
- end
- function Physics()
- x = x+sx
- y = y+sy
- -- Check brick colision
- local counter = 1
- for i,u in pairs(Bricks) do
- --print(x .. "," .. y .. "," .. u[1] .. "," .. u[2])
- if (x==u[1] and y==u[2]) then
- table.remove(Bricks, counter)
- sx=sx*-1
- sy=sy*-1
- break
- end
- counter = counter+1
- end
- --check ball-player collision
- if (pY == y and (pX <= x and (pX+4)>= x)) then
- y = pX-2
- sx=sx*-1
- sy=sy*-1
- end
- --X Boundries
- if (x < 1) then
- x=2
- sx=sx*-1
- elseif (x > MaxX) then
- x=MaxX-1
- sx=sx*-1
- end
- --Y Boundries
- if (y < 1) then
- y=2
- sy=sy*-1
- elseif (y > MaxY) then
- -- Loose live
- y=MaxY-1
- sy=sy*-1
- end
- end
- while (true) do
- parallel.waitForAny(function()
- Physics()
- Draw()
- sleep(0.2)
- end,
- function()
- local event, key = os.pullEvent("key")
- if (key == keys.left) then
- pX = pX-1
- elseif (key == keys.right) then
- pX = pX+1
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment