Premier projet pour tester mes connaissances,l’algorithme a était la chose la plus compliqué, j’ai passé des heures devant mon pc à imaginer quel combinaison de code, de condition etc pour
arriver à ce que je souhaitais 😀
Le jeux et très classique, j’ai préféré ne pas me lancer trop loin et rester en un simple projet test. Il ni a donc pas de titre juste le jeu.
J’y reviendrais ultérieurement pour le faire évoluer, plein de petite idée qui attendent sagement X)
Pour le langage tout en Lua, voici ci dessous le code source, ci cela peux vous servir d’exemple ou vous aider dans vos cours 😉
(PS pas eu le temps de faire le ménage dsl XP)
io.stdout:setvbuf(‘no’)
if arg[#arg] == « -debug » then require(« mobdebug »).start() end
local pad = {}
pad.x = 0
pad.y = 0
pad.largeur = 20
pad.hauteur = 80
pad.x2 = 0
pad.y2 = 0
local mur = {}
mur.x = 0
mur.y = 0
mur.largeur = 5
mur.hauteur = 0
local balle = {}
balle.x = 0
balle.y = 0
balle.rayon = 10
balle.colle = true
balle.vx = 0
balle.vy = 0
balle.Joueur1 = false
balle.Joueur2 = true
local number = {}
number.J1 = 0
number.J2 = 0
function love.load ()
largeur = love.graphics.getWidth()
hauteur = love.graphics.getHeight()
pad.x = largeur – pad.largeur
mur.x = largeur /2
mur.hauteur = hauteur
balle.colle = true
end
function love.update (dt)
if balle.y < 0 then
balle.vy = 200
balle.y = 0
elseif balle.y > hauteur then
balle.vy = 0 – balle.vy
balle.y = hauteur
end
if love.keyboard.isDown (« up ») then
if pad.y > 0 then
pad.y = pad.y – 20 * 60*dt
end
end
if love.keyboard.isDown (« down ») then
if pad.y < hauteur then
pad.y = pad.y + 20 * 60*dt
end
end
if love.keyboard.isDown (« z ») then
if pad.y2 > 0 then
pad.y2= pad.y2 – 20 * 60*dt
end
end
if love.keyboard.isDown (« s ») then
if pad.y2 < hauteur then
pad.y2 = pad.y2 + 20 * 60*dt
end
end
if balle.Joueur1 == false and balle.colle == true then
if love.keyboard.isDown(« a ») then
balle.vx = -200
balle.vy = -200
balle.colle = false
end
end
if love.keyboard.isDown (« q ») then
number.J1 = 0
number.J2 = 0
balle.colle = true
balle.Joueur1 = false
end
if balle.colle == true then
balle.y = pad.y
balle.x = pad.x – pad.largeur /2
elseif balle.colle == false and balle.Joueur1 == false then
balle.x = balle.x + balle.vx*dt
balle.y = balle.y + balle.vy*dt
end
if balle.x > largeur then
balle.colle = true
number.J1 = number.J1 + 1
end
if balle.Joueur1 == true then
balle.x = pad.x2 + pad.largeur + balle.rayon /2
balle.y = pad.y2
if love.keyboard.isDown(« a ») then
balle.vx = 0 – balle.vx
balle.vy = 0 – balle.vy
balle.Joueur1 = false
end
end
if balle.x < 0 then
balle.Joueur1 = true
number.J2= number.J2 + 1
end
local collision = pad.x – pad.largeur/2
if balle.x > collision then
local dist = math.abs( pad.y – balle.y)
if dist < pad.hauteur/2 then
balle.vx = 0 – balle.vx
balle.x = collision
end
end
local collision2 = 0 + pad.largeur + balle.rayon
if balle.x < collision2 then
local dist2 = math.abs(pad.y2 – balle.y)
if dist2 < collision2 then
balle.vx = 0 – balle.vx
balle.x = collision2
end
end
if love.keyboard.isDown(« w ») then
balle.vx = 200
balle.vy = – 200
balle.Joueur1 = falses
end
end
function love.draw ()
love.graphics.rectangle(« fill »,pad.x,pad.y – pad.hauteur /2,pad.largeur,pad.hauteur)
love.graphics.rectangle(« fill »,pad.x2,pad.y2 – pad.hauteur/2,pad.largeur,pad.hauteur)
love.graphics.rectangle(« fill »,mur.x – mur.largeur/2 ,mur.y,mur.largeur,mur.hauteur)
love.graphics.circle(« fill »,balle.x,balle.y,balle.rayon)
love.graphics.print(number.J1, largeur/4 – balle.rayon,0 + pad.largeur,0,4)
love.graphics.print(number.J2, (largeur – largeur /4) -balle.rayon ,0 + pad.largeur,0,4)
end