starter game 2

Here’s another starter game for anyone who wants it. Add more things to make it interesting. Pull the beetle ship to the left and release to shoot it across several screens where there are 20 UFO’s waiting to be hit.


displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)

function setup()
    sx=400
    sy=400
    setup1()
    ufo={}
    createUFO()
end

function setup1()   -- setup beetle ship
    b=physics.body(CIRCLE,5)
    b.x=sx
    b.y=sy
    b.gravityScale=0
    b.interpolate=true   
    b.linearVelocity=vec2(0,0)
    mov=true
end

function createUFO()
    for z=1,20 do   -- set position of targets
        table.insert(ufo,vec2(math.random(WIDTH,WIDTH*4),math.random(100,HEIGHT)))
    end   
end   

function draw()
    background(40, 40, 50)
    fill(255)
    fontSize(30)
    
    -- determine which screen to show
    z1,z2=math.modf(b.x/WIDTH)
    text("Screen "..z1+1,WIDTH/2,100)
    text("UFO's left   "..#ufo,WIDTH/2,50)
    
    -- no UFO's left
    if #ufo==0 then
        text("Complete",WIDTH/2,HEIGHT-200)
    end
    
    -- showing first screen
    if z1==0 then
        text("Pull Beetle Ship to this area",200,330)
        text("then release to launch.",200,300)
    else
        translate(-WIDTH*z1,0)
    end
    
    -- pulling beetle ship
    if mov then
        stroke(3, 253, 7, 255)
        strokeWidth(10)
        line(b.x,b.y,450,390)
    end
    
    -- show tower and beetle ship
    sprite("Small World:Tower",450,325)
    sprite("SpaceCute:Beetle Ship",b.x,b.y,80)
    
    -- draw targets and check for hits
    for a1,b1 in pairs(ufo) do
        sprite("Space Art:UFO",b1.x,b1.y)
        v1=vec2(b.x,b.y)  
        if v1:dist(vec2(b1.x,b1.y)) <40 then
            table.remove(ufo,a1)
        end
    end
    
    -- beetle ship off bottom of screen, setup ship again
    if b.y<-50 then
        setup1()
    end
end

function touched(t)
    if t.state==BEGAN and #ufo==0 then   -- no targets left
        createUFO()
    elseif t.state==MOVING and mov then -- dragging ship
        b.x=b.x+t.deltaX
        b.y=b.y+t.deltaY
    elseif t.state==ENDED and mov then  -- done dragging
        dx=sx-b.x
        dy=sy-b.y
        b.linearVelocity=vec2(dx*5,dy*5)
        b.gravityScale=1
        mov=false
    end
end

really cool!