Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. local largeur
  2. local hauteur
  3. local lives -- Déclaration variable pour les vies
  4.  
  5. local pad = {}
  6. pad.x = 0
  7. pad.y = 0
  8. pad.largeur = 80
  9. pad.hauteur = 20
  10.  
  11. local balle = {}
  12. balle.x = 0
  13. balle.y = 0
  14. balle.vx = 0
  15. balle.vy = 0
  16. balle.angle = 0
  17. balle.angleNeutre = 0 - ((math.pi*2) / 2)
  18. balle.vitesse = 0
  19. balle.colle = true
  20. balle.rayon = 10
  21. degre45 = (math.pi*2) / (360/45)
  22.  
  23. local brique = {}
  24. local niveau = {}
  25.  
  26. function Demarre()
  27. pad.y = hauteur - (15/2)
  28.  
  29. brique.hauteur = 25
  30. brique.largeur = largeur / 15
  31.  
  32. balle.angle = 0 - degre45
  33. balle.vitesse = 300
  34. balle.colle = true
  35.  
  36. for l = 1,6 do
  37. niveau[l] = {}
  38. for c = 1,15 do
  39. niveau[l][c] = 1
  40. end
  41. end
  42. end
  43.  
  44. function love.load()
  45. love.window.setTitle("Casse-briques") -- Change le titre de la fenêtre
  46. local imgIcon = love.graphics.newImage("images/icon.png") -- Chargement de l'image
  47. love.window.setIcon(imgIcon:getData()) -- Change l'icone de la fenêtre
  48. love.window.setMode(480, 640) -- Change les dimensions de la fenêtre
  49.  
  50. largeur = love.graphics.getWidth()
  51. hauteur = love.graphics.getHeight()
  52. Demarre()
  53. end
  54.  
  55. function love.update(dt)
  56. pad.x = love.mouse.getX()
  57. if pad.x < 0 then pad.x = 0 end
  58. if pad.x > largeur then pad.x = largeur
  59.  
  60. end
  61. if balle.colle== true then
  62. balle.x = pad.x
  63. balle.y = pad.y - (pad.hauteur/2) - (balle.rayon)
  64. else
  65. balle.x = balle.x + balle.vx*dt
  66. balle.y = balle.y + balle.vy*dt
  67. local c = math.floor((balle.x / brique.largeur)) + 1
  68. local l = math.floor((balle.y / brique.hauteur)) + 1
  69.  
  70. if l > 0 and l <= #niveau and c >= 1 and c <= 15 then
  71. if niveau[l][c] == 1 then
  72. niveau [l][c] = 0
  73. local brickx = ((c-1) * brique.largeur) + brique.largeur/2
  74. local bricky = ((l-1) * brique.hauteur) + brique.hauteur/2
  75. balle.vy = 0 - balle.vy
  76. end
  77. end
  78.  
  79. if balle.y > (pad.y - pad.hauteur/2) - balle.rayon then
  80. local distancex = math.abs(pad.x - balle.x)
  81. if distancex < pad.largeur / 2 then
  82. balle.vy = 0 - balle.vy
  83. balle.y = (pad.y - pad.hauteur/2) - balle.rayon
  84. end
  85. end
  86.  
  87. if balle.x > largeur or balle.x < 0 then balle.vx = 0 - balle.vx end
  88. if balle.y < 0 then balle.vy = 0 - balle.vy end
  89.  
  90. if balle.y > hauteur then
  91. balle.colle = true
  92. end
  93. end
  94.  
  95. end
  96.  
  97. function love.draw()
  98. local bx, by = 0,0
  99. for l = 1,6 do
  100. bx = 0
  101. for c = 1,15 do
  102. if niveau[l][c] == 1 then
  103. love.graphics.rectangle("fill",bx + 1, by + 1, brique.largeur - 2, brique.hauteur - 2)
  104. end
  105. bx = bx + brique.largeur
  106. end
  107. by = by + brique.hauteur
  108. end
  109.  
  110. love.graphics.rectangle("fill", pad.x - (pad.largeur/2), pad.y - (pad.hauteur/2), pad.largeur, pad.hauteur)
  111. love.graphics.circle("fill", balle.x, balle.y, balle.rayon)
  112.  
  113. end
  114. function love.mousepressed(px, py, pn)
  115. if balle.colle == true then
  116. balle.colle = false
  117. balle.vx = balle.vitesse * math.cos(balle.angle)
  118. balle.vy = balle.vitesse * math.sin(balle.angle)
  119. end
  120. end
  121. function initializeLives()
  122.  
  123. lives = {} -- Initialisation variable pour les vies
  124. lives.count = NB_LIVES -- Nombre de vie
  125. lives.img = love.graphics.newImage(PATH_LIFE) -- Image vie
  126. lives.width, lives.height = lives.img:getDimensions() -- Dimensions de l'image
  127.  
  128. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement