Not sure if this is what you’re after.
viewer.mode=FULLSCREEN
function setup()
vel1,vel2=1,2
boss=vec2(WIDTH/2,HEIGHT)
shipBullet={}
orb1Bullet={}
orb2Bullet={}
hit=false
msg=""
shipX,shipY=WIDTH/2,60
orb1X,orb1Y=WIDTH*.75,HEIGHT-50
orb2X,orb2Y=WIDTH*.25,HEIGHT-50
end
function draw()
background(255, 185, 0)
if not hit then
shipMove()
shipShooting()
orb1Move()
orb1Shooting()
orb1Hit()
ship1Hit()
orb2Move()
orb2Shooting()
orb2Hit()
ship2Hit()
bossMove()
bossHit()
text("Double tap to shoot",WIDTH/2,80)
else
fontSize(100)
fill(255,0,0)
text(msg,WIDTH/2,HEIGHT/2)
fontSize(40)
fill(255)
text("Double tap to restart",WIDTH/2,HEIGHT/2-80)
end
end
function bossMove()
speed1=2
local v1=vec2(boss.x-shipX,boss.y-shipY)
v1=v1:normalize()
boss.x=boss.x-v1.x*speed1
boss.y=boss.y-v1.y*speed1
sprite(asset.builtin.Tyrian_Remastered.Boss_A,boss.x,boss.y)
end
function bossHit()
if boss.x>shipX-30 and boss.x<shipX+30 and boss.y>shipY-30 and boss.y<shipY+30 then
msg="You lose"
hit=true
end
end
function shipMove()
sprite(asset.builtin.Tyrian_Remastered.Ship_B, shipX, shipY, 100, 100)
end
function orb1Move()
orb1X=orb1X+vel1
if orb1X>WIDTH or orb1X<0 then
vel1=-vel1
end
sprite(asset.builtin.Tyrian_Remastered.Energy_Orb_2, orb1X, orb1Y,50)
end
function orb2Move()
orb2X=orb2X+vel2
if orb2X>WIDTH or orb2X<0 then
vel2=-vel2
end
sprite(asset.builtin.Tyrian_Remastered.Energy_Orb_2, orb2X, orb2Y,50)
end
function shipShooting()
offset = 20
if shoot then
shoot=false
if #shipBullet<5 then -- only allow 5 bullets at a time
table.insert(shipBullet,vec2(shipX,shipY+offset))
end
end
for a,b in pairs(shipBullet) do -- show and increment bullet
sprite(asset.builtin.Tyrian_Remastered.Energy_Orb_1, shipBullet[a].x, shipBullet[a].y+offset)
shipBullet[a].y=shipBullet[a].y+5
end
for a,b in pairs(shipBullet) do
if shipBullet[a].y+offset>HEIGHT then
table.remove(shipBullet,a)
end
end
end
function orb1Shooting()
if #orb1Bullet<1 then -- change to 2 for 2 bullets
table.insert(orb1Bullet,vec2(orb1X,orb1Y))
end
for a,b in pairs(orb1Bullet) do -- show and increment bullet
sprite(asset.builtin.Tyrian_Remastered.Mine_Spiked_Huge, orb1Bullet[a].x, orb1Bullet[a].y)
orb1Bullet[a].y=orb1Bullet[a].y-5
attack1()
end
for a,b in pairs(orb1Bullet) do
if orb1Bullet[a].y<0 then
table.remove(orb1Bullet,a)
end
end
end
function attack1()
speed1=6
if orb1Bullet[1].y>shipY then
v1=vec2(orb1Bullet[1].x-shipX,orb1Bullet[1].y-shipY)
v1=v1:normalize()
end
orb1Bullet[1].x=orb1Bullet[1].x-v1.x*speed1
orb1Bullet[1].y=orb1Bullet[1].y-v1.y*speed1
end
function orb2Shooting()
if #orb2Bullet<1 then -- change to 2 for 2 bullets
table.insert(orb2Bullet,vec2(orb2X,orb2Y))
end
for a,b in pairs(orb2Bullet) do -- show and increment bullet
sprite(asset.builtin.Tyrian_Remastered.Mine_Spiked_Huge, orb2Bullet[a].x, orb2Bullet[a].y)
orb2Bullet[a].y=orb2Bullet[a].y-5
attack2()
end
for a,b in pairs(orb2Bullet) do
if orb2Bullet[a].y<0 then
table.remove(orb2Bullet,a)
end
end
end
function attack2()
speed2=4
if orb2Bullet[1].y>shipY then
v2=vec2(orb2Bullet[1].x-shipX,orb2Bullet[1].y-shipY)
v2=v2:normalize()
end
orb2Bullet[1].x=orb2Bullet[1].x-v2.x*speed2
orb2Bullet[1].y=orb2Bullet[1].y-v2.y*speed2
end
function ship1Hit()
for a,b in pairs(orb1Bullet) do
if orb1Bullet[a].x>shipX-30 and orb1Bullet[a].x<shipX+30 and orb1Bullet[a].y>shipY-30 and orb1Bullet[a].y<shipY+30 then
msg="You lose"
hit=true
end
end
end
function ship2Hit()
for a,b in pairs(orb2Bullet) do
if orb2Bullet[a].x>shipX-30 and orb2Bullet[a].x<shipX+30 and orb2Bullet[a].y>shipY-30 and orb2Bullet[a].y<shipY+30 then
msg="You lose"
hit=true
end
end
end
function orb1Hit()
for a,b in pairs(shipBullet) do
if shipBullet[a].x>orb1X-30 and shipBullet[a].x<orb1X+30 and shipBullet[a].y>orb1Y-30 and shipBullet[a].y<orb1Y+30 then
msg="You win"
hit=true
end
end
end
function orb2Hit()
for a,b in pairs(shipBullet) do
if shipBullet[a].x>orb2X-30 and shipBullet[a].x<orb2X+30 and shipBullet[a].y>orb2Y-30 and shipBullet[a].y<orb2Y+30 then
msg="You win"
hit=true
end
end
end
function touched(t)
if t.state==BEGAN and t.tapCount==2 then
shoot=true
if hit then
viewer.restart()
end
end
if t.state==CHANGED then
shipX=shipX+t.deltaX*2
shipY=shipY+t.deltaY*2
end
end