home *** CD-ROM | disk | FTP | other *** search
- Rem Project: RoomDemo
- Rem Created: 30/07/2002 17:17:07
- rem Hours: 20
-
- rem Initialise
- sync on : sync rate 60 : hide mouse : backdrop off
- set image colorkey 0,0,0
- set text font "Verdana"
- set text size 20
-
- rem Global data
- global ambience# as integer
- global blockobj as integer
- dim objtype(10000)
-
- rem Make Hero
- gosub _make_hero
-
- rem Make Room
- gosub _create_lights
- gosub _make_room
-
- rem Start things off
- gosub _start_demo
-
- rem Main loop
- do
-
- rem Control Hero
- gosub _control_hero
-
- rem Control room effects
- gosub _control_effects
-
- rem Stats
- center text screen width()/2,440,user$
-
- rem Update screen
- sync
-
- rem End loop
- loop
- end
-
- _control_hero:
-
- rem Store hero position before action
- oox1#=object position x(1)-40
- ooy1#=object position y(1)
- ooz1#=object position z(1)-40
- oox2#=object position x(1)+40
- ooy2#=object position y(1)+190
- ooz2#=object position z(1)+40
-
- rem Move hero
- walk=0
- scrape=0
- if grabseq=0
- if upkey()=1 then move object 1,4 : walk=1
- if downkey()=1 then move object 1,-4 : walk=1
- if leftkey()=1 then yrotate object 1,wrapvalue(object angle y(1)-4) : walk=1
- if rightkey()=1 then yrotate object 1,wrapvalue(object angle y(1)+4) : walk=1
- if controlkey()=1 and grab=0 and pushslider>0 then grab=1 : grabseq=1 : change=0
- else
- if grabseq>=2 and grabseq<=3 and upkey()=1 and pushslider>0
- if object position z(pushslider)<1800
- if pushdire=1 then move object 1,4 : move object pushslider,4 : scrape=1
- endif
- if object position x(pushslider)>200
- if pushdire=2 then move object 1,4 : yrotate object pushslider,270 : move object pushslider,4 : yrotate object pushslider,0 : scrape=1
- endif
- endif
- endif
- if (controlkey()=0 or upkey()=0) and grab=1 and grabseq<>4 then grabseq=4 : change=0
- if (controlkey()=0 or upkey()=0) then pushslider=0
- if scrape=1 then set sound volume 3,100 else set sound volume 3,0
-
- rem Track hero with camera
- x#=object position x(1)
- y#=object position y(1)
- z#=object position z(1)
- a#=object angle y(1)
- d#=250.0
- h#=185.0
- s#=50.0
- set camera to follow x#,y#,z#,a#,d#,h#,s#,1
-
- rem Ensure hero stays within blocks
- ox1#=object position x(1)-40
- oy1#=object position y(1)
- oz1#=object position z(1)-40
- ox2#=object position x(1)+40
- oy2#=object position y(1)+190
- oz2#=object position z(1)+40
- if get static collision hit(oox1#,ooy1#,ooz1#,oox2#,ooy2#,ooz2#,ox1#,oy1#,oz1#,ox2#,oy2#,oz2#)>0
- ox#=object position x(1)
- oy#=object position y(1)
- oz#=object position z(1)
- ox#=ox#-get static collision x()
- oz#=oz#-get static collision z()
- position object 1,ox#,oy#,oz#
- endif
-
- rem Ensure hero stays outside sliding blocks
- colwithslider=object collision(1,0)
- if colwithslider>0
- ox#=object position x(1)
- oy#=object position y(1)
- oz#=object position z(1)
- ox#=ox#-get object collision x()
- oz#=oz#-get object collision z()
- position object 1,ox#,oy#,oz#
- user$="USE CONTROL KEY AND FORWARD TO PUSH BLOCK"
- else
- user$="USE ARROW KEYS TO MOVE AROUND"
- endif
- if vic=1 then user$="YOU FOUND THE SECRET ROOM - WELL DONE!"
-
- rem If touching slider, figure out which one
- if colwithslider>0 and controlkey()=1
- nearest=0
- dist#=999999
- for obj=101 to blockobj-1
- if objtype(obj)=3
- dx#=object position x(obj)-object position x(1)
- dz#=object position z(obj)-object position z(1)
- dd#=sqrt(abs(dx#*dx#)+abs(dz#*dz#))
- da#=wrapvalue(atanfull(dx#,dz#))
- if dd#<dist# and dd#<275
- a#=wrapvalue(object angle y(1))
- ok=0
- if (a#>360-22 or a#<22) and (da#>360-16 or da#<16) then ok=1 : tdire=1
- if (a#>270-22 and a#<270+22) and (da#>270-16 and da#<270+16) then ok=1 : tdire=2
- if ok=1 then dist#=dd# : nearest=obj : dire=tdire
- endif
- endif
- next obj
- if nearest>0 then pushslider=nearest : pushdire=dire
- endif
-
- rem Ensure camera stays within blocks
- ocx1#=cx1# : ocy1#=cy1# : ocz1#=cz1#
- ocx2#=cx2# : ocy2#=cy2# : ocz2#=cz2#
- cx1#=camera position x()-20
- cy1#=camera position y()-10
- cz1#=camera position z()-20
- cx2#=camera position x()+20
- cy2#=camera position y()+10
- cz2#=camera position z()+20
- if get static collision hit(ocx1#,ocy1#,ocz1#,ocx2#,ocy2#,ocz2#,cx1#,cy1#,cz1#,cx2#,cy2#,cz2#)>0
- cx#=camera position x()
- cy#=camera position y()
- cz#=camera position z()
- cx#=cx#-get static collision x()
- cy#=cy#-get static collision y()
- cz#=cz#-get static collision z()
- position camera cx#,cy#,cz#
- endif
-
- rem Animate hero for walking
- if grab=0
- if walk<>lastwalk then change=1
- if change=1
- if walk=0 then loop object 1,0*heroframe#,39*heroframe#
- if walk=1 then loop object 1,40*heroframe#,59*heroframe#
- change=0 : lastwalk=walk
- endif
- else
- if change=0
- if grabseq=1 then play object 1,60*heroframe#,80*heroframe#
- if grabseq=2 then play object 1,120*heroframe#,150*heroframe#
- if grabseq=3 then loop object 1,130*heroframe#,149*heroframe#
- if grabseq=4 then play object 1,80*heroframe#,100*heroframe#
- if grabseq=5 then play object 1,60*heroframe#,80*heroframe#
- if grabseq=6 then play object 1,160*heroframe#,190*heroframe#
- if grabseq=7 then loop object 1,170*heroframe#,189*heroframe#
- change=1
- else
- if grabseq=1
- rem Ensure hero faces slider slowly
- if pushdire=1 then a#=curveangle(0,object angle y(1),4.0)
- if pushdire=2 then a#=curveangle(270,object angle y(1),4.0)
- yrotate object 1,a#
- endif
- if grabseq>=1 and grabseq<=2
- rem Ensure hero moves far enough away
- dx#=object position x(pushslider)-object position x(1)
- dz#=object position z(pushslider)-object position z(1)
- dd#=sqrt(abs(dx#*dx#)+abs(dz#*dz#))
- if dd#<204 then move object 1,-4.0
- endif
- if grabseq=1 and object frame(1)>78*heroframe# then change=0 : inc grabseq
- if grabseq=2 and object frame(1)>=148*heroframe# then change=0 : inc grabseq
- if grabseq=4 and object frame(1)>=94*heroframe# then grabseq=0 : grab=0 : lastwalk=-1
- if grabseq=5 and object frame(1)>78*heroframe# then change=0 : inc grabseq
- if grabseq=6 and object frame(1)>=188*heroframe# then change=0 : inc grabseq
- endif
- endif
-
- rem Control ambience based on light proximity
- dx#=abs(camera position x()-400) : dy#=abs(camera position z()-600)
- distamb#=sqrt((dx#*dx#)+(dy#*dy#))/35.0
- if distamb#>15 then distamb#=15
- ambience#=curvevalue(distamb#,ambience#,5.0)
- set ambient light ambience#
-
- rem reposition listener for 3dsound
- position listener object position x(1),object position y(1)+250,object position z(1)
-
- return
-
- _control_effects:
-
- rem Scroll lightspot
- scroll object texture 2001,0,0.0005
-
- rem Control effect on objects
- for obj=101 to blockobj-1
- if objtype(obj)>0
- r#=wrapvalue(r#+0.5)
- if objtype(obj)=1 then yrotate object obj,90+(cos(wrapvalue(r#+wrapvalue(obj*100)))*5.0)
- if objtype(obj)=2 then yrotate object obj,0+(cos(wrapvalue(r#+wrapvalue(obj*100)))*5.0)
- endif
- next obj
-
- rem Move particle in fire slightly
- position particle emissions 1,0,0,(rnd(20)-10)/20.0
-
- rem Rotate green spotlight
- l#=wrapvalue(l#+1) : position light 4,400+sin(l#)*50,100,1700+cos(l#)*50
- if object position x(1)<600 and object position z(1)>1400 and vic=0 then play sound 4 : vic=1
-
- return
-
- _start_demo:
-
- rem Begin Hero Activity
- position object 1,400,0,600
- yrotate object 1,90
- heroframe#=total object frames(1)/200.0
- loop object 1,0,39*heroframe#
-
- rem Setup conelight object
- make object cone 2001,500
- position object 2001,400,0,600
- scale object 2001,100,500,100
- ghost object on 2001,0
- load image "media\gfx\shimer.bmp",2001
- texture object 2001,2001
- scale object texture 2001,1,0.2
- set object collision off 2001
-
- rem Begins ounds
- loop sound 1 : loop sound 2
-
- rem Setup camera
- position camera 400,250,600
-
- return
-
- _create_lights:
-
- rem Setup main soft light
- set point light 0,400,0,600
- position light 0,400,0,600
- set light range 0,10000
-
- rem Create cone of light
- make light 1
- set spot light 1,5,60
- position light 1,400,500,600
-
- rem Create particles for fire
- load image "media\gfx\fire.bmp",1
- make particles 1,1,5,60.0
- set particle gravity 1,1
- set particle life 1,10
- set particle speed 1,0.006
-
- rem Create particles for torches
- torchparticles=2
- for t=2 to 3
- make light t
- set point light t,0,0,0
- color light t,rgb(255,48,48)
- make particles t,1,10,20.0
- set particle gravity t,-3
- set particle life t,15
- set particle speed t,0.006
- next t
-
- rem Create green light of secret room
- make light 4
- set point light 4,0,0,0
- color light 4,rgb(32,255,32)
- set light range 4,600
-
- return
-
- _make_hero:
-
- rem Load Hero
- load object "media\hero\roomdemo.x",1
- set object specular 1,0
- xrotate object 1,270
- fix object pivot 1
- rotate object 1,0,180,0
- set object speed 1,12000
- make object collision box 1,-40,0,-40,40,150,40,0
-
- rem Load Sounds
- load 3dsound "media\sounds\fire.wav",1 : position sound 1,1200,250,400
- load 3dsound "media\sounds\wind.wav",2 : position sound 2,600,250,400
- load sound "media\sounds\move.wav",3 : set sound volume 3,0 : loop sound 3
- load sound "media\sounds\treat.wav",4
-
- return
-
- _make_room:
-
- rem Room media
- set dir "media\room\"
-
- rem Create Floor template
- template=1001 : make object cube template,200
- make mesh from object template,template
- delete object template
-
- rem Load template images
- template=1001 : load image "floor.bmp",template
- template=1002 : load image "roof.bmp",template
- template=1003 : load image "wallb.bmp",template
- template=1004 : load image "wallc.bmp",template
- template=1005 : load image "walld.bmp",template
- template=1006 : load image "iron.bmp",template
-
- rem Load template transparent images
- template=1011 : load image "bannera.bmp",template
- template=1012 : load image "bannerb.bmp",template
- template=1013 : load image "bannerc.bmp",template
-
- rem Create room
- blockobj=101
- for pass=0 to 1
- restore _room1
- for z=0 to 9
- for x=0 to 9
- read mapid
- if pass=0
- if mapid=0
- gosub _addfloor
- gosub _addroof
- endif
- if mapid=1
- gosub _addlowerwall
- gosub _addupperwall
- endif
- if mapid=2
- gosub _addfloor
- load object "door.x",blockobj
- set object specular blockobj,0
- position object blockobj,x*200,0,(10-z)*200
- set object collision off blockobj
- coly=100 : gosub _setblockcollision
- inc blockobj
- gosub _addupperwall
- endif
- if mapid=3
- gosub _addfloor
- endif
- if mapid=4
- gosub _addfloor
- load object "fireplace.x",blockobj
- set object specular blockobj,0
- set object collision off blockobj
- coly=100 : gosub _setblockcollision
- position object blockobj,x*200,0,(10-z)*200
- position particles 1,(x*200)-70,-20,(10-z)*200
- yrotate object blockobj,270
- inc blockobj
- gosub _addupperwall
- endif
- if mapid=5
- gosub _addfloor
- gosub _addroof
- load object "torch.x",blockobj
- set object specular blockobj,0
- set object collision off blockobj
- position object blockobj,x*200,150,(10-z)*200
- position particles torchparticles,(x*200)+75,210,(10-z)*200
- position light torchparticles,(x*200),50,(10-z)*200
- inc torchparticles
- inc blockobj
- endif
- if mapid=6
- gosub _addlowerwall
- gosub _addupperwindow
- endif
- if mapid=7
- gosub _addlowerwall
- gosub _addupperwall
- endif
- if mapid=8
- gosub _addlowerwall
- gosub _addupperwall
- endif
- if mapid=9
- make object blockobj,1001,1004
- set object collision off blockobj
- position object blockobj,x*200,100,(10-z)*200
- inc blockobj
- make object blockobj,1001,1005
- position object blockobj,x*200,300,(10-z)*200
- inc blockobj
- endif
- if mapid=10
- gosub _addfloor
- make object blockobj,1001,1006
- make object collision box blockobj,-100,-100,-100,100,100,100,0
- position object blockobj,x*200,100,(10-z)*200
- objtype(blockobj)=3
- inc blockobj
- gosub _addupperwall
- endif
- endif
- if pass=1
- if mapid=4
- gosub _addbannerc
- endif
- if mapid=7
- gosub _addbannera
- endif
- if mapid=8
- gosub _addbannerb
- endif
- endif
- next x
- next z
- next pass
-
- rem restore directory
- set dir "..\.."
-
- return
-
- _addfloor:
- make object blockobj,1001,1001
- set object collision off blockobj
- position object blockobj,x*200,-100,(10-z)*200
- inc blockobj
- return
-
- _addroof:
- make object blockobj,1001,1002
- set object collision off blockobj
- position object blockobj,x*200,500,(10-z)*200
- inc blockobj
- return
-
- _addlowerwall:
- make object blockobj,1001,1003
- set object collision off blockobj
- position object blockobj,x*200,100,(10-z)*200
- coly=100 : gosub _setblockcollision
- inc blockobj
- return
-
- _addupperwall:
- make object blockobj,1001,1003
- set object collision off blockobj
- position object blockobj,x*200,300,(10-z)*200
- coly=300 : gosub _setblockcollision
- inc blockobj
- return
-
- _addupperwindow:
- load object "window.x",blockobj
- set object specular blockobj,0
- set object collision off blockobj
- position object blockobj,x*200,200,(10-z)*200
- coly=300 : gosub _setblockcollision
- inc blockobj
- return
-
- _addbannera:
- load object "bannera.x",blockobj
- set object specular blockobj,0
- set object collision off blockobj
- texture object blockobj,1011
- position object blockobj,(x*200),165,((10-z)*200)+115
- yrotate object blockobj,90
- set object blockobj,1,1,1
- objtype(blockobj)=1
- inc blockobj
- return
-
- _addbannerb:
- load object "bannerb.x",blockobj
- set object specular blockobj,0
- set object collision off blockobj
- texture object blockobj,1012
- position object blockobj,(x*200),165,((10-z)*200)-115
- yrotate object blockobj,90
- set object blockobj,1,1,1
- objtype(blockobj)=1
- inc blockobj
- return
-
- _addbannerc:
- load object "bannera.x",blockobj
- set object specular blockobj,0
- set object collision off blockobj
- texture object blockobj,1013
- position object blockobj,(x*200)-115,165,((10-z)*200)
- set object blockobj,1,1,1,1,0,0,0
- objtype(blockobj)=2
- inc blockobj
- return
-
- _setblockcollision:
- make static collision box (x*200)-100,coly-100,((10-z)*200)-100,(x*200)+100,coly+100,((10-z)*200)+100
- return
-
- _room1:
- data 01,01,09,01,01,01,01,01,01,01
- data 01,00,00,00,01,00,00,00,00,01
- data 09,00,00,00,10,00,00,00,00,01
- data 01,00,00,00,01,00,00,00,00,01
- data 01,08,02,08,01,00,00,00,00,01
- data 01,00,00,00,01,10,01,01,02,01
- data 01,00,00,00,00,00,05,01,00,01
- data 01,00,03,00,00,00,00,04,00,01
- data 01,00,00,00,00,00,05,01,00,01
- data 01,06,07,06,07,07,01,01,01,01
-
-