Are you after something like this.
viewer.mode=FULLSCREEN
function setup()
--
init()
tab1={}
set()
explode=false
end
function draw()
--
background(255, 185, 0)
sprite(pad,padPos.x, padPos.y)
sprite(ship,x,y,120,160)
shooting()
attack()
hit()
end
function set()
for z=1,10 do
table.insert(tab1,vec2(math.random(WIDTH),HEIGHT+math.random(400)))
end
end
function attack()
for z=#tab1,1,-1 do
sprite(asset.builtin.Tyrian_Remastered.Evil_Spike,tab1[z].x,tab1[z].y)
tab1[z].y=tab1[z].y-math.random(0,3)
if tab1[z].y<-5 then
table.remove(tab1,z)
table.insert(tab1,vec2(math.random(WIDTH),HEIGHT+math.random(200)))
end
end
end
function hit()
for z=#tab1,1,-1 do
if tab1[z].x>x-40 and tab1[z].x<x+40 and tab1[z].y>y-40 and tab1[z].y<y+40 then
table.remove(tab1,z)
explode=true
end
end
if explode then
sprite(asset.builtin.Tyrian_Remastered.Explosion_Huge,x,y,200)
end
end
function shooting()
offset = 20
if shoot then
shoot=false
if #tab<5 then -- only allow 5 bullets at a time
table.insert(tab,vec2(x,y+offset)) -- position of player for bullet
end
end
for a,b in pairs(tab) do -- show and increment bullet
sprite(asset.builtin.Tyrian_Remastered.Bullet_Simple_B, tab[a].x, tab[a].y+offset)
tab[a].y=tab[a].y+5
end
for a,b in pairs(tab) do -- remove bullet when off screen at top
if tab[a].y+offset>HEIGHT then
table.remove(tab,a)
end
end
end
function touched(t)
if t.state ~= ENDED then
if t.x >= padPos.x-40 and t.x <= padPos.x+40 then -- shoot
if t.y >= padPos.y-40 and t.y <= padPos.y+40 then
shoot=true
end
end
end
if t.state == BEGAN or t.state==MOVING then
if t.x >= padLeft.x-40 and t.x <= padLeft.x+40 and
t.y >= padLeft.y-40 and t.y <= padLeft.y+40 then
x = x - 5
elseif t.x >= padRight.x-40 and t.x <= padRight.x+40 and
t.y >= padRight.y-40 and t.y <= padRight.y+40 then
x = x + 5
elseif t.x >= padUp.x-40 and t.x <= padUp.x+40 and
t.y >= padUp.y-40 and t.y <= padUp.y+40 then
y = y + 5
elseif t.x >= padDown.x-40 and t.x <= padDown.x+40 and
t.y >= padDown.y-40 and t.y <= padDown.y+40 then
y = y - 5
end
end
end
function init()
--
tab={}
x,y = WIDTH/2,60
ship = asset.builtin.Tyrian_Remastered.Ship_B
pad = image(248,248)
padPos = vec2(128,136)
padLeft = vec2(40,124)
padRight = vec2(208,124)
padUp = vec2(124, 208)
padDown = vec2(124, 40)
padFire = vec2(124, 124)
makePad()
end
function makePad()
--
setContext(pad)
textMode(CENTER)
font("AmericanTypewriter-Bold")
fontSize(32)
ellipseMode(CENTER)
fill(193, 196, 216)
stroke(58, 67, 134)
ellipse(124,124,200,200)
fill(107, 211, 103)
stroke(38, 74, 36)
strokeWidth(8)
ellipse(padLeft.x, padLeft.y,80,80)
ellipse(padRight.x, padRight.y,80,80)
ellipse(padDown.x, padDown.y,80,80)
ellipse(padUp.x, padUp.y,80,80)
fill(34, 105, 39)
text("L",padLeft.x, padLeft.y)
text("R",padRight.x, padRight.y)
text("D",padDown.x, padDown.y)
text("U",padUp.x, padUp.y)
fill(255)
stroke(184, 33, 24)
ellipse(padFire.x, padFire.y,80,80)
fill(251, 25, 12)
text("F", padPos.x-4, padPos.y-12)
setContext()
end