Flappy Bird Remake

Any constructive criticism please give me your feedback.
Thanks

function setup()
    img=readImage("Project:Background")
    img2=readImage("Dropbox:Bird")
    img3=readImage("Dropbox:Bottom Pipe")
    img4=readImage("Dropbox:Top Pipe")
    birdX=100
    birdY=HEIGHT/2
    birdspeed=1
    pipeX=WIDTH
    pipeY=math.random(-15,18)*10
    pipespeed=-4
    pipeW=pipeX+325
    pipeZ=math.random(-15,18)*10
    pipeA=pipeW+325
    pipeB=math.random(-15,18)*10
    score=0
    gamestate=1
    crash=0
end

function draw()
    sprite(img,WIDTH/2,HEIGHT/2,WIDTH,HEIGHT)
      if gamestate==1 then
        birdspeed=birdspeed-0.175
        birdY=birdY+birdspeed
   end
    sprite("Dropbox:flappy",birdX,birdY,125)
    if birdY<=30 then
        gamestate=crash
    end
    if birdY>=HEIGHT-30 then
        birdY=HEIGHT-30
        birdspeed=-1
    end
       pipeX=pipeX+pipespeed
   sprite(img3,pipeX,pipeY,70,500)
   sprite(img4,pipeX,pipeY+700,70,500)
   if pipeX<=-70 then
       pipeX=pipeA+325
       pipeY=math.random(-15,18)*10
       score=score+1
   end
   pipeW=pipeW+pipespeed
   sprite(img3,pipeW,pipeZ,70,500)
   sprite(img4,pipeW,pipeZ+700,70,500)
   if pipeW<=-70 then
       pipeW=pipeX+325
       pipeZ=math.random(-15,18)*10
       score=score+1
   end
   pipeA=pipeA+pipespeed
   sprite(img3,pipeA,pipeB,70,500)
   sprite(img4,pipeA,pipeB+700,70,500)
   if pipeA<=-70 then
       pipeA=pipeW+325
       pipeB=math.random(-15,18)*10
       score=score+1
   end
   function touched(touch)
        if touch.state==BEGAN then
            birdspeed=birdspeed+7
        end
        if gamestate==crash and touch.state==BEGAN then
            pipeX=WIDTH
            pipeW=pipeX+325
            pipeA=pipeW+325
            pipeY=math.random(-15,18)*10
            pipeZ=math.random(-15,18)*10
            pipeB=math.random(-15,18)*10
            birdY=HEIGHT/2
            score=0
            pipespeed=-4
            birdspeed=1
            gamestate=1
        end
    end
    if birdX>=pipeX-65 and birdX<=pipeX+65 and birdY<=pipeY+250 then
       gamestate=crash
   end
    if birdX>=pipeX-65 and birdX<=pipeX+65 and birdY>=pipeY+450 then
       gamestate=crash
   end
    if birdX>=pipeW-65 and birdX<=pipeW+65 and birdY<=pipeZ+250 then
       gamestate=crash
   end
    if birdX>=pipeW-65 and birdX<=pipeW+65 and birdY>=pipeZ+450 then
       gamestate=crash
   end
    if birdX>=pipeA-65 and birdX<=pipeA+65 and birdY<=pipeB+250 then
       gamestate=crash
   end
    if birdX>=pipeA-65 and birdX<=pipeA+65 and birdY>=pipeB+450 then
       gamestate=crash
   end
    if gamestate==crash then
        birdspeed=birdspeed*0
        pipespeed=pipespeed*0
        text("YOU FAILED! You scored "..(score).." points.",WIDTH/2,350)
    end
end

I haven’t tried playing it, but the code looks neat and well laid out.

Except for one thing. Take the touched function outside the draw function.

@Ignatz Touched is outside the draw function - it’s just the indenting that’s off.
@(iangid) all your graphics are local to your machine - I swapped out for some standard codea images to get a feel - a nice game.

Some observations:

putting the current score on screen would be good.
birdspeed=birdspeed*0 - this is more complex than need be. Why not birdspeed=0?
Though your gamestate works, it’s probably not the best way to implement for readable code . A good way is to define constants, and a common convention would be to CAPITLISE the values. For example

PLAYING=1
CRASH=0
gamestate=PLAYING

This way you reference the game states with English words making the code a bit more readable. Not really a major issue here but if you aren’t rigorous then it could lead to problems with more complex code

And to my codes you say they’re terrible :s

This is beginner code, like yours, and compared to professionals, it is not well written.

But these guys are not suggesting that their code is professional quality, like you did. For beginners, they are doing fine. For a beginner, you are doing fine.

But the difference is that they understand their code can be improved, whereas you tell us how great your code is. You don’t seem to understand you are a beginner.

So we tell them they are doing fine.

And we tell you that you need to learn a lot more before your code is good enough for other people to use.