starter game 3

Here’s another game anyone can take and make it how they want. There are 10 ships (dots) that move at random around the screen, but you can’t see where they are (unless you cheat). The purpose is to tap at different positions on the screen to find each ship and destroy it. A sonar type circle will expand from where you touch. If the sonar ring crosses a ship, a red dot will flash at its location. If you tap within 50 pixels of a ship, the ship blows up. You can’t create another sonar circle until the previous one finishes. If you want to cheat, a double tap at the start of the sonar circle will show the ships (dots) for about a second.


displayMode(FULLSCREEN)
    
function setup()
    hit=vec3(0,0,0)
    ships={}
    for z=1,10 do
        table.insert(ships,vec4(math.random(WIDTH),math.random(HEIGHT),
        math.random(-150,150),math.random(-150,150)))
    end
    speed=.2
end

function draw()
    background(40,40,50)
    fill(255)
    if #ships==0 then
        text("Complete",WIDTH/2,HEIGHT-50)
    else
        text("Ships left  "..#ships,WIDTH/2,HEIGHT-50)
        text("tap screen to find the ships",WIDTH/2,HEIGHT-100)
    end
    if hit.z>0 then
        sprite("Tyrian Remastered:Explosion Huge",hit.x,hit.y)
        hit.z=hit.z-1
    end
    for a,b in pairs(ships) do
        if b.z==0 then
            b.z=math.random(-150,150)
        end
        if b.w==0 then
            b.w=math.random(-150,150)
        end
        if b.z>0 then
            b.x=b.x+speed
            b.z=b.z-1
        else
            b.x=b.x-speed
            b.z=b.z+1
        end       
        if b.w>0 then
            b.y=b.y+speed
            b.w=b.w-1
        else
            b.y=b.y-speed
            b.w=b.w+1
        end
        if b.x<0 or b.x>WIDTH then
            b.z=b.z*-1        
        end
        if b.y<0 or b.y>HEIGHT then
            b.w=b.w*-1
        end
        if cheat then
            fill(255)
            ellipse(b.x,b.y,5)
        end
    end
    if show then
        z=z+1
        if z>75 then
            cheat=false
        end
        for a,b in pairs(ships) do
            noFill()
            stroke(0,255,0)
            strokeWidth(2)
            ellipse(tx,ty,z)
            v1=vec2(tx,ty)
            d=v1:dist(vec2(b.x,b.y))*2
            if math.abs(d-z)<2 then
                fill(255,0,0)
                noStroke()
                ellipse(b.x,b.y,20)
                if z<50 then
                    table.remove(ships,a)
                    hit=vec3(b.x,b.y,10)
                end
            end
            if z>=200 then
                show=false
            end
        end
    end
end

function touched(t)
    if t.state==BEGAN and not show then
        tx=t.x
        ty=t.y
        show=true
        z=0
    end 
    if t.state==BEGAN and t.tapCount==2 and show and z<100 then
        cheat=true
    end
end

@Dave1707 I liked your code! I’m pleasure to be here in this forum with people like you that help everybody! :slight_smile:

Thank you!