As requested by BN2, some code that I wrote to demonstrate my skills (or lack thereof!). It's a Space Invaders clone, probably could have been written in a quarter of the lines but that's why I'm joining the DarkNoobs team - to learn how to do this kind of stuff better!
rem space invaders by Jim
hide mouse
rem Create an offscreen bitmap, fill with near black - use as flashing screen fix
create bitmap 1,640,480
cls rgb(1,1,1)
rem initialise the screen and timers
randomize timer()
sync on
StartTime1 = timer()
StartTime2 = timer()
StartTime3 = timer()
rem array to hold alien sprite numbers
dim AlienArray(50)
for n = 1 to 50
AlienArray(n) = n
next n
rem 4 arrays to hold shield sprite numbers
dim Shield1Array(20)
dim Shield2Array(20)
dim Shield3Array(20)
dim Shield4Array(20)
for n = 1 to 20
Shield1Array(n) = n + 100
Shield2Array(n) = n + 120
Shield3Array(n) = n + 140
Shield4Array(n) = n + 160
next n
rem load sounds
load sound "explosion.wav", 1
load sound "alienbullet.wav", 2
load sound "basebullet.wav", 3
load sound "move.wav", 4
rem declare variables and constants
rem playing area constants
LeftEdge = 120
TopEdge = 80
RightEdge = 480
BottomEdge = 360
rem leftmost alien starting positions
rem alien1 is the top row, alien 5 is the bottom row
Alien1Top = 100
Alien2Top = 120
Alien3Top = 140
Alien4Top = 160
Alien5Top = 180
AlienLeft = 150
rem leftmost shield starting position
ShieldLeft = 160
ShieldTop = 300
rem player base starting position
BaseLeft = 300
BaseTop = 340
rem constants to hold image and sprite names
Alien1 = 1
Alien2 = 2
Alien3 = 3
Base = 4
AlienExplosion = 5
AlienBullet = 6
BaseBullet = 7
Shield = 8
rem draw sprites off screen to avoid initial "delete sprite" problems
sprite 60, 700, 600, AlienExplosion
sprite 54, 700, 600, BaseBullet
sprite 91, 700, 600, AlienExplosion
rem movement constants
AlienMove = 3
BaseMove = 4
BulletMove = 4
AlienMoveDelay = 1000
rem others
Lives = 3
Score$ = "000000000"
TempScore$ = ""
Score = 0
LengthScore = 0
AlienBulletCounter1 = 1
AlienBulletCounter2 = 1
AlienBulletCounter3 = 1
StopBullet1 = 0
StopBullet2 = 0
StopBullet3 = 0
BulletShot = 0
SpaceBarPressed = 1
FireBase = 0
BulletFired = 1
AlienExplodeFlag = 0
AlienExplodeCounter = 1
BaseExplode = 0
BaseExplodeCounter = 1
LoseLife = 0
AlienTotal = 0
rem level end conditions - 1 means Game Over, 2 means reset the level
EndCondition = 0
rem load images
load image "alien1.bmp", Alien1
load image "alien2.bmp", Alien2
load image "alien3.bmp", Alien3
load image "base.bmp", Base
load image "explosion.bmp", AlienExplosion
load image "alienbullet.bmp", AlienBullet
load image "basebullet.bmp", BaseBullet
load image "shield.bmp", Shield
rem **************************************************************************************************************
rem GAME LOOP
rem **************************************************************************************************************
do
if EndCondition < 2
cls
set current bitmap 1
ink rgb(255,255,255), 0
set text size 16
center text 320, 200, "Space Jimvaders"
set text size 8
center text 320, 400, "Use the arrow keys to move your base"
center text 320, 410, "and the Space Bar to shoot."
center text 320, 450, "Press any key to play!"
set current bitmap 0
copy bitmap 1, 0
wait key
endif
do
set current bitmap 1
EndCondition = 0
gosub Score
gosub Lives
gosub DrawBox
gosub DrawAliens
gosub MoveAliens
gosub MoveDrawBase
gosub DrawShields
gosub AlienBullets
gosub BaseBullets
gosub ShieldCollision
gosub AlienExplode
gosub BaseHit
gosub BaseExplode
gosub AlienShieldCollide
gosub AlienBaseCollide
gosub EndLevel
set current bitmap 0
copy bitmap 1,0
if EndCondition > 0 then exit
sync
loop
if EndCondition = 1
ink rgb(255,0,0),0
set text size 32
center text 300, 200, "GAME OVER"
wait key
exit
endif
if EndCondition = 2
cls
gosub ResetLevel
endif
loop
rem ***************************************************************************************************************
rem SUBROUTINES
rem ***************************************************************************************************************
Score:
ink rgb(255,255,255),0
TempScore$ = str$(Score)
LengthScore = len(TempScore$)
if LengthScore = 1
Score$ = "000000000"
else
if LengthScore = 3
Score$ = "000000" + TempScore$
else
if LengthScore = 4
Score$ = "00000" + TempScore$
else
if LengthScore = 5
Score$ = "0000" + TempScore$
else
if LengthScore = 6
Score$ = "000" + TempScore$
else
if LengthScore = 7
Score$ = "00" + TempScore$
else
if LengthScore = 8
Score$ = "0" + TempScore$
else
if LengthScore = 9
Score$ = TempScore$
endif
endif
endif
endif
endif
endif
endif
endif
cls
set text size 8
text LeftEdge, TopEdge -15, "SCORE: " + Score$
return
Lives:
rem display the base image as sprite number 90
sprite 90, RightEdge - 20, TopEdge - 20, Base
text RightEdge - 40, TopEdge - 15, str$(Lives) + " x "
return
DrawBox:
ink rgb(255,255,255), 0
box LeftEdge-1, TopEdge-1, RightEdge+1, BottomEdge+1
ink 0,0
box LeftEdge, TopEdge, RightEdge, Bottomedge
return
DrawAliens:
for n = 1 to 50
if n < 21
AlienImage = Alien1
else
if n > 20 and n < 31
AlienImage = Alien2
else
if n > 30 and n < 51
AlienImage = Alien3
endif
endif
endif
if n < 11
AlienTop = Alien1Top
Offset = 0
else
if n > 10 and n < 21
AlienTop = Alien2Top
Offset = 10
else
if n > 20 and n < 31
AlienTop = Alien3Top
Offset = 20
else
if n > 30 and n < 41
AlienTop = Alien4Top
Offset = 30
else
if n > 40 and n < 51
AlienTop = Alien5Top
Offset = 40
endif
endif
endif
endif
endif
if AlienArray(n) > 0
sprite AlienArray(n), AlienLeft + ((n-Offset) * 30) - 30, AlienTop, AlienImage
else
delete sprite n
endif
next n
return
MoveAliens:
if timer() > AlienDelay
AlienLeft = AlienLeft + AlienMove
play sound 4
if AlienLeft => (RightEdge - 290) or AlienLeft <= Leftedge
Alien1Top = Alien1Top + 15
Alien2Top = Alien2Top + 15
Alien3Top = Alien3Top + 15
Alien4Top = Alien4Top + 15
Alien5Top = Alien5Top + 15
AlienMove = AlienMove * -1
AlienMoveDelay = AlienMoveDelay - 120
endif
AlienDelay = timer() + AlienMoveDelay
endif
return
MoveDrawBase:
rem move the base
if leftkey() and BaseLeft > LeftEdge
BaseLeft = BaseLeft - BaseMove
else
if rightkey() and BaseLeft < RightEdge-20
BaseLeft = BaseLeft + BaseMove
endif
endif
rem draw the base - sprite 80
if HideBase = 0
sprite 80, BaseLeft, BaseTop, Base
endif
return
DrawShields:
rem draw the shields - sprites 101 to 180 (20 per shield)
rem each loop draws 20 sprites next to each other for whole shield
for x = 1 to 10
if Shield1Array(x) > 0
sprite Shield1Array(x), ShieldLeft + (x*4) - 4, ShieldTop, Shield
endif
next x
for x = 1 to 10
if Shield1Array(x+10) > 0
sprite Shield1Array(x+10), ShieldLeft + (x*4) - 4, ShieldTop + 8, Shield
endif
next x
for x = 1 to 10
if Shield2Array(x) > 0
sprite Shield2Array(x), ShieldLeft + 80 + (x*4) - 4, ShieldTop, Shield
endif
next x
for x = 1 to 10
if Shield2Array(x+10) > 0
sprite Shield2Array(x+10), ShieldLeft + 80 + (x*4) - 4, ShieldTop + 8, Shield
endif
next x
for x = 1 to 10
if Shield3Array(x) > 0
sprite Shield3Array(x), ShieldLeft + 160 + (x*4) - 4, ShieldTop, Shield
endif
next x
for x = 1 to 10
if Shield3Array(x+10) > 0
sprite Shield3Array(x+10), ShieldLeft + 160 + (x*4) - 4, ShieldTop + 8, Shield
endif
next x
for x = 1 to 10
if Shield4Array(x) > 0
sprite Shield4Array(x), ShieldLeft + 240 + (x*4) - 4, ShieldTop, Shield
endif
next x
for x = 1 to 10
if Shield4Array(x+10) > 0
sprite Shield4Array(x+10), ShieldLeft + 240 + (x*4) - 4, ShieldTop + 8, Shield
endif
next x
return
AlienBullets:
rem fire shots from the aliens - sprite 51
rem fire a bullet every few seconds - pick the alien before entering the loop
if AlienBulletCounter1 = 1
FiringAlien1 = rnd(49) + 1
FiringAlien1PosX = Sprite X(FiringAlien1)
FiringAlien1PosY = Sprite Y(FiringAlien1)
AlienBulletCounter1 = 0
StopBullet1 = 0
endif
if FiringAlien1PosY < BottomEdge and StopBullet1 = 0 and AlienArray(FiringAlien1) > 0
if AlienNoise1 = 0
play sound 2
AlienNoise1 = 1
endif
sprite 51, FiringAlien1PosX, FiringAlien1PosY, AlienBullet
FiringAlien1PosY = FiringAlien1PosY + BulletMove
else
AlienBulletCounter1 = 1
AlienNoise1 = 0
endif
rem fire shots from the aliens - sprite 52
if AlienBulletCounter2 = 1
FiringAlien2 = rnd(49) + 1
FiringAlien2PosX = Sprite X(FiringAlien2)
FiringAlien2PosY = Sprite Y(FiringAlien2)
AlienBulletCounter2 = 0
StopBullet2 = 0
endif
if FiringAlien2PosY < BottomEdge and StopBullet2 = 0 and AlienArray(FiringAlien2) > 0
if AlienNoise2 = 0
play sound 2
AlienNoise2 = 1
endif
sprite 52, FiringAlien2PosX, FiringAlien2PosY, AlienBullet
FiringAlien2PosY = FiringAlien2PosY + BulletMove
else
AlienBulletCounter2 = 1
AlienNoise2 = 0
endif
rem fire shots from the aliens - sprite 53
if AlienBulletCounter3 = 1
FiringAlien3 = rnd(49) + 1
FiringAlien3PosX = Sprite X(FiringAlien3)
FiringAlien3PosY = Sprite Y(FiringAlien3)
AlienBulletCounter3 = 0
endif
if FiringAlien3PosY < BottomEdge and StopBullet3 = 0 and AlienArray(FiringAlien3) > 0
if AlienNoise3 = 0
play sound 2
AlienNoise3 = 1
endif
sprite 53, FiringAlien3PosX, FiringAlien3PosY, AlienBullet
FiringAlien3PosY = FiringAlien3PosY + BulletMove
else
AlienBulletCounter3 = 1
AlienNoise3 = 0
endif
return
BaseBullets:
rem fire bullets from the base - sprite 54 - and handle collision. AlienExplode is sprite 60
if spacekey() and BulletFired = 1
SpaceBarPressed = 1
FireBase = 1
endif
if SpaceBarPressed = 1
FiringBasePosX = sprite x(80)
FiringBasePosY = sprite y(80)
SpaceBarPressed = 0
endif
if FireBase = 1 and FiringBasePosY > TopEdge
if BaseNoise = 0
play sound 3
BaseNoise = 1
endif
sprite 54, FiringBasePosX+4, FiringBasePosY, BaseBullet
FiringBasePosY = FiringBasePosY - BulletMove
BulletFired = 0
for n = 1 to 50
if sprite hit(54, n)
ExplodeX = Sprite X(AlienArray(n))
ExplodeY = Sprite Y(AlienArray(n))
AlienExplodeFlag = 1
AlienArray(n) = 0
FireBase = 0
delete sprite 54
Score = Score + 1000
play sound 1
endif
next n
else
BulletFired = 1
delete sprite 54
BaseNoise = 0
endif
return
ShieldCollision:
rem check for collision between all bullets and shields and if so, remove appropriate sprites
if firebase = 1
for n = 1 to 20
if sprite hit(54,n+100)
Shield1Array(n) = 0
delete sprite 54
delete sprite n+100
FireBase = 0
else
if sprite hit(54,n+120)
Shield2Array(n) = 0
delete sprite 54
delete sprite n+120
FireBase = 0
else
if sprite hit(54,n+140)
Shield3Array(n) = 0
delete sprite 54
delete sprite n+140
FireBase = 0
else
if sprite hit(54,n+160)
Shield4Array(n) = 0
delete sprite 54
delete sprite n+160
FireBase = 0
endif
endif
endif
endif
next n
endif
for n = 1 to 20
if sprite hit(51,n+100)
Shield1Array(n) = 0
delete sprite 51
delete sprite n+100
StopBullet1 = 1
else
if sprite hit(51,n+120)
Shield2Array(n) = 0
delete sprite 51
delete sprite n+120
StopBullet1 = 1
else
if sprite hit(51,n+140)
Shield3Array(n) = 0
delete sprite 51
delete sprite n+140
StopBullet1 = 1
else
if sprite hit(51,n+160)
Shield4Array(n) = 0
delete sprite 51
delete sprite n+160
StopBullet1 = 1
endif
endif
endif
endif
next n
for n = 1 to 20
if sprite hit(52,n+100)
Shield1Array(n) = 0
delete sprite 52
delete sprite n+100
StopBullet2 = 1
else
if sprite hit(52,n+120)
Shield2Array(n) = 0
delete sprite 52
delete sprite n+120
StopBullet2 = 1
else
if sprite hit(52,n+140)
Shield3Array(n) = 0
delete sprite 52
delete sprite n+140
StopBullet2 = 1
else
if sprite hit(52,n+160)
Shield4Array(n) = 0
delete sprite 52
delete sprite n+160
StopBullet2 = 1
endif
endif
endif
endif
next n
for n = 1 to 20
if sprite hit(53,n+100)
Shield1Array(n) = 0
delete sprite 53
delete sprite n+100
StopBullet3 = 1
else
if sprite hit(53,n+120)
Shield2Array(n) = 0
delete sprite 53
delete sprite n+120
StopBullet3 = 1
else
if sprite hit(53,n+140)
Shield3Array(n) = 0
delete sprite 53
delete sprite n+140
StopBullet3 = 1
else
if sprite hit(53,n+160)
Shield4Array(n) = 0
delete sprite 53
delete sprite n+160
StopBullet3 = 1
endif
endif
endif
endif
next n
return
AlienExplode:
rem AlienExplode is sprite 60
if AlienExplodeFlag = 1 and AlienExplodeCounter < 11
sprite 60, ExplodeX, ExplodeY, AlienExplosion
inc AlienExplodeCounter
else
AlienExplodeFlag = 0
AlienExplodeCounter = 1
delete sprite 60
endif
return
BaseHit:
rem check for collision between alien bullets and base
if sprite hit(51, 80)
dec Lives
BaseExplodeX = sprite x(80)
BaseExplodeY = sprite y(80)
delete sprite 51
delete sprite 80
StopBullet1 = 1
BaseExplode = 1
play sound 1
endif
if sprite hit(52, 80)
dec Lives
BaseExplodeX = sprite x(80)
BaseExplodeY = sprite y(80)
delete sprite 52
delete sprite 80
StopBullet2 = 1
BaseExplode = 1
play sound 1
endif
if sprite hit(53, 80)
dec Lives
BaseExplodeX = sprite x(80)
BaseExplodeY = sprite y(80)
delete sprite 53
delete sprite 80
StopBullet3 = 1
BaseExplode = 1
play sound 1
endif
return
BaseExplode:
rem show base explosion sprite 91 and delay base replacement for 20 loops
if BaseExplode = 1 and BaseExplodeCounter < 50
sprite 91, BaseExplodeX, BaseExplodeY, AlienExplosion
inc BaseExplodeCounter
HideBase = 1
else
BaseExplode = 0
BaseExplodeCounter = 0
HideBase = 0
delete sprite 91
endif
return
AlienShieldCollide:
for n = 1 to 50
for x = 1 to 20
if AlienArray(n) > 0 and Shield1Array(x) > 0
if sprite hit(AlienArray(n), Shield1Array(x))
delete sprite Shield1Array(x)
Shield1Array(x) = 0
endif
endif
if AlienArray(n) > 0 and Shield2Array(x) > 0
if sprite hit(AlienArray(n), Shield2Array(x))
delete sprite Shield2Array(x)
Shield2Array(x) = 0
endif
endif
if AlienArray(n) > 0 and Shield3Array(x) > 0
if sprite hit(AlienArray(n), Shield3Array(x))
delete sprite Shield3Array(x)
Shield3Array(x) = 0
endif
endif
if AlienArray(n) > 0 and Shield4Array(x) > 0
if sprite hit(AlienArray(n), Shield4Array(x))
delete sprite Shield4Array(x)
Shield4Array(x) = 0
endif
endif
next x
next n
return
AlienBaseCollide:
for n = 1 to 50
if AlienArray(n) > 0
if sprite hit(AlienArray(n), 80)
EndCondition = 1
endif
endif
next n
return
EndLevel:
rem check if all aliens have been destroyed or all lives lost
AlienTotal = 0
for n = 1 to 50
AlienTotal = AlienTotal + AlienArray(n)
next n
if AlienTotal = 0
EndCondition = 2
endif
if Lives = 0
EndCondition = 1
endif
return
ResetLevel:
rem reset all of the alien and shield arrays, and the alien starting positions
rem alien array:
for n = 1 to 50
AlienArray(n) = n
next n
rem alien positions:
Alien1Top = 100
Alien2Top = 120
Alien3Top = 140
Alien4Top = 160
Alien5Top = 180
AlienLeft = 150
rem shield arrays:
for n = 1 to 20
Shield1Array(n) = n + 100
Shield2Array(n) = n + 120
Shield3Array(n) = n + 140
Shield4Array(n) = n + 160
next n
rem others
AlienMoveDelay = 1000
return