numStars=15
Dim starsx(numStars)
Dim starsy(numStars)
numBorg=1
Dim borgx(numBorg)
Dim borgy(numBorg)
Dim borgs(numBorg)
Dim btorx(numBorg)
Dim btory(numBorg)
torpedo = -1
torpedox = 0
lives = 3
extraLifeAfter = 30
numDestroyedCubes = 0
score = 0
setup:
for i = 0 to numStars - 1
starsx[i] = Floor( screenWidth * Rand)
starsy[i] = Floor( screenHeight * Rand)
next i
lives = 3
gosub attack
gosub mainloop
return
mainloop:
a = key
if ( a = left and playerx > 0 ) then playerx = playerx - 2
if ( a = right and playerx < screenWidth - playerSize ) then playerx = playerx + 2
if ( a = up and playery > 0 ) then playery = playery - 2
if ( a = down and playery < screenHeight - playerSize) then playery = playery + 2
if ( a = shoot and torpedo < 0 ) then gosub fire
gosub updateWorld
gosub paint
goto mainloop
updateWorld:
# move stars
for i = 0 to numStars - 1
starsy[i] = starsy[i] + 1
if starsy[i] > screenHeight then starsy[i] = 0
next i
# move borg
for i = 0 to numBorg - 1
if borgs[i] = exploding then borgs[i] = dead
borgy[i] = borgy[i] + 1
if borgy[i] > 50 then borgy[i] = 50
explodingBorg = i
# check if we hit a cube
if borgs[i] = alive and torpedo > borgy[i] and torpedo < borgy[i] + playerSize and torpedox > borgx[i] and torpedox < borgx[i] + playerSize then borgs[explodingBorg]=exploding : gosub cubeDestroyed
# decide if this cube will shoot now
if borgs[i] = alive and btory[i] >= screenHeight and rand < 0.004 then btory[i] = borgy[i]+playerSize + 10
# move borg torpedoes
if btory[i] < screenHeight then btory[i] = btory[i] + 1
# have we been hit
if btory[i] < (playery + playerSize) and btory[i] > playery and btorx[i] > playerx and btorx[i] < (playerx + playerSize) then btory[i] = screenHeight + 1 : goto killed
next i
# move the torpedo
if torpedo > -1 then torpedo = torpedo - 2
# if all borg are dead, attack again
countDead = 0
for i = 0 to numBorg - 1
if borgs[i] = dead then countDead = countDead + 1
next i
if countDead = numBorg then gosub attack
return
paint:
Fastgraphics
# draw background
color black
Rect 0,0,screenWidth, screenHeight
# draw stars
color white
for i = 0 to numStars - 1
plot starsx[i], starsy[i]
next i
# draw borg and card
color green
for i = 0 to numBorg - 1
if borgs[i] = alive then color green : rect borgx[i], borgy[i], playerSize, playerSize
if borgs[i] = exploding then color red : rect borgx[i], borgy[i], playerSize, playerSize
next i
# draw player
color blue
rect playerx, playery, playerSize, playerSize
# draw torpedo
color red
line torpedox, torpedo, torpedox, torpedo - 10
# draw borg torpedoes
color green
for i = 0 to numBorg - 1
if btory[i] < screenHeight then line btorx[i], btory[i], btorx[i], btory[i]- 10
next i
refresh
return
Great game. I updated code for using keypressed() function.
Fastgraphicsleft_key=16777234right_key=16777236down_key=16777237up_key=16777235shoot_key=32alive=0exploding=1dead=2screenWidth=300screenHeight=300playerSize=20playerx=(screenWidth-playerSize)/2playery=screenHeight-playerSizenumStars=15Dimstarsx(numStars)Dimstarsy(numStars)numBorg=1Dimborgx(numBorg)Dimborgy(numBorg)Dimborgs(numBorg)Dimbtorx(numBorg)Dimbtory(numBorg)torpedo=-1torpedox=0lives=3extraLifeAfter=30numDestroyedCubes=0score=0setup:fori=0tonumStars-1starsx[i]=Floor(screenWidth*Rand)starsy[i]=Floor(screenHeight*Rand)nextilives=3gosubattackgosubmainloopreturnmainloop:if(keypressed(left_key)andplayerx>0)thenplayerx=playerx-2if(keypressed(right_key)andplayerx<screenWidth-playerSize)thenplayerx=playerx+2if(keypressed(up_key)andplayery>0)thenplayery=playery-2if(keypressed(down_key)andplayery<screenHeight-playerSize)thenplayery=playery+2if(keypressed(shoot_key)andtorpedo<0)thengosubfiregosubupdateWorldgosubpaintgotomainloopupdateWorld:#movestarsfori=0tonumStars-1starsy[i]=starsy[i]+1ifstarsy[i]>screenHeightthenstarsy[i]=0nexti#moveborgfori=0tonumBorg-1ifborgs[i]=explodingthenborgs[i]=deadborgy[i]=borgy[i]+1ifborgy[i]>50thenborgy[i]=50explodingBorg=i#checkifwehitacubeifborgs[i]=aliveandtorpedo>borgy[i]andtorpedo<borgy[i]+playerSizeandtorpedox>borgx[i]andtorpedox<borgx[i]+playerSizethenborgs[explodingBorg]=exploding:gosubcubeDestroyed#decideifthiscubewillshootnowifborgs[i]=aliveandbtory[i]>=screenHeightandrand<0.004thenbtory[i]=borgy[i]+playerSize+10#moveborgtorpedoesifbtory[i]<screenHeightthenbtory[i]=btory[i]+1#havewebeenhitifbtory[i]<(playery+playerSize)andbtory[i]>playeryandbtorx[i]>playerxandbtorx[i]<(playerx+playerSize)thenbtory[i]=screenHeight+1:gotokillednexti#movethetorpedoiftorpedo>-1thentorpedo=torpedo-2#ifallborgaredead,attackagaincountDead=0fori=0tonumBorg-1ifborgs[i]=deadthencountDead=countDead+1nextiifcountDead=numBorgthengosubattackreturnpaint:#drawbackgroundclgblack#drawstarscolorwhitefori=0tonumStars-1plotstarsx[i],starsy[i]nexti#drawborgandcardcolorgreenfori=0tonumBorg-1ifborgs[i]=alivethencolorgreen:rectborgx[i],borgy[i],playerSize,playerSizeifborgs[i]=explodingthencolorred:rectborgx[i],borgy[i],playerSize,playerSizenexti#drawplayercolorbluerectplayerx,playery,playerSize,playerSize#drawtorpedocolorredlinetorpedox,torpedo,torpedox,torpedo-10#drawborgtorpedoescolorgreenfori=0tonumBorg-1ifbtory[i]<screenHeightthenlinebtorx[i],btory[i],btorx[i],btory[i]-10nextirefreshreturnfire:torpedox=playerx+playerSize/2torpedo=playeryreturnattack:print"Level "+String(numBorg)numBorg=numBorg+1Dimborgx(numBorg)Dimborgy(numBorg)Dimborgs(numBorg)Dimbtorx(numBorg)Dimbtory(numBorg)fori=0tonumBorg-1borgx[i]=Floor((screenWidth-playerSize)*Rand)borgy[i]=-20borgs[i]=alivebtorx[i]=borgx[i]+playerSize/2btory[i]=screenHeightnextireturncubeDestroyed:torpedo=-1score=score+10+numBorgprint"Score: "+String(score)#extralife?numDestroyedCubes=numDestroyedCubes+1ifnumDestroyedCubes>=extraLifeAfterthengosubextralifereturnextralife:lives=lives+1numDestroyedCubes=0print"You've got an etra life! Lives left: "+String(lives)returnkilled:print"You have been hit!"lives=lives-1iflives=0thengotoendgameprint"Lives left: "+String(lives)returnendgame:print"You have been killed on Level "+String(numBorg-1)print"Your score was "+String(score)end
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Here is a simple game using graphics. Really enjoyed making it, hope you like it...
B & I
left = 16777234
right = 16777236
down = 16777237
up = 16777235
shoot = 32
alive=0
exploding=1
dead=2
screenWidth=300
screenHeight=300
playerSize=20
playerx=(screenWidth-playerSize)/2
playery= screenHeight - playerSize
numStars=15
Dim starsx(numStars)
Dim starsy(numStars)
numBorg=1
Dim borgx(numBorg)
Dim borgy(numBorg)
Dim borgs(numBorg)
Dim btorx(numBorg)
Dim btory(numBorg)
torpedo = -1
torpedox = 0
lives = 3
extraLifeAfter = 30
numDestroyedCubes = 0
score = 0
setup:
for i = 0 to numStars - 1
starsx[i] = Floor( screenWidth * Rand)
starsy[i] = Floor( screenHeight * Rand)
next i
lives = 3
gosub attack
gosub mainloop
return
mainloop:
a = key
if ( a = left and playerx > 0 ) then playerx = playerx - 2
if ( a = right and playerx < screenWidth - playerSize ) then playerx = playerx + 2
if ( a = up and playery > 0 ) then playery = playery - 2
if ( a = down and playery < screenHeight - playerSize) then playery = playery + 2
if ( a = shoot and torpedo < 0 ) then gosub fire
gosub updateWorld
gosub paint
goto mainloop
updateWorld:
# move stars
for i = 0 to numStars - 1
starsy[i] = starsy[i] + 1
if starsy[i] > screenHeight then starsy[i] = 0
next i
# move borg
for i = 0 to numBorg - 1
if borgs[i] = exploding then borgs[i] = dead
borgy[i] = borgy[i] + 1
if borgy[i] > 50 then borgy[i] = 50
explodingBorg = i
# check if we hit a cube
if borgs[i] = alive and torpedo > borgy[i] and torpedo < borgy[i] + playerSize and torpedox > borgx[i] and torpedox < borgx[i] + playerSize then borgs[explodingBorg]=exploding : gosub cubeDestroyed
# decide if this cube will shoot now
if borgs[i] = alive and btory[i] >= screenHeight and rand < 0.004 then btory[i] = borgy[i]+playerSize + 10
# move borg torpedoes
if btory[i] < screenHeight then btory[i] = btory[i] + 1
# have we been hit
if btory[i] < (playery + playerSize) and btory[i] > playery and btorx[i] > playerx and btorx[i] < (playerx + playerSize) then btory[i] = screenHeight + 1 : goto killed
next i
# move the torpedo
if torpedo > -1 then torpedo = torpedo - 2
# if all borg are dead, attack again
countDead = 0
for i = 0 to numBorg - 1
if borgs[i] = dead then countDead = countDead + 1
next i
if countDead = numBorg then gosub attack
return
paint:
Fastgraphics
# draw background
color black
Rect 0,0,screenWidth, screenHeight
# draw stars
color white
for i = 0 to numStars - 1
plot starsx[i], starsy[i]
next i
# draw borg and card
color green
for i = 0 to numBorg - 1
if borgs[i] = alive then color green : rect borgx[i], borgy[i], playerSize, playerSize
if borgs[i] = exploding then color red : rect borgx[i], borgy[i], playerSize, playerSize
next i
# draw player
color blue
rect playerx, playery, playerSize, playerSize
# draw torpedo
color red
line torpedox, torpedo, torpedox, torpedo - 10
# draw borg torpedoes
color green
for i = 0 to numBorg - 1
if btory[i] < screenHeight then line btorx[i], btory[i], btorx[i], btory[i]- 10
next i
refresh
return
fire:
torpedox = playerx + playerSize /2
torpedo = playery
return
attack:
print "Level " + String(numBorg)
numBorg = numBorg + 1
Dim borgx(numBorg)
Dim borgy(numBorg)
Dim borgs(numBorg)
Dim btorx(numBorg)
Dim btory(numBorg)
for i = 0 to numBorg - 1
borgx[i] = Floor( (screenWidth - playerSize) * Rand)
borgy[i] = -20
borgs[i] = alive
btorx[i] = borgx[i] + playerSize / 2
btory[i] = screenHeight
next i
return
cubeDestroyed:
torpedo = -1
score = score + 10 + numBorg
print "Score: " + String (score)
# extra life?
numDestroyedCubes = numDestroyedCubes + 1
if numDestroyedCubes >= extraLifeAfter then gosub extralife
return
extralife:
lives = lives + 1
numDestroyedCubes = 0
print "You've got an etra life! Lives left: " + String(lives)
return
killed:
print "You have been hit!"
lives = lives - 1
if lives = 0 then goto endgame
print "Lives left: " + String(lives)
return
endgame:
print "You have been killed on Level " + String (numBorg-1)
print "Your score was " + String (score)
end
Good work!
But with the new version you must change the names of the "left" and "right" variables since they became keywords.
By the way, is there a workaround to avoid changing the keyboard delays in the system control panel?
Great game. I updated code for using keypressed() function.
nothing working,only error !
It works just fine on the current release 1.99.99.xxx. It runs too fast on my PC and a sleep will need to be added in the mainloop.
We emailled and he was running a very old version fro the LINUX PPA.