Skip to content

Instantly share code, notes, and snippets.

@Sephi-Chan
Created March 17, 2019 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sephi-Chan/630c43336f34f487e1c595d74faf873d to your computer and use it in GitHub Desktop.
Save Sephi-Chan/630c43336f34f487e1c595d74faf873d to your computer and use it in GitHub Desktop.
math.randomseed(os.time())
local score = 0
local game_over = false
local ecran = {}
ecran.largeur = 800
ecran.hauteur = 600
local panier = {}
panier.vitesse = 500
panier.largeur = 100
panier.hauteur = 20
panier.x = 400 - panier.largeur/2
panier.y = 580
local balle = {}
balle.vitesse = 250
balle.rayon = 10
function love.load()
lancer_balle(balle)
end
function love.update(delta)
if love.keyboard.isDown("left") and not love.keyboard.isDown("right") then
panier.x = panier.x - panier.vitesse * delta
if panier.x < 0 then
panier.x = 0
end
elseif love.keyboard.isDown("right") and not love.keyboard.isDown("left") then
panier.x = panier.x + panier.vitesse * delta
if panier.x > 700 then
panier.x = 700
end
end
balle.y = balle.y + balle.vitesse * delta
if panier.x < balle.x and balle.x < panier.x + panier.largeur and panier.y < balle.y and balle.y < panier.y + panier.hauteur then
score = score + 1
lancer_balle(balle)
end
if balle.y > 600 then
game_over = true
end
end
function lancer_balle(balle)
balle.y = -balle.rayon
balle.x = math.random(0, 800)
end
function love.draw()
love.graphics.setColor(1, 1, 1)
love.graphics.rectangle("fill", panier.x, panier.y, panier.largeur, panier.hauteur)
love.graphics.setColor(1, 0, 0)
love.graphics.circle("fill", balle.x, balle.y, balle.rayon)
love.graphics.setColor(1, 1, 1)
love.graphics.print(score, 10, 10)
if game_over then
love.graphics.setColor(1, 1, 1)
love.graphics.print("Perdu !", 360, 280)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment