Shooting

I want to tap to shoot but with more than one bullet using tables. I found one befor but I can’t find it again

Here’s a start. There’s still a lot more that needs to be added. Touch or slide your finger on the screen to shoot.

function setup()
    tab={}
    c=0
end

function draw()
    background(40, 40, 50)
    fill(255)
    if shoot then
        c=c+1
        if c>10 then
            table.insert(tab,vec4(sx,sy,0,5))
            c=0
        end
    end
    for a,b in pairs(tab) do
        ellipse(b.x,b.y,5)
        b.x=b.x+b.z
        b.y=b.y+b.w
    end
end

function touched(t)
    if t.state==BEGAN or t.state==MOVING then
        shoot=true
        sx=t.x
        sy=t.y
    end
    if t.state==ENDED then
        shoot=false
    end
end

Thanks

Nice and simple. Great example!

This does generate lag though is there a way to delete the ellipse after it goes off the screen?

@dave1707

Check the sx values for less than 0 or greater than width and the sy values for less than 0 and greater than height. Then do a table.remove.
if they beyond the limits.