EntityBlend.bb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. Graphics3D 640,480
  2. SetBuffer BackBuffer()
  3. SeedRnd MilliSecs()
  4. ; create camera
  5. camera=CreateCamera()
  6. CameraClsColor camera,160,160,160
  7. PositionEntity camera,0,0,-30
  8. middle=CreatePivot()
  9. EntityParent camera,middle
  10. ; create add texture - white cirlce on a black background
  11. For n=0 To 50
  12. Color 5+(n*5),5+(n*5),5+(n*5)
  13. Oval 10+n,10+n,236-(n*2),236-(n*2),1
  14. Next
  15. blob_tex=CreateTexture(256,256)
  16. blob=CreateImage(256,256)
  17. GrabImage blob,0,0
  18. CopyRect 0,0,256,256,0,0,ImageBuffer(blob),TextureBuffer(blob_tex)
  19. FreeImage blob
  20. max_blobs=100
  21. ; create blobs using add blend mode
  22. Dim blobs(max_blobs) ; blob sprites
  23. Dim xyblobs#(max_blobs,2) ; blob vector
  24. For n=0 To max_blobs
  25. blobs(n)=CreateSprite()
  26. EntityFX blobs(n),1
  27. EntityBlend blobs(n),3 ;set blend mode to add
  28. EntityTexture blobs(n),blob_tex
  29. xyblobs(n,0)=Rnd(-.1,.1)
  30. xyblobs(n,1)=Rnd(-.1,.1)
  31. xyblobs(n,2)=Rnd(-.1,.1)
  32. EntityColor blobs(n),Rand(0,255),Rand(0,255),Rand(0,255) ;give it a colour
  33. Next
  34. ; create cube texture
  35. Color 255,255,255
  36. Rect 0,0,256,256,1
  37. For n=0 To 7
  38. If n=0 Then Color 0,0,0
  39. If n=1 Then Color 0,0,255
  40. If n=2 Then Color 0,255,0
  41. If n=3 Then Color 0,255,255
  42. If n=4 Then Color 255,0,0
  43. If n=5 Then Color 255,0,255
  44. If n=6 Then Color 255,255,0
  45. If n=7 Then Color 255,255,255
  46. Rect n*32,n*32,32,32,1
  47. Next
  48. Color 0,0,0
  49. For n=0 To 255 Step 32
  50. Line 0,n,255,n
  51. Line n,0,n,255
  52. Next
  53. cube_tex=CreateTexture(256,256)
  54. cube=CreateImage(256,256)
  55. GrabImage cube,0,0
  56. CopyRect 0,0,256,256,0,0,ImageBuffer(cube),TextureBuffer(cube_tex)
  57. FreeImage cube
  58. ; create cube
  59. cube=CreateCube()
  60. ScaleEntity cube,11,11,11
  61. EntityTexture cube,cube_tex
  62. EntityFX cube,17 ;set fullbright and 2 sided textures
  63. EntityBlend cube,2 ;set multiply blend
  64. Repeat
  65. ; move the blobs around
  66. For n=0 To max_blobs
  67. MoveEntity blobs(n),xyblobs(n,0),xyblobs(n,1),xyblobs(n,2)
  68. ;bounce off sides
  69. If EntityX(blobs(n))<-10 Or EntityX(blobs(n))>10 Then xyblobs(n,0)=-xyblobs(n,0)
  70. If EntityY(blobs(n))<-10 Or EntityY(blobs(n))>10 Then xyblobs(n,1)=-xyblobs(n,1)
  71. If EntityZ(blobs(n))<-10 Or EntityZ(blobs(n))>10 Then xyblobs(n,2)=-xyblobs(n,2)
  72. Next
  73. ; turn camera
  74. TurnEntity middle,.1,.2,.3
  75. UpdateWorld
  76. RenderWorld
  77. Flip
  78. Until KeyHit(1)