Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Cette ligne permet d'afficher des traces dans la console pendant l'éxécution
- io.stdout:setvbuf('no')
- --declaration de la racket contenant les valeur
- local racket = {}
- racket.x = 0;
- racket.y = 585;
- racket.largeur = 80;
- racket.hauteur = 20;
- --declaration de la balle contenant les valeur
- local ball = {}
- ball.x = 0;
- ball.y = 0;
- ball.rayon = 10;
- ball.colle = false;
- ball.vx = 0;
- ball.vy = 0;
- local brique = {}
- local niveau = {}
- -- Cette ligne permet de déboguer pas à pas dans ZeroBraneStudio
- if arg[#arg] == "-debug" then require("mobdebug").start() end
- --fonction qui colle la balle
- function demarre()
- ball.colle = true;
- niveau = {}
- local l,c;
- for l = 1,6 do
- niveau[l] = {}
- for c = 1,15 do
- niveau[l][c] = 1
- end
- end
- end
- --ce contenue ce charge au lancement du niveau
- function love.load()
- demarre();
- largeur = love.graphics.getWidth()
- hauteur = love.graphics.getHeight()
- brique.hauteur = 25;
- brique.largeur = largeur/15;
- end
- --raffraichissement de l'image contien les ligne qui suit la souris
- function love.update(dt)
- racket.x = love.mouse.getX()
- love.mouse.setVisible(true)
- --determine si la balle est coler ou non
- if ball.colle == true then
- ball.x = racket.x;
- ball.y = racket.y-racket.hauteur/2-ball.rayon
- --sinon la balle est projeter
- else
- ball.x = ball.x+(ball.vx*dt)
- ball.y = ball.y+(ball.vy*dt)
- end
- local c = math.floor(ball.x/brique.largeur) + 1
- local l = math.floor(ball.y/brique.hauteur) + 1
- if l >=1 and l<= #niveau and c>= 1 and c<=15 then
- if niveau[l][c] == 1 then
- ball.vy = 0 - ball.vy
- niveau[l][c] = 0
- end
- end
- --si la balle est superieur a la largeur de lecran celle si rebondit
- if ball.x > largeur then
- ball.vx = 0-ball.vx;
- ball.x = largeur;
- end
- --si la balle est en dehors de lecran celle ci sinisialise a 0
- if ball.x < 0 then
- ball.vx = 0 - ball.vx;
- ball.x = 0;
- end
- --si la balle est inferieure a la hauteur celle ci sinisialise a 0
- if ball.y<0 then
- ball.vy = 0 - ball.vy;
- ball.y = 0;
- end
- --si la ball est en dehors de lecran elle ce recolle
- if ball.y> hauteur then
- ball.colle = true;
- end
- local posCollisionBalle = racket.y - (racket.hauteur/2) - ball.rayon
- if ball.y > posCollisionBalle then
- local dist = math.abs(racket.x - ball.x)
- if dist < racket.largeur/2 then
- ball.vy = 0 - ball.vy
- ball.y = posCollisionBalle
- end
- end
- --fin
- function love.draw()
- --je dessine le niveau
- local l,c
- local bx,by = 0,0;
- for l = 1,6 do
- niveau[l] = {}
- bx = 0;
- for c = 1,15 do
- niveau[l][c] = 1;
- if niveau[l][c] == 1 then
- love.graphics.rectangle("fill", bx+1,by+1,brique.largeur-2,brique.hauteur-2)
- end
- bx = bx+brique.largeur
- end
- by = by+brique.hauteur
- end
- --dessine la racket
- love.graphics.rectangle("fill",racket.x-(racket.largeur/2),racket.y-(racket.hauteur/2), racket.largeur,racket.hauteur);
- --dessine la balle
- love.graphics.circle("fill", ball.x, ball.y, ball.rayon)
- end
- function love.keypressed(key)
- end
- --au click de souris
- function love.mousepressed(x,y,n)
- --si la balle est colle alors la balle ne l'est plus et la vitesse est initialiser
- if ball.colle ==true then
- ball.colle =false;
- ball.vx = 400;
- ball.vy = -400;
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement