Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.66 KB | None | 0 0
  1. local padgauche = {}
  2. padgauche.y = 0
  3. padgauche.x = 0
  4. padgauche.hauteur = 100
  5. padgauche.largeur = 12
  6. padgauche.vy = 300
  7.  
  8. local paddroite = {}
  9. paddroite.y = 0
  10. paddroite.x = 0
  11. paddroite.hauteur = 100
  12. paddroite.largeur = 18
  13. paddroite.vy = 300
  14.  
  15. local balle = {}
  16. balle.x = 0
  17. balle.y = 0
  18. balle.rayon = 9
  19. balle.vx = -200
  20. balle.vy = 200
  21. balle.start = false
  22.  
  23.  
  24. function start()
  25.   if love.keyboard.isDown("space") then
  26.     balle.start = true
  27.   end
  28. end
  29.  
  30.  
  31. function love.load()
  32.   hauteur = love.graphics.getHeight()
  33.   largeur = love.graphics.getWidth()
  34.  
  35.   balle.x = largeur / 2 - balle.rayon
  36.   balle.y = hauteur / 2 - balle.rayon
  37.  
  38.   padgauche.y = hauteur / 2
  39.   paddroite.y = hauteur / 2
  40.  
  41.   padgauche.x = 15
  42.   paddroite.x = largeur - 15
  43.  
  44. end
  45.  
  46. function love.update(dt)
  47.   start()
  48.  
  49.   if balle.start == true then                                                     --lancer la balle
  50.     balle.x = balle.x + balle.vx * dt
  51.     balle.y = balle.y + balle.vy * dt
  52.   else
  53.     balle.x = largeur / 2
  54.     balle.y = hauteur / 2
  55.     start()
  56.   end
  57.  
  58.   if love.keyboard.isDown("z") then                                                --diriger les pads
  59.     padgauche.y = padgauche.y - padgauche.vy * dt
  60.   elseif love.keyboard.isDown("s") then
  61.     padgauche.y = padgauche.y + padgauche.vy * dt
  62.   end
  63.  
  64.   if love.keyboard.isDown("up") then
  65.     paddroite.y = paddroite.y - paddroite.vy * dt
  66.   elseif love.keyboard.isDown("down") then
  67.     paddroite.y = paddroite.y + paddroite.vy * dt
  68.   end
  69.  
  70.   if balle.x > largeur then                                                           --collision en x
  71.     balle.start = false
  72.   elseif balle.x < 0 then
  73.     balle.start = false
  74.   end
  75.  
  76.   if balle.y > hauteur then                                                             --collision en y
  77.     balle.vy = 0 - balle.vy
  78.     balle.y = hauteur
  79.   elseif balle.y < 0 then
  80.     balle.vy = 0 - balle.vy
  81.     balle.y = 0
  82.   end
  83.                                                                                             --tester collision avec le pad de gauche
  84.  
  85.   if balle.x <= padgauche.x + padgauche.largeur and balle.y >= padgauche.y and balle.y <= padgauche.y + hauteur and balle.x >= padgauche.x then
  86.     balle.vx = 0 - balle.vx
  87.     balle.vy = 0 - balle.vy
  88.     balle.x = padgauche.x + padgauche.largeur
  89.   end
  90.  
  91. end
  92.  
  93.  
  94. function love.draw()
  95.   love.graphics.rectangle("fill", padgauche.x, padgauche.y, padgauche.largeur, padgauche.hauteur)
  96.   love.graphics.rectangle("fill", paddroite.x, paddroite.y, paddroite.largeur, paddroite.hauteur)
  97.   love.graphics.circle("fill", balle.x-balle.rayon, balle.y-balle.rayon, balle.rayon)
  98.  
  99. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement