I had part of this for awhile and thought I’d turn it into a starter game for someone. The object is to run the space ship into each star. If you hit a star, it disappears. To steer the ship, touch the screen anywhere and move your finger around. There is a red dot where you first touched the screen and the ship will go in the direction that your finger is from the red dot. The speed of the ship is dependent on the distance your finger is from the red dot. There is no scoring or end game code, so it’s up to you to add whatever you want to turn this into a useful game.
EDIT: Game modified. See post below.
displayMode(FULLSCREEN)
function setup()
font("Courier-BoldOblique")
scores={}
ship=readImage("Space Art:Red Ship")
start()
end
function start()
cx=400;cy=600
jx=0;jy=0
tx=0;ty=0
tab={}
for z=1,20 do
table.insert(tab,{p=vec2(math.random(20,WIDTH-20),math.random(20,HEIGHT-20)),
s=math.random(5),d=vec2(math.random(-2,2),math.random(-2,2)),
h=false,n=z})
end
z=0
next=1
time=0
et=ElapsedTime
update=true
end
function touched(t)
if t.state==BEGAN then
if t.tapCount==2 and #tab==0 then
start()
return
end
jx=t.x;jy=t.y;tx=jx;ty=jy
end
if t.state==MOVING then
tx=t.x;ty=t.y
z=90+math.deg(math.atan2(jy-t.y,jx-t.x))
end
if t.state==ENDED then
jx=0;jy=0;tx=0;ty=0
end
end
function checkHit()
for a,b in pairs(tab) do
if vec2(cx,cy):dist(vec2(b.p.x,b.p.y))<10 then
if next==b.n then
b.h=true
next=next+1
sprite("Tyrian Remastered:Explosion Huge",b.p.x,b.p.y)
end
end
end
end
function draw()
background(40, 40, 50)
fill(255)
if #tab==0 then
text(" Game over\
\
Double tap to restart",WIDTH/2,HEIGHT/2)
if update then
table.insert(scores,time)
update=false
end
for a,b in pairs(scores) do
text(string.format("Game %2d %4.1f seconds",a,b),WIDTH/2,HEIGHT-20*a)
end
else
time=ElapsedTime-et
text("Find "..next,WIDTH/2,HEIGHT-25)
cx=cx-(jx-tx)*.1
cy=cy-(jy-ty)*.1
if cx>WIDTH then cx=0 elseif cx<0 then cx=WIDTH end
if cy>HEIGHT then cy=0 elseif cy<0 then cy=HEIGHT end
text(string.format("%.1f seconds",time),WIDTH/2,HEIGHT-50)
end
for a,b in pairs(tab) do
sprite("Space Art:Green Explosion",b.p.x,b.p.y,30)
b.p=b.p+b.d
if b.p.x<0 then b.p.x=WIDTH end
if b.p.x>WIDTH then b.p.x=0 end
if b.p.y<0 then b.p.y=HEIGHT end
if b.p.y>HEIGHT then b.p.y=0 end
text(b.n,b.p.x,b.p.y-20)
end
if #tab~=0 then
if jx+jy>0 then
stroke(255)
fill(255,0,0)
ellipse(jx,jy,16)
end
pushMatrix()
translate(cx,cy)
rotate(z)
sprite(ship,0,0,40)
popMatrix()
checkHit()
for a,b in pairs(tab) do
if b.h then
table.remove(tab,a)
return
end
end
end
end