Beruflich Dokumente
Kultur Dokumente
DarkBasicGuides
DarkBasic
ProgrammingTutorials
MainMenu
HomePage
RequiredKnowledge
1Basics
2MediaBasics
3CameraControl
42DGame
53DGame
Tutorial2Media
SAMPLECODE:
Withtheknowledgethatyouhavesofar,youareabletocreate
simpletextbasedcomputergames.Youalsohavethe
knowledgeonhowtostructureagraphicalcomputergame.
Allcomputergamesnowusedifferenttypesofmedia.
Thedifferenttypesofmediathatyoucanuseincludeimages,
objectsandsounds.
Eachofthose3catagorieshavesubcatagoriesofmedia.A
coupleoftheseare:
ImagesBackgroundsandtextures.
ObjectsModelsandmatrices.
SoundsSoundeffectsandmusic.
Thisisnotaworkingprogram.
Thisisjustawholegroupofcode
snippetsthatdisplayhowtousethe
commands.
Thecommandsarespacedoutso
thattheyareclosetowheretheyare
mentionedinthemaintext.
Mostexampleswillincorporatethe
previouslyexplainedcommands.
IMAGES:
Imagesuseaspecialidentificationnumberwhichyougive
tothem(inthetutorialstheplacetoputitislabelledwith
inum).Therecannotbetwoimageswiththesame
number.
loadimage"face.bmp",1
loadimage"people/person1.bmp",2
Command
Purpose
loadimage"mygame/cars/car1.jpg",3
Loadsanimagefromafolder
intomemoryforthegameto
use.
inumistheplaceinmemory
wheretheimageisstored.
loadimage"mygame/cars/car2.jpg",4
deleteimageinum
Deletesimagenumbered
inum.
spritesnum,x,y,inum
Positionsanimageatxandy
onthescreen.Theimage
usedisinum.Givesthesprite
anumberofsnumforfuture
reference.
loadimage"name",inum
rotatespritesnum,angle
Rotatesaspritebyangle
degrees.
hidespritesnum
Hidethespritewithreference
numbersnum.
showspritesnum
Showthesnumsprite.
deletespritesnum
Deletethesprite.
sprite1,50,200,3
sprite2,100,200,2
sprite3,100,180,1
rotatesprite1,90
hidesprite3
wait500
showsprite3
sprite1,50,200,4
deletesprite1
deletesprite2
deletesprite3
Youmaynotrealiseit,butusingallthecommandsyouhave
learntsofar,youcaneasilycreategameslikefrogger!
OBJECTS:
http://nodnyl.com/english/tut2.html
3Dobjectscreateawholeworldofexcitement.Using3D
objectsopensuptheopportunitytocreategameslikeCounter
StrikeandGrandTheftAuto.
Objectsuseaspecialidentificationnumberwhichyougiveto
them(inthetutorialstheplacetoputitislabelledwithonum).
Therecannotbetwoobjectswiththesamenumber.
1/3
9/16/2016
DarkBasicGuides
CREATINGOBJECTS:
loadobject"car.3ds",1
Command
loadobject"name",onum
makeobjectsphereonum,rad
makeobjectcylinderonum,rad
Purpose
loadobject"dog.x",2
Loadsanobjectfroma
specifiedfilepath.Theobject
dataissavedasanumberfor
futurereference.
makeobjectsphere3,300
Createsaspherewitha
radiusofrad.
Createsacylinderwitha
raduisofradandaheightof
doublerad.
makeobjectboxonum,x,y,z
Createsaboxthathas
dimensionsxbyybyz.
makeobjectcubeonum,size
Createsacubewithssidesof
size.
makeobjectcylinder4,55
makeobjectbox5,10,40,80
makeobjectcube6,250
remloadthemedia
loadobject"house.x",1
loadimage"bricks.bmp",1
OBJECTSAPPEARANCE:
Command
Purpose
remsetthevariables
Hidestheobjectsothatthe
playercannotseeitonthe
screen.
fadevalue=100
showobjectonum
Displaystheobjectagain.
repeat
deleteobjectonum
Deletestheobjectfrom
memory.
fadeobject1,fadevalue
fadeobjectonum,fade
Fadestheobjecttoagiven
value.
0isnotvisible.
100isvisible.
hideobject1
Makestheobjectpartially
transparentandalsocolours
itwhite.
hideobjectonum
ghostobjectononum
ghostobjectoffonum
Changestheobjectbacktoits
normalself.
textureobjectonum,inum
Texturetheobjectwitha
preloadedimage.
remfadetheobjecttonothing
fadevalue=fadevalue1
untilfadevalue=0
wait1000
remloadobjectsandpositionthem
loadobject"cars/car.x",1
loadobject"obstacles/wall.x",2
positionobject1,10,0,100
positionobject2,10,0,200
`gameloop
do
`movethecar
OBJECTMOVEMENT:
ifupkey()=1thenmoveobject1,5
Command
positionobjectonum,x,y,z
Movetheobjectforwardata
speedonspeed.
rotateobjectonum,x,y,z
Rotatetheobjectoneach
axisbydifferentamounts.
SOUNDS:
http://nodnyl.com/english/tut2.html
Positiontheobjectata
positionin3Dspaceatx,y
andzcoordinates.
moveobjectonum,speed
objectcollision(onum,onum2)
Purpose
Forusewithan"ifthen"
statement.Itwillreturntrueif
objectonumhascollidingwith
objectonum2.
`checkifcarhitswall
ifobjectcollision(1,2)then
moveobject1,5
endif
sync
loop
`loadasound
loadsound"car_engine.wav",1
playsound1
do
ifspacekey()=1thenpausesound1
2/3
9/16/2016
DarkBasicGuides
Soundaddtheextradimensiontogaming.Soundsinagame
stimulateanothersenseandcanincreasetheenjoymentofa
gameconsiderably.
Soundsuseaspecialidentificationnumberwhichyougiveto
them(inthetutorialstheplacetoputitislabelledwithsnum).
Therecannotbetwosoundswiththesamenumber.
ifshiftkey()=1thenresumesound1
ifcontrolkey()=1thenstopsound1
ifupkey()=1thenexit
loop
deletesound1
Command
Purpose
loadsound"name",snum
Loadsasoundfromafile.
deletesoundsnum
Deletesthesoundfrom
memory.
playsoundsnum
Playsaloadedsound.
pausesoundsnum
Pausesaplayingsound.
resumesoundsnum
Resumesapausedsound.
stopsoundsnum
Stopsaplayingsound.
Congradulations!
Younowknowallthebasicsonhowtoaddmediaintoyour
veryowncomputergame.Allyouneedtolearnnowishowto
controlthecamera(whattheplayersees)andthenyouareset
tocreateyourfullyfunctionalcomputergames!
<<BASICS^TOPOFPAGE^
CAMERA>>
TutorialsBy:
LyndonCarter
HelpfulHint:
HelpfulHint:
PressF4tocheckyourcodeforsyntaxerrors.
PressF5torunyourprogram.
DBPT@nodnyl.com
LyndonCarterSACEStage2EnglishCommunicationsAssignmentApplication1BuildAWebsiteMrsNelson
http://nodnyl.com/english/tut2.html
3/3