Hi,
this a game I have in code base and have used the commpresser on I got it down to 20 lines.
If you have installed DBPro in the standard place then it will be able to find the media it needs.
work with mouse or joy stick if you have one.
so here it is :-
global sw sh score shipassed yes no:global stars distance timeleft:global ship numberofships:global tv show ForcePresent level rate#:global posx posx# posy posy# sheilds# endtitle:global xunit# yunit# laser delay gameover joy mouse:global newspeed# jump shiptopass flashme gamestart:randomize timer():level=1:yes=1:no=0:gameover=yes:gamestart=no:setupscreen():checkforjoy():findscreensize():loadimages():loadsounds():makecrosshairs():startpos():
makestars():makeships():showships():updatestars():do:makeplay():loop:function makeplay():if gamestart=no:showstarttitle():endif:updatestars():if gameover<>yes:showscoresandtimeleft():if joy=yes:handlejoy():endif:if mouse=yes:handlemouse():endif:
updatecrosshairs():showcrosshairs():firelaser():checkhit():moveships():endif:sync:endfunction:function setupscreen():sync on:sync rate 0:backdrop on:color backdrop rgb(0,0,0):hide mouse:set text font "arial":set text size 22:set text transparent:endfunction:function showcrosshairs():sprite 1,posx,posy,1:
endfunction:function updatecrosshairs():posx=posx#:posy=posy#:endfunction:function checkforjoy():ForcePresent=0:empty checklist:PERFORM CHECKLIST FOR CONTROL DEVICES:for c=1 to checklist quantity():print checklist string$(c):if checklist value a(c):SET CONTROL DEVICE checklist string$(c):ForcePresent=1:endif:next c:endfunction:function loadimages():set image colorkey 255,0,255:imgtra=1:
load image "C:\Program Files\Dark Basic Software\Dark Basic Professional\Help\examples\input\crosshair.bmp",1,imgtra:load image "C:\Program Files\Dark Basic Software\Dark Basic Professional\Media\Textures\Metal_Plates_T.BMP",2,imgtra:cls rgb(255,0,255):set text size 70:center text sw/2,sh/2-150,"ACE":center text sw/2,sh/2-50,"Gunner 2":set text size 22:center text sw/2,sh/2+75,"Press SpaceBar, Fire or":center text sw/2,sh/2+97,"Left mouse Button to Start":get image 3,0,0,sw,sh,1:paste image 3,0,0,1:sprite 1001,0,0,3:cls RGB(162,209,238):get image 4,0,0,sw,sh,1:endfunction:function loadsounds():load sound "C:\Program Files\Dark Basic Software\Dark Basic Professional\Media\Sounds\Guns\Ray gun.wav",1,0:load sound "C:\Program Files\Dark Basic Software\Dark Basic Professional\media\sounds\guns\blaster.wav",2,0:load sound "C:\Program Files\Dark Basic Software\Dark Basic Professional\media\sounds\explosions\boom 2.wav",3,0:load sound "C:\Program Files\Dark Basic Software\Dark Basic Professional\media\sounds\shot impacts\hit oil tank.wav",4,0:
endfunction:function makecrosshairs():set current bitmap 0:set sprite 1,0,1:offset sprite 1,16,16,:endfunction:function startpos():newspeed#=newspeed#+0.1:flashme=255:oldscore=score:score=0:show=1:shiptopass=20:sheilds#=100:shipassed=0:stars=100:posx#=320:posy#=240:timeleft=10000:gameover=yes:
gamestart=no:endfunction:function findscreensize():sw=screen width():sh=screen height():endfunction:function makestars():Dim star_ang#(stars):Dim star_rad#(stars):Dim star_spd#(stars):for st=0 to stars:star_ang#(st)=rnd(36000)/100.00:star_rad#(st)=rnd(sw/2):star_spd#(st)=0.5+abs(sin(rnd(360))):next st:endfunction:function makeships():numberofships = 50:dim shipspeed#(numberofships):for shipobj = 1 to numberofships:
make object cube shipobj,2:TEXTURE OBJECT shipobj ,2:set object cull shipobj,1:hide object shipobj:next shipobj:positionships():endfunction:function positionships():for shipobj = 1 to rnd(numberofships)+1:shipspeed#(shipobj)=.2+newspeed#:if object position z(shipobj)<200:position object shipobj,rnd(shipptopass)-10,rnd(shiptopass)-10,rnd(500):show object shipobj:endif:next numberofships:endfunction:function handlemouse():if posx#>=0.0:posx#=mousex():endif:
if posx#>=sw:posx#=sw:else:if posx#<=0.0:posx#=0.0:endif:endif:if posy#>=0.0:posy#=mousey():endif:if posy#>=sh:posy#=sh:else:if posy#<=0.0:posy#=0.0:endif:endif:endfunction:function handlejoy():if posx#>=0.0:
posx#=posx#+((joystick x()+1000/2000)/100):endif:if posx#>=sw:posx#=sw:else:if posx#<=0.0:posx#=0.0:endif:endif:if posy#>=0.0:posy#=posy#+((joystick y()+1000/2000)/100):endif:if posy#>=sh:posy#=sh:else:if posy#<=0.0:posy#=0.0:endif:endif:endfunction:
function showstarttitle():if keystate(57) or joystick fire a()=1 or mouseclick()=1:if mouseclick()=1:mouse=1:joy=0:else:mouse=0:joy=1:endif:cls:hide sprite 1001:gamestart=yes:gameover=no:endif:endfunction:function showships():if gamerover<>yes:if shipassed<>shiptopass:for shipobj =1 to numberofships:move object shipobj,-shipspeed#(shipobj):
if object position z(shipobj)<0:position object shipobj,rnd(shiptopass)-10,rnd(shiptopass)-10,500:inc shipassed:endif:next shipobj:endif:endif:endfunction:function showscoresandtimeleft():set text size 22:text 0,0,"Score "+str$(score)+" ":tv$="Sheilds "+str$(sheilds#)+"% ":text sw-text width(tv$),0,"Sheilds "+str$(sheilds#)+"% ":center text sw/2,25,"Level "+str$(level):if val(mid$(str$(timer()),3))>0 and gameover<>yes:timeleft=timeleft-1:endif:center text sw/2,0,"Hyper-Jump ready in "+str$(timeleft/100):if timeleft<=0:hyperjump():
endif:endfunction:function hyperjump():if gameover=yes:exitfunction:endif:jump=1:jumptime=200:repeat:updatestars():sync:dec jumptime,1:until jumptime=0:jump=0:inc level,1:timeleft=10000*level:shipassed=0:positionships():endfunction:function moveships():
if gameover<>yes:if shipassed<>50:for shipobj = 1 to numberofships:move object shipobj ,-shipspeed#(shipobj):if object position z(shipobj)<0:position object shipobj,rnd(shiptopass)-10,rnd(shiptopass)-10,500:inc shipassed:sheilds#=sheilds#-((shipassed*10)/shiptopass):makeplay():play sound 4:screenflash():endif:next shipobj:endif:endif:if shipassed=shiptopass or sheilds#<0:gameover=yes:endtitle=yes:sheilds#=100.0:shipassed=0:
lastshippassed():endif:endfunction:function lastshippassed():if endtitle<>yes or gameover<>yes:exitfunction:endif:if endtitle=yes:gamestart=no:time=timer():hide sprite 2001:repeat:center text sw/2,sh/2,"The Dorg have Won! You failed..":center text sw/2,sh/2+22,"You scored "+str$(score)+" this time round.":makeplay():until timer()>time+5000:endtitle=no:restartgame():endif:endfunction:
function restartgame():show=0:level=0:jump=0:shippassed=0:gameover=yes:gamestart=no:timeleft=10000:sheilds#=100.0:endtitle=no:makeplay():endfunction:function playfiresound():play sound 2:endfunction:function firelaser():if gameover<>yes:if joy=1:fire=joystick fire a():endif:
if mouse=1:if mouseclick()=1 then fire=1:endif:if fire=1 and laser<>1:laser=1:delay=0:playfiresound():if ForcePresent=1 then force shoot 100,20:repeat:line 0,sh/2,posx,posy:line 0,sh/2+1,posx,posy:line sw,sh/2,posx,posy:inc delay,1:showscoresandtimeleft():updatestars():until delay=5:endif:if fire<>1:laser=0:endif:
endif:endfunction:function checkhit():if laser<>0 and gameover=no:object=pick object(posx,posy,1,numberofships):if object>0:distance=get pick distance():if distance<200:hide object object:score=score+20:position object object,rnd(20)-10,rnd(20)-10,500:show object object:play sound 3:endif:endif:endif:endfunction:function updatestars():for st=0 to stars:star_rad#(st)=star_rad#(st)-star_spd#(st):
if star_rad#(st)<0 then star_rad#(st)=star_rad#(st)+sw/2:px=sw/2+(sin(star_ang#(st))*star_rad#(st)):py=sh/2+(cos(star_ang#(st))*star_rad#(st)):pc=(star_rad#(st))+55:if pc>255 then pc=255:dot px,py,rgb(pc,pc,pc):if jump=1:line px,py,sw/2,sh/2:endif:next st:endfunction:function screenflash():if gameover=yes:set sprite alpha 2001,0:exitfunction:endif:if gameover=no:repeat:sprite 2001,0,0,4:set sprite alpha 2001,flashme:
dec flashme:makeplay():until flashme=0:flashme=255:endif:endfunction
heres it is uncompressed
global sw sh score shipassed yes no
global stars distance timeleft
global ship numberofships
global tv show ForcePresent level rate#
global posx posx# posy posy# sheilds# endtitle
global xunit# yunit# laser delay gameover joy mouse
global newspeed# jump shiptopass flashme gamestart
randomize timer()
level=1
yes=1
no=0
gameover=yes
gamestart=no
setupscreen()
checkforjoy()
findscreensize()
loadimages()
loadsounds()
makecrosshairs()
startpos()
makestars()
makeships()
showships()
updatestars()
do
makeplay()
loop
function makeplay()
if gamestart=no
showstarttitle()
endif
updatestars()
if gameover<>yes
showscoresandtimeleft()
if joy=yes
handlejoy()
endif
if mouse=yes
handlemouse()
endif
updatecrosshairs()
showcrosshairs()
firelaser()
checkhit()
moveships()
endif
sync
endfunction
function setupscreen()
sync on
sync rate 0
backdrop on
color backdrop rgb(0,0,0)
hide mouse
set text font "arial"
set text size 22
set text transparent
endfunction
function showcrosshairs()
sprite 1,posx,posy,1
endfunction
function updatecrosshairs()
posx=posx#
posy=posy#
endfunction
function checkforjoy()
ForcePresent=0
empty checklist
PERFORM CHECKLIST FOR CONTROL DEVICES
for c=1 to checklist quantity()
print checklist string$(c)
if checklist value a(c)
SET CONTROL DEVICE checklist string$(c)
ForcePresent=1
endif
next c
endfunction
function loadimages()
set image colorkey 255,0,255
imgtra=1
load image "C:\Program Files\Dark Basic Software\Dark Basic Professional\Help\examples\input\crosshair.bmp",1,imgtra
load image "C:\Program Files\Dark Basic Software\Dark Basic Professional\Media\Textures\Metal_Plates_T.BMP",2,imgtra
cls rgb(255,0,255)
set text size 70
center text sw/2,sh/2-150,"ACE"
center text sw/2,sh/2-50,"Gunner 2"
set text size 22
center text sw/2,sh/2+75,"Press SpaceBar, Fire or"
center text sw/2,sh/2+97,"Left mouse Button to Start"
get image 3,0,0,sw,sh,1
paste image 3,0,0,1
sprite 1001,0,0,3
cls RGB(162,209,238)
get image 4,0,0,sw,sh,1
endfunction
function loadsounds()
load sound "C:\Program Files\Dark Basic Software\Dark Basic Professional\Media\Sounds\Guns\Ray gun.wav",1,0
load sound "C:\Program Files\Dark Basic Software\Dark Basic Professional\media\sounds\guns\blaster.wav",2,0
load sound "C:\Program Files\Dark Basic Software\Dark Basic Professional\media\sounds\explosions\boom 2.wav",3,0
load sound "C:\Program Files\Dark Basic Software\Dark Basic Professional\media\sounds\shot impacts\hit oil tank.wav",4,0
endfunction
function makecrosshairs()
set current bitmap 0
set sprite 1,0,1
offset sprite 1,16,16,
endfunction
function startpos()
newspeed#=newspeed#+0.1
flashme=255
oldscore=score
score=0
show=1
shiptopass=20
sheilds#=100
shipassed=0
stars=100
posx#=320
posy#=240
timeleft=10000
gameover=yes
gamestart=no
endfunction
function findscreensize()
sw=screen width()
sh=screen height()
endfunction
function makestars()
Dim star_ang#(stars)
Dim star_rad#(stars)
Dim star_spd#(stars)
for st=0 to stars
star_ang#(st)=rnd(36000)/100.00
star_rad#(st)=rnd(sw/2)
star_spd#(st)=0.5+abs(sin(rnd(360)))
next st
endfunction
function makeships()
numberofships = 50
dim shipspeed#(numberofships)
for shipobj = 1 to numberofships
make object cube shipobj,2
TEXTURE OBJECT shipobj ,2
set object cull shipobj,1
hide object shipobj
next shipobj
positionships()
endfunction
function positionships()
for shipobj = 1 to rnd(numberofships)+1
shipspeed#(shipobj)=.2+newspeed#
if object position z(shipobj)<200
position object shipobj,rnd(shipptopass)-10,rnd(shiptopass)-10,rnd(500)
show object shipobj
endif
next numberofships
endfunction
function handlemouse()
if posx#>=0.0
posx#=mousex()
endif
if posx#>=sw
posx#=sw
else
if posx#<=0.0
posx#=0.0
endif
endif
if posy#>=0.0
posy#=mousey()
endif
if posy#>=sh
posy#=sh
else
if posy#<=0.0
posy#=0.0
endif
endif
endfunction
function handlejoy()
if posx#>=0.0
posx#=posx#+((joystick x()+1000/2000)/100)
endif
if posx#>=sw
posx#=sw
else
if posx#<=0.0
posx#=0.0
endif
endif
if posy#>=0.0
posy#=posy#+((joystick y()+1000/2000)/100)
endif
if posy#>=sh
posy#=sh
else
if posy#<=0.0
posy#=0.0
endif
endif
endfunction
function showstarttitle()
if keystate(57) or joystick fire a()=1 or mouseclick()=1
if mouseclick()=1
mouse=1
joy=0
else
mouse=0
joy=1
endif
cls
hide sprite 1001
gamestart=yes
gameover=no
endif
endfunction
function showships()
if gamerover<>yes
if shipassed<>shiptopass
for shipobj =1 to numberofships
move object shipobj,-shipspeed#(shipobj)
if object position z(shipobj)<0
position object shipobj,rnd(shiptopass)-10,rnd(shiptopass)-10,500
inc shipassed
endif
next shipobj
endif
endif
endfunction
function showscoresandtimeleft()
set text size 22
text 0,0,"Score "+str$(score)+" "
tv$="Sheilds "+str$(sheilds#)+"% "
text sw-text width(tv$),0,"Sheilds "+str$(sheilds#)+"% "
center text sw/2,25,"Level "+str$(level)
if val(mid$(str$(timer()),3))>0 and gameover<>yes
timeleft=timeleft-1
endif
center text sw/2,0,"Hyper-Jump ready in "+str$(timeleft/100)
if timeleft<=0
hyperjump()
endif
endfunction
function hyperjump()
if gameover=yes
exitfunction
endif
jump=1
jumptime=200
repeat
updatestars()
sync
dec jumptime,1
until jumptime=0
jump=0
inc level,1
timeleft=10000*level
shipassed=0
positionships()
endfunction
function moveships()
if gameover<>yes
if shipassed<>50
for shipobj = 1 to numberofships
move object shipobj ,-shipspeed#(shipobj)
if object position z(shipobj)<0
position object shipobj,rnd(shiptopass)-10,rnd(shiptopass)-10,500
inc shipassed
sheilds#=sheilds#-((shipassed*10)/shiptopass)
makeplay()
play sound 4
screenflash()
endif
next shipobj
endif
endif
if shipassed=shiptopass or sheilds#<0
gameover=yes
endtitle=yes
sheilds#=100.0
shipassed=0
lastshippassed()
endif
endfunction
function lastshippassed()
if endtitle<>yes or gameover<>yes
exitfunction
endif
if endtitle=yes
gamestart=no
time=timer()
hide sprite 2001
repeat
center text sw/2,sh/2,"The Dorg have Won! You failed.."
center text sw/2,sh/2+22,"You scored "+str$(score)+" this time round."
makeplay()
until timer()>time+5000
endtitle=no
restartgame()
endif
endfunction
function restartgame()
show=0
level=0
jump=0
shippassed=0
gameover=yes
gamestart=no
timeleft=10000
sheilds#=100.0
endtitle=no
makeplay()
endfunction
function playfiresound()
play sound 2
endfunction
function firelaser()
if gameover<>yes
if joy=1
fire=joystick fire a()
endif
if mouse=1
if mouseclick()=1 then fire=1
endif
if fire=1 and laser<>1
laser=1
delay=0
playfiresound()
if ForcePresent=1 then force shoot 100,20
repeat
line 0,sh/2,posx,posy
line 0,sh/2+1,posx,posy
line sw,sh/2,posx,posy
inc delay,1
showscoresandtimeleft()
updatestars()
until delay=5
endif
if fire<>1
laser=0
endif
endif
endfunction
function checkhit()
if laser<>0 and gameover=no
object=pick object(posx,posy,1,numberofships)
if object>0
distance=get pick distance()
if distance<200
hide object object
score=score+20
position object object,rnd(20)-10,rnd(20)-10,500
show object object
play sound 3
endif
endif
endif
endfunction
function updatestars()
for st=0 to stars
star_rad#(st)=star_rad#(st)-star_spd#(st)
if star_rad#(st)<0 then star_rad#(st)=star_rad#(st)+sw/2
px=sw/2+(sin(star_ang#(st))*star_rad#(st))
py=sh/2+(cos(star_ang#(st))*star_rad#(st))
pc=(star_rad#(st))+55
if pc>255 then pc=255
dot px,py,rgb(pc,pc,pc)
if jump=1
line px,py,sw/2,sh/2
endif
next st
endfunction
function screenflash()
if gameover=yes
set sprite alpha 2001,0
exitfunction
endif
if gameover=no
repeat
sprite 2001,0,0,4
set sprite alpha 2001,flashme
dec flashme
makeplay()
until flashme=0
flashme=255
endif
endfunction
I'm not getting you down am I, Ho Look! another fancy Door?