Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.21 KB | None | 0 0
  1. local raquette = {}
  2.         raquette[1] = {x = 0, y = 150, img = Image.createEmpty(10, 70), score = 0}
  3.         raquette[2] = {x = 470, y = 15, img = Image.createEmpty(10, 70), score = 0}
  4.  
  5. local balle = {x = screen:width()/2, y = screen:height()/2, vitX = 5, vitY = 5, img = Image.createEmpty(10, 10)}
  6.  
  7. for i = 1, #raquette do raquette[i].img:clear(Color.new(255, 255, 255)) end
  8. balle.img:clear(Color.new(255, 255, 255))
  9.  
  10. while 1 do
  11.     screen:clear()
  12.     pad = Controls.read()
  13.    
  14.     for i = 1, #raquette do
  15.         screen:blit(raquette[i].x, raquette[i].y, raquette[i].img)
  16.         screen:print(screen:width()/3*i, 10, raquette[i].score, Color.new(255, 0, 0))
  17.     end
  18.    
  19.     screen:blit(balle.x, balle.y, balle.img)
  20.    
  21.     if pad:up() then raquette[1].y = raquette[1].y - (raquette[1].y >= 0 and 3 or 0)
  22.     elseif pad:down() then raquette[1].y = raquette[1].y + (raquette[1].y <= screen:height()-raquette[1].img:height() and 3 or 0) end
  23.    
  24.     if raquette[2].y <= 0 then raquette[2].y = 0
  25.     elseif raquette[2].y >= 272-raquette[2].img:height() then raquette[2].y = 272-raquette[2].img:height() end
  26.    
  27.     if (balle.y <= 0) or (balle.y >= 272 - balle.img:height()) then balle.vitY = balle.vitY * -1 end   
  28.    
  29.     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
  30.         balle.vitX = balle.vitX * -1
  31.     end
  32.     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
  33.         balle.vitX = balle.vitX * -1
  34.     end
  35.    
  36.     if balle.x < 0 then  
  37.         raquette[2].score = raquette[2].score + 1
  38.         balle.x = screen:width()/2
  39.         balle.y = screen:height()/2
  40.     elseif balle.x > 480 then
  41.         raquette[1].score = raquette[1].score + 1
  42.         balle.x = screen:width()/2
  43.         balle.y = screen:height()/2
  44.     end
  45.    
  46.     balle.x = balle.x - balle.vitX
  47.     balle.y = balle.y - balle.vitY
  48.    
  49.     if balle.x >= screen:width()/2 then
  50.         if balle.vitY > 0 then raquette[2].y = raquette[2].y - 3
  51.         elseif balle.vitY < 0 then raquette[2].y = raquette[2].y + 3 end
  52.     end
  53.    
  54.     screen.waitVblankStart()
  55.     screen.flip()
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement