home *** CD-ROM | disk | FTP | other *** search
/ DarkBasic Professional / DarkBasicPro.iso / data1.cab / Lang_Files_(English) / Projects / RoomDemo / RoomDemo.dba next >
Encoding:
Text File  |  2004-09-22  |  14.1 KB  |  536 lines

  1. Rem Project: RoomDemo
  2. Rem Created: 30/07/2002 17:17:07
  3. rem Hours: 20
  4.  
  5. rem Initialise
  6. sync on : sync rate 60 : hide mouse : backdrop off
  7. set image colorkey 0,0,0
  8. set text font "Verdana"
  9. set text size 20
  10.  
  11. rem Global data
  12. global ambience# as integer
  13. global blockobj as integer
  14. dim objtype(10000)
  15.  
  16. rem Make Hero
  17. gosub _make_hero
  18.  
  19. rem Make Room
  20. gosub _create_lights
  21. gosub _make_room
  22.  
  23. rem Start things off
  24. gosub _start_demo
  25.  
  26. rem Main loop
  27. do
  28.  
  29.  rem Control Hero
  30.  gosub _control_hero
  31.  
  32.  rem Control room effects
  33.  gosub _control_effects
  34.  
  35.  rem Stats
  36.  center text screen width()/2,440,user$
  37.  
  38.  rem Update screen
  39.  sync
  40.  
  41. rem End loop
  42. loop
  43. end
  44.  
  45. _control_hero:
  46.  
  47. rem Store hero position before action
  48. oox1#=object position x(1)-40
  49. ooy1#=object position y(1)
  50. ooz1#=object position z(1)-40
  51. oox2#=object position x(1)+40
  52. ooy2#=object position y(1)+190
  53. ooz2#=object position z(1)+40
  54.  
  55. rem Move hero
  56. walk=0
  57. scrape=0
  58. if grabseq=0
  59.  if upkey()=1 then move object 1,4 : walk=1
  60.  if downkey()=1 then move object 1,-4 : walk=1
  61.  if leftkey()=1 then yrotate object 1,wrapvalue(object angle y(1)-4) : walk=1
  62.  if rightkey()=1 then yrotate object 1,wrapvalue(object angle y(1)+4) : walk=1
  63.  if controlkey()=1 and grab=0 and pushslider>0 then grab=1 : grabseq=1 : change=0
  64. else
  65.  if grabseq>=2 and grabseq<=3 and upkey()=1 and pushslider>0
  66.   if object position z(pushslider)<1800
  67.    if pushdire=1 then move object 1,4 : move object pushslider,4 : scrape=1
  68.   endif
  69.   if object position x(pushslider)>200
  70.    if pushdire=2 then move object 1,4 : yrotate object pushslider,270 : move object pushslider,4 : yrotate object pushslider,0 : scrape=1
  71.   endif
  72.  endif
  73. endif
  74. if (controlkey()=0 or upkey()=0) and grab=1 and grabseq<>4 then grabseq=4 : change=0
  75. if (controlkey()=0 or upkey()=0) then pushslider=0
  76. if scrape=1 then set sound volume 3,100 else set sound volume 3,0
  77.  
  78. rem Track hero with camera
  79. x#=object position x(1)
  80. y#=object position y(1)
  81. z#=object position z(1)
  82. a#=object angle y(1)
  83. d#=250.0
  84. h#=185.0
  85. s#=50.0
  86. set camera to follow x#,y#,z#,a#,d#,h#,s#,1
  87.  
  88. rem Ensure hero stays within blocks
  89. ox1#=object position x(1)-40
  90. oy1#=object position y(1)
  91. oz1#=object position z(1)-40
  92. ox2#=object position x(1)+40
  93. oy2#=object position y(1)+190
  94. oz2#=object position z(1)+40
  95. if get static collision hit(oox1#,ooy1#,ooz1#,oox2#,ooy2#,ooz2#,ox1#,oy1#,oz1#,ox2#,oy2#,oz2#)>0
  96.  ox#=object position x(1)
  97.  oy#=object position y(1)
  98.  oz#=object position z(1)
  99.  ox#=ox#-get static collision x()
  100.  oz#=oz#-get static collision z()
  101.  position object 1,ox#,oy#,oz#
  102. endif
  103.  
  104. rem Ensure hero stays outside sliding blocks
  105. colwithslider=object collision(1,0)
  106. if colwithslider>0
  107.  ox#=object position x(1)
  108.  oy#=object position y(1)
  109.  oz#=object position z(1)
  110.  ox#=ox#-get object collision x()
  111.  oz#=oz#-get object collision z()
  112.  position object 1,ox#,oy#,oz#
  113.  user$="USE CONTROL KEY AND FORWARD TO PUSH BLOCK"
  114. else
  115.  user$="USE ARROW KEYS TO MOVE AROUND"
  116. endif
  117. if vic=1 then user$="YOU FOUND THE SECRET ROOM - WELL DONE!"
  118.  
  119. rem If touching slider, figure out which one
  120. if colwithslider>0 and controlkey()=1
  121.  nearest=0
  122.  dist#=999999
  123.  for obj=101 to blockobj-1
  124.   if objtype(obj)=3
  125.    dx#=object position x(obj)-object position x(1)
  126.    dz#=object position z(obj)-object position z(1)
  127.    dd#=sqrt(abs(dx#*dx#)+abs(dz#*dz#))
  128.    da#=wrapvalue(atanfull(dx#,dz#))
  129.    if dd#<dist# and dd#<275
  130.     a#=wrapvalue(object angle y(1))
  131.     ok=0
  132.     if (a#>360-22 or a#<22) and (da#>360-16 or da#<16) then ok=1 : tdire=1
  133.     if (a#>270-22 and a#<270+22) and (da#>270-16 and da#<270+16) then ok=1 : tdire=2
  134.     if ok=1 then dist#=dd# : nearest=obj : dire=tdire
  135.    endif
  136.   endif
  137.  next obj
  138.  if nearest>0 then pushslider=nearest : pushdire=dire
  139. endif
  140.  
  141. rem Ensure camera stays within blocks
  142. ocx1#=cx1# : ocy1#=cy1# : ocz1#=cz1#
  143. ocx2#=cx2# : ocy2#=cy2# : ocz2#=cz2#
  144. cx1#=camera position x()-20
  145. cy1#=camera position y()-10
  146. cz1#=camera position z()-20
  147. cx2#=camera position x()+20
  148. cy2#=camera position y()+10
  149. cz2#=camera position z()+20
  150. if get static collision hit(ocx1#,ocy1#,ocz1#,ocx2#,ocy2#,ocz2#,cx1#,cy1#,cz1#,cx2#,cy2#,cz2#)>0
  151.  cx#=camera position x()
  152.  cy#=camera position y()
  153.  cz#=camera position z()
  154.  cx#=cx#-get static collision x()
  155.  cy#=cy#-get static collision y()
  156.  cz#=cz#-get static collision z()
  157.  position camera cx#,cy#,cz#
  158. endif
  159.  
  160. rem Animate hero for walking
  161. if grab=0
  162.  if walk<>lastwalk then change=1
  163.  if change=1
  164.   if walk=0 then loop object 1,0*heroframe#,39*heroframe#
  165.   if walk=1 then loop object 1,40*heroframe#,59*heroframe#
  166.   change=0 : lastwalk=walk
  167.  endif
  168. else
  169.  if change=0
  170.   if grabseq=1 then play object 1,60*heroframe#,80*heroframe#
  171.   if grabseq=2 then play object 1,120*heroframe#,150*heroframe#
  172.   if grabseq=3 then loop object 1,130*heroframe#,149*heroframe#
  173.   if grabseq=4 then play object 1,80*heroframe#,100*heroframe#
  174.   if grabseq=5 then play object 1,60*heroframe#,80*heroframe#
  175.   if grabseq=6 then play object 1,160*heroframe#,190*heroframe#
  176.   if grabseq=7 then loop object 1,170*heroframe#,189*heroframe#
  177.   change=1
  178.  else
  179.   if grabseq=1
  180.    rem Ensure hero faces slider slowly
  181.    if pushdire=1 then a#=curveangle(0,object angle y(1),4.0)
  182.    if pushdire=2 then a#=curveangle(270,object angle y(1),4.0)
  183.    yrotate object 1,a#
  184.   endif
  185.   if grabseq>=1 and grabseq<=2
  186.    rem Ensure hero moves far enough away
  187.    dx#=object position x(pushslider)-object position x(1)
  188.    dz#=object position z(pushslider)-object position z(1)
  189.    dd#=sqrt(abs(dx#*dx#)+abs(dz#*dz#))
  190.    if dd#<204 then move object 1,-4.0
  191.   endif
  192.   if grabseq=1 and object frame(1)>78*heroframe# then change=0 : inc grabseq
  193.   if grabseq=2 and object frame(1)>=148*heroframe# then change=0 : inc grabseq
  194.   if grabseq=4 and object frame(1)>=94*heroframe# then grabseq=0 : grab=0 : lastwalk=-1
  195.   if grabseq=5 and object frame(1)>78*heroframe# then change=0 : inc grabseq
  196.   if grabseq=6 and object frame(1)>=188*heroframe# then change=0 : inc grabseq
  197.  endif
  198. endif
  199.  
  200. rem Control ambience based on light proximity
  201. dx#=abs(camera position x()-400) : dy#=abs(camera position z()-600)
  202. distamb#=sqrt((dx#*dx#)+(dy#*dy#))/35.0
  203. if distamb#>15 then distamb#=15
  204. ambience#=curvevalue(distamb#,ambience#,5.0)
  205. set ambient light ambience#
  206.  
  207. rem reposition listener for 3dsound
  208. position listener object position x(1),object position y(1)+250,object position z(1)
  209.  
  210. return
  211.  
  212. _control_effects:
  213.  
  214. rem Scroll lightspot
  215. scroll object texture 2001,0,0.0005
  216.  
  217. rem Control effect on objects
  218. for obj=101 to blockobj-1
  219.  if objtype(obj)>0
  220.   r#=wrapvalue(r#+0.5)
  221.   if objtype(obj)=1 then yrotate object obj,90+(cos(wrapvalue(r#+wrapvalue(obj*100)))*5.0)
  222.   if objtype(obj)=2 then yrotate object obj,0+(cos(wrapvalue(r#+wrapvalue(obj*100)))*5.0)
  223.  endif
  224. next obj
  225.  
  226. rem Move particle in fire slightly
  227. position particle emissions 1,0,0,(rnd(20)-10)/20.0
  228.  
  229. rem Rotate green spotlight
  230. l#=wrapvalue(l#+1) : position light 4,400+sin(l#)*50,100,1700+cos(l#)*50
  231. if object position x(1)<600 and object position z(1)>1400 and vic=0 then play sound 4 : vic=1
  232.  
  233. return
  234.  
  235. _start_demo:
  236.  
  237. rem Begin Hero Activity
  238. position object 1,400,0,600
  239. yrotate object 1,90
  240. heroframe#=total object frames(1)/200.0
  241. loop object 1,0,39*heroframe#
  242.  
  243. rem Setup conelight object
  244. make object cone 2001,500
  245. position object 2001,400,0,600
  246. scale object 2001,100,500,100
  247. ghost object on 2001,0
  248. load image "media\gfx\shimer.bmp",2001
  249. texture object 2001,2001
  250. scale object texture 2001,1,0.2
  251. set object collision off 2001
  252.  
  253. rem Begins ounds
  254. loop sound 1 : loop sound 2
  255.  
  256. rem Setup camera
  257. position camera 400,250,600
  258.  
  259. return
  260.  
  261. _create_lights:
  262.  
  263. rem Setup main soft light
  264. set point light 0,400,0,600
  265. position light 0,400,0,600
  266. set light range 0,10000
  267.  
  268. rem Create cone of light
  269. make light 1
  270. set spot light 1,5,60
  271. position light 1,400,500,600
  272.  
  273. rem Create particles for fire
  274. load image "media\gfx\fire.bmp",1
  275. make particles 1,1,5,60.0
  276. set particle gravity 1,1
  277. set particle life 1,10
  278. set particle speed 1,0.006
  279.  
  280. rem Create particles for torches
  281. torchparticles=2
  282. for t=2 to 3
  283.  make light t
  284.  set point light t,0,0,0
  285.  color light t,rgb(255,48,48)
  286.  make particles t,1,10,20.0
  287.  set particle gravity t,-3
  288.  set particle life t,15
  289.  set particle speed t,0.006
  290. next t
  291.  
  292. rem Create green light of secret room
  293. make light 4
  294. set point light 4,0,0,0
  295. color light 4,rgb(32,255,32)
  296. set light range 4,600
  297.  
  298. return
  299.  
  300. _make_hero:
  301.  
  302. rem Load Hero
  303. load object "media\hero\roomdemo.x",1
  304. set object specular 1,0
  305. xrotate object 1,270
  306. fix object pivot 1
  307. rotate object 1,0,180,0
  308. set object speed 1,12000
  309. make object collision box 1,-40,0,-40,40,150,40,0
  310.  
  311. rem Load Sounds
  312. load 3dsound "media\sounds\fire.wav",1 : position sound 1,1200,250,400
  313. load 3dsound "media\sounds\wind.wav",2 : position sound 2,600,250,400
  314. load sound "media\sounds\move.wav",3 : set sound volume 3,0 : loop sound 3
  315. load sound "media\sounds\treat.wav",4
  316.  
  317. return
  318.  
  319. _make_room:
  320.  
  321. rem Room media
  322. set dir "media\room\"
  323.  
  324. rem Create Floor template
  325. template=1001 : make object cube template,200
  326. make mesh from object template,template
  327. delete object template
  328.  
  329. rem Load template images
  330. template=1001 : load image "floor.bmp",template
  331. template=1002 : load image "roof.bmp",template
  332. template=1003 : load image "wallb.bmp",template
  333. template=1004 : load image "wallc.bmp",template
  334. template=1005 : load image "walld.bmp",template
  335. template=1006 : load image "iron.bmp",template
  336.  
  337. rem Load template transparent images
  338. template=1011 : load image "bannera.bmp",template
  339. template=1012 : load image "bannerb.bmp",template
  340. template=1013 : load image "bannerc.bmp",template
  341.  
  342. rem Create room
  343. blockobj=101
  344. for pass=0 to 1
  345. restore _room1
  346. for z=0 to 9
  347.  for x=0 to 9
  348.   read mapid
  349.   if pass=0
  350.    if mapid=0
  351.     gosub _addfloor
  352.     gosub _addroof
  353.    endif
  354.    if mapid=1
  355.     gosub _addlowerwall
  356.     gosub _addupperwall
  357.    endif
  358.    if mapid=2
  359.     gosub _addfloor
  360.     load object "door.x",blockobj
  361.     set object specular blockobj,0
  362.     position object blockobj,x*200,0,(10-z)*200
  363.     set object collision off blockobj
  364.     coly=100 : gosub _setblockcollision
  365.     inc blockobj
  366.     gosub _addupperwall
  367.    endif
  368.    if mapid=3
  369.     gosub _addfloor
  370.    endif
  371.    if mapid=4
  372.     gosub _addfloor
  373.     load object "fireplace.x",blockobj
  374.     set object specular blockobj,0
  375.     set object collision off blockobj
  376.     coly=100 : gosub _setblockcollision
  377.     position object blockobj,x*200,0,(10-z)*200
  378.     position particles 1,(x*200)-70,-20,(10-z)*200
  379.     yrotate object blockobj,270
  380.     inc blockobj
  381.     gosub _addupperwall
  382.    endif
  383.    if mapid=5
  384.     gosub _addfloor
  385.     gosub _addroof
  386.     load object "torch.x",blockobj
  387.     set object specular blockobj,0
  388.     set object collision off blockobj
  389.     position object blockobj,x*200,150,(10-z)*200
  390.     position particles torchparticles,(x*200)+75,210,(10-z)*200
  391.     position light torchparticles,(x*200),50,(10-z)*200
  392.     inc torchparticles
  393.     inc blockobj
  394.    endif
  395.    if mapid=6
  396.     gosub _addlowerwall
  397.     gosub _addupperwindow
  398.    endif
  399.    if mapid=7
  400.     gosub _addlowerwall
  401.     gosub _addupperwall
  402.    endif
  403.    if mapid=8
  404.     gosub _addlowerwall
  405.     gosub _addupperwall
  406.    endif
  407.    if mapid=9
  408.     make object blockobj,1001,1004
  409.     set object collision off blockobj
  410.     position object blockobj,x*200,100,(10-z)*200
  411.     inc blockobj
  412.     make object blockobj,1001,1005
  413.     position object blockobj,x*200,300,(10-z)*200
  414.     inc blockobj
  415.    endif
  416.    if mapid=10
  417.     gosub _addfloor
  418.     make object blockobj,1001,1006
  419.     make object collision box blockobj,-100,-100,-100,100,100,100,0
  420.     position object blockobj,x*200,100,(10-z)*200
  421.     objtype(blockobj)=3
  422.     inc blockobj
  423.     gosub _addupperwall
  424.    endif
  425.   endif
  426.   if pass=1
  427.    if mapid=4
  428.     gosub _addbannerc
  429.    endif
  430.    if mapid=7
  431.     gosub _addbannera
  432.    endif
  433.    if mapid=8
  434.     gosub _addbannerb
  435.    endif
  436.   endif
  437.  next x
  438. next z
  439. next pass
  440.  
  441. rem restore directory
  442. set dir "..\.."
  443.  
  444. return
  445.  
  446. _addfloor:
  447.  make object blockobj,1001,1001
  448.  set object collision off blockobj
  449.  position object blockobj,x*200,-100,(10-z)*200
  450.  inc blockobj
  451. return
  452.  
  453. _addroof:
  454.  make object blockobj,1001,1002
  455.  set object collision off blockobj
  456.  position object blockobj,x*200,500,(10-z)*200
  457.  inc blockobj
  458. return
  459.  
  460. _addlowerwall:
  461.  make object blockobj,1001,1003
  462.  set object collision off blockobj
  463.  position object blockobj,x*200,100,(10-z)*200
  464.  coly=100 : gosub _setblockcollision
  465.  inc blockobj
  466. return
  467.  
  468. _addupperwall:
  469.  make object blockobj,1001,1003
  470.  set object collision off blockobj
  471.  position object blockobj,x*200,300,(10-z)*200
  472.  coly=300 : gosub _setblockcollision
  473.  inc blockobj
  474. return
  475.  
  476. _addupperwindow:
  477.  load object "window.x",blockobj
  478.  set object specular blockobj,0
  479.  set object collision off blockobj
  480.  position object blockobj,x*200,200,(10-z)*200
  481.  coly=300 : gosub _setblockcollision
  482.  inc blockobj
  483. return
  484.  
  485. _addbannera:
  486.  load object "bannera.x",blockobj
  487.  set object specular blockobj,0
  488.  set object collision off blockobj
  489.  texture object blockobj,1011
  490.  position object blockobj,(x*200),165,((10-z)*200)+115
  491.  yrotate object blockobj,90
  492.  set object blockobj,1,1,1
  493.  objtype(blockobj)=1
  494.  inc blockobj
  495. return
  496.  
  497. _addbannerb:
  498.  load object "bannerb.x",blockobj
  499.  set object specular blockobj,0
  500.  set object collision off blockobj
  501.  texture object blockobj,1012
  502.  position object blockobj,(x*200),165,((10-z)*200)-115
  503.  yrotate object blockobj,90
  504.  set object blockobj,1,1,1
  505.  objtype(blockobj)=1
  506.  inc blockobj
  507. return
  508.  
  509. _addbannerc:
  510.  load object "bannera.x",blockobj
  511.  set object specular blockobj,0
  512.  set object collision off blockobj
  513.  texture object blockobj,1013
  514.  position object blockobj,(x*200)-115,165,((10-z)*200)
  515.  set object blockobj,1,1,1,1,0,0,0
  516.  objtype(blockobj)=2
  517.  inc blockobj
  518. return
  519.  
  520. _setblockcollision:
  521.  make static collision box (x*200)-100,coly-100,((10-z)*200)-100,(x*200)+100,coly+100,((10-z)*200)+100
  522. return
  523.  
  524. _room1:
  525. data 01,01,09,01,01,01,01,01,01,01
  526. data 01,00,00,00,01,00,00,00,00,01
  527. data 09,00,00,00,10,00,00,00,00,01
  528. data 01,00,00,00,01,00,00,00,00,01
  529. data 01,08,02,08,01,00,00,00,00,01
  530. data 01,00,00,00,01,10,01,01,02,01
  531. data 01,00,00,00,00,00,05,01,00,01
  532. data 01,00,03,00,00,00,00,04,00,01
  533. data 01,00,00,00,00,00,05,01,00,01
  534. data 01,06,07,06,07,07,01,01,01,01
  535.  
  536.