Flappy Bird Clone For Programming Class

This is the code for the flappy bird clone I made for my programming class. Any suggestions or constructive criticism is welcome.

-- Flappy Bird

function setup()
    img=readImage("Dropbox:Flappy Background")
    img2=readImage("Dropbox:Bird")
    img3=readImage("Dropbox:Bottom Pipe")
    img4=readImage("Dropbox:Top Pipe")
    img5=readImage("Dropbox:Game Over")
    img6=readImage("Dropbox:Flappy Title")
    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
    highscore=0
    gamestate=0
    begin=1
    play=2
    crash=3
    gamestate=begin
end

function draw() 
    sprite(img,WIDTH/2,HEIGHT/2,WIDTH,HEIGHT)
if gamestate==begin then
        sprite(img6,WIDTH/2,450,900)
        text("Tap anywhere to begin.",WIDTH/2,350)
    function touched(touch)
        if touch.state==BEGAN then
                gamestate=play
        end
    end
end
if gamestate==play then    
        birdspeed=birdspeed-0.175
        birdY=birdY+birdspeed
        sprite(img2,birdX,birdY,200)
    if birdY<=30 then
        gamestate=crash
    end
    if birdY>=HEIGHT-25 then
        birdY=HEIGHT-25
        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=play
        end
    end
    if birdX>=pipeX-65 and birdX<=pipeX+65 and birdY<=pipeY+275 then
        gamestate=crash
    end
    if birdX>=pipeX-65 and birdX<=pipeX+65 and birdY>=pipeY+425 then
        gamestate=crash
    end
    if birdX>=pipeW-65 and birdX<=pipeW+65 and birdY<=pipeZ+275 then
        gamestate=crash
    end
    if birdX>=pipeW-65 and birdX<=pipeW+65 and birdY>=pipeZ+425 then
        gamestate=crash
    end
    if birdX>=pipeA-65 and birdX<=pipeA+65 and birdY<=pipeB+275 then
        gamestate=crash
    end
    if birdX>=pipeA-65 and birdX<=pipeA+65 and birdY>=pipeB+425 then
        gamestate=crash
    end
end
if gamestate==crash then
        birdspeed=birdspeed*0
        pipespeed=pipespeed*0
        if score>=highscore then
            highscore=score
        end
        sprite(img5,WIDTH/2,450,400,300)
        text("You lost! You scored "..(score).." points. Your current highscore is "..(highscore).." points.",WIDTH/2,350)
        text("Tap anywhere to restart.",WIDTH/2,320)
    end
end

I really like this code.

How come the code is so similar for the two of you?

We are in the same class and I was helping him. A lot of our class is using my code as a baseline for their own flappy bird clones. In his case, his code got deleted due to an issue with our schools iPads, so I helped him re-code his project from scratch.