Some Source Codes for DarkBASIC.
Noob Codes:
Simple Geussing Game:
PRINT "Welcome to the geussing game!"
WAIT 3000
PRINT "I'm thinking of a number between 1 and 5."
WAIT 1000
PRINT "Can you geuss it? Just type your geuss below!"
INPUT 1
WAIT 5000
INPUT "And the number is (whatever you want it to be)!", 1
Great! You just typed your first "true" game! "Hello World" examples are not "real" games so this should start
you on your way to making great games! Advanced users can randomize the number so its different every time.
Bitmaps and Sound:
Custom Slide Show:
First you need to copy your Bitmaps and WAV song to your project folder. Then replace all the "NAME"
with the name of your files. To create more slides just copy it from line number 6.
LOAD BITMAP "NAME.bmp" LOAD BITMAP "NAME.bmp", 1 LOAD SOUND "NAME.wav", 1 PLAY SOUND 1 WAIT
6000 LOAD BITMAP "NAME.bmp" LOAD BITMAP "NAME.bmp", 2 WAIT 8000 LOAD BITMAP "NAME.bmp" LOAD BITMAP "NAME.bmp",
3
Animation:
Load Bitmap "NAME.bmp" LOAD BITMAP "NAME.bmp",1 WAIT 500 LOAD BITMAP "Name.bmp" LOAD BITMAP
"Name.bmp", 1
rem You can see how simple that was! Draw Bitmaps that change only a little at a time!
USER CODES:
TRASKO: Space Game
remstart ************************************************************ *
SPACE WAR by Trasko
* *
* * This game is an old-styled space game for my Amiga 500 * * computer. I don't remember who was the author.
* * The Original game need of 3 boundary instead 1 like mine * * but unfortunatly i wasn't able to make a better job
* *
* * The point - line distance function was taken from * * www.thegamescreator.com site.
* * Thank to the author KyleTDBoy
* *
* * For suggest, problem contact me at:
* * trasko@traskosfriends.it
* *
* * P.S. Sorry for my bad english! But i come from Italy * ************************************************************ remend sync
rate 300 sync on hide mouse randomize timer()
rem Array for Bullet dim xp#(1,60) dim yp#(1,60) dim pa(1,60) dim vxp#(1,60) dim vyp#(1,60) rem
Array for Boundary dim angb(9) dim angba(9) rem Array for Star Field dim xs#(150) dim ys(150) dim ms(150) dim
ps#(150)
init: for i=1 to 150 xs#(i)=rnd(640) ys(i)=rnd(480) ms(i)=rnd(5) ps#(i)=rnd(4)/4 next
i ok=1 repeat for i=1 to 150 ink rgb(51*ms(i),51*ms(i),51*ms(i)),0 dot xs#(i),ys(i)
xs#(i)=xs#(i)+ps#(i) if xs#(i)>640 then xs#(i)=0 next i ink rgb(255,255,0),0 set text size 30 center
text 320,50,"SPACE WAR" set text size 8 center text 320,100,"Scopo del gioco è distruggere l'avversario situato nel
centro dello schermo." center text 320,120,"L'avversario è protetto da una barriera rotante che può resistere a molti" center
text 320,140,"colpi. Inizialmente sparerà un colpo ogni tanto per mantere le distanze" center text 320,160,"ma con il cadere
delle barriere il nemico si sentirà minacciato e comincierà" center text 320,180,"a sparare sempre più velocemente." center
text 320,200,"Puoi resistere fino a 5 colpi, dopodichè la tua astronave esploderà." center text 320,300,"Premi invio per
iniziare la partita" sync cls 0 if returnkey()=1 and ok=0 then ok=2 if returnkey()=0 then ok=0 until returnkey()=1
and ok=2 rem Human player Setting x#=100 y#=240 velx#=0 vely#=0 a=wrapvalue(rnd(360)) energia=5 punti=0
nemico: rem Cpu player setting xn#=320 yn#=240 an=wrapvalue(rnd(360)) vivo=1 for i=0 to
1 for j=0 to 60 xp#(i,j)=0 yp#(i,j)=0 pa(i,j)=0
next j next i
rem boundary setting for i=0 to 9 angb(i)=wrapvalue(i*36) angba(i)=16 next
i
rem Main loop repeat starfield() gosub player_human gosub player_cpu gosub proiettili astronave(x#,y#,a,rgb(255,0,0)) if
vivo=1 astronave(xn#,yn#,an,rgb(0,0,255)) else goto enemy_death endif if energia=0
then goto gameover ink rgb(200,150,20),0 center text 320,0,"Punti: "+str$(punti) text 0,0,"Energia:" box 60,3,energia*50,13 sync cls
0 until 0
player_human: if leftkey()=1 then a=wrapvalue(a-1) if rightkey()=1 then a=wrapvalue(a+1) velx#=sin(a) vely#=cos(a) if
upkey()=1 then f#=1 if upkey()=0 f#=f#-0.001 if f#<0 then f#=0 endif if spacekey()=1
relay=relay+1 if relay=6 relay=0 shot=shot+1
if shot>60 then shot=0 if pa(0,shot)=0
pa(0,shot)=1 xp#(0,shot)=x#
yp#(0,shot)=y# vxp#(0,shot)=sin(a)*1.5
vyp#(0,shot)=cos(a)*1.5 endif endif endif x#=x#-(velx#*f#) y#=y#+(vely#*f#) if
x#>640 then x#=640 if x#<0 then x#=0 if y#>480 then y#=480 if y#<0 then y#=0 return
player_cpu: rem Calculated the enemy position ang#=wrapvalue((atanfull((xn#-x#),(yn#-y#))+180)*-1) if
wrapvalue(an-ang#)<179 then gosub sx if wrapvalue(an-ang#)>181 then gosub dx rem Where and when i can shoot? if
an<=(ang#+1) and an>=(ang#-1) relayn=relayn+1 if relayn>=pericolo
relayn=0 shotn=shotn+1 if shotn>60 then shotn=0
if pa(1,shotn)=0 pa(1,shotn)=1
xp#(1,shotn)=xn# yp#(1,shotn)=yn#
vxp#(1,shotn)=sin(an)*2 vyp#(1,shotn)=cos(an)*2
endif endif endif rem Draw the boundary pericolo=0 for i=0 to 9 succ=i+1
if succ>9 then succ=0 rem calculate if it's hit from an enemy bullet for k=1 to 60
if PointLineDistance(cos(angb(i))*40+320,sin(angb(i))*40+240,cos(angb(succ))*40+320,sin(angb(succ))*40+240,xp#(0,k),yp#(0,k))<1
and angba(i)>0 and pa(0,k)=1 angba(i)=angba(i)-1
punti=punti+1 pa(0,k)=0 endif
next k rem calculate if then enemy ship collide whith the boundary if PointLineDistance(cos(angb(i))*40+320,sin(angb(i))*40+240,cos(angb(succ))*40+320,sin(angb(succ))*40+240,x#,y#)<6
and angba(i)>0 energia=0 endif rem If energy boundary
isn't 0 then draw it if angba(i)>0 ink rgb(0,16*angba(i)-1,0),0
line cos(angb(i))*40+320,sin(angb(i))*40+240,cos(angb(succ))*40+320,sin(angb(succ))*40+240 endif
angb(i)=wrapvalue(angb(i)+1) pericolo=pericolo+angba(i) next i return
rem Draw the ship (position x, position y, direction degree, color) function astronave(x#,y#,a,c) ink
c,0 line cos(wrapvalue(a+90))*10+x#,sin(wrapvalue(a+90))*10+y#,cos(wrapvalue(a+315))*10+x#,sin(wrapvalue(a+315))*10+y# line
cos(wrapvalue(a+315))*10+x#,sin(wrapvalue(a+315))*10+y#,x#,y# line x#,y#,cos(wrapvalue(a+225))*10+x#,sin(wrapvalue(a+225))*10+y# line
cos(wrapvalue(a+225))*10+x#,sin(wrapvalue(a+225))*10+y#,cos(wrapvalue(a+90))*10+x#,sin(wrapvalue(a+90))*10+y# endfunction
rem turn right dx: an=wrapvalue(an+1) return
rem turn left sx: an=wrapvalue(an-1) return
rem calculate the bullet position proiettili: for i=0 to 1 if i=0 then ink rgb(255,0,0),0 else
ink rgb(0,0,255),0 for j=1 to 60 if pa(i,j)=1
xp#(i,j)=xp#(i,j)-vxp#(i,j) yp#(i,j)=yp#(i,j)+vyp#(i,j)
dot xp#(i,j),yp#(i,j) if xp#(i,j)>640 then pa(i,j)=0
if xp#(i,j)<0 then pa(i,j)=0 if yp#(i,j)>480 then pa(i,j)=0
if yp#(i,j)<0 then pa(i,j)=0 if dis(xp#(0,j),yp#(0,j),xn#,yn#)<6
and vivo=1 vivo=0
punti=punti+500 pa(0,j)=0
endif if dis(xp#(1,j),yp#(1,j),x#,y#)<6 and energia>0
energia=energia-1 pa(1,j)=0
endif endif next j next i return
enemy_death: pressione=0 dd=0 repeat starfield() ink rgb(255,255,0),0 center text 320,240,"C
O N G R A T U L A Z I O N I ! ! !" center text 320,256,"Premi Invio per continuare" for i=0 to 9 succ=i+1
if succ>9 then succ=0 if angba(i)>0 ink rgb(0,16*angba(i)-1,0),0
line cos(angb(i))*(40+dd)+320,sin(angb(i))*(40+dd)+240,cos(angb(succ))*(40+dd)+320,sin(angb(succ))*(40+dd)+240
endif angb(i)=wrapvalue(angb(i)+1) next i dd=dd+1 sync cls 0 if returnkey()=1 then pressione=1 until
pressione<>0 goto nemico
gameover: dd=0 repeat starfield() if dd<60 ink rgb(255,0,0),0
circle x#,y#,dd dd=dd+1 endif ink rgb(255,255,0),0 center text 320,200,"G A M E O V E
R" center text 320,230,"Il tuo punteggio è: "+str$(punti) center text 320,256,"Premi Invio per continuare" sync cls
0 until returnkey()=1 goto init end
Function Dis(x1#,y1#,x2#,y2#) VX# = X2# - X1# VY# = Y2# - Y1#
V# = SQRT(VX#^2 + VY#^2) Endfunction V#
Function PointLineDistance(x1#,y1#,x2#,y2#,x3#,y3#)
`First We Have To Find The Length Of The Line LineMag# = Dis(x2#,y2#,x1#,y1#)
`U# Is A Percentage. Its The Percent Of The Line That Can Be Added To The Line To Find The
Intersection U# = (((x3# - x1#) * (x2# - x1#)) + ((y3# - y1#) * (y2# - y1#))) / LineMag#^2
`Lets Find The Intersection (Or The Closest Point On The Line To The Point)
IntersectionX# = X1# + U# * ( X2# - X1#) IntersectionY# = Y1# + U# * ( Y2# - Y1#)
`This Section of Code Is Incase The Second Point Is Less Than The First Point.
`Normally, It Would Cause A Lot Of Problems, But We Solved Them If X2# > X1#
If IntersectionX# > X2# then IntersectionX# = X2# If IntersectionX# < X1# then IntersectionX#
= X1# Endif
If X2# < X1# If IntersectionX# < X2# then IntersectionX#
= X2# If IntersectionX# > X1# then IntersectionX# = X1# Endif
If Y2# > Y1# If IntersectionY# > Y2# then IntersectionY#
= Y2# If IntersectionY# < Y1# then IntersectionY# = Y1# Endif
If Y2# < Y1# If IntersectionY# < Y2# then IntersectionY#
= Y2# If IntersectionY# > Y1# then IntersectionY# = Y1# Endif
`Get Our Distance From The Point To The Line Distance# = Dis(IntersectionX#,IntersectionY#,X3#,Y3#) Endfunction
Distance#
rem Draw the starfield function starfield() for i=1 to 50 ink rgb(51*ms(i),51*ms(i),51*ms(i)),0
dot xs#(i),ys(i) xs#(i)=xs#(i)+ps#(i) if xs#(i)>640 then xs#(i)=0 next i endfunction
Darth Mans: Rocket
LOAD SOUND "explosion.wav",1 Load Music "Music03.mid",1 beggin: Play music 1 sync rate 200
t=100:tb=50:l=2 x=325:y=150 Hide Mouse CLS Gosub drawrocket
set text size t center text 320,10,"Rocket" set text size tb center text 320,400,"Press Space Bar
To Launch" wait key y=250
INPUT "Enter time limit ";time# Sync on
DO CLS y=y-3 Gosub drawrocket IF y<-100 then GOTO wattup sync Loop
wattup: DIM bx(10000):DIM by(10000)
start: y=400:x=250 l=1:b=0:s=0:a=1:q=0:p#=0
f=1:g=1:ex=50:ey=50
DO q=q+1 if q=100 time#=time#-1 q=0 Endif if time#=0 then goto end CLS circle
15,15,50 Print time# Print p#
GOSUB DrawROCKET GOSUB Drawbad if leftkey()=1 then x=x-5 if rightkey()=1 then x=x+5 if upkey()=1
then y=y-5 if downkey()=1 then y=y+5
if x<-40 then x=690 if x>690 then x=-40 if y<-70 then y=520 if y>520 then y=-70
If s<20 then Goto NoBullet Gosub Createbullet Nobullet: s=s+1 If s>20 then s=0 Gosub
Drawbullet If b>9999 then goto start sync Loop
drawrocket: LINE x,y,(x+(l*10)),(y+(l*10)) LINE (x+(l*10)),(y+(l*10)),(x+(l*10)),(y+(l*60)) LINE
(x+(l*10)),(y+(l*60)),(x+(l*20)),(y+(l*70)) LINE (x+(l*20)),(y+(l*70)),(x-(l*10)),(y+(l*70)) LINE (x-(l*10)),(y+(l*70)),(x+(l*10)),(y+(l*70)) LINE
x,y,(x-(l*10)),(y+(l*10)) LINE (x-(l*10)),(y+(l*10)),(x-(l*10)),(y+(l*60)) LINE (x-(l*10)),(y+(l*60)),(x-(l*20)),(y+(l*70)) LINE
(x-(l*20)),(y+(l*70)),(x-(l*10)),(y+(l*70)) LINE (x+(l*10)),(y+(l*10)),(x+(l*40)),(y+(l*60)) LINE (x+(l*40)),(y+(l*60)),(x+(l*10)),(y+(l*60)) LINE
(x-(l*10)),(y+(l*10)),(x-(l*40)),(y+(l*60)) LINE (x-(l*40)),(y+(l*60)),(x-(l*10)),(y+(l*60)) LINE (x+(l*10)),(y+(l*10)),(x-(l*10)),(y+(l*10)) Return
Createbullet: If spacekey()=1 b=b+1 bx(b)=x:by(b)=y endif Return
drawbullet: for c=a to b circle bx(c),by(c),2 by(c)=by(c)-10 If by(c)<0 then a=a+1
If bx(c)>=ex and bx(c)<=(ex+20) and by(c)>=ey and by(c)<=(ey+20) PLAY SOUND 1 p#=p#+1 ink
rgb(rnd(255),rnd(255),rnd(255)),1 endif next c Return
Drawbad: If ex>615 or ex<20 then f=f*(-1) If ey>450 or ey<20 then g=g*(-1) d=f*3:e=g*3 ex=ex+d:ey=ey+e BOX
ex,ey,(ex+10),(ey+10) Return
end: DO CLS PRINT "FINAL SCORE = "; print p# center text 320,30,"Darn your out of time" center
text 320,250,"Press 'Enter' to replay" if returnkey()=1 then goto beggin sync LOOP
|