This is my flappy bird code, I had this as a class project and I would like some useful feedback and nice comments thanks. Before you read the below I must say this was a CLASS project, I worked with others so my code is somewhat similar to others on this website but alas all is generic to me.
function setup()
flappy=readImage("Dropbox:mlgflappybird")
pipe=readImage("Dropbox:pipe up")
pipe2=readImage("Dropbox:pipedown")
background=readImage("Dropbox:mlg")
flappyX=100
flappyY=HEIGHT/2
flappySpeed=1
pipeSpeed=-3
pipeHeight=10
x1=100
y1=500
w=125
pipeX=WIDTH
pipeY=math.random(-15,15)*10
pipeA=pipeX+375
pipeB=math.random(-15,15)*10
pipeC=pipeA+375
pipeD=math.random(-15,15)*10
gamestate=1
score=0
crash=0
end --all of the above are random useful variables for this code, some for the pipes and some for the flappy, all very helpful.
function draw()
sprite(background,WIDTH/2, HEIGHT/2, WIDTH, HEIGHT)
flappyY=flappyY+flappySpeed
flappySpeed=flappySpeed-0.11 --this is what makes flappy down on the y axis
sprite(flappy,x1,flappyY,w) --this is the actual pic of the flappy
if flappyY>=HEIGHT-15 then flappyY=HEIGHT-15 --roof
flappySpeed=-1
end
if flappyY<=15 then flappyY=15 --floor
flappySpeed=1
end
sprite("Dropbox:pipedown",pipeX,pipeY+765,75,550) --this is the first section of the top and bottom pipe, it makes the pipes move on the x axis and you score when you pass them. It also has it so the gap is always in different spots.
sprite("Dropbox:pipe up",pipeX,pipeY,75,550)
pipeX=pipeX+pipeSpeed
if pipeX<=-75 then
pipeX=pipeC+350
pipeY=math.random(-15,15)*10
score=score+1
end
sprite("Dropbox:pipedown",pipeA,pipeB+765,75,550) --this is both of the second pipes and it does the same as I explained above
sprite("Dropbox:pipe up",pipeA,pipeB,75,550)
pipeA=pipeA+pipeSpeed
if pipeA<=-75 then
pipeA=pipeX+350
pipeB=math.random(-15,15)*10
score=score+1
end
sprite("Dropbox:pipedown",pipeC,pipeD+765,75,550) --this is both of the third pipes
sprite("Dropbox:pipe up",pipeC,pipeD,75,550)
pipeC=pipeC+pipeSpeed
if pipeC<=-75 then
pipeC=pipeA+350
pipeD=math.random(-15,15)*10
score=score+1
end
function touched(touch)
if touch.state==BEGAN then flappySpeed=flappySpeed+5.5 end --this is what makes the flappy go up with touch incorporated
end
if flappyX>=pipeX-70 and flappyX<=pipeX+70 and flappyY<=pipeY+310 then --This here is the first of the collition detection, this is the bottom pipe of the first two that gives its defined collition detection.
gamestate=crash
end
if flappyX>=pipeA-70 and flappyX<=pipeA+70 and flappyY<=pipeB+310 then --This is the second row of the bottom pipe
gamestate=crash
end
if flappyX>=pipeC-70 and flappyX<=pipeC+70 and flappyY<=pipeD+310 then --This is the third row of the bottom pipe
gamestate=crash
end
if flappyX>=pipeX-70 and flappyX<=pipeX+70 and flappyY>=pipeY+460 then --This is the collition detection of the top pipe of the first row, all was changed was the height of the collition detection because they are both in the same spot.
gamestate=crash
end
if flappyX>=pipeA-70 and flappyX<=pipeA+70 and flappyY>=pipeB+460 then --This is the second row of the top pipe
gamestate=crash
end
if flappyX>=pipeC-70 and flappyX<=pipeC+70 and flappyY>=pipeD+460 then --This is the third row of the top pipe
gamestate=crash
end
if gamestate==crash then
flappySpeed=flappySpeed*0
pipeSpeed=pipeSpeed*0
text("YOU FAILED! You scored "..(score).." points.",WIDTH/2,350) --all of this here simply says if you die then everything stops and a text pops up saying you failed and your score.
end
end
Thank you