starter game 9

Here’s a simple pinball game. Just tap the screen to flip the paddles.


displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT_ANY)

function setup()
    physics.continuous=true
    
    e1=physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
    e1.info=0
    e2=physics.body(EDGE,vec2(WIDTH,0),vec2(WIDTH,HEIGHT))
    e2.info=0
    e3=physics.body(EDGE,vec2(0,HEIGHT),vec2(WIDTH,HEIGHT))
    e3.info=0
    
    p1=physics.body(POLYGON,vec2(0,-10),vec2(250,-10),vec2(250,10),vec2(0,10))
    p1.x=100
    p1.y=200
    p1.gravityScale=0
    p1.type=KINEMATIC
    p1.angle=-45
    p1.info=4
    
    p2=physics.body(POLYGON,vec2(0,-10),vec2(250,-10),vec2(250,10),vec2(0,10))
    p2.x=WIDTH-100
    p2.y=200
    p2.gravityScale=0
    p2.type=KINEMATIC
    p2.angle=225
    p2.info=5
    
    c1=physics.body(CIRCLE,40)
    c1.x=200
    c1.y=700
    c1.type=KINEMATIC
    c1.info=1
    
    c2=physics.body(CIRCLE,40)
    c2.x=WIDTH-200
    c2.y=700
    c2.type=KINEMATIC
    c2.info=2
    
    c3=physics.body(CIRCLE,40)
    c3.x=WIDTH/2
    c3.y=500
    c3.type=KINEMATIC
    c3.info=3
    
    rot=false
    count=0
    score=0
    highScore=0
    amt=0
    balls=5
    state="play"
    createBalls()
end

function draw()
    background(40, 40, 50)
    sprite("SpaceCute:Background",WIDTH/2,HEIGHT/2,WIDTH,HEIGHT)
    
    stroke(255, 106, 0, 255)
    strokeWidth(8)
    line(0,0,0,HEIGHT)
    line(WIDTH,0,WIDTH,HEIGHT)
    line(0,HEIGHT,WIDTH,HEIGHT)
    
    noStroke()
    fill(255, 193, 0, 255)
    if state=="play" then
        ellipse(b.x,b.y,60)
    end
    
    fill(255)
    if v==1 then
        fill(255,0,0)
    end
    ellipse(c1.x,c1.y,80)
    
    fill(255)
    if v==2 then
        fill(255,0,0)
    end
    ellipse(c2.x,c2.y,80)
    
    fill(255)
    if v==3 then
        fill(255,0,0)
    end
    ellipse(c3.x,c3.y,80)
    
    pushMatrix()
    fill(225, 10, 251, 255)
    if v==4 then
        fill(255,0,0)
    end
    translate(p1.x,p1.y)
    if rot then
        p1.angularVelocity=200
    end
    rotate(p1.angle)
    rect(0,-10,250,20)
    if p1.angle>0 then
        p1.angle=-45
        p1.angularVelocity=0
    end
    popMatrix()
    
    pushMatrix()
    fill(225, 10, 251, 255)
    if v==5 then
        fill(255,0,0)
    end
    translate(p2.x,p2.y)
    if rot then
        p2.angularVelocity=-200
    end
    rotate(p2.angle)
    rect(0,-10,250,20)
    if p2.angle<180 then
        p2.angle=225
        p2.angularVelocity=0
    end
    popMatrix()
    rot=false
    
    if state=="play" then
        if b.y<0 then
            b:destroy()
            b=nil
            balls=balls-1 
            if balls==0 then
                state="gameover"
            else
                createBalls()
            end
        end
    else
        fontSize(30)
        fill(255)
        text("Game Over",WIDTH/2,350)
        text("double tap to play",WIDTH/2,310)
    end
    
    if count>0 then
        count=count-1
    else
        v=0
    end
    
    fill(255)
    fontSize(50)
    text("Score "..score,WIDTH/2,HEIGHT-100)
    fontSize(30)
    text("High Score  "..highScore,WIDTH/2,HEIGHT-150)
    fontSize(20)
    text("Balls remaining "..balls,WIDTH/2,HEIGHT-30)
       
    fill(255,0,0)
    fontSize(40)
    text("200",c1.x,c1.y)
    text("200",c2.x,c2.y)
    text("100",c3.x,c3.y)
end

function createBalls()
    b=physics.body(CIRCLE,30)
    b.x=math.random(200,WIDTH-200)
    b.y=HEIGHT-100
    b.restitution=.8   
    b.info=0      
end

function touched(t)
    if t.state==BEGAN then
        if state=="play" then
            rot=true
        elseif t.tapCount==2 then
            score=0
            balls=5
            state="play"
            createBalls()
        end
    end
end

function collide(c)
    if c.state==BEGAN then
        v=c.bodyA.info+c.bodyB.info
        count=15
        if v==1 or v==2 then
            amt=200
        elseif v==3 then
            amt=100
        elseif v==4 or v==5 then
            amt=50
        end
        score=score+amt
        if score>highScore then
            highScore=score
        end
        amt=0
    end        
end

The user and all related content has been deleted.