May 07, 2024, 01:25:10 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


3D ghost train + sound by My Main man Jolly Roger :)

Started by pistol350, September 04, 2007, 09:15:01 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

pistol350

Wow!
When Scary and wonderful are together, jolly Roger is around  ;D
try this!  :P


'Ghost train
'Jolly Roger Oct 2004
DECLARE "kernel32",GetTickCount(),INT
DEF win:WINDOW
DEF error,run:INT
DEF scene,camera,light,lastframetime,timesincelastframe:INT
DEF rail1,rail2,sleeper[10],n,spiderbody,spiderhead,starttime:INT
DEF spiderlegbit[16],spiderthread,spiderdropping,spiderrising:INT
DEF ghostbody,ghosthead,ghostleftarm,ghostrightarm,ghostrising:INT
DEF armbone1,armbone2,handbone,thumbbone,fingerbone[4],ground,armmoving:INT
DEF ghostlefteye,ghostrighteye,lastghosttime,lastspidertime,lastarmtime:INT
DEF spidery,sleeperz[10],spiderz,ghosty,ghostz:FLOAT
DEF lightxangle,armx,armz:FLOAT
DEF soundmem[3]:MEMORY

spiderz=500:spidery=300:spiderdropping=0:spiderrising=0
ghosty=-150:ghostrising=0:ghostz=800
armx=250:armz=400:armmoving=0

'Open a window
WINDOW win,0,0,640,480,@NOAUTODRAW,0,"",mainwindow

MOVE win,250,200:PRINT win,"Generating sounds"

GOSUB createwavsinmemory

'Create a 3D screen
error=CREATE3DSCREEN(win,640,480,32)
IF error<>0
  MESSAGEBOX win, "Could not create Direct3D screen","Error"
  CLOSEWINDOW win
  END
ENDIF

FRONTPEN win,RGB(255,255,255)
BACKPEN win,0

D3DSETQUALITY win,@LIGHTON | @FILLSOLID | @SHADEGOURAUD

GOSUB setupscene

STARTTIMER win,1000

'Hide cursor
SETCURSOR win,@CSCUSTOM,0

lastframetime=GetTickCount()-1
starttime=lastframetime
run=1

WAITUNTIL run=0

'Delete things
D3DDELETE light
D3DDELETE camera
D3DDELETE rail1
D3DDELETE rail2
D3DDELETE spiderbody
FOR n=0 TO 11:D3DDELETE spiderlegbit[n]:NEXT n
D3DDELETE spiderthread
D3DDELETE ghostbody
D3DDELETE ghosthead
D3DDELETE ghostleftarm
D3DDELETE ghostrightarm
D3DDELETE ghostlefteye
D3DDELETE ghostrighteye
D3DDELETE armbone1
D3DDELETE armbone2
D3DDELETE handbone
D3DDELETE thumbbone
FOR n=0 TO 3:D3DDELETE fingerbone[n]:NEXT n
FOR n=0 TO 9:D3DDELETE sleeper[n]:NEXT n
D3DDELETE ground
D3DDELETE scene
CLOSEWINDOW win
FOR n=0 TO 2:FREEMEM soundmem[n]:NEXT n
END



SUB mainwindow
  SELECT @class
   CASE @IDKEYDOWN
      'Esc key
     IF @CODE=0x1B THEN run=0
    CASE @IDCLOSEWINDOW:run=0
    CASE @IDTIMER
      'Start ghost,spider or skeletal arm
      IF ghostrising=0 & spiderrising=0 & spiderdropping=0 & armmoving=0 & (GetTickCount()-starttime>5000)
        n=RND(10)
        IF n<3 & GetTickCount()-lastspidertime>6000
          spiderdropping=1:lastspidertime=GetTickCount()
          PLAYWAVE soundmem[1],@SNDASYNC
        ENDIF
        IF n>3 & n<7 & GetTickCount()-lastarmtime>6000
          armmoving=1:lastarmtime=GetTickCount()
          PLAYWAVE soundmem[2],@SNDASYNC
        ENDIF
        IF n>7 & GetTickCount()-lastghosttime>6000
          ghostrising=1:lastghosttime=GetTickCount()
          PLAYWAVE soundmem[0],@SNDASYNC
        ENDIF
      ENDIF
   CASE @IDDXUPDATE
      'Find time since last frame to make things run at a constant speed
      timesincelastframe=GetTickCount()-lastframetime
      IF timesincelastframe>2
        lastframetime=GetTickCount()
        FOR n=0 TO 9
          sleeperz[n]=sleeperz[n]-timesincelastframe/4
          D3DCOMMAND sleeper[n],@SETPOSITION,scene,0,-10,sleeperz[n]
        NEXT n
        IF sleeperz[0]<150
          FOR n=0 TO 9
            sleeperz[n]=sleeperz[n]+150
            D3DCOMMAND sleeper[n],@SETPOSITION,scene,0,-10,sleeperz[n]
          NEXT n
        ENDIF
        IF spiderdropping | spiderrising
          IF spidery>80 & spiderdropping
             spidery=spidery-timesincelastframe/5
          ENDIF
          IF spiderrising
            spidery=spidery+timesincelastframe/5
          ENDIF
          spiderz=spiderz-timesincelastframe/4
          IF spiderz<120
             spiderrising=1:spiderdropping=0
          ENDIF
          IF spiderz<0
             spidery=300:spiderz=500:spiderdropping=0:spiderrising=0
          ENDIF
          D3DCOMMAND spiderbody,@SETPOSITION,scene,0,spidery,spiderz
        ENDIF
        IF ghostrising
          IF ghosty<0 THEN ghosty=ghosty+timesincelastframe/10
          ghostz=ghostz-timesincelastframe/4
          IF ghostz<0
             ghosty=-150:ghostz=800:ghostrising=0
          ENDIF
          D3DCOMMAND ghostbody,@SETPOSITION,scene,0,ghosty,ghostz
        ENDIF
        IF armmoving
           IF armx>30 THEN armx=armx-timesincelastframe/6
           armz=armz-timesincelastframe/4
           IF armz<0
             armx=250:armz=400:armmoving=0
           ENDIF
           D3DCOMMAND armbone1,@SETPOSITION,scene,armx,81,armz
        ENDIF
      'Render the scene
      D3DRENDER scene,camera
      MOVE win,5,5:PRINT win,"Press Esc to exit"
      'Show the scene
      DXFLIP win,0,0
      ENDIF
  ENDSELECT
RETURN



SUB setupscene
'The parent scene frame
scene = D3DSCENE(win)
D3DCOMMAND scene,@SETSCENEBACKCOLOR,0,0,0

'Create and position the camera
camera = D3DCAMERA(scene)
D3DCOMMAND camera,@SETPOSITION,scene,0,80,0
D3DCOMMAND camera,@SETORIENTATION,scene,0,0,1,0,1,0

'Create and orient a spotlight
lightxangle=.6
light = D3DLIGHT(scene,@LIGHTSPOT,1,1,1)
D3DCOMMAND light,@SETPOSITION,scene,0,600,-500
D3DCOMMAND light,@SETORIENTATION,scene,0,-SIN(lightxangle),COS(lightxangle),  0,COS(lightxangle),SIN(lightxangle)

'Create track
rail1=D3DSHAPE(scene,@SHAPECUBE,10,10,1500)
D3DCOMMAND rail1,@SETPOSITION,scene,-40,0,850
D3DCOMMAND rail1,@SETSHAPECOLOR,1,1,1

rail2=D3DSHAPE(scene,@SHAPECUBE,10,10,1500)
D3DCOMMAND rail2,@SETPOSITION,scene,40,0,850
D3DCOMMAND rail2,@SETSHAPECOLOR,1,1,1

FOR n=0 TO 9
  sleeper[n]=D3DSHAPE(scene,@SHAPECUBE,140,10,20)
  sleeperz[n]=250+150*n
  D3DCOMMAND sleeper[n],@SETPOSITION,scene,0,-10,sleeperz[n]
  D3DCOMMAND sleeper[n],@SETSHAPECOLOR,.4,.25,0
NEXT n

'Create spider
spiderbody=D3DSHAPE(scene,@SHAPESPHERE,10,10)
D3DCOMMAND spiderbody,@SCALE,1,.6,1.2
D3DCOMMAND spiderbody,@SETSHAPECOLOR,.5,.3,0

spiderhead=D3DSHAPE(spiderbody,@SHAPESPHERE,5,8)
D3DCOMMAND spiderhead,@SETPOSITION,spiderbody,0,0,-16
D3DCOMMAND spiderhead,@SETSHAPECOLOR,.5,.3,0

'Create spider legs
FOR n=0 TO 3
  spiderlegbit[n*3]=D3DSHAPE(spiderbody,@SHAPECUBE,30,1,1)
  D3DCOMMAND spiderlegbit[n*3],@SETPOSITION,spiderbody,0,0,10-n*5
  spiderlegbit[n*3+1]=D3DSHAPE(spiderbody,@SHAPECUBE,10,1,1)
  D3DCOMMAND spiderlegbit[n*3+1],@SETPOSITION,spiderbody,-18,-3.5,10-n*5
  D3DCOMMAND spiderlegbit[n*3+1],@SETORIENTATION,scene,0,0,1, -1,1,0
  spiderlegbit[n*3+2]=D3DSHAPE(spiderbody,@SHAPECUBE,10,1,1)
  D3DCOMMAND spiderlegbit[n*3+2],@SETPOSITION,spiderbody,18,-3.5,10-n*5
  D3DCOMMAND spiderlegbit[n*3+2],@SETORIENTATION,scene,0,0,1, 1,1,0
NEXT n
'Colour spider legs
FOR n=0 TO 11
  D3DCOMMAND spiderlegbit[n],@SETSHAPECOLOR,.5,.3,0
NEXT n

'Create thread
spiderthread=D3DSHAPE(spiderbody,@SHAPECUBE,.5,100,.5)
D3DCOMMAND spiderthread,@SETPOSITION,spiderbody,0,50,0

'Create ghost
ghostbody=D3DSHAPE(scene,@SHAPESPHERE,50,12)
D3DCOMMAND ghostbody,@SCALE,.8,1.6,1
D3DCOMMAND ghostbody,@SETPOSITION,scene,0,ghosty,ghostz

ghosthead=D3DSHAPE(ghostbody,@SHAPESPHERE,25,8)
D3DCOMMAND ghosthead,@SCALE,.8,1.2,1
D3DCOMMAND ghosthead,@SETPOSITION,ghostbody,0,80,0

ghostleftarm=D3DSHAPE(ghostbody,@SHAPESPHERE,25,8)
D3DCOMMAND ghostleftarm,@SCALE,.4,.4,3
D3DCOMMAND ghostleftarm,@SETPOSITION,ghostbody,30,50,-60

ghostrightarm=D3DSHAPE(ghostbody,@SHAPESPHERE,25,8)
D3DCOMMAND ghostrightarm,@SCALE,.4,.4,3
D3DCOMMAND ghostrightarm,@SETPOSITION,ghostbody,-30,50,-60

ghostlefteye=D3DSHAPE(ghostbody,@SHAPESPHERE,3,8)
D3DCOMMAND ghostlefteye,@SETPOSITION,ghostbody,8,90,-20
D3DCOMMAND ghostlefteye,@SETSHAPECOLOR,0,0,0

ghostrighteye=D3DSHAPE(ghostbody,@SHAPESPHERE,3,8)
D3DCOMMAND ghostrighteye,@SETPOSITION,ghostbody,-8,90,-20
D3DCOMMAND ghostrighteye,@SETSHAPECOLOR,0,0,0

'Create skeletal arm
armbone1=D3DSHAPE(scene,@SHAPESPHERE,2,8)
D3DCOMMAND armbone1,@SCALE,10,1,1
D3DCOMMAND armbone1,@SETPOSITION,scene,armx,80,armz

armbone2=D3DSHAPE(armbone1,@SHAPESPHERE,2,8)
D3DCOMMAND armbone2,@SCALE,10,1,1
D3DCOMMAND armbone2,@SETPOSITION,armbone1,0,5,0

handbone=D3DSHAPE(armbone1,@SHAPESPHERE,7,8)
D3DCOMMAND handbone,@SCALE,1,.7,.1
D3DCOMMAND handbone,@SETPOSITION,armbone1,-24,2.5,0

thumbbone=D3DSHAPE(armbone1,@SHAPESPHERE,1,8)
D3DCOMMAND thumbbone,@SCALE,6,1,1
D3DCOMMAND thumbbone,@SETPOSITION,armbone1,-27,11,0
D3DCOMMAND thumbbone,@SETORIENTATION,scene,0,0,1, .8,1,0

'Create finger bones
FOR n=0 TO 3
  fingerbone[n]=D3DSHAPE(armbone1,@SHAPESPHERE,1,8)
  D3DCOMMAND fingerbone[n],@SCALE,6,1,1
  D3DCOMMAND fingerbone[n],@SETPOSITION,armbone1,-36,-1.2+n*2.2,0
NEXT n

'Create ground
ground=D3DSHAPE(scene,@SHAPEcube,500,2,1000)
D3DCOMMAND ground,@SETPOSITION,scene,0,-16,500
D3DCOMMAND ground,@SETSHAPECOLOR,0,0,0

RETURN



SUB createwavsinmemory
  DEF filelength,datalength,databyte:INT
  DEF duration,phase,mult:FLOAT
  duration=1.5
  datalength=11025*duration
  filelength=datalength+44
  DEF snd[filelength]:CHAR
  RECT win,240,230,150,20,0
  'Create header
  snd="R","I","F","F"
  snd[4]=(filelength-8) & (0xFF),((filelength-8) & (0xFF00))/(0x100),((filelength-8) & (0xFF0000))/(0x10000),(filelength-8)/0x1000000
  snd[8]="W","A","V","E","f","m","t"," ",16,0,0,0,1,0,1,0,17,43,0,0
  snd[28]=17,43,0,0,1,0,8,0,"d","a","t","a"
  snd[40]=datalength & (0xFF),(datalength & (0xFF00))/(0x100),(datalength & (0xFF0000))/(0x10000),datalength/0x1000000
  For n=0 TO 2:ALLOCMEM soundmem[n],1,filelength:NEXT n
  'Create ghost sound
  FOR databyte=1 TO datalength
    mult=(1-ABS((datalength/2)-databyte)/(datalength/2))
    phase=phase+.5*mult
    snd[databyte+43]=128+mult*100*SIN(phase)
  NEXT databyte
  WRITEMEM soundmem[0],1,snd
  RECT win,240,230,50,20,0,0
  'Create spider sound
  FOR databyte=1 TO datalength
    IF databyte%1500<1
      snd[databyte+43]=128+100*databyte/datalength
    ELSE
      snd[databyte+43]=128
    ENDIF
  NEXT databyte
  WRITEMEM soundmem[1],1,snd
  RECT win,240,230,100,20,0,0
  'Create arm sound
  FOR databyte=1 TO datalength STEP 2
    snd[databyte+43]=128+(databyte<datalength-50)*databyte*RND(50)/datalength
    IF databyte<>datalength THEN snd[databyte+44]=snd[databyte+43]
  NEXT databyte
  WRITEMEM soundmem[2],1,snd
RETURN

Regards,

Peter B.

GWS

Gosh! .. i'm going to be up half the night trying all these goodies out ..  :)

I hope Jolly Roger sees these threads - he does some great stuff.

Also ZeroDog - I loved his 'spooks in the back yard' program ..  :)  I've probably got it somewhere.

Graham :)



Tomorrow may be too late ..

pistol350

I got it too.
Don't worry graham ,i will post almost everything funny i got from everyone  ;)
Regards,

Peter B.