Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. -- Cette ligne permet d'afficher des traces dans la console pendant l'éxécution
  2. io.stdout:setvbuf('no')
  3.  
  4. --declaration de la racket contenant les valeur
  5.  
  6. local racket = {}
  7. racket.x = 0;
  8. racket.y = 585;
  9. racket.largeur = 80;
  10. racket.hauteur = 20;
  11. --declaration de la balle contenant les valeur
  12. local ball = {}
  13. ball.x = 0;
  14. ball.y = 0;
  15. ball.rayon = 10;
  16. ball.colle = false;
  17. ball.vx = 0;
  18. ball.vy = 0;
  19.  
  20. local brique = {}
  21. local niveau = {}
  22. -- Cette ligne permet de déboguer pas à pas dans ZeroBraneStudio
  23.  
  24. if arg[#arg] == "-debug" then require("mobdebug").start() end
  25.  
  26. --fonction qui colle la balle
  27. function demarre()
  28. ball.colle = true;
  29. niveau = {}
  30. local l,c;
  31.  
  32. for l = 1,6 do
  33. niveau[l] = {}
  34. for c = 1,15 do
  35. niveau[l][c] = 1
  36. end
  37. end
  38. end
  39. --ce contenue ce charge au lancement du niveau
  40. function love.load()
  41. demarre();
  42. largeur = love.graphics.getWidth()
  43. hauteur = love.graphics.getHeight()
  44.  
  45. brique.hauteur = 25;
  46. brique.largeur = largeur/15;
  47.  
  48. end
  49. --raffraichissement de l'image contien les ligne qui suit la souris
  50. function love.update(dt)
  51. racket.x = love.mouse.getX()
  52. love.mouse.setVisible(true)
  53.  
  54. --determine si la balle est coler ou non
  55. if ball.colle == true then
  56. ball.x = racket.x;
  57. ball.y = racket.y-racket.hauteur/2-ball.rayon
  58. --sinon la balle est projeter
  59. else
  60. ball.x = ball.x+(ball.vx*dt)
  61. ball.y = ball.y+(ball.vy*dt)
  62. end
  63.  
  64. local c = math.floor(ball.x/brique.largeur) + 1
  65. local l = math.floor(ball.y/brique.hauteur) + 1
  66.  
  67. if l >=1 and l<= #niveau and c>= 1 and c<=15 then
  68. if niveau[l][c] == 1 then
  69. ball.vy = 0 - ball.vy
  70. niveau[l][c] = 0
  71. end
  72. end
  73. --si la balle est superieur a la largeur de lecran celle si rebondit
  74. if ball.x > largeur then
  75. ball.vx = 0-ball.vx;
  76. ball.x = largeur;
  77. end
  78. --si la balle est en dehors de lecran celle ci sinisialise a 0
  79. if ball.x < 0 then
  80. ball.vx = 0 - ball.vx;
  81. ball.x = 0;
  82. end
  83. --si la balle est inferieure a la hauteur celle ci sinisialise a 0
  84. if ball.y<0 then
  85. ball.vy = 0 - ball.vy;
  86. ball.y = 0;
  87. end
  88. --si la ball est en dehors de lecran elle ce recolle
  89. if ball.y> hauteur then
  90. ball.colle = true;
  91. end
  92.  
  93. local posCollisionBalle = racket.y - (racket.hauteur/2) - ball.rayon
  94. if ball.y > posCollisionBalle then
  95. local dist = math.abs(racket.x - ball.x)
  96. if dist < racket.largeur/2 then
  97. ball.vy = 0 - ball.vy
  98. ball.y = posCollisionBalle
  99. end
  100. end
  101. --fin
  102. function love.draw()
  103. --je dessine le niveau
  104. local l,c
  105. local bx,by = 0,0;
  106.  
  107. for l = 1,6 do
  108. niveau[l] = {}
  109. bx = 0;
  110. for c = 1,15 do
  111. niveau[l][c] = 1;
  112.  
  113. if niveau[l][c] == 1 then
  114.  
  115. love.graphics.rectangle("fill", bx+1,by+1,brique.largeur-2,brique.hauteur-2)
  116. end
  117. bx = bx+brique.largeur
  118. end
  119. by = by+brique.hauteur
  120. end
  121.  
  122. --dessine la racket
  123. love.graphics.rectangle("fill",racket.x-(racket.largeur/2),racket.y-(racket.hauteur/2), racket.largeur,racket.hauteur);
  124. --dessine la balle
  125. love.graphics.circle("fill", ball.x, ball.y, ball.rayon)
  126.  
  127. end
  128.  
  129. function love.keypressed(key)
  130.  
  131.  
  132. end
  133. --au click de souris
  134. function love.mousepressed(x,y,n)
  135. --si la balle est colle alors la balle ne l'est plus et la vitesse est initialiser
  136. if ball.colle ==true then
  137. ball.colle =false;
  138. ball.vx = 400;
  139. ball.vy = -400;
  140. end
  141. end
  142. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement