Voilà comme promis, je poste mon tout premier code LUA, bien sur non optimisé et avant d'aller plus loin, je voudrais savoir ce que vous en pensez :
- Code: Tout sélectionner
local t=2
local pi=math.pi
local puiss=4
local angle=0
local degre=0
local hautrect=2
local nopause=0
local x=10
local charge=1
local px=10
local b=1
local c=0
local j=1
local lp1=50
local lp2=50
local px2=290
local x2=290
local gameover=0
local y=4.9*((x-px)/(puiss*b))^2-c*(x-px)+192
function on.enterKey()
if gameover==1 then
t=2
pi=math.pi
puiss=4
angle=0
degre=0
hautrect=2
nopause=0
x=10
charge=1
px=10
b=1
c=0
lp1=50
lp2=50
px2=290
x2=290
gameover=0
y=4.9*((x-px)/(puiss*b))^2-c*(x-px)+192
end
---nopause=1 quand trace---
nopause=nopause+1
if nopause==1 then
if j==1 then
x=px
px=px-2
elseif j==2 then
x2=px2
px2=px2+2
end
timer.start(0.01)
b=math.cos(angle)
c=math.tan(angle)
end
end
function on.timer()
---incremente---
--- j 1 ---
if j==1 then
if x<317 then
if angle>60 then
t=3
elseif angle>30 and angle<61 then
t=4
elseif angle<31 then
t=5
end
x=x+t
y=4.9*((x-px)/(puiss*b))^2-c*(x-px)+192
charge=0
if 191<y and 210>y then
if x+3>px2-20 and x+3<px2+30 then
lp2=lp2-4
if x+3>px2-10 and x+3<px2+20 then
lp2=lp2-3
end
x=318
end
end
if y>211 then
x=318
end
---fin incrementation---
elseif x>316 then
x2=px2
y=4.9*((x2-px2)/(puiss*b))^2-c*(x2-px2)+192
timer.stop()
nopause=0
charge=1
j=2
end
--- j 2 ---
elseif j==2 then
if x2<2*px2 then
if angle>60 then
t=3
elseif angle>30 and angle<61 then
t=4
elseif angle<31 then
t=5
end
x2=x2+t
y=4.9*((x2-px2)/(puiss*b))^2-c*(x2-px2)+192
charge=0
if y>211 then
x2=2*px2
end
if 191<y and 210>y then
if 2*px2-x2+4>px-19 and 2*px2-x2+6<px+31 then
lp1=lp1-4
if 2*px2-x2+4>px-9 and 2*px2-x2+6<px+21 then
lp1=lp1-3
end
x2=2*px2+9
end
end
---fin incrementation---
elseif x2>2*px2-1 then
x=px
y=4.9*((x-px)/(puiss*b))^2-c*(x-px)+192
timer.stop()
nopause=0
charge=1
j=1
end
end
if lp1<0 or lp2<0 then
gameover=1
end
platform.window:invalidate()
end
function adoucir(gc)
gc:setColorRGB(255,255,255)
gc:setFont("sansserif","r",8)
gc:drawString("Angle",295,105)
gc:drawString(degre.."°",301,120)
gc:drawString(puiss.."%",296,12)
gc:drawRect(97,2,53,11)
gc:drawRect(167,2,53,11)
gc:setFont("serif","b",19)
if gameover==1 then
timer.stop()
gc:drawString("Joueur "..j.." a gagné !",30,100)
end
end
function obus(gc)
---obus---
gc:setColorRGB(0,0,0)
if j==1 then
gc:fillArc(x+3,y,5,5,0,360)
elseif j==2 then
gc:fillArc(2*px2-x2+4,y,5,5,0,360)
end
end
function tank(gc)
---tank 1---
gc:setColorRGB(100,100,100)
gc:fillRect(px,195,16,7)
gc:fillRect(px+3,191,9,4)
gc:fillRect(px+12,192,5,2)
gc:setColorRGB(0,141,0)
gc:drawLine(px,201,px,201)
gc:drawLine(px+15,201,px+15,201)
---tank 2---
gc:setColorRGB(255,0,0)
gc:fillRect(px2,195,16,7)
gc:fillRect(px2+4,191,9,4)
gc:fillRect(px2-1,192,5,2)
gc:setColorRGB(0,141,0)
gc:drawLine(px2,201,px2,201)
gc:drawLine(px2+15,201,px2+15,201)
end
function on.paint(gc)
---background---
for degrade=180,211 do
gc:setColorRGB(0,degrade-60,0)
gc:fillRect(0,degrade,318,211)
end
gc:setColorRGB(180,180,255)
gc:fillRect(0,0,318,180)
---panel---
gc:setColorRGB(60,60,60)
gc:fillRect(294,0,24,150)
gc:fillRect(49,0,220,18)
gc:fillRect(0,0,24,150)
adoucir(gc)
gc:drawRect(303,18,10,54)
---jauge et vie---
if gameover==0 then
gc:setColorRGB(0,200,0)
gc:fillRect(305,70-hautrect,7,1+hautrect)
gc:fillRect(169,4,lp2,8)
gc:fillRect(149-lp1,4,lp1,8)
end
obus(gc)
tank(gc)
---etat---
if charge==0 then
---rond rouge---
gc:setColorRGB(255,0,0)
gc:fillArc(301,130,10,10,0,360)
---cercle et rect---
gc:setColorRGB(255,255,255)
gc:drawArc(301,130,10,10,0,360)
gc:fillRect(304,134,5,3)
else
---tick---
gc:setColorRGB(0,255,0)
for tick=136,138 do
gc:drawLine(303,134,307,tick)
end
gc:drawLine(307,138,313,127)
end
end
function on.charIn(touche)
if nopause<1 then
if touche=="-" and puiss>4 then
puiss=puiss-4
hautrect=hautrect-2
if j==1 then
x=px
elseif j==2 then
x2=px2
end
elseif touche=="+" and puiss<100 then
puiss=puiss+4
hautrect=hautrect+2
if j==1 then
x=px
elseif j==2 then
x2=px2
end
elseif touche=="*" and degre<88 then
angle=angle+pi/45
degre=degre+4
if j==1 then
x=px
elseif j==2 then
x2=px2
end
elseif touche=="/" and degre>0 then
angle=angle-pi/45
degre=degre-4
if j==1 then
x=px
elseif j==2 then
x2=px2
end
elseif touche=="4" then
on.arrowKey("left")
elseif touche=="6" then
on.arrowKey("right")
end
platform.window:invalidate()
end
end
function on.arrowKey(key)
if nopause~=1 then
if j==1 then
if key=="left" and px>16 then
px=px-15
elseif key=="right" and px<px2-30 then
px=px+15
end
x=px
elseif j==2 then
if key=="left" and px2>px+30 then
px2=px2-15
elseif key=="right" and px2<277 then
px2=px2+15
end
x2=px2
end
platform.window:invalidate()
end
end
Alors ?