Here is a game I wrote while watching a couple of football games on Sunday. I wasn’t satisfied with the way it worked, so I re-wrote it on Monday and made other updates today. I’m not sure what reminded me of the game, but I just started to write it. It’s based on a game my daughter and I played many, many, many years ago on her Commodore 64. It’s called Beam Rider. If you’re old enough you may have played it, if not you can do a search for it to see the original. I played this game serval times, but I’m not sure if I have all the bugs worked out. If you find any, let me know. To see the instructions, you can either load the game or just scroll down to the end and read the instructions there. This game is posted in several chunks.
displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT)
-- copyright dave1707 2012 - all rights reserved
function setup()
--to clear the high scores, uncomment clearLocalData().
--run the game, stop it, then comment clearLocalData().
--clearLocalData()
bx={ 35, 85,135,185,235,285,335,385,435,485,535,585,635,685,735}
tx={280,295,310,325,340,355,370,385,400,415,430,445,460,475,490}
msx={}
enx={}
calcMsxEnx()
init()
showInstructions=true
end
function init()
misslesTab={ {},{},{},{},{},{},{},{},{},{},{},{},{},{},{} }
enemyTab={ {},{},{},{},{},{},{},{},{},{},{},{},{},{},{} }
explosionTab={}
enemyHit=0
misslesFired=0
objectsLeft=0
total=0
sx=WIDTH/2
ang=0
shoot=0
hit=true
enemyEt=0
shootEt=0
shieldStrength=10
showingHighScore=false
end
function draw()
background(40, 40, 50)
if showInstructions then
instructions()
return
end
drawLines()
drawObjects()
removeObjects()
createEnemy()
showScore()
endGame()
who()
end
function showScore()
fill(39, 176, 93, 255)
fontSize(30)
fill(0,0,255)
text("Thread Runner",WIDTH/2,830)
fill(0,255,0)
str=string.format("Enemy ships hit %4d",enemyHit)
text(str,150,1000)
str=string.format("Objects left %3d",objectsLeft)
text(str,150,960)
str=string.format("Shield strength %3d%% ",shieldStrength*10)
text(str,375,100)
str=string.format("Missles fired %4d",misslesFired)
text(str,600,1000)
fontSize(80)
total=enemyHit*50-misslesFired*2-objectsLeft*10
str=string.format("%d",total)
text(str,375,900)
end
function createEnemy()
if shieldStrength>0 then
if ElapsedTime-enemyEt>10 then
offset=math.random(1,15)
table.insert(enemyTab[offset],enemy(tx[offset],800,enx[offset]))
enemyEt=ElapsedTime
end
if hit then
offset=math.random(1,15)
table.insert(enemyTab[offset],enemy(tx[offset],800,enx[offset]))
end
hit=false
end
end
function endGame()
local z; local y; local count
if shieldStrength==0 then
for z=1,#enemyTab do
for y=1,#enemyTab[z] do
if enemyTab[z][y].y==200 then
table.insert(explosionTab,explosion(enemyTab[z][y].x,enemyTab[z][y].y))
enemyTab[z][y].removeE=true
return
end
end
end
count=0
for z=1,#misslesTab do
count=count+#misslesTab[z]
end
for z=1,#enemyTab do
count=count+#enemyTab[z]
end
count=count+#explosionTab
if count==0 then
showHighScore()
fontSize(40)
fill(255,0,0)
text("Double tap screen to restart",WIDTH/2,220)
end
end
end
function drawLines()
local z
local alpha=100
if shieldStrength>0 then
alpha=255
end
stroke(255,255,255,alpha)
strokeWidth(4)
for z=1,#bx do
line(bx[z],200,tx[z],800)
end
line(117,400,653,400)
line(178,550,592,550)
line(219,650,551,650)
line(249,725,520,725)
line(268,770,502,770)
strokeWidth(6)
line(0,200,WIDTH,200)
line(0,800,WIDTH,800)
end
function drawObjects()
local z; local y
if shieldStrength>0 then
drawShip()
end
for z=1,#misslesTab do
for y=1,#misslesTab[z] do
misslesTab[z][y]:draw()
if y==1 then misslesTab[z][y]:checkHit() end
end
end
for z=1,#enemyTab do
for y=1,#enemyTab[z] do
enemyTab[z][y]:draw()
enemyTab[z][y]:checkHit()
end
end
for z=1,#explosionTab do
explosionTab[z]:draw()
end
end
function who()
fontSize(17)
fill(100,100,100,220)
text("dave1707 (c) 12/26/2012",600,30)
end
function touched(t)
local z
if t.state==BEGAN then
if t.tapCount==2 then
if showingHighScore then
init() return
end
if showInstructions then
showInstructions=false
return
end
end
if t.y>800 and ElapsedTime-shootEt>.1 then
shootEt=ElapsedTime
for z=1,#bx do
if sx>bx[z]-15 and sx<bx[z]+15 then
shoot=1
table.insert(misslesTab[z],missles(bx[z],200,msx[z],z))
misslesFired = misslesFired + 1
sound(SOUND_SHOOT, 49730)
return
end
end
return
end
end
if t.state==MOVING and shieldStrength>0 then
sx=sx+t.deltaY
ang=-(WIDTH/2-sx)/15
if sx<35 then
sx=35
elseif sx>735 then
sx=735
end
end
end