home *** CD-ROM | disk | FTP | other *** search
/ DarkBasic Professional / DarkBasicPro.iso / data1.cab / Lang_Files_(English) / Help / tutorials / tutorial7.dba < prev    next >
Encoding:
Text File  |  2004-09-22  |  4.3 KB  |  178 lines

  1. rem Tutorial 7
  2.  
  3. rem Initial settings
  4. sync on : sync rate 100
  5. backdrop off : hide mouse
  6.  
  7. rem Select font
  8. set text font "arial" : set text size 16
  9. set text to bold : set text transparent
  10.  
  11. rem Loading prompt
  12. sync : center text screen width()/2,screen height()/2,"LOADING" : sync
  13.  
  14. rem Load all media for game
  15. gosub _load_game
  16.  
  17. rem Setup all objects for game
  18. gosub _setup_game
  19.  
  20. rem Game loop
  21. do
  22.  
  23.  rem Control game elements
  24.  gosub _control_player
  25.  gosub _control_gunandbullet
  26.  gosub _control_enemies
  27.  
  28.  rem Update screen
  29.  sync
  30.  
  31. rem End loop
  32. loop
  33.  
  34. rem End program
  35. end
  36.  
  37. _control_player:
  38.  
  39. rem Control player direction
  40. rotate camera camera angle x(0)+(mousemovey()/2.0),camera angle y(0)+(mousemovex()/2.0),0
  41.  
  42. rem Control player movement
  43. cx#=camera angle x(0) : cy#=camera angle y(0)
  44. if upkey()=1 then xrotate camera 0,0 : move camera 0,0.2 : xrotate camera 0,cx#
  45. if downkey()=1 then xrotate camera 0,0 : move camera 0,-0.2 : xrotate camera 0,cx#
  46. if leftkey()=1 then yrotate camera 0,cy#-90 : move camera 0.2 : yrotate camera 0,cy#
  47. if rightkey()=1 then yrotate camera 0,cy#+90 : move camera 0.2 : yrotate camera 0,cy#
  48. if wrapvalue(camera angle x(0))>40 and wrapvalue(camera angle x(0))<180 then xrotate camera 0,40
  49. if wrapvalue(camera angle x(0))>180 and wrapvalue(camera angle x(0))<280 then xrotate camera 0,280
  50.  
  51. rem Apply simple gravity to player
  52. position camera camera position x(),camera position y()-0.1,camera position z()
  53.  
  54. rem Player is always focal point of sky
  55. position object SkyObj,camera position x(),camera position y(),camera position z()
  56.  
  57. rem Position listener at player for 3D sound
  58. position listener camera position x(),camera position y(),camera position z()
  59. rotate listener camera angle x(),camera angle y(),camera angle z()
  60.  
  61. rem In case of restart
  62. if restart=1
  63.    restart=0
  64.    set bsp collision off 1
  65.    rotate camera 0,0,0
  66.    position camera 2,2,2
  67.    set bsp camera collision 1,0,0.75,0
  68. endif
  69.  
  70. return
  71.  
  72. _control_gunandbullet:
  73.  
  74.  rem Control gun firing
  75.  if mouseclick()=1 and bullet=-50
  76.   bullet=100
  77.   play sound GunSnd
  78.   position object BulletObj,camera position x(0),camera position y(0),camera position z(0)
  79.   rotate object BulletObj,camera angle x(0),camera angle y(0),0
  80.   set bsp object collision 2,BulletObj,0.1,1
  81.   move object BulletObj,0.2
  82.  endif
  83.  
  84.  rem Control life of bullet
  85.  if bullet>0
  86.  
  87.   rem If bullet collides with BSP world
  88.   if bsp collision hit(2)=1 or bulletimpact=1
  89.    rem End bullet on wall
  90.    position sound ImpactSnd,object position x(BulletObj), object position y(BulletObj), object position z(BulletObj)
  91.    play sound ImpactSnd
  92.    bulletimpact=0
  93.    bullet=0
  94.   else
  95.    rem Move bullet
  96.    dec bullet
  97.    move object BulletObj,0.5
  98.   endif
  99.  
  100.   rem Bullet dies
  101.   if bullet=0
  102.    set bsp collision off 2
  103.   endif
  104.  
  105.  else
  106.   rem Gun recharge phase
  107.   if bullet>-50 then dec bullet
  108.  endif
  109.  
  110. return
  111.  
  112. _control_enemies:
  113.  rem *ADDCODE* TUT7C
  114. return
  115.  
  116. _control_stats:
  117. return
  118.  
  119. _setup_game:
  120.  
  121.  rem Setup camera
  122.  set camera range 0.1,5000
  123.  autocam off
  124.  
  125.  rem Setup sky model
  126.  set object SkyObj,1,0,0,0,0,0,0
  127.  scale object SkyObj,20,20,20
  128.  
  129.  rem Setup gun for player
  130.  lock object on GunObj
  131.  scale object GunObj,2,2,4
  132.  rotate object GunObj,270,0,0
  133.  position object GunObj,0.5,-1,2
  134.  disable object zdepth GunObj
  135.  
  136.  rem Create object for bullet
  137.  BulletObj=3 : make object cube BulletObj,0.1
  138.  
  139.  rem Create simple sprite based crosshair
  140.  sprite 1,320-16,240-16,CrossHairImg
  141.  set sprite 1,0,1
  142.  
  143.  rem *ADDCODE* TUT7D
  144.  
  145.  rem Trigger player initialisation
  146.  restart=1
  147.  
  148. return
  149.  
  150. _load_game:
  151.  
  152.  rem Load BSP world and sky model
  153.  load bsp "world\ikzdm1.pk3","ikzdm1.bsp"
  154.  SkyObj=1 : load object "models\sky\am.x",SkyObj
  155.  
  156.  rem Load model for gun
  157.  GunObj=2 : load object "models\gun\gun.x",GunObj
  158.  
  159.  rem *ADDCODE* TUT7A
  160.  
  161.  rem Load all sounds
  162.  GunSnd=1 : load sound "sounds\gun.wav",GunSnd
  163.  ImpactSnd=2 : load 3dsound "sounds\impact.wav",ImpactSnd
  164.  DieSnd=3 : load sound "sounds\die.wav",DieSnd
  165.  
  166.  rem *ADDCODE* TUT7B
  167.  
  168.  rem Load music (WAV best for looping)
  169.  MusicSnd=101 : load sound "sounds\ingame.wav",MusicSnd
  170.  loop sound MusicSnd : set sound volume MusicSnd,80
  171.  
  172.  rem Load images
  173.  FireImg=1 : load image "images\fire.bmp",FireImg
  174.  CrossHairImg=2 : load image "images\crosshair.bmp",CrossHairImg
  175.  
  176. return
  177.  
  178.