@DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDLDDLDDLDDLDDLDDLDDLDDLDDDDDDDDDDDDDDCDDDDDDDDDDDDDDDDDDDDDDDDDDDD?DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDLDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD4?DDD?DDDCDCDCD23DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"DDDD43DDDDODODODODODODODBDCDCDODODODODODDDDDDDDDDDDDDTDDDDCDCDCDDDDDDDDDDDDDDDDDDD_2!"3""2""21BBBpgUwfVgffgffBBBBBBBBBBBB!"2!"21gffgffwwwpwW !"#$%&' !"#$%&'$%& !"#01234567012345670123 !"#$%&'@ABCDEFG@ABCDEFG"#$@ABC01234567PQRSTUVWPQRSTUVWPQRG `abcdefg`abcdefg!"#`ab !"#$%&'W01234567g)*+,-./ !"@ABCDEFG9:;<=>?012PQRSTUVWIJKLMNO@AB`abcdefgYZ[\]^_ijklmno !"#$ !"#$%&'0123401234567@ABCD@ABCDEFGPQRSTUVWXYUVWXYZPQRSTUVW`abcdefghi !"#$%&'efghij`abcdefg01234567@ABCDEFGPQRSTUVW`abcdefg >? -- title: Pong -- author: E. QUARANTA -- desc: The Famous Pong Game -- script: lua -- version : 1.01 currentScreen = "Menu" player = { one = { x = 0, y = 0, vy = 5, largeur = 8, hauteur = 24, score = 0 }, two = { x = 231, y = 0, vy = 5, largeur = 8, hauteur = 24, score = 0 }, } balle = { x = 120, y = 70, vx = 1, vy = 1, speed = 1, largeur = 8, hauteur =8 } listeEtoiles={} for i=0,50 do etoile={x =math.random(10,220), y =math.random(10,126), vx = 1, sprite = 1,} etoile3={x =math.random(10,220), y =math.random(10,126), vx = 0.2, sprite = 4,} listeEtoiles[i]=etoile end listeEtoiles2={} for n=0,30 do etoile2= {x =math.random(10,220), y =math.random(10,126), vx = 0.5, sprite = 2,} listeEtoiles2[n]=etoile2 end listeEtoiles3={} for m=0,5 do etoile3= {x =math.random(10,220), y =math.random(10,126), vx = 0.2, sprite = 4,} listeEtoiles3[m]=etoile3 end titreY = 60 vyTitre = 0.5 function TIC() movePlayer() for k,etoile in pairs(listeEtoiles) do etoile.x = etoile.x + etoile.vx if etoile.x > 239 then etoile.x = 0 end end for k,etoile3 in pairs(listeEtoiles3) do etoile3.x = etoile3.x + etoile3.vx if etoile3.x > 239 then etoile3.x = 0 end end for k,etoile2 in pairs(listeEtoiles2) do etoile2.x = etoile2.x + etoile2.vx if etoile2.x > 239 then etoile2.x = 0 end end cls() rebondBalle() rebondPlayer() --line(119,0,119,135,12) titreY = titreY + vyTitre if titreY > 65 then vyTitre = -0.5 elseif titreY < 55 then vyTitre = 0.5 end updateGame() end -- tic -- --------------------------------------------------- function movePlayer() local po = player.one local pt = player.two if btn(0) and pt.y > 0 then pt.y=pt.y - pt.vy end if btn(1) and pt.y < 110 then pt.y=pt.y + pt.vy end if btn(8) and po.y > 0 then po.y=po.y - po.vy end if btn(9) and po.y < 110 then po.y=po.y + po.vy end end -- --------------------------------------------------- function centreBalle() balle.x = 239/2 balle.y = 135/2 balle.speed = 1 end -- --------------------------------------------------- function moveBalle() balle.x = balle.x + balle.vx * balle.speed balle.y = balle.y + balle.vy * balle.speed end -- --------------------------------------------------- function rebondBalle() if balle.y >= 133 or balle.y <= 0 then balle.vy = -balle.vy end if balle.x < 0 then centreBalle() player.one.score = player.one.score + 1 balle.vx = -balle.vx elseif balle.x > 239 then centreBalle() player.two.score = player.two.score + 1 balle.vx = -balle.vx end end -- --------------------------------------------------- function rebondPlayer() -- player.one if balle.x <= player.one.x + player.one.largeur then if balle.y + balle.hauteur > player.one.y and balle.y < player.one.y + player.one.hauteur then balle.speed = balle.speed + 0.1 balle.vx = math.abs(balle.vx) end end -- player.two if balle.x + balle.largeur > player.two.x then if balle.y + balle.hauteur > player.two.y and balle.y < player.two.y + player.two.hauteur then balle.speed = balle.speed + 0.1 balle.vx = -math.abs(balle.vx) end end end -- --------------------------------------------------- function updateGame() if currentScreen == "Menu" then map() line(119,0,119,135,12) print("Pressez 'Entree' pour commencer",30,titreY,12) rect(0,0,5,20,12) rect(231,60,5,20,12) rect(90,40,5,5,12) print("SCORE : 4 - 6",84,5,12) if keyp(50) then currentScreen = "game" end end if currentScreen == "game" then moveBalle() line(119,0,119,135,12) for k,etoile in pairs(listeEtoiles) do spr(etoile.sprite,etoile.x, etoile.y,0) end for k,etoile2 in pairs(listeEtoiles2) do spr(etoile2.sprite,etoile2.x, etoile2.y,0) end for k,etoile3 in pairs(listeEtoiles3) do spr(etoile3.sprite,etoile3.x, etoile3.y,0) end spr(257,player.one.x,player.one.y,00,1,0,0,1,3) spr(258,player.two.x,player.two.y,00,1,0,0,1,3) spr(259,balle.x,balle.y,00,1) print("SCORE : "..player.two.score.." - "..player.one.score,84,5,12) end if player.one.score >= 10 then currentScreen = "victoire" elseif player.two.score >= 10 then currentScreen = "victoire"end if currentScreen == "victoire" then map(30,0) if player.one.score > player.two.score then print("Bravo joueur 1\nvous avez battu\nvotre adversaire !!",0,50,12) else print("Bravo joueur 2\nvous avez battu\nvotre adversaire !!",0,50,12) end print("Pressez 'Entree' pour rejouer",30,titreY+50,12) if keyp(50) then player.one.score = 0 player.two.score = 0 currentScreen = "game" end end end -- ---------------------------------------------------