Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local raquette = {}
- raquette[1] = {x = 0, y = 150, img = Image.createEmpty(10, 70), score = 0}
- raquette[2] = {x = 470, y = 15, img = Image.createEmpty(10, 70), score = 0}
- local balle = {x = screen:width()/2, y = screen:height()/2, vitX = 5, vitY = 5, img = Image.createEmpty(10, 10)}
- for i = 1, #raquette do raquette[i].img:clear(Color.new(255, 255, 255)) end
- balle.img:clear(Color.new(255, 255, 255))
- while 1 do
- screen:clear()
- pad = Controls.read()
- for i = 1, #raquette do
- screen:blit(raquette[i].x, raquette[i].y, raquette[i].img)
- screen:print(screen:width()/3*i, 10, raquette[i].score, Color.new(255, 0, 0))
- end
- screen:blit(balle.x, balle.y, balle.img)
- if pad:up() then raquette[1].y = raquette[1].y - (raquette[1].y >= 0 and 3 or 0)
- elseif pad:down() then raquette[1].y = raquette[1].y + (raquette[1].y <= screen:height()-raquette[1].img:height() and 3 or 0) end
- if raquette[2].y <= 0 then raquette[2].y = 0
- elseif raquette[2].y >= 272-raquette[2].img:height() then raquette[2].y = 272-raquette[2].img:height() end
- if (balle.y <= 0) or (balle.y >= 272 - balle.img:height()) then balle.vitY = balle.vitY * -1 end
- if (balle.x <= raquette[1].img:width()) and (balle.x >= raquette[1].img:width()-1) and (balle.y+balle.img:height()/2 >= raquette[1].y) and (balle.y+balle.img:height()/2 <= raquette[1].y + raquette[1].img:height()) then
- balle.vitX = balle.vitX * -1
- end
- if (balle.x+balle.img:width() >= raquette[2].x) and (balle.x <= raquette[2].x+2) and (balle.y+balle.img:height()/2 >= raquette[2].y) and (balle.y+balle.img:height()/2 <= raquette[2].y + raquette[2].img:height()) then
- balle.vitX = balle.vitX * -1
- end
- if balle.x < 0 then
- raquette[2].score = raquette[2].score + 1
- balle.x = screen:width()/2
- balle.y = screen:height()/2
- elseif balle.x > 480 then
- raquette[1].score = raquette[1].score + 1
- balle.x = screen:width()/2
- balle.y = screen:height()/2
- end
- balle.x = balle.x - balle.vitX
- balle.y = balle.y - balle.vitY
- if balle.x >= screen:width()/2 then
- if balle.vitY > 0 then raquette[2].y = raquette[2].y - 3
- elseif balle.vitY < 0 then raquette[2].y = raquette[2].y + 3 end
- end
- screen.waitVblankStart()
- screen.flip()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement